1 #include <Engine/Data/VolumetricMaterial.hpp>
3 #include <Engine/Data/ShaderConfigFactory.hpp>
4 #include <Engine/Data/ShaderProgramManager.hpp>
5 #include <Engine/Data/Texture.hpp>
6 #include <Engine/Data/TextureManager.hpp>
7 #include <Engine/RadiumEngine.hpp>
8 #include <Engine/Rendering/RenderTechnique.hpp>
16 static const std::string materialName {
"Volumetric" };
18 nlohmann::json VolumetricMaterial::s_parametersMetadata = {};
29 updateRenderingParameters();
33 auto& renderParameters = getParameters();
36 m_g = renderParameters.getParameter<Scalar>(
"material.g" );
37 m_scale = renderParameters.getParameter<Scalar>(
"material.scale" );
38 m_stepsize = renderParameters.getParameter<Scalar>(
"material.stepsize" );
41 void VolumetricMaterial::updateRenderingParameters() {
42 auto& renderParameters = getParameters();
43 renderParameters.addParameter(
"material.sigma_a",
m_sigma_a );
44 renderParameters.addParameter(
"material.sigma_s",
m_sigma_s );
45 renderParameters.addParameter(
"material.g",
m_g );
46 renderParameters.addParameter(
"material.scale",
m_scale );
48 auto dim = std::sqrt( Scalar( m_texture->
width() * m_texture->
width() +
51 renderParameters.addParameter(
"material.stepsize", 1._ra / dim );
53 else { renderParameters.addParameter(
"material.stepsize",
m_stepsize ); }
54 renderParameters.addParameter(
"material.density", m_texture );
55 renderParameters.addParameter(
"material.modelToDensity",
m_modelToMedium.matrix() );
64 auto resourcesRootDir { RadiumEngine::getInstance()->getResourcesDir() };
65 auto shaderProgramManager = RadiumEngine::getInstance()->getShaderProgramManager();
67 shaderProgramManager->addShaderProgram(
68 { {
"ComposeVolume" },
69 resourcesRootDir +
"Shaders/2DShaders/Basic2D.vert.glsl",
70 resourcesRootDir +
"Shaders/Materials/Volumetric/ComposeVolumeRender.frag.glsl" } );
73 shaderProgramManager->addNamedString(
74 "/Volumetric.glsl", resourcesRootDir +
"Shaders/Materials/Volumetric/Volumetric.glsl" );
79 resourcesRootDir +
"Shaders/Materials/Volumetric/Volumetric.vert.glsl",
80 resourcesRootDir +
"Shaders/Materials/Volumetric/Volumetric.frag.glsl" );
86 resourcesRootDir +
"Shaders/Materials/Volumetric/Volumetric.vert.glsl",
87 resourcesRootDir +
"Shaders/Materials/Volumetric/VolumetricOIT.frag.glsl" );
101 Rendering::EngineRenderTechniques::registerDefaultTechnique(
113 Rendering::DefaultRenderingPasses::LIGHTING_VOLUMETRIC );
121 Rendering::EngineRenderTechniques::removeDefaultTechnique(
"Volumetric" );
static void loadMetaData(const std::string &basename, nlohmann::json &destination)
Load the ParameterSet description.
bool isTransparent() const override
Core::Utils::Color m_sigma_s
Scattering coefficient, default to Air (2.55, 3.21, 3.77)
~VolumetricMaterial() override
static void unregisterMaterial()
Scalar m_scale
Scale factor applied to the absorption and scattering coefficients.
Core::Transform m_modelToMedium
EIGEN_MAKE_ALIGNED_OPERATOR_NEW VolumetricMaterial(const std::string &name)
static void registerMaterial()
void updateGL() override
Update the OpenGL states used by the ShaderParameterProvider. These state could be the ones from an a...
Scalar m_g
phase function assymetry factor, default to 0
Core::Utils::Color m_sigma_a
Absorption coefficient, default to Air (0.0011, 0.0024, 0.014)
void updateFromParameters() override
Update the attributes of the ShaderParameterProvider to their actual values stored in the renderParam...
void setConfiguration(const Data::ShaderConfiguration &newConfig, Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE)
void addConfiguration(const ShaderConfiguration &config)
Core::Utils::optional< ShaderConfiguration > getConfiguration(const std::string &name)