Commit ff6ce4c6 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Use clamp() instead of max() for calculating the clamped cosine in the…

wined3d: Use clamp() instead of max() for calculating the clamped cosine in the ffp lighting calculations. On typical hardware, the clamp() would be an instruction modifier, while the max() would need an extra instruction.
parent 725b069e
......@@ -4940,7 +4940,7 @@ static void shader_glsl_ffp_vertex_lighting(struct wined3d_shader_buffer *buffer
if (!settings->normal)
break;
shader_addline(buffer, "dir = normalize(dir);\n");
shader_addline(buffer, "diffuse += (max(0.0, dot(dir, normal))"
shader_addline(buffer, "diffuse += (clamp(dot(dir, normal), 0.0, 1.0)"
" * gl_LightSource[%u].diffuse.xyz) / att;\n", i);
if (settings->localviewer)
shader_addline(buffer, "t = dot(normal, normalize(dir - normalize(ec_pos.xyz)));\n");
......@@ -4965,7 +4965,7 @@ static void shader_glsl_ffp_vertex_lighting(struct wined3d_shader_buffer *buffer
shader_addline(buffer, "ambient += gl_LightSource[%u].ambient.xyz * att;\n", i);
if (!settings->normal)
break;
shader_addline(buffer, "diffuse += (max(0.0, dot(dir, normal))"
shader_addline(buffer, "diffuse += (clamp(dot(dir, normal), 0.0, 1.0)"
" * gl_LightSource[%u].diffuse.xyz) * att;\n", i);
if (settings->localviewer)
shader_addline(buffer, "t = dot(normal, normalize(dir - normalize(ec_pos.xyz)));\n");
......@@ -4980,7 +4980,8 @@ static void shader_glsl_ffp_vertex_lighting(struct wined3d_shader_buffer *buffer
if (!settings->normal)
break;
shader_addline(buffer, "dir = normalize(gl_LightSource[%u].position.xyz);\n", i);
shader_addline(buffer, "diffuse += max(0.0, dot(dir, normal)) * gl_LightSource[%u].diffuse.xyz;\n", i);
shader_addline(buffer, "diffuse += clamp(dot(dir, normal), 0.0, 1.0)"
" * gl_LightSource[%u].diffuse.xyz;\n", i);
shader_addline(buffer, "t = dot(normal, gl_LightSource[%u].halfVector.xyz);\n", i);
shader_addline(buffer, "if (t > 0.0) specular += pow(t, gl_FrontMaterial.shininess)"
" * gl_LightSource[%u].specular;\n", i);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment