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 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 | */
|
---|
48 | pixel 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 | }
|
---|