string description = "TextRendering"; /************* UN-TWEAKABLES **************/ #include "..\\Basic_Utils.cgfx" float4x4 wM < string UIWidget="None"; >; float4x4 vM; float4x4 vP; float4 colourMod = {1.0f, 1.0f, 1.0f, 1.0f}; float4 inverseParams; /*********** Tweakables **********************/ 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; /************* Textures ******************/ sampler2D TexturePage[1]; texture bm : Diffuse < string ResourceType = "2D"; >; sampler2D baseBlendMap = sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; }; /************* DATA STRUCTS **************/ /* data from application vertex buffer */ struct appdata { float4 position : POSITION; float2 texCoord0 : TEXCOORD0; int textureIdx : TEXCOORD1; }; /* data passed from vertex shader to pixel shader */ struct vertexOutput { float4 position : POSITION; half3 texCoord : TEXCOORD0; half3 normal : TEXCOORD1; half3 tangent : TEXCOORD2; float2 screenPos : TEXCOORD3; half4 colour : COLOR0; // z = screenDepth }; /*********** vertex program ******/ vertexOutput simpleVP(appdata IN) { vertexOutput OUT = (vertexOutput)0; OUT.colour = half4(1.h); OUT.texCoord.xy = IN.texCoord0; //postion and depth OUT.position = mul(wM, float4(IN.position.xyz, 1.f)); OUT.position = mul(vP, OUT.position); // BM: Transform normal and tangent into object space OUT.normal = mul(wM, half4(0.h, 0.h, 1.h, 0.h)).xyz; OUT.tangent = mul(wM, half4(0.h, 1.h, 0.h, 0.h)).xyz; OUT.normal = mul(vM, half4(OUT.normal, 0.h)).xyz; OUT.tangent = mul(vM, half4(OUT.tangent, 0.h)).xyz; OUT.screenPos.xy = OUT.position.zw; return OUT; } /********* fragment program ********/ void simpleFP(in vertexOutput IN, // in float4 screen : WPOS, out half4 colour : COLOR0, out half4 normal : COLOR1 ) { //final colour, textures and composite lighting contributions half4 texColour = h4tex2D(TexturePage[0], IN.texCoord.xy) * colourMod; half4 normalBlend = half4(0.h, 0.h, 0.5h, 0.5h);//h4tex2D(baseBlendMap, IN.texCoord.xy); if(texColour.a < 0.1h) discard; half2 blendMask = normalBlend.xy; half3 nM; nM.xy = normalBlend.zw; half3 binormal = GetBiNormal(IN.tangent, IN.normal); //generate normal and world normal nM.xy -= 0.5h.xx; nM.xy *= 2.h.xx; nM = DecodeNormal(nM.xy); nM = normalize(nM.x * IN.tangent + nM.y * binormal + nM.z*IN.normal); float viewDepth = inverseParams.w / ((IN.screenPos.x/IN.screenPos.y) + inverseParams.z); colour = half4(half3(texColour * IN.colour.a), blendMask.g * reflectivity); normal = half4(nM.x, nM.y, clamp(blendMask.r * specularInt, 0, 0.95h) + ceil(specularExp), signZero(nM.z) * viewDepth); } /*************/ technique basic < string layer = "3DScene" ; > { pass p0 { VertexProgram = compile vp30 simpleVP(); FragmentProgram = compile fp40 simpleFP(); DepthTestEnable = true; DepthMask = true; BlendEnable = false; } } /***************************** eof ***/