dev-docs/RFCs/v7.2/layer-shader-hook-rfc.md
With the new shader hooks system in luma.gl v7.1, it is now possible to create public APIs for shaders. This RFC proposes adding a set of standard shader hooks to the official deck.gl layers.
One of the biggest pain points in subclassing a layer is injecting custom code into its shaders. Currently, this is done in one of two ways:
While the second approach is a little more robust by dynamically adding custom code to the base shader, the following issues remain:
decl, main-start, main-end) are very limiting. If the subclass wishes to manipulate intermediate values in the shader, e.g. offset in ScatterplotLayer's vertex shader before projection is performed, custom code must be injected using key strings in the base shader, which is even more fragile.Publicly documented shader hooks make it possible to:
The basic implementation of the GPU data filter discards any fragment from objects that are filtered out. However, some users (including kepler.gl) wish to have more control of the output appearance, e.g. circles grow/shrink as they enter/exit a time window; render the objects that are filtered out with a different color; etc. This requires layers to expose shader hooks for object dimensions and colors.
Brushing is based on mouse position and the position of the current object. To implement it in a way that is reusable across multiple layers, it requires the layers to expose shader hooks for object positions.
Instead of filling an area (triangle) with a solid color, fill it with a tiling pattern. The pattern would be supplied with a sprite image, with additional attributes controlling the size and the orientation. This is needed in rendering realistic maps e.g. a polygon or path that represents "crosswalk." This requires layers to expose shader hooks for object colors and texture coordinates.
Shader hook names follow the pattern DECKGL_<action>_<target>.
DECKGL_ prefixFILTER: if the hook can modify the input value(s).worldPosition, pixelSize.Provides a single interface for a collection of vertex shader variables.
vec3 worldPosition - the primary world space position associated with the current vertex.vec3 worldPositionAlt - the secondary world space position associated with the current vertex, available if the shader renders an edge-like instance.vec4 position - the common space position of this vertex. Only available after projection.vec4 normal - the common space normal of this vertex.vec2 uv - the uv of this vertex.Semantic meanings of worldPosition:
getPolygon)bounds)getPath)getSourcePosition)getPosition)Semantic meanings of worldPositionAlt:
getTargetPosition)getPath)getPolygon)Provides a single interface for a collection of fragment shader variables.
vec2 uv - the uv of this fragment.Modify the commonspace dimensions associated with the current vertex, called before projection.
Semantic meanings:
Modify the clipspace position (gl_Position) of the current vertex, called after projection.
Modify the color of the current vertex, called after projection.
Modify the color of the current fragment.