mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-09-09 11:05:56 +00:00
Further refactoring attempt
This commit is contained in:
parent
f419a40558
commit
0c34ca7b89
1 changed files with 32 additions and 23 deletions
|
@ -22,25 +22,48 @@ static void GenerateLightShader(ShaderCode& object, const LightingUidData& uid_d
|
|||
object.Write(" float3 ldir = " LIGHT_POS ".xyz - pos.xyz;\n", LIGHT_POS_PARAMS(index));
|
||||
object.Write(" float dist2 = dot(ldir, ldir);\n"
|
||||
" float dist = sqrt(dist2);\n"
|
||||
" ldir = ldir / dist;\n");
|
||||
" ldir = ldir / dist;\n\n");
|
||||
|
||||
switch (diffuse_func)
|
||||
{
|
||||
case DiffuseFunc::None:
|
||||
object.Write(" float diffuse = 1.0;\n\n");
|
||||
break;
|
||||
case DiffuseFunc::Sign:
|
||||
default: // Confirmed by hardware testing that invalid values use this
|
||||
object.Write(" float diffuse = dot(ldir, _normal);\n\n");
|
||||
break;
|
||||
case DiffuseFunc::Clamp:
|
||||
object.Write(" float diffuse = max(0.0, dot(ldir, _normal));\n\n");
|
||||
break;
|
||||
}
|
||||
|
||||
switch (attn_func)
|
||||
{
|
||||
case AttenuationFunc::None:
|
||||
if (diffuse_func == DiffuseFunc::None)
|
||||
{
|
||||
object.Write(" float attn = 1.0;\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
object.Write(" lacc.{} += int{}(round(255 * sign(diffuse)));\n", swizzle,
|
||||
swizzle_components);
|
||||
object.Write(" }}\n");
|
||||
return; // Return, not break!
|
||||
}
|
||||
case AttenuationFunc::Dir:
|
||||
object.Write(" float attn = 1.0;\n");
|
||||
break;
|
||||
case AttenuationFunc::Spec:
|
||||
object.Write(" float cosine = 0.0;\n"
|
||||
" // Ensure that the object is facing the light\n"
|
||||
" if (dot(_normal, ldir) >= 0.0) {{\n"
|
||||
" // Compute the cosine of the angle between the object normal\n"
|
||||
" // and the half-angle direction for the viewer\n"
|
||||
" // (assuming the half-angle direction is a unit vector)\n"
|
||||
" cosine = max(0.0, dot(_normal, " LIGHT_DIR ".xyz));\n",
|
||||
" cosine = max(0.0, dot(_normal, -" LIGHT_DIR ".xyz));\n",
|
||||
LIGHT_DIR_PARAMS(index));
|
||||
object.Write(" }}\n"
|
||||
" // Specular lights use the angle for the denominator as well\n"
|
||||
object.Write(" // Specular lights use the angle for the denominator as well\n"
|
||||
" dist = cosine;\n"
|
||||
" dist2 = dist * dist;\n");
|
||||
break;
|
||||
|
@ -76,20 +99,6 @@ static void GenerateLightShader(ShaderCode& object, const LightingUidData& uid_d
|
|||
" float attn = max(0.0f, numerator / denominator);\n");
|
||||
}
|
||||
|
||||
switch (diffuse_func)
|
||||
{
|
||||
case DiffuseFunc::None:
|
||||
object.Write(" float diffuse = 1.0;\n");
|
||||
break;
|
||||
case DiffuseFunc::Sign:
|
||||
default: // Confirmed by hardware testing that invalid values use this
|
||||
object.Write(" float diffuse = dot(ldir, _normal);\n");
|
||||
break;
|
||||
case DiffuseFunc::Clamp:
|
||||
object.Write(" float diffuse = max(0.0, dot(ldir, _normal));\n");
|
||||
break;
|
||||
}
|
||||
|
||||
object.Write(" lacc.{} += int{}(round(attn * diffuse * float{}(" LIGHT_COL ")));\n", swizzle,
|
||||
swizzle_components, swizzle_components, LIGHT_COL_PARAMS(index, swizzle));
|
||||
object.Write(" }}\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue