Skip to content

ShaderMaterial

Represents a material rendered with custom shaders.

This material allows rendering with user-defined GLSL shaders. It is suitable for advanced effects, custom lighting, and any scenario requiring programmable control over the rendering pipeline.

cpp
auto material = vglx::ShaderMaterial::Create({
  vertex_shader_str,
  fragment_shader_str,
  {
    // custom uniforms
    {"u_Time", 0.0f},
    {"u_Resolution", Vector2::Zero }
  }
});

auto mesh = vglx::Mesh::Create(geometry, material);
scene->Add(mesh);

INFO

Derives from Material and inherits all public properties and methods.

Construction

Constructors


ShaderMaterial()

cpp
vglx::ShaderMaterial::ShaderMaterial(std::string_view vertex_shader, std::string_view fragment_shader, const std::unordered_map< std::string, UniformValue > &uniforms)
ParameterDescription
vertex_shaderVertex shader GLSL source-code.
fragment_shaderFragment shader GLSL source-code.
uniformsCustom uniforms used by the shader.

Constructs a ShaderMaterial object.

Factories preferred


ShaderMaterial::Create() auto

cpp
static auto vglx::ShaderMaterial::Create(std::string_view vertex_shader, std::string_view fragment_shader, const std::unordered_map< std::string, UniformValue > &uniforms)
ParameterDescription
vertex_shaderVertex shader GLSL source-code.
fragment_shaderFragment shader GLSL source-code.
uniformsCustom uniforms used by the shader.

Creates a shared pointer to a ShaderMaterial object.

Properties

uniforms std::unordered_map< std::string,UniformValue>

cpp
std::unordered_map< std::string,UniformValue> uniforms

Stores values for custom uniforms used by the shader.

Functions

GetType() MaterialType virtual

cpp
MaterialType vglx::ShaderMaterial::GetType() const override

Returns material type.

Released under the MIT License.