summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/VertexShaderGen.cpp
diff options
context:
space:
mode:
authorTilka <tilkax@gmail.com>2024-10-12 19:49:48 +0100
committerGitHub <noreply@github.com>2024-10-12 19:49:48 +0100
commitd43c6dc555fea0b0ec84d05779a62dc876b70bf4 (patch)
treef7e24ca237cdda8cde7e611ee52806fdea96292a /Source/Core/VideoCommon/VertexShaderGen.cpp
parent35ec2e97a8ea90730cb33eceec701f81597f98f7 (diff)
parent937bb2aa2e12b635ba328af8de7c9a5d5963d084 (diff)
Merge pull request #13074 from Pokechu22/normal-cache
Cache normals in addition to binormals and tangents
Diffstat (limited to 'Source/Core/VideoCommon/VertexShaderGen.cpp')
-rw-r--r--Source/Core/VideoCommon/VertexShaderGen.cpp67
1 files changed, 27 insertions, 40 deletions
diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp
index 9f854f2d9e..4a46834c14 100644
--- a/Source/Core/VideoCommon/VertexShaderGen.cpp
+++ b/Source/Core/VideoCommon/VertexShaderGen.cpp
@@ -312,56 +312,43 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
out.Write("int posidx = int(posmtx.r);\n"
"float4 P0 = " I_TRANSFORMMATRICES "[posidx];\n"
"float4 P1 = " I_TRANSFORMMATRICES "[posidx + 1];\n"
- "float4 P2 = " I_TRANSFORMMATRICES "[posidx + 2];\n");
- if ((uid_data->components & VB_HAS_NORMAL) != 0)
- {
- out.Write("int normidx = posidx & 31;\n"
- "float3 N0 = " I_NORMALMATRICES "[normidx].xyz;\n"
- "float3 N1 = " I_NORMALMATRICES "[normidx + 1].xyz;\n"
- "float3 N2 = " I_NORMALMATRICES "[normidx + 2].xyz;\n");
- }
+ "float4 P2 = " I_TRANSFORMMATRICES "[posidx + 2];\n"
+ "int normidx = posidx & 31;\n"
+ "float3 N0 = " I_NORMALMATRICES "[normidx].xyz;\n"
+ "float3 N1 = " I_NORMALMATRICES "[normidx + 1].xyz;\n"
+ "float3 N2 = " I_NORMALMATRICES "[normidx + 2].xyz;\n");
}
else
{
// One shared matrix
out.Write("float4 P0 = " I_POSNORMALMATRIX "[0];\n"
"float4 P1 = " I_POSNORMALMATRIX "[1];\n"
- "float4 P2 = " I_POSNORMALMATRIX "[2];\n");
- if ((uid_data->components & VB_HAS_NORMAL) != 0)
- {
- out.Write("float3 N0 = " I_POSNORMALMATRIX "[3].xyz;\n"
- "float3 N1 = " I_POSNORMALMATRIX "[4].xyz;\n"
- "float3 N2 = " I_POSNORMALMATRIX "[5].xyz;\n");
- }
+ "float4 P2 = " I_POSNORMALMATRIX "[2];\n"
+ "float3 N0 = " I_POSNORMALMATRIX "[3].xyz;\n"
+ "float3 N1 = " I_POSNORMALMATRIX "[4].xyz;\n"
+ "float3 N2 = " I_POSNORMALMATRIX "[5].xyz;\n");
}
out.Write("// Multiply the position vector by the position matrix\n"
"float4 pos = float4(dot(P0, rawpos), dot(P1, rawpos), dot(P2, rawpos), 1.0);\n");
- if ((uid_data->components & VB_HAS_NORMAL) != 0)
- {
- if ((uid_data->components & VB_HAS_TANGENT) == 0)
- out.Write("float3 rawtangent = " I_CACHED_TANGENT ".xyz;\n");
- if ((uid_data->components & VB_HAS_BINORMAL) == 0)
- out.Write("float3 rawbinormal = " I_CACHED_BINORMAL ".xyz;\n");
-
- // The scale of the transform matrix is used to control the size of the emboss map effect, by
- // changing the scale of the transformed binormals (which only get used by emboss map texgens).
- // By normalising the first transformed normal (which is used by lighting calculations and needs
- // to be unit length), the same transform matrix can do double duty, scaling for emboss mapping,
- // and not scaling for lighting.
- out.Write("float3 _normal = normalize(float3(dot(N0, rawnormal), dot(N1, rawnormal), dot(N2, "
- "rawnormal)));\n"
- "float3 _tangent = float3(dot(N0, rawtangent), dot(N1, rawtangent), dot(N2, "
- "rawtangent));\n"
- "float3 _binormal = float3(dot(N0, rawbinormal), dot(N1, rawbinormal), dot(N2, "
- "rawbinormal));\n");
- }
- else
- {
- out.Write("float3 _normal = float3(0.0, 0.0, 0.0);\n");
- out.Write("float3 _binormal = float3(0.0, 0.0, 0.0);\n");
- out.Write("float3 _tangent = float3(0.0, 0.0, 0.0);\n");
- }
+ if ((uid_data->components & VB_HAS_NORMAL) == 0)
+ out.Write("float3 rawnormal = " I_CACHED_NORMAL ".xyz;\n");
+ if ((uid_data->components & VB_HAS_TANGENT) == 0)
+ out.Write("float3 rawtangent = " I_CACHED_TANGENT ".xyz;\n");
+ if ((uid_data->components & VB_HAS_BINORMAL) == 0)
+ out.Write("float3 rawbinormal = " I_CACHED_BINORMAL ".xyz;\n");
+
+ // The scale of the transform matrix is used to control the size of the emboss map effect, by
+ // changing the scale of the transformed binormals (which only get used by emboss map texgens).
+ // By normalising the first transformed normal (which is used by lighting calculations and needs
+ // to be unit length), the same transform matrix can do double duty, scaling for emboss mapping,
+ // and not scaling for lighting.
+ out.Write("float3 _normal = normalize(float3(dot(N0, rawnormal), dot(N1, rawnormal), dot(N2, "
+ "rawnormal)));\n"
+ "float3 _tangent = float3(dot(N0, rawtangent), dot(N1, rawtangent), dot(N2, "
+ "rawtangent));\n"
+ "float3 _binormal = float3(dot(N0, rawbinormal), dot(N1, rawbinormal), dot(N2, "
+ "rawbinormal));\n");
out.Write("o.pos = float4(dot(" I_PROJECTION "[0], pos), dot(" I_PROJECTION
"[1], pos), dot(" I_PROJECTION "[2], pos), dot(" I_PROJECTION "[3], pos));\n");