// 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 worldPos: TEXCOORD1; // world position float3 normal: TEXCOORD2; float4 mypos: TEXCOORD3; }; // fragment input struct fragin { float4 position: POSITION; // eye space float4 texCoord: TEXCOORD0; float4 projPos: WPOS; float4 color: COLOR0; float4 worldPos: TEXCOORD1; // world position float3 normal: TEXCOORD2; float4 mypos: TEXCOORD3; //float DEPTH; }; struct pixel { float4 col: COLOR0; float4 pos: COLOR1; float4 norm: COLOR2; }; vtxout vtx(vtxin IN, const uniform float4x4 ModelViewProj, uniform float4x4 ModelMatrix) { vtxout OUT; // transform the vertex position into eye space OUT.color = IN.color; OUT.texCoord = IN.texCoord; OUT.worldPos = mul(ModelMatrix, IN.position); // transform the vertex position into eye space OUT.position = mul(ModelViewProj, OUT.worldPos); OUT.normal = IN.normal; OUT.mypos = OUT.position; return OUT; } pixel fragtex(fragin IN, uniform sampler2D tex, uniform float maxDepth, uniform float4 ambient, uniform float4 diffuse) { pixel pix; pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy); pix.pos = IN.worldPos * maxDepth; pix.norm.xyz = IN.normal * 0.5f + 0.5f; // hack: squeeze some information about ambient into the texture pix.norm.w = ambient.x; // hack: store projection coordinate for scaling ssao pix.pos.w = IN.projPos.w; if (pix.col.w < 0.5f) discard; pix.col.w = IN.mypos.z / IN.mypos.w; return pix; } pixel frag(fragin IN, uniform float maxDepth, uniform float4 ambient, uniform float4 diffuse) { pixel pix; pix.col = diffuse; pix.pos = IN.worldPos * maxDepth; pix.norm.xyz = IN.normal * 0.5f + float3(0.5f); // hack: squeeze some information about ambient into the texture pix.norm.w = ambient.x; pix.pos.w = IN.mypos.w; pix.col.w = IN.mypos.z / IN.mypos.w; return pix; }