string description = "Basic Material Static"; /************* UN-TWEAKABLES **************/ float4x4 vP : ViewProjection < string UIWidget="None"; >; float4x4 vIT : ViewInverseTranspose < string UIWidget="None"; >; float4x4 wM : World < 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 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; /************* 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 envMap : Environment < string ResourceType = "Cube"; >; texture l1nm : Normal < string ResourceType = "2D"; >; sampler2D layer1NormalMap = sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; }; 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 binormal : TEXCOORD1; half2 texCoord1 : TEXCOORD3; half3 normal : NORMAL; half4 colour : COLOR0; }; /* data passed from vertex shader to pixel shader */ struct vertexOutput { float4 oPosition : POSITION; half4 oTexCoord : TEXCOORD0; // z contains world depth half4 normal : TEXCOORD1; half4 tangent : TEXCOORD2; half4 binormal : 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; OUT.oTexCoord.zw = IN.texCoord1 * uvTileLayer1; //made commented until we can switch off/on as needed // OUT.BulletUV = IN.texCoord0 * uvTileBullet; //postion and depth float4 worldPos = mul(wM, IN.position); OUT.oPosition = mul(vP, worldPos); //compute the transform from tangent space to object space half3 vtan = IN.tangent; half3 vbinorm = IN.binormal; half3 vnorm = IN.normal; OUT.normal = mul(wM, float4(vnorm, 0)); OUT.tangent = mul(wM, float4(vtan, 0)); OUT.binormal = mul(wM, float4(vbinorm, 0)); // getTSRows ( vtan, vbinorm, vnorm, wM, // OUT.TSRow1, OUT.TSRow2, OUT.TSRow3); half4 eyeVector = worldPos - vIT[3]; OUT.normal.w = eyeVector.x; OUT.tangent.w = eyeVector.y; OUT.binormal.w = eyeVector.z; OUT.lightDir = normalize(lightPosition - worldPos.xyz); return OUT; } /********* fragment program ********/ void simpleFP(vertexOutput IN, out float4 colour : COLOR0) { //final colour, textures and composite lighting contributions half4 texColour = h4tex2D(baseColourMap, IN.oTexCoord.xy); half4 blend = h4tex2D(baseBlendMap, IN.oTexCoord.xy); half4 normal = h4tex2D(baseNormalMap, IN.oTexCoord.xy); half4 normal2 = h4tex2D(layer1NormalMap, IN.oTexCoord.zw); if(texColour.a == 0) discard; half2 blendMask = blend.xy; half3 nM = normal.xyz; // get normal from xy in 0 - 1 to xyz in -1 - 1 nM.xyz -= 0.5f.xxx; nM.xyz *= 2.f.xxx; nM = normalize(nM); half3 nM2 = normal2.xyz; // get normal from xy in 0 - 1 to xyz in -1 - 1 nM2.xyz -= 0.5f.xxx; nM2.xyz *= 2.f.xxx; half3 lightDir = IN.lightDir; half3 lColour = lightColour; half3 aColour = ambientColour; //generate normal and world normal // half3 bM = GetBiNormal(float3(1.f, 0, 0), nM); // half3 tM = GetBiNormal(bM, nM); // bM = GetBiNormal(tM, nM); // nM = normalize(nM.x * IN.tangent.xyz + nM.y * IN.binormal.xyz + nM.z * IN.normal.xyz); // nM = normalize(nM2.x * tM + nM2.y * bM + nM2.z * nM); float3 bM = -GetBiNormal(nM, float3(1.f, 0.f, 0.f)); nM = normalize(nM.x * IN.tangent.xyz + nM.y * IN.binormal.xyz + nM.z*IN.normal.xyz); bM = normalize(bM.x * IN.tangent.xyz + bM.y * IN.binormal.xyz + bM.z*IN.normal.xyz); float3 tM = GetBiNormal(nM, bM); nM = normalize(nM2.x * tM + nM2.y * bM + nM2.z * nM); //generate normal and world normal half3 worldNorm = nM; //generate eye vector, reflected diffuse and envornment contributions half3 eyeVector = normalize(half3(IN.normal.w, IN.tangent.w, IN.binormal.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; half4 litRelPos; half3 litVec = getLitVec(lightDir, worldNorm, eyeVector, specularExp); colour.rgb = getDiffuse(aColour, diffEnvMap.rgb, lColour, litVec, 1.h.xxxx) * texColour.rgb * IN.oColour.a; colour.rgb += getSpecular(specularInt, litVec, blendMask.r, 1.h.xxxx) + (envMap * blendMask.r * specularInt); //colour.rgb = worldNorm; colour.a = 1.f; } /*************/ technique basic { pass p0 { VertexProgram = compile vp30 simpleVP(); FragmentProgram = compile fp40 simpleFP(); DepthTestEnable = true; DepthMask = true; BlendEnable = false; BlendFuncSeparate = int4( DstAlpha , OneMinusSrcAlpha , Zero , One ) ; } } /***************************** eof ***/