Blobalizer
Loading...
Searching...
No Matches
RayMarchingShader.h
Go to the documentation of this file.
1#include <Corrade/Utility/Resource.h>
2#include <Magnum/GL/AbstractShaderProgram.h>
3#include <Magnum/GL/Shader.h>
4#include <Magnum/GL/Texture.h>
5#include <Magnum/GL/Version.h>
6
7using namespace Magnum;
8
10class RayMarchingShader : public GL::AbstractShaderProgram {
11public:
14 Utility::Resource rs("data");
15
16 GL::Shader vertShader{GL::Version::GL460, GL::Shader::Type::Vertex};
17 GL::Shader fragShader{GL::Version::GL460, GL::Shader::Type::Fragment};
18 vertShader.addSource(rs.getString("RayMarchingShader.vert"));
19 fragShader.addSource(rs.getString("RayMarchingShader.frag"));
20
21 CORRADE_INTERNAL_ASSERT_OUTPUT(vertShader.compile() && fragShader.compile());
22 this->attachShaders({vertShader, fragShader});
23 CORRADE_INTERNAL_ASSERT(this->link());
24
25 this->viewportSizeUniform = this->uniformLocation("viewportSize");
26 this->viewMatrixUniform = this->uniformLocation("viewMatrix");
27 this->projectionMatrixUniform = this->uniformLocation("projectionMatrix");
28 this->cameraPositionUniform = this->uniformLocation("cameraPosition");
29 this->sdfSizeUniform = this->uniformLocation("sdfSize");
30 this->surfaceRenderingModeUniform = this->uniformLocation("surfaceRenderingMode");
31 this->displayModeUniform = this->uniformLocation("displayMode");
32 this->dmaxUniform = this->uniformLocation("dmax");
33 this->reflectionCountUniform = this->uniformLocation("reflectionCount");
34 this->SSSUniform = this->uniformLocation("enableSubsurfaceScattering");
35 this->surfaceColorUniform = this->uniformLocation("surfaceColor");
36 this->SSSModeUniform = this->uniformLocation("sssMode");
37 this->subSurfaceColorUniform = this->uniformLocation("subSurfaceColor");
38 this->subSurfaceStrengthUniform = this->uniformLocation("subSurfaceStrength");
39 }
40
43 void RayMarchingShader::bindSdf(GL::Texture3D& texture) {
44 texture.bind(SDFTextureUnit);
45 }
46
49 void RayMarchingShader::bindStructure(GL::Texture2D& texture) {
50 texture.bind(StructureTextureUnit);
51 }
52
55 void RayMarchingShader::bindStructurePos(GL::Texture2D& texture) {
56 texture.bind(StructurePosTextureUnit);
57 }
58
61 void RayMarchingShader::bindStructureMask(GL::Texture2D& texture) {
62 texture.bind(StructureMaskTextureUnit);
63 }
64
67 void RayMarchingShader::setViewportSize(const Vector2ui& viewportSize) {
68 this->setUniform(this->viewportSizeUniform, viewportSize);
69 }
70
73 void RayMarchingShader::setProjectionMatrix(const Matrix4 &matrix) {
74 this->setUniform(this->projectionMatrixUniform, matrix);
75 }
76
79 void RayMarchingShader::setViewMatrix(const Matrix4 &matrix) {
80 this->setUniform(this->viewMatrixUniform, matrix);
81 }
82
85 void RayMarchingShader::setCameraPosition(const Vector3 &position) {
86 this->setUniform(this->cameraPositionUniform, position);
87 }
88
91 void RayMarchingShader::setSdfSize(const Vector3 &size) {
92 this->setUniform(this->sdfSizeUniform, size);
93 }
94
97 void RayMarchingShader::setSurfaceRenderingMode(const UnsignedInt& mode) {
98 this->setUniform(this->surfaceRenderingModeUniform, mode);
99 }
100
103 void RayMarchingShader::setDisplayMode(const UnsignedInt& mode) {
104 this->setUniform(this->displayModeUniform, mode);
105 }
106
109 void RayMarchingShader::setDmax(const float dmax) {
110 this->setUniform(this->dmaxUniform, dmax);
111 }
112
115 void RayMarchingShader::setSSS(const bool SSS) {
116 this->setUniform(this->SSSUniform, SSS);
117 }
118
121 void RayMarchingShader::setSSSMode(const UnsignedInt& mode) {
122 this->setUniform(this->SSSModeUniform, mode);
123 }
124
127 void RayMarchingShader::setReflectionCount(const UnsignedInt& reflectionCount) {
128 this->setUniform(this->reflectionCountUniform, reflectionCount);
129 }
130
133 void RayMarchingShader::setSurfaceColor(const Color3& color) {
134 this->setUniform(this->surfaceColorUniform, color);
135 }
136
139 void RayMarchingShader::setSubSurfaceColor(const Color3& color) {
140 this->setUniform(this->subSurfaceColorUniform, color);
141 }
142
145 void RayMarchingShader::setSubSurfaceStrength(const float strength) {
146 this->setUniform(this->subSurfaceStrengthUniform, strength);
147 }
148
149private:
150 enum : Int {
155 };
156
171};
A class representing the shader responsible for the ray marching of the application.
Definition RayMarchingShader.h:10
Int projectionMatrixUniform
Definition RayMarchingShader.h:159
void setSSSMode(const UnsignedInt &mode)
Set the subsurface scattering mode uniform. This is used to determine how to render the subsurface sc...
Definition RayMarchingShader.h:121
Int SSSModeUniform
Definition RayMarchingShader.h:166
Int subSurfaceStrengthUniform
Definition RayMarchingShader.h:170
void setSurfaceColor(const Color3 &color)
Set the surface color uniform. This decides in which color to render the surface.
Definition RayMarchingShader.h:133
void setReflectionCount(const UnsignedInt &reflectionCount)
Set the reflection count uniform. This decides how many times the ray is reflected.
Definition RayMarchingShader.h:127
@ StructureTextureUnit
Definition RayMarchingShader.h:152
@ SDFTextureUnit
Definition RayMarchingShader.h:151
@ StructureMaskTextureUnit
Definition RayMarchingShader.h:154
@ StructurePosTextureUnit
Definition RayMarchingShader.h:153
Int surfaceColorUniform
Definition RayMarchingShader.h:168
Int SSSUniform
Definition RayMarchingShader.h:165
Int surfaceRenderingModeUniform
Definition RayMarchingShader.h:162
void setCameraPosition(const Vector3 &position)
Update the camera position uniform of this shader.
Definition RayMarchingShader.h:85
void setSubSurfaceStrength(const float strength)
Set the subsurface strength uniform. This is used for determining how strong the subsurface scatterin...
Definition RayMarchingShader.h:145
void setViewportSize(const Vector2ui &viewportSize)
Update the viewport size uniform of this shader.
Definition RayMarchingShader.h:67
void setSSS(const bool SSS)
Set the subsurface scattering uniform. This is used to determine whether to render the subsurface sca...
Definition RayMarchingShader.h:115
void setDisplayMode(const UnsignedInt &mode)
Set the display mode uniform. This decides whether to render the structure, the surface,...
Definition RayMarchingShader.h:103
Int subSurfaceColorUniform
Definition RayMarchingShader.h:169
void setViewMatrix(const Matrix4 &matrix)
Update the view matrix uniform of this shader.
Definition RayMarchingShader.h:79
Int sdfSizeUniform
Definition RayMarchingShader.h:161
void setProjectionMatrix(const Matrix4 &matrix)
Update the projection matrix uniform of this shader.
Definition RayMarchingShader.h:73
void setDmax(const float dmax)
Set the attenuation distance uniform. This is used for attenuating the inner structure based on dista...
Definition RayMarchingShader.h:109
Int viewMatrixUniform
Definition RayMarchingShader.h:158
void bindStructurePos(GL::Texture2D &texture)
Bind the given structure positions texture to the shader.
Definition RayMarchingShader.h:55
Int displayModeUniform
Definition RayMarchingShader.h:163
RayMarchingShader()
Loads the shader files from disk, then compiles and links them.
Definition RayMarchingShader.h:13
Int cameraPositionUniform
Definition RayMarchingShader.h:160
void setSubSurfaceColor(const Color3 &color)
Set the subsurface color uniform. This decides in which color to render the subsurface scattering eff...
Definition RayMarchingShader.h:139
void setSurfaceRenderingMode(const UnsignedInt &mode)
Set the surface rendering mode uniform. This decides how the surface is rendered.
Definition RayMarchingShader.h:97
Int dmaxUniform
Definition RayMarchingShader.h:164
Int reflectionCountUniform
Definition RayMarchingShader.h:167
void bindStructureMask(GL::Texture2D &texture)
Bind the given structure mask texture to the shader.
Definition RayMarchingShader.h:61
void bindStructure(GL::Texture2D &texture)
Bind the given structure texture to the shader.
Definition RayMarchingShader.h:49
Int viewportSizeUniform
Definition RayMarchingShader.h:157
void bindSdf(GL::Texture3D &texture)
Bind the given sdf texture to the shader.
Definition RayMarchingShader.h:43
void setSdfSize(const Vector3 &size)
Set the size of the sdf grid in object space.
Definition RayMarchingShader.h:91