Skip to content

Latest commit

 

History

History
171 lines (120 loc) · 4.3 KB

language.md

File metadata and controls

171 lines (120 loc) · 4.3 KB

TheHolyShadingLanguage

Table Of Content

Introduction

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.

Data Types

Integers:

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

Floating-points:

  • float (32 bit)
  • double (64 bit)

Vectors:

  • vec2
  • dvec2
  • vec3
  • dvec3
  • vec4
  • dvec4

Matrices:

  • mat3
  • dmat3
  • mat4
  • dmat4

Vector and Matrix types prefixed with d are 64 bit floats and those without the prefix are 32 bit floats.

NOTE:

All 64 bit types are currently unsupported

Pipeline Layout

For a shader stage to function you need to define variables and associate those variables to the input data.

Layout Types:
  • in
  • out
  • UniformBuffer
  • Sampler1D
  • Sampler2D
  • Sampler3D

Input And Output Layout:

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

Uniforms

Vulkan
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

OpenGL
layout (binding = <N>) <uniform_type> <type> <name>

Where N is the location number of the uniform.

List of supported Uniform Types

Builtin

Variables

Name Type Shader
Position Output Vertex
PointSize Input Vertex
VertexID Input Vertex
InstanceID Input Vertex
FragCoord Input Fragment
FragDepth Output Fragment
Usage:
<in/out> <type> <name> = <builtin_name>;

out vec4 pos = Position;
in vec4 fragCoord = FragCoord;

More info in SPIR-V Documentation

Functions

SPIR-V Extended Instructions for a list of builtin functions.

Example

Simple example with a vertex and fragment stage that renders a textured model.

Vertex Shader:

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;
}

Fragment Shader

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;
}