[852] | 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 ModelViewProj :state.matrix.mvp,
|
---|
| 20 | uniform float4x4 ModelViewMatrix:state.matrix.modelview
|
---|
| 21 | )
|
---|
| 22 | {
|
---|
| 23 | VertexOut Out;
|
---|
| 24 |
|
---|
| 25 | Out.Color=Color;
|
---|
| 26 |
|
---|
| 27 | Out.VertexPosition=mul(ModelViewProj, Position);
|
---|
| 28 | Out.TexCoord=Texcoord.xy;
|
---|
| 29 |
|
---|
| 30 | Out.Position=Out.VertexPosition;
|
---|
| 31 | Out.BbSizeAngleCos.x=Texcoord.z;
|
---|
| 32 |
|
---|
| 33 | Out.EyePosition=mul(ModelViewMatrix, Position);
|
---|
| 34 |
|
---|
| 35 | Out.Position.xyz=(Out.Position.xyz/Out.Position.w+1)/2;
|
---|
| 36 |
|
---|
| 37 | return Out;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | //
|
---|
| 41 | // Fragment program for displaying particle system with rectangle rendertexture
|
---|
| 42 | //
|
---|
| 43 | void FragmentProgram( VertexOut In,
|
---|
| 44 | uniform samplerRECT FrontTexture,
|
---|
| 45 | uniform samplerRECT ObjTexture,
|
---|
| 46 | uniform float Transparency,
|
---|
| 47 | uniform float3 LightColor,
|
---|
| 48 | float4 out Color:COLOR
|
---|
| 49 | )
|
---|
| 50 | {
|
---|
| 51 |
|
---|
| 52 | float objdepth=texRECT(ObjTexture,In.Position.xy*512).r;
|
---|
| 53 |
|
---|
| 54 | In.TexCoord*=256;
|
---|
| 55 |
|
---|
| 56 | float depth=texRECT(FrontTexture,In.TexCoord).r;
|
---|
| 57 | float density=1;
|
---|
| 58 |
|
---|
| 59 | if(depth.x==1)
|
---|
| 60 | {
|
---|
| 61 | Color=float4(0,0,0,1);
|
---|
| 62 | }
|
---|
| 63 | else
|
---|
| 64 | {
|
---|
| 65 | float size=0.5*In.BbSizeAngleCos.x;
|
---|
| 66 | float frontdepth=-In.EyePosition.z-size+texRECT(FrontTexture,In.TexCoord).r*size;
|
---|
| 67 | float backdepth=-In.EyePosition.z-size+(1-texRECT(FrontTexture,In.TexCoord).g)*size;
|
---|
| 68 |
|
---|
| 69 | float d=backdepth-frontdepth;
|
---|
| 70 | float o=-objdepth-frontdepth;
|
---|
| 71 |
|
---|
| 72 | density*=texRECT(FrontTexture,In.TexCoord).a;//density
|
---|
| 73 | density*=saturate(o/d);
|
---|
| 74 |
|
---|
| 75 | float realdens=density*Transparency;
|
---|
| 76 |
|
---|
| 77 | Color=float4(LightColor*realdens*In.Color.rgb,1-realdens);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | }
|
---|
| 81 |
|
---|