• 14
• 14
• 9
• 10
• 9

# simple vertex shader question regarding height

This topic is 4300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

All the shader examples I see don't use any of the vertex x,y or z values directly. What I'm thinking of doing is simple: when drawing the terrain - for vertices above 1500metres (which is where my snow will lie) - to make the snow reflect the sun's light to give a specular color. So I'd want to do: if y value > 1500 do specular color end is that possible ? cheers

##### Share on other sites

You can use the saturate function for example to calculate a factor for the specular.

float specular_factor = saturate(position.z - snowlevel);

so at snowlevel the specular_factor is zero and 1 unit higher it has the full strength.

Cheers

//Vertex Shaderuniform vec4f color;varying vec4 my_color;void main(){   vec3 pos=gl_ModelViewMatrix*gl_Position;   my_color=color;   if(pos.y>1500){      my_color+=specular_color;//no matter how you calculate the specular_color, add it to your color here         }   ftransform();}//Fragment Shadervarying vec4 my_color;void main(){   gl_FragColor=my_color;}