Browse Source

Shaders: clamp shininess factor in Phong to minimize artifacts.

I feel this makes the shader code unnecessarily slow to handle bad
parameters. But eh, until I actually benchmark, I shouldn't be making
assumptions.
pull/362/head
Vladimír Vondruš 7 years ago
parent
commit
8d98f1161e
  1. 5
      doc/changelog.dox
  2. 2
      src/Magnum/Shaders/Phong.frag

5
doc/changelog.dox

@ -292,6 +292,11 @@ See also:
also with @ref Corrade::Containers::ArrayView,
@ref Corrade::Containers::StridedArrayView and friends
@subsubsection changelog-latest-changes-shaders Shaders library
- @ref Shaders::Phong now clamps the specular factor to minimize artifacts
when shininess is near zero
@subsubsection changelog-latest-changes-texturetools TextureTools library
- @ref TextureTools::distanceField() was updated to work on ES3 SwiftShader

2
src/Magnum/Shaders/Phong.frag

@ -181,7 +181,7 @@ void main() {
/* Add specular color, if needed */
if(intensity > 0.001) {
highp vec3 reflection = reflect(-normalizedLightDirection, normalizedTransformedNormal);
mediump float specularity = pow(max(0.0, dot(normalize(cameraDirection), reflection)), shininess);
mediump float specularity = clamp(pow(max(0.0, dot(normalize(cameraDirection), reflection)), shininess), 0.0, 1.0);
color += vec4(finalSpecularColor.rgb*specularity, finalSpecularColor.a);
}
}

Loading…
Cancel
Save