Question

I'm still very inexperienced with shaders but I'm climbing the learning curve well.

Something I've stumbled upon this morning is an effort to use a same-named uniform in both fragment and vertex shaders.

The uniform can be defined in both shaders, but it can only be accessed exclusively in one or the other shader, but not both. If I try to access the shader in both, the program does not compile.

The last idea I had was they are compiled as separate symbols, but I don't know how to get access to them except by glGetUniformLocation. Calling that twice with the same string returns the same uniform location... not a great help.

The shaders are pretty simple, and everything works perfectly except for the single line work-or-not tests that have no effect on the rendering.

Is there a special approach for using the same-named uniform with same value between the two shaders?

Was it helpful?

Solution

SOLVED! The precision qualifier isn't usually a requirement from my experience. I wasn't using it... and because my uniform was an integer.

I read a confirmation that uniforms can be same-named between vertex and fragment shaders here:

http://www.gamedev.net/topic/535321-glsl-the-same-named-uniform-in-vertex-and-fragment-shaders/

So I believed it was my own mistake.

Finally, I tried adding the highp precision qualifer, and that has SOLVED the issue of crashing.

Technically:

Setup 1 (crash)

Vertex shader:
uniform int frameNum;

Fragment shader:
uniform int frameNum;

Setup 2 (crash)

Vertex shader:
uniform highp int frameNum;

Fragment shader:
uniform int frameNum;

Setup 3 (SUCCESS)

Vertex shader:
uniform highp int frameNum;

Fragment shader:
uniform highp int frameNum;

Setup 4 (SUCCESS)

Vertex shader:
uniform int frameNum;

Fragment shader:
uniform highp int frameNum;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top