// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // File : WOWvx.fx // Purpose : WOWvx 3D Display mode // Path : // Created : 8.3.7 // Author : Phil Palmer (http://www.programmerart.org) // Info : // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include "h_WOWvx.fx" // PP(17.6.7): Header file shared by WOWvx.fx and the main game code //--------------------------------------------------------------// // SinglePass //--------------------------------------------------------------// texture position_Tex; sampler2D positionSampler = sampler_state { Texture = (position_Tex); ADDRESSU = CLAMP; ADDRESSV = CLAMP; ADDRESSW = CLAMP; MINFILTER = POINT; MIPFILTER = NONE; MAGFILTER = POINT; }; texture header_Tex; sampler2D headerSampler = sampler_state { Texture = (header_Tex); ADDRESSU = CLAMP; ADDRESSV = CLAMP; ADDRESSW = CLAMP; MINFILTER = POINT; MIPFILTER = NONE; MAGFILTER = POINT; }; texture banner_Tex; sampler2D bannerSampler = sampler_state { Texture = (banner_Tex); ADDRESSU = CLAMP; ADDRESSV = CLAMP; ADDRESSW = CLAMP; MINFILTER = POINT; MIPFILTER = NONE; MAGFILTER = LINEAR; }; float4 cMainViewpoint; float4 vp; float4 cViewVec; float cNearDist;// PP(8.3.7): WS float cFarDist;// PP(8.3.7): WS struct STransferData { float4 pos : POSITION0; float2 texCoord : TEXCOORD0; }; STransferData _VertexShader(const STransferData input) { STransferData output; output.pos =float4(0,0,0,0);// PP(9.3.7): totally ignored, must be the vertex type output.texCoord = input.texCoord; return output; } // PP(17.6.7): convert rescaled z-buffer depth to 'disparity' as described in the WOWvx docs float DepthToDisparity(const float depthIn) { //* // PP(17.6.7): 42" constants const float M = -1960.37f; // linear function multiplier const float Zd = 0.467481f; // depth of display plane const float vz = 7.655192f; // view distance in coordinate units const float C = 127.5f; // linear function constant /*/ // PP(17.6.7): 21" constants const float M = -1586.34; // linear function multiplier const float Zd = 0.459813f; // depth of display plane const float vz = 6.180772; // view distance in coordinate units const float C = 127.5f; // linear function constant //*/ return (M * ( 1.f - (vz/(depthIn-Zd+vz)) ) + C) / 255.f; } // PP(9.3.7): disparity image float4 PixelShader_Disparity(const STransferData input) : COLOR { float4 rtn; float3 pixelPos = tex2D(positionSampler, input.texCoord); float3 vpToPixel = pixelPos + (cMainViewpoint-vp);// this expression avoids large intermediate terms that might ruin the precision float depth = dot(vpToPixel, cViewVec); depth = GetZBufferDepth(depth, cNearDist, cFarDist); rtn.rgb = DepthToDisparity(depth); rtn.a = 1.f; return rtn; } // PP(9.3.7): header float4 PixelShader_Header(const STransferData input) : COLOR { float4 rtn; float4 headerSample = tex2D(headerSampler, input.texCoord); clip(headerSample.r - 0.5f);// PP(17.6.7): NOTE: RED IS NOW THE MASK, NOT ALPHA rtn.rgb = headerSample.b; rtn.a = 1.f; return rtn; } // PP(6.5.8): banner float4 PixelShader_Banner(const STransferData input) : COLOR { float4 rtn; float4 bannerSample = tex2D(bannerSampler, input.texCoord); clip(bannerSample.r - 0.01f);// PP(6.5.8): red is opacity rtn.rgb = bannerSample.g; rtn.b += bannerSample.b; rtn.a = bannerSample.r; return rtn; } //--------------------------------------------------------------// // Technique Section //--------------------------------------------------------------// technique SingleTechnique { // PP(9.3.7): disparity image pass DisparityPass { CULLMODE = NONE; ALPHABLENDENABLE = FALSE; ALPHATESTENABLE = FALSE; ZENABLE = FALSE; ZWRITEENABLE = FALSE; VertexShader = compile vs_3_0 _VertexShader(); PixelShader = compile ps_3_0 PixelShader_Disparity(); } // PP(9.3.7): header // PP(9.3.7): TODO: ALPHATEST pass HeaderPass { CULLMODE = NONE; ALPHABLENDENABLE = FALSE; ALPHATESTENABLE = FALSE; ZENABLE = FALSE; ZWRITEENABLE = FALSE; FOGENABLE = FALSE; COLORWRITEENABLE = BLUE; VertexShader = compile vs_3_0 _VertexShader(); PixelShader = compile ps_3_0 PixelShader_Header(); } pass BannerPass { CULLMODE = NONE; ALPHABLENDENABLE = TRUE; DESTBLEND = INVSRCALPHA; SRCBLEND = SRCALPHA; BLENDOP = ADD; ZENABLE = FALSE; ZWRITEENABLE = FALSE; FOGENABLE = FALSE; COLORWRITEENABLE = RED|GREEN|BLUE; VertexShader = compile vs_3_0 _VertexShader(); PixelShader = compile ps_3_0 PixelShader_Banner(); } }