string description = "SelfIlluminatingParticleRendering"; /************* UN-TWEAKABLES **************/ float4x4 vM < string UIWidget="None"; >; float4x4 pM < string UIWidget="None"; >; float4x4 vP; float3 colourTint; float3 camPos; #include "VFX_Utils.cgfx" /*********** Tweakables **********************/ /************* Textures ******************/ texture cm : Diffuse < string ResourceType = "2D"; >; sampler2D baseColourMap = sampler_state { Texture = ; MinFilter = LinearMipMapLinear; MagFilter = Linear; }; /************* DATA STRUCTS **************/ /* data from application vertex buffer */ struct appdata { float4 position : POSITION; float4 offset : TEXCOORD0; float4 texCoord : TEXCOORD1; }; /* data passed from vertex shader to pixel shader */ struct vertexOutput { float4 position : POSITION; float opacity : TEXCOORD0; float2 texCoord : TEXCOORD1; float3 Colour : TEXCOORD2; }; /*********** vertex program ******/ vertexOutput simpleVP(appdata IN) { vertexOutput OUT = (vertexOutput)0; // Lock to this axis float3 up = float3(0.0f, 1.0f, 0.0f); up.x = IN.offset.w; up.y = IN.texCoord.z; up.z = IN.texCoord.w; up = normalize(up); // Get the view direction from the camera float3 forward = camPos.xyz - IN.position.xyz; forward = forward - up; forward = normalize(forward); // Calculate the right vector float3 right = cross(forward, up); right = normalize(right); // Recalculate the forward vector forward = cross(up, right); forward = normalize(forward); // Generate a rotation matrix from these 3 vectors float3x3 rotMat; rotMat[0].x = right.x; rotMat[0].y = up.x; rotMat[0].z = forward.x; rotMat[1].x = right.y; rotMat[1].y = up.y; rotMat[1].z = forward.y; rotMat[2].x = right.z; rotMat[2].y = up.z; rotMat[2].z = forward.z; // Rotate the offset float3 offsets = mul(rotMat, IN.offset.xyz); // Add the offset to the position float3 pos = IN.position.xyz + offsets; // Get the vertex's Index int index = GetIndex(IN.position.w); // Get the Opacity float opacity = GetOpacity(IN.position.w, index); // Perform view and projection transformations OUT.position = mul(vM, float4(pos, 1.0f)); OUT.position = mul(pM, OUT.position); OUT.opacity = opacity; OUT.texCoord = IN.texCoord.xy; return OUT; } /********* fragment program ********/ float4 simpleFP(vertexOutput IN) : COLOR { float4 colour = tex2D(baseColourMap, IN.texCoord); colour.rgb *= colourTint; colour.a *= IN.opacity; colour.rgb *= colour.a; return colour; } /*************/ technique basic < string layer = "PostFog" ; > { pass p0 { VertexProgram = compile arbvp1 simpleVP(); FragmentProgram = compile arbfp1 simpleFP(); DepthTestEnable = true; DepthMask = false; BlendEnable = true; BlendFuncSeparate = int4( DstAlpha , OneMinusSrcAlpha , Zero , One ) ; CullFaceEnable = false; } } /***************************** eof ***/