GPU: Correct software transform projection.

Now reading the new fog value.
This commit is contained in:
Unknown W. Brackets 2021-10-24 12:27:47 -07:00
parent 4ec75de0e7
commit e688bb2cdf
3 changed files with 20 additions and 11 deletions

View file

@ -213,6 +213,7 @@ void SoftwareTransform::Decode(int prim, u32 vertType, const DecVtxFormat &decVt
// TODO: Write to a flexible buffer, we don't always need all four components.
TransformedVertex &vert = transformed[index];
reader.ReadPos(vert.pos);
vert.posw = 1.0f;
if (reader.hasColor0()) {
if (provokeIndOffset != 0 && index + provokeIndOffset < maxIndex) {
@ -429,12 +430,9 @@ void SoftwareTransform::Decode(int prim, u32 vertType, const DecVtxFormat &decVt
fogCoef = (v[2] + fog_end) * fog_slope;
// TODO: Write to a flexible buffer, we don't always need all four components.
Vec4f projected;
Vec3ByMatrix44(projected.AsArray(), v, projMatrix_.m);
Vec3f viewportPos = projected.xyz() / projected.w;
memcpy(&transformed[index].x, viewportPos.AsArray(), 3 * sizeof(float));
transformed[index].posw = fogCoef;
memcpy(&transformed[index].u, uv, 3 * sizeof(float));
Vec3ByMatrix44(transformed[index].pos, v, projMatrix_.m);
transformed[index].fog = fogCoef;
memcpy(&transformed[index].uv, uv, 3 * sizeof(float));
transformed[index].color0_32 = c0.ToRGBA();
transformed[index].color1_32 = c1.ToRGBA();

View file

@ -236,11 +236,12 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag
if (useHWTransform)
WRITE(p, "layout (location = %d) in vec3 position;\n", (int)PspAttributeLocation::POSITION);
else
// we pass the fog coord in w
WRITE(p, "layout (location = %d) in vec4 position;\n", (int)PspAttributeLocation::POSITION);
if (useHWTransform && hasNormal)
WRITE(p, "layout (location = %d) in vec3 normal;\n", (int)PspAttributeLocation::NORMAL);
if (!useHWTransform && enableFog)
WRITE(p, "layout (location = %d) in float fog;\n", (int)PspAttributeLocation::NORMAL);
if (doTexture && hasTexcoord) {
if (!useHWTransform && doTextureTransform && !isModeThrough) {
@ -386,6 +387,9 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag
if (lmode) {
WRITE(p, " vec3 color1 : COLOR1;\n");
}
if (enableFog) {
WRITE(p, " float fog : NORMAL;\n");
}
WRITE(p, "};\n");
}
@ -435,6 +439,10 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag
WRITE(p, "%s mediump vec3 normal;\n", compat.attribute);
*attrMask |= 1 << ATTR_NORMAL;
}
if (!useHWTransform && enableFog) {
WRITE(p, "%s highp float fog;\n", compat.attribute);
*attrMask |= 1 << ATTR_NORMAL;
}
if (doTexture && hasTexcoord) {
if (!useHWTransform && doTextureTransform && !isModeThrough) {
@ -789,7 +797,7 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag
WRITE(p, " %sv_color1 = splat3(0.0);\n", compat.vsOutPrefix);
}
if (enableFog) {
WRITE(p, " %sv_fogdepth = position.w;\n", compat.vsOutPrefix);
WRITE(p, " %sv_fogdepth = fog;\n", compat.vsOutPrefix);
}
if (isModeThrough) {
WRITE(p, " vec4 outPos = mul(u_proj_through, vec4(position.xyz, 1.0));\n");
@ -804,9 +812,9 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag
// The viewport is used in this case, so need to compensate for that.
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
WRITE(p, " vec4 outPos = depthRoundZVP(mul(displayRotation, vec4(position.xyz, 1.0)));\n");
WRITE(p, " vec4 outPos = depthRoundZVP(mul(displayRotation, position));\n");
} else {
WRITE(p, " vec4 outPos = mul(displayRotation, vec4(position.xyz, 1.0));\n");
WRITE(p, " vec4 outPos = mul(displayRotation, position);\n");
}
}
} else {

View file

@ -85,7 +85,10 @@ LinkedShader::LinkedShader(GLRenderManager *render, VShaderID VSID, Shader *vs,
std::vector<GLRProgram::Semantic> semantics;
semantics.push_back({ ATTR_POSITION, "position" });
semantics.push_back({ ATTR_TEXCOORD, "texcoord" });
if (useHWTransform_)
semantics.push_back({ ATTR_NORMAL, "normal" });
else
semantics.push_back({ ATTR_NORMAL, "fog" });
semantics.push_back({ ATTR_W1, "w1" });
semantics.push_back({ ATTR_W2, "w2" });
semantics.push_back({ ATTR_COLOR0, "color0" });