mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
PixelShaderGen: Perform some of the fog calculations with integers.
This commit is contained in:
@ -291,7 +291,8 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
|
||||
DeclareUniform(out, ApiType, C_INDTEXSCALE, "float4", I_INDTEXSCALE"[2]");
|
||||
DeclareUniform(out, ApiType, C_INDTEXMTX, "int4", I_INDTEXMTX"[6]");
|
||||
DeclareUniform(out, ApiType, C_FOGCOLOR, "int4", I_FOGCOLOR);
|
||||
DeclareUniform(out, ApiType, C_FOG, "float4", I_FOG"[2]");
|
||||
DeclareUniform(out, ApiType, C_FOGI, "int4", I_FOGI"[1]");
|
||||
DeclareUniform(out, ApiType, C_FOGF, "float4", I_FOGF"[2]");
|
||||
|
||||
// For pixel lighting - TODO: Should only be defined when per pixel lighting is enabled!
|
||||
DeclareUniform(out, ApiType, C_PLIGHT_COLORS, "int4", I_PLIGHT_COLORS"[8]");
|
||||
@ -1049,33 +1050,36 @@ static inline void WriteFog(T& out, pixel_shader_uid_data& uid_data)
|
||||
uid_data.fog_proj = bpmem.fog.c_proj_fsel.proj;
|
||||
|
||||
out.SetConstantsUsed(C_FOGCOLOR, C_FOGCOLOR);
|
||||
out.SetConstantsUsed(C_FOG, C_FOG);
|
||||
out.SetConstantsUsed(C_FOGI, C_FOGI);
|
||||
out.SetConstantsUsed(C_FOGF, C_FOGF+1);
|
||||
if (bpmem.fog.c_proj_fsel.proj == 0)
|
||||
{
|
||||
// perspective
|
||||
// ze = A/(B - (Zs >> B_SHF)
|
||||
out.Write("\tfloat ze = " I_FOG"[0].x / (" I_FOG"[0].y - (float(zCoord) / 16777215.0 / " I_FOG"[0].w));\n");
|
||||
// TODO: Verify that we want to drop lower bits here! (currently taken over from software renderer)
|
||||
out.Write("\tfloat ze = (" I_FOGF"[1].x * 16777215.0) / float(" I_FOGI"[0].y - (zCoord >> " I_FOGI"[0].w));\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// orthographic
|
||||
// ze = a*Zs (here, no B_SHF)
|
||||
out.Write("\tfloat ze = " I_FOG"[0].x * float(zCoord) / 16777215.0;\n");
|
||||
out.Write("\tfloat ze = " I_FOGF"[1].x * float(zCoord) / 16777215.0;\n");
|
||||
}
|
||||
|
||||
// x_adjust = sqrt((x-center)^2 + k^2)/k
|
||||
// ze *= x_adjust
|
||||
// this is completely theoretical as the real hardware seems to use a table intead of calculating the values.
|
||||
// TODO Instead of this theoretical calculation, we should use the
|
||||
// coefficient table given in the fog range BP registers!
|
||||
uid_data.fog_RangeBaseEnabled = bpmem.fogRange.Base.Enabled;
|
||||
if (bpmem.fogRange.Base.Enabled)
|
||||
{
|
||||
out.SetConstantsUsed(C_FOG+1, C_FOG+1);
|
||||
out.Write("\tfloat x_adjust = (2.0 * (clipPos.x / " I_FOG"[1].y)) - 1.0 - " I_FOG"[1].x;\n");
|
||||
out.Write("\tx_adjust = sqrt(x_adjust * x_adjust + " I_FOG"[1].z * " I_FOG"[1].z) / " I_FOG"[1].z;\n");
|
||||
out.SetConstantsUsed(C_FOGF, C_FOGF);
|
||||
out.Write("\tfloat x_adjust = (2.0 * (clipPos.x / " I_FOGF"[0].y)) - 1.0 - " I_FOGF"[0].x;\n");
|
||||
out.Write("\tx_adjust = sqrt(x_adjust * x_adjust + " I_FOGF"[0].z * " I_FOGF"[0].z) / " I_FOGF"[0].z;\n");
|
||||
out.Write("\tze *= x_adjust;\n");
|
||||
}
|
||||
|
||||
out.Write("\tfloat fog = clamp(ze - " I_FOG"[0].z, 0.0, 1.0);\n");
|
||||
out.Write("\tfloat fog = clamp(ze - " I_FOGF"[1].z, 0.0, 1.0);\n");
|
||||
|
||||
if (bpmem.fog.c_proj_fsel.fsel > 3)
|
||||
{
|
||||
|
Reference in New Issue
Block a user