[3004] | 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;
|
---|
[3034] | 17 | float4 eyePos: TEXCOORD1; // eye position
|
---|
[3004] | 18 | float3 normal: TEXCOORD2;
|
---|
| 19 | };
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | // fragment input
|
---|
| 23 | struct fragin
|
---|
| 24 | {
|
---|
| 25 | float4 color: COLOR0;
|
---|
[3034] | 26 | //float4 position: POSITION;
|
---|
[3004] | 27 | float4 texCoord: TEXCOORD0;
|
---|
| 28 |
|
---|
[3017] | 29 | float4 winPos: WPOS;
|
---|
[3034] | 30 | float4 eyePos: TEXCOORD1; // eye position
|
---|
[3004] | 31 | float3 normal: TEXCOORD2;
|
---|
| 32 | };
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | struct pixel
|
---|
| 36 | {
|
---|
[3005] | 37 | float4 col: COLOR0;
|
---|
[3017] | 38 | float3 norm: COLOR1;
|
---|
[3009] | 39 | float3 pos: COLOR2;
|
---|
[3004] | 40 | };
|
---|
| 41 |
|
---|
[3034] | 42 |
|
---|
[3004] | 43 | #pragma position_invariant vtx
|
---|
| 44 |
|
---|
[3034] | 45 | vtxout vtx(vtxin IN)
|
---|
[3004] | 46 | {
|
---|
| 47 | vtxout OUT;
|
---|
| 48 |
|
---|
| 49 | OUT.color = IN.color;
|
---|
| 50 | OUT.texCoord = IN.texCoord;
|
---|
| 51 |
|
---|
| 52 | // transform the vertex position into eye space
|
---|
[3034] | 53 | OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position);
|
---|
| 54 | // transform the vertex position into post projection space
|
---|
[3004] | 55 | OUT.position = mul(glstate.matrix.mvp, IN.position);
|
---|
| 56 |
|
---|
| 57 | OUT.normal = IN.normal;
|
---|
| 58 |
|
---|
| 59 | return OUT;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[3017] | 62 | //#pragma position_invariant fragtex
|
---|
[3004] | 63 |
|
---|
| 64 | pixel fragtex(fragin IN,
|
---|
[3034] | 65 | uniform sampler2D tex
|
---|
[3004] | 66 | )
|
---|
| 67 | {
|
---|
| 68 | float4 texColor = tex2D(tex, IN.texCoord.xy);
|
---|
| 69 |
|
---|
| 70 | // account for alpha blending
|
---|
| 71 | if (texColor.w < 0.5f) discard;
|
---|
| 72 |
|
---|
| 73 | pixel pix;
|
---|
| 74 |
|
---|
| 75 | // save color in first render target
|
---|
| 76 | // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term)
|
---|
| 77 | pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor;
|
---|
[3017] | 78 | // save world space normal in rt
|
---|
| 79 | pix.norm = IN.normal;
|
---|
[3004] | 80 |
|
---|
| 81 | // hack: squeeze some information about ambient into the texture
|
---|
| 82 | //pix.col.w = glstate.material.emission.x;
|
---|
| 83 |
|
---|
| 84 | // compute eye linear depth
|
---|
[3034] | 85 | pix.col.w = length(IN.eyePos.xyz);
|
---|
[3004] | 86 |
|
---|
| 87 | return pix;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 |
|
---|
[3034] | 91 | pixel frag(fragin IN)
|
---|
[3004] | 92 | {
|
---|
| 93 | pixel pix;
|
---|
| 94 |
|
---|
| 95 | // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
|
---|
| 96 | pix.col = glstate.material.diffuse + glstate.material.emission;
|
---|
| 97 |
|
---|
[3017] | 98 | pix.norm = IN.normal;
|
---|
[3004] | 99 |
|
---|
[3034] | 100 | pix.col.w = length(IN.eyePos.xyz);
|
---|
| 101 |
|
---|
[3004] | 102 | // hack: squeeze some information about the ambient term into the target
|
---|
| 103 | //pix.col.w = glstate.material.emission.x;
|
---|
| 104 |
|
---|
| 105 | return pix;
|
---|
[2928] | 106 | } |
---|