diff --git a/src/core/hle/D3D8/Direct3D9/CxbxVertexShaderTemplate.hlsl b/src/core/hle/D3D8/Direct3D9/CxbxVertexShaderTemplate.hlsl index ebaca85f2..718694cd7 100644 --- a/src/core/hle/D3D8/Direct3D9/CxbxVertexShaderTemplate.hlsl +++ b/src/core/hle/D3D8/Direct3D9/CxbxVertexShaderTemplate.hlsl @@ -28,9 +28,6 @@ struct VS_OUTPUT // Declared identical to pixel shader input (see PS_INPUT) // Xbox constant registers uniform float4 C[X_D3DVS_CONSTREG_COUNT] : register(c0); -// Parameters for mapping the shader's fog output value to a fog factor -uniform float4 CxbxFogInfo: register(c218); // = CXBX_D3DVS_CONSTREG_FOGINFO - // Default values for vertex registers, and whether to use them uniform float4 vRegisterDefaultValues[16] : register(c192); uniform float4 vRegisterDefaultFlagsPacked[4] : register(c208); @@ -40,6 +37,9 @@ uniform float4 xboxScreenspaceOffset : register(c213); uniform float4 xboxTextureScale[4] : register(c214); +// Parameters for mapping the shader's fog output value to a fog factor +uniform float4 CxbxFogInfo: register(c218); // = CXBX_D3DVS_CONSTREG_FOGINFO + // Overloaded casts, assuring all inputs are treated as float4 float4 _tof4(float src) { return float4(src, src, src, src); } float4 _tof4(float2 src) { return src.xyyy; } @@ -329,6 +329,8 @@ R"DELIMITER( // Copy variables to output struct VS_OUTPUT xOut; + // Fogging + // TODO deduplicate const float fogDepth = abs(oFog.x); const float fogTableMode = CxbxFogInfo.x; const float fogDensity = CxbxFogInfo.y; @@ -348,7 +350,7 @@ R"DELIMITER( if(fogTableMode == FOG_TABLE_EXP2) fogFactor = 1 / exp(pow(fogDepth * fogDensity, 2)); /* / 1 / e^((d * density)^2)*/ if(fogTableMode == FOG_TABLE_LINEAR) - fogFactor = (fogEnd - fogDepth) / (fogEnd - fogStart) ; + fogFactor = (fogEnd - fogDepth) / (fogEnd - fogStart); xOut.oPos = reverseScreenspaceTransform(oPos); xOut.oD0 = saturate(oD0); diff --git a/src/core/hle/D3D8/Direct3D9/VertexShader.cpp b/src/core/hle/D3D8/Direct3D9/VertexShader.cpp index e4ebc6f75..959fe0abd 100644 --- a/src/core/hle/D3D8/Direct3D9/VertexShader.cpp +++ b/src/core/hle/D3D8/Direct3D9/VertexShader.cpp @@ -259,6 +259,9 @@ uniform float4 xboxScreenspaceOffset : register(c213); uniform float4 xboxTextureScale[4] : register(c214); +// Parameters for mapping the shader's fog output value to a fog factor +uniform float4 CxbxFogInfo: register(c218); // = CXBX_D3DVS_CONSTREG_FOGINFO + struct VS_INPUT { float4 v[16] : TEXCOORD; @@ -337,10 +340,33 @@ VS_OUTPUT main(const VS_INPUT xIn) // Copy variables to output struct VS_OUTPUT xOut; + // Fogging + // TODO deduplicate + const float fogDepth = abs(oFog.x); + const float fogTableMode = CxbxFogInfo.x; + const float fogDensity = CxbxFogInfo.y; + const float fogStart = CxbxFogInfo.z; + const float fogEnd = CxbxFogInfo.w; + + const float FOG_TABLE_NONE = 0; + const float FOG_TABLE_EXP = 1; + const float FOG_TABLE_EXP2 = 2; + const float FOG_TABLE_LINEAR = 3; + + float fogFactor; + if(fogTableMode == FOG_TABLE_NONE) + fogFactor = fogDepth; + if(fogTableMode == FOG_TABLE_EXP) + fogFactor = 1 / exp(fogDepth * fogDensity); /* / 1 / e^(d * density)*/ + if(fogTableMode == FOG_TABLE_EXP2) + fogFactor = 1 / exp(pow(fogDepth * fogDensity, 2)); /* / 1 / e^((d * density)^2)*/ + if(fogTableMode == FOG_TABLE_LINEAR) + fogFactor = (fogEnd - fogDepth) / (fogEnd - fogStart); + xOut.oPos = reverseScreenspaceTransform(oPos); xOut.oD0 = saturate(oD0); xOut.oD1 = saturate(oD1); - xOut.oFog = oFog.x; // Note : Xbox clamps fog in pixel shader + xOut.oFog = fogFactor; // Note : Xbox clamps fog in pixel shader xOut.oPts = oPts.x; xOut.oB0 = saturate(oB0); xOut.oB1 = saturate(oB1);