1 | struct fragment |
---|
2 | { |
---|
3 | // normalized screen position |
---|
4 | float4 pos: WPOS; |
---|
5 | float4 texCoord: TEXCOORD0; |
---|
6 | float3 view: COLOR0; |
---|
7 | }; |
---|
8 | |
---|
9 | |
---|
10 | struct pixel |
---|
11 | { |
---|
12 | float4 color: COLOR0; |
---|
13 | }; |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | /** function for standard deferred shading |
---|
18 | */ |
---|
19 | float4 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 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f); |
---|
27 | |
---|
28 | // global ambient |
---|
29 | const float4 ambient = 0.3f; |
---|
30 | |
---|
31 | // float3 L = normalize(lightPosition - position); |
---|
32 | float3 light = normalize(lightDir.xyz); |
---|
33 | float3 light2 = normalize(lightDir2.xyz); |
---|
34 | |
---|
35 | float diffuseLight = saturate(dot(normal, light)); |
---|
36 | float diffuseLight2 = saturate(dot(normal, light2)); |
---|
37 | |
---|
38 | float diffuse = diffuseLight + diffuseLight2; |
---|
39 | |
---|
40 | return (ambient + diffuse) * color * (1.0f - amb) + amb * color; |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | /** The mrt shader for standard rendering |
---|
45 | */ |
---|
46 | pixel main2(fragment IN, |
---|
47 | uniform sampler2D colors, |
---|
48 | uniform sampler2D positions, |
---|
49 | uniform sampler2D normals |
---|
50 | ) |
---|
51 | { |
---|
52 | pixel OUT; |
---|
53 | |
---|
54 | float4 norm = tex2D(normals, IN.texCoord.xy); |
---|
55 | float4 color = tex2D(colors, IN.texCoord.xy); |
---|
56 | float4 position = tex2D(positions, IN.texCoord.xy); |
---|
57 | |
---|
58 | // an ambient color term |
---|
59 | float amb = norm.w; |
---|
60 | |
---|
61 | // expand normal |
---|
62 | float3 normal = normalize(norm.xyz);// * 2.0f - float4(1.0f)); |
---|
63 | |
---|
64 | float4 col = shade(IN, color, position, normal, amb); |
---|
65 | |
---|
66 | //OUT.color = float4(1.0f); |
---|
67 | OUT.color = col; |
---|
68 | OUT.color.w = color.w; |
---|
69 | |
---|
70 | return OUT; |
---|
71 | } |
---|
72 | |
---|
73 | /** The mrt shader for standard rendering |
---|
74 | */ |
---|
75 | pixel main(fragment IN, |
---|
76 | uniform sampler2D colors, |
---|
77 | uniform sampler2D positions, |
---|
78 | uniform sampler2D normals |
---|
79 | ) |
---|
80 | { |
---|
81 | pixel OUT; |
---|
82 | |
---|
83 | float4 norm = tex2D(normals, IN.texCoord.xy); |
---|
84 | float4 color = tex2D(colors, IN.texCoord.xy); |
---|
85 | float4 position = tex2D(positions, IN.texCoord.xy); |
---|
86 | |
---|
87 | // an ambient color term |
---|
88 | float amb = norm.w; |
---|
89 | |
---|
90 | // expand normal |
---|
91 | float3 normal = normalize(norm.xyz);// * 2.0f - float4(1.0f)); |
---|
92 | |
---|
93 | float4 col = shade(IN, color, position, normal.xyz, amb); |
---|
94 | |
---|
95 | //OUT.color = float4(1.0f); |
---|
96 | OUT.color = col; |
---|
97 | |
---|
98 | return OUT; |
---|
99 | } |
---|