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.
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.
TEXTURE
: the shader will use texturesLIGHTS
: the shader employs lightingUBOS
: the shader use uniform buffer objects to store data (UBOS 1024) means that array has size 1024.TEXTURE_PACKER
: the shader integrates with the texture packer architectureCWL_V_TRANSFORMATION
: the shader uses the matricescamera_to_clip
,world_to_camera
andlocal_to_world
in the formCVL v
wherev
is a position in space andCWL
is the product of the matrices.camera_to_clip
: the transformation which takes the world as seen from the camera and applies effects like perspective to the view, since this is the last applied transform the resulting points are interepreted in clip spaceworld_to_camera
: the transformation which positions the world to make the camera be at the originlocal_to_world
: usually objects have thieir origin set to the center of the object, ie, when imported they will be at the origin, this matrix positions the model in the right place and correct orientiation
RIGGED_AND_ANIMATED
: the shader uses skeletal animation and requires bone weights along with animation matrices to operate correctly
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.
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);
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, <w_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);
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();
}