Jump to content
  • Advertisement
Sign in to follow this  
ade-the-heat

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


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

//Vertex Shader

uniform 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 Shader
varying vec4 my_color;

void main(){
gl_FragColor=my_color;
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!