source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg @ 2892

Revision 2892, 2.5 KB checked in by mattausch, 16 years ago (diff)
Line 
1struct fragment
2{
3         // normalized screen position
4        float4 pos: WPOS;
5        float4 texCoord: TEXCOORD0;
6        float3 view: COLOR0;
7};
8
9
10struct pixel
11{
12        float4 color: COLOR0;
13};
14
15
16
17/** function for standard deferred shading
18*/
19float4 shade(fragment IN,
20                         uniform float4 color,
21                         uniform float4 position,
22                         uniform float3 normal,
23                         uniform float amb)
24{
25        float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f);
26        //float4 lightDir = float4(0.0f, 1.0f, 0.0f, 0.0f);
27        float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f);
28
29        // global ambient
30        const float4 ambient = 0.25f;
31
32        // float3 L = normalize(lightPosition - position);
33        float3 light = normalize(lightDir.xyz);
34        float3 light2 = normalize(lightDir2.xyz);
35
36        float diffuseLight = saturate(dot(normal, light));
37        float diffuseLight2 = saturate(dot(normal, light2));
38
39        float diffuse = diffuseLight + diffuseLight2;
40
41        return (ambient + diffuse) * color * (1.0f - amb) + amb * color;
42}
43
44
45
46/** The mrt shader for standard rendering
47*/
48pixel main(fragment IN,
49                   uniform sampler2D colors,
50                   uniform sampler2D positions,
51                   uniform sampler2D normals   
52                   )
53{
54        pixel OUT;
55
56        float4 norm = tex2D(normals, IN.texCoord.xy);
57        float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0));
58        float4 position = tex2D(positions, IN.texCoord.xy);
59
60        // an ambient color term
61        float amb = norm.w;
62
63        // expand normal
64        float3 normal = normalize(norm.xyz);// * 2.0f - float4(1.0f));
65
66        float4 col = shade(IN, color, position, normal, amb);
67       
68        //OUT.color = float4(1.0f);
69        OUT.color = col;
70        OUT.color.w = color.w;
71
72        return OUT;
73}
74
75/** The mrt shader for standard rendering
76*/
77pixel main_shadow(fragment IN,
78                                  uniform sampler2D colors,
79                                  uniform sampler2D positions,
80                                  uniform sampler2D normals,               
81                                  uniform sampler2D shadowMap,
82                                  uniform float4x4 shadowMatrix
83                                  )
84{
85        pixel OUT;
86
87        float4 norm = tex2D(normals, IN.texCoord.xy);
88        float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0));
89        float4 position = tex2D(positions, IN.texCoord.xy);
90
91        float4 lightSpacePos = mul(shadowMatrix, position);
92
93        float shadowDepth = tex2D(shadowMap, IN.texCoord.xy);
94
95        // an ambient color term
96        float amb = norm.w;
97
98        float3 normal = normalize(norm.xyz);
99        float4 col = shade(IN, color, position, normal, amb);
100       
101        OUT.color = col;
102       
103        if (lightSpacePos.z / lightSpacePos.w < shadowDepth)
104        {
105                OUT.color *= 0.1f;
106        }
107       
108        //OUT.color = float4(lightSpacePos.z / lightSpacePos.w);
109        //OUT.color = float4(shadowDepth);
110        OUT.color.w = color.w;
111
112        return OUT;
113}
Note: See TracBrowser for help on using the repository browser.