Commit b97a4883 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

BUG: Updates all the renderer configuration in updateConfig

Adds SSAO to the rendering example
parent 8c4715a1
Pipeline #233498 passed with stage
......@@ -49,6 +49,7 @@ main()
// Write log to stdout and file
Logger::startLogger();
double sceneSize;
imstkNew<Scene> scene("Rendering");
{
// Add IBL Probe
......@@ -61,6 +62,10 @@ main()
// Head mesh
auto surfaceMesh = MeshIO::read<SurfaceMesh>(iMSTK_DATA_ROOT "/head/head_revised.obj");
Vec3d l, u;
surfaceMesh->computeBoundingBox(l, u, 20.);
sceneSize = (u - l).norm() * 2;
imstkNew<RenderMaterial> material;
material->setDisplayMode(RenderMaterial::DisplayMode::Surface);
material->setShadingModel(RenderMaterial::ShadingModel::PBR);
......@@ -83,15 +88,10 @@ main()
// Lights
imstkNew<DirectionalLight> dirLight("DirectionalLight");
dirLight->setIntensity(4.0);
dirLight->setIntensity(15.0);
dirLight->setColor(Color(1.0, 0.95, 0.8));
scene->addLight(dirLight);
imstkNew<PointLight> pointLight("PointLight");
pointLight->setIntensity(0.1);
pointLight->setPosition(0.1, 0.2, 0.5);
//scene->addLight(pointLight);
// Plane
auto planeObj = apiutils::createVisualAnalyticalSceneObject("Plane", scene, "VisualPlane", Vec3d(10.0, 10.0, 10.0));
imstkNew<RenderMaterial> planeMaterial;
......@@ -127,6 +127,16 @@ main()
viewer->addControl(keyControl);
}
// Enable SSAO
auto rendConfig = std::make_shared<RendererConfig>();
rendConfig->m_ssaoConfig.m_enableSSAO = true;
rendConfig->m_ssaoConfig.m_SSAOBlur = true;
rendConfig->m_ssaoConfig.m_SSAORadius = 0.1 * sceneSize;
rendConfig->m_ssaoConfig.m_SSAOBias = 0.001 * sceneSize;
rendConfig->m_ssaoConfig.m_KernelSize = 128;
viewer->getActiveRenderer()->setConfig(rendConfig);
driver->start();
}
......
......@@ -64,6 +64,7 @@ VTKRenderer::VTKRenderer(std::shared_ptr<Scene> scene, const bool enableVR) :
m_renderStepsPass(vtkSmartPointer<vtkRenderStepsPass>::New())
{
// create m_vtkRenderer depending on enableVR
m_VrEnabled = enableVR;
if (!enableVR)
{
m_vtkRenderer = vtkSmartPointer<vtkRenderer>::New();
......@@ -173,9 +174,7 @@ VTKRenderer::VTKRenderer(std::shared_ptr<Scene> scene, const bool enableVR) :
camActor->SetCamera(m_camera);
m_debugVtkActors.push_back(camActor);
///TODO : based on scene properties
// Customize background colors
m_vtkRenderer->SetBackground(m_config->m_BGColor1.r, m_config->m_BGColor1.g, m_config->m_BGColor1.b);
m_vtkRenderer->SetBackground2(m_config->m_BGColor2.r, m_config->m_BGColor2.g, m_config->m_BGColor2.b);
......@@ -628,34 +627,34 @@ VTKRenderer::updateBackground(const Vec3d backgroundOne, const Vec3d backgroundT
}
void
VTKRenderer::applyConfigChanges(std::shared_ptr<RendererConfig> config)
VTKRenderer::setConfig(std::shared_ptr<RendererConfig> config)
{
bool enableSSAO = m_config->m_ssaoConfig.m_enableSSAO;
m_config = config;
updateConfig();
}
void
VTKRenderer::updateConfig()
{
// update SSAO if enabled
if (m_config->m_ssaoConfig.m_enableSSAO)
{
m_ssaoPass->SetRadius(config->m_ssaoConfig.m_SSAORadius); // comparison radius
m_ssaoPass->SetBias(config->m_ssaoConfig.m_SSAOBias); // comparison bias
m_ssaoPass->SetKernelSize(config->m_ssaoConfig.m_KernelSize); // number of samples used
if (config->m_ssaoConfig.m_SSAOBlur)
{
m_ssaoPass->BlurOn(); // blur occlusion
}
else
{
m_ssaoPass->BlurOff(); // do not blur occlusion
}
}
m_config->m_ssaoConfig.m_SSAOBlur ? m_ssaoPass->BlurOn() : m_ssaoPass->BlurOff(); // Blur on/off
m_ssaoPass->SetRadius(m_config->m_ssaoConfig.m_SSAORadius); // comparison radius
m_ssaoPass->SetBias(m_config->m_ssaoConfig.m_SSAOBias); // comparison bias
m_ssaoPass->SetKernelSize(m_config->m_ssaoConfig.m_KernelSize); // number of samples used
if (enableSSAO)
{
m_ssaoPass->SetDelegatePass(m_renderStepsPass);
m_vtkRenderer->SetPass(m_ssaoPass);
}
else
{
m_vtkRenderer->SetPass(NULL);
m_vtkRenderer->SetPass(nullptr);
}
// update background colors
m_vtkRenderer->SetBackground(m_config->m_BGColor1.r, m_config->m_BGColor1.g, m_config->m_BGColor1.b);
m_vtkRenderer->SetBackground2(m_config->m_BGColor2.r, m_config->m_BGColor2.g, m_config->m_BGColor2.b);
}
void
......
......@@ -147,7 +147,9 @@ protected:
///
/// \brief Apply config changes
///
void applyConfigChanges(std::shared_ptr<RendererConfig> config) override;
void setConfig(std::shared_ptr<RendererConfig> config) override;
void updateConfig() override;
protected:
///
......
......@@ -38,8 +38,7 @@ struct SSAOConfig
struct RendererConfig
{
bool m_enableVR = false;
// Blue background
Color m_BGColor1 = Color(0.3285, 0.3285, 0.6525);
Color m_BGColor2 = Color(0.13836, 0.13836, 0.2748);
......@@ -96,8 +95,8 @@ public:
///
/// \brief Apply config changes
///
void updateConfig() { applyConfigChanges(m_config); }
virtual void applyConfigChanges(std::shared_ptr<RendererConfig> config) = 0;
virtual void updateConfig() = 0;
virtual void setConfig(std::shared_ptr<RendererConfig> config) = 0;
protected:
bool m_VrEnabled = false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment