-
Notifications
You must be signed in to change notification settings - Fork 4
Uniform Variables
Creating shaders is inevitable part of the game development process. Something that can be very annoying about shaders is making sure uniform variables are set properly. To solve this, many built in Crynn components will automatically set uniforms for the shaders. The reference sheet below shows all the built in uniforms you can access. If you meet the dependency, the uniform will automatically be set, and can be used without worry.
Remember that these names are case sensitive inside the shader. They follow pascalCase.
Variable Description | GLSL Uniform Name | Dependency |
---|---|---|
A 3D vector with the world space camera position. | uniform vec3 cameraPos |
An instance of the Camera class. |
A 4x4 matrix containing the model matrix of the object being rendered. |
uniform mat4 model |
An instance of the MeshRenderer class. |
A float variable with the time since the program started in seconds. |
uniform float time |
Set automatically. |
A 3x3 matrix containing the world space normal matrix of the mesh you are rendering. |
uniform mat4 normalMatrix |
An instance of the MeshRenderer class. |
To Set your own uniforms, override the BeforeUpdate
function. You have to set these using a shader, but you can also use Shader::SetCurrent functions if you wish to not store a reference to it. You can get access to it by inheriting the CrynnObject
class.
Simple Example:
class SetUniform : CrynnObject //Inherit from to access Update
{
public:
//the frame deltaTime will be passed to this function
void Update(float deltaTime) override
{
//Check shader docs for more info
//set a uniform variable called "deltaTimeUnfiform" in the currently bound shader.
Shader::SetFloatCurrent("deltaTimeUniform", deltaTime);
}
}