TheHolyShadingLanguage is a shading language that compiles to SPIR-V for use in Vulkan or OpenGL (Since version 4.6)
Currently supported stages are Vertex and Fragment shaders.
- byte (8 bit)
- short (16 bit)
- int (32 bit)
- long (64 bit)
All integers are signed by default but can be set explicitly as signed or unsigned.
signed int var;
unsigned long var2;
- float (32 bit)
- double (64 bit)
- vec2
- dvec2
- vec3
- dvec3
- vec4
- dvec4
- mat3
- dmat3
- mat4
- dmat4
Vector and Matrix types prefixed with d
are 64 bit floats and those without the prefix are 32 bit floats.
All 64 bit types are currently unsupported
For a shader stage to function you need to define variables and associate those variables to the input data.
- in
- out
- UniformBuffer
- Sampler1D
- Sampler2D
- Sampler3D
layout (location = <N>, component = <M>) in <type> <name>
layout (location = <N>) out <type> <name>
Where N
is the shader binding location number and M
the component. component is optional and can be completely omitted.
Read more about vertex attributes: Vulkan, OpenGL
layout (binding = <N>, set = <M>) <uniform_type> <type> <name>
Where N
is the binding within DescriptorSet M
. set
is optional and can be completely omitted, it will default to 0.
List of supported Uniform Types
layout (binding = <N>) <uniform_type> <type> <name>
Where N
is the location number of the uniform.
List of supported Uniform Types
Name | Type | Shader |
---|---|---|
Position | Output | Vertex |
PointSize | Input | Vertex |
VertexID | Input | Vertex |
InstanceID | Input | Vertex |
FragCoord | Input | Fragment |
FragDepth | Output | Fragment |
<in/out> <type> <name> = <builtin_name>;
out vec4 pos = Position;
in vec4 fragCoord = FragCoord;
More info in SPIR-V Documentation
SPIR-V Extended Instructions for a list of builtin functions.
Simple example with a vertex and fragment stage that renders a textured model.
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 texCoord;
layout (location = 2) in vec4 color;
layout (location = 0) out vec2 texCoordToFrag;
layout (location = 1) out vec4 colorToFrag;
layout (binding = 0) UniformBuffer data {
mat4 model;
mat4 view;
mat4 proj;
};
layout (Position) out vec4 pos;
void main() {
pos = data.proj * data.view * data.model * vec4(position, 1);
colorToFrag = color;
texCoordToFrag = texCoord;
}
layout (location = 0) in vec2 texCoord;
layout (location = 1) in vec4 color;
layout (location = 0) out vec4 outColor;
layout (binding = 1) sampler2D sampler;
void main() {
outColor = texture(sampler, texCoord) * color;
}