/************* UN-TWEAKABLES **************/ float4x4 wVP : WorldViewProjection; float4x4 wM : World; float4x4 vIT : ViewInverseTranspose; #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 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 refractInd < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.01; > = 1.0; float fresnelBias < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.01; > = 0.5; float3 glass < string UIWidget = "Color"; > = float3(1, 1, 1); float uvTileBase < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 5.0; float UIStep = 0.01; > = 1.0; ////// // Transparency for objects that smash and disappear float4 colourMod = {1.0f, 1.0f, 1.0f, 1.0f}; /************ Textures ***************/ texture nm < string ResourceType = "2D"; >; sampler2D baseNormalMap = sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; }; texture envMapBelow < string ResourceType = "Cube"; >; samplerCUBE cubeMapBelow= sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; WrapS = ClampToEdge; WrapT = ClampToEdge; }; texture envMap < 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; 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; half3 lightDir : TEXCOORD5; 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 diffColour; half3 specColour; half3 nM = tex2D(baseNormalMap, IN.oTexCoord).xyz; half3 lightDir = IN.lightDir; half3 lColour = lightColour; half3 aColour = ambientColour; half3 worldNorm = getWorldNormal(IN.TSRow1, IN.TSRow2, IN.TSRow3, nM); half3 eyeVector = half3(IN.TSRow1.w, IN.TSRow2.w, IN.TSRow3.w); half3 reflection = reflect(eyeVector, worldNorm); half3 glassRef = texCUBE(cubeMap, reflection).xyz * glass; half3 refraction = refract(eyeVector, worldNorm, refractInd); half3 glassColour = texCUBE(cubeMapBelow, refraction).xyz * glass; half3 Hnorm = normalize(lightDir + -eyeVector); half NdotL = dot(worldNorm , lightDir ); half NdotH = dot(worldNorm, Hnorm); half3 litVec = lit(NdotL, NdotH, specularExp).xyz; half fresnel = fresnelBias + 1 / (pow((1 - dot(eyeVector, worldNorm)), 2)); fresnel += (fresnelBias + (1.0-fresnelBias)*pow((1-NdotL), 2), 0.0); diffColour += aColour ; diffColour += litVec.y * lColour ; specColour += specularInt * litVec.z * diffColour; glassColour = (lerp( glassColour, glassRef, reflectivity) + specColour.xyz); colour = half4(lerp(glassRef.xyz, glassColour.xyz, fresnel),1 * colourMod.a); #ifdef _PRAETORIAN_ depthBlur = half4(IN.oTexCoord.z, worldNorm.x, worldNorm.y, 1.0f); #else depthBlur = half4(0,0,0,0); #endif } /*************/ technique main { pass p0 { VertexProgram = compile vp30 simpleVP(); FragmentProgram = compile fp40 simpleFP(); DepthTestEnable = true; DepthMask = true; BlendEnable = true; BlendFunc = int2( SrcAlpha , InvSrcAlpha ); } } /***************************** eof ***/