Consistent lighting clamping

This commit is contained in:
Jack Andersen 2019-01-29 10:14:34 -10:00
parent cf9062bba5
commit 89906be162
6 changed files with 18 additions and 14 deletions

View File

@ -77,14 +77,15 @@ FOG_STRUCT_GLSL
" {\n" " {\n"
" vec3 delta = mvPosIn - lights[i].pos.xyz;\n" " vec3 delta = mvPosIn - lights[i].pos.xyz;\n"
" float dist = length(delta);\n" " float dist = length(delta);\n"
" float angDot = clamp(dot(normalize(delta), lights[i].dir.xyz), 0.0, 1.0);\n" " vec3 deltaNorm = delta / dist;\n"
" float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.0);\n"
" float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n" " float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n"
" lights[i].linAtt[1] * dist +\n" " lights[i].linAtt[1] * dist +\n"
" lights[i].linAtt[0]);\n" " lights[i].linAtt[0]);\n"
" float angAtt = lights[i].angAtt[2] * angDot * angDot +\n" " float angAtt = lights[i].angAtt[2] * angDot * angDot +\n"
" lights[i].angAtt[1] * angDot +\n" " lights[i].angAtt[1] * angDot +\n"
" lights[i].angAtt[0];\n" " lights[i].angAtt[0];\n"
" ret += lights[i].color * angAtt * att * clamp(dot(normalize(-delta), mvNormIn), 0.0, 1.0);\n" " ret += lights[i].color * angAtt * att * max(dot(-deltaNorm, mvNormIn), 0.0);\n"
" }\n" " }\n"
" \n" " \n"
" return clamp(ret, 0.0, 1.0);\n" " return clamp(ret, 0.0, 1.0);\n"
@ -127,31 +128,33 @@ static std::string_view LightingShadowGLSL =
" \n" " \n"
" vec3 delta = mvPosIn - lights[0].pos.xyz;\n" " vec3 delta = mvPosIn - lights[0].pos.xyz;\n"
" float dist = length(delta);\n" " float dist = length(delta);\n"
" float angDot = clamp(dot(normalize(delta), lights[0].dir.xyz), 0.0, 1.0);\n" " vec3 deltaNorm = delta / dist;\n"
" float angDot = max(dot(deltaNorm, lights[0].dir.xyz), 0.0);\n"
" float att = 1.0 / (lights[0].linAtt[2] * dist * dist +\n" " float att = 1.0 / (lights[0].linAtt[2] * dist * dist +\n"
" lights[0].linAtt[1] * dist +\n" " lights[0].linAtt[1] * dist +\n"
" lights[0].linAtt[0]);\n" " lights[0].linAtt[0]);\n"
" float angAtt = lights[0].angAtt[2] * angDot * angDot +\n" " float angAtt = lights[0].angAtt[2] * angDot * angDot +\n"
" lights[0].angAtt[1] * angDot +\n" " lights[0].angAtt[1] * angDot +\n"
" lights[0].angAtt[0];\n" " lights[0].angAtt[0];\n"
" ret += lights[0].color * clamp(angAtt, 0.0, 1.0) * att * clamp(dot(normalize(-delta), mvNormIn), 0.0, 1.0) *\n" " ret += lights[0].color * angAtt * att * max(dot(-deltaNorm, mvNormIn), 0.0) *\n"
" texture(extTex7, shadowUV).r;\n" " texture(extTex7, shadowUV).r;\n"
" \n" " \n"
" for (int i=1 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n" " for (int i=1 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
" {\n" " {\n"
" vec3 delta = mvPosIn - lights[i].pos.xyz;\n" " vec3 delta = mvPosIn - lights[i].pos.xyz;\n"
" float dist = length(delta);\n" " float dist = length(delta);\n"
" float angDot = clamp(dot(normalize(delta), lights[i].dir.xyz), 0.0, 1.0);\n" " vec3 deltaNorm = delta / dist;\n"
" float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.0);\n"
" float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n" " float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n"
" lights[i].linAtt[1] * dist +\n" " lights[i].linAtt[1] * dist +\n"
" lights[i].linAtt[0]);\n" " lights[i].linAtt[0]);\n"
" float angAtt = lights[i].angAtt[2] * angDot * angDot +\n" " float angAtt = lights[i].angAtt[2] * angDot * angDot +\n"
" lights[i].angAtt[1] * angDot +\n" " lights[i].angAtt[1] * angDot +\n"
" lights[i].angAtt[0];\n" " lights[i].angAtt[0];\n"
" ret += lights[i].color * clamp(angAtt, 0.0, 1.0) * att * clamp(dot(normalize(-delta), mvNormIn), 0.0, 1.0);\n" " ret += lights[i].color * angAtt * att * max(dot(-deltaNorm, mvNormIn), 0.0);\n"
" }\n" " }\n"
" \n" " \n"
" return ret;\n" " return clamp(ret, 0.0, 1.0);\n"
"}\n"sv; "}\n"sv;
static std::string_view MainPostGLSL = static std::string_view MainPostGLSL =

View File

@ -86,7 +86,7 @@ FOG_STRUCT_HLSL
" ret += lights[i].color * angAtt * att * saturate(dot(normalize(-delta), mvNormIn));\n" " ret += lights[i].color * angAtt * att * saturate(dot(normalize(-delta), mvNormIn));\n"
" }\n" " }\n"
" \n" " \n"
" return ret;\n" " return saturate(ret);\n"
"}\n"sv; "}\n"sv;
static std::string_view LightingShadowHLSL = static std::string_view LightingShadowHLSL =

View File

@ -86,7 +86,7 @@ FOG_STRUCT_METAL
" ret += lu.lights[i].color * angAtt * att * saturate(dot(normalize(-delta), mvNormIn));\n" " ret += lu.lights[i].color * angAtt * att * saturate(dot(normalize(-delta), mvNormIn));\n"
" }\n" " }\n"
" \n" " \n"
" return ret;\n" " return saturate(ret);\n"
"}\n"sv; "}\n"sv;
static std::string_view LightingShadowMetal = static std::string_view LightingShadowMetal =

View File

@ -203,17 +203,18 @@ static const char* FS =
" {\n" " {\n"
" vec3 delta = mvPosIn - lights[i].pos.xyz;\n" " vec3 delta = mvPosIn - lights[i].pos.xyz;\n"
" float dist = length(delta);\n" " float dist = length(delta);\n"
" float angDot = clamp(dot(normalize(delta).xyz, lights[i].dir.xyz), 0.0, 1.0);\n" " vec3 deltaNorm = delta / dist;\n"
" float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.0);\n"
" float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n" " float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n"
" lights[i].linAtt[1] * dist +\n" " lights[i].linAtt[1] * dist +\n"
" lights[i].linAtt[0]);\n" " lights[i].linAtt[0]);\n"
" float angAtt = lights[i].angAtt[2] * angDot * angDot +\n" " float angAtt = lights[i].angAtt[2] * angDot * angDot +\n"
" lights[i].angAtt[1] * angDot +\n" " lights[i].angAtt[1] * angDot +\n"
" lights[i].angAtt[0];\n" " lights[i].angAtt[0];\n"
" ret += lights[i].color * angAtt * att * clamp(dot(normalize(-delta).xyz, mvNormIn), 0.0, 1.0);\n" " ret += lights[i].color * angAtt * att * max(dot(-deltaNorm, mvNormIn), 0.0);\n"
" }\n" " }\n"
" \n" " \n"
" return ret;\n" " return clamp(ret, 0.0, 1.0);\n"
"}\n" "}\n"
"\n" "\n"
"struct VertToFrag\n" "struct VertToFrag\n"

View File

@ -249,7 +249,7 @@ static const char* FS =
" ret += lights[i].color * angAtt * att * saturate(dot(normalize(-delta), mvNormIn));\n" " ret += lights[i].color * angAtt * att * saturate(dot(normalize(-delta), mvNormIn));\n"
" }\n" " }\n"
" \n" " \n"
" return ret;\n" " return saturate(ret);\n"
"}\n" "}\n"
"\n" "\n"
"struct VertToFrag\n" "struct VertToFrag\n"

View File

@ -233,7 +233,7 @@ static const char* FS =
" ret += lu.lights[i].color * angAtt * att * saturate(dot(normalize(-delta), mvNormIn));\n" " ret += lu.lights[i].color * angAtt * att * saturate(dot(normalize(-delta), mvNormIn));\n"
" }\n" " }\n"
" \n" " \n"
" return ret;\n" " return saturate(ret);\n"
"}\n" "}\n"
"\n" "\n"
"struct VertToFrag\n" "struct VertToFrag\n"