struct VertexOut { float4 VertexPosition :POSITION; float2 TexCoord :TEXCOORD; float4 Position :TEXCOORD1; float4 EyePosition :TEXCOORD2; float2 BbSizeAngleCos :TEXCOORD3; float4 LightSpacePos :TEXCOORD4; float4 Color :COLOR0; }; // // Vertex program for displaying particle system with rectangle rendertexture // VertexOut VertexProgram( float4 Position :POSITION, float4 Texcoord: TEXCOORD, float4 Color:COLOR0, uniform float4x4 LightModelViewProj, uniform float3 LightPosition, uniform float3 EyePosition, uniform float4x4 ModelViewProj :state.matrix.mvp, uniform float4x4 ModelViewMatrix:state.matrix.modelview ) { VertexOut Out; Out.Color=Color; Out.VertexPosition=mul(ModelViewProj, Position); Out.TexCoord=Texcoord.xy; Out.LightSpacePos=mul(LightModelViewProj, Position); Out.LightSpacePos.xyz=Out.LightSpacePos.xyz/Out.LightSpacePos.w; Out.LightSpacePos.xyz=(Out.LightSpacePos.xyz+1)/2; Out.Position=Out.VertexPosition; Out.BbSizeAngleCos.x=Texcoord.z; float3 LightToPoint=normalize(Position.xyz-LightPosition); float3 PointToEye=normalize(EyePosition-Position.xyz); Out.BbSizeAngleCos.y=dot(LightToPoint,PointToEye); Out.EyePosition=mul(ModelViewMatrix, Position); Out.Position.xyz=(Out.Position.xyz/Out.Position.w+1)/2; return Out; } // // Fragment program for displaying particle system with rectangle rendertexture // void FragmentProgram( VertexOut In, uniform samplerRECT FrontTexture, uniform samplerRECT ObjTexture, uniform samplerRECT PhaseTexture, uniform float Albedo, uniform float Transparency, uniform float Symmetry, uniform float3 LightColor, uniform float4x4 ProjMatrixInv:state.matrix.projection.inverse, uniform float4x4 ProjMatrix:state.matrix.projection, float4 out Color:COLOR ) { float objdepth=texRECT(ObjTexture,In.Position.xy*512).r; float2 depths=float2(texRECT(FrontTexture,In.TexCoord*256).r,1-texRECT(FrontTexture,In.TexCoord*256).g); float density=1; if(depths.x==1) { Color=float4(0,0,0,1); } else { depths=In.EyePosition.zz+In.BbSizeAngleCos.x*(0.5-depths); float size=0.5*In.BbSizeAngleCos.x; float frontdepth=-In.EyePosition.z-size+texRECT(FrontTexture,In.TexCoord*256).r*size; float backdepth=-In.EyePosition.z-size+(1-texRECT(FrontTexture,In.TexCoord*256).g)*size; float d=backdepth-frontdepth; float o=-objdepth-frontdepth; density*=texRECT(FrontTexture,In.TexCoord*256).a;//density density*=saturate(o/d); float phase=texRECT(PhaseTexture,float2(Symmetry,In.BbSizeAngleCos.y)*256); float realdens=density*Transparency; float outcol=realdens*phase*Albedo; Color=float4(LightColor*outcol*In.Color.rgb,1-realdens); } }