Skip to main content

4.11) Shaders system

Shader Variables (uniforms)


You can also configure the variables (uniforms) that each shader will receive from the UI.

You can create your own variables primitives vars:

  • int
  • float
  • vec2
  • vec3
  • vec4
  • texture

Or you can select system uniforms:

  • delta_time (float)
  • execution_time (float)
  • scene (texture).

Additionally, geometry shaders (which only apply to Mesh3D) allow you to use system types such as diffuse or specular, with textures belonging to the particular model.

Postprocessing Shader Template


Below are empty templates for the postprocessing shader.

VertexShader:

#version 330 core

layout (location = 0) in vec4 vertex; // <vec2 position, vec2 texCoords>

out vec2 TexCoords;

uniform mat4 model;
uniform mat4 projection;

void main()
{
TexCoords = vec2(vertex.z, -vertex.w);
gl_Position = projection * model * vec4(vertex.xy, 0.0, 1.0);
}

FragmentShader:

#version 330 core

in vec2 TexCoords;

//out vec4 FragColor;

void main()
{
//FragColor = texture(sceneTexture, TexCoords);
}

Geometry Shader Template


Below are empty templates for the geometry shader.

VertexShader:

#version 330 core

layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;

out vec3 FragPos;
out vec3 Normal;
out vec2 TexCoords;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
FragPos = vec3(model * vec4(aPos, 1.0));
Normal = mat3(transpose(inverse(model))) * aNormal;
TexCoords = aTexCoords;

gl_Position = projection * view * vec4(FragPos, 1.0);
}

FragmentShader:

#version 330 core

//uniform sampler2D diffuse;

out vec4 FragColor;

in vec3 FragPos;
in vec3 Normal;
in vec2 TexCoords;

void main()
{
vec3 norm = normalize(Normal);
vec3 viewDir = normalize(viewPos - FragPos);

//FragColor = texture(diffuse, TexCoords);
}

Internal Shaders


You can find the shaders that Brakeza3D uses internally in the /GLSL folder.

Mesh/Object Shaders

ShaderFilesDescription
RenderRender.vs / Render.fsMesh3D forward rendering
OutlinerOutliner.vs / Outliner.fsOutliner for a selected object
ColorColor.vs / Color.fsRenders a Mesh3D with a given color
WireframeWireframe.vs / Wireframe.fsRenders vertices of a Mesh3D
PointsPoints.vs / Points.fsRenders vertices of a Mesh3D
Line3DLine3D.vs / Line3D.fsRenders 3D lines
LineLine.vs / Line.fsDraws a 2D line on screen
ImageImage.vs / Image.fsRenders an image on screen
ParticleParticle.vs / Particle.fsDraws a particle on screen; used by ParticleEmitter
ShadingShading.vs / Shading.fsRenders an object to a buffer to be used as a mask

Postprocessing / Scene Shaders

ShaderFilesDescription
DeepOfFieldDeepOfField.vs / DeepOfField.fsDepth of field effect
FOGFOG.vs / FOG.fsFog effect
DepthMapDepthMap.vs / DepthMap.fsDraws the depth map of the scene
TintTint.vs / Tint.fsColors the screen with a given color and alpha
BonesTransformsBonesTransforms.vsBone transform calculations for skeletal animation
GBufferGBuffer.vs / GBuffer.fsG-buffer pass for deferred rendering
LightingPassLightingPass.vs / LightingPass.fsHandles lighting computations for deferred pipeline
ShadowPassShadowPass.vs / ShadowPass.fsShadow mapping pass
ShadowPassDebugLightShadowPassDebugLight.vs / ShadowPassDebugLight.fsDebugging shadows visualization

If you know what you’re doing, you can freely manipulate the shaders as you see fit!