Added setAnim to camera. Added global fog set via worldspawn.

This commit is contained in:
Justin Marshall
2026-05-21 06:17:29 -07:00
parent 24e694c240
commit aec93deaa0
26 changed files with 571 additions and 156 deletions
+51 -4
View File
@@ -1114,7 +1114,7 @@ cbuffer DrawCB : register(b0)
float gFogEnd;
float gPointSize;
float gMaterialType;
float gFogPad2;
float gAlphaFunc;
float4 gFogColor;
@@ -1123,17 +1123,61 @@ cbuffer DrawCB : register(b0)
float2 gJitterPixels;
float2 gPrevJitterPixels;
float4 gMotionPad;
float4 gMaterialMapPad;
float4 gTexComb0RGB;
float4 gTexComb0Alpha;
float4 gTexComb0Operand;
float4 gTexEnvColor0;
float4 gTexComb1RGB;
float4 gTexComb1Alpha;
float4 gTexComb1Operand;
float4 gTexEnvColor1;
float4 gCameraPomPad;
float4 gNeuralPomPad;
float4 gARBEnv[128];
float4 gARBLocalVP[128];
float4 gARBLocalFP[128];
};
#define gCameraWorldPos gCameraPomPad.xyz
#define gCameraPomValid gCameraPomPad.w
float3 QD3D12ARB_NormalizeSafe(float3 v)
{
return v * rsqrt(max(dot(v, v), 1e-20));
}
float QD3D12ARB_ComputeFogFactor(float fogCoord)
{
if (gFogEnabled < 0.5)
return 1.0;
float f;
if (gFogMode < 0.5)
{
float denom = max(gFogEnd - gFogStart, 0.00001);
f = (gFogEnd - fogCoord) / denom;
}
else if (gFogMode < 1.5)
{
f = exp(-gFogDensity * fogCoord);
}
else
{
float d = gFogDensity * fogCoord;
f = exp(-(d * d));
}
return saturate(f);
}
float4 QD3D12ARB_ApplyFog(float4 color, float fogCoord)
{
float fogFactor = QD3D12ARB_ComputeFogFactor(fogCoord);
color.rgb = lerp(gFogColor.rgb, color.rgb, fogFactor);
return color;
}
)HLSL";
}
@@ -1172,6 +1216,7 @@ VSOut VSMain(VSIn i)
{
VSOut o = (VSOut)0;
o.pos = mul(gMVP, float4(i.pos, 1.0));
float4 worldPos = mul(gModelMatrix, float4(i.pos, 1.0));
o.tc0 = float4(i.uv0, 0.0, 1.0);
o.tc1 = float4(i.uv1, 0.0, 1.0);
o.tc2 = float4(0.0, 0.0, 0.0, 1.0);
@@ -1181,7 +1226,9 @@ VSOut VSMain(VSIn i)
o.tc6 = float4(0.0, 0.0, 0.0, 1.0);
o.tc7 = float4(0.0, 0.0, 0.0, 1.0);
o.col = i.col;
o.fog = float4(0.0, 0.0, 0.0, 0.0);
o.fog = float4((gCameraPomValid > 0.5)
? length(worldPos.xyz - gCameraWorldPos)
: abs(o.pos.z / max(abs(o.pos.w), 0.00001)), 0.0, 0.0, 1.0);
float4 vertex_position = float4(i.pos, 1.0);
float4 vertex_color = i.col;
@@ -1251,7 +1298,7 @@ float4 PSMain(PSIn i) : SV_Target0
for (const std::string& d : m_tempDecls) ss << d;
for (const std::string& d : m_paramDecls) ss << d;
for (const std::string& i : m_instructions) ss << i;
ss << " return result_color;\n}\n";
ss << " return QD3D12ARB_ApplyFog(result_color, i.fog.x);\n}\n";
return ss.str();
}
};
@@ -1749,4 +1796,4 @@ GLboolean APIENTRY glIsProgramARB(GLuint program)
return (g_vertexPrograms.find(program) != g_vertexPrograms.end() ||
g_fragmentPrograms.find(program) != g_fragmentPrograms.end()) ? GL_TRUE : GL_FALSE;
}
}