Magnum::Shaders::PhongGL class new in Git master

Phong OpenGL shader.

Uses ambient, diffuse and specular color or texture. For a colored mesh you need to provide the Position and Normal attributes in your triangle mesh. By default, the shader renders the mesh with a white color in an identity transformation. Use setTransformationMatrix(), setNormalMatrix(), setProjectionMatrix(), setLightPosition() and others to configure the shader.

Image

Colored rendering

Common mesh setup:

struct Vertex {
    Vector3 position;
    Vector3 normal;
};
Vertex data[60]{
    // ...
};

GL::Buffer vertices;
vertices.setData(data, GL::BufferUsage::StaticDraw);

GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0,
    Shaders::PhongGL::Position{},
    Shaders::PhongGL::Normal{});

Common rendering setup:

Matrix4 transformationMatrix = Matrix4::translation(Vector3::zAxis(-5.0f));
Matrix4 projectionMatrix =
    Matrix4::perspectiveProjection(35.0_degf, 1.0f, 0.001f, 100.0f);

Shaders::PhongGL shader;
shader.setDiffuseColor(0x2f83cc_rgbf)
    .setShininess(200.0f)
    .setTransformationMatrix(transformationMatrix)
    .setNormalMatrix(transformationMatrix.normalMatrix())
    .setProjectionMatrix(projectionMatrix)
    .draw(mesh);

Textured rendering

If you want to use textures, you need to provide also the TextureCoordinates attribute. Pass appropriate Flag combination to the constructor and then at render time don't forget to also call appropriate subset of bindAmbientTexture(), bindDiffuseTexture() and bindSpecularTexture() (or the combined bindTextures()). The texture is multiplied by the color, which is by default set to fully opaque white for enabled textures. Mesh setup with a diffuse and a specular texture:

struct Vertex {
    Vector3 position;
    Vector3 normal;
    Vector2 textureCoordinates;
};
Vertex data[60]{
    // ...
};

GL::Buffer vertices;
vertices.setData(data, GL::BufferUsage::StaticDraw);

GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0,
    Shaders::PhongGL::Position{},
    Shaders::PhongGL::Normal{},
    Shaders::PhongGL::TextureCoordinates{});

Common rendering setup:

Matrix4 transformationMatrix, projectionMatrix;
GL::Texture2D diffuseTexture, specularTexture;

Shaders::PhongGL shader{Shaders::PhongGL::Flag::DiffuseTexture|
                      Shaders::PhongGL::Flag::SpecularTexture};
shader.bindTextures(nullptr, &diffuseTexture, &specularTexture, nullptr)
    .setTransformationMatrix(transformationMatrix)
    .setNormalMatrix(transformationMatrix.normalMatrix())
    .setProjectionMatrix(projectionMatrix)
    .draw(mesh);

Light specification

By default, the shader provides a single directional "fill" light, coming from the center of the camera. Using the lightCount parameter in constructor, you can specify how many lights you want, and then control light parameters using setLightPositions(), setLightColors(), setLightSpecularColors() and setLightRanges(). Light positions are specified as four-component vectors, the last component distinguishing between directional and point lights.

  • Point lights are specified with camera-relative position and the last component set to 1.0f together with setLightRanges() describing the attenuation. The range corresponds to the Trade::LightData::range() and the attenuation is calculated as the following — see Attenuation calculation for more information:

    \[ F_{att} = \frac{\operatorname{clamp}(1 - (\frac{d}{\color{m-info} R})^4, 0, 1)^2}{1 + d^2} \]

    If you use Constants::inf() as a range (which is also the default), the equation reduces down to a simple inverse square:

    \[ F_{att} = \lim_{{\color{m-info} R} \to \infty} \frac{{\color{m-dim} \operatorname{clamp}(} 1 \mathbin{\color{m-dim} -} {\color{m-dim} (\frac{d}{R})^4, 0, 1)^2}}{1 + d^2} = \frac{1}{1 + d^2} \]
  • Directional lights are specified with a camera-relative direction to the light with the last component set to 0.0f — which effectively makes $ d = 0 $ — and are not affected by values from setLightRanges() in any way:

    \[ F_{att} = \lim_{d \to 0} \frac{{\color{m-dim} \operatorname{clamp}(} 1 \mathbin{\color{m-dim} -} {\color{m-dim} (\frac{d}{R})^4, 0, 1)^2}}{1 \mathbin{\color{m-dim} +} {\color{m-dim} d^2}} = 1 \]

Light color and intensity, corresponding to Trade::LightData::color() and Trade::LightData::intensity(), is meant to be multiplied together and passed to setLightColors() and setLightSpecularColors().

The following example shows a three-light setup with one dim directional light shining from the top and two stronger but range-limited point lights:

Matrix4 directionalLight, pointLight1, pointLight2; // camera-relative

Shaders::PhongGL shader{{}, 3}; // 3 lights
shader
    .setLightPositions({Vector4{directionalLight.up(), 0.0f},
                        Vector4{pointLight1.translation(), 1.0f},
                        Vector4{pointLight2.translation(), 1.0f}})
    .setLightColors({0xf0f0ff_srgbf*0.1f,
                     0xff8080_srgbf*10.0f,
                     0x80ff80_srgbf*10.0f})
    .setLightColors()
    .setLightRanges({Constants::inf(),
                     2.0f,
                     2.0f});

Ambient lights

In order to avoid redundant uniform inputs, there's no dedicated way to specify ambient lights. Instead, they are handled by the ambient color input, as the math for ambient color and lights is equivalent. Add the ambient colors together and reuse the diffuse texture in the bindAmbientTexture() slot to have it affected by the ambient as well:

Trade::LightData ambientLight = ;

Shaders::PhongGL shader{Shaders::PhongGL::Flag::AmbientTexture|, };
shader
    .setAmbientColor(ambientColor + ambientLight.color()*ambientLight.intensity())
    .bindAmbientTexture(diffuseTexture)
    .bindDiffuseTexture(diffuseTexture);

Zero lights

As a special case, creating this shader with zero lights makes its output equivalent to the FlatGL3D shader — only setAmbientColor() and bindAmbientTexture() (if Flag::AmbientTexture is enabled) are taken into account, which corresponds to FlatGL::setColor() and FlatGL::bindTexture(). This is useful to reduce complexity in apps that render models with pre-baked lights. For instanced workflows using zero lights means the NormalMatrix instance attribute doesn't need to be supplied either. In addition, enabling Flag::VertexColor and using a default ambient color with no texturing makes this shader equivalent to VertexColorGL.

Alpha blending and masking

Alpha / transparency is supported by the shader implicitly, but to have it working on the framebuffer, you need to enable GL::Renderer::Feature::Blending and set up the blending function. See GL::Renderer::setBlendFunction() for details.

To avoid specular highlights on transparent areas, specular alpha should be always set to 0.0f. On the other hand, non-zero specular alpha can be for example used to render transparent materials which are still expected to have specular highlights such as glass or soap bubbles.

An alternative is to enable Flag::AlphaMask and tune setAlphaMask() for simple binary alpha-masked drawing that doesn't require depth sorting or blending enabled. Note that this feature is implemented using the GLSL discard operation which is known to have considerable performance impact on some platforms. With proper depth sorting and blending you'll usually get much better performance and output quality.

For general alpha-masked drawing you need to provide an ambient texture with alpha channel and set alpha channel of the diffuse/specular color to 0.0f so only ambient alpha will be taken into account. If you have a diffuse texture combined with the alpha mask, you can use that texture for both ambient and diffuse part and then separate the alpha like this:

Shaders::PhongGL shader{Shaders::PhongGL::Flag::AmbientTexture|
                      Shaders::PhongGL::Flag::DiffuseTexture};
shader.bindTextures(&diffuseAlphaTexture, &diffuseAlphaTexture, nullptr, nullptr)
    .setAmbientColor(0x000000ff_rgbaf)
    .setDiffuseColor(Color4{diffuseRgb, 0.0f})
    .setSpecularColor(Color4{specularRgb, 0.0f});

Normal mapping

If you want to use normal textures, enable Flag::NormalTexture and call bindNormalTexture(). In addition you need to supply per-vertex tangent and bitangent direction:

If you supply just a three-component Tangent attribute and no bitangents, the shader will implicitly assume the fourth component to be 1.0f, forming a right-handed tangent space. This is a valid optimization when you have full control over the bitangent orientation, but won't work with general meshes.

The strength of the effect can be controlled by setNormalTextureScale(). See Trade::MaterialAttribute::NormalTextureScale for a description of the factor is used.

Object ID output

The shader supports writing object ID to the framebuffer for object picking or other annotation purposes. Enable it using Flag::ObjectId and set up an integer buffer attached to the ObjectIdOutput attachment. If you have a batch of meshes with different object IDs, enable Flag::InstancedObjectId and supply per-vertex IDs to the ObjectId attribute. The output will contain a sum of the per-vertex ID and ID coming from setObjectId().

The functionality is practically the same as in the FlatGL shader, see its documentation for more information and usage example.

Instanced rendering

Enabling Flag::InstancedTransformation will turn the shader into an instanced one. It'll take per-instance transformation and normal matrix from the TransformationMatrix and NormalMatrix attributes, applying those before the matrix set by setTransformationMatrix() and setNormalMatrix(). Besides that, Flag::VertexColor (and the Color3 / Color4) attributes can work as both per-vertex and per-instance, and for texturing it's possible to have per-instance texture offset taken from TextureOffset when Flag::InstancedTextureOffset is enabled (similarly to transformation, applied before setTextureMatrix()). The snippet below shows adding a buffer with per-instance transformation to a mesh — note how a normal matrix attribute has to be populated and supplied as well to ensure lighting works:

struct {
    Matrix4 transformation;
    Matrix3x3 normal;
} instanceData[] {
    {Matrix4::translation({1.0f, 2.0f, 0.0f})*Matrix4::rotationX(90.0_degf), {}},
    {Matrix4::translation({2.0f, 1.0f, 0.0f})*Matrix4::rotationY(90.0_degf), {}},
    {Matrix4::translation({3.0f, 0.0f, 1.0f})*Matrix4::rotationZ(90.0_degf), {}},
    // ...
};
for(auto& instance: instanceData)
    instance.normal = instance.transformation.normalMatrix();

mesh.setInstanceCount(Containers::arraySize(instanceData))
    .addVertexBufferInstanced(GL::Buffer{instanceData}, 1, 0,
        Shaders::PhongGL::TransformationMatrix{},
        Shaders::PhongGL::NormalMatrix{});

Uniform buffers

See Using uniform buffers for a high-level overview that applies to all shaders. In this particular case, the shader needs a separate ProjectionUniform3D and TransformationUniform3D buffer, lights are supplied via a PhongLightUniform. To maximize use of the limited uniform buffer memory, materials are supplied separately in a PhongMaterialUniform buffer and then referenced via materialId from a PhongDrawUniform; for optional texture transformation a per-draw TextureTransformationUniform can be supplied as well. A uniform buffer setup equivalent to the colored case at the top, with one default light, would look like this:

GL::Buffer projectionUniform, lightUniform, materialUniform,
    transformationUniform, drawUniform;
projectionUniform.setData({
    Shaders::ProjectionUniform3D{}
        .setProjectionMatrix(projectionMatrix)
});
lightUniform.setData({
    Shaders::PhongLightUniform{}
});
materialUniform.setData({
    Shaders::PhongMaterialUniform{}
        .setDiffuseColor(0x2f83cc_rgbf)
        .setShininess(200.0f)
});
transformationUniform.setData({
    Shaders::TransformationUniform3D{}
        .setTransformationMatrix(transformationMatrix)
});
drawUniform.setData({
    Shaders::PhongDrawUniform{}
        .setNormalMatrix(transformationMatrix.normalMatrix())
        .setMaterialId(0)
});

Shaders::PhongGL shader{Shaders::PhongGL::Flag::UniformBuffers};
shader
    .bindProjectionBuffer(projectionUniform)
    .bindLightBuffer(lightUniform)
    .bindMaterialBuffer(materialUniform)
    .bindTransformationBuffer(transformationUniform)
    .bindDrawBuffer(drawUniform)
    .draw(mesh);

For a multidraw workflow enable Flag::MultiDraw (and possibly Flag::TextureArrays) and supply desired light, material and draw count in the PhongGL(Flags, UnsignedInt, UnsignedInt, UnsignedInt) constructor. For every draw then specify material references and texture offsets/layers. With Flag::LightCulling it's also possible to perform per-draw light culling by supplying a subrange into the PhongLightUniform array using PhongDrawUniform::lightOffset and lightCount. Besides that, the usage is similar for all shaders, see Multidraw and reducing driver overhead for an example.

Base classes

class Magnum::GL::AbstractShaderProgram
Base for shader program implementations.

Public types

enum (anonymous): UnsignedInt { ColorOutput = GenericGL3D::ColorOutput new in 2019.10, ObjectIdOutput = GenericGL3D::ObjectIdOutput new in 2019.10 }
enum class Flag: UnsignedInt { AmbientTexture = 1 << 0, DiffuseTexture = 1 << 1, SpecularTexture = 1 << 2, NormalTexture = 1 << 4 new in 2019.10, AlphaMask = 1 << 3, VertexColor = 1 << 5 new in 2019.10, Bitangent = 1 << 11 new in Git master, TextureTransformation = 1 << 6 new in 2020.06, ObjectId = 1 << 7 new in 2019.10, InstancedObjectId = (1 << 8)|ObjectId new in 2020.06, InstancedTransformation = 1 << 9 new in 2020.06, InstancedTextureOffset = (1 << 10)|TextureTransformation new in 2020.06, UniformBuffers = 1 << 12 new in Git master, MultiDraw = UniformBuffers|(1 << 13) new in Git master, TextureArrays = 1 << 14 new in Git master, LightCulling = 1 << 15 new in Git master, NoSpecular = 1 << 16 new in Git master }
Flag.
using Position = GenericGL3D::Position
Vertex position.
using Normal = GenericGL3D::Normal
Normal direction.
using Tangent = GenericGL3D::Tangent new in 2019.10
Tangent direction.
using Tangent4 = GenericGL3D::Tangent4 new in Git master
Tangent direction with a bitangent sign.
using Bitangent = GenericGL3D::Bitangent new in Git master
Bitangent direction.
using TextureCoordinates = GenericGL3D::TextureCoordinates
2D texture coordinates
using Color3 = GenericGL3D::Color3 new in 2019.10
Three-component vertex color.
using Color4 = GenericGL3D::Color4 new in 2019.10
Four-component vertex color.
using ObjectId = GenericGL3D::ObjectId new in 2020.06
(Instanced) object ID
using TransformationMatrix = GenericGL3D::TransformationMatrix new in 2020.06
(Instanced) transformation matrix
using NormalMatrix = GenericGL3D::NormalMatrix new in 2020.06
(Instanced) normal matrix
using TextureOffset = GenericGL3D::TextureOffset new in 2020.06
(Instanced) texture offset
using TextureOffsetLayer = GenericGL3D::TextureOffsetLayer new in Git master
(Instanced) texture offset and layer
using Flags = Containers::EnumSet<Flag>
Flags.

Constructors, destructors, conversion operators

PhongGL(Flags flags = {}, UnsignedInt lightCount = 1) explicit
Constructor.
PhongGL(Flags flags, UnsignedInt lightCount, UnsignedInt materialCount, UnsignedInt drawCount) explicit
Construct for a multi-draw scenario.
PhongGL(NoCreateT) explicit noexcept
Construct without creating the underlying OpenGL object.
PhongGL(const PhongGL&) deleted
Copying is not allowed.
PhongGL(PhongGL&&) defaulted noexcept
Move constructor.

Public functions

auto operator=(const PhongGL&) -> PhongGL& deleted
Copying is not allowed.
auto operator=(PhongGL&&) -> PhongGL& defaulted noexcept
Move assignment.
auto flags() const -> Flags
Flags.
auto lightCount() const -> UnsignedInt
Light count.
auto materialCount() const -> UnsignedInt new in Git master
Material count.
auto drawCount() const -> UnsignedInt new in Git master
Draw count.

Uniform setters

Used only if Flag::UniformBuffers is not set.

auto setAmbientColor(const Magnum::Color4& color) -> PhongGL&
Set ambient color.
auto setDiffuseColor(const Magnum::Color4& color) -> PhongGL&
Set diffuse color.
auto setNormalTextureScale(Float scale) -> PhongGL& new in Git master
Set normal texture scale.
auto setSpecularColor(const Magnum::Color4& color) -> PhongGL&
Set specular color.
auto setShininess(Float shininess) -> PhongGL&
Set shininess.
auto setAlphaMask(Float mask) -> PhongGL&
Set alpha mask value.
auto setObjectId(UnsignedInt id) -> PhongGL&
Set object ID.
auto setTransformationMatrix(const Matrix4& matrix) -> PhongGL&
Set transformation matrix.
auto setNormalMatrix(const Matrix3x3& matrix) -> PhongGL&
Set normal matrix.
auto setProjectionMatrix(const Matrix4& matrix) -> PhongGL&
Set projection matrix.
auto setTextureMatrix(const Matrix3& matrix) -> PhongGL& new in 2020.06
Set texture coordinate transformation matrix.
auto setTextureLayer(UnsignedInt layer) -> PhongGL& new in Git master
Set texture array layer.
auto setLightPositions(Containers::ArrayView<const Vector4> positions) -> PhongGL& new in Git master
Set light positions.
auto setLightPositions(std::initializer_list<Vector4> positions) -> PhongGL& new in Git master
auto setLightPositions(Containers::ArrayView<const Vector3> positions) -> PhongGL& deprecated in Git master
Set light positions.
auto setLightPositions(std::initializer_list<Vector3> positions) -> PhongGL& deprecated in Git master
auto setLightPosition(UnsignedInt id, const Vector4& position) -> PhongGL& new in Git master
Set position for given light.
auto setLightPosition(UnsignedInt id, const Vector3& position) -> PhongGL& deprecated in Git master
Set position for given light.
auto setLightPosition(const Vector3& position) -> PhongGL& deprecated in Git master
Set light position.
auto setLightColors(Containers::ArrayView<const Magnum::Color3> colors) -> PhongGL& new in Git master
Set light colors.
auto setLightColors(std::initializer_list<Magnum::Color3> colors) -> PhongGL& new in Git master
auto setLightColors(Containers::ArrayView<const Magnum::Color4> colors) -> PhongGL& deprecated in Git master
Set light colors.
auto setLightColors(std::initializer_list<Magnum::Color4> colors) -> PhongGL& deprecated in Git master
auto setLightColor(UnsignedInt id, const Magnum::Color3& color) -> PhongGL& new in Git master
Set color for given light.
auto setLightColor(UnsignedInt id, const Magnum::Color4& color) -> PhongGL& deprecated in Git master
Set color for given light.
auto setLightColor(const Magnum::Color4& color) -> PhongGL& deprecated in Git master
Set light color.
auto setLightSpecularColors(Containers::ArrayView<const Magnum::Color3> colors) -> PhongGL& new in Git master
Set light specular colors.
auto setLightSpecularColors(std::initializer_list<Magnum::Color3> colors) -> PhongGL& new in Git master
auto setLightSpecularColor(UnsignedInt id, const Magnum::Color3& color) -> PhongGL& new in Git master
Set specular color for given light.
auto setLightRanges(Containers::ArrayView<const Float> ranges) -> PhongGL& new in Git master
Set light attenuation ranges.
auto setLightRanges(std::initializer_list<Float> ranges) -> PhongGL& new in Git master
auto setLightRange(UnsignedInt id, Float range) -> PhongGL& new in Git master
Set attenuation range for given light.

Texture binding

auto bindAmbientTexture(GL::Texture2D& texture) -> PhongGL&
Bind an ambient texture.
auto bindAmbientTexture(GL::Texture2DArray& texture) -> PhongGL& new in Git master
Bind an ambient array texture.
auto bindDiffuseTexture(GL::Texture2D& texture) -> PhongGL&
Bind a diffuse texture.
auto bindDiffuseTexture(GL::Texture2DArray& texture) -> PhongGL& new in Git master
Bind a diffuse array texture.
auto bindSpecularTexture(GL::Texture2D& texture) -> PhongGL&
Bind a specular texture.
auto bindSpecularTexture(GL::Texture2DArray& texture) -> PhongGL& new in Git master
Bind a specular array texture.
auto bindNormalTexture(GL::Texture2D& texture) -> PhongGL& new in 2019.10
Bind a normal texture.
auto bindNormalTexture(GL::Texture2DArray& texture) -> PhongGL& new in Git master
Bind a normal array texture.
auto bindTextures(GL::Texture2D* ambient, GL::Texture2D* diffuse, GL::Texture2D* specular, GL::Texture2D* normal = nullptr) -> PhongGL&
Bind textures.

Enum documentation

enum Magnum::Shaders::PhongGL::(anonymous): UnsignedInt

Enumerators
ColorOutput new in 2019.10

Color shader output. Generic output, present always. Expects three- or four-component floating-point or normalized buffer attachment.

ObjectIdOutput new in 2019.10

Object ID shader output. Generic output, present only if Flag::ObjectId is set. Expects a single-component unsigned integral attachment. Writes the value set in setObjectId() there, see Object ID output for more information.

enum class Magnum::Shaders::PhongGL::Flag: UnsignedInt

Flag.

Enumerators
AmbientTexture

Multiply ambient color with a texture.

DiffuseTexture

Multiply diffuse color with a texture.

SpecularTexture

Multiply specular color with a texture.

NormalTexture new in 2019.10

Modify normals according to a texture. Requires the Tangent attribute to be present.

AlphaMask

Enable alpha masking. If the combined fragment color has an alpha less than the value specified with setAlphaMask(), given fragment is discarded.

This uses the discard operation which is known to have considerable performance impact on some platforms. While useful for cheap alpha masking that doesn't require depth sorting, with proper depth sorting and blending you'll usually get much better performance and output quality.

VertexColor new in 2019.10

Multiply the diffuse and ambient color with a vertex color. Requires either the Color3 or Color4 attribute to be present.

Bitangent new in Git master

Use the separate Bitangent attribute for retrieving vertex bitangents. If this flag is not present, the last component of Tangent4 is used to calculate bitangent direction. See Normal mapping for more information.

TextureTransformation new in 2020.06

Enable texture coordinate transformation. If this flag is set, the shader expects that at least one of Flag::AmbientTexture, Flag::DiffuseTexture, Flag::SpecularTexture or Flag::NormalTexture is enabled as well.

ObjectId new in 2019.10

Enable object ID output. See Object ID output for more information.

InstancedObjectId new in 2020.06

Instanced object ID. Retrieves a per-instance / per-vertex object ID from the ObjectId attribute, outputting a sum of the per-vertex ID and ID coming from setObjectId() or PhongDrawUniform::objectId. Implicitly enables Flag::ObjectId. See Object ID output for more information.

InstancedTransformation new in 2020.06

Instanced transformation. Retrieves a per-instance transformation and normal matrix from the TransformationMatrix / NormalMatrix attributes and uses them together with matrices coming from setTransformationMatrix() and setNormalMatrix() or TransformationUniform3D::transformationMatrix and PhongDrawUniform::normalMatrix (first the per-instance, then the uniform matrix). See Instanced rendering for more information.

InstancedTextureOffset new in 2020.06

Instanced texture offset. Retrieves a per-instance offset vector from the TextureOffset attribute and uses it together with the matrix coming from setTextureMatrix() or TextureTransformationUniform::rotationScaling and TextureTransformationUniform::offset (first the per-instance vector, then the uniform matrix). Instanced texture scaling and rotation is not supported at the moment, you can specify that only via the uniform setTextureMatrix(). Implicitly enables Flag::TextureTransformation. See Instanced rendering for more information.

If Flag::TextureArrays is set as well, a three-component TextureOffsetLayer attribute can be used instead of TextureOffset to specify per-instance texture layer, which gets added to the uniform layer numbers set by setTextureLayer() or TextureTransformationUniform::layer.

UniformBuffers new in Git master

Use uniform buffers. Expects that uniform data are supplied via bindProjectionBuffer(), bindTransformationBuffer(), bindDrawBuffer(), bindTextureTransformationBuffer(), bindMaterialBuffer() and bindLightBuffer() instead of direct uniform setters.

MultiDraw new in Git master

Enable multidraw functionality. Implies Flag::UniformBuffers and adds the value from setDrawOffset() with the gl_DrawID builtin, which makes draws submitted via GL::AbstractShaderProgram::draw(Containers::ArrayView<const Containers::Reference<MeshView>>) pick up per-draw parameters directly, without having to rebind the uniform buffers or specify setDrawOffset() before each draw. In a non-multidraw scenario, gl_DrawID is 0, which means a shader with this flag enabled can be used for regular draws as well.

TextureArrays new in Git master

Use 2D texture arrays. Expects that the texture is supplied via bindAmbientTexture(GL::Texture2DArray&) / bindDiffuseTexture(GL::Texture2DArray&) / bindSpecularTexture(GL::Texture2DArray&) / bindNormalTexture(GL::Texture2DArray&) instead of bindAmbientTexture(GL::Texture2D&) / bindDiffuseTexture(GL::Texture2D&) / bindSpecularTexture(GL::Texture2D&) / bindNormalTexture(GL::Texture2D&) and the layer shared by all textures is set via setTextureLayer() or TextureTransformationUniform::layer. If Flag::InstancedTextureOffset is set as well and a three-component TextureOffsetLayer attribute is used instead of TextureOffset, the per-instance and uniform layer numbers are added together.

LightCulling new in Git master

Enable light culling in uniform buffer workflows using the PhongDrawUniform::lightOffset and PhongDrawUniform::lightCount fields. If not enabled, all lightCount() lights are used for every draw. Expects that Flag::UniformBuffers is enabled as well.

NoSpecular new in Git master

Disable specular contribution in light calculation. Can result in a significant performance improvement compared to calling setSpecularColor() with 0x00000000_rgbaf when specular highlights are not desired.

Typedef documentation

typedef GenericGL3D::Position Magnum::Shaders::PhongGL::Position

Vertex position.

Generic attribute, Vector3.

typedef GenericGL3D::Normal Magnum::Shaders::PhongGL::Normal

Normal direction.

Generic attribute, Vector3.

typedef GenericGL3D::Tangent Magnum::Shaders::PhongGL::Tangent new in 2019.10

Tangent direction.

Generic attribute, Vector3. Use either this or the Tangent4 attribute. If only a three-component attribute is used and Flag::Bitangent is not enabled, it's the same as if Tangent4 was specified with the fourth component always being 1.0f. Used only if Flag::NormalTexture is set.

typedef GenericGL3D::Tangent4 Magnum::Shaders::PhongGL::Tangent4 new in Git master

Tangent direction with a bitangent sign.

Generic attribute, Vector4. Use either this or the Tangent attribute. If Flag::Bitangent is set, the fourth component is ignored and bitangents are taken from the Bitangent attribute instead. Used only if Flag::NormalTexture is set.

typedef GenericGL3D::Bitangent Magnum::Shaders::PhongGL::Bitangent new in Git master

Bitangent direction.

Generic attribute, Vector3. Use either this or the Tangent4 attribute. Used only if both Flag::NormalTexture and Flag::Bitangent are set.

typedef GenericGL3D::TextureCoordinates Magnum::Shaders::PhongGL::TextureCoordinates

2D texture coordinates

Generic attribute, Vector2, used only if at least one of Flag::AmbientTexture, Flag::DiffuseTexture and Flag::SpecularTexture is set.

typedef GenericGL3D::Color3 Magnum::Shaders::PhongGL::Color3 new in 2019.10

Three-component vertex color.

Generic attribute, Magnum::Color3. Use either this or the Color4 attribute. Used only if Flag::VertexColor is set.

typedef GenericGL3D::Color4 Magnum::Shaders::PhongGL::Color4 new in 2019.10

Four-component vertex color.

Generic attribute, Magnum::Color4. Use either this or the Color3 attribute. Used only if Flag::VertexColor is set.

typedef GenericGL3D::ObjectId Magnum::Shaders::PhongGL::ObjectId new in 2020.06

(Instanced) object ID

Generic attribute, Magnum::UnsignedInt. Used only if Flag::InstancedObjectId is set.

typedef GenericGL3D::TextureOffsetLayer Magnum::Shaders::PhongGL::TextureOffsetLayer new in Git master

(Instanced) texture offset and layer

Generic attribute, Magnum::Vector3, with the last component interpreted as an integer. Use either this or the TextureOffset attribute. First two components used only if Flag::InstancedTextureOffset is set, third component only if Flag::TextureArrays is set.

typedef Containers::EnumSet<Flag> Magnum::Shaders::PhongGL::Flags

Flags.

Function documentation

Magnum::Shaders::PhongGL::PhongGL(Flags flags = {}, UnsignedInt lightCount = 1) explicit

Constructor.

Parameters
flags Flags
lightCount Count of light sources

While this function is meant mainly for the classic uniform scenario (without Flag::UniformBuffers set), it's equivalent to PhongGL(Flags, UnsignedInt, UnsignedInt, UnsignedInt) with materialCount and drawCount set to 1.

Magnum::Shaders::PhongGL::PhongGL(Flags flags, UnsignedInt lightCount, UnsignedInt materialCount, UnsignedInt drawCount) explicit

Construct for a multi-draw scenario.

Parameters
flags Flags
lightCount Size of a PhongLightUniform buffer bound with bindLightBuffer()
materialCount Size of a PhongMaterialUniform buffer bound with bindMaterialBuffer()
drawCount Size of a ProjectionUniform3D / TransformationUniform3D / PhongDrawUniform / TextureTransformationUniform buffer bound with bindProjectionBuffer(), bindTransformationBuffer(), bindDrawBuffer() and bindTextureTransformationBuffer()

If flags contains Flag::UniformBuffers, lightCount, materialCount and drawCount describe the uniform buffer sizes as these are required to have a statically defined size. The draw offset is then set via setDrawOffset() and the per-draw materials and lights are specified via PhongDrawUniform::materialId, PhongDrawUniform::lightOffset and PhongDrawUniform::lightCount.

If flags don't contain Flag::UniformBuffers, materialCount and drawCount is ignored and the constructor behaves the same as PhongGL(Flags, UnsignedInt).

Magnum::Shaders::PhongGL::PhongGL(NoCreateT) explicit noexcept

Construct without creating the underlying OpenGL object.

The constructed instance is equivalent to a moved-from state. Useful in cases where you will overwrite the instance later anyway. Move another object over it to make it useful.

This function can be safely used for constructing (and later destructing) objects even without any OpenGL context being active. However note that this is a low-level and a potentially dangerous API, see the documentation of NoCreate for alternatives.

UnsignedInt Magnum::Shaders::PhongGL::lightCount() const

Light count.

If Flag::UniformBuffers is set, this is the statically defined size of the PhongLightUniform uniform buffer.

UnsignedInt Magnum::Shaders::PhongGL::materialCount() const new in Git master

Material count.

Statically defined size of the PhongMaterialUniform uniform buffer. Has use only if Flag::UniformBuffers is set.

UnsignedInt Magnum::Shaders::PhongGL::drawCount() const new in Git master

Draw count.

Statically defined size of each of the ProjectionUniform3D, TransformationUniform3D, PhongDrawUniform and TextureTransformationUniform uniform buffers. Has use only if Flag::UniformBuffers is set.

PhongGL& Magnum::Shaders::PhongGL::setAmbientColor(const Magnum::Color4& color)

Set ambient color.

Returns Reference to self (for method chaining)

If Flag::AmbientTexture is set, default value is 0xffffffff_rgbaf and the color will be multiplied with ambient texture, otherwise default value is 0x00000000_rgbaf. If Flag::VertexColor is set, the color is multiplied with a color coming from the Color3 / Color4 attribute.

Expects that Flag::UniformBuffers is not set, in that case fill PhongMaterialUniform::ambientColor and call bindMaterialBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setDiffuseColor(const Magnum::Color4& color)

Set diffuse color.

Returns Reference to self (for method chaining)

Initial value is 0xffffffff_rgbaf. If Flag::DiffuseTexture is set, the color will be multiplied with the texture. If lightCount() is zero, this function is a no-op, as diffuse color doesn't contribute to the output in that case. If Flag::VertexColor is set, the color is multiplied with a color coming from the Color3 / Color4 attribute.

Expects that Flag::UniformBuffers is not set, in that case fill PhongMaterialUniform::diffuseColor and call bindMaterialBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setNormalTextureScale(Float scale) new in Git master

Set normal texture scale.

Returns Reference to self (for method chaining)

Affects strength of the normal mapping. Initial value is 1.0f, meaning the normal texture is not changed in any way; a value of 0.0f disables the normal texture effect altogether.

Expects that the shader was created with Flag::NormalTexture enabled. If lightCount() is zero, this function is a no-op, as normals don't contribute to the output in that case.

Expects that Flag::UniformBuffers is not set, in that case fill PhongMaterialUniform::normalTextureScale and call bindDrawBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setSpecularColor(const Magnum::Color4& color)

Set specular color.

Returns Reference to self (for method chaining)

Initial value is 0xffffff00_rgbaf. Expects that the shader was not created with Flag::NoSpecular. If Flag::SpecularTexture is set, the color will be multiplied with the texture. If you want to have a fully diffuse material, it's recommended to disable the specular contribution altogether with Flag::NoSpecular. If having a dedicated shader variant is not possible, set the specular color to 0x00000000_rgbaf. If lightCount() is zero, this function is a no-op, as specular color doesn't contribute to the output in that case.

Expects that Flag::UniformBuffers is not set, in that case fill PhongMaterialUniform::specularColor and call bindMaterialBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setShininess(Float shininess)

Set shininess.

Returns Reference to self (for method chaining)

The larger value, the harder surface (smaller specular highlight). Initial value is 80.0f. If lightCount() is zero, this function is a no-op, as specular color doesn't contribute to the output in that case.

Expects that Flag::UniformBuffers is not set, in that case fill PhongMaterialUniform::shininess and call bindMaterialBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setAlphaMask(Float mask)

Set alpha mask value.

Returns Reference to self (for method chaining)

Expects that the shader was created with Flag::AlphaMask enabled. Fragments with alpha values smaller than the mask value will be discarded. Initial value is 0.5f. See the flag documentation for further information.

This corresponds to glAlphaFunc() in classic OpenGL.

Expects that Flag::UniformBuffers is not set, in that case fill PhongMaterialUniform::alphaMask and call bindMaterialBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setObjectId(UnsignedInt id)

Set object ID.

Returns Reference to self (for method chaining)

Expects that the shader was created with Flag::ObjectId enabled. Value set here is written to the ObjectIdOutput, see Object ID output for more information. Default is 0. If Flag::InstancedObjectId is enabled as well, this value is added to the ID coming from the ObjectId attribute.

Expects that Flag::UniformBuffers is not set, in that case fill PhongDrawUniform::objectId and call bindDrawBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setTransformationMatrix(const Matrix4& matrix)

Set transformation matrix.

Returns Reference to self (for method chaining)

You need to set also setNormalMatrix() with a corresponding value. Initial value is an identity matrix. If Flag::InstancedTransformation is set, the per-instance transformation coming from the TransformationMatrix attribute is applied first, before this one.

Expects that Flag::UniformBuffers is not set, in that case fill TransformationUniform3D::transformationMatrix and call bindTransformationBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setNormalMatrix(const Matrix3x3& matrix)

Set normal matrix.

Returns Reference to self (for method chaining)

The matrix doesn't need to be normalized, as renormalization is done per-fragment anyway. You need to set also setTransformationMatrix() with a corresponding value. Initial value is an identity matrix. If lightCount() is zero, this function is a no-op, as normals don't contribute to the output in that case. If Flag::InstancedTransformation is set, the per-instance normal matrix coming from the NormalMatrix attribute is applied first, before this one.

Expects that Flag::UniformBuffers is not set, in that case fill PhongDrawUniform::normalMatrix and call bindDrawBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setProjectionMatrix(const Matrix4& matrix)

Set projection matrix.

Returns Reference to self (for method chaining)

Initial value is an identity matrix (i.e., an orthographic projection of the default $ [ -\boldsymbol{1} ; \boldsymbol{1} ] $ cube).

Expects that Flag::UniformBuffers is not set, in that case fill ProjectionUniform3D::projectionMatrix and call bindProjectionBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setTextureMatrix(const Matrix3& matrix) new in 2020.06

Set texture coordinate transformation matrix.

Returns Reference to self (for method chaining)

Expects that the shader was created with Flag::TextureTransformation enabled. Initial value is an identity matrix. If Flag::InstancedTextureOffset is set, the per-instance offset coming from the TextureOffset atttribute is applied first, before this matrix.

Expects that Flag::UniformBuffers is not set, in that case fill TextureTransformationUniform::rotationScaling and TextureTransformationUniform::offset and call bindTextureTransformationBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setTextureLayer(UnsignedInt layer) new in Git master

Set texture array layer.

Returns Reference to self (for method chaining)

Expects that the shader was created with Flag::TextureArrays enabled. Initial value is 0. If Flag::InstancedTextureOffset is set and a three-component TextureOffsetLayer attribute is used instead of TextureOffset, this value is added to the layer coming from the third component.

Expects that Flag::UniformBuffers is not set, in that case fill TextureTransformationUniform::layer and call bindTextureTransformationBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setLightPositions(Containers::ArrayView<const Vector4> positions) new in Git master

Set light positions.

Returns Reference to self (for method chaining)

Depending on the fourth component, the value is treated as either a camera-relative position of a point light, if the fourth component is 1.0f; or a direction to a directional light, if the fourth component is 0.0f. Expects that the size of the positions array is the same as lightCount(). Initial values are {0.0f, 0.0f, 1.0f, 0.0f} — a directional "fill" light coming from the camera.

Expects that Flag::UniformBuffers is not set, in that case fill PhongLightUniform::position and call bindLightBuffer() instead

PhongGL& Magnum::Shaders::PhongGL::setLightPositions(std::initializer_list<Vector4> positions) new in Git master

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

PhongGL& Magnum::Shaders::PhongGL::setLightPositions(Containers::ArrayView<const Vector3> positions)

Set light positions.

0.0f to preserve the original behavior as close as possible.

PhongGL& Magnum::Shaders::PhongGL::setLightPositions(std::initializer_list<Vector3> positions)

0.0f to preserve the original behavior as close as possible.

PhongGL& Magnum::Shaders::PhongGL::setLightPosition(UnsignedInt id, const Vector4& position) new in Git master

Set position for given light.

Returns Reference to self (for method chaining)

Unlike setLightPositions() updates just a single light position. If updating more than one light, prefer the batch function instead to reduce the count of GL API calls. Expects that id is less than lightCount().

Expects that Flag::UniformBuffers is not set, in that case fill PhongLightUniform::position and call bindLightBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setLightPosition(UnsignedInt id, const Vector3& position)

Set position for given light.

0.0f to preserve the original behavior as close as possible.

PhongGL& Magnum::Shaders::PhongGL::setLightPosition(const Vector3& position)

Set light position.

0.0f to preserve the original behavior as close as possible.

PhongGL& Magnum::Shaders::PhongGL::setLightColors(Containers::ArrayView<const Magnum::Color3> colors) new in Git master

Set light colors.

Returns Reference to self (for method chaining)

Initial values are 0xffffff_rgbf. Expects that the size of the colors array is the same as lightCount().

Expects that Flag::UniformBuffers is not set, in that case fill PhongLightUniform::color and call bindLightBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setLightColors(std::initializer_list<Magnum::Color3> colors) new in Git master

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

PhongGL& Magnum::Shaders::PhongGL::setLightColors(Containers::ArrayView<const Magnum::Color4> colors)

Set light colors.

PhongGL& Magnum::Shaders::PhongGL::setLightColors(std::initializer_list<Magnum::Color4> colors)

PhongGL& Magnum::Shaders::PhongGL::setLightColor(UnsignedInt id, const Magnum::Color3& color) new in Git master

Set color for given light.

Returns Reference to self (for method chaining)

Unlike setLightColors() updates just a single light color. If updating more than one light, prefer the batch function instead to reduce the count of GL API calls. Expects that id is less than lightCount().

Expects that Flag::UniformBuffers is not set, in that case fill PhongLightUniform::color and call bindLightBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setLightColor(UnsignedInt id, const Magnum::Color4& color)

Set color for given light.

PhongGL& Magnum::Shaders::PhongGL::setLightColor(const Magnum::Color4& color)

Set light color.

PhongGL& Magnum::Shaders::PhongGL::setLightSpecularColors(Containers::ArrayView<const Magnum::Color3> colors) new in Git master

Set light specular colors.

Returns Reference to self (for method chaining)

Usually you'd set this value to the same as setLightColors(), but it allows for greater flexibility such as disabling specular highlights on certain lights. Initial values are 0xffffff_rgbf. Expects that the size of the colors array is the same as lightCount().

Expects that Flag::UniformBuffers is not set, in that case fill PhongLightUniform::specularColor and call bindLightBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setLightSpecularColors(std::initializer_list<Magnum::Color3> colors) new in Git master

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

PhongGL& Magnum::Shaders::PhongGL::setLightSpecularColor(UnsignedInt id, const Magnum::Color3& color) new in Git master

Set specular color for given light.

Returns Reference to self (for method chaining)

Unlike setLightSpecularColors() updates just a single light color. If updating more than one light, prefer the batch function instead to reduce the count of GL API calls. Expects that id is less than lightCount().

Expects that Flag::UniformBuffers is not set, in that case fill PhongLightUniform::specularColor and call bindLightBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setLightRanges(Containers::ArrayView<const Float> ranges) new in Git master

Set light attenuation ranges.

Returns Reference to self (for method chaining)

Initial values are Constants::inf(). Expects that the size of the ranges array is the same as lightCount().

Expects that Flag::UniformBuffers is not set, in that case fill PhongLightUniform::range and call bindLightBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setLightRanges(std::initializer_list<Float> ranges) new in Git master

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

PhongGL& Magnum::Shaders::PhongGL::setLightRange(UnsignedInt id, Float range) new in Git master

Set attenuation range for given light.

Returns Reference to self (for method chaining)

Unlike setLightRanges() updates just a single light range. If updating more than one light, prefer the batch function instead to reduce the count of GL API calls. Expects that id is less than lightCount().

Expects that Flag::UniformBuffers is not set, in that case fill PhongLightUniform::range and call bindLightBuffer() instead.

PhongGL& Magnum::Shaders::PhongGL::setDrawOffset(UnsignedInt offset) new in Git master

Set a draw offset.

Returns Reference to self (for method chaining)

Specifies which item in the TransformationUniform3D, PhongDrawUniform and TextureTransformationUniform buffers bound with bindTransformationBuffer(), bindDrawBuffer() and bindTextureTransformationBuffer() should be used for current draw. Expects that Flag::UniformBuffers is set and offset is less than drawCount(). Initial value is 0, if drawCount() is 1, the function is a no-op as the shader assumes draw offset to be always zero.

If Flag::MultiDraw is set, gl_DrawID is added to this value, which makes each draw submitted via GL::AbstractShaderProgram::draw(Containers::ArrayView<const Containers::Reference<MeshView>>) pick up its own per-draw parameters.

PhongGL& Magnum::Shaders::PhongGL::bindProjectionBuffer(GL::Buffer& buffer) new in Git master

Set a projection uniform buffer.

Returns Reference to self (for method chaining)

Expects that Flag::UniformBuffers is set. The buffer is expected to contain at least one instance of ProjectionUniform3D. At the very least you need to call also bindTransformationBuffer(), bindDrawBuffer() and bindMaterialBuffer(), usually bindLightBuffer() as well.

PhongGL& Magnum::Shaders::PhongGL::bindProjectionBuffer(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size) new in Git master

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

PhongGL& Magnum::Shaders::PhongGL::bindTransformationBuffer(GL::Buffer& buffer) new in Git master

Set a transformation uniform buffer.

Returns Reference to self (for method chaining)

Expects that Flag::UniformBuffers is set. The buffer is expected to contain drawCount() instances of TransformationUniform3D. At the very least you need to call also bindProjectionBuffer(), bindDrawBuffer() and bindMaterialBuffer(), usually bindLightBuffer() as well.

PhongGL& Magnum::Shaders::PhongGL::bindTransformationBuffer(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size) new in Git master

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

PhongGL& Magnum::Shaders::PhongGL::bindDrawBuffer(GL::Buffer& buffer) new in Git master

Set a draw uniform buffer.

Returns Reference to self (for method chaining)

Expects that Flag::UniformBuffers is set. The buffer is expected to contain drawCount() instances of PhongDrawUniform. At the very least you need to call also bindProjectionBuffer(), bindTransformationBuffer() and bindMaterialBuffer(), usually bindLightBuffer() as well.

PhongGL& Magnum::Shaders::PhongGL::bindDrawBuffer(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size) new in Git master

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

PhongGL& Magnum::Shaders::PhongGL::bindTextureTransformationBuffer(GL::Buffer& buffer) new in Git master

Set a texture transformation uniform buffer.

Returns Reference to self (for method chaining)

Expects that both Flag::UniformBuffers and Flag::TextureTransformation is set. The buffer is expected to contain drawCount() instances of TextureTransformationUniform.

PhongGL& Magnum::Shaders::PhongGL::bindTextureTransformationBuffer(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size) new in Git master

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

PhongGL& Magnum::Shaders::PhongGL::bindMaterialBuffer(GL::Buffer& buffer) new in Git master

Set a material uniform buffer.

Returns Reference to self (for method chaining)

Expects that Flag::UniformBuffers is set. The buffer is expected to contain materialCount() instances of PhongMaterialUniform. At the very least you need to call also bindProjectionBuffer(), bindTransformationBuffer() and bindDrawBuffer(), usually bindLightBuffer() as well.

PhongGL& Magnum::Shaders::PhongGL::bindMaterialBuffer(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size) new in Git master

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

PhongGL& Magnum::Shaders::PhongGL::bindLightBuffer(GL::Buffer& buffer) new in Git master

Set a light uniform buffer.

Returns Reference to self (for method chaining)

Expects that Flag::UniformBuffers is set. The buffer is expected to contain lightCount() instances of PhongLightUniform.

PhongGL& Magnum::Shaders::PhongGL::bindLightBuffer(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size) new in Git master

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

PhongGL& Magnum::Shaders::PhongGL::bindAmbientTexture(GL::Texture2D& texture)

Bind an ambient texture.

Returns Reference to self (for method chaining)

Expects that the shader was created with Flag::AmbientTexture enabled. If Flag::TextureArrays is enabled as well, use bindAmbientTexture(GL::Texture2DArray&) instead.

PhongGL& Magnum::Shaders::PhongGL::bindAmbientTexture(GL::Texture2DArray& texture) new in Git master

Bind an ambient array texture.

Returns Reference to self (for method chaining)

Expects that the shader was created with both Flag::AmbientTexture and Flag::TextureArrays enabled. If Flag::UniformBuffers is not enabled, the layer is set via setTextureLayer(); if Flag::UniformBuffers is enabled, Flag::TextureTransformation has to be enabled as well and the layer is set via TextureTransformationUniform::layer.

PhongGL& Magnum::Shaders::PhongGL::bindDiffuseTexture(GL::Texture2D& texture)

Bind a diffuse texture.

Returns Reference to self (for method chaining)

Expects that the shader was created with Flag::DiffuseTexture enabled. If Flag::TextureArrays is enabled as well, use bindDiffuseTexture(GL::Texture2DArray&) instead. If lightCount() is zero, this function is a no-op, as diffuse color doesn't contribute to the output in that case.

PhongGL& Magnum::Shaders::PhongGL::bindDiffuseTexture(GL::Texture2DArray& texture) new in Git master

Bind a diffuse array texture.

Returns Reference to self (for method chaining)

Expects that the shader was created with both Flag::DiffuseTexture and Flag::TextureArrays enabled. If Flag::UniformBuffers is not enabled, the layer is set via setTextureLayer(); if Flag::UniformBuffers is enabled, Flag::TextureTransformation has to be enabled as well and the layer is set via TextureTransformationUniform::layer. If lightCount() is zero, this function is a no-op, as diffuse color doesn't contribute to the output in that case.

PhongGL& Magnum::Shaders::PhongGL::bindSpecularTexture(GL::Texture2D& texture)

Bind a specular texture.

Returns Reference to self (for method chaining)

Expects that the shader was created with Flag::SpecularTexture enabled and that Flag::NoSpecular is not set. If Flag::TextureArrays is enabled as well, use bindSpecularTexture(GL::Texture2DArray&) instead. If lightCount() is zero, this function is a no-op, as specular color doesn't contribute to the output in that case.

PhongGL& Magnum::Shaders::PhongGL::bindSpecularTexture(GL::Texture2DArray& texture) new in Git master

Bind a specular array texture.

Returns Reference to self (for method chaining)

Expects that the shader was created with both Flag::SpecularTexture and Flag::TextureArrays enabled and that Flag::NoSpecular is not set. If Flag::UniformBuffers is not enabled, the layer is set via setTextureLayer(); if Flag::UniformBuffers is enabled, Flag::TextureTransformation has to be enabled as well and the layer is set via TextureTransformationUniform::layer. If lightCount() is zero, this function is a no-op, as specular color doesn't contribute to the output in that case.

PhongGL& Magnum::Shaders::PhongGL::bindNormalTexture(GL::Texture2D& texture) new in 2019.10

Bind a normal texture.

Returns Reference to self (for method chaining)

Expects that the shader was created with Flag::NormalTexture enabled and the Tangent attribute was supplied. If Flag::TextureArrays is enabled as well, use bindNormalTexture(GL::Texture2DArray&) instead. If lightCount() is zero, this function is a no-op, as normals don't contribute to the output in that case.

PhongGL& Magnum::Shaders::PhongGL::bindNormalTexture(GL::Texture2DArray& texture) new in Git master

Bind a normal array texture.

Returns Reference to self (for method chaining)

Expects that the shader was created with both Flag::NormalTexture and Flag::TextureArrays enabled and the Tangent attribute was supplied. If lightCount() is zero, this function is a no-op, as normals don't contribute to the output in that case.

PhongGL& Magnum::Shaders::PhongGL::bindTextures(GL::Texture2D* ambient, GL::Texture2D* diffuse, GL::Texture2D* specular, GL::Texture2D* normal = nullptr)

Bind textures.

Returns Reference to self (for method chaining)

A particular texture has effect only if particular texture flag from Flag is set, you can use nullptr for the rest. Expects that the shader was created with at least one of Flag::AmbientTexture, Flag::DiffuseTexture, Flag::SpecularTexture or Flag::NormalTexture enabled and Flag::TextureArrays is not set. More efficient than setting each texture separately.

Debug& operator<<(Debug& debug, PhongGL::Flag value)

Debug output operator.

Debug& operator<<(Debug& debug, PhongGL::Flags value)

Debug output operator.