string description = "Basic Material Dynamic"; /************* UN-TWEAKABLES **************/ float4x4 wVP : WorldViewProjection < string UIWidget="None"; >; float4x4 wM : World < string UIWidget="None"; >; float4x4 vIT : ViewInverseTranspose < string UIWidget="None"; >; #include "y:\\art\\shaders\\Basic_Utils.cgfx" /*********** Tweakables **********************/ float3 lightPosition : Position < string Object = "PointLight0"; string Space = "World"; > = {100.0f, 100.0f, 100.0f}; ///// float3 lightColour : Diffuse < string UIWidget = "Color"; > = {1.0f, 1.0f, 1.0f}; ///// float3 ambientColour : Ambient < string UIWidget = "Color"; > = {0.42f, 0.42f, 0.42f}; ///// ///// float3 Subcutaneous < string UIWidget = "Color"; > = {0.5f, 0.1f, 0.0f}; ///// float bleed < string UIName = "Scatter Rolloff"; string UIWidget = "Slider"; float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.01; > = 0.2; ///// float specularInt < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 5.0; float UIStep = 0.01; > = 1.0; float specularExp < string UIWidget = "slider"; float UIMin = 1.0; float UIMax = 128.0; float UIStep = 1.0; > = 32.0; ////// float reflectivity < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.01; > = 0.0; ////// float uvTileBase < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 5.0; float UIStep = 0.01; > = 1.0; // float uvTileBullet // < // string UIWidget = "slider"; // float UIMin = 0.0; // float UIMax = 10.0; // float UIStep = 0.01; // > = 1.0; // // Bullet Variables // int bulletNumber = 0; // float impactArea // < // string UIWidget = "slider"; // float UIMin = 0.0; // float UIMax = 5.0; // float UIStep = 0.01; // > = 2; // float4 impactPoint[16]; // Transparency for objects that smash and disappear float4 colourMod = {1.0f, 1.0f, 1.0f, 1.0f}; /************* Textures ******************/ texture cm : Diffuse < string ResourceType = "2D"; >; sampler2D baseColourMap = sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; }; texture nm : Normal < string ResourceType = "2D"; >; sampler2D baseNormalMap = sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; }; texture bm : Diffuse < string ResourceType = "2D"; >; sampler2D baseBlendMap = sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; }; // texture bulletNM : Normal // < // string ResourceName = "Y:\\Art\\Levels\\Western\\Textures\\Final\\damage_nm.dds"; // string ResourceType = "2D"; // >; // sampler2D bulletNormalMap = sampler_state // { // Texture = ; // MinFilter = LinearMipMapLinear; // MagFilter = Linear; // }; texture envMap : Environment < string ResourceType = "Cube"; >; samplerCUBE cubeMap= sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; WrapS = ClampToEdge; WrapT = ClampToEdge; }; texture diffEnvMap : Environment < string ResourceType = "Cube"; >; samplerCUBE diffCubeMap= sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; WrapS = ClampToEdge; WrapT = ClampToEdge; }; /************* DATA STRUCTS **************/ /* data from application vertex buffer */ struct appdata { float4 position : POSITION; half2 texCoord0 : TEXCOORD0; half3 tangent : TEXCOORD1; half3 normal : NORMAL; half4 colour : COLOR0; }; /* data passed from vertex shader to pixel shader */ struct vertexOutput { float4 oPosition : POSITION; half3 oTexCoord : TEXCOORD0; // z contains world depth half4 TSRow1 : TEXCOORD1; half4 TSRow2 : TEXCOORD2; half4 TSRow3 : TEXCOORD3; half4 worldPos : TEXCOORD4; // half2 BulletUV : TEXCOORD5; half3 lightDir : TEXCOORD6; half4 oColour : COLOR0; }; /*********** vertex program ******/ vertexOutput simpleVP(appdata IN) { vertexOutput OUT = (vertexOutput)0; //hack for FXC as IN.colour = half4(0,0,0,0); to be removed for in game. //IN.colour = half4(0,0,0,1); //constants OUT.oColour = IN.colour; OUT.oTexCoord.xy = IN.texCoord0 * uvTileBase; //made commented until we can switch off/on as needed // OUT.BulletUV = IN.texCoord0 * uvTileBullet; //postion and depth OUT.oPosition = mul(wVP, IN.position); OUT.oTexCoord.z = OUT.oPosition.z; //compute the transform from tangent space to object space half3 vtan = IN.tangent; half3 vbinorm = GetBiNormal(IN.tangent, IN.normal); half3 vnorm = IN.normal; getTSRows ( vtan, vbinorm, vnorm, wM, OUT.TSRow1, OUT.TSRow2, OUT.TSRow3); OUT.worldPos = mul(wM, IN.position); half4 eyeVector = OUT.worldPos - vIT[3]; OUT.TSRow1.w = eyeVector.x; OUT.TSRow2.w = eyeVector.y; OUT.TSRow3.w = eyeVector.z; OUT.lightDir = normalize(lightPosition - OUT.worldPos.xyz); return OUT; } /********* fragment program ********/ void simpleFP(vertexOutput IN, out float4 colour : COLOR0, out float4 depthBlur : COLOR1 ) { //final colour, textures and composite lighting contributions half3 texColour = tex2D(baseColourMap, IN.oTexCoord.xy).xyz; half3 nM = tex2D(baseNormalMap, IN.oTexCoord.xy).xyz; half3 blendMask = tex2D(baseBlendMap, IN.oTexCoord.xy).xyz; //made commented until we can switch off/on as needed // half3 damageNM = tex2D(bulletNormalMap, IN.BulletUV).rgb; half3 lightDir = IN.lightDir; half3 lColour = lightColour; half3 aColour = ambientColour; //made commented until we can switch off/on as needed or control the number of loops generated // getBulletHoles( nM, // damageNM, // IN.oColour.a, // impactPoint, // IN.worldPos, // impactArea); //generate normal and world normal half3 worldNorm = getWorldNormal(IN.TSRow1, IN.TSRow2, IN.TSRow3, nM); //generate eye vector, reflected diffuse and envornment contributions half3 eyeVector = normalize(half3(IN.TSRow1.w, IN.TSRow2.w, IN.TSRow3.w)); half3 reflection = reflect(eyeVector, worldNorm); half3 envMap = texCUBE(cubeMap, reflection).xyz; half3 diffEnvMap = texCUBE(diffCubeMap, reflection).xyz; //rim light subsurface scatter half rim = smoothstep(-bleed,1,dot(worldNorm , eyeVector)) - smoothstep(0,1,dot(worldNorm , eyeVector)); rim = max(0,rim); //point light subsurface scatter half sub = smoothstep(-bleed,1,dot(worldNorm , lightDir)) - smoothstep(0,1,dot(worldNorm , lightDir)); sub = max(0,sub + rim); texColour.rgb += sub * Subcutaneous; #ifdef _PRAETORIAN_ half4 litRelPos = getLitRelPos(IN.worldPos); #else half4 litRelPos; #endif colour.xyz = getFinalColourReflection( lightDir, worldNorm, eyeVector, specularExp, specularInt, reflectivity, aColour, lColour, texColour, blendMask, envMap, diffEnvMap, litRelPos, IN.oColour.a); colour.a = colourMod.a; #ifdef _PRAETORIAN_ depthBlur = half4(IN.oTexCoord.z, worldNorm.x, worldNorm.y, 1.0f); #else depthBlur = half4(0,0,0,0); #endif } /*************/ technique basic { pass p0 { VertexProgram = compile vp30 simpleVP(); FragmentProgram = compile fp40 simpleFP(); DepthTestEnable = true; DepthMask = true; BlendEnable = true; BlendFunc = int2( SrcAlpha , InvSrcAlpha ); } } /***************************** eof ***/