string description = "SelfIlluminatingParticleRendering"; /************* UN-TWEAKABLES **************/ float4x4 vM < string UIWidget="None"; >; float4x4 pM < string UIWidget="None"; >; float4x4 vP; float3 colourTint; float3 camPos; float4 inverseParams; float3 inverseOffset; float3 inverseScale; // Note these default values are all ignored anyway by the PS3 float3 offsets[4] = { { -0.5f, -0.5f, 0.0f }, { -0.5f, 0.5f, 0.0f }, { 0.5f, 0.5f, 0.0f }, { 0.5f, -0.5f, 0.0f } }; /*********** Tweakables **********************/ float specularInt < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 5.0; float UIStep = 0.01; > = 0.6; float specularExp < string UIWidget = "slider"; float UIMin = 1.0; float UIMax = 128.0; float UIStep = 1.0; > = 48.0; ////// float reflectivity < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.01; > = 0.4; ////// float uvTileBase < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 5.0; float UIStep = 0.01; > = 1.0; float depthOffset < string UIWidget = "slider"; float UIMin = -5.0; float UIMax = 5.0; float UIStep = 0.01; > = 0.5; float depthScale < 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 dm < string ResourceType = "2D"; >; sampler2D baseDepthMap = sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; }; /************* INCLUDES *****************/ #include "..\\Basic_Utils.cgfx" #include "VFX_BasicDepth.cgfx" /************* DATA STRUCTS **************/ /* data from application vertex buffer */ struct appdata { float4 position : POSITION; float4 tangent : TEXCOORD0; float4 scale : TEXCOORD1; float4 texCoord : TEXCOORD2; }; /* data passed from vertex shader to pixel shader */ struct vertexOutput { float4 position : POSITION; float4 texCoord : TEXCOORD0; float4 colour : TEXCOORD1; float4 normal : TEXCOORD2; float2 screen : TEXCOORD3; float4 binormal : TEXCOORD4; }; /*********** vertex program ******/ vertexOutput simpleVP(appdata IN) { vertexOutput OUT = (vertexOutput)0; OUT.position = mul( vM, float4( IN.position.xyz, 1.f)); // Get the vertex's Index float indexf = IN.position.w / 10.0f; int index = round(indexf); // Get vertex's offsets half3 offset = offsets[index]; // Get the Opacity float opacity = IN.position.w - (index * 10.0f); // Get the Tangent (normalised in code) half3 tangent = IN.tangent.xyz; // Get the Scale half3 scale = IN.scale.xyz; // Get the Normal in view space OUT.normal.xyz = - mul(vM, float4(IN.position.xyz, 1.f)).xyz; OUT.normal.xyz = normalize(OUT.normal.xyz); // Get the binormal OUT.binormal.xyz = GetBiNormal(OUT.normal.xyz, tangent); OUT.binormal.w = scale.x; // Calculate the offsets offset *= scale; offset = ((OUT.binormal.xyz * offset.x) + (tangent.xyz * offset.y) + (OUT.normal.xyz * offset.z)); OUT.position.xyz += offset; OUT.position = mul(pM, OUT.position); OUT.texCoord.xy = IN.texCoord.xy; OUT.texCoord.z = opacity; OUT.colour.r = IN.tangent.w; OUT.colour.gb = IN.texCoord.zw; OUT.colour.rgb *= colourTint; // we never use blue anyway... OUT.screen.xy = OUT.position.zw; // pack the tangent OUT.texCoord.w = tangent.x; OUT.colour.w = tangent.y; OUT.normal.w = tangent.z; return OUT; } /********* fragment program ********/ void simpleFP(vertexOutput IN, out float4 colour : COLOR0, out float4 normal : COLOR1, out float depth : DEPTH) { // Get the pixel colour and bail if the alpha is too low colour = tex2D(baseColourMap, IN.texCoord.xy); if(colour.a <= 0.01f) discard; // Sample the luminance map float4 normalBlend = tex2D(baseNormalMap, IN.texCoord.xy); float depthValue = tex2D(baseDepthMap, IN.texCoord.xy).r; // get the blendmask half2 blendMask = normalBlend.xy; // get the normal half3 nM; nM.xy = normalBlend.zw; // unpack the tangent half3 tangent = half3(IN.texCoord.w, IN.colour.w, IN.normal.w); //generate normal and world normal nM.xy -= 0.5f.xx; nM.xy *= 2.f.xx; nM = DecodeNormal(nM.xy); // nM.xy += nM.xy * 0.25f; // exagerate normals // nM = normalize(nM); nM = normalize(nM.x * IN.binormal.xyz + nM.y * tangent.xyz + nM.z * IN.normal.xyz); // Calculate the depth depthValue = (depthValue - 0.5f) ; // put into range -0.5,0.5 depthValue -= depthOffset; // offset to origin of particle depthValue *= depthScale * IN.binormal.w; // scale to size of particle float viewDepth = inverseParams.w / ((IN.screen.x/IN.screen.y) + inverseParams.z); viewDepth += depthValue; depth = (inverseParams.w / viewDepth) - inverseParams.z; depth = ((depth)/inverseScale.z)-inverseOffset.z; depth = saturate(depth); colour = float4(colour.rgb * IN.colour.rgb, blendMask.g * reflectivity); normal = half4(nM.x, nM.y, clamp(blendMask.r * specularInt, 0, 0.95h) + ceil(specularExp), sign(IN.normal.z) * viewDepth); //colour.rgb = IN.binormal; } /*************/ technique basic < string layer = "3DScene" ; > { pass p0 { VertexProgram = compile arbvp1 simpleVP(); FragmentProgram = compile arbfp1 simpleFP(); DepthTestEnable = true; DepthMask = true; //BlendEnable = true; //BlendFuncSeparate = int4( SrcAlpha , OneMinusSrcAlpha , Zero , One ) ; CullFaceEnable = false; } pass shadowPass < string layer = "Shadow" ; string excludeData = "NoShadowCast" ; > { VertexProgram = compile vp20 VFX_BasicDepthVP(); FragmentProgram = compile fp20 VFX_BasicDepthFP(); DepthTestEnable = true; DepthMask = true; ColorMask = bool4( false , false , false , false ); BlendEnable = false; AlphaTest = false; CullFaceEnable = false; } } /***************************** eof ***/