string description = "Basic Material Static"; /************* UN-TWEAKABLES **************/ float4x4 wM; float4x4 vM; float4x4 pM; float3 materialIndex; #include "y:\\art\\shaders\\Basic_Utils.cgfx" /*********** 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; ////// float uvTileBase < 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; }; /************* 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 position : POSITION; half2 texCoord : TEXCOORD0; half3 normal : TEXCOORD1; half3 tangent : TEXCOORD2; half3 binormal : TEXCOORD3; float4 colour : COLOR0; }; /*********** vertex program ******/ vertexOutput simpleVP(appdata IN) { vertexOutput OUT = (vertexOutput)0; OUT.colour = IN.colour; OUT.texCoord.xy = IN.texCoord0 * uvTileBase; //compute matrices float4x4 wvM = mul(vM, wM); float4x4 wVP = mul(pM, wvM); //postion and depth OUT.position = mul(wVP, float4(IN.position.xyz, 1.f)); // BM: Transform normal and tangent into object space, calculate biNormal OUT.normal = mul(wvM, float4(IN.normal, 0.f)); OUT.tangent = mul(wvM, float4(IN.tangent, 0.f)); OUT.binormal = GetBiNormal(OUT.tangent, OUT.normal); return OUT; } /********* fragment program ********/ void simpleFP(vertexOutput IN, out float4 colour : COLOR0, out float4 normal : COLOR1 ) { //final colour, textures and composite lighting contributions half3 texColour = tex2D(baseColourMap, IN.texCoord.xy).xyz; half4 normalBlend = tex2D(baseBlendMap, IN.texCoord.xy); half2 blendMask = normalBlend.xy; half3 nM; nM.xy = normalBlend.zw; //generate normal and world normal nM.xy -= 0.5f.xx; nM.xy *= 2.f.xx; nM = DecodeNormal(nM.xy); nM = normalize(nM.x * IN.tangent + nM.y * IN.binormal + nM.z*IN.normal); // float3 factor = float3(16777215.f/65536.f, 16777215.f/256.f, 16777215.f/1.f ); // float3 material = dot(round( abs(materialIndex.xxx) * 255.0f.xxx ), factor.xyz); colour = half4(half3(materialIndex), blendMask.g * reflectivity); normal = half4(nM.x, nM.y, blendMask.r * specularInt, specularExp); } /*************/ technique basic { pass p0 { VertexProgram = compile vp30 simpleVP(); FragmentProgram = compile fp40 simpleFP(); DepthTestEnable = true; DepthMask = true; BlendEnable = false; } } /***************************** eof ***/