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 |
|
---|
45 | /** The mrt shader for standard rendering
|
---|
46 | */
|
---|
47 | pixel main(fragment IN,
|
---|
48 | uniform sampler2D colors,
|
---|
49 | uniform sampler2D positions,
|
---|
50 | uniform sampler2D normals
|
---|
51 | )
|
---|
52 | {
|
---|
53 | pixel OUT;
|
---|
54 |
|
---|
55 | float4 norm = tex2D(normals, IN.texCoord.xy);
|
---|
56 | float4 color = tex2D(colors, IN.texCoord.xy);
|
---|
57 | float4 position = tex2D(positions, IN.texCoord.xy);
|
---|
58 |
|
---|
59 | // an ambient color term
|
---|
60 | float amb = norm.w;
|
---|
61 |
|
---|
62 | // expand normal
|
---|
63 | float3 normal = normalize(norm.xyz);// * 2.0f - float4(1.0f));
|
---|
64 |
|
---|
65 | float4 col = shade(IN, color, position, normal, amb);
|
---|
66 |
|
---|
67 | //OUT.color = float4(1.0f);
|
---|
68 | OUT.color = col;
|
---|
69 | OUT.color.w = color.w;
|
---|
70 |
|
---|
71 | return OUT;
|
---|
72 | }
|
---|