kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #27278
Improvements on reflection and refraction
Hi all,
Attached is a patch that fixes some issues and improves the reflection and refraction on 3D-viewer raytracing.
Hope you can merge it.
This followed the critics sent by Chris Pavlina and Marcos Chaparro.
Thanks for the feedback!
Mario Luzeiro
From 5e3c1d81ac9b1e528b75b08c5b0b94c6de140269 Mon Sep 17 00:00:00 2001
Message-Id: <5e3c1d81ac9b1e528b75b08c5b0b94c6de140269.1485005374.git.mrluzeiro@xxxxx>
From: Mario Luzeiro <mrluzeiro@xxxxx>
Date: Sat, 21 Jan 2017 13:30:05 +0100
Subject: [PATCH] 3D-Viewer: Improvements on reflection and refraction
- crete an option for absorvance (works better to make the epoxy
different for regular transparent materials).
- visual fix an issue related with the epoxy render (square bands on the
render).
- fix a reflection issue (it was not take in account the reflection
material color).
---
.../3d_render_raytracing/c3d_render_createscene.cpp | 2 ++
.../3d_render_raytracing/c3d_render_raytracing.cpp | 20 +++++++++++---------
.../3d_rendering/3d_render_raytracing/cmaterial.cpp | 2 ++
.../3d_rendering/3d_render_raytracing/cmaterial.h | 4 ++++
4 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp
index 560c7dd..5e42cd1 100644
--- a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp
+++ b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp
@@ -146,6 +146,8 @@ void C3D_RENDER_RAYTRACING::setupMaterials()
0.10f, // transparency
0.0f ); // reflection
+ m_materials.m_EpoxyBoard.SetAbsorvance( 10.0f );
+
if( m_settings.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) )
m_materials.m_EpoxyBoard.SetNormalPerturbator( &m_board_normal_perturbator );
diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_raytracing.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_raytracing.cpp
index 094541c..eb216e0 100644
--- a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_raytracing.cpp
+++ b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_raytracing.cpp
@@ -1905,15 +1905,17 @@ SFVEC3F C3D_RENDER_RAYTRACING::shadeHit( const SFVEC3F &aBgColor,
if( m_accelerator->Intersect( reflectedRay, reflectedHit ) )
{
- sum_color += objMaterial->GetReflection() *
+ sum_color += ( diffuseColorObj + objMaterial->GetSpecularColor() ) *
shadeHit( aBgColor,
reflectedRay,
reflectedHit,
false,
aRecursiveLevel + 1,
is_testShadow ) *
- (1.0f / ( 1.0f + 0.75f * reflectedHit.m_tHit *
- reflectedHit.m_tHit) ); // Falloff factor
+ SFVEC3F( objMaterial->GetReflection() *
+ // Falloff factor
+ (1.0f / ( 1.0f + 0.75f * reflectedHit.m_tHit *
+ reflectedHit.m_tHit) ) );
}
}
@@ -1941,8 +1943,10 @@ SFVEC3F C3D_RENDER_RAYTRACING::shadeHit( const SFVEC3F &aBgColor,
refractionRatio,
refractedVector ) )
{
- // If we want to apply some randomize to the refracted vector
- //refractedVector = refractedVector + UniformRandomHemisphereDirection() * 0.01f;
+ const float objTransparency = objMaterial->GetTransparency();
+
+ // apply some randomize to the refracted vector
+ refractedVector = refractedVector + UniformRandomHemisphereDirection() * 0.2f * (1.0f - objTransparency);
refractedVector = glm::normalize( refractedVector );
// This increase the start point by a "fixed" factor so it will work the
@@ -1957,9 +1961,7 @@ SFVEC3F C3D_RENDER_RAYTRACING::shadeHit( const SFVEC3F &aBgColor,
HITINFO refractedHit;
refractedHit.m_tHit = std::numeric_limits<float>::infinity();
- SFVEC3F refractedColor = aBgColor;
-
- float objTransparency = objMaterial->GetTransparency();
+ SFVEC3F refractedColor = objMaterial->GetAmbientColor();
if( m_accelerator->Intersect( refractedRay, refractedHit ) )
{
@@ -1972,7 +1974,7 @@ SFVEC3F C3D_RENDER_RAYTRACING::shadeHit( const SFVEC3F &aBgColor,
const SFVEC3F absorbance = ( SFVEC3F(1.0f) - diffuseColorObj ) *
(1.0f - objTransparency ) *
- 1.0000f * // Adjust falloff factor
+ objMaterial->GetAbsorvance() * // Adjust falloff factor
-refractedHit.m_tHit;
const SFVEC3F transparency = SFVEC3F( expf( absorbance.r ),
diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/cmaterial.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/cmaterial.cpp
index 4f7892a..6a6bca9 100644
--- a/3d-viewer/3d_rendering/3d_render_raytracing/cmaterial.cpp
+++ b/3d-viewer/3d_rendering/3d_render_raytracing/cmaterial.cpp
@@ -45,6 +45,7 @@ CMATERIAL::CMATERIAL()
m_transparency = 0.0f; // completely opaque
m_cast_shadows = true;
m_reflection = 0.0f;
+ m_absorbance = 1.0f;
m_normal_perturbator = NULL;
}
@@ -72,6 +73,7 @@ CMATERIAL::CMATERIAL( const SFVEC3F &aAmbient,
m_specularColor = aSpecular;
m_shinness = aShinness;
m_transparency = aTransparency;
+ m_absorbance = 1.0f;
m_reflection = aReflection;
m_cast_shadows = true;
diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/cmaterial.h b/3d-viewer/3d_rendering/3d_render_raytracing/cmaterial.h
index 2b70939..e605013 100644
--- a/3d-viewer/3d_rendering/3d_render_raytracing/cmaterial.h
+++ b/3d-viewer/3d_rendering/3d_render_raytracing/cmaterial.h
@@ -182,6 +182,9 @@ public:
float GetShinness() const { return m_shinness; }
float GetTransparency() const { return m_transparency; }
float GetReflection() const { return m_reflection; }
+ float GetAbsorvance() const { return m_absorbance; }
+
+ void SetAbsorvance( float aAbsorvanceFactor ) { m_absorbance = aAbsorvanceFactor; }
/**
* @brief SetCastShadows - Set if the material can receive shadows
@@ -226,6 +229,7 @@ protected:
SFVEC3F m_specularColor;
float m_shinness;
float m_transparency; ///< 1.0 is completely transparent, 0.0 completely opaque
+ float m_absorbance; ///< absorvance factor for the transparent material
float m_reflection; ///< 1.0 completely reflective, 0.0 no reflective
bool m_cast_shadows; ///< true if this object will block the light
--
2.7.4
Follow ups