This commit is contained in:
Henrik Rydgård
2022-08-01 12:11:42 +02:00
parent 73fc9fb520
commit 7b7d16d2fb
3 changed files with 29 additions and 8 deletions
+1 -1
View File
@@ -93,7 +93,7 @@ void ShaderLanguageDesc::Init(ShaderLanguage lang) {
fragColor0 = "outfragment.target";
fragColor1 = "outfragment.target1";
} else {
fragColor0 = "target";
fragColor0 = "outfragment.target";
}
varying_fs = "in";
varying_vs = "out";
+20 -6
View File
@@ -275,6 +275,13 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
WRITE(p, " float depth : SV_Depth;\n");
}
WRITE(p, "};\n");
} else if (compat.shaderLanguage == HLSL_D3D9) {
WRITE(p, "struct PS_OUT {\n");
WRITE(p, " vec4 target : COLOR;\n");
if (writeDepth) {
WRITE(p, " float depth : DEPTH;\n");
}
WRITE(p, "};\n");
}
} else if (ShaderLanguageIsOpenGL(compat.shaderLanguage)) {
if ((shaderDepal || colorWriteMask) && gl_extensions.IsGLES) {
@@ -442,8 +449,12 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
WRITE(p, " float gl_FragDepth;\n");
}
} else if (compat.shaderLanguage == HLSL_D3D9) {
WRITE(p, "vec4 main( PS_IN In ) : COLOR {\n");
WRITE(p, "PS_OUT main( PS_IN In ) {\n");
WRITE(p, " PS_OUT outfragment;\n");
WRITE(p, " vec4 target;\n");
if (colorToDepth) {
WRITE(p, " float gl_FragDepth;\n");
}
} else {
WRITE(p, "void main() {\n");
}
@@ -1053,8 +1064,13 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
if (colorToDepth) {
DepthScaleFactors factors = GetDepthScaleFactors();
WRITE(p, " highp float depthValue = float(uint(%s.x * 32.0) | (uint(%s.y * 64.0) << 5) | (uint(%s.z * 32.0) << 11)) / 65535.0;\n", "v", "v", "v"); // compat.fragColor0, compat.fragColor0, compat.fragColor0);
WRITE(p, " gl_FragDepth = (depthValue / %f) - %f;\n", factors.scale / 65535.0f, factors.offset);
if (compat.bitwiseOps) {
WRITE(p, " highp float depthValue = float(uint(%s.x * 32.0) | (uint(%s.y * 64.0) << 5) | (uint(%s.z * 32.0) << 11)) / 65535.0;\n", "v", "v", "v"); // compat.fragColor0, compat.fragColor0, compat.fragColor0);
} else {
// D3D9-compatible alternative
WRITE(p, " highp float depthValue = (floor(%s.x * 32.0) + floor(%s.y * 64.0) * 32.0 + floor(%s.z * 32.0) * 2048.0) / 65535.0;\n", "v", "v", "v"); // compat.fragColor0, compat.fragColor0, compat.fragColor0);
}
WRITE(p, " gl_FragDepth = (depthValue / %f) + %f;\n", factors.scale / 65535.0f, factors.offset);
}
if (gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT)) {
@@ -1081,13 +1097,11 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
WRITE(p, " gl_FragDepth = gl_FragCoord.z;\n");
}
if (compat.shaderLanguage == HLSL_D3D11) {
if (compat.shaderLanguage == HLSL_D3D11 || compat.shaderLanguage == HLSL_D3D9) {
if (writeDepth) {
WRITE(p, " outfragment.depth = gl_FragDepth;\n");
}
WRITE(p, " return outfragment;\n");
} else if (compat.shaderLanguage == HLSL_D3D9) {
WRITE(p, " return target;\n");
}
WRITE(p, "}\n");
+8 -1
View File
@@ -197,7 +197,14 @@ void DrawEngineDX9::ApplyDrawState(int prim) {
ConvertStencilFuncState(stencilState);
// Set Stencil/Depth
if (gstate.isModeClear()) {
if (gstate_c.renderMode == FB_MODE_COLOR_TO_DEPTH) {
// Enforce plain depth writing.
dxstate.depthTest.enable();
dxstate.depthFunc.set(D3DCMP_ALWAYS);
dxstate.depthWrite.set(true);
dxstate.stencilTest.disable();
} else if (gstate.isModeClear()) {
// Depth Test
dxstate.depthTest.enable();
dxstate.depthFunc.set(D3DCMP_ALWAYS);