Hot answers tagged

3

I fully agree with all other replies and comments that rgba is definitely faster as it reduces the number of fetches from 16 to 4. You can even omit the per-element assignment: //I also fixed the typo in Matric[i]es m[0] = texelFetch( projMatrices , ivec2( 0 , lightIndex ) , 0 ); m[1] = texelFetch( projMatrices , ivec2( 1 , lightIndex ) , 0 ); m[2] = ...


3

It should be significantly faster to sample one RGBA value from one location in a texture than four R values from different locations in the texture.


3

This question and its answer, actually answer my question. I had to read its answer carefully and find my mistake. Now my fragment shader look like this: const GLchar* fragmentSource = R"glsl( #version 330 core in vec2 TexCoord; uniform sampler2D ourTexture; #define PI 3.141592653589793238462f #define TWO_PI 6....


3

GLSL does not support C++ style namespaces. You might want to do some regex magic before parsing the shader, replacing '::' with '_' or something. You might want to have a preprocessor of sorts - or just forget about it entirely.


2

As Olivier mentioned, it's not safe in general to apply algebraic optimizations to floating-point math, as floating point doesn't actually obey associativity rules due to roundoff error. $(a + b) - b$ will not be equal to $a$, if the intermediate result $(a + b)$ had to be rounded; nor will $a \cdot (b + c)$ be equal to $a \cdot b + a \cdot c$ in general, ...


1

The eye position (a vec3) was being bound to the wrong shader, resulting in the glUniform3 error when OpenGL (mesa) checked the validity of the uniforms. The error was due to a typo; I named my simple-mesh and animated-mesh shaders similar things. glUseProgram(smesh_shader.get()); smb.predraw(); glUniform3fv(mesh_shader.uniform("eye"), 1, &...


1

Yes, it is guaranteed by the GLSL language specifications (click me). Section "4.1.10. Implicit Conversions" says In some situations, an expression and its type will be implicitly converted to a different type. The spec shows all possible implicit conversions inside a table, also int -> float. It further says: When an implicit conversion is done, it ...


Only top voted, non community-wiki answers of a minimum length are eligible