User Tools

Site Tools


public:t-vien-09-1:lab_7_materials

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

public:t-vien-09-1:lab_7_materials [2009/02/26 12:46]
hannes
public:t-vien-09-1:lab_7_materials [2009/02/26 15:12] (current)
hannes
Line 28: Line 28:
 viewpoint.reparentTo(model) # Attach to the teapot viewpoint.reparentTo(model) # Attach to the teapot
 model.setTexture(ts1, buffer.getTexture()) model.setTexture(ts1, buffer.getTexture())
 +# The following seems to be needed to stop the cube map from rotating with the teapot...
 +viewpointmover = lerpHprInterval(viewpoint, 15.0, Vec3(0,0,0), Vec3(359, 0, 0))
 +viewpointmover.loop()
 </code> You will have access to this texture inside your pixel shader as the **tex_1** color sampler (the new input variable is **uniform samplerCUBE tex_1 : TEXUNIT1**). Notice that this is a special cube texture. The final stage is to look up the color value of this cube map and multiply that with your existing diffuse color component (which already includes the color value from your other texture). You look up values in a cube map with the function **texCUBE(<texture>,<3Dtexturecoordinates>)**. Notice that you need 3D texture coordinates here. Actually, all you need is the View ReflectionVector. That is, the part of the environment that you see reflected in the surface of the teapot is exactly the part pointed at by a vector that has the same angle as your view angle, but in the opposite direction. This vector you can calculate just like the Light ReflectionVector above, but replace the light with the view vector: **VR = normalize(2*N*dot(N,V)-V);**. So, pass **VR** now into the **texCUBE** function as your texture coordinates and you should be all set. Test it out! </code> You will have access to this texture inside your pixel shader as the **tex_1** color sampler (the new input variable is **uniform samplerCUBE tex_1 : TEXUNIT1**). Notice that this is a special cube texture. The final stage is to look up the color value of this cube map and multiply that with your existing diffuse color component (which already includes the color value from your other texture). You look up values in a cube map with the function **texCUBE(<texture>,<3Dtexturecoordinates>)**. Notice that you need 3D texture coordinates here. Actually, all you need is the View ReflectionVector. That is, the part of the environment that you see reflected in the surface of the teapot is exactly the part pointed at by a vector that has the same angle as your view angle, but in the opposite direction. This vector you can calculate just like the Light ReflectionVector above, but replace the light with the view vector: **VR = normalize(2*N*dot(N,V)-V);**. So, pass **VR** now into the **texCUBE** function as your texture coordinates and you should be all set. Test it out!
   - **Normal Map:**\\ For this part, you need to be using a **sphere** model and you need to assign the **bricks.png** and **bricks-n.png** textures to two separate texture stages on the model.  The latter texture is a normal map (passed in as **uniform sampler2D tex_1 : TEXUNIT1**) To add lighting detail with this normal map, a new coordinate space, called the tangent space, needs to be created inside the vertex shader.  This space is local to each vertex and is defined by the axes formed by the vertex normal, binormal and tangent.  Therefore the following automatic varying inputs need to be added to the vertex shader: <code c>   - **Normal Map:**\\ For this part, you need to be using a **sphere** model and you need to assign the **bricks.png** and **bricks-n.png** textures to two separate texture stages on the model.  The latter texture is a normal map (passed in as **uniform sampler2D tex_1 : TEXUNIT1**) To add lighting detail with this normal map, a new coordinate space, called the tangent space, needs to be created inside the vertex shader.  This space is local to each vertex and is defined by the axes formed by the vertex normal, binormal and tangent.  Therefore the following automatic varying inputs need to be added to the vertex shader: <code c>
/var/www/ailab/WWW/wiki/data/pages/public/t-vien-09-1/lab_7_materials.txt ยท Last modified: 2009/02/26 15:12 by hannes