# simple vertex shader question regarding height

This topic is 4513 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

##### Share on other sites
Well, you probably have to do something like this (assuming you use GLSL):

//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;}

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632984
• Total Posts
3009716
• ### Who's Online (See full list)

There are no registered users currently online

×