[852] | 1 | struct VertexOut
|
---|
| 2 | {
|
---|
| 3 | float4 VertexPosition :POSITION;
|
---|
| 4 | float2 TexCoord :TEXCOORD;
|
---|
| 5 | };
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | Vertex program for cloud rendering
|
---|
| 10 | */
|
---|
| 11 | VertexOut VertexProgram( float4 Position :POSITION,
|
---|
| 12 | float2 Texcoord: TEXCOORD
|
---|
| 13 | )
|
---|
| 14 | {
|
---|
| 15 | VertexOut Out;
|
---|
| 16 |
|
---|
| 17 | Out.VertexPosition=Position;
|
---|
| 18 | Out.TexCoord=Texcoord;
|
---|
| 19 |
|
---|
| 20 | return Out;
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | Fragment program for cloud rendering
|
---|
| 25 | */
|
---|
| 26 | float4 FragmentProgram( VertexOut In,
|
---|
| 27 | uniform float Albedo,
|
---|
| 28 | uniform float Transparency,
|
---|
| 29 | uniform float Symmetry,
|
---|
| 30 | uniform samplerRECT IllumTexture,
|
---|
| 31 | uniform samplerRECT PhaseTexture,
|
---|
| 32 | uniform samplerRECT AngleTexture):COLOR
|
---|
| 33 | {
|
---|
| 34 | In.TexCoord.y=1-In.TexCoord.y;
|
---|
| 35 | float uvsize=256;
|
---|
| 36 | float4 Color=texRECT(IllumTexture,In.TexCoord*uvsize);
|
---|
| 37 |
|
---|
| 38 | if(Color.a!=1)
|
---|
| 39 | {
|
---|
| 40 |
|
---|
| 41 | //3 random uv's
|
---|
| 42 | float transparency=Transparency;
|
---|
| 43 | float albedo=Albedo;
|
---|
| 44 | float t=0.3;
|
---|
| 45 | float g=Symmetry;
|
---|
| 46 |
|
---|
| 47 | float2 Rand1=(float2(noise(float3(In.TexCoord,t)),noise(float3(In.TexCoord.x,t,In.TexCoord.y))))*10;
|
---|
| 48 | float2 Rand2=(float2(noise(float3(In.TexCoord.yx,t)),noise(float3(In.TexCoord.y,t,In.TexCoord.x))))*10;
|
---|
| 49 | float2 Rand3=(float2(noise(float3(t,In.TexCoord)),noise(float3(t,In.TexCoord.yx))))*10;
|
---|
| 50 |
|
---|
| 51 | float3 dist;
|
---|
| 52 | float3 Cosangles;
|
---|
| 53 | float3 PhasesFront;
|
---|
| 54 | float3 PhasesBack;
|
---|
| 55 | float3 Scattering;
|
---|
| 56 |
|
---|
| 57 | float3 RedSamples;
|
---|
| 58 | float3 GreenSamples;
|
---|
| 59 | float3 BlueSamples;
|
---|
| 60 | float3 AlphaSamples;
|
---|
| 61 |
|
---|
| 62 | /*
|
---|
| 63 | float2 point1=saturate(In.TexCoord+Rand1)*uvsize;
|
---|
| 64 | float2 point2=saturate(In.TexCoord+Rand2)*uvsize;
|
---|
| 65 | float2 point3=saturate(In.TexCoord+Rand3)*uvsize;
|
---|
| 66 |
|
---|
| 67 | RedSamples=float3(texRECT(IllumTexture,point1).r,texRECT(IllumTexture,point2).r,texRECT(IllumTexture,point3).r);
|
---|
| 68 | GreenSamples=float3(texRECT(IllumTexture,point1).g,texRECT(IllumTexture,point2).g,texRECT(IllumTexture,point3).g);
|
---|
| 69 | BlueSamples=float3(texRECT(IllumTexture,point1).b,texRECT(IllumTexture,point2).b,texRECT(IllumTexture,point3).b);
|
---|
| 70 | AlphaSamples=float3(texRECT(IllumTexture,point1).a,texRECT(IllumTexture,point2).a,texRECT(IllumTexture,point3).a);
|
---|
| 71 | */
|
---|
| 72 |
|
---|
| 73 | In.TexCoord*=uvsize;
|
---|
| 74 |
|
---|
| 75 | RedSamples=float3(texRECT(IllumTexture,In.TexCoord+Rand1).r,texRECT(IllumTexture,In.TexCoord+Rand2).r,texRECT(IllumTexture,In.TexCoord+Rand3).r);
|
---|
| 76 | GreenSamples=float3(texRECT(IllumTexture,In.TexCoord+Rand1).g,texRECT(IllumTexture,In.TexCoord+Rand2).g,texRECT(IllumTexture,In.TexCoord+Rand3).g);
|
---|
| 77 | BlueSamples=float3(texRECT(IllumTexture,In.TexCoord+Rand1).b,texRECT(IllumTexture,In.TexCoord+Rand2).b,texRECT(IllumTexture,In.TexCoord+Rand3).b);
|
---|
| 78 | AlphaSamples=float3(texRECT(IllumTexture,In.TexCoord+Rand1).a,texRECT(IllumTexture,In.TexCoord+Rand2).a,texRECT(IllumTexture,In.TexCoord+Rand3).a);
|
---|
| 79 |
|
---|
| 80 | /*
|
---|
| 81 | //background
|
---|
| 82 | if(RedSamples.x==1)RedSamples.x=0;
|
---|
| 83 | if(RedSamples.y==1)RedSamples.y=0;
|
---|
| 84 | if(RedSamples.z==1)RedSamples.z=0;
|
---|
| 85 | if(GreenSamples.x==1)GreenSamples.x=0;
|
---|
| 86 | if(GreenSamples.y==1)GreenSamples.y=0;
|
---|
| 87 | if(GreenSamples.z==1)GreenSamples.z=0;
|
---|
| 88 | if(BlueSamples.x==1)BlueSamples.x=0;
|
---|
| 89 | if(BlueSamples.y==1)BlueSamples.y=0;
|
---|
| 90 | if(BlueSamples.z==1)BlueSamples.z=0;
|
---|
| 91 | */
|
---|
| 92 |
|
---|
| 93 | dist=float3(length(Rand1),length(Rand2),length(Rand3));
|
---|
| 94 |
|
---|
| 95 | Cosangles=float3(texRECT(AngleTexture,float2(dist.x,0.25)).r,
|
---|
| 96 | texRECT(AngleTexture,float2(dist.y,0.25)).r,
|
---|
| 97 | texRECT(AngleTexture,float2(dist.z,0.25)).r)/2;
|
---|
| 98 |
|
---|
| 99 | PhasesFront=float3(texRECT(PhaseTexture,float2(g,0.5+Cosangles.x)*256).r,
|
---|
| 100 | texRECT(PhaseTexture,float2(g,0.5+Cosangles.y)*256).r,
|
---|
| 101 | texRECT(PhaseTexture,float2(g,0.5+Cosangles.z)*256).r);
|
---|
| 102 | PhasesBack=float3(texRECT(PhaseTexture,float2(g,0.5-Cosangles.x)*256).r,
|
---|
| 103 | texRECT(PhaseTexture,float2(g,0.5-Cosangles.y)*256).r,
|
---|
| 104 | texRECT(PhaseTexture,float2(g,0.5-Cosangles.z)*256).r);
|
---|
| 105 |
|
---|
| 106 | PhasesFront*=transparency*albedo/12.5;
|
---|
| 107 | PhasesBack*=transparency*albedo/12.5;
|
---|
| 108 |
|
---|
| 109 | //Red Channel
|
---|
| 110 | //Scattering=Color.g*PhasesBack;
|
---|
| 111 | Scattering=GreenSamples*PhasesBack;
|
---|
| 112 | Color.r+=Scattering.x+Scattering.y+Scattering.z;
|
---|
| 113 |
|
---|
| 114 | //Green Channel
|
---|
| 115 | //Scattering=Color.b*PhasesBack+Color.r*PhasesFront;
|
---|
| 116 | Scattering=RedSamples*PhasesFront+BlueSamples*PhasesBack;
|
---|
| 117 | Color.g+=Scattering.x+Scattering.y+Scattering.z;
|
---|
| 118 |
|
---|
| 119 | //Blue Channel
|
---|
| 120 | //Scattering=Color.a*PhasesBack+Color.g*PhasesFront;
|
---|
| 121 | Scattering=GreenSamples*PhasesFront+AlphaSamples*PhasesBack;
|
---|
| 122 | Color.b+=Scattering.x+Scattering.y+Scattering.z;
|
---|
| 123 |
|
---|
| 124 | //Alpha Channel
|
---|
| 125 | //Scattering=Color.b*PhasesFront;
|
---|
| 126 | Scattering=BlueSamples*PhasesFront;
|
---|
| 127 | Color.a+=Scattering.x+Scattering.y+Scattering.z;
|
---|
| 128 |
|
---|
| 129 | }
|
---|
| 130 | else
|
---|
| 131 | {
|
---|
| 132 | Color=float4(1,1,1,1);
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | return Color;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 |
|
---|