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