Fix the mip bias to take the texture depth and sampling offset into account.

This commit is contained in:
Henrik Rydgård 2022-07-25 21:13:56 +02:00
parent 2cb9e09ad3
commit d7aa3ee486
2 changed files with 4 additions and 4 deletions

View file

@ -560,11 +560,10 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
}
} else {
if (texture3D) {
WRITE(p, " float bias = u_mipBias * 1.0;\n");
if (doTextureProjection) {
WRITE(p, " vec4 t = %sProj(tex, vec4(%s.xy, bias, %s.z));\n", compat.texture, texcoord, texcoord);
WRITE(p, " vec4 t = %sProj(tex, vec4(%s.xy, u_mipBias, %s.z));\n", compat.texture, texcoord, texcoord);
} else {
WRITE(p, " vec4 t = %s(tex, vec3(%s.xy, bias));\n", compat.texture, texcoord);
WRITE(p, " vec4 t = %s(tex, vec3(%s.xy, u_mipBias));\n", compat.texture, texcoord);
}
} else {
if (doTextureProjection) {

View file

@ -105,7 +105,8 @@ void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipView
ub->texClampOffset[0] = gstate_c.curTextureXOffset * invW;
ub->texClampOffset[1] = gstate_c.curTextureYOffset * invH;
ub->mipBias = (float)gstate.getTexLevelOffset16() * (1.0 / 16.0f);
float mipBias = (float)gstate.getTexLevelOffset16() * (1.0 / 16.0f);
ub->mipBias = (mipBias + 0.5f) / (float)(gstate.getTextureMaxLevel() + 1);
}
if (dirtyUniforms & DIRTY_PROJMATRIX) {