// $Revision$ $Author$ $DateTime$ //------------------------------------------------------------------------------------------------ // // ***************** FIRAXIS GAME ENGINE ******************** // // FILE: VSTerrain_UnderdarkP3_11.vsh // // AUTHOR: Bart Muzzin - 19/03/2004 // // PURPOSE: This draw a fogged black object over where the terrain will be rendered. This is done // so that the terrain can be additive blended on top of it, without doing any real // calculations. // //------------------------------------------------------------------------------------------------ // Copyright (c) 2004 Firaxis Games, Inc. All rights reserved. //------------------------------------------------------------------------------------------------ vs_1_1 // Declare the color registers dcl_position v0 dcl_normal v1 dcl_color0 v3 dcl_color1 v4 dcl_color2 v5 // The following instructions multiply the input position by the world matrix mul r3.xy, v0.xy, c19.z // 1 // r3.xy = (pos.xy * 255) * xy_scaling mov r3.y, -r3.y // 1 // r3.y = -(pos.y * 255) * xy_scaling (negate y) mul r3.z, v0.z, c19.w // 1 // r3.z = (pos.z * 255) * z_scaling mul r3.z, r3.z, c18.w // 1 // Scale the world Z position by the landscape scaling factor mov r3.w, c14.x // 1 // w = 1. m4x4 r8, r3, c0 // 4 // This translates the final world position into screen space mov oPos, r8 // 1 (8) // Move the final position into the output register // Do the alpha sum of the terrain pieces dp4 r9, v3, c15 // 1 // Extract all alphas by using DPs against predefined constants dp4 r10, v4, c16 // 1 dp4 r11, v5, c17 // 1 add r9, r9, r10 // 1 // Add all the components together add r9, r9, r11 // 1 (13) // Put the output in the diffuse alpha mul oD0.a, r9, c20.y // 1 // Multiply by 1 / 255.0, so we normalize the alpha output // Fogging calculations mul r6.w, r8.z, c8.x // 1 // sqrt( (WP - FC) dot (WP - FC) ) / (Far plane distance) = Fogging, [0..1] add r2, r6.w, -c8.y // 1 // ( Fogging - MinFogValue ) mul r2, r2, c8.z // 1 // ( Fogging - MinFogValue ) / ( 1 - MinFogValue ) sge r3, r6.w, c8.y // 1 // If (Fogging >= MinFogValue ) { r3 = 1 } else { r3 = 0 } mul r4, r3.x, r2.x // 1 (18) // Record the fogging value. // We now need to find out what the color of this vert will be, based on the alphas of ocean3, sand and sand wet. //mul r6, v3.x, c90 // 1 mul r6, v3.x, c91 // 1 mad r6, v3.y, c92, r6 // 1 mul r6, r6, c20.y // 1 // Normalize to [0..1] // We don't use fogging directly, so we need to reduce the levels of things that will be fogged, // because the terrain is going to be added in an additive method. add r3, c14.x, -r4 // 1 // Take the complement of the fog value mul r11, r3, r6 // 1 (25) // Turn down the "alpha" by the amount of fog at this pixel // Now compute lighting information mul r6, v1, c20.y // 1 // r6 = norm / 255.0 add r1, r6, -c14.w // 1 // norm = (norm.xy - 0.5) mul r1, r1, c14.z // 1 // norm = (norm.xy - 0.5) * 2.0 dp3 r9, -c10, r1 // 1 // (Light Vector) dot (Normal) (L.N) mul r9, r9, c11 // 1 // Modulate diffuse by its color add r9, r9, c12 // 1 // Add the ambient color to this value. max r9, c14.y, r9 // 1 // Clamp the minimum value to 0 min r1, c14.x, r9 // 1 // Clamp the maximum value to 1 mul r11, r11, r1 // 1 // Multiply the computed alpha sum color by the diffuse/ambient lighting // Get the final color mul r10, r4, c9 // 1 // Modulate the fog color by the fogging value. add oD0.rgb, r10, r11 // 1 (27) // Add the terrain color to the fog color, and make that the diffuse color