Sign in to follow this  

simple vertex shader question regarding height

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

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

This topic is 4201 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this