Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfPhong.h
1/*******************************************************************************
2 * This file is part of Tissue Forge.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
20/*
21Derived from Magnum with the following notice:
22
23 Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
24 2020, 2021 Vladimír Vondruš <mosra@centrum.cz>
25
26 Permission is hereby granted, free of charge, to any person obtaining a
27 copy of this software and associated documentation files (the "Software"),
28 to deal in the Software without restriction, including without limitation
29 the rights to use, copy, modify, merge, publish, distribute, sublicense,
30 and/or sell copies of the Software, and to permit persons to whom the
31 Software is furnished to do so, subject to the following conditions:
32
33 The above copyright notice and this permission notice shall be included
34 in all copies or substantial portions of the Software.
35
36 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
39 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
41 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
42 DEALINGS IN THE SOFTWARE.
43 */
44
45#ifndef _SOURCE_SHADERS_TFPHONG_H_
46#define _SOURCE_SHADERS_TFPHONG_H_
47
48#include "Magnum/GL/AbstractShaderProgram.h"
49#include "Magnum/Shaders/Generic.h"
50#include "Magnum/Shaders/visibility.h"
51
52
53using namespace Magnum;
54
55
56namespace TissueForge::shaders {
57
58
59 class Phong: public GL::AbstractShaderProgram {
60 public:
64 typedef Magnum::Shaders::Generic3D::Position Position;
65
69 typedef Magnum::Shaders::Generic3D::Normal Normal;
70
74 typedef Magnum::Shaders::Generic3D::Tangent Tangent;
75
79 typedef typename Magnum::Shaders::Generic3D::Tangent4 Tangent4;
80
84 typedef typename Magnum::Shaders::Generic3D::Bitangent Bitangent;
85
89 typedef Magnum::Shaders::Generic3D::TextureCoordinates TextureCoordinates;
90
94 typedef Magnum::Shaders::Generic3D::Color3 Color3;
95
99 typedef Magnum::Shaders::Generic3D::Color4 Color4;
100
101 #ifndef MAGNUM_TARGET_GLES2
105 typedef Magnum::Shaders::Generic3D::ObjectId ObjectId;
106 #endif
107
111 typedef Magnum::Shaders::Generic3D::TransformationMatrix TransformationMatrix;
112
116 typedef Magnum::Shaders::Generic3D::NormalMatrix NormalMatrix;
117
121 typedef typename Magnum::Shaders::Generic3D::TextureOffset TextureOffset;
122
123 enum: UnsignedInt {
127 ColorOutput = Magnum::Shaders::Generic3D::ColorOutput,
128
129 #ifndef MAGNUM_TARGET_GLES2
133 ObjectIdOutput = Magnum::Shaders::Generic3D::ObjectIdOutput
134 #endif
135 };
136
140 enum class Flag: UnsignedShort {
145
150
155
160
164 AlphaMask = 1 << 3,
165
169 VertexColor = 1 << 5,
170
174 Bitangent = 1 << 11,
175
180
181 #ifndef MAGNUM_TARGET_GLES2
185 ObjectId = 1 << 7,
186
191 #endif
192
197
202 };
203
207 typedef Containers::EnumSet<Flag> Flags;
208
214 explicit Phong(Flags flags = {}, unsigned lightCount = 1, unsigned clipPlaneCount = 0);
215
219 explicit Phong(NoCreateT) noexcept: GL::AbstractShaderProgram{NoCreate} {}
220
222 Phong(const Phong&) = delete;
223
225 Phong(Phong&&) noexcept = default;
226
228 Phong& operator=(const Phong&) = delete;
229
231 Phong& operator=(Phong&&) noexcept = default;
232
234 Flags flags() const { return _flags; }
235
237 UnsignedInt lightCount() const { return _lightCount; }
238
243 Phong& setAmbientColor(const Magnum::Color4& color);
244
249 Phong& bindAmbientTexture(GL::Texture2D& texture);
250
255 Phong& setDiffuseColor(const Magnum::Color4& color);
256
261 Phong& bindDiffuseTexture(GL::Texture2D& texture);
262
268
273 Phong& bindNormalTexture(GL::Texture2D& texture);
274
279 Phong& setSpecularColor(const Magnum::Color4& color);
280
285 Phong& bindSpecularTexture(GL::Texture2D& texture);
286
291 Phong& bindTextures(GL::Texture2D* ambient, GL::Texture2D* diffuse, GL::Texture2D* specular, GL::Texture2D* normal
292 #ifdef MAGNUM_BUILD_DEPRECATED
293 = nullptr
294 #endif
295 );
296
301 Phong& setShininess(Float shininess);
302
307 Phong& setAlphaMask(Float mask);
308
309 #ifndef MAGNUM_TARGET_GLES2
314 Phong& setObjectId(UnsignedInt id);
315 #endif
316
321 Phong& setTransformationMatrix(const Matrix4& matrix);
322
327 Phong& setNormalMatrix(const Matrix3x3& matrix);
328
333 Phong& setProjectionMatrix(const Matrix4& matrix);
334
339 Phong& setTextureMatrix(const Matrix3& matrix);
340
345 Phong& setLightPositions(Containers::ArrayView<const Vector4> positions);
346
347 Phong& setLightPositions(std::initializer_list<Vector4> positions);
348
349 #ifdef MAGNUM_BUILD_DEPRECATED
350
351 CORRADE_DEPRECATED("use setLightPositions(Containers::ArrayView<const Vector4>) instead") Phong& setLightPositions(Containers::ArrayView<const Vector3> positions);
352
353 CORRADE_DEPRECATED("use setLightPositions(std::initializer_list<Vector4>) instead") Phong& setLightPositions(std::initializer_list<Vector3> positions);
354 #endif
355
360 Phong& setLightPosition(UnsignedInt id, const Vector4& position);
361
362
367 Phong& setclipPlaneEquation(UnsignedInt id, const Vector4& position);
368
369 #ifdef MAGNUM_BUILD_DEPRECATED
370
371 CORRADE_DEPRECATED("use setLightPosition(UnsignedInt, const Vector4&) instead") Phong& setLightPosition(UnsignedInt id, const Vector3& position);
372
373 CORRADE_DEPRECATED("use setLightPositions(std::initializer_list<Vector4>) instead") Phong& setLightPosition(const Vector3& position);
374 #endif
375
380 Phong& setLightColors(Containers::ArrayView<const Magnum::Color3> colors);
381
382 Phong& setLightColors(std::initializer_list<Magnum::Color3> colors);
383
384 #ifdef MAGNUM_BUILD_DEPRECATED
385
386 CORRADE_DEPRECATED("use setLightColors(Containers::ArrayView<const Magnum::Color3>) instead") Phong& setLightColors(Containers::ArrayView<const Magnum::Color4> colors);
387
388 CORRADE_DEPRECATED("use setLightColors(std::initializer_list<Magnum::Color3>) instead") Phong& setLightColors(std::initializer_list<Magnum::Color4> colors);
389 #endif
390
395 Phong& setLightColor(UnsignedInt id, const Magnum::Color3& color);
396
397 #ifdef MAGNUM_BUILD_DEPRECATED
398
399 CORRADE_DEPRECATED("use setLightColor(UnsignedInt, const Magnum::Color3&) instead") Phong& setLightColor(UnsignedInt id, const Magnum::Color4& color);
400
401 CORRADE_DEPRECATED("use setLightColor(std::initializer_list<Color3>) instead") Phong& setLightColor(const Magnum::Color4& color);
402 #endif
403
408 Phong& setLightSpecularColors(Containers::ArrayView<const Magnum::Color3> colors);
409
410 Phong& setLightSpecularColors(std::initializer_list<Magnum::Color3> colors);
411
416 Phong& setLightSpecularColor(UnsignedInt id, const Magnum::Color3& color);
417
422 Phong& setLightRanges(Containers::ArrayView<const Float> ranges);
423
424 Phong& setLightRanges(std::initializer_list<Float> ranges);
425
430 Phong& setLightRange(UnsignedInt id, Float range);
431
432 unsigned clipPlaneCount() const {
433 return _clipPlaneCount;
434 }
435
436 private:
437 /* Prevent accidentally calling irrelevant functions */
438 #ifndef MAGNUM_TARGET_GLES
439 using GL::AbstractShaderProgram::drawTransformFeedback;
440 #endif
441 #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
442 using GL::AbstractShaderProgram::dispatchCompute;
443 #endif
444
445 Flags _flags;
446 UnsignedInt _lightCount{};
447 Int _transformationMatrixUniform{0},
448 _projectionMatrixUniform{1},
449 _normalMatrixUniform{2},
450 _textureMatrixUniform{3},
451 _ambientColorUniform{4},
452 _diffuseColorUniform{5},
453 _specularColorUniform{6},
454 _shininessUniform{7},
455 _normalTextureScaleUniform{8},
456 _alphaMaskUniform{9};
457 #ifndef MAGNUM_TARGET_GLES2
458 Int _objectIdUniform{10};
459 #endif
460 Int _lightPositionsUniform{11},
461 _lightColorsUniform, /* 11 + lightCount, set in the constructor */
462 _lightSpecularColorsUniform, /* 11 + 2*lightCount */
463 _lightRangesUniform; /* 11 + 3*lightCount */
464
465
466 UnsignedInt _clipPlaneCount{1};
467
468 Int _clipPlanesUniform; /*_lightRangesUniform + 1, or 11 + 4*lightCount, set in the constructor */
469 };
470
471 MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, Phong::Flag value);
472 MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, Phong::Flags value);
473 CORRADE_ENUMSET_OPERATORS(Phong::Flags)
474
475}
476
477#endif // _SOURCE_SHADERS_TFPHONG_H_
Phong & setSpecularColor(const Magnum::Color4 &color)
Set specular color.
Magnum::Shaders::Generic3D::Color3 Color3
Three-component vertex color.
Definition tfPhong.h:94
Phong & setLightRanges(Containers::ArrayView< const Float > ranges)
Set light attenuation ranges.
Phong & setclipPlaneEquation(UnsignedInt id, const Vector4 &position)
Set clip plane equation for given clip plane.
Phong & setObjectId(UnsignedInt id)
Set object ID.
Magnum::Shaders::Generic3D::TextureOffset TextureOffset
(Instanced) texture offset
Definition tfPhong.h:121
Magnum::Shaders::Generic3D::TransformationMatrix TransformationMatrix
(Instanced) transformation matrix
Definition tfPhong.h:111
Magnum::Shaders::Generic3D::Position Position
Vertex position.
Definition tfPhong.h:64
Phong(Phong &&) noexcept=default
Move constructor.
Magnum::Shaders::Generic3D::Tangent Tangent
Tangent direction.
Definition tfPhong.h:74
Magnum::Shaders::Generic3D::NormalMatrix NormalMatrix
(Instanced) normal matrix
Definition tfPhong.h:116
Phong(NoCreateT) noexcept
Construct without creating the underlying OpenGL object.
Definition tfPhong.h:219
Phong & setLightRange(UnsignedInt id, Float range)
Set attenuation range for given light.
Phong & setLightPositions(Containers::ArrayView< const Vector4 > positions)
Set light positions.
Phong & setNormalMatrix(const Matrix3x3 &matrix)
Set normal matrix.
Phong & setShininess(Float shininess)
Set shininess.
Magnum::Shaders::Generic3D::ObjectId ObjectId
(Instanced) object ID
Definition tfPhong.h:105
Magnum::Shaders::Generic3D::Color4 Color4
Four-component vertex color.
Definition tfPhong.h:99
Containers::EnumSet< Flag > Flags
Flags.
Definition tfPhong.h:207
UnsignedInt lightCount() const
Light count.
Definition tfPhong.h:237
Phong & setTextureMatrix(const Matrix3 &matrix)
Set texture coordinate transformation matrix.
Phong & setTransformationMatrix(const Matrix4 &matrix)
Set transformation matrix.
Flags flags() const
Flags.
Definition tfPhong.h:234
Magnum::Shaders::Generic3D::Normal Normal
Normal direction.
Definition tfPhong.h:69
Phong & setLightSpecularColor(UnsignedInt id, const Magnum::Color3 &color)
Set position for given light.
Magnum::Shaders::Generic3D::TextureCoordinates TextureCoordinates
2D texture coordinates
Definition tfPhong.h:89
Phong & setAlphaMask(Float mask)
Set alpha mask value.
Phong & setProjectionMatrix(const Matrix4 &matrix)
Set projection matrix.
Phong & setDiffuseColor(const Magnum::Color4 &color)
Set diffuse color.
Phong & setLightColor(UnsignedInt id, const Magnum::Color3 &color)
Set position for given light.
Magnum::Shaders::Generic3D::Tangent4 Tangent4
Tangent direction with a bitangent sign.
Definition tfPhong.h:79
Phong & setAmbientColor(const Magnum::Color4 &color)
Set ambient color.
Phong & bindDiffuseTexture(GL::Texture2D &texture)
Bind a diffuse texture.
Phong & bindTextures(GL::Texture2D *ambient, GL::Texture2D *diffuse, GL::Texture2D *specular, GL::Texture2D *normal)
Bind textures.
Phong & bindAmbientTexture(GL::Texture2D &texture)
Bind an ambient texture.
Phong(Flags flags={}, unsigned lightCount=1, unsigned clipPlaneCount=0)
Constructor.
Phong & setNormalTextureScale(Float scale)
Set normal texture scale.
Magnum::Shaders::Generic3D::Bitangent Bitangent
Bitangent direction.
Definition tfPhong.h:84
Phong & setLightSpecularColors(Containers::ArrayView< const Magnum::Color3 > colors)
Set light specular colors.
Phong & bindNormalTexture(GL::Texture2D &texture)
Bind a normal texture.
@ ObjectIdOutput
Definition tfPhong.h:133
@ ColorOutput
Definition tfPhong.h:127
Flag
Flag.
Definition tfPhong.h:140
@ AmbientTexture
Definition tfPhong.h:144
@ InstancedTransformation
Definition tfPhong.h:196
@ TextureTransformation
Definition tfPhong.h:179
@ SpecularTexture
Definition tfPhong.h:154
@ InstancedObjectId
Definition tfPhong.h:190
@ NormalTexture
Definition tfPhong.h:159
@ AlphaMask
Definition tfPhong.h:164
@ VertexColor
Definition tfPhong.h:169
@ DiffuseTexture
Definition tfPhong.h:149
@ InstancedTextureOffset
Definition tfPhong.h:201
Phong & setLightColors(Containers::ArrayView< const Magnum::Color3 > colors)
Set light colors.
Phong & bindSpecularTexture(GL::Texture2D &texture)
Bind a specular texture.
Phong & setLightPosition(UnsignedInt id, const Vector4 &position)
Set position for given light.
Phong(const Phong &)=delete
Copying is not allowed.
Tissue Forge shaders.
Definition tfFlat3D.h:57