string description = "Basic Material Static"; /************* UN-TWEAKABLES **************/ float4x4 wVP : WorldViewProjection < string UIWidget="None"; >; float4x4 ivM; float4x4 wM : World < string UIWidget="None"; >; float4x4 ipM; float2 planeDepths; #include "y:\\art\\shaders\\Basic_Utils.cgfx" /*********** Tweakables **********************/ float3 lightColour : Ambient < string UIWidget = "Color"; > = {0.42f, 0.42f, 0.42f}; /************* Textures ******************/ texture cm : Diffuse < string ResourceType = "2D"; >; sampler2D colourTexture = sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; }; texture nm : Normal < string ResourceType = "2D"; >; sampler2D normalTexture = sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; }; texture dm : Diffuse < string ResourceType = "2D"; >; sampler2D depthTexture = 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; }; texture diffEnvMap : Environment < string ResourceType = "Cube"; >; samplerCUBE diffCubeMap = 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; }; /* data passed from vertex shader to pixel shader */ struct vertexOutput { float4 oPosition : POSITION; half2 oTexCoord : TEXCOORD0; half3 oViewPos : TEXCOORD1; }; /*********** vertex program ******/ vertexOutput simpleVP(appdata IN) { vertexOutput OUT = (vertexOutput)0; OUT.oPosition = float4((IN.position.xy - 0.5f) * 2.f, 0.f, 1.f); OUT.oTexCoord = IN.position.xy; half4 viewPos = mul(ipM, OUT.oPosition); viewPos /= viewPos.w; OUT.oViewPos = viewPos.xyz; OUT.oViewPos = mul(ivM, half4(OUT.oViewPos, 0.h)).xyz; return OUT; } /********* fragment program ********/ void simpleFP(vertexOutput IN, out half4 colour : COLOR0) { half4 nm = tex2D(normalTexture, IN.oTexCoord); half3 normal = DecodeNormal(nm.xy); normal.z *= (sign(nm.a) * -1.0h); // If you want to use nm.a then uncomment below //nm.a = abs(nm.a); //nm.a *= -1.0h; half3 view = normalize(IN.oViewPos); half4 cm = tex2D(colourTexture, IN.oTexCoord); half3 texColour = cm.rgb; half reflectMask = cm.a; half specularExp; half specularInt = modf(nm.b, specularExp); normal = mul(ivM, half4(normal, 0.h)).xyz; half3 reflection = normalize(reflect(view, normal)); // reflection = mul(ivM, half4(reflection, 0.h)).xyz; 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(normal.xyz, 6.f)); diffEnvMap.rgb += diffEnvMap.rgb * diffEnvMap.a; colour.rgb = texColour * lightColour * diffEnvMap.rgb; colour.rgb = colour.rgb + (envMap * specularInt * lightColour); colour.a = 1.h; // Encode to RGBdiv8 colour = colour/max(max(colour.r, colour.g), max(colour.b, 1.1h)); } /*************/ technique basic { pass p0 { VertexProgram = compile vp30 simpleVP(); FragmentProgram = compile fp40 simpleFP(); DepthTestEnable = false; DepthMask = false; BlendEnable = false; } } /***************************** eof ***/