Tag Info

New answers tagged

0

You could use an user-defined conversion, something like this: struct GpuVec3 { public: GpuVec3() {} GpuVec3& GpuVec3::operator=(const vec3& other) { v.x = other.x; v.y = other.y; v.z = other.z; v.w = 1.0f; return *this; } operator glm::vec3() const { return v.xyz; } private: vec4 ...


1

I think you would do to keep your GPUVec3 and your vec3 as two separate classes, not one containing the other. Here's an example: struct vec3 { float x,y,z; }; struct GPUVec3 { float x,y,z, pad; GPUVec3() { } GPUVec3( float x, float y, float z ) { } GPUVec3( const vec3 & v ) { } operator vec3 const & () const { return ...


1

Tobias, If you declare your vec3 class in C++ as having 16 byte alignment, you will have the matching offset. struct vec3 { float x,y,z; } __attribute__ ((aligned(16))); However this will align it everywhere. You might want a GPUVec3 which is aligned, and has copy constructor from your general vec3 so you don't burn that extra float everywhere. I ...


-1

Sounds like an alignment or memory size issue. Perhaps with this one increased float your memory needs are being bumped up to some magic number that slows down the MAC (I don't use MACs myself) but most likely it is causing an alignment issue. Consider a C++ type structure in pseudo code: struct myStruct { char x; int y; } If this structure is ...


8

You already know what you have to do, I'll just summarize it. There are three ways to solve your problem: Go ahead and make a conditional like you're saying, either by sampling the texture or by creating a separate uniform for this purpose. As you probably know, adding branching on a shader is almost never a good idea, and much less so in the fragment ...


4

This is a pretty late reply, but some new options have shown up recently to address this. Khronos released a reference compiler called glslangValidator that can perform syntax validation (and more) on GLSL shader files. If there are any issues with your shader, it will print them out with line number information. You can set up a custom pre build step or ...


0

Not that I'm aware of (you're asking if there's some sort of glsl function that would do the conversion, right?) It's a pretty simple conversion though, just three lines; here it is in pseudocode: r = sqrt(x*x+y*y+z*z); theta = atan2(y,x); phi = atan2(sqrt(x*x+y*y),z);


2

One way of doing this is to when you are loading the model and creating the vertex layout. you could calculate a second set of normals. which would be the flat normals. Do so by taking the connecting triangles. and then put it into all the vertices. if there is more than one connecting pollygon, you could insert some indexing to make it easier to handle ...


3

You need two different models, because flat-shaded and smooth-shaded models normals are different. One of the ways is to generate 2 separate models and replace them with one another on demand. Another way is to make a single model prepared for flat shaded render (all vertices unique) and replace only normals when switching to flat/smooth shading. For ...


0

texelFetch is used for lockups without performing mip-mappnig, filtering..etc. and even with this you still need to pass a sampler. Otherwise your out of luck, as far as I am aware, making such operation available restricts driver writers from doing certain optimization, for instance they need to keep textures in a certain layout in memory.


1

The way to discriminate that is to use the screen position intrinsic of GLSL gl_FragCoord (some call it a built-in variable). And pass it through a floating point function that will do the equivalent of a modulo in integers math. This way, you can use 2 as a divisor and the (floating point) alternation of the saw-dent-like ramps it will create (rising from 0 ...


0

glUniform*() only affects the currently bound program. Therefore one must call glUseProgram() before making any calls to glUniform*().


1

It's a simple interpolation. Let's assume that your heights span -1 to 1, 0 is water surface and you have 3 colours: dark green, light green and white. A way to do what you want is to have the following color_from_height function in the pixel or fragment shader (depending on how efficient you want to be). In my shader below I visualize the gradient, but the ...


0

As pointed out by @UnholySheep, I was linking the normal PhysX libraries, but the CHECKED versions of them must be linked for the PhysX Visual Debugger to work, and all the "error" messages that show up are perfectly normal when the PVD can't connect, which was the case.


3

Assuming that location is the uniform location you've already retrieved from the shader, and vec is your vector, then in C++11 you can do: glUniform3fv(location, vec.size(), reinterpret_cast<GLfloat *>(vec.data())); Prior to C++11: glUniform3fv(location, vec.size(), reinterpret_cast<GLfloat *>(&vec[0])); The "old" method will work in ...


0

Assuming your Vector3f class is laid out linear in memory. std::vector<Vector3f> m_verts; float* address = &m_verts[0].x; This will get the address of the x value of the first element, so long as your data is laid out linearly, and your sizeof(Vector3f) == size(float) * 3 you should be fine.


1

You don't specify what rendering method you want to use. Standard rasterisation of a 3D mesh? Or do you have a volume representation of the model and your renderer uses that directly? If you render a volume, check this: http://http.developer.nvidia.com/GPUGems/gpugems_ch39.html especially 39.2. The effect in the picture you provide is mainly subsurface ...


2

Yes. There an article about this by Chris­t­ian Schüler: http://www.thetenthplanet.de/archives/1180 It's a followup to a book article (ShaderX 5) which did exactly what you need. I've used it myself. Here is the part that you need: (p : world-space position, N : world-space normal) mat3 cotangent_frame( vec3 N, vec3 p, vec2 uv ) { // get edge vectors ...



Top 50 recent answers are included