Skip to content

Shaders

rust edited this page Mar 28, 2024 · 9 revisions
  1. GLSL
  2. Attributes and Uniforms

A shader is a set of programs that run on the graphics card (GPU). one or more shaders must exist in order to render models into a 3D scene. Each Model can be associated with a different shader in order to create a particular visual effect. For example models colored with textures need a shader that handles texture mapping coordinates.

Currently the vu engine uses spir-v shaders compiled from GLSL. These are located in vu/assets/shaders

Attributes and Uniforms

Shader programs expect attribute and uniform data. The data. comes from the 3D Assets loaded by the vu engine.

Shader assets are comprised of program code for each pipeline stage. For example:

  • tex3D.vert # Vertex shader code. A program that runs for each models vertex.
  • tex3D.frag # Fragment shader code. A program that runs for each screen pixel.

Shader code must be compiled into SPIR-V byte code *.spv files using a shader compile tool like glslc.

  • glslc tex3D.vert -o tex3D.vert.spv
  • glslc tex3D.frag -o tex3D.frag.spv

The vu engine matches the attributes and uniforms expected by the shader with with the application assets using yaml shader configuration files vu/assets/shaders/*.shd. The shader configuration tells the engine about the shaders attributes, uniforms, and data types. The names and order of the attributes and uniforms must match the shader code. The configuration file is a custom data file unique to the vu engine, eg:

# tex3D is a shader uses a texture for model color.
name: tex3D
pass: 3D
stages: [ vert, frag ]
attrs:
    - { name: position, data: vec3, scope: vertex }
    - { name: texcoord, data: vec2, scope: vertex }
uniforms:
    - { name: proj,  data: mat4,    scope: scene    }
    - { name: view,  data: mat4,    scope: scene    }
    - { name: color, data: sampler, scope: material }
    - { name: model, data: mat4,    scope: model    }

The supported shader attributes and uniforms can be seen in vu/load/shd.go and can be modified or extended by updating the public data mapping files.

Clone this wiki locally