Browse Source

Reverted interval in distancefield-related things.

1.0 is taken as shape center (white), 0.0 as shape surroundings (black).
It was unintuitive to have it reverted, updated documentation to make it
right.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
5c06009446
  1. 8
      src/Shaders/DistanceFieldVector.frag
  2. 8
      src/Shaders/DistanceFieldVector.h
  3. 6
      src/TextureTools/DistanceField.h

8
src/Shaders/DistanceFieldVector.frag

@ -32,12 +32,12 @@
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 1) uniform lowp vec4 color;
layout(location = 2) uniform lowp vec4 outlineColor;
layout(location = 3) uniform lowp vec2 outlineRange = vec2(0.5, 0.0);
layout(location = 3) uniform lowp vec2 outlineRange = vec2(0.5, 1.0);
layout(location = 4) uniform lowp float smoothness = 0.04;
#else
uniform lowp vec4 color;
uniform lowp vec4 outlineColor;
uniform lowp vec2 outlineRange = vec2(0.5, 0.0);
uniform lowp vec2 outlineRange = vec2(0.5, 1.0);
uniform lowp float smoothness = 0.04;
#endif
#else
@ -66,9 +66,9 @@ void main() {
fragmentColor = smoothstep(outlineRange.x-smoothness, outlineRange.x+smoothness, intensity)*color;
/* Outline */
if(outlineRange.x < outlineRange.y) {
if(outlineRange.x > outlineRange.y) {
lowp float mid = (outlineRange.x + outlineRange.y)/2.0;
lowp float half = (outlineRange.y - outlineRange.x)/2.0;
lowp float half = (outlineRange.x - outlineRange.y)/2.0;
fragmentColor += smoothstep(half+smoothness, half-smoothness, distance(mid, intensity))*outlineColor;
}
}

8
src/Shaders/DistanceFieldVector.h

@ -81,12 +81,12 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
* @return Pointer to self (for method chaining)
*
* Parameter @p start describes where fill ends and possible outline
* starts. Initial value is `0.5f`, smaller values will make the vector
* art look thinner, larger will make it look thicker.
* starts. Initial value is `0.5f`, larger values will make the vector
* art look thinner, smaller will make it look thicker.
*
* Parameter @p end describes where outline ends. If set to value
* smaller than @p start the outline is not drawn. Initial value is
* `0.0f`.
* larger than @p start the outline is not drawn. Initial value is
* `1.0f`.
*
* @see setOutlineColor()
*/

6
src/TextureTools/DistanceField.h

@ -56,9 +56,9 @@ foundation for features like outlining, glow or drop shadow essentialy for free.
For each pixel inside @p rectangle the algorithm looks at corresponding pixel in
@p input and tries to find nearest pixel of opposite color in area given by
@p radius. Signed distance between the points is then saved as value of given
pixel in @p output. Value of `0` means that the pixel was originally colored
white and nearest black pixel is farther than @p radius, value of `1` means that
the pixel was originally black and nearest white pixel is farther than
pixel in @p output. Value of `1.0` means that the pixel was originally colored
white and nearest black pixel is farther than @p radius, value of `0.0` means
that the pixel was originally black and nearest white pixel is farther than
@p radius. Values around `0.5` are around edges.
The resulting texture can be used with bilinear filtering. It can be converted

Loading…
Cancel
Save