1 | #define D 128
|
---|
2 |
|
---|
3 | struct VertexOut
|
---|
4 | {
|
---|
5 | float4 VertexPosition :POSITION;
|
---|
6 | float2 TexCoord :TEXCOORD;
|
---|
7 | int ID :TEXCOORD1;
|
---|
8 | };
|
---|
9 |
|
---|
10 |
|
---|
11 | /*
|
---|
12 | Vertex program for cloud rendering
|
---|
13 | */
|
---|
14 | VertexOut VertexProgram( float4 Position :POSITION,
|
---|
15 | float2 Texcoord: TEXCOORD
|
---|
16 | )
|
---|
17 | {
|
---|
18 | VertexOut Out;
|
---|
19 |
|
---|
20 | Out.VertexPosition=Position;
|
---|
21 | Out.TexCoord=Texcoord;
|
---|
22 | Out.ID=Texcoord.x;
|
---|
23 |
|
---|
24 | return Out;
|
---|
25 | }
|
---|
26 |
|
---|
27 | /*
|
---|
28 | Fragment program for cloud rendering
|
---|
29 | */
|
---|
30 | float3 FragmentProgram( VertexOut In,
|
---|
31 | uniform samplerRECT LVisMap,
|
---|
32 | uniform samplerRECT Phase,
|
---|
33 | uniform float4 LightDirsWeights,
|
---|
34 | uniform float3 LightRad,
|
---|
35 | uniform float3 LightRad2,
|
---|
36 | uniform float2 Alb_Op):COLOR
|
---|
37 | {
|
---|
38 | float3 Color=float3(0,0,0);
|
---|
39 |
|
---|
40 | int direction=floor(In.TexCoord.y);
|
---|
41 | int negDir=D-1-direction;
|
---|
42 | int particle=In.ID;
|
---|
43 |
|
---|
44 | float a_o=Alb_Op.x*Alb_Op.y;
|
---|
45 |
|
---|
46 | //Light1
|
---|
47 | int LDir=floor(LightDirsWeights.x);
|
---|
48 | float isvisible=texRECT(LVisMap,float2(particle,0)).r;
|
---|
49 |
|
---|
50 | //Scattering
|
---|
51 | Color+=isvisible*a_o*texRECT(Phase,float2(LDir,negDir)).r*LightRad;
|
---|
52 | //Transmittance
|
---|
53 | if(direction==LDir)
|
---|
54 | {
|
---|
55 | //Color+=LightRad*(1-Alb_Op.y)*isvisible;
|
---|
56 | Color+=LightRad*isvisible;
|
---|
57 | }
|
---|
58 |
|
---|
59 | //Light2
|
---|
60 | int LDir2=floor(LightDirsWeights.y);
|
---|
61 |
|
---|
62 | isvisible=texRECT(LVisMap,float2(particle,1)).r;
|
---|
63 | //isvisible=1;
|
---|
64 |
|
---|
65 | //Scattering
|
---|
66 | Color+=isvisible*a_o*texRECT(Phase,float2(LDir2,negDir)).r*LightRad2;
|
---|
67 | //Transmittance
|
---|
68 | if(direction==LDir2)
|
---|
69 | {
|
---|
70 | //Color+=LightRad2*(1-Alb_Op.y)*isvisible;
|
---|
71 | Color+=LightRad2*isvisible;
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | ///Emission
|
---|
76 | //Color+=float3(0.01,0.01,0.01);
|
---|
77 |
|
---|
78 | return Color;
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|