shader standard

shader_standard

a system which enforces a standard for naming variables in shaders, this is so that we can have systems such as the shader cache, and it can integrate much easier with more assumptions.

catalog

Note that for each shader program listed here you can explore standard.py to specifically to see what shader files are used to build it.

terminology

stuff that applies to many shaders

TEXTURE PACKERS

For every texture packer you need to at least assign the bounding boxes:

    TexturePacker texture_packer(textures_directory, output_dir, container_side_length);

    shader_cache.set_uniform(ShaderType::CWL_V_TRANSFORMATION_TEXTURE_PACKED,
                             ShaderUniformVariable::PACKED_TEXTURE_BOUNDING_BOXES,
                             texture_packer.texture_index_to_bounding_box);

the texture packer allows you to add new textures dynamically when you do a call to regenerate, you will have to refresh all existing geometry though, see how observatory does this until this is better documented.

CWL_V SHADERS

You'll want to update their uniforms one time per frame like this:

shader_cache.set_uniform(ShaderType::CWL_V_TRANSFORMATION_TEXTURE_PACKED, ShaderUniformVariable::CAMERA_TO_CLIP, projection);
shader_cache.set_uniform(ShaderType::CWL_V_TRANSFORMATION_TEXTURE_PACKED, ShaderUniformVariable::WORLD_TO_CAMERA, origin_view); shader_cache.set_uniform(ShaderType::CWL_V_TRANSFORMATION_TEXTURE_PACKED, ShaderUniformVariable::LOCAL_TO_WORLD, local_to_world);

UBO SHADERS

First assign all your matrices like this as a uniform buffer object

GLuint ltw_matrices_gl_name;
glm::mat4 ltw_matrices[1024];

// initialize all matrices to identity matrices
for (int i = 0; i < 1024; ++i) {
    ltw_matrices[i] = glm::mat4(1.0f);
}

glGenBuffers(1, &ltw_matrices_gl_name);
glBindBuffer(GL_UNIFORM_BUFFER, ltw_matrices_gl_name);
glBufferData(GL_UNIFORM_BUFFER, sizeof(ltw_matrices), ltw_matrices, GL_STATIC_DRAW);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, ltw_matrices_gl_name);

Then feel free to modify the ltw_matrices variable, each object you draw will contain an index into this array, and thus all you have to do is be sure you put the transform matrix you want to apply to a specific object in the right place, and then one time per frame be sure to upload the new matrices:

glBindBuffer(GL_UNIFORM_BUFFER, ltw_matrices_gl_name);
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(ltw_matrices), ltw_matrices);
glBindBuffer(GL_UNIFORM_BUFFER, 0);

notes for specific shaders

TRANSFORM_V_WITH_SIGNED_DISTANCE_FIELD_TEXT

To set up this shader be sure to do the following:

void setup_sdf_shader_uniforms(ShaderCache &shader_cache) {
    auto text_color = glm::vec3(0.5, 0.5, 1);
    float char_width = 0.5;
    float edge_transition = 0.1;

    shader_cache.use_shader_program(ShaderType::TRANSFORM_V_WITH_SIGNED_DISTANCE_FIELD_TEXT);

    shader_cache.set_uniform(ShaderType::TRANSFORM_V_WITH_SIGNED_DISTANCE_FIELD_TEXT, ShaderUniformVariable::TRANSFORM,
                             glm::mat4(1.0f));

    shader_cache.set_uniform(ShaderType::TRANSFORM_V_WITH_SIGNED_DISTANCE_FIELD_TEXT, ShaderUniformVariable::RGB_COLOR,
                             text_color);

    shader_cache.set_uniform(ShaderType::TRANSFORM_V_WITH_SIGNED_DISTANCE_FIELD_TEXT,
                             ShaderUniformVariable::CHARACTER_WIDTH, char_width);

    shader_cache.set_uniform(ShaderType::TRANSFORM_V_WITH_SIGNED_DISTANCE_FIELD_TEXT,
                             ShaderUniformVariable::EDGE_TRANSITION_WIDTH, edge_transition);
    shader_cache.stop_using_shader_program();
}

TEXTURE_PACKER_RIGGED_AND_ANIMATED_CWL_V_TRANSFORMATION_UBOS_1024_WITH_TEXTURES_AND_MULTIPLE_LIGHTS

TEXTURE_PACKER_RIGGED_AND_ANIMATED_CWL_V_TRANSFORMATION_UBOS_2048_WITH_TEXTURES_AND_MULTIPLE_LIGHTS

TEXTURE_PACKER_RIGGED_AND_ANIMATED_CWL_V_TRANSFORMATION_UBOS_4096_WITH_TEXTURES_AND_MULTIPLE_LIGHTS

TEXTURE_PACKER_RIGGED_AND_ANIMATED_CWL_V_TRANSFORMATION_WITH_TEXTURES

TEXTURE_PACKER_CWL_V_TRANSFORMATION_UBOS_1024_AMBIENT_AND_DIFFUSE_LIGHTING

TEXTURE_PACKER_CWL_V_TRANSFORMATION_UBOS_1024_MULTIPLE_LIGHTS

TEXTURE_PACKER_CWL_V_TRANSFORMATION_UBOS_1024

RIGGED_AND_ANIMATED_CWL_V_TRANSFORMATION_WITH_TEXTURES

CWL_V_TRANSFORMATION_WITH_SOLID_COLOR

CWL_V_TRANSFORMATION_USING_UBOS_WITH_SOLID_COLOR

CWL_V_TRANSFORMATION_WITH_TEXTURES

TRANSFORM_V_WITH_TEXTURES

CWL_V_TRANSFORMATION_WITH_TEXTURES_AMBIENT_LIGHTING

CWL_V_TRANSFORMATION_WITH_TEXTURES_AMBIENT_AND_DIFFUSE_LIGHTING

SKYBOX

ABSOLUTE_POSITION_WITH_SOLID_COLOR

TEXT

ABSOLUTE_POSITION_WITH_COLORED_VERTEX

ABSOLUTE_POSITION_TEXTURED

source code

git submodule add git@github.com:cpp-toolbox/shader_standard.git


edit this page