string description = "Basic 2 Blend 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}; ///// float specularInt < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 5.0; float UIStep = 0.01; > = 1.0; float blendWeight < 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 uvTileLayer1 < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 5.0; float UIStep = 0.01; > = 1.0; float falloff < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 5.0; float UIStep = 0.01; > = 1.0; float blendMin < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 5.0; float UIStep = 0.01; > = 0.0; float blendMax < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 5.0; float UIStep = 0.01; > = 1.0; /************* 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 l1cm : Diffuse < string ResourceType = "2D"; >; sampler2D layer1ColourMap = sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; }; texture l1nm : Normal < string ResourceType = "2D"; >; sampler2D layer1NormalMap = sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; }; texture l1bm : Diffuse < string ResourceType = "2D"; >; sampler2D layer1BlendMap = 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; }; /************* DATA STRUCTS **************/ /* data from application vertex buffer */ struct appdata { float4 position : POSITION; half2 texCoord0 : TEXCOORD0; half4 tangent : TEXCOORD1; half3 binormal : TEXCOORD2; 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; half4 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 * float4(blendWeight.r, 1.f.rrr); OUT.oTexCoord.xy = IN.texCoord0 * uvTileBase; OUT.BulletUV.zw = IN.texCoord0 * uvTileLayer1; //made commented until we can switch off/on as needed // OUT.BulletUV.xy = 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.xyz; #ifdef _PRAETORIAN_ half3 vbinorm = GetBiNormal(IN.tangent.xyz, IN.normal) * IN.tangent.w; #else half3 vbinorm = IN.binormal; #endif 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 half4 baseColour = tex2D(baseColourMap, IN.oTexCoord.xy); //mixMask = clamp( ( ( heightmap - vertexColor.r ) / blendFalloff ), 0.0, 1.0 ); // DR: this is artist bollocks //float blend = step(baseColour.a, IN.oColour.r) * (IN.oColour.g); IN.oColour.g = max(IN.oColour.g, 0.05f); baseColour.a *= 0.999f; float blend = saturate(smoothstep(baseColour.a, saturate(baseColour.a+IN.oColour.g), IN.oColour.r)); half3 texColour = lerp (baseColour, tex2D(layer1ColourMap, IN.BulletUV.zw), blend).xyz ; half3 nM = lerp (tex2D(baseNormalMap, IN.oTexCoord.xy), tex2D(layer1NormalMap, IN.BulletUV.zw), blend).xyz; half3 blendMask = lerp (tex2D(baseBlendMap, IN.oTexCoord.xy), tex2D(layer1BlendMap, IN.BulletUV.zw), blend).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); half4 envMap = texCUBElod(cubeMap, float4(reflection.xyz, 7.f * (1.f-(specularExp/96.f)))); envMap.rgb += envMap.rgb * envMap.a; half4 diffEnvMap = texCUBElod(cubeMap, float4(worldNorm.xyz, 6.f)); diffEnvMap.rgb += diffEnvMap.rgb * diffEnvMap.a; #ifdef _PRAETORIAN_ half4 litRelPos = getLitRelPos(IN.worldPos); #else half4 litRelPos; #endif colour.xyz = getFinalColourReflection( lightDir, worldNorm, eyeVector, specularExp, specularInt, specularInt, aColour, lColour, texColour, blendMask, envMap.rgb, diffEnvMap.rgb, litRelPos, IN.oColour.a); colour.a = 1; #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 = false; } } technique doubleSided { pass p0 { VertexProgram = compile vp30 simpleVP(); FragmentProgram = compile fp40 simpleFP(); DepthTestEnable = true; DepthMask = true; BlendEnable = false; AlphaTestEnable = false; CullFaceEnable = false; } } /***************************** eof ***/