Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tips for Shading Your Terrain

Similar presentations


Presentation on theme: "Tips for Shading Your Terrain"— Presentation transcript:

1 Tips for Shading Your Terrain
CS 418 Exercise 5

2 You Need to Shade your Terrain
You need to compute Blinn-Phong per Fragment What do you send from the vertex to fragment shader?

3 You Need to Shade your Terrain
Varyings Surface normal Vertex position Uniforms Viewer position Light position Calculate the Halfway vector 𝐻= 𝐿+𝑉 𝐿+𝑉

4 What about Material Colors?
You’ll calculate a material color in the vertex shader based on height. Send in a per-vertex value for height You can normalize the height value: 𝐻 𝑛𝑜𝑟𝑚𝑒𝑑 = (𝐻−𝑀𝑖𝑛𝐻𝑒𝑖𝑔ℎ𝑡) 𝑀𝑎𝑥𝐻𝑒𝑖𝑔ℎ𝑡−𝑀𝑖𝑛𝐻𝑒𝑖𝑔ℎ𝑡 Lies in [0,1] Allows you to use a simple colormap in shader E.g. [0,0.2)Blue, [0.2,0.5]green, etc.

5 What about alpha? Can use a uniform alpha if you wish
Or…maybe compute it per vertex…pass as varying Make blue shiny like water Keep in mind that the specular material color need not match diffuse material color White is often a good choice

6 Common Bugs Make sure all vectors are unit length
Make sure all vectors and positions are in the same coordinate space If you work in view/camera coordinates this means apply view transformation to the light position What is the eye/viewer position in view/camera space?

7 Common Bugs Is the ambient level too high?
Might make things look unshaded Try not using ambient…only add if too dark Are your normals facing the right direction? If some parts of mesh are… the normals may be reversed Did you store the triangles in CCW order?

8 Testing Normal Directions
You can render the normal values Use set the per-vertex rgb value to be the normal Don’t shade…just draw the color Red=x, Green=y, Blue =z You should be able see the directions….


Download ppt "Tips for Shading Your Terrain"

Similar presentations


Ads by Google