🟪
Shaders
Explanation
Byte uses a shading language very similar to GLSL with a few tiny differences. All relevant information will be declared here.
- uint8: 8 bit unsigned integer
- uint16: 16 bit unsigned integer
- uint32: 32 bit unsigned integer
- uint64: 64 bit unsigned integer
- vec4f: 4 component vector of 32 bit floating point numbers
vec2u
: 2 component vector of 32bit unsigned integer numbersvec3u
: 3 component vector of 32bit unsigned integer numbersmat4f
: 4x4 matrix of 32bit floating point numbers
//known size
float32[SIZE] name;
//unknown size
float32[] name;
To sample an image use the
Sample
functionsSample(TextureReference, vec2f)
: To sample a two dimensional texture with normalized coordinatesWrite(ImageReference, vec2u)
: To write to a two dimensional image with un-normalized coordinates.Several types of shader environments are specified to tackle different kinds of workloads.
The different shader types will be converted to different shader backend types.
The following table shows what types of engine shaders can get translated into what backend shader types.
Shader type | Vertex | Fragment/PIxel | Task + Mesh | Compute | Ray Generation | Closest Hit | Any hit | Intersection | Miss |
---|---|---|---|---|---|---|---|---|---|
Vertex | |||||||||
Surface | |||||||||
Compute | |||||||||
Ray Generation | |||||||||
Miss |
Extra work on the rendering framework's behalf might have to be done in order to get some shader conversions to work for certain workloads. Refer to the render backend documentation for more information.
Vertex shader specify how to modify a vertex for wind movement, skeletal animation, etc.
- GetVertexPosition()
- GetVertexNormal()
- GetVertexTextureCoordinates()
- GetCameraViewMatrix()
- GetProjectionMatrix()
Surface shaders specify how to shade a surface.
- GetSurfaceViewSpaceNormal()
- GetSurfaceViewPosition()
- GetSurfaceBarycenter()
Compute shaders can execute almost any kind of task, and are specially useful to process arbitrary/user defined data.
- GetExecutionId()
- Returns a
vec3u
with the thread id.
- GetDispatchSize()
- Returns a
vec3u
with the dispatch size.
Miss shader are executed for pixels at the end of a render pass which have no information written. These are useful for paintings backgrounds such as skies, since their specific usage case allows them to be efficient and avoid overdraw.
Ray generation shaders define an operation to be executed for element in a 3d dispatch grid(similar to compute shaders, although their execution capabilities are more limited and specific)
- GetFragmentPosition()
- Returns a
vec2u
containing the current pixel position (assuming we are shooting rays from the screen, a more appropriate name may have to be chosen)
- GetFragmentNormalizedPosition()
- Returns a
vec2f
containing the current pixel position in normalized coordinates. [0, 1]
Last modified 1yr ago