[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 | { |
---|
[2891] | 26 | float4 color: COLOR0; |
---|
| 27 | float4 position: POSITION; // eye space |
---|
| 28 | float4 texCoord: TEXCOORD0; |
---|
[2810] | 29 | |
---|
[2891] | 30 | float4 projPos: WPOS; |
---|
| 31 | float4 worldPos: TEXCOORD1; // world position |
---|
| 32 | float3 normal: TEXCOORD2; |
---|
| 33 | float4 mypos: TEXCOORD3; |
---|
[2810] | 34 | }; |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | struct pixel |
---|
| 38 | { |
---|
| 39 | float4 col: COLOR0; |
---|
| 40 | float4 pos: COLOR1; |
---|
[2822] | 41 | float4 norm: COLOR2; |
---|
[2810] | 42 | }; |
---|
| 43 | |
---|
[2951] | 44 | #pragma position_invariant vtx |
---|
[2810] | 45 | |
---|
[2818] | 46 | vtxout vtx(vtxin IN, |
---|
[2834] | 47 | const uniform float4x4 ModelViewProj, |
---|
[2952] | 48 | uniform float4x4 ModelView) |
---|
[2810] | 49 | { |
---|
[2952] | 50 | vtxout OUT; |
---|
[2810] | 51 | |
---|
[2952] | 52 | OUT.color = IN.color; |
---|
| 53 | OUT.texCoord = IN.texCoord; |
---|
[2818] | 54 | |
---|
[2952] | 55 | //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position); |
---|
| 56 | OUT.worldPos = mul(ModelView, IN.position); |
---|
[2958] | 57 | // transform the vertex position into eye space |
---|
| 58 | OUT.position = mul(glstate.matrix.mvp, IN.position); |
---|
[2810] | 59 | |
---|
[2952] | 60 | OUT.normal = IN.normal; |
---|
| 61 | OUT.mypos = OUT.position; |
---|
| 62 | |
---|
| 63 | return OUT; |
---|
[2810] | 64 | } |
---|
| 65 | |
---|
| 66 | |
---|
[2822] | 67 | pixel fragtex(fragin IN, |
---|
[2964] | 68 | uniform sampler2D dirtTex, |
---|
| 69 | uniform float maxDepth, |
---|
| 70 | uniform sampler2D tex) |
---|
[2810] | 71 | { |
---|
[2865] | 72 | pixel pix; |
---|
[2836] | 73 | |
---|
[2964] | 74 | float4 texColor = tex2D(tex, IN.texCoord.xy); |
---|
| 75 | |
---|
[2866] | 76 | // save color in first render target |
---|
[2974] | 77 | // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term) |
---|
[2964] | 78 | pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor; |
---|
[2867] | 79 | |
---|
[2951] | 80 | // save world position in second render target |
---|
[2865] | 81 | pix.pos = IN.worldPos * maxDepth; |
---|
[2974] | 82 | // save world space normal in third rt |
---|
[2867] | 83 | pix.norm.xyz = IN.normal; |
---|
[2836] | 84 | |
---|
[2866] | 85 | // store projection coordinates with positions (used for ssao) |
---|
[2974] | 86 | pix.norm.w = IN.projPos.w; |
---|
| 87 | // write the depth |
---|
| 88 | pix.pos.w = IN.mypos.z / IN.mypos.w; |
---|
[2836] | 89 | |
---|
[2865] | 90 | // account for alpha blending |
---|
| 91 | if (pix.col.w < 0.5f) |
---|
| 92 | discard; |
---|
[2810] | 93 | |
---|
[2974] | 94 | // hack: squeeze some information about ambient into the texture |
---|
| 95 | pix.col.w = glstate.material.emission.x; |
---|
[2982] | 96 | //pix.col.w = length(currentPos - IN.worldPos) |
---|
[2865] | 97 | |
---|
| 98 | return pix; |
---|
[2810] | 99 | } |
---|
[2819] | 100 | |
---|
| 101 | |
---|
[2822] | 102 | pixel frag(fragin IN, |
---|
[2960] | 103 | uniform float maxDepth) |
---|
[2819] | 104 | { |
---|
[2865] | 105 | pixel pix; |
---|
[2819] | 106 | |
---|
[2960] | 107 | // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) |
---|
| 108 | pix.col = glstate.material.diffuse + glstate.material.emission; |
---|
[2865] | 109 | pix.pos = IN.worldPos * maxDepth; |
---|
[2873] | 110 | |
---|
[2867] | 111 | pix.norm.xyz = IN.normal; |
---|
[2873] | 112 | |
---|
[2974] | 113 | // store projection coordinates with positions (used for ssao) |
---|
| 114 | pix.norm.w = IN.mypos.w; |
---|
| 115 | // the projected depth |
---|
| 116 | pix.pos.w = IN.mypos.z / IN.mypos.w; |
---|
| 117 | |
---|
[2867] | 118 | // hack: squeeze some information about the ambient term into the target |
---|
[2974] | 119 | pix.col.w = glstate.material.emission.x; |
---|
[2865] | 120 | |
---|
| 121 | return pix; |
---|
[2928] | 122 | } |
---|