//vertex shader for grass xvs.1.1 #pragma screenspace // Constants // c0 to c63 - Disturbance grid : pos.x, pos.z, intensity, packedIdx // c64 to c79 - Lights grid // c80 to c83 - World + View + Projection : transpose matrix // c84 to c91 - Wind grid // c92 - 0.0f, -1.0f, 0.0f, 0.0f; // c93 - radius, unused, luxScale, luxConstant // c94 - 0.0f, 0.5f, 1.0f, 0.4f;//w->luxThreshold // c95 - camPos; // dcl_position0 v0 //xyzh // dcl_position1 v1 //u, v, gi, wi // dcl_position2 v2 //light index // dcl_position3 v3 //light weight // dcl_position4 v4 //blade position // def c92, 0.0f, -1.0f, 0.0f, 0.0f; // def c93, 0.6f, 5.0f, 10.8f, 0.6f;//Radius, unused, luxScale, luxConstant // def c94, 0.0f, 0.5f, 1.0f, 0.4f;//w->luxThreshold // camera position #define C_V_CAMERA_POS c95 // fog #define C_F_FOG_NEAR c-1.x #define C_F_FOG_INV_FAR_SUB_NEAR c-1.y #define C_F_FOG_MIN c-1.z #define C_F_FOG_MAX_SUB_MIN c-1.w #define C_F_FOG_FAR c-2.x #define C_F_FOG_MAX c-2.y // OFFSET & SCALE #define C_V_PROJECTION_OFFSET c-3 #define C_V_PROJECTION_SCALE c-4 //---Texture----------------- mov oT0.xy, v1.xy; //---Texture----------------- //---Disturbance------------- mov a0.x, v1.z; //Find the grid index mov r0.x, c[a0.x].w; //Retreive the index //Find the pos of the first idx influence mov a0.x, r0.x; //Find the disturbance index mov r1, c[a0.x].xxyy; //Retreive the effect x and z position sub r1, v4, r1; //BladePos - EffectPos mov r1.y, c94.x; //Put the y to 0.0f dp3 r2.x, r1, r1; sub r2.x, c93.x, r2.x; //Radius˛ - dot(distance) mul r2.x, r2.x, c[a0.x].z; // multiply by the intensity max r2.x, r2.x, c94.x; //if < 0.0f = 0.0f mul r3, r1, r2.x; //Give the EffectForce //mov r3.x, c94.x;//0.f //Will stop the force on x //mov r3.z, c94.x;//0.f //Will stop the force on z //---Disturbance------------- //---Wind Force-------------- mov a0.x, v1.w; //Find the wind index frc r0.y, v1.w; //Take the fraction part of wind index mov r1, c[a0.x+84]; //Retreive the wind force sub r0.x, c94.z, r0.y; //1.0f - fraction part (0->1) mul r2.xy, r1.xy, r0.x; //F.xy = wind.xy * (1-fract) mad r2.xy, r1.zw, r0.y, r2.xy; //F.xy += wind.zw * fract //mov r2.x, c94.x;//0.f //Will stop the wind on x //mov r2.y, c94.x;//0.f //Will stop the wind on z //---Wind Force-------------- //---Postition-------------- add r2.xz, r2.xy, r3.xz; //Add the wind force and the disturbance force mul r2.xz, r2.xz, v0.w; //Multiply by height˛ mov r0, v0; //Get the vertexPos add r0.xz, r0.xz, r2.xz; //Add the forces to the vertexPos mov r0.w, c94.z; //Fill w with 1.0f dp4 oPos.x, r0, c80; dp4 oPos.y, r0, c81; dp4 oPos.z, r0, c82; dp4 oPos.w, r0, c83; //---Postition-------------- //---FOG--- // (R11) distance to camera (pos-cam).length sub r11, r0, C_V_CAMERA_POS dp3 r11.w, r11, r11 rsq r11.w, r11.w rcp r11.w, r11.w // (R10) factor = ( length - minLength ) / (maxLength - minLength ), clamped // fog = min + ( max - min ) * factor sub r10.x, r11.w, C_F_FOG_NEAR mul r10.x, r10.x, C_F_FOG_INV_FAR_SUB_NEAR max r10.x, r10.x, C_F_FOG_MIN min r10.x, r10.x, C_F_FOG_MAX mad oFog.x, C_F_FOG_MAX_SUB_MIN, r10.x, C_F_FOG_MIN //---FOG--- //---Colour------------------ mov a0.x, v2.x; //Find the first light index mul r1, c[a0.x+64], v3.x; //Multiply it's colour by the weight mov a0.x, v2.y; //Find the second light index mad r1, c[a0.x+64], v3.y, r1; //Multiply it's colour by the weight and add it to the previous colour mov a0.x, v2.z; //Find the third light index mad r1, c[a0.x+64], v3.z, r1; //Multiply it's colour by the weight and add it to the previous colour mov a0.x, v2.w; //Find the fourth light index mad r1, c[a0.x+64], v3.w, r1; //Multiply it's colour by the weight and add it to the previous colour mov r1.w, c94.z; //Put 1.0f in the alpha cause it's the density parameter in it //---Colour------------------ //---Lux on the bend-------- //r0 = VertexPos //r1 = VertexColour //r2 = BendForce mov r2.y, c94.x; //Put 0.0f in it just to be able to use it sub r3, r0, c95; //VertexPos - CamPos mul r5, r3.x, r3.x; //Start normalizing mad r5, r3.y, r3.y, r5; mad r5, r3.z, r3.z, r5; rsq r4.x, r5; //Inverse sqrt mul r4, r3, r4.x; //End normalizing dp3 r3.x, r2, r4; mad r3.x, r3.x, c93.z, c93.w; //Multiply by the luxScale and add the luxConstant max r3.x, c94.w, r3.x; //Not under c94.w min r3.x, c94.z, r3.x; //Not over c94.z mul oD0, r1, r3.x; //---Lux on the bend-------- // offset and scale mul oPos.xyz, r12, C_V_PROJECTION_SCALE // scale rcc r1.x, r12.w // compute 1/w mad oPos.xyz, r12, r1.x, C_V_PROJECTION_OFFSET // scale by 1/w, add offset