Fix through mode differences

This commit is contained in:
Henrik Rydgård 2020-11-01 12:07:40 +01:00
parent 9b3662460c
commit ba7c2e856b
3 changed files with 28 additions and 19 deletions

View File

@ -59,7 +59,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
bool flipNormal = id.Bit(VS_BIT_NORM_REVERSE);
int ls0 = id.Bits(VS_BIT_LS0, 2);
int ls1 = id.Bits(VS_BIT_LS1, 2);
bool enableBones = id.Bit(VS_BIT_ENABLE_BONES);
bool enableBones = id.Bit(VS_BIT_ENABLE_BONES) && !useHWTransform;
bool enableLighting = id.Bit(VS_BIT_LIGHTING_ENABLE);
int matUpdate = id.Bits(VS_BIT_MATERIAL_UPDATE, 3);
@ -212,7 +212,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
}
// only software transform supplies color1 as vertex data
if (lmode) {
WRITE(p, " vec4 color1 : COLOR1;\n");
WRITE(p, " vec3 color1 : COLOR1;\n");
}
WRITE(p, "};\n");
}
@ -355,7 +355,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
if (hasColor) {
WRITE(p, " vec4 color0 = In.color0;\n");
if (lmode && !useHWTransform) {
WRITE(p, " vec4 color1 = In.color1;\n");
WRITE(p, " vec3 color1 = In.color1;\n");
}
}
if (hasNormal) {
@ -382,7 +382,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
if (hasColor) {
WRITE(p, " Out.v_color0 = color0;\n");
if (lmode)
WRITE(p, " Out.v_color1 = color1.rgb;\n");
WRITE(p, " Out.v_color1 = color1;\n");
} else {
WRITE(p, " Out.v_color0 = u_matambientalpha;\n");
if (lmode)
@ -392,12 +392,12 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
WRITE(p, " Out.v_fogdepth = position.w;\n");
}
if (isModeThrough) {
WRITE(p, " vec4 outPos = mul(u_proj_through, vec4(In.position.xyz, 1.0));\n");
WRITE(p, " vec4 outPos = mul(u_proj_through, vec4(position.xyz, 1.0));\n");
} else {
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
WRITE(p, " vec4 outPos = depthRoundZVP(mul(u_proj, vec4(In.position.xyz, 1.0)));\n");
WRITE(p, " vec4 outPos = depthRoundZVP(mul(u_proj, vec4(position.xyz, 1.0)));\n");
} else {
WRITE(p, " vec4 outPos = mul(u_proj, vec4(In.position.xyz, 1.0));\n");
WRITE(p, " vec4 outPos = mul(u_proj, vec4(position.xyz, 1.0));\n");
}
}
} else {

View File

@ -200,7 +200,7 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const ShaderLan
bool flipNormal = id.Bit(VS_BIT_NORM_REVERSE);
int ls0 = id.Bits(VS_BIT_LS0, 2);
int ls1 = id.Bits(VS_BIT_LS1, 2);
bool enableBones = id.Bit(VS_BIT_ENABLE_BONES);
bool enableBones = id.Bit(VS_BIT_ENABLE_BONES) && useHWTransform;
bool enableLighting = id.Bit(VS_BIT_LIGHTING_ENABLE);
int matUpdate = id.Bits(VS_BIT_MATERIAL_UPDATE, 3);
@ -404,7 +404,7 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const ShaderLan
}
// only software transform supplies color1 as vertex data
if (lmode) {
WRITE(p, " vec4 color1 : COLOR1;\n");
WRITE(p, " vec3 color1 : COLOR1;\n");
}
WRITE(p, "};\n");
}
@ -738,7 +738,7 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const ShaderLan
if (hasColor) {
WRITE(p, " vec4 color0 = In.color0;\n");
if (lmode && !useHWTransform) {
WRITE(p, " vec4 color1 = In.color1;\n");
WRITE(p, " vec3 color1 = In.color1;\n");
}
}
if (hasNormal) {
@ -758,25 +758,25 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const ShaderLan
// Simple pass-through of vertex data to fragment shader
if (doTexture) {
if (texCoordInVec3) {
WRITE(p, " v_texcoord = texcoord;\n");
WRITE(p, " %sv_texcoord = texcoord;\n", compat.vsOutPrefix);
} else {
WRITE(p, " v_texcoord = vec3(texcoord, 1.0);\n");
WRITE(p, " %sv_texcoord = vec3(texcoord, 1.0);\n", compat.vsOutPrefix);
}
}
if (hasColor) {
WRITE(p, " v_color0 = color0;\n");
WRITE(p, " %sv_color0 = color0;\n", compat.vsOutPrefix);
if (lmode)
WRITE(p, " v_color1 = color1;\n");
WRITE(p, " %sv_color1 = color1;\n", compat.vsOutPrefix);
} else {
WRITE(p, " v_color0 = u_matambientalpha;\n");
WRITE(p, " %sv_color0 = u_matambientalpha;\n", compat.vsOutPrefix);
if (lmode)
WRITE(p, " v_color1 = vec3(0.0);\n");
WRITE(p, " %sv_color1 = vec3(0.0);\n", compat.vsOutPrefix);
}
if (enableFog) {
WRITE(p, " v_fogdepth = position.w;\n");
WRITE(p, " %sv_fogdepth = position.w;\n", compat.vsOutPrefix);
}
if (isModeThrough) {
WRITE(p, " vec4 outPos = u_proj_through * vec4(position.xyz, 1.0);\n");
WRITE(p, " vec4 outPos = mul(u_proj_through, vec4(position.xyz, 1.0));\n");
} else {
// The viewport is used in this case, so need to compensate for that.
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {

View File

@ -191,8 +191,17 @@ bool TestShaderGenerators() {
id.d[0] = bottom;
id.d[1] = top;
// The generated bits need some adjustment:
// We don't use these bits in the HLSL shader generator.
id.SetBits(VS_BIT_WEIGHT_FMTSCALE, 2, 0);
// If mode is through, we won't do hardware transform.
if (id.Bit(VS_BIT_IS_THROUGH)) {
id.SetBit(VS_BIT_USE_HW_TRANSFORM, 0);
}
if (!id.Bit(VS_BIT_USE_HW_TRANSFORM)) {
id.SetBit(VS_BIT_ENABLE_BONES, 0);
}
bool generateSuccess[numLanguages]{};
std::string genErrorString[numLanguages];
@ -223,7 +232,7 @@ bool TestShaderGenerators() {
if (generateSuccess[j]) {
std::string errorMessage;
if (!TestCompileShader(buffer[j], languages[j], true, &errorMessage)) {
printf("Error compiling vertex shader:\n\n%s\n\n%s\n", LineNumberString(buffer[j]).c_str(), errorMessage.c_str());
printf("Error compiling vertex shader %d:\n\n%s\n\n%s\n", (int)j, LineNumberString(buffer[j]).c_str(), errorMessage.c_str());
return false;
}
successes++;