Hi, I try to find in the vertex shader if the vertex y value is higher then const number, how do I do that?

I try with h = gl_Vertex.y but it doesnt work when i transform the matrix(e.g. rotate). its also doesnt work when i try:

h = vec3(gl_ModelViewMatrix * gl_Vertex).y

any idea?

TIA

In what space is “const number”? You have to transform the position into that space before the comparison can be meaningful.

I wont to draw another texture to vertex under the water height.

for example if the water height is 10.f so every pixel that found under this height will be colored blue.

so the “const number” is the water height and i need to check if the vertex(after the transformation if exist) is under this ‘line’

Make sure all your comparisons are in the same space.

Multiplying by gl_ModelViewMatrix is transforming to eye space so your comparison height must also be transformed into eye space. You may have to pass your own matrix for the camera rather than relying upon inbuilt uniforms.

so when i rotate and translate the mesh with glrotatef and gltranslatef(when use glMatrixMode(GL_MODELVIEW)) what i need to do? I have 2 float vars. h - the vertex y value ans waterh - the water height.

when i dont apply any transform i can do:

h=gl_vertex.y; waterh = 10.f

when i apply transformation what i need to do? multiplying both h and waterh by what?

so when i rotate and translate the mesh with glrotatef and gltranslatef(when use glMatrixMode(GL_MODELVIEW)) what i need to do

Transform your vec4(vec3(height),1.0) by the same modelview matrix.

when i dont apply any transform i can do:

That’s not possible other wise your vertex would not be visible in the screen. You mean when you have an identity modelmatrix - or in other words, you are not using gltranslatef. In which case still multiply by modelview matrix.

ok, thanks.

but now i cant just do the simple check if h < waterh if:

h=vec3(gl_ModelViewMatrix * gl_Vertex).y;

waterh=vec3(gl_ModelViewMatrix * vec4(0,water_height,0,1.0)).y;

i have to multiply only by gl_modelmatrix, but there are no modelmatrix.

Then supply your own uniform for the model matrix.

yes that what i do. but i still have the problem when i rotate the mesh i cant just check: if(h<waterh){…}