Skip to content

Custom Shaders

Adrien Givry edited this page Aug 9, 2024 · 3 revisions

1. Overload GLSL Flavor

Overload utilizes a custom GLSL flavor as its shading language, which includes the following features:

  • #include statements
  • Fragment and vertex section specification

1.1. File Extensions

Overload shaders can have the following file extensions:

  • .ovfx: A compilable shader file that contains (or includes) both a vertex and a fragment shader.
  • .ovfxh: A partial shader file (non-compilable) that can be included within another shader file.

1.2. Include Statements

Overload shaders can be included using the #include statement.

To include engine shaders, prefix the file name with a colon (:):

#include ":Shaders/Vertex/Basic.ovfxh"

If the colon is omitted, the shader loader will search within the user project's assets:

#include "Shaders/MyCustomShader.ovfxh"

1.3. Fragment/Vertex Sections

A complete shader (.ovfx) must include both vertex and fragment sections, which are specified using the #shader vertex and #shader fragment directives.

#shader vertex
#version 430 core

// Vertex shader code

#shader fragment
#version 430 core

// Fragment shader code

2. Complete Shader Example

// Unlit.ovfx

#shader vertex
#version 430 core

#include ":Shaders/Common/Buffers/EngineUBO.ovfxh"
#include ":Shaders/Common/Utils.ovfxh"

layout (location = 0) in vec3 geo_Pos;
layout (location = 1) in vec2 geo_TexCoords;

out VS_OUT
{
    vec3 FragPos;
    vec2 TexCoords;
} vs_out;

void main()
{
    vs_out.FragPos = vec3(ubo_Model * vec4(geo_Pos, 1.0));
    vs_out.TexCoords = geo_TexCoords;

    gl_Position = ubo_Projection * ubo_View * vec4(vs_out.FragPos, 1.0);
}

#shader fragment
#version 430 core

#include ":Shaders/Common/Buffers/EngineUBO.ovfxh"
#include ":Shaders/Common/Utils.ovfxh"

in VS_OUT
{
    vec3 FragPos;
    vec2 TexCoords;
} fs_in;

uniform vec4 u_Diffuse = vec4(1.0);
uniform sampler2D u_DiffuseMap;
uniform vec2 u_TextureTiling = vec2(1.0);
uniform vec2 u_TextureOffset = vec2(0.0);

out vec4 FRAGMENT_COLOR;

void main()
{
    vec2 texCoords = TileAndOffsetTexCoords(fs_in.TexCoords, u_TextureTiling, u_TextureOffset);
    FRAGMENT_COLOR = texture(u_DiffuseMap, texCoords) * u_Diffuse;
}

Here's the corrected version:

3. Visual Studio Code Syntax Highlighting

To add syntax highlighting for .ovfx and .ovfxh files in Visual Studio Code:

  1. Open the Command Palette (CTRL + Shift + P).
  2. Search for and select "Preferences: Open User Settings (JSON)".
  3. Edit or create a files.associations entry in the settings file:
"files.associations": {
    "*.ovfx": "glsl",
    "*.ovfxh": "glsl"
},