Copyright © NVIDIA Corporation 2004
GDC 2005
•v2f BumpReflectVS(a2v IN,
• uniform float4x4 WorldViewProj,
• uniform float4x4 World,
• uniform float4x4 ViewIT)
•{
• v2f OUT;
• // Position in screen space.
• OUT.Position = mul(IN.Position, WorldViewProj);
• // pass texture coordinates for fetching the normal map
• OUT.TexCoord.xyz = IN.TexCoord;
• OUT.TexCoord.w = 1.0;
• // compute the 4x4 tranform from tangent space to object space
• float3x3 TangentToObjSpace;
• // first rows are the tangent and binormal scaled by the bump scale
• TangentToObjSpace[0] = float3(IN.Tangent.x, IN.Binormal.x, IN.Normal.x);
• TangentToObjSpace[1] = float3(IN.Tangent.y, IN.Binormal.y, IN.Normal.y);
• TangentToObjSpace[2] = float3(IN.Tangent.z, IN.Binormal.z, IN.Normal.z);
• OUT.TexCoord1.x = dot(World[0].xyz, TangentToObjSpace[0]);
• OUT.TexCoord1.y = dot(World[1].xyz, TangentToObjSpace[0]);
• OUT.TexCoord1.z = dot(World[2].xyz, TangentToObjSpace[0]);
• OUT.TexCoord2.x = dot(World[0].xyz, TangentToObjSpace[1]);
• OUT.TexCoord2.y = dot(World[1].xyz, TangentToObjSpace[1]);
• OUT.TexCoord2.z = dot(World[2].xyz, TangentToObjSpace[1]);
• OUT.TexCoord3.x = dot(World[0].xyz, TangentToObjSpace[2]);
• OUT.TexCoord3.y = dot(World[1].xyz, TangentToObjSpace[2]);
• OUT.TexCoord3.z = dot(World[2].xyz, TangentToObjSpace[2]);
• float4 worldPos = mul(IN.Position, World);
• // compute the eye vector (going from shaded point to eye) in cube space
• float4 eyeVector = worldPos - ViewIT[3]; // view inv. transpose contains eye position in world space in last row.
• OUT.TexCoord1.w = eyeVector.x;
• OUT.TexCoord2.w = eyeVector.y;
• OUT.TexCoord3.w = eyeVector.z;
• return OUT;
•}
•
•///////////////// pixel shader //////////////////
•
•float4 BumpReflectPS(v2f IN,
• uniform sampler2D NormalMap,
• uniform samplerCUBE EnvironmentMap,
•      uniform float BumpScale) : COLOR
•{
• // fetch the bump normal from the normal map
• float3 normal = tex2D(NormalMap, IN.TexCoord.xy).xyz * 2.0 - 1.0;
• normal = normalize(float3(normal.x * BumpScale, normal.y * BumpScale, normal.z));
• // transform the bump normal into cube space
• // then use the transformed normal and eye vector to compute a reflection vector
• // used to fetch the cube map
• // (we multiply by 2 only to increase brightness)
• float3 eyevec = float3(IN.TexCoord1.w, IN.TexCoord2.w, IN.TexCoord3.w);
• float3 worldNorm;
• worldNorm.x = dot(IN.TexCoord1.xyz,normal);
• worldNorm.y = dot(IN.TexCoord2.xyz,normal);
• worldNorm.z = dot(IN.TexCoord3.xyz,normal);
• float3 lookup = reflect(eyevec, worldNorm);
• return texCUBE(EnvironmentMap, lookup);
•}
NVShaderPerf
Inputs:
•HLSL
•GLSL (fragments)
•!!FP1.0
•!!ARBfp1.0
•PS1.x,PS2.x,PS3.x
•VS1.x,VS2.x, VS3.x
•Cg
NVShaderPerf
GPU Arch:
•GeForce FX
•GeForce 6 Series
•Quadro FX
Outputs:
•Assembly code
•# of cycles
•# of temporary registers
•Pixel throughput
•Forces all fp16 and all fp32
-Allows developers to be able to run numbers and performance estimates without having the hardware or the driver…
-It also allows developers to figure out performance cliffs for shading languages like GLSL that are abstracting HW resource limitations
-It works for Quadro Workstation GPUs as well
-NVShaderPerf can easily be used as regression tool in a production environment to keep track of shader cycle budgets…