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