Sign in to follow this  
reoxthen

strange shader problem

Recommended Posts

reoxthen    122
guys, strangely, if I don't call one of the built-in uniform matrices (no matter which) in my shader, my application crashes with access violation. as I tried the variations, I realized it doesn't matter which one of the matrices called. I don't have to assign em to something or use in a operation. so if I add "just one" of following lines, it works just fine. otherwise it crashes the application: mat4 dummy = gl_ProjectionMatrix; or gl_Position = gl_ModelViewProjectionMatrix * vec4(vertexpos, 1.0f); or just gl_ModelViewMatrix; gl_ProjectionMatrix; etc... any one familiar? or am I missing something? (Card's ATI mobility radeon x700)

Share this post


Link to post
Share on other sites
reoxthen    122
as I dig more I realized actually it crashes if I don't call at least one of the built-in uniforms of vertex shaders listed in http://www.opengl.org/sdk/libs/OpenSceneGraph/glsl_quickref.pdf in some point of vertex shader. but I try to create everything custom and don't want to use these built ins. any idea?

Share this post


Link to post
Share on other sites
Aph3x    288
Is anything output at the shader validation stage? I've had problems with shaders that run fine on NVidia but crash horribly on Ati...

Share this post


Link to post
Share on other sites
reoxthen    122
if you mean the info log, the answer is no. it says the fragment and vertex shaders are compiled succesfully and program linked succesfully.

by the way during the debug crash, access violation creates a breakpoint in the line that I pass my sampler to shader with glUniform call. but as I said before, if I access one of these built-ins in vertex shader, sampler works just fine.

Share this post


Link to post
Share on other sites
Aph3x    288
Yes the info log. Do you actually try to validate the shader (not just compile and link)? It may give some clue to what's happening. Shaders get very aggressively optimised which can lead to some seemingly strange behaviour.

You get the crash when binding a sampler - this leads me to think you may get a "Validation failed - samplers of different types are bound to the same texture image unit" error when validating...

Share this post


Link to post
Share on other sites
Could be many things going on... for example an output variable from the vertex shader that is input for the fragment shader that doesn't have the exact same format or qualifiers. An example I encountered a few days ago (only applies to GLSL version 1.30 and higher), I got similar behavior you described (strange things seemed to fix the program), the cause:

vertex shader:
#version 130;
out vec4 color;
void main(void)
{
gl_Position = ... // fill the position
color = vec4(1.0, 1.0, 1.0, 1.0);
}
fragment shader:
#version 130;
precision mediump float; // otherwise the compiler complained not specifying a precision
in vec4 color;
out vec4 fragmentColor;

void main(void)
{
fragmentColor = color;
}
As soon as I added the precision qualifier in the vertex shader to the out variable as well it worked flawlessly (while the program compiled, linked and validated). These kind of things can be very strict I guess.

Other possible causes:
Have you checked all attributes (you are probably using as you are trying not to use the built-in attributes) are bound properly? Same goes for custom uniforms you have bound.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this