From 6d270870534117575ec44e9197bca73170989682 Mon Sep 17 00:00:00 2001 From: Mario Luzeiro Date: Tue, 4 Oct 2016 22:23:21 +0100 Subject: [PATCH] Improve board texture (make it square), add directional light to top/bot. --- .../c3d_render_createscene.cpp | 121 ++++++++++-------- .../3d_render_raytracing/clight.h | 13 +- .../3d_render_raytracing/cmaterial.cpp | 9 +- 3 files changed, 80 insertions(+), 63 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 9a508b0963..29688ac17c 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 @@ -119,7 +119,7 @@ void C3D_RENDER_RAYTRACING::setupMaterials() (SFVEC3F)m_settings.m_SolderMaskColor ), SFVEC3F( 0.0f ), SFVEC3F( 0.35f ) ), // specular - 0.85f * 128.0f, // shiness + 0.95f * 128.0f, // shiness 0.12f, // transparency 0.16f ); // reflection @@ -260,58 +260,6 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER *aStatusTextReporter ) SFVEC3F camera_pos = m_settings.GetBoardCenter3DU(); 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() * 0.03f, - glm::pi() * 0.25f ), - SFVEC3F( light_directional_intensity_top ) ) ); - - m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 0.97f, - glm::pi() * 1.25f ), - SFVEC3F( light_directional_intensity_top ) ) ); - - - m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 1.0f / 8.0f, - glm::pi() * 1 / 4.0f ), - SFVEC3F( light_directional_intensity ) ) ); - m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 1.0f / 8.0f, - glm::pi() * 3 / 4.0f ), - SFVEC3F( light_directional_intensity ) ) ); - m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 1.0f / 8.0f, - glm::pi() * 5 / 4.0f ), - SFVEC3F( light_directional_intensity ) ) ); - m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 1.0f / 8.0f, - glm::pi() * 7 / 4.0f ), - SFVEC3F( light_directional_intensity ) ) ); - - - m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 7.0f / 8.0f, - glm::pi() * 1 / 4.0f ), - SFVEC3F( light_directional_intensity ) ) ); - m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 7.0f / 8.0f, - glm::pi() * 3 / 4.0f ), - SFVEC3F( light_directional_intensity ) ) ); - m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 7.0f / 8.0f, - glm::pi() * 5 / 4.0f ), - SFVEC3F( light_directional_intensity ) ) ); - m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 7.0f / 8.0f, - glm::pi() * 7 / 4.0f ), - SFVEC3F( light_directional_intensity ) ) ); - - m_object_container.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() * 0.03f, + glm::pi() * 0.25f ), + SFVEC3F( light_top_bottom ) ) ); + + m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 0.97f, + glm::pi() * 1.25f ), + SFVEC3F( light_top_bottom ) ) ); + */ + + m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 1.0f / 8.0f, + glm::pi() * 1 / 4.0f ), + SFVEC3F( light_directional_intensity ) ) ); + m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 1.0f / 8.0f, + glm::pi() * 3 / 4.0f ), + SFVEC3F( light_directional_intensity ) ) ); + m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 1.0f / 8.0f, + glm::pi() * 5 / 4.0f ), + SFVEC3F( light_directional_intensity ) ) ); + m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 1.0f / 8.0f, + glm::pi() * 7 / 4.0f ), + SFVEC3F( light_directional_intensity ) ) ); + + + m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 7.0f / 8.0f, + glm::pi() * 1 / 4.0f ), + SFVEC3F( light_directional_intensity ) ) ); + m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 7.0f / 8.0f, + glm::pi() * 3 / 4.0f ), + SFVEC3F( light_directional_intensity ) ) ); + m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 7.0f / 8.0f, + glm::pi() * 5 / 4.0f ), + SFVEC3F( light_directional_intensity ) ) ); + m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi() * 7.0f / 8.0f, + glm::pi() * 7 / 4.0f ), + SFVEC3F( light_directional_intensity ) ) ); + + // Create an accelerator // ///////////////////////////////////////////////////////////////////////// diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/clight.h b/3d-viewer/3d_rendering/3d_render_raytracing/clight.h index fb45d45093..296d25cc08 100644 --- a/3d-viewer/3d_rendering/3d_render_raytracing/clight.h +++ b/3d-viewer/3d_rendering/3d_render_raytracing/clight.h @@ -72,9 +72,9 @@ public: { m_position = aPos; m_color = aColor; - m_att_constant = 1.0f; - m_att_linear = 0.5f; - m_att_exp = 0.25f; + m_att_constant = 0.9f; + m_att_linear = 0.0005f; + m_att_exp = 0.001f; m_castShadow = true; } @@ -90,10 +90,9 @@ public: aOutDistance = glm::length( vectorLight ); aOutVectorToLight = vectorLight / aOutDistance; // normalize - - float att = 1.0f / ( m_att_constant + - m_att_linear * aOutDistance + - m_att_exp * aOutDistance * aOutDistance ); + const float att = 1.0f / ( m_att_constant + + m_att_linear * aOutDistance + + m_att_exp * aOutDistance * aOutDistance ); if( att <= 0.0f ) aOutLightColor = SFVEC3F( 0.0f, 0.0f, 0.0f ); diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/cmaterial.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/cmaterial.cpp index 59427150d8..8647393c05 100644 --- a/3d-viewer/3d_rendering/3d_render_raytracing/cmaterial.cpp +++ b/3d-viewer/3d_rendering/3d_render_raytracing/cmaterial.cpp @@ -152,10 +152,13 @@ SFVEC3F CBOARDNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const // 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; - const float y = (glm::sin(glm::sin( glm::sin( hitPos.y * m_scale ) * 1.9f ) * 1.5f ) + 0.0f) * 0.04f; + // Implement a texture as the "measling crazing blistering" method of FR4 - 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 ); }