source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/OgreGames/SpaceStation/Media/Station/Station_HPS.hlsl @ 3255

Revision 3255, 2.8 KB checked in by szirmay, 15 years ago (diff)
Line 
1//////////////
2///This shader renders a HPS with depth calculation and with shading (light extintion).
3///The pixel shader identifies the two layers of the illumination volume between wich the shaded point is,
4/// and interpolates the stored extintion values.
5/////////////
6struct VS_OUT_DEPTH_ILLUM
7{
8        float4 hPosition        : POSITION;
9        float4 cPosition        : TEXCOORD1;
10        float2 texCoord         : TEXCOORD0;
11        float r                         : TEXCOORD2;   
12        float4 center           : TEXCOORD3;
13        float4 Color            : TEXCOORD4;   
14        float2 screenCoord      : TEXCOORD5;
15        float4 lightCoord       : TEXCOORD6;
16};
17
18
19float4 HPS_Large_Depth_Illum_PS(VS_OUT_DEPTH_ILLUM IN,
20                                                uniform float nearplane,
21                                                uniform sampler2D Texture  : register(s0),
22                                                uniform sampler2D depthTexture : register(s1),
23                                                uniform sampler2D illumVolume : register(s2)                   
24                                                        ) : COLOR
25{
26        float4 Color = 0;
27        float4 impostor = tex2D(Texture, IN.texCoord);
28        float f = 1.0 - impostor.g;
29        float b = impostor.r;
30        float alpha = 0;
31       
32        if(b == 0)
33                discard;       
34////altering opacity according to scene depth
35        float sceneDepth = tex2D(depthTexture, IN.screenCoord).r;
36        if(sceneDepth == 0)
37        {
38                discard;//alpha = impostor.a;
39        }
40        else
41        {       
42                float size = 2.0 * IN.r;
43                float frontDepth = IN.cPosition.z + size * (f - 0.5);
44                float backDepth = IN.cPosition.z +  size * (b - 0.5);
45                float B = min(sceneDepth, backDepth);
46                float F = max(frontDepth, 0.01);
47                float ds = B - F;
48                alpha = ds / (backDepth - frontDepth);
49                alpha =saturate(alpha) * impostor.a;
50        }
51        if(alpha == 0)
52                discard;
53///identify light volume slices and interpolation       
54        float2 lightCoord;
55        lightCoord = (IN.lightCoord.xy + float2(1.0, 1.0)) / 2.0;
56        lightCoord.y = 1.0 - lightCoord.y;
57        float z = IN.lightCoord.z / IN.lightCoord.w;
58               
59        float4 extintion = tex2D(illumVolume, lightCoord);
60       
61                float intensities[5];
62                intensities[0] = 1.0;
63                intensities[1] = extintion.r;
64                intensities[2] = extintion.g;
65                intensities[3] = extintion.b;
66                intensities[4] = extintion.a;
67                       
68                float3 start;
69                float3 end;
70                float3 temp = 1.0;
71                float t;
72               
73                float4 planes = float4(0.33, 0.5, 0.66, 1);
74                if(z < planes.x)
75                {
76                        start = intensities[0];
77                        end = intensities[1];
78                        t = z / planes.x;
79                        temp = lerp(start, end, t);                             
80                }
81                if(z > planes.x && z < planes.y)
82                {
83                        start = intensities[1];
84                        end = intensities[2];
85                        t = (z - planes.x) / (planes.y - planes.x);
86                        temp = lerp(start, end, t);                                     
87                }
88                if(z > planes.y && z < planes.z)
89                {
90                        start = intensities[2];
91                        end = intensities[3];
92                        t = (z - planes.y) / (planes.z - planes.y);
93                        temp = lerp(start, end, t);                             
94                }
95                if(z > planes.z)
96                {
97                        start = intensities[3];
98                        end = intensities[4];
99                        t = (z - planes.z) / (planes.a - planes.z);
100                        temp = lerp(start, end, t);                                     
101                }
102                IN.Color.rgb *= temp;
103///final color 
104 
105        Color = float4(1, 1, 1, alpha) * IN.Color;
106    return Color;       
107}
Note: See TracBrowser for help on using the repository browser.