Note

All materials have static constant variables with the names of the uniforms associated with the material’s shaders. These should be used when making use of set_shader.

Material

struct glen::Material

Main material class that stores relevent information and functions about a particular material.

Subclassed by AO_BlurMaterial, AO_GBufferMaterial, AO_Material, BlinnDeferredMaterial, BlinnMaterial, BloomMaterial, CubeMapMaterial, DepthCubeMaterial, DepthMaterial, GaussianBlurMaterial, GBufferMaterial, HDRMaterial, LightMaterial

Public Functions

Material(const std::string &name, const std::string &vertex_shader, const std::string &fragment_shader)

Constructor.

Parameters
  • name: Name to give material.

  • vertex_shader: Path to the vertex shader. Should be a .vert file.

  • fragment_shader: Path to the fragment shader. Should be a .frag file.

Material(const std::string &name, const std::string &vertex_shader, const std::string &geometry_shader, const std::string &fragment_shader)

Constructor.

Parameters
  • name: Name to give material.

  • vertex_shader: Path to the vertex shader. Should be a .vert file.

  • fragment_shader: Path to the fragment shader. Should be a .frag file.

Material(const std::string &name, const char *vertex_shader, const char *fragment_shader)

Constructor.

Parameters
  • name: Name to give material.

  • vertex_shader: Path to the vertex shader. Should be a .vert file.

  • fragment_shader: Path to the fragment shader. Should be a .frag file.

Material(const std::string &name, const char *vertex_shader, const char *geometry_shader, const char *fragment_shader)

Constructor.

Parameters
  • name: Name to give material.

  • vertex_shader: Path to the vertex shader. Should be a .vert file.

  • geometry_shader: Path to the geometry shader. Should be a .geom file.

  • fragment_shader: Path to the fragment shader. Should be a .frag file.

Material(const Material &other) = delete

Use move instead constructor instead of copy constructor.

Material(Material &&other) noexcept

Move constructor.

Material &operator=(Material &&other) noexcept

Move assign.

~Material()

Destructor.

void use()

Tell OpenGL to use the shader program for this shader.

bool contains_uniform(const std::string uniform_name)

Return

True if shader program contains the specified uniform.

void update_lights(const std::vector<LightNode*> &light_nodes)

Iterate over all lights in light_nodes and update the material.

Parameters
  • light_nodes: The lights to iterate over.

void update_light_transform(const LightNode *light_node, const CameraNode *camera_node)

Update shader with new light position.

Parameters
  • light_node: The light to update with.

  • camera_node: The main viewing camera.

void bind_textures()

Ensure all textures associated with this material are ‘active’ in relation to OpenGL.

void unbind_textures()

Unbind textures.

void update_view(const CameraNode *cameraNode, const Node *node)

Update material with new camera position.

Parameters
  • cameraNode: The main viewing camera.

  • node: The node (usually a MeshNode for which the material is applied.

const GLuint program_id() const

Return

The shader program ID.

const std::string name() const

Return

The name of the shader.

const std::map<std::string, Uniform> &uniforms() const

Return

All uniforms of the shader associated with this material.

const GLuint num_uniforms() const

Return

The number of uniforms in the shader associated with this material.

const GLuint num_textures() const

Return

The number of texture slots available in the shader associated with this material.

void set_name(const std::string &name)

Parameters
  • name: The new name for the shader.

void set_sampler_color(const std::string &uniform_name, const glm::vec3 &color)

Provide a color to the shader in place of a texture.

Parameters
  • uniform_name: The name of the uniform.

  • color: The r, g, b color. Values in the range 0 to 1.

void set_sampler_value(const std::string &uniform_name, const GLfloat value)
void set_texture(const std::string &uniform_name, Texture *texture)
template<typename T>
void set_uniform(const std::string &name, const std::vector<T> &data_vector)

Set uniforms of the shader.

Automatically choose correct upload path based on data type Defined in header because of template usage

Template Parameters
  • T: A type accepted by OpenGL shaders

Parameters
  • name: The name of the uniform

  • data_vector: The data to send to the uniform

template<typename T>
void set_uniform(const std::string &name, const T &data, const GLuint num_elements = 1u)

Set uniforms of the shader.

Automatically choose correct upload path based on data type Defined in header because of template usage

Template Parameters
  • T: A type accepted by OpenGL shaders

Parameters
  • name: The name of the uniform

  • data: The data to send to the uniform

  • num_elements: The number of elements to send to the uniform

Public Static Functions

std::string shaders_dir()

Use this to get a path to the shaders directory that works with unit tests.

This relies on there being a preprocessor directive. In Visual Studio 2019, this setting can by right clicking on the gl_engine project and clicking Configuration -> C/C++ -> Preprocessor.

Return

Absolute path to shaders directory.

Note

All materials have static constant variables with the names of the uniforms associated with the material’s shaders. These should be used when making use of set_shader.

AO Blur Material

struct glen::AO_BlurMaterial : public Material

Helper material for creating screen space ambient occlusion.

Public Functions

AO_BlurMaterial()
AO_BlurMaterial(const std::string &name)

AO G-Buffer Material

struct glen::AO_GBufferMaterial : public Material

Helper material for creating screen space ambient occlusion.

Public Functions

AO_GBufferMaterial()
AO_GBufferMaterial(const std::string &name)
void update_view(const CameraNode *camera_node, const Node *model_node) override

Update material with new camera position.

Parameters
  • cameraNode: The main viewing camera.

  • node: The node (usually a MeshNode for which the material is applied.

AO Material

struct glen::AO_Material : public Material

Ambient Occlusion Material.

Uses deferred rendering and a post effect to apply ambient occlusion to all objects.

Public Functions

AO_Material()
AO_Material(const std::string &name)
void update_view(const CameraNode *camera_node, const Node *model_node) override

Update material with new camera position.

Parameters
  • cameraNode: The main viewing camera.

  • node: The node (usually a MeshNode for which the material is applied.

Blinn Deferred Material

struct glen::BlinnDeferredMaterial : public Material

Primary shader for use in deferred mode.

Currently not as powerful as the BlinnMaterial but this can still be useful for scenarios where lots of lights are required.

Public Functions

BlinnDeferredMaterial()
BlinnDeferredMaterial(const std::string &name)
void update_view(const CameraNode *camera_node, const Node *model_node)

Update material with new camera position.

Parameters
  • cameraNode: The main viewing camera.

  • node: The node (usually a MeshNode for which the material is applied.

void update_lights(const std::vector<LightNode*> &light_nodes) override

Iterate over all lights in light_nodes and update the material.

Parameters
  • light_nodes: The lights to iterate over.

Blinn Material

struct glen::BlinnMaterial : public Material

Primary ‘uber’ material.

Designed to be a versatile material that can be used with any mesh Currently allows for:

  • Diffuse textures

  • Specular textures

  • Glossiness textures (black and white)

  • Normal maps

  • Displacement maps

Public Functions

BlinnMaterial()
BlinnMaterial(const std::string &name)
void update_view(const CameraNode *camera_node, const Node *model_node) override

Update material with new camera position.

Parameters
  • cameraNode: The main viewing camera.

  • node: The node (usually a MeshNode for which the material is applied.

void update_lights(const std::vector<LightNode*> &light_nodes) override

Iterate over all lights in light_nodes and update the material.

Parameters
  • light_nodes: The lights to iterate over.

void update_light_transform(const LightNode *light_node, const CameraNode *camera_node) override

Update shader with new light position.

Parameters
  • light_node: The light to update with.

  • camera_node: The main viewing camera.

Blooom Material

struct glen::BloomMaterial : public Material

2D post effect. Causes very bright parts of the scene to ‘glow’. This effect mimics real life cameras.

Public Functions

BloomMaterial()
BloomMaterial(const std::string &name)

Cube Map Material

struct glen::CubeMapMaterial : public Material

Used for creating textured skyboxes and reflection cubes.

Requires six textures in the following order:

  • Positive X (Right)

  • Negative X (Left)

  • Positive Y (Top)

  • Negative Y (Bottom)

  • Positive Z (Back)

  • Negative Z (Front)

Public Functions

CubeMapMaterial()
CubeMapMaterial(const std::string &name)
void update_view(const CameraNode *camera_node, const Node *model_node)

Update material with new camera position.

Parameters
  • cameraNode: The main viewing camera.

  • node: The node (usually a MeshNode for which the material is applied.

Depth Cube Material

struct glen::DepthCubeMaterial : public Material

Depth cube material. Various uses. Main use for this engine is to provide depth mapped shadows for spot lights.

Attention

Cube maps are six times as expensive to render as normal depth maps. If given the choice, go for the former.

Public Functions

DepthCubeMaterial()
DepthCubeMaterial(const std::string &name)
void update_view(const CameraNode *camera_node, const Node *model_node)

Update material with new camera position.

Parameters
  • cameraNode: The main viewing camera.

  • node: The node (usually a MeshNode for which the material is applied.

Depth Material

struct glen::DepthMaterial : public Material

Depth material. Various uses. Main use for this engine is for depth mapped shadows.

Public Functions

DepthMaterial()
DepthMaterial(const std::string &name)
void update_view(const CameraNode *camera_node, const Node *model_node) override

Update material with new camera position.

Parameters
  • cameraNode: The main viewing camera.

  • node: The node (usually a MeshNode for which the material is applied.

Gaussian Blur Material

struct glen::GaussianBlurMaterial : public Material

2D Post effect. Blurs everything on screen. Useful in Bloom effect.

Public Functions

GaussianBlurMaterial()
GaussianBlurMaterial(const std::string &name)

G-Buffer Material

struct glen::GBufferMaterial : public Material

Intermediate material for use in deferred rendering situations.

Public Functions

GBufferMaterial()
GBufferMaterial(const std::string &name)
void update_view(const CameraNode *camera_node, const Node *model_node) override

Update material with new camera position.

Parameters
  • cameraNode: The main viewing camera.

  • node: The node (usually a MeshNode for which the material is applied.

HDR Material

struct glen::HDRMaterial : public Material

2D Post effect. Allows for tone mapping of values outside the usual 0 to 1 range.

Public Functions

HDRMaterial()
HDRMaterial(const std::string &name)

Light Material

struct glen::LightMaterial : public Material

Simple self illuminated shader. Primarily used for display meshes of lights.

Public Functions

LightMaterial()
LightMaterial(const std::string &name)
void update_view(const CameraNode *cameraNode, const Node *model_node) override

Update material with new camera position.

Parameters
  • cameraNode: The main viewing camera.

  • node: The node (usually a MeshNode for which the material is applied.