VideoCommon: Add comment explaining why only the first normal gets normalized

Co-authored-by: Scott Mansell <phiren@gmail.com>
This commit is contained in:
Pokechu22 2022-04-19 17:46:20 -07:00
parent 2a5c77f43f
commit 784079853d
3 changed files with 15 additions and 2 deletions

View File

@ -97,6 +97,11 @@ void TransformNormal(const InputVertexData* src, OutputVertexData* dst)
MultiplyVec3Mat33(src->normal[0], mat, dst->normal[0]);
MultiplyVec3Mat33(src->normal[1], mat, dst->normal[1]);
MultiplyVec3Mat33(src->normal[2], mat, dst->normal[2]);
// 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.
dst->normal[0].Normalize();
}

View File

@ -158,7 +158,11 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config
"o.pos = float4(dot(" I_PROJECTION "[0], pos), dot(" I_PROJECTION
"[1], pos), dot(" I_PROJECTION "[2], pos), dot(" I_PROJECTION "[3], pos));\n"
"\n"
"// Only the first normal gets normalized (TODO: why?)\n"
"// The scale of the transform matrix is used to control the size of the emboss map\n"
"// effect by changing the scale of the transformed binormals (which only get used by\n"
"// emboss map texgens). By normalising the first transformed normal (which is used\n"
"// by lighting calculations and needs to be unit length), the same transform matrix\n"
"// can do double duty, scaling for emboss mapping, and not scaling for lighting.\n"
"float3 _normal = float3(0.0, 0.0, 0.0);\n"
"if ((components & {}u) != 0u) // VB_HAS_NORMAL\n",
VB_HAS_NORMAL);

View File

@ -258,7 +258,11 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
if ((uid_data->components & VB_HAS_BINORMAL) == 0)
out.Write("float3 rawbinormal = " I_CACHED_BINORMAL ".xyz;\n");
// Only the first normal gets normalized (TODO: why?)
// 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, "