[2810] | 1 | // input |
---|
| 2 | struct vtxin |
---|
| 3 | { |
---|
| 4 | float4 position: POSITION; |
---|
| 5 | float3 normal: NORMAL; |
---|
| 6 | float4 color: COLOR0; |
---|
| 7 | float4 texCoord: TEXCOORD0; |
---|
| 8 | }; |
---|
| 9 | |
---|
| 10 | // vtx output |
---|
| 11 | struct vtxout |
---|
| 12 | { |
---|
| 13 | float4 position: POSITION; // eye space |
---|
| 14 | float4 texCoord: TEXCOORD0; |
---|
| 15 | |
---|
| 16 | float4 color: COLOR0; |
---|
| 17 | float4 worldPos: TEXCOORD1; // world position |
---|
[2811] | 18 | float3 normal: TEXCOORD2; |
---|
[2834] | 19 | float4 mypos: TEXCOORD3; |
---|
[2810] | 20 | }; |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | // fragment input |
---|
| 24 | struct fragin |
---|
| 25 | { |
---|
| 26 | float4 position: POSITION; // eye space |
---|
| 27 | float4 texCoord: TEXCOORD0; |
---|
| 28 | |
---|
[2813] | 29 | float4 projPos: WPOS; |
---|
[2810] | 30 | float4 color: COLOR0; |
---|
| 31 | float4 worldPos: TEXCOORD1; // world position |
---|
[2811] | 32 | float3 normal: TEXCOORD2; |
---|
[2834] | 33 | |
---|
| 34 | float4 mypos: TEXCOORD3; |
---|
| 35 | //float DEPTH; |
---|
[2810] | 36 | }; |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | struct pixel |
---|
| 40 | { |
---|
| 41 | float4 col: COLOR0; |
---|
| 42 | float4 pos: COLOR1; |
---|
[2822] | 43 | float4 norm: COLOR2; |
---|
[2810] | 44 | }; |
---|
| 45 | |
---|
| 46 | |
---|
[2818] | 47 | vtxout vtx(vtxin IN, |
---|
[2834] | 48 | const uniform float4x4 ModelViewProj, |
---|
| 49 | uniform float4x4 ModelMatrix) |
---|
[2810] | 50 | { |
---|
| 51 | vtxout OUT; |
---|
| 52 | |
---|
| 53 | // transform the vertex position into eye space |
---|
| 54 | OUT.color = IN.color; |
---|
| 55 | |
---|
| 56 | OUT.texCoord = IN.texCoord; |
---|
[2818] | 57 | OUT.worldPos = mul(ModelMatrix, IN.position); |
---|
| 58 | |
---|
| 59 | // transform the vertex position into eye space |
---|
| 60 | OUT.position = mul(ModelViewProj, OUT.worldPos); |
---|
| 61 | |
---|
[2811] | 62 | OUT.normal = IN.normal; |
---|
[2810] | 63 | |
---|
[2834] | 64 | OUT.mypos = OUT.position; |
---|
[2810] | 65 | return OUT; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | |
---|
[2822] | 69 | pixel fragtex(fragin IN, |
---|
[2834] | 70 | uniform sampler2D tex, |
---|
| 71 | uniform float maxDepth, |
---|
| 72 | uniform float4 ambient, |
---|
| 73 | uniform float4 diffuse) |
---|
[2810] | 74 | { |
---|
[2865] | 75 | pixel pix; |
---|
[2836] | 76 | |
---|
[2866] | 77 | // save color in first render target |
---|
[2865] | 78 | pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy); |
---|
[2867] | 79 | |
---|
[2866] | 80 | // save world position in second rt |
---|
[2865] | 81 | pix.pos = IN.worldPos * maxDepth; |
---|
[2866] | 82 | // save normal in third rt |
---|
[2867] | 83 | //pix.norm.xyz = IN.normal * 0.5f + 0.5f; |
---|
| 84 | pix.norm.xyz = IN.normal; |
---|
[2836] | 85 | |
---|
[2865] | 86 | // hack: squeeze some information about ambient into the texture |
---|
| 87 | pix.norm.w = ambient.x; |
---|
[2866] | 88 | // store projection coordinates with positions (used for ssao) |
---|
[2865] | 89 | pix.pos.w = IN.projPos.w; |
---|
[2836] | 90 | |
---|
[2865] | 91 | // account for alpha blending |
---|
| 92 | if (pix.col.w < 0.5f) |
---|
| 93 | discard; |
---|
[2810] | 94 | |
---|
[2865] | 95 | // write the depth |
---|
| 96 | pix.col.w = IN.mypos.z / IN.mypos.w; |
---|
| 97 | |
---|
| 98 | return pix; |
---|
[2810] | 99 | } |
---|
[2819] | 100 | |
---|
| 101 | |
---|
[2822] | 102 | pixel frag(fragin IN, |
---|
| 103 | uniform float maxDepth, |
---|
| 104 | uniform float4 ambient, |
---|
| 105 | uniform float4 diffuse) |
---|
[2819] | 106 | { |
---|
[2865] | 107 | pixel pix; |
---|
[2819] | 108 | |
---|
[2865] | 109 | pix.col = diffuse; |
---|
| 110 | pix.pos = IN.worldPos * maxDepth; |
---|
[2867] | 111 | //pix.norm.xyz = IN.normal * 0.5f + float3(0.5f); |
---|
| 112 | pix.norm.xyz = IN.normal; |
---|
| 113 | // hack: squeeze some information about the ambient term into the target |
---|
[2865] | 114 | pix.norm.w = ambient.x; |
---|
| 115 | pix.pos.w = IN.mypos.w; |
---|
| 116 | pix.col.w = IN.mypos.z / IN.mypos.w; |
---|
| 117 | |
---|
| 118 | return pix; |
---|
[2819] | 119 | } |
---|