SLIDE 6 6
Bump mapping in RenderMan
Bump mapping calculations should be
done in “shader” space
The coordinate system in which the shading calculations are being performed. This is normally the "camera" or "world" coordinate system. "current" The coordinate system in which the shader was defined. This is the "object" coordinate system when the shader is defined. "shader" Description Coordinate System
Bump Mapping in Renderman
vector Nshad = vtransform (“shader”, N); point Pshad = transform (“shader”, P); Pshad += amp * normalize (Nshad); P = transform (“shader”, “current”, Pshad); N = calculatenormal (P);
Works just as well (see Section 8.2.3 in text
for derivation)
vector Nn = normalize (N); P += Nn * (amp / length (vtransform(“shader”, Nn));
Bump mapping in Cg
Once again, bump mapping like all
texture mapping, must be done by a fragment shader.
Consider the basic Phong shader.
Phong as a Fragment Shader
void PhongVertexPass (float4 position: POSITION, float3 normal: NORMAL,
- ut float4 oPosition: POSITION,
- ut float3 objPos: TEXCOORD0,
- ut float3 oNormal: TEXCOORD1
uniform float4x4 modelViewProj) {
- Position = mul (modelViewProj, position);
- bjPos = position.xyz;
- Normal = normal;
}
Need texCoord at vertex to be passed to fragment shader
Phong as a Fragment Shader
void basicPhongFrag (float4 position: TEXCOORD0, float3 normal : TEXCOORD1,
uniform float3 globalAmbient, uniform float3 lightColor, uniform float3 lightPos, uniform float3 eyePos, uniform float3 Ka, uniform float3 Kd, uniform float3 Ks, uniform float shininess)
Need texCoord at vertex to be accepted by fragment shader Texture map need to be added as a parameter These values will be modified by values in bump map
Phong as a Fragment Shader
{ float3 P = position.xyz; float3 N = normalize (normal); // ambient term float3 ambient = Ka * globalAmbient; // diffuse term float3 L = normalize (lightPos - P); float diffuseLight = max (dot(N, L), 0); float3 diffuse = Kd * lightColor * diffuseLight;