[845] | 1 | struct VertexOut
|
---|
| 2 | {
|
---|
| 3 | float4 VertexPosition :POSITION;
|
---|
| 4 | float2 TexCoord :TEXCOORD;
|
---|
| 5 | float4 Position :TEXCOORD1;
|
---|
| 6 | float4 EyePosition :TEXCOORD2;
|
---|
| 7 | float2 BbSizeAngleCos :TEXCOORD3;
|
---|
| 8 | float4 LightSpacePos :TEXCOORD4;
|
---|
| 9 | float4 Color :COLOR0;
|
---|
| 10 | };
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | //
|
---|
| 14 | // Vertex program for displaying particle system with rectangle rendertexture
|
---|
| 15 | //
|
---|
| 16 | VertexOut VertexProgram( float4 Position :POSITION,
|
---|
| 17 | float4 Texcoord: TEXCOORD,
|
---|
| 18 | float4 Color:COLOR0,
|
---|
| 19 | uniform float4x4 LightModelViewProj,
|
---|
| 20 | uniform float3 LightPosition,
|
---|
| 21 | uniform float3 EyePosition,
|
---|
| 22 | uniform float4x4 ModelViewProj :state.matrix.mvp,
|
---|
| 23 | uniform float4x4 ModelViewMatrix:state.matrix.modelview
|
---|
| 24 | )
|
---|
| 25 | {
|
---|
| 26 | VertexOut Out;
|
---|
| 27 |
|
---|
| 28 | Out.Color=Color;
|
---|
| 29 |
|
---|
| 30 | Out.VertexPosition=mul(ModelViewProj, Position);
|
---|
| 31 | Out.TexCoord=Texcoord.xy;
|
---|
| 32 |
|
---|
| 33 | Out.LightSpacePos=mul(LightModelViewProj, Position);
|
---|
| 34 | Out.LightSpacePos.xyz=Out.LightSpacePos.xyz/Out.LightSpacePos.w;
|
---|
| 35 | Out.LightSpacePos.xyz=(Out.LightSpacePos.xyz+1)/2;
|
---|
| 36 |
|
---|
| 37 | Out.Position=Out.VertexPosition;
|
---|
| 38 | Out.BbSizeAngleCos.x=Texcoord.z;
|
---|
| 39 |
|
---|
| 40 | float3 LightToPoint=normalize(Position.xyz-LightPosition);
|
---|
| 41 | float3 PointToEye=normalize(EyePosition-Position.xyz);
|
---|
| 42 | Out.BbSizeAngleCos.y=dot(LightToPoint,PointToEye);
|
---|
| 43 |
|
---|
| 44 | Out.EyePosition=mul(ModelViewMatrix, Position);
|
---|
| 45 |
|
---|
| 46 | Out.Position.xyz=(Out.Position.xyz/Out.Position.w+1)/2;
|
---|
| 47 |
|
---|
| 48 | return Out;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | //
|
---|
| 52 | // Fragment program for displaying particle system with rectangle rendertexture
|
---|
| 53 | //
|
---|
| 54 | void FragmentProgram( VertexOut In,
|
---|
| 55 | uniform samplerRECT FrontTexture,
|
---|
| 56 | uniform samplerRECT ObjTexture,
|
---|
| 57 | uniform samplerRECT PhaseTexture,
|
---|
| 58 | uniform float Albedo,
|
---|
| 59 | uniform float Transparency,
|
---|
| 60 | uniform float Symmetry,
|
---|
| 61 | uniform float3 LightColor,
|
---|
| 62 | uniform float4x4 ProjMatrixInv:state.matrix.projection.inverse,
|
---|
| 63 | uniform float4x4 ProjMatrix:state.matrix.projection,
|
---|
| 64 | float4 out Color:COLOR
|
---|
| 65 | )
|
---|
| 66 | {
|
---|
| 67 |
|
---|
| 68 | float objdepth=texRECT(ObjTexture,In.Position.xy*512).r;
|
---|
| 69 |
|
---|
| 70 | float2 depths=float2(texRECT(FrontTexture,In.TexCoord*256).r,1-texRECT(FrontTexture,In.TexCoord*256).g);
|
---|
| 71 | float density=1;
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | if(depths.x==1)
|
---|
| 75 | {
|
---|
| 76 | Color=float4(0,0,0,1);
|
---|
| 77 | }
|
---|
| 78 | else
|
---|
| 79 | {
|
---|
| 80 |
|
---|
| 81 | depths=In.EyePosition.zz+In.BbSizeAngleCos.x*(0.5-depths);
|
---|
| 82 |
|
---|
| 83 | float size=0.5*In.BbSizeAngleCos.x;
|
---|
| 84 | float frontdepth=-In.EyePosition.z-size+texRECT(FrontTexture,In.TexCoord*256).r*size;
|
---|
| 85 | float backdepth=-In.EyePosition.z-size+(1-texRECT(FrontTexture,In.TexCoord*256).g)*size;
|
---|
| 86 |
|
---|
| 87 | float d=backdepth-frontdepth;
|
---|
| 88 | float o=-objdepth-frontdepth;
|
---|
| 89 |
|
---|
| 90 | density*=texRECT(FrontTexture,In.TexCoord*256).a;//density
|
---|
| 91 | density*=saturate(o/d);
|
---|
| 92 |
|
---|
| 93 | float phase=texRECT(PhaseTexture,float2(Symmetry,In.BbSizeAngleCos.y)*256);
|
---|
| 94 | float realdens=density*Transparency;
|
---|
| 95 | float outcol=realdens*phase*Albedo;
|
---|
| 96 |
|
---|
| 97 | Color=float4(LightColor*outcol*In.Color.rgb,1-realdens);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | }
|
---|
| 101 |
|
---|