wined3d: Use dot() instead of length() in shader_glsl_nrm().

As Eric Anholt pointed out, using length() here is suboptimal. It essentially
translates into "inversesqrt(dot(x, x));", but needs to handle the case of
zero-length vectors, much like nrm.
oldstable
Henri Verbeet 2011-01-24 11:19:40 +01:00 committed by Alexandre Julliard
parent 010e285b88
commit a50546e563
1 changed files with 5 additions and 3 deletions

View File

@ -2314,16 +2314,18 @@ static void shader_glsl_nrm(const struct wined3d_shader_instruction *ins)
mask_size = shader_glsl_get_write_mask_size(write_mask);
shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src_param);
shader_addline(buffer, "tmp0.x = length(%s);\n", src_param.param_str);
shader_addline(buffer, "tmp0.x = dot(%s, %s);\n",
src_param.param_str, src_param.param_str);
shader_glsl_append_dst(buffer, ins);
if (mask_size > 1)
{
shader_addline(buffer, "tmp0.x == 0.0 ? vec%u(0.0) : (%s / tmp0.x));\n",
shader_addline(buffer, "tmp0.x == 0.0 ? vec%u(0.0) : (%s * inversesqrt(tmp0.x)));\n",
mask_size, src_param.param_str);
}
else
{
shader_addline(buffer, "tmp0.x == 0.0 ? 0.0 : (%s / tmp0.x));\n",
shader_addline(buffer, "tmp0.x == 0.0 ? 0.0 : (%s * inversesqrt(tmp0.x)));\n",
src_param.param_str);
}
}