source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/OgreGames/MoriaBattle/Media/MORIA/MoriaDust.hlsl @ 3255

Revision 3255, 2.7 KB checked in by szirmay, 15 years ago (diff)
Line 
1struct SBB_VS_OUT
2{
3        float4 hPosition        : POSITION;
4        float4 texCoord         : TEXCOORD0;
5        float3 P                : TEXCOORD1;
6        float3 Q                : TEXCOORD2;
7        float r                 : TEXCOORD3;
8        float2 screenCoord      : TEXCOORD4;   
9        float4 color            : COLOR0;
10};
11
12SBB_VS_OUT MoriaDust_VS (float4 position : POSITION,   
13                float4 texCoord : TEXCOORD0,
14                float4 color    : COLOR,
15                uniform float width,
16                uniform float height,
17                uniform float4x4 worldView,
18                uniform float4x4 Proj)
19{
20        SBB_VS_OUT OUT;
21 ///transform to camera space and create a sprite with vertex offset
22        float2 offset = texCoord.zw;
23        float4 cPosition;   
24        float4 wPosition = position;   
25        cPosition = mul(worldView, wPosition);
26/// P is the particle sphere center     
27        OUT.P = cPosition.xyz;
28        OUT.P.z = - 1 * OUT.P.z;
29        cPosition.xy += offset;
30/// Q is the shaded point (it is moved backwards to avoid unwanted frontplane clipping)                         
31        OUT.Q = cPosition.xyz; 
32        OUT.Q.z = OUT.P.z;
33        OUT.r = abs(texCoord.z);   
34/// calculate screen space position
35   OUT.hPosition = mul( Proj, cPosition );
36   OUT.screenCoord =  (OUT.hPosition.xy / OUT.hPosition.w + 1.0) / 2.0;
37   OUT.screenCoord.y = 1.0 - OUT.screenCoord.y;
38   OUT.screenCoord += float2(0.5/width, 0.5/height);   
39   
40   OUT.texCoord = texCoord;
41   OUT.color = color;
42
43  return OUT;
44}
45
46
47float4 MoriaDust_PS(SBB_VS_OUT IN ,
48        //      in screenCoord : VPOS,
49            uniform float nearplane,
50            uniform float farplane,
51            uniform float4 lightCPos,
52            uniform float lightPower,
53        uniform float4 color,
54        uniform float symmetry,
55            uniform sampler2D colorTexture : register(s0),
56            uniform sampler2D DepthMap : register(s1),
57            uniform sampler2D PhaseMap : register(s2)
58           ) : COLOR
59{
60        float4 Color = IN.color * color;
61        float alpha = 0;
62       
63/// get the depth values from the depthMap and calculate ray length in sphere   
64        float d = length( IN.Q - IN.P );
65        float Zs;
66        if( d < IN.r )
67        {
68         
69         float w = sqrt( IN.r * IN.r - d * d );
70         alpha = w / IN.r;
71         alpha *= pow( (IN.r-d) / IN.r , 2);
72       
73         float F = IN.Q.z - w;
74         float B = IN.Q.z + w;
75         
76
77         Zs = tex2D( DepthMap, IN.screenCoord ).r;
78         if(Zs == 0) Zs = farplane;
79         float ds = min( Zs, B ) - max( nearplane, F ); 
80        // float ds = min( Zs, B ) - F; 
81         alpha *=  ds / w * 0.5;
82        }
83/// fetch opacity from a texture
84        Color.a *= tex2D( colorTexture, IN.texCoord.xy).r;
85        Color.a *= alpha;
86       
87        //illumination
88        lightCPos.z *= -1;
89        float2 L = lightCPos.xy - IN.Q.xy;
90        float ld = length(L);
91        L = L / ld;
92        float3 V = normalize(-IN.Q);
93        float phase;// = /*lightPower / (ld*ld) * */tex2D(PhaseMap, float2(symmetry, dot(L,V)) * 0.5 + 0.5).r;
94//      float phase = (dot(L, V) + 1.0) * 0.5;
95
96        float ld2 = max(0.01, ld * ld);
97        phase = lightPower / ld2;
98        //Color.rgb *= phase;
99        return Color;
100}
Note: See TracBrowser for help on using the repository browser.