tree: 31e626c33094429f20ab2f5e0debe163f3f4e639 [path history] [tgz]
  1. GrClampedGradientEffect.cpp
  2. GrClampedGradientEffect.fp
  3. GrClampedGradientEffect.h
  4. GrGradientShader.cpp
  5. GrGradientShader.h
  6. GrLinearGradientLayout.cpp
  7. GrLinearGradientLayout.fp
  8. GrLinearGradientLayout.h
  9. GrRadialGradientLayout.cpp
  10. GrRadialGradientLayout.fp
  11. GrRadialGradientLayout.h
  12. GrSingleIntervalGradientColorizer.cpp
  13. GrSingleIntervalGradientColorizer.fp
  14. GrSingleIntervalGradientColorizer.h
  15. GrSweepGradientLayout.cpp
  16. GrSweepGradientLayout.fp
  17. GrSweepGradientLayout.h
  18. GrTiledGradientEffect.cpp
  19. GrTiledGradientEffect.fp
  20. GrTiledGradientEffect.h
  21. GrTwoPointConicalGradientLayout.cpp
  22. GrTwoPointConicalGradientLayout.fp
  23. GrTwoPointConicalGradientLayout.h
  24. README.md
src/gpu/gradients/README.md

Gradients on the GPU

Gradients can be thought of, at a very high level, as three pieces:

  1. A color interpolator that is one dimensional, returning a color for an input within the range [0.0, 1.0]. This obfuscates the the definition of specific color stops and how to wrap, tile, or clamp out of bound inputs. A color interpolator will be named GrYGradientColorizer
  2. A layout that converts from 2D geometry/position to the one dimensional domain of the color interpolator. This is how a linear or radial gradient distinguishes itself. When designing a new gradient, this is the component that you have to implement. A layout will generally be named GrXGradientLayout
  3. A master effect that composes the layout and color interpolator together. It is also responsible for implementing the clamping behavior that can be abstracted away from both the layout and colorization.

GrClampedGradientEffect handles clamped and decal tile modes, while GrTiledGradientEffect implements repeat and mirror tile modes. The GrClampedGradientEffect requires border colors to be specified outside of its colorizer child, but these border colors may be defined by the gradient color stops. Both of these master effects delegate calculating a t interpolant to a child process, perform their respective tile mode operations, and possibly convert the tiled t value (guaranteed to be within 0 and 1) into an output color using their child colorizer process.

Because of how child processors are currently defined, where they have a single half4 input and a single half4 output, their is a type mismatch between the 1D t value and the 4D inputs/outputs of the layout and colorizer processes. For now, the master effect assumes an untiled t is output in sk_OutColor.x by the layout and it tiles solely off of that value.

However, layouts can output a negative value in the w component to invalidate the gradient location (currently on the two point conical gradient does this). When invalidated, the master effect outputs transparent black and does not invoke the child processor. Other than this condition, any value in y, z, or w are passed into the colorizer unmodified. The colorizer should assume that the valid tiled t value is in sk_InColor.x and can safely ignore y, z, and w.

Currently there are color interpolators (colorizers) for analytic color cases (evaluated directly on the GPU) and sampling a generated texture map.

GrGradientShader provides static factory functions to create GrFragmentProcessor graphs that reproduce a particular SkGradientShader.