Search
⌃K
🟪

Shaders

Explanation

Introduction

Byte uses a shading language very similar to GLSL with a few tiny differences. All relevant information will be declared here.

Default types

  • 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 numbers
  • vec3u: 3 component vector of 32bit unsigned integer numbers
  • mat4f: 4x4 matrix of 32bit floating point numbers

Declarations

Array declaration

//known size
float32[SIZE] name;
//unknown size
float32[] name;

Functions

Sampling

To sample an image use the Sample functions
Sample(TextureReference, vec2f): To sample a two dimensional texture with normalized coordinates

Writing

Write(ImageReference, vec2u): To write to a two dimensional image with un-normalized coordinates.

Shader types

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

Vertex shader specify how to modify a vertex for wind movement, skeletal animation, etc.

Intrinsic functions

  • GetVertexPosition()
  • GetVertexNormal()
  • GetVertexTextureCoordinates()
  • GetCameraViewMatrix()
  • GetProjectionMatrix()

Surface

Surface shaders specify how to shade a surface.

Intrisinc functions

  • GetSurfaceViewSpaceNormal()
  • GetSurfaceViewPosition()
  • GetSurfaceBarycenter()

Compute

Compute shaders can execute almost any kind of task, and are specially useful to process arbitrary/user defined data.

Intrinsic functions

  • GetExecutionId()
    • Returns a vec3u with the thread id.
  • GetDispatchSize()
    • Returns a vec3u with the dispatch size.

Miss

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

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)

Intrinsic functions

  • 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]