// input struct vtxin { float4 position: POSITION; float3 normal: NORMAL; float4 color: COLOR0; float4 texCoord: TEXCOORD0; }; // vtx output struct vtxout { float4 position: POSITION; // eye space float4 texCoord: TEXCOORD0; float4 color: COLOR0; float4 eyePos: TEXCOORD1; // eye position float3 normal: TEXCOORD2; }; // fragment input struct fragin { float4 color: COLOR0; //float4 position: POSITION; float4 texCoord: TEXCOORD0; float4 winPos: WPOS; float4 eyePos: TEXCOORD1; // eye position float3 normal: TEXCOORD2; }; struct pixel { float4 col: COLOR0; float3 norm: COLOR1; float3 pos: COLOR2; }; #pragma position_invariant vtx vtxout vtx(vtxin IN) { vtxout OUT; OUT.color = IN.color; OUT.texCoord = IN.texCoord; // transform the vertex position into eye space OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position); // transform the vertex position into post projection space OUT.position = mul(glstate.matrix.mvp, IN.position); OUT.normal = IN.normal; return OUT; } //#pragma position_invariant fragtex pixel fragtex(fragin IN, uniform sampler2D tex ) { float4 texColor = tex2D(tex, IN.texCoord.xy); // account for alpha blending if (texColor.w < 0.5f) discard; pixel pix; // save color in first render target // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term) pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor; // save world space normal in rt pix.norm = IN.normal; // hack: squeeze some information about ambient into the texture //pix.col.w = glstate.material.emission.x; // compute eye linear depth pix.col.w = length(IN.eyePos.xyz); return pix; } pixel frag(fragin IN) { pixel pix; // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) pix.col = glstate.material.diffuse + glstate.material.emission; pix.norm = IN.normal; pix.col.w = length(IN.eyePos.xyz); // hack: squeeze some information about the ambient term into the target //pix.col.w = glstate.material.emission.x; return pix; }