Sign in to follow this  
nebulus-design

GLSL Vertex Shader weirdness!

Recommended Posts

Hi All I'm just tinkering with a vertex shader and I came across a weird behaviour and wondered if it was me or is something odd going on!? I'm using a vertex shader to gently move all vertices over time using a sine wave, here is the shader: uniform float t; void main( void ) { vec4 vert = gl_Vertex; vert.x += sin( t ); gl_Position = gl_ModelViewProjectionMatrix * vert ; gl_FrontColor = gl_Color ; } This works nicely as long as all the objects are using the same ModelView matrix, unfortunately I'm not, my gl rendering (which is all using the same program) goes something like this: glPushMatrix(); DrawSomething(); glPopMatrix(); glPushMatrix(); glScalef( 2,2,2 ); DrawSomething(); glPopMatrix(); Now with the original shader the second larger object moves twice as much, which totally makes sense, so I modified the shader to this: uniform float t; void main( void ) { vec4 vert = gl_ModelViewMatrix * gl_Vertex; vert.x += sin( t ); gl_Position = gl_ProjectionMatrix * vert ; gl_FrontColor = gl_Color ; } Now neither object appears to move, but they do appear to jitter a couple of pixels! I've played with larger (and much larger!) multipliers on the sin line to see if it was just a fact that post ModelView matrix the coord system was wildly different, but it always looks the same... It's got me stumped, unless I'm being stupid and have missed something really obvious? any ideas???

Share this post


Link to post
Share on other sites
If you want to you can pass in the scale factor to the vertex shader to allow you to use the same shader or make two shaders one for scale=1 and scale=2. I would recommend the former.

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