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.vertfile.fragment_shader: Path to the fragment shader. Should be a.fragfile.
-
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.vertfile.fragment_shader: Path to the fragment shader. Should be a.fragfile.
-
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.vertfile.fragment_shader: Path to the fragment shader. Should be a.fragfile.
-
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.vertfile.geometry_shader: Path to the geometry shader. Should be a.geomfile.fragment_shader: Path to the fragment shader. Should be a.fragfile.
-
~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_nodesand 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 aMeshNodefor 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)¶
-
template<typename
T>
voidset_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 uniformdata_vector: The data to send to the uniform
-
template<typename
T>
voidset_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 uniformdata: The data to send to the uniformnum_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_engineproject and clickingConfiguration->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¶
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 aMeshNodefor 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 aMeshNodefor 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
BlinnMaterialbut 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 aMeshNodefor which the material is applied.
-
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 aMeshNodefor which the material is applied.
-
void
update_lights(const std::vector<LightNode*> &light_nodes) override¶ Iterate over all lights in
light_nodesand 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¶
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 aMeshNodefor 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 aMeshNodefor 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 aMeshNodefor which the material is applied.
-
Gaussian Blur Material¶
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 aMeshNodefor which the material is applied.
-
HDR Material¶
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 aMeshNodefor which the material is applied.
-