Permalink
Browse files

Minor uniform cleanup

  • Loading branch information...
hrydgard committed Dec 8, 2017
1 parent 2afb671 commit 4a0c2ad6831a53f615429547815611f6c3c48605
@@ -114,27 +114,27 @@ void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipView
}
if (dirtyUniforms & DIRTY_FOGCOEF) {
float fogcoef_stencil[2] = {
float fogcoef[2] = {
getFloat24(gstate.fog1),
getFloat24(gstate.fog2),
};
if (my_isinf(fogcoef_stencil[1])) {
if (my_isinf(fogcoef[1])) {
// not really sure what a sensible value might be.
fogcoef_stencil[1] = fogcoef_stencil[1] < 0.0f ? -10000.0f : 10000.0f;
} else if (my_isnan(fogcoef_stencil[1])) {
fogcoef[1] = fogcoef[1] < 0.0f ? -10000.0f : 10000.0f;
} else if (my_isnan(fogcoef[1])) {
// Workaround for https://github.com/hrydgard/ppsspp/issues/5384#issuecomment-38365988
// Just put the fog far away at a large finite distance.
// Infinities and NaNs are rather unpredictable in shaders on many GPUs
// so it's best to just make it a sane calculation.
fogcoef_stencil[0] = 100000.0f;
fogcoef_stencil[1] = 1.0f;
fogcoef[0] = 100000.0f;
fogcoef[1] = 1.0f;
}
#ifndef MOBILE_DEVICE
else if (my_isnanorinf(fogcoef_stencil[1]) || my_isnanorinf(fogcoef_stencil[0])) {
ERROR_LOG_REPORT_ONCE(fognan, G3D, "Unhandled fog NaN/INF combo: %f %f", fogcoef_stencil[0], fogcoef_stencil[1]);
else if (my_isnanorinf(fogcoef[1]) || my_isnanorinf(fogcoef[0])) {
ERROR_LOG_REPORT_ONCE(fognan, G3D, "Unhandled fog NaN/INF combo: %f %f", fogcoef[0], fogcoef[1]);
}
#endif
CopyFloat2(ub->fogCoef, fogcoef_stencil);
CopyFloat2(ub->fogCoef, fogcoef);
}
if (dirtyUniforms & DIRTY_STENCILREPLACEVALUE) {
@@ -50,7 +50,8 @@ R"( mat4 proj_mtx;
mat3x4 tex_mtx;
vec4 uvscaleoffset;
vec4 depthRange;
vec3 fogcoef_stencilreplace;
vec2 fogcoef;
float stencilReplace;
vec4 matambientalpha;
int spline_count_u;
int spline_count_v;
@@ -75,7 +76,8 @@ R"( float4x4 u_proj;
float4x3 u_tex;
float4 u_uvscaleoffset;
float4 u_depthRange;
float3 u_fogcoef_stencilreplace;
float2 u_fogcoef;
float u_stencilReplaceValue;
float4 u_matambientalpha;
int u_spline_count_u;
int u_spline_count_v;
@@ -437,7 +437,7 @@ bool GenerateFragmentShaderHLSL(const FShaderID &id, char *buffer, ShaderLanguag
if (stencilToAlpha != REPLACE_ALPHA_NO) {
switch (replaceAlphaWithStencilType) {
case STENCIL_VALUE_UNIFORM:
replacedAlpha = (lang == HLSL_D3D11 || lang == HLSL_D3D11_LEVEL9) ? "u_fogcoef_stencilreplace.z" : "u_stencilReplaceValue";
replacedAlpha = "u_stencilReplaceValue";
break;
case STENCIL_VALUE_ZERO:
@@ -796,11 +796,7 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
// Compute fogdepth
if (enableFog) {
if (lang == HLSL_D3D11 || lang == HLSL_D3D11_LEVEL9) {
WRITE(p, " Out.v_fogdepth = (viewPos.z + u_fogcoef_stencilreplace.x) * u_fogcoef_stencilreplace.y;\n");
} else {
WRITE(p, " Out.v_fogdepth = (viewPos.z + u_fogcoef.x) * u_fogcoef.y;\n");
}
WRITE(p, " Out.v_fogdepth = (viewPos.z + u_fogcoef.x) * u_fogcoef.y;\n");
}
}
@@ -387,7 +387,7 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer) {
if (stencilToAlpha != REPLACE_ALPHA_NO) {
switch (replaceAlphaWithStencilType) {
case STENCIL_VALUE_UNIFORM:
replacedAlpha = "base.fogcoef_stencilreplace.z";
replacedAlpha = "base.stencilReplace";
break;
case STENCIL_VALUE_ZERO:
@@ -693,7 +693,7 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer, bool *use
// Compute fogdepth
if (enableFog)
WRITE(p, " v_fogdepth = (viewPos.z + base.fogcoef_stencilreplace.x) * base.fogcoef_stencilreplace.y;\n");
WRITE(p, " v_fogdepth = (viewPos.z + base.fogcoef.x) * base.fogcoef.y;\n");
}
WRITE(p, "}\n");
return true;

0 comments on commit 4a0c2ad

Please sign in to comment.