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).
This commit is contained in:
Mario Luzeiro 2017-01-21 13:30:05 +01:00 committed by Chris Pavlina
parent 550a1ea4d6
commit 33449216b5
4 changed files with 19 additions and 9 deletions

View File

@ -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 );

View File

@ -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 ),

View File

@ -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;

View File

@ -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