View Full Version : get position of vertex

shlomip

07-15-2011, 04:26 AM

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

Alfonse Reinheart

07-15-2011, 04:31 AM

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

shlomip

07-15-2011, 04:55 AM

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'

BionicBytes

07-15-2011, 06:48 AM

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.

shlomip

07-15-2011, 07:56 AM

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?

BionicBytes

07-15-2011, 08:46 AM

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.

shlomip

07-16-2011, 12:19 PM

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.

BionicBytes

07-17-2011, 11:20 AM

Then supply your own uniform for the model matrix.

shlomip

07-17-2011, 12:47 PM

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

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.