vs_1_1 // Define Constants. //def c8, 1, 10.0, 8, 0.5f // [0] = universial "1", [1] = global constant offset, [2] = regionY multiplier, [3] = cull offset //def c78, 6.0, 0.04, 0.0, 1.0 // [0] = regionX multiplier, [1] = canopy region bias, [2] = shadow bias dcl_position v0 dcl_texcoord v1 dcl_color v2 dcl_normal v3 // Find the fractional component within the cell. mov r6, v2.baba // 1 fraction -> r6 // Find all of: x*y, 1-x*y, x*1-y, 1-x*1-y. Used for interpolation add r8, -r6.x, c8.x // 1 // 1-x add r9, -r6.y, c8.x // 1 // 1-y mul r2, r8, r9 // 1 // r2 = (1-x) * (1-y) mul r3, r6.x, r9 // 1 // r3 = (x) * (1-y) mul r4, r8, r6.y // 1 // r4 = (1-x) * (y) mul r5, r6.x, r6.y // 1 ( 7 ) // r5 = (x) * (y) // Find the region. mad r1.xy, v2.rg, c78.xx, c78.yy // 1 // r1 = v2.rgrg * 6 + 0.4 (ie. scale [0..1] -> [0.4 .. 6.4]) mad r1.x, r1.x, c8.z, r1.y // 1 // r1.xy = regionY * 8 + regionX add r1.x, r1.x, c8.y // 1 ( 10 ) // Find the interpolation of the height offset mov a0.x, r1.x // 1 // Start addressing at constant register 10 (where the height information starts) mul r8, r4, c[a0.x + 1] // 1 // Upper left mul r9, r5, c[a0.x + 9] // 1 // Upper right mad r10, r2, c[a0.x + 0], r8 // 1 // Lower left mad r11, r3, c[a0.x + 8], r9 // 1 // Lower right add r1, r10, r11 // 1 (16) // r1 = (1-x)(1-y)*P(0,0) + (1-x)(y)*P(0,1) + (x)(1-y)*P(1,0) + (x)(y)*P(1,1) // Now we have the interpolation of all of the constants between the four points // The following instructions multiply the input position by the world matrix mov r0.xyz, v0 // 1 // Move the object position into r0 add r0.z, r1.x, r0.z // 1 // Add the height differential to the world output position mov r0.w, c8.x // 1 // w = 1. m4x3 r8.xyz, r0, c4 // 3 // Multply the position by the world matrix mov r8.w, c8.x // 1 // w = 1. m4x4 oPos, r8, c0 // 4 (27) // This translates the final world position into screen space // Now find the fogging values (assume that the fog center is [0,0,0]). dp3 r4.w, r8, r8 // 1 // (WP - FC) dot (WP - FC) rsq r0.w, r4.w // 1 // 1 / sqrt( (WP - FC) dot (WP - FC) ) mul r11.w, r0.w, r4.w // 1 // sqrt( (WP - FC) dot (WP - FC) ) mul r6.w, r11.w, c74.x // 1 // sqrt( (WP - FC) dot (WP - FC) ) / (Far plane distance) = Fogging, [0..1] add r2, r6.w, -c74.y // 1 // ( Fogging - MinFogValue ) mul r2, r2, c74.z // 1 // ( Fogging - MinFogValue ) / ( 1 - MinFogValue ) sge r3, r6.w, c74.y // 1 // If (Fogging >= MinFogValue ) { r3 = 1 } else { r3 = 0 } mul r6.w, r3, r2 // 1 (35) // Which means that if ( Fogging < MinFogValue ) Fogging = 0. // Light calculations dp3 r11, -c76, v3 // 1 // (Light Vector) dot (Normal) (L.N) mul r11, r11, c75 // 1 // Modulate diffuse by its color add r11, r11, c77 // 1 // Add the ambient color to this value. max r11, c78.zzzz, r11 // 1 // Clamp the minimum value to 0 min r11, c78.wwww, r11 // 1 // Clamp the maximum value to 1 add r1.z, r1.z, c77.w // 1 // Add the ambient to the shadowing value min r1.z, r1.z, c78.wwww // 1 (42) // Clamp the shadowing value at 1 // Finish off, and write the destination registers sub oT0.xyz, r1.y, c8.w // 1 // Move cull value - 0.5, therefore, if cull value is < 0.5, then t0.z will be negative, into T0 mov oT1.xyz, v1 // 1 // now move the original texture coordinates into oT1. mul oD0, r1.z, r11 // 1 // Multiply the lighting value with the shadow, and put it in diffuse #0 min oD1, r6.w, c8.x // 1 (46) // Fog value = min( 1, value ) into diffuse #1. // Total Instructions = 46.