Improve board texture (make it square), add directional light to top/bot.

This commit is contained in:
Mario Luzeiro 2016-10-04 22:23:21 +01:00 committed by Wayne Stambaugh
parent f59bde8cc3
commit 6d27087053
3 changed files with 80 additions and 63 deletions

View File

@ -119,7 +119,7 @@ void C3D_RENDER_RAYTRACING::setupMaterials()
(SFVEC3F)m_settings.m_SolderMaskColor ), (SFVEC3F)m_settings.m_SolderMaskColor ),
SFVEC3F( 0.0f ), SFVEC3F( 0.0f ),
SFVEC3F( 0.35f ) ), // specular SFVEC3F( 0.35f ) ), // specular
0.85f * 128.0f, // shiness 0.95f * 128.0f, // shiness
0.12f, // transparency 0.12f, // transparency
0.16f ); // reflection 0.16f ); // reflection
@ -260,58 +260,6 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER *aStatusTextReporter )
SFVEC3F camera_pos = m_settings.GetBoardCenter3DU(); SFVEC3F camera_pos = m_settings.GetBoardCenter3DU();
m_settings.CameraGet().SetBoardLookAtPos( camera_pos ); m_settings.CameraGet().SetBoardLookAtPos( camera_pos );
// Init initial lights
m_lights.Clear();
// This will work as the front camera light.
const float light_camera_intensity = 0.20;
const float light_directional_intensity_top = 0.35;
const float light_directional_intensity = ( 1.0f - ( light_camera_intensity +
light_directional_intensity_top ) ) / 4.0f;
m_camera_light = new CDIRECTIONALLIGHT( SFVEC3F( 0.0f, 0.0f, 0.0f ),
SFVEC3F( light_camera_intensity ) );
m_camera_light->SetCastShadows( false );
m_lights.Add( m_camera_light );
// http://www.flashandmath.com/mathlets/multicalc/coords/shilmay23fin.html
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 0.03f,
glm::pi<float>() * 0.25f ),
SFVEC3F( light_directional_intensity_top ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 0.97f,
glm::pi<float>() * 1.25f ),
SFVEC3F( light_directional_intensity_top ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 1.0f / 8.0f,
glm::pi<float>() * 1 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 1.0f / 8.0f,
glm::pi<float>() * 3 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 1.0f / 8.0f,
glm::pi<float>() * 5 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 1.0f / 8.0f,
glm::pi<float>() * 7 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 7.0f / 8.0f,
glm::pi<float>() * 1 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 7.0f / 8.0f,
glm::pi<float>() * 3 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 7.0f / 8.0f,
glm::pi<float>() * 5 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 7.0f / 8.0f,
glm::pi<float>() * 7 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_object_container.Clear(); m_object_container.Clear();
m_containerWithObjectsToDelete.Clear(); m_containerWithObjectsToDelete.Clear();
@ -879,6 +827,73 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER *aStatusTextReporter )
} }
// Init initial lights
// /////////////////////////////////////////////////////////////////////////
m_lights.Clear();
// This will work as the front camera light.
const float light_camera_intensity = 0.15;
const float light_top_bottom = 0.70;
const float light_directional_intensity = ( 1.0f - ( light_camera_intensity +
light_top_bottom * 0.5f ) ) / 4.0f;
m_camera_light = new CDIRECTIONALLIGHT( SFVEC3F( 0.0f, 0.0f, 0.0f ),
SFVEC3F( light_camera_intensity ) );
m_camera_light->SetCastShadows( false );
m_lights.Add( m_camera_light );
// Option 1 - using Point Lights
const SFVEC3F &boarCenter = m_settings.GetBBox3DU().GetCenter();
m_lights.Add( new CPOINTLIGHT( SFVEC3F( boarCenter.x, boarCenter.y, +RANGE_SCALE_3D * 2.0f ),
SFVEC3F( light_top_bottom ) ) );
m_lights.Add( new CPOINTLIGHT( SFVEC3F( boarCenter.x, boarCenter.y, -RANGE_SCALE_3D * 2.0f ),
SFVEC3F( light_top_bottom ) ) );
// http://www.flashandmath.com/mathlets/multicalc/coords/shilmay23fin.html
// Option 2 - Top/Bottom direction lights
/*
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 0.03f,
glm::pi<float>() * 0.25f ),
SFVEC3F( light_top_bottom ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 0.97f,
glm::pi<float>() * 1.25f ),
SFVEC3F( light_top_bottom ) ) );
*/
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 1.0f / 8.0f,
glm::pi<float>() * 1 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 1.0f / 8.0f,
glm::pi<float>() * 3 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 1.0f / 8.0f,
glm::pi<float>() * 5 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 1.0f / 8.0f,
glm::pi<float>() * 7 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 7.0f / 8.0f,
glm::pi<float>() * 1 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 7.0f / 8.0f,
glm::pi<float>() * 3 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 7.0f / 8.0f,
glm::pi<float>() * 5 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 7.0f / 8.0f,
glm::pi<float>() * 7 / 4.0f ),
SFVEC3F( light_directional_intensity ) ) );
// Create an accelerator // Create an accelerator
// ///////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////

View File

@ -72,9 +72,9 @@ public:
{ {
m_position = aPos; m_position = aPos;
m_color = aColor; m_color = aColor;
m_att_constant = 1.0f; m_att_constant = 0.9f;
m_att_linear = 0.5f; m_att_linear = 0.0005f;
m_att_exp = 0.25f; m_att_exp = 0.001f;
m_castShadow = true; m_castShadow = true;
} }
@ -90,10 +90,9 @@ public:
aOutDistance = glm::length( vectorLight ); aOutDistance = glm::length( vectorLight );
aOutVectorToLight = vectorLight / aOutDistance; // normalize aOutVectorToLight = vectorLight / aOutDistance; // normalize
const float att = 1.0f / ( m_att_constant +
float att = 1.0f / ( m_att_constant + m_att_linear * aOutDistance +
m_att_linear * aOutDistance + m_att_exp * aOutDistance * aOutDistance );
m_att_exp * aOutDistance * aOutDistance );
if( att <= 0.0f ) if( att <= 0.0f )
aOutLightColor = SFVEC3F( 0.0f, 0.0f, 0.0f ); aOutLightColor = SFVEC3F( 0.0f, 0.0f, 0.0f );

View File

@ -152,10 +152,13 @@ SFVEC3F CBOARDNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const
// http://www.fooplot.com/#W3sidHlwZSI6MCwiZXEiOiJzaW4oc2luKHNpbih4KSoxLjkpKjEuNSkiLCJjb2xvciI6IiMwMDAwMDAifSx7InR5cGUiOjEwMDAsIndpbmRvdyI6WyItMC45NjIxMDU3MDgwNzg1MjYyIiwiNy45NzE0MjYyNjc2MDE0MyIsIi0yLjUxNzYyMDM1MTQ4MjQ0OSIsIjIuOTc5OTM3Nzg3Mzk3NTMwMyJdLCJzaXplIjpbNjQ2LDM5Nl19XQ-- // http://www.fooplot.com/#W3sidHlwZSI6MCwiZXEiOiJzaW4oc2luKHNpbih4KSoxLjkpKjEuNSkiLCJjb2xvciI6IiMwMDAwMDAifSx7InR5cGUiOjEwMDAsIndpbmRvdyI6WyItMC45NjIxMDU3MDgwNzg1MjYyIiwiNy45NzE0MjYyNjc2MDE0MyIsIi0yLjUxNzYyMDM1MTQ4MjQ0OSIsIjIuOTc5OTM3Nzg3Mzk3NTMwMyJdLCJzaXplIjpbNjQ2LDM5Nl19XQ--
const float x = (glm::sin(glm::sin( glm::sin( hitPos.x * m_scale ) * 1.9f ) * 1.5f ) + 0.0f) * 0.10f; // Implement a texture as the "measling crazing blistering" method of FR4
const float y = (glm::sin(glm::sin( glm::sin( hitPos.y * m_scale ) * 1.9f ) * 1.5f ) + 0.0f) * 0.04f;
return SFVEC3F( x, y, 0.0f ); const float x = (glm::sin(glm::sin( glm::sin( hitPos.x * m_scale ) * 1.9f ) * 1.5f ) + 0.0f) * 0.10f;
const float y = (glm::sin(glm::sin( glm::sin( hitPos.y * m_scale ) * 1.9f ) * 1.5f ) + 0.0f) * 0.10f;
const float z = glm::sin( 2.0f * hitPos.z * m_scale + Fast_RandFloat() * 1.0f ) * 0.2f;
return SFVEC3F( x, y, z );
} }