KiCad PCB EDA Suite
C3D_RENDER_RAYTRACING Class Reference

#include <c3d_render_raytracing.h>

Inheritance diagram for C3D_RENDER_RAYTRACING:
C3D_RENDER_BASE

Public Member Functions

 C3D_RENDER_RAYTRACING (CINFO3D_VISU &aSettings)
 
 ~C3D_RENDER_RAYTRACING ()
 
void SetCurWindowSize (const wxSize &aSize) override
 SetCurWindowSize - Before each render, the canvas will tell the render what is the size of its windows, so render can take actions if it changed. More...
 
bool Redraw (bool aIsMoving, REPORTER *aStatusTextReporter) override
 Redraw - Ask to redraw the view. More...
 
int GetWaitForEditingTimeOut () override
 GetWaitForEditingTimeOut - Give the interface the time (in ms) that it should wait for editing or movements before (this works for display preview mode) More...
 
void ReloadRequest ()
 ReloadRequest - !TODO: this must be reviewed to add flags to improve specific render. More...
 
bool IsReloadRequestPending () const
 IsReloadRequestPending - Query if there is a pending reload request. More...
 

Protected Attributes

CINFO3D_VISUm_settings
 settings refrence in use for this render More...
 
bool m_is_opengl_initialized
 flag if the opengl specific for this render was already initialized More...
 
bool m_reloadRequested
 !TODO: this must be reviewed in order to flag change types More...
 
wxSize m_windowSize
 The window size that this camera is working. More...
 

Static Protected Attributes

static const wxChar * m_logTrace = wxT( "KI_TRACE_3D_RENDER" )
 Trace mask used to enable or disable the trace output of this class. More...
 

Private Member Functions

bool initializeOpenGL ()
 
void initializeNewWindowSize ()
 
void opengl_init_pbo ()
 
void opengl_delete_pbo ()
 
void reload (REPORTER *aStatusTextReporter)
 
void restart_render_state ()
 
void rt_render_tracing (GLubyte *ptrPBO, REPORTER *aStatusTextReporter)
 
void rt_render_post_process_shade (GLubyte *ptrPBO, REPORTER *aStatusTextReporter)
 
void rt_render_post_process_blur_finish (GLubyte *ptrPBO, REPORTER *aStatusTextReporter)
 
void rt_render_trace_block (GLubyte *ptrPBO, signed int iBlock)
 
void rt_final_color (GLubyte *ptrPBO, const SFVEC3F &rgbColor, bool applyColorSpaceConversion)
 
void rt_shades_packet (const SFVEC3F *bgColorY, const RAY *aRayPkt, HITINFO_PACKET *aHitPacket, bool is_testShadow, SFVEC3F *aOutHitColor)
 
void rt_trace_AA_packet (const SFVEC3F *aBgColorY, const HITINFO_PACKET *aHitPck_X0Y0, const HITINFO_PACKET *aHitPck_AA_X1Y1, const RAY *aRayPck, SFVEC3F *aOutHitColor)
 
void setupMaterials ()
 
SFVEC3F shadeHit (const SFVEC3F &aBgColor, const RAY &aRay, HITINFO &aHitInfo, bool aIsInsideObject, unsigned int aRecursiveLevel, bool is_testShadow) const
 
void create_3d_object_from (CCONTAINER &aDstContainer, const COBJECT2D *aObject2D, float aZMin, float aZMax, const CMATERIAL *aMaterial, const SFVEC3F &aObjColor)
 Function create_3d_object_from. More...
 
void add_3D_vias_and_pads_to_container ()
 
void insert3DViaHole (const VIA *aVia)
 
void insert3DPadHole (const D_PAD *aPad)
 
void load_3D_models ()
 
void add_3D_models (const S3DMODEL *a3DModel, const glm::mat4 &aModelMatrix)
 
void initialize_block_positions ()
 
void render (GLubyte *ptrPBO, REPORTER *aStatusTextReporter)
 
void render_preview (GLubyte *ptrPBO)
 

Private Attributes

struct {
   CBLINN_PHONG_MATERIAL   m_Paste
 
   CBLINN_PHONG_MATERIAL   m_SilkS
 
   CBLINN_PHONG_MATERIAL   m_SolderMask
 
   CBLINN_PHONG_MATERIAL   m_EpoxyBoard
 
   CBLINN_PHONG_MATERIAL   m_Copper
 
   CBLINN_PHONG_MATERIAL   m_Floor
 
m_materials
 
CBOARDNORMAL m_board_normal_perturbator
 
CCOPPERNORMAL m_copper_normal_perturbator
 
CSOLDERMASKNORMAL m_solder_mask_normal_perturbator
 
CPLASTICNORMAL m_plastic_normal_perturbator
 
CPLASTICSHINENORMAL m_plastic_shine_normal_perturbator
 
CMETALBRUSHEDNORMAL m_brushed_metal_normal_perturbator
 
bool m_isPreview
 
RT_RENDER_STATE m_rt_render_state
 State used on quality render. More...
 
unsigned long int m_stats_start_rendering_time
 Time that the render starts. More...
 
size_t m_nrBlocksRenderProgress
 Save the number of blocks progress of the render. More...
 
CPOSTSHADER_SSAO m_postshader_ssao
 
CLIGHTCONTAINER m_lights
 
CDIRECTIONALLIGHTm_camera_light
 
bool m_opengl_support_vertex_buffer_object
 
GLuint m_pboId
 
GLuint m_pboDataSize
 
CCONTAINER m_object_container
 
CCONTAINER2D m_containerWithObjectsToDelete
 This will store the list of created objects special for RT, that will be clear in the end. More...
 
CCONTAINER2Dm_outlineBoard2dObjects
 
CGENERICACCELERATORm_accelerator
 
SFVEC3F m_BgColorTop_LinearRGB
 
SFVEC3F m_BgColorBot_LinearRGB
 
wxSize m_oldWindowsSize
 used to see if the windows size changed More...
 
std::vector< SFVEC2UIm_blockPositions
 this encodes the Morton code positions More...
 
std::vector< int > m_blockPositionsWasProcessed
 this flags if a position was already processed (cleared each new render) More...
 
std::vector< SFVEC2UIm_blockPositionsFast
 this encodes the Morton code positions (on fast preview mode) More...
 
SFVEC2UI m_realBufferSize
 
SFVEC2UI m_fastPreviewModeSize
 
HITINFO_PACKETm_firstHitinfo
 
SFVEC3Fm_shaderBuffer
 
unsigned int m_xoffset
 
unsigned int m_yoffset
 
unsigned int m_stats_converted_dummy_to_plane
 
unsigned int m_stats_converted_roundsegment2d_to_roundsegment
 
MAP_MODEL_MATERIALS m_model_materials
 Stores materials of the 3D models. More...
 

Detailed Description

Definition at line 59 of file c3d_render_raytracing.h.

Constructor & Destructor Documentation

C3D_RENDER_RAYTRACING::C3D_RENDER_RAYTRACING ( CINFO3D_VISU aSettings)
explicit

Definition at line 48 of file c3d_render_raytracing.cpp.

References m_accelerator, m_camera_light, m_firstHitinfo, m_isPreview, C3D_RENDER_BASE::m_logTrace, m_nrBlocksRenderProgress, m_oldWindowsSize, m_opengl_support_vertex_buffer_object, m_outlineBoard2dObjects, m_pboDataSize, m_pboId, m_rt_render_state, m_shaderBuffer, m_stats_converted_dummy_to_plane, m_stats_converted_roundsegment2d_to_roundsegment, m_stats_start_rendering_time, m_xoffset, m_yoffset, and RT_RENDER_STATE_MAX.

48  :
49  C3D_RENDER_BASE( aSettings ),
50  m_postshader_ssao( aSettings.CameraGet() )
51 {
52  wxLogTrace( m_logTrace, wxT( "C3D_RENDER_RAYTRACING::C3D_RENDER_RAYTRACING" ) );
53 
55  m_pboId = GL_NONE;
56  m_pboDataSize = 0;
57  m_accelerator = NULL;
60  m_oldWindowsSize.x = 0;
61  m_oldWindowsSize.y = 0;
63  m_firstHitinfo = NULL;
64  m_shaderBuffer = NULL;
65  m_camera_light = NULL;
66 
67  m_xoffset = 0;
68  m_yoffset = 0;
69 
70  m_isPreview = false;
71  m_rt_render_state = RT_RENDER_STATE_MAX; // Set to an initial invalid state
74 }
CPOSTSHADER_SSAO m_postshader_ssao
wxSize m_oldWindowsSize
used to see if the windows size changed
HITINFO_PACKET * m_firstHitinfo
unsigned int m_stats_converted_dummy_to_plane
CGENERICACCELERATOR * m_accelerator
size_t m_nrBlocksRenderProgress
Save the number of blocks progress of the render.
C3D_RENDER_BASE(CINFO3D_VISU &aSettings)
RT_RENDER_STATE m_rt_render_state
State used on quality render.
unsigned int m_stats_converted_roundsegment2d_to_roundsegment
CDIRECTIONALLIGHT * m_camera_light
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
unsigned long int m_stats_start_rendering_time
Time that the render starts.
CCONTAINER2D * m_outlineBoard2dObjects
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
C3D_RENDER_RAYTRACING::~C3D_RENDER_RAYTRACING ( )

Definition at line 77 of file c3d_render_raytracing.cpp.

References m_accelerator, C3D_RENDER_BASE::m_logTrace, m_outlineBoard2dObjects, m_shaderBuffer, and opengl_delete_pbo().

78 {
79  wxLogTrace( m_logTrace, wxT( "C3D_RENDER_RAYTRACING::~C3D_RENDER_RAYTRACING" ) );
80 
81  delete m_accelerator;
82  m_accelerator = NULL;
83 
86 
87  delete[] m_shaderBuffer;
88  m_shaderBuffer = NULL;
89 
91 }
CGENERICACCELERATOR * m_accelerator
CCONTAINER2D * m_outlineBoard2dObjects
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.

Member Function Documentation

void C3D_RENDER_RAYTRACING::add_3D_models ( const S3DMODEL a3DModel,
const glm::mat4 &  aModelMatrix 
)
private

Definition at line 1299 of file c3d_render_createscene.cpp.

References abs, CGENERICCONTAINER::Add(), ConvertSRGBToLinear(), FL_RENDER_RAYTRACING_POST_PROCESSING, FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES, CINFO3D_VISU::GetFlag(), SMATERIAL::m_Ambient, m_brushed_metal_normal_perturbator, SMESH::m_Color, SMATERIAL::m_Diffuse, SMATERIAL::m_Emissive, SMESH::m_FaceIdx, SMESH::m_FaceIdxSize, SMESH::m_MaterialIdx, S3DMODEL::m_Materials, S3DMODEL::m_MaterialsSize, S3DMODEL::m_Meshes, S3DMODEL::m_MeshesSize, m_model_materials, SMESH::m_Normals, m_object_container, m_plastic_normal_perturbator, m_plastic_shine_normal_perturbator, SMESH::m_Positions, C3D_RENDER_BASE::m_settings, SMATERIAL::m_Shininess, SMATERIAL::m_Specular, SMATERIAL::m_Transparency, SMESH::m_VertexSize, MATERIAL_MODE_CAD_MODE, MATERIAL_MODE_NORMAL, MaterialDiffuseToColorCAD(), CINFO3D_VISU::MaterialModeGet(), RGBtoGray(), CTRIANGLE::SetColor(), COBJECT::SetMaterial(), and CMATERIAL::SetNormalPerturbator().

Referenced by load_3D_models().

1301 {
1302 
1303  // Validate a3DModel pointers
1304  wxASSERT( a3DModel != NULL );
1305 
1306  if( a3DModel == NULL )
1307  return;
1308 
1309  wxASSERT( a3DModel->m_Materials != NULL );
1310  wxASSERT( a3DModel->m_Meshes != NULL );
1311  wxASSERT( a3DModel->m_MaterialsSize > 0 );
1312  wxASSERT( a3DModel->m_MeshesSize > 0 );
1313 
1314  if( (a3DModel->m_Materials != NULL) && (a3DModel->m_Meshes != NULL) &&
1315  (a3DModel->m_MaterialsSize > 0) && (a3DModel->m_MeshesSize > 0) )
1316  {
1317 
1318  MODEL_MATERIALS *materialVector;
1319 
1320  // Try find if the materials already exists in the map list
1321  if( m_model_materials.find( a3DModel ) != m_model_materials.end() )
1322  {
1323  // Found it, so get the pointer
1324  materialVector = &m_model_materials[a3DModel];
1325  }
1326  else
1327  {
1328  // Materials was not found in the map, so it will create a new for
1329  // this model.
1330 
1331  m_model_materials[a3DModel] = MODEL_MATERIALS();
1332  materialVector = &m_model_materials[a3DModel];
1333 
1334  materialVector->resize( a3DModel->m_MaterialsSize );
1335 
1336  for( unsigned int imat = 0;
1337  imat < a3DModel->m_MaterialsSize;
1338  ++imat )
1339  {
1341  {
1342  const SMATERIAL &material = a3DModel->m_Materials[imat];
1343 
1344  // http://www.fooplot.com/#W3sidHlwZSI6MCwiZXEiOiJtaW4oc3FydCh4LTAuMzUpKjAuNDAtMC4wNSwxLjApIiwiY29sb3IiOiIjMDAwMDAwIn0seyJ0eXBlIjoxMDAwLCJ3aW5kb3ciOlsiMC4wNzA3NzM2NzMyMzY1OTAxMiIsIjEuNTY5NTcxNjI5MjI1NDY5OCIsIi0wLjI3NDYzNTMyMTc1OTkyOTMiLCIwLjY0NzcwMTg4MTkyNTUzNjIiXSwic2l6ZSI6WzY0NCwzOTRdfV0-
1345 
1346  float reflectionFactor = 0.0f;
1347 
1348  if( (material.m_Shininess - 0.35f) > FLT_EPSILON )
1349  {
1350  reflectionFactor = glm::clamp( glm::sqrt( (material.m_Shininess - 0.35f) ) *
1351  0.40f - 0.05f,
1352  0.0f,
1353  0.5f );
1354  }
1355 
1356  CBLINN_PHONG_MATERIAL &blinnMaterial = (*materialVector)[imat];
1357 
1358  SFVEC3F ambient;
1359 
1361  {
1362  // apply a gain to the (dark) ambient colors
1363 
1364  // http://www.fooplot.com/#W3sidHlwZSI6MCwiZXEiOiIoKHgrMC4yMCleKDEvMi4wMCkpLTAuMzUiLCJjb2xvciI6IiMwMDAwMDAifSx7InR5cGUiOjAsImVxIjoieCIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMCwid2luZG93IjpbIi0xLjI0OTUwNTMzOTIyMzYyIiwiMS42Nzc4MzQ0MTg1NjcxODQzIiwiLTAuNDM1NTA0NjQyODEwOTMwMjYiLCIxLjM2NTkzNTIwODEzNzI1OCJdLCJzaXplIjpbNjQ5LDM5OV19XQ--
1365  // ambient = glm::max( (glm::pow((material.m_Ambient + 0.20f), SFVEC3F(1.0f / 2.00f)) - SFVEC3F(0.35f)), material.m_Ambient );
1366 
1367  // http://www.fooplot.com/#W3sidHlwZSI6MCwiZXEiOiIoKHgrMC4yMCleKDEvMS41OCkpLTAuMzUiLCJjb2xvciI6IiMwMDAwMDAifSx7InR5cGUiOjAsImVxIjoieCIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMCwid2luZG93IjpbIi0xLjI0OTUwNTMzOTIyMzYyIiwiMS42Nzc4MzQ0MTg1NjcxODQzIiwiLTAuNDM1NTA0NjQyODEwOTMwMjYiLCIxLjM2NTkzNTIwODEzNzI1OCJdLCJzaXplIjpbNjQ5LDM5OV19XQ--
1368  //ambient = glm::max( (glm::pow((material.m_Ambient + 0.20f), SFVEC3F(1.0f / 1.58f)) - SFVEC3F(0.35f)), material.m_Ambient );
1369 
1370  // http://www.fooplot.com/#W3sidHlwZSI6MCwiZXEiOiIoKHgrMC4yMCleKDEvMS41NCkpLTAuMzQiLCJjb2xvciI6IiMwMDAwMDAifSx7InR5cGUiOjAsImVxIjoieCIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMCwid2luZG93IjpbIi0yLjcyMTA5NTg0MjA1MDYwNSIsIjEuODUyODcyNTI5NDk3NTIyMyIsIi0xLjQyMTM3NjAxOTkyOTA4MDYiLCIxLjM5MzM3Mzc0NzE3NzQ2MTIiXSwic2l6ZSI6WzY0OSwzOTldfV0-
1371  ambient = ConvertSRGBToLinear(
1372  glm::pow((material.m_Ambient + 0.30f), SFVEC3F(1.0f / 1.54f)) - SFVEC3F(0.34f) );
1373  }
1374  else
1375  {
1376  ambient = ConvertSRGBToLinear( material.m_Ambient );
1377  }
1378 
1379 
1380  blinnMaterial = CBLINN_PHONG_MATERIAL(
1381  ambient,
1382  ConvertSRGBToLinear( material.m_Emissive ),
1383  ConvertSRGBToLinear( material.m_Specular ),
1384  material.m_Shininess * 180.0f,
1385  material.m_Transparency,
1386  reflectionFactor );
1387 
1389  {
1390  // Guess material type and apply a normal perturbator
1391 
1392  if( ( RGBtoGray(material.m_Diffuse) < 0.3f ) &&
1393  ( material.m_Shininess < 0.36f ) &&
1394  ( material.m_Transparency == 0.0f ) &&
1395  ( (glm::abs( material.m_Diffuse.r - material.m_Diffuse.g ) < 0.15f) &&
1396  (glm::abs( material.m_Diffuse.b - material.m_Diffuse.g ) < 0.15f) &&
1397  (glm::abs( material.m_Diffuse.r - material.m_Diffuse.b ) < 0.15f) ) )
1398  {
1399  // This may be a black plastic..
1400 
1401  if( material.m_Shininess < 0.26f )
1403  else
1405  }
1406  else
1407  {
1408  if( ( RGBtoGray(material.m_Diffuse) > 0.3f ) &&
1409  ( material.m_Shininess < 0.30f ) &&
1410  ( material.m_Transparency == 0.0f ) &&
1411  ( (glm::abs( material.m_Diffuse.r - material.m_Diffuse.g ) > 0.25f) ||
1412  (glm::abs( material.m_Diffuse.b - material.m_Diffuse.g ) > 0.25f) ||
1413  (glm::abs( material.m_Diffuse.r - material.m_Diffuse.b ) > 0.25f) ) )
1414  {
1415  // This may be a color plastic ...
1417  }
1418  else
1419  {
1420  if( ( RGBtoGray(material.m_Diffuse) > 0.6f ) &&
1421  ( material.m_Shininess > 0.35f ) &&
1422  ( material.m_Transparency == 0.0f ) &&
1423  ( (glm::abs( material.m_Diffuse.r - material.m_Diffuse.g ) < 0.40f) &&
1424  (glm::abs( material.m_Diffuse.b - material.m_Diffuse.g ) < 0.40f) &&
1425  (glm::abs( material.m_Diffuse.r - material.m_Diffuse.b ) < 0.40f) ) )
1426  {
1427  // This may be a brushed metal
1429  }
1430  }
1431  }
1432  }
1433  }
1434  else
1435  {
1436  (*materialVector)[imat] = CBLINN_PHONG_MATERIAL( SFVEC3F( 0.2f ),
1437  SFVEC3F( 0.0f ),
1438  SFVEC3F( 0.0f ),
1439  0.0f,
1440  0.0f,
1441  0.0f );
1442  }
1443  }
1444  }
1445 
1446  const glm::mat3 normalMatrix = glm::transpose( glm::inverse( glm::mat3( aModelMatrix ) ) );
1447 
1448  for( unsigned int mesh_i = 0;
1449  mesh_i < a3DModel->m_MeshesSize;
1450  ++mesh_i )
1451  {
1452  const SMESH &mesh = a3DModel->m_Meshes[mesh_i];
1453 
1454  // Validate the mesh pointers
1455  wxASSERT( mesh.m_Positions != NULL );
1456  wxASSERT( mesh.m_FaceIdx != NULL );
1457  wxASSERT( mesh.m_Normals != NULL );
1458  wxASSERT( mesh.m_FaceIdxSize > 0 );
1459  wxASSERT( (mesh.m_FaceIdxSize % 3) == 0 );
1460 
1461 
1462  if( (mesh.m_Positions != NULL) &&
1463  (mesh.m_Normals != NULL) &&
1464  (mesh.m_FaceIdx != NULL) &&
1465  (mesh.m_FaceIdxSize > 0) &&
1466  (mesh.m_VertexSize > 0) &&
1467  ((mesh.m_FaceIdxSize % 3) == 0) &&
1468  (mesh.m_MaterialIdx < a3DModel->m_MaterialsSize) )
1469  {
1470  const CBLINN_PHONG_MATERIAL &blinn_material = (*materialVector)[mesh.m_MaterialIdx];
1471 
1472  // Add all face triangles
1473  for( unsigned int faceIdx = 0;
1474  faceIdx < mesh.m_FaceIdxSize;
1475  faceIdx += 3 )
1476  {
1477  const unsigned int idx0 = mesh.m_FaceIdx[faceIdx + 0];
1478  const unsigned int idx1 = mesh.m_FaceIdx[faceIdx + 1];
1479  const unsigned int idx2 = mesh.m_FaceIdx[faceIdx + 2];
1480 
1481  wxASSERT( idx0 < mesh.m_VertexSize );
1482  wxASSERT( idx1 < mesh.m_VertexSize );
1483  wxASSERT( idx2 < mesh.m_VertexSize );
1484 
1485  if( ( idx0 < mesh.m_VertexSize ) &&
1486  ( idx1 < mesh.m_VertexSize ) &&
1487  ( idx2 < mesh.m_VertexSize ) )
1488  {
1489  const SFVEC3F &v0 = mesh.m_Positions[idx0];
1490  const SFVEC3F &v1 = mesh.m_Positions[idx1];
1491  const SFVEC3F &v2 = mesh.m_Positions[idx2];
1492 
1493  const SFVEC3F &n0 = mesh.m_Normals[idx0];
1494  const SFVEC3F &n1 = mesh.m_Normals[idx1];
1495  const SFVEC3F &n2 = mesh.m_Normals[idx2];
1496 
1497  // Transform vertex with the model matrix
1498  const SFVEC3F vt0 = SFVEC3F( aModelMatrix * glm::vec4( v0, 1.0f) );
1499  const SFVEC3F vt1 = SFVEC3F( aModelMatrix * glm::vec4( v1, 1.0f) );
1500  const SFVEC3F vt2 = SFVEC3F( aModelMatrix * glm::vec4( v2, 1.0f) );
1501 
1502  const SFVEC3F nt0 = glm::normalize( SFVEC3F( normalMatrix * n0 ) );
1503  const SFVEC3F nt1 = glm::normalize( SFVEC3F( normalMatrix * n1 ) );
1504  const SFVEC3F nt2 = glm::normalize( SFVEC3F( normalMatrix * n2 ) );
1505 
1506  CTRIANGLE *newTriangle = new CTRIANGLE( vt0, vt2, vt1,
1507  nt0, nt2, nt1 );
1508 
1509 
1510 
1511  m_object_container.Add( newTriangle );
1512  newTriangle->SetMaterial( (const CMATERIAL *)&blinn_material );
1513 
1514  if( mesh.m_Color == NULL )
1515  {
1516  const SFVEC3F diffuseColor =
1517  a3DModel->m_Materials[mesh.m_MaterialIdx].m_Diffuse;
1518 
1520  newTriangle->SetColor( ConvertSRGBToLinear( MaterialDiffuseToColorCAD( diffuseColor ) ) );
1521  else
1522  newTriangle->SetColor( ConvertSRGBToLinear( diffuseColor ) );
1523  }
1524  else
1525  {
1527  newTriangle->SetColor( ConvertSRGBToLinear( MaterialDiffuseToColorCAD( mesh.m_Color[idx0] ) ),
1530  else
1531  newTriangle->SetColor( ConvertSRGBToLinear( mesh.m_Color[idx0] ),
1532  ConvertSRGBToLinear( mesh.m_Color[idx1] ),
1533  ConvertSRGBToLinear( mesh.m_Color[idx2] ) );
1534  }
1535  }
1536  }
1537  }
1538  }
1539  }
1540 }
SFVEC3F * m_Normals
Vertex normals array.
Definition: c3dmodel.h:80
float RGBtoGray(const SFVEC3F &aColor)
Definition: 3d_math.h:147
SFVEC3F m_Ambient
Definition: c3dmodel.h:39
CPLASTICNORMAL m_plastic_normal_perturbator
SFVEC3F ConvertSRGBToLinear(const SFVEC3F &aSRGBcolor)
MATERIAL_MODE MaterialModeGet() const
MaterialModeGet.
Definition: cinfo3d_visu.h:246
A base material class that can be used to derive a material implementation.
Definition: cmaterial.h:167
void SetMaterial(const CMATERIAL *aMaterial)
Definition: cobject.h:62
CPLASTICSHINENORMAL m_plastic_shine_normal_perturbator
float m_Transparency
1.0 is completely transparent, 0.0 completely opaque
Definition: c3dmodel.h:44
void SetNormalPerturbator(const CPROCEDURALGENERATOR *aPerturbator)
Definition: cmaterial.h:220
SFVEC3F * m_Positions
Vertex position array.
Definition: c3dmodel.h:79
CMETALBRUSHEDNORMAL m_brushed_metal_normal_perturbator
CINFO3D_VISU & m_settings
settings refrence in use for this render
#define abs(a)
Definition: auxiliary.h:84
Per-vertex normal/color/texcoors structure.
Definition: c3dmodel.h:76
SMESH * m_Meshes
The meshes list of this model.
Definition: c3dmodel.h:93
unsigned int m_FaceIdxSize
Number of elements of the m_FaceIdx array.
Definition: c3dmodel.h:83
std::vector< CBLINN_PHONG_MATERIAL > MODEL_MATERIALS
Vector of materials.
void SetColor(const SFVEC3F &aColor)
Definition: ctriangle.cpp:161
unsigned int m_VertexSize
Number of vertex in the arrays.
Definition: c3dmodel.h:78
Blinn Phong based material https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model.
Definition: cmaterial.h:248
SFVEC3F * m_Color
Vertex color array, can be NULL.
Definition: c3dmodel.h:82
Use a gray shading based on diffuse material.
Definition: 3d_enums.h:94
float m_Shininess
Definition: c3dmodel.h:43
unsigned int m_MaterialsSize
Number of materials in the material array.
Definition: c3dmodel.h:95
A triangle object.
Definition: ctriangle.h:42
void Add(COBJECT *aObject)
Definition: ccontainer.h:52
Use all material properties from model file.
Definition: 3d_enums.h:92
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
SFVEC3F MaterialDiffuseToColorCAD(const SFVEC3F &aDiffuseColor)
Definition: 3d_math.h:154
SFVEC3F m_Emissive
Definition: c3dmodel.h:41
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
unsigned int m_MaterialIdx
Material Index to be used in this mesh (must be < m_MaterialsSize )
Definition: c3dmodel.h:85
SMATERIAL * m_Materials
The materials list of this model.
Definition: c3dmodel.h:96
SFVEC3F m_Diffuse
Default diffuse color if m_Color is NULL.
Definition: c3dmodel.h:40
unsigned int * m_FaceIdx
Triangle Face Indexes.
Definition: c3dmodel.h:84
unsigned int m_MeshesSize
Number of meshes in the array.
Definition: c3dmodel.h:92
MAP_MODEL_MATERIALS m_model_materials
Stores materials of the 3D models.
SFVEC3F m_Specular
Definition: c3dmodel.h:42
void C3D_RENDER_RAYTRACING::add_3D_vias_and_pads_to_container ( )
private

Definition at line 1168 of file c3d_render_createscene.cpp.

References CINFO3D_VISU::GetBoard(), insert3DPadHole(), insert3DViaHole(), BOARD::m_Modules, C3D_RENDER_BASE::m_settings, BOARD::m_Track, TRACK::Next(), MODULE::Next(), D_PAD::Next(), PAD_ATTRIB_HOLE_NOT_PLATED, and PCB_VIA_T.

Referenced by reload().

1169 {
1170  // Insert plated vertical holes inside the board
1171  // /////////////////////////////////////////////////////////////////////////
1172 
1173  // Insert vias holes (vertical cylinders)
1174  for( const TRACK* track = m_settings.GetBoard()->m_Track;
1175  track;
1176  track = track->Next() )
1177  {
1178  if( track->Type() == PCB_VIA_T )
1179  {
1180  const VIA *via = static_cast<const VIA*>(track);
1181  insert3DViaHole( via );
1182  }
1183  }
1184 
1185  // Insert pads holes (vertical cylinders)
1186  for( const MODULE* module = m_settings.GetBoard()->m_Modules;
1187  module;
1188  module = module->Next() )
1189  {
1190  for( const D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
1191  if( pad->GetAttribute () != PAD_ATTRIB_HOLE_NOT_PLATED )
1192  {
1193  insert3DPadHole( pad );
1194  }
1195  }
1196 }
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:65
MODULE * Next() const
Definition: class_module.h:122
void insert3DViaHole(const VIA *aVia)
CINFO3D_VISU & m_settings
settings refrence in use for this render
D_PAD * Next() const
Definition: class_pad.h:160
TRACK * Next() const
Definition: class_track.h:103
DLIST< MODULE > m_Modules
Definition: class_board.h:249
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
DLIST< TRACK > m_Track
Definition: class_board.h:250
void insert3DPadHole(const D_PAD *aPad)
const BOARD * GetBoard() const
GetBoard - Get current board to be rendered.
Definition: cinfo3d_visu.h:128
void C3D_RENDER_RAYTRACING::create_3d_object_from ( CCONTAINER aDstContainer,
const COBJECT2D aObject2D,
float  aZMin,
float  aZMax,
const CMATERIAL aMaterial,
const SFVEC3F aObjColor 
)
private

Function create_3d_object_from.

Creates on or more 3D objects form a 2D object and Z positions. It try optimize some types of objects that will be faster to trace than the CLAYERITEM object.

Parameters
aObject2D
aZMin
aZMax

Definition at line 179 of file c3d_render_createscene.cpp.

References CGENERICCONTAINER::Add(), ConvertSRGBToLinear(), COBJECT2D::GetBBox(), COBJECT2D::GetObjectType(), m_stats_converted_dummy_to_plane, m_stats_converted_roundsegment2d_to_roundsegment, CBBOX2D::Max(), CBBOX2D::Min(), OBJ2D_DUMMYBLOCK, OBJ2D_ROUNDSEG, CLAYERITEM::SetColor(), CROUNDSEG::SetColor(), CXYPLANE::SetColor(), and COBJECT::SetMaterial().

Referenced by reload().

184 {
185  switch( aObject2D->GetObjectType() )
186  {
187  case OBJ2D_DUMMYBLOCK:
188  {
190 #if 1
191  CXYPLANE *objPtr;
192  objPtr = new CXYPLANE( CBBOX ( SFVEC3F( aObject2D->GetBBox().Min().x,
193  aObject2D->GetBBox().Min().y,
194  aZMin ),
195  SFVEC3F( aObject2D->GetBBox().Max().x,
196  aObject2D->GetBBox().Max().y,
197  aZMin ) ) );
198  objPtr->SetMaterial( aMaterial );
199  objPtr->SetColor( ConvertSRGBToLinear( aObjColor ) );
200  aDstContainer.Add( objPtr );
201 
202  objPtr = new CXYPLANE( CBBOX ( SFVEC3F( aObject2D->GetBBox().Min().x,
203  aObject2D->GetBBox().Min().y,
204  aZMax ),
205  SFVEC3F( aObject2D->GetBBox().Max().x,
206  aObject2D->GetBBox().Max().y,
207  aZMax ) ) );
208  objPtr->SetMaterial( aMaterial );
209  objPtr->SetColor( ConvertSRGBToLinear( aObjColor ) );
210  aDstContainer.Add( objPtr );
211 #else
212  objPtr = new CDUMMYBLOCK( CBBOX ( SFVEC3F( aObject2D->GetBBox().Min().x,
213  aObject2D->GetBBox().Min().y,
214  aZMin ),
215  SFVEC3F( aObject2D->GetBBox().Max().x,
216  aObject2D->GetBBox().Max().y,
217  aZMax ) ) );
218  objPtr->SetMaterial( aMaterial );
219  aDstContainer.Add( objPtr );
220 #endif
221  }
222  break;
223 
224  case OBJ2D_ROUNDSEG:
225  {
227 
228  const CROUNDSEGMENT2D *aRoundSeg2D = static_cast<const CROUNDSEGMENT2D *>( aObject2D );
229  CROUNDSEG *objPtr = new CROUNDSEG( *aRoundSeg2D, aZMin, aZMax );
230  objPtr->SetMaterial( aMaterial );
231  objPtr->SetColor( ConvertSRGBToLinear( aObjColor ) );
232  aDstContainer.Add( objPtr );
233  }
234  break;
235 
236 
237  default:
238  {
239  CLAYERITEM *objPtr = new CLAYERITEM( aObject2D, aZMin, aZMax );
240  objPtr->SetMaterial( aMaterial );
241  objPtr->SetColor( ConvertSRGBToLinear( aObjColor ) );
242  aDstContainer.Add( objPtr );
243  }
244  break;
245  }
246 }
SFVEC3F ConvertSRGBToLinear(const SFVEC3F &aSRGBcolor)
void SetMaterial(const CMATERIAL *aMaterial)
Definition: cobject.h:62
A dummy block is used to fill the polygons.
Definition: cdummyblock.h:39
void SetColor(SFVEC3F aObjColor)
Definition: croundseg.h:48
A plane that is parallel to XY plane.
Definition: cplane.h:38
unsigned int m_stats_converted_dummy_to_plane
void SetColor(SFVEC3F aObjColor)
Definition: cplane.h:52
OBJECT2D_TYPE GetObjectType() const
Definition: cobject2d.h:125
unsigned int m_stats_converted_roundsegment2d_to_roundsegment
void SetColor(SFVEC3F aObjColor)
Definition: clayeritem.h:46
void Add(COBJECT *aObject)
Definition: ccontainer.h:52
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
const CBBOX2D & GetBBox() const
Definition: cobject2d.h:121
const SFVEC2F & Min() const
Function Min return the minimun vertex pointer.
Definition: cbbox2d.h:176
Class CBBOX manages a bounding box defined by two SFVEC3F min max points.
Definition: cbbox.h:40
const SFVEC2F & Max() const
Function Max return the maximum vertex pointer.
Definition: cbbox2d.h:183
int C3D_RENDER_RAYTRACING::GetWaitForEditingTimeOut ( )
overridevirtual

GetWaitForEditingTimeOut - Give the interface the time (in ms) that it should wait for editing or movements before (this works for display preview mode)

Returns
a value in miliseconds

Implements C3D_RENDER_BASE.

Definition at line 94 of file c3d_render_raytracing.cpp.

95 {
96  return 1000; // ms
97 }
void C3D_RENDER_RAYTRACING::initialize_block_positions ( )
private

Definition at line 2077 of file c3d_render_raytracing.cpp.

References DecodeMorton2X(), DecodeMorton2Y(), i, m_blockPositions, m_blockPositionsFast, m_fastPreviewModeSize, m_postshader_ssao, m_realBufferSize, m_shaderBuffer, C3D_RENDER_BASE::m_windowSize, m_xoffset, m_yoffset, opengl_init_pbo(), RAYPACKET_DIM, RAYPACKET_INVMASK, and CPOSTSHADER::UpdateSize().

Referenced by Redraw().

2078 {
2079 
2080  m_realBufferSize = SFVEC2UI( 0 );
2081 
2082  // Calc block positions for fast preview mode
2083  // /////////////////////////////////////////////////////////////////////
2084  m_blockPositionsFast.clear();
2085 
2086  unsigned int i = 0;
2087 
2088  while(1)
2089  {
2090  const unsigned int mX = DecodeMorton2X(i);
2091  const unsigned int mY = DecodeMorton2Y(i);
2092 
2093  i++;
2094 
2095  const SFVEC2UI blockPos( mX * 4 * RAYPACKET_DIM - mX * 4,
2096  mY * 4 * RAYPACKET_DIM - mY * 4);
2097 
2098  if( ( blockPos.x >= ( (unsigned int)m_windowSize.x - ( 4 * RAYPACKET_DIM + 4 ) ) ) &&
2099  ( blockPos.y >= ( (unsigned int)m_windowSize.y - ( 4 * RAYPACKET_DIM + 4 ) ) ) )
2100  break;
2101 
2102  if( ( blockPos.x < ( (unsigned int)m_windowSize.x - ( 4 * RAYPACKET_DIM + 4) ) ) &&
2103  ( blockPos.y < ( (unsigned int)m_windowSize.y - ( 4 * RAYPACKET_DIM + 4) ) ) )
2104  {
2105  m_blockPositionsFast.push_back( blockPos );
2106 
2107  if( blockPos.x > m_realBufferSize.x )
2108  m_realBufferSize.x = blockPos.x;
2109 
2110  if( blockPos.y > m_realBufferSize.y )
2111  m_realBufferSize.y = blockPos.y;
2112  }
2113  }
2114 
2116 
2119 
2120  m_xoffset = (m_windowSize.x - m_realBufferSize.x) / 2;
2121  m_yoffset = (m_windowSize.y - m_realBufferSize.y) / 2;
2122 
2124 
2125 
2126  // Calc block positions
2127  // /////////////////////////////////////////////////////////////////////
2128  m_blockPositions.clear();
2131 
2132  i = 0;
2133 
2134  while(1)
2135  {
2136  SFVEC2UI blockPos( DecodeMorton2X(i) * RAYPACKET_DIM,
2137  DecodeMorton2Y(i) * RAYPACKET_DIM );
2138  i++;
2139 
2140  if( (blockPos.x >= m_realBufferSize.x) && (blockPos.y >= m_realBufferSize.y) )
2141  break;
2142 
2143  if( (blockPos.x < m_realBufferSize.x) && (blockPos.y < m_realBufferSize.y) )
2144  m_blockPositions.push_back( blockPos );
2145  }
2146 
2147  // Create m_shader buffer
2148  delete[] m_shaderBuffer;
2150 
2151  opengl_init_pbo();
2152 }
#define RAYPACKET_DIM
Definition: raypacket.h:37
CPOSTSHADER_SSAO m_postshader_ssao
uint32_t DecodeMorton2X(uint32_t code)
Definition: mortoncodes.cpp:98
#define RAYPACKET_INVMASK
Definition: raypacket.h:39
uint32_t DecodeMorton2Y(uint32_t code)
glm::uvec2 SFVEC2UI
Definition: xv3d_types.h:41
wxSize m_windowSize
The window size that this camera is working.
std::vector< SFVEC2UI > m_blockPositionsFast
this encodes the Morton code positions (on fast preview mode)
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
std::vector< SFVEC2UI > m_blockPositions
this encodes the Morton code positions
size_t i
Definition: json11.cpp:597
void UpdateSize(const SFVEC2UI &aSize)
Definition: cpostshader.cpp:72
void C3D_RENDER_RAYTRACING::initializeNewWindowSize ( )
private

Definition at line 2034 of file c3d_render_raytracing.cpp.

References opengl_init_pbo().

Referenced by SetCurWindowSize().

2035 {
2036  opengl_init_pbo();
2037 }
bool C3D_RENDER_RAYTRACING::initializeOpenGL ( )
private

Definition at line 2069 of file c3d_render_raytracing.cpp.

References C3D_RENDER_BASE::m_is_opengl_initialized.

Referenced by Redraw().

2070 {
2071  m_is_opengl_initialized = true;
2072 
2073  return true;
2074 }
bool m_is_opengl_initialized
flag if the opengl specific for this render was already initialized
void C3D_RENDER_RAYTRACING::insert3DPadHole ( const D_PAD aPad)
private

Definition at line 1011 of file c3d_render_createscene.cpp.

References CGENERICCONTAINER2D::Add(), CGENERICCONTAINER::Add(), B_Cu, CINFO3D_VISU::BiuTo3Dunits(), ConvertSRGBToLinear(), CSGITEM_EMPTY, CSGITEM_FULL, F_Cu, FL_USE_REALISTIC_MODE, COBJECT2D::GetBBox(), CINFO3D_VISU::GetCopperThickness3DU(), CINFO3D_VISU::GetCopperThicknessBIU(), D_PAD::GetDrillSize(), CINFO3D_VISU::GetFlag(), CINFO3D_VISU::GetItemColor(), CINFO3D_VISU::GetLayerBottomZpos3DU(), CGENERICCONTAINER2D::GetList(), CBVHCONTAINER2D::GetListObjectsIntersects(), D_PAD::GetOrientation(), D_PAD::GetPosition(), CINFO3D_VISU::GetThroughHole_Inner(), COBJECT2D::Intersects(), LAYER_PADS_TH, m_containerWithObjectsToDelete, CINFO3D_VISU::m_CopperColor, m_materials, m_object_container, C3D_RENDER_BASE::m_settings, RotatePoint(), CLAYERITEM::SetColor(), and COBJECT::SetMaterial().

Referenced by add_3D_vias_and_pads_to_container().

1012 {
1013  const COBJECT2D *object2d_A = NULL;
1014 
1015  SFVEC3F objColor;
1016 
1018  objColor = (SFVEC3F)m_settings.m_CopperColor;
1019  else
1020  objColor = m_settings.GetItemColor( LAYER_PADS_TH );
1021 
1022  const wxSize drillsize = aPad->GetDrillSize();
1023  const bool hasHole = drillsize.x && drillsize.y;
1024 
1025  if( !hasHole )
1026  return;
1027 
1028  const float topZ = m_settings.GetLayerBottomZpos3DU( F_Cu ) +
1030 
1031  const float botZ = m_settings.GetLayerBottomZpos3DU( B_Cu ) -
1033 
1034  if( drillsize.x == drillsize.y ) // usual round hole
1035  {
1036  SFVEC2F center = SFVEC2F( aPad->GetPosition().x * m_settings.BiuTo3Dunits(),
1037  -aPad->GetPosition().y * m_settings.BiuTo3Dunits() );
1038 
1039  CRING2D *ring = new CRING2D( center,
1040  ( drillsize.x / 2 ) * m_settings.BiuTo3Dunits(),
1041  ( ( drillsize.x / 2 ) +
1044  *aPad );
1045 
1047 
1048  object2d_A = ring;
1049  }
1050  else // Oblong hole
1051  {
1052  wxPoint ends_offset;
1053  int width;
1054 
1055  if( drillsize.x > drillsize.y ) // Horizontal oval
1056  {
1057  ends_offset.x = ( drillsize.x - drillsize.y ) / 2;
1058  width = drillsize.y;
1059  }
1060  else // Vertical oval
1061  {
1062  ends_offset.y = ( drillsize.y - drillsize.x ) / 2;
1063  width = drillsize.x;
1064  }
1065 
1066  RotatePoint( &ends_offset, aPad->GetOrientation() );
1067 
1068  wxPoint start = aPad->GetPosition() + ends_offset;
1069  wxPoint end = aPad->GetPosition() - ends_offset;
1070 
1071  CROUNDSEGMENT2D *innerSeg = new CROUNDSEGMENT2D(
1072  SFVEC2F( start.x * m_settings.BiuTo3Dunits(),
1073  -start.y * m_settings.BiuTo3Dunits() ),
1074  SFVEC2F( end.x * m_settings.BiuTo3Dunits(),
1075  -end.y * m_settings.BiuTo3Dunits() ),
1076  width * m_settings.BiuTo3Dunits(),
1077  *aPad );
1078 
1079  CROUNDSEGMENT2D *outterSeg = new CROUNDSEGMENT2D(
1080  SFVEC2F( start.x * m_settings.BiuTo3Dunits(),
1081  -start.y * m_settings.BiuTo3Dunits() ),
1082  SFVEC2F( end.x * m_settings.BiuTo3Dunits(),
1083  -end.y * m_settings.BiuTo3Dunits() ),
1084  ( width + m_settings.GetCopperThicknessBIU() * 2 ) *
1086  *aPad );
1087 
1088  // NOTE: the round segment width is the "diameter", so we double the thickness
1089 
1090  std::vector<const COBJECT2D *> *object2d_B = new std::vector<const COBJECT2D *>();
1091  object2d_B->push_back( innerSeg );
1092 
1093  CITEMLAYERCSG2D *itemCSG2d = new CITEMLAYERCSG2D( outterSeg,
1094  object2d_B,
1095  CSGITEM_FULL,
1096  *aPad );
1097 
1098  m_containerWithObjectsToDelete.Add( itemCSG2d );
1099  m_containerWithObjectsToDelete.Add( innerSeg );
1100  m_containerWithObjectsToDelete.Add( outterSeg );
1101 
1102  object2d_A = itemCSG2d;
1103  }
1104 
1105 
1106  if( object2d_A )
1107  {
1108  std::vector<const COBJECT2D *> *object2d_B = new std::vector<const COBJECT2D *>();
1109 
1110  // Check if there are any other THT that intersects this hole
1111  // It will use the non inflated holes
1112  if( !m_settings.GetThroughHole_Inner().GetList().empty() )
1113  {
1114 
1115  CONST_LIST_OBJECT2D intersectionList;
1117  intersectionList );
1118 
1119  if( !intersectionList.empty() )
1120  {
1121  for( CONST_LIST_OBJECT2D::const_iterator hole = intersectionList.begin();
1122  hole != intersectionList.end();
1123  ++hole )
1124  {
1125  const COBJECT2D *hole2d = static_cast<const COBJECT2D *>(*hole);
1126 
1127  if( object2d_A->Intersects( hole2d->GetBBox() ) )
1128  //if( object2d_A->GetBBox().Intersects( hole2d->GetBBox() ) )
1129  object2d_B->push_back( hole2d );
1130  }
1131  }
1132  }
1133 
1134  if( object2d_B->empty() )
1135  {
1136  delete object2d_B;
1137  object2d_B = CSGITEM_EMPTY;
1138  }
1139 
1140  if( object2d_B == CSGITEM_EMPTY )
1141  {
1142  CLAYERITEM *objPtr = new CLAYERITEM( object2d_A, topZ, botZ );
1143 
1144  objPtr->SetMaterial( &m_materials.m_Copper );
1145  objPtr->SetColor( ConvertSRGBToLinear( objColor ) );
1146  m_object_container.Add( objPtr );
1147  }
1148  else
1149  {
1150  CITEMLAYERCSG2D *itemCSG2d = new CITEMLAYERCSG2D( object2d_A,
1151  object2d_B,
1152  CSGITEM_FULL,
1153  (const BOARD_ITEM &)*aPad );
1154 
1155  m_containerWithObjectsToDelete.Add( itemCSG2d );
1156 
1157  CLAYERITEM *objPtr = new CLAYERITEM( itemCSG2d, topZ, botZ );
1158 
1159  objPtr->SetMaterial( &m_materials.m_Copper );
1160  objPtr->SetColor( ConvertSRGBToLinear( objColor ) );
1161 
1162  m_object_container.Add( objPtr );
1163  }
1164  }
1165 }
void GetListObjectsIntersects(const CBBOX2D &aBBox, CONST_LIST_OBJECT2D &aOutList) const override
GetListObjectsIntersects - Get a list of objects that intersects a bbox.
struct C3D_RENDER_RAYTRACING::@37 m_materials
const LIST_OBJECT2D & GetList() const
Definition: ccontainer2d.h:64
SFVEC3F ConvertSRGBToLinear(const SFVEC3F &aSRGBcolor)
float GetCopperThickness3DU() const
GetCopperThickness3DU - Get the current copper layer thickness.
Definition: cinfo3d_visu.h:165
multilayer pads, usually with holes
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
SFVEC3D m_CopperColor
in realistic mode: copper color
Definition: cinfo3d_visu.h:509
SFVEC3F GetItemColor(int aItemId) const
GetItemColor - get the technical color of a layer.
std::list< const COBJECT2D * > CONST_LIST_OBJECT2D
Definition: ccontainer2d.h:38
void SetMaterial(const CMATERIAL *aMaterial)
Definition: cobject.h:62
int GetCopperThicknessBIU() const
GetCopperThicknessBIU - Get the current copper layer thickness.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
const wxSize & GetDrillSize() const
Definition: class_pad.h:275
CINFO3D_VISU & m_settings
settings refrence in use for this render
#define CSGITEM_EMPTY
This class is used to make constructive solig geometry for items objects on layers.
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
float GetLayerBottomZpos3DU(PCB_LAYER_ID aLayerId) const
GetLayerBottomZpos3DU - Get the bottom z position.
Definition: cinfo3d_visu.h:287
CCONTAINER2D m_containerWithObjectsToDelete
This will store the list of created objects special for RT, that will be clear in the end...
#define CSGITEM_FULL
void SetColor(SFVEC3F aObjColor)
Definition: clayeritem.h:46
void Add(COBJECT *aObject)
Definition: ccontainer.h:52
const CBVHCONTAINER2D & GetThroughHole_Inner() const
GetThroughHole_Inner - Get the ThroughHole container.
Definition: cinfo3d_visu.h:350
void Add(COBJECT2D *aObject)
Definition: ccontainer2d.h:52
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:382
const CBBOX2D & GetBBox() const
Definition: cobject2d.h:121
const wxPoint GetPosition() const override
Definition: class_pad.h:220
virtual bool Intersects(const CBBOX2D &aBBox) const =0
Function Intersects.
double BiuTo3Dunits() const
BiuTo3Dunits - Board integer units To 3D units.
Definition: cinfo3d_visu.h:141
void C3D_RENDER_RAYTRACING::insert3DViaHole ( const VIA aVia)
private

Definition at line 971 of file c3d_render_createscene.cpp.

References CGENERICCONTAINER2D::Add(), CGENERICCONTAINER::Add(), CINFO3D_VISU::BiuTo3Dunits(), ConvertSRGBToLinear(), FL_USE_REALISTIC_MODE, CINFO3D_VISU::GetCopperThickness3DU(), CINFO3D_VISU::GetCopperThicknessBIU(), VIA::GetDrillValue(), CINFO3D_VISU::GetFlag(), CINFO3D_VISU::GetItemColor(), CINFO3D_VISU::GetLayerBottomZpos3DU(), TRACK::GetStart(), VIA::GetViaType(), LAYER_VIAS, VIA::LayerPair(), m_containerWithObjectsToDelete, CINFO3D_VISU::m_CopperColor, m_materials, m_object_container, C3D_RENDER_BASE::m_settings, CLAYERITEM::SetColor(), and COBJECT::SetMaterial().

Referenced by add_3D_vias_and_pads_to_container().

972 {
973  PCB_LAYER_ID top_layer, bottom_layer;
974  int radiusBUI = (aVia->GetDrillValue() / 2);
975 
976  aVia->LayerPair( &top_layer, &bottom_layer );
977 
978  float topZ = m_settings.GetLayerBottomZpos3DU( top_layer ) +
980 
981  float botZ = m_settings.GetLayerBottomZpos3DU( bottom_layer ) -
983 
984  const SFVEC2F center = SFVEC2F( aVia->GetStart().x * m_settings.BiuTo3Dunits(),
985  -aVia->GetStart().y * m_settings.BiuTo3Dunits() );
986 
987  CRING2D *ring = new CRING2D( center,
988  radiusBUI * m_settings.BiuTo3Dunits(),
989  ( radiusBUI + m_settings.GetCopperThicknessBIU() ) *
991  *aVia );
992 
994 
995 
996  CLAYERITEM *objPtr = new CLAYERITEM( ring, topZ, botZ );
997 
998  objPtr->SetMaterial( &m_materials.m_Copper );
999 
1002  else
1004 
1005  m_object_container.Add( objPtr );
1006 }
struct C3D_RENDER_RAYTRACING::@37 m_materials
SFVEC3F ConvertSRGBToLinear(const SFVEC3F &aSRGBcolor)
float GetCopperThickness3DU() const
GetCopperThickness3DU - Get the current copper layer thickness.
Definition: cinfo3d_visu.h:165
SFVEC3D m_CopperColor
in realistic mode: copper color
Definition: cinfo3d_visu.h:509
SFVEC3F GetItemColor(int aItemId) const
GetItemColor - get the technical color of a layer.
void SetMaterial(const CMATERIAL *aMaterial)
Definition: cobject.h:62
int GetCopperThicknessBIU() const
GetCopperThicknessBIU - Get the current copper layer thickness.
CINFO3D_VISU & m_settings
settings refrence in use for this render
PCB_LAYER_ID
A quick note on layer IDs:
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
VIATYPE_T GetViaType() const
Definition: class_track.h:461
float GetLayerBottomZpos3DU(PCB_LAYER_ID aLayerId) const
GetLayerBottomZpos3DU - Get the bottom z position.
Definition: cinfo3d_visu.h:287
const wxPoint & GetStart() const
Definition: class_track.h:126
CCONTAINER2D m_containerWithObjectsToDelete
This will store the list of created objects special for RT, that will be clear in the end...
void SetColor(SFVEC3F aObjColor)
Definition: clayeritem.h:46
void Add(COBJECT *aObject)
Definition: ccontainer.h:52
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Function LayerPair Return the 2 layers used by the via (the via actually uses all layers between thes...
void Add(COBJECT2D *aObject)
Definition: ccontainer2d.h:52
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
double BiuTo3Dunits() const
BiuTo3Dunits - Board integer units To 3D units.
Definition: cinfo3d_visu.h:141
bool C3D_RENDER_BASE::IsReloadRequestPending ( ) const
inlineinherited

IsReloadRequestPending - Query if there is a pending reload request.

Returns
true if it wants to reload, false if there is no reload pending

Definition at line 79 of file c3d_render_base.h.

References C3D_RENDER_BASE::GetWaitForEditingTimeOut(), and C3D_RENDER_BASE::m_reloadRequested.

Referenced by EDA_3D_CANVAS::IsReloadRequestPending().

79 { return m_reloadRequested; }
bool m_reloadRequested
!TODO: this must be reviewed in order to flag change types
void C3D_RENDER_RAYTRACING::load_3D_models ( )
private

Definition at line 1199 of file c3d_render_createscene.cpp.

References add_3D_models(), CINFO3D_VISU::BiuTo3Dunits(), CINFO3D_VISU::Get3DCacheManager(), CINFO3D_VISU::GetBoard(), S3D_CACHE::GetModel(), CINFO3D_VISU::GetModulesZcoord3DIU(), BOARD::m_Modules, C3D_RENDER_BASE::m_settings, MODULE::Next(), scale, CINFO3D_VISU::ShouldModuleBeDisplayed(), and UNITS3D_TO_UNITSPCB.

Referenced by reload().

1200 {
1201  // Go for all modules
1202  for( const MODULE* module = m_settings.GetBoard()->m_Modules;
1203  module;
1204  module = module->Next() )
1205  {
1206  if( (!module->Models().empty() ) &&
1207  m_settings.ShouldModuleBeDisplayed( (MODULE_ATTR_T)module->GetAttributes() ) )
1208  {
1209  double zpos = m_settings.GetModulesZcoord3DIU( module->IsFlipped() );
1210 
1211  wxPoint pos = module->GetPosition();
1212 
1213  glm::mat4 moduleMatrix = glm::mat4( 1.0f );
1214 
1215  moduleMatrix = glm::translate( moduleMatrix,
1216  SFVEC3F( pos.x * m_settings.BiuTo3Dunits(),
1217  -pos.y * m_settings.BiuTo3Dunits(),
1218  zpos ) );
1219 
1220  if( module->GetOrientation() )
1221  {
1222  moduleMatrix = glm::rotate( moduleMatrix,
1223  ( (float)(module->GetOrientation() / 10.0f) / 180.0f ) *
1224  glm::pi<float>(),
1225  SFVEC3F( 0.0f, 0.0f, 1.0f ) );
1226  }
1227 
1228 
1229  if( module->IsFlipped() )
1230  {
1231  moduleMatrix = glm::rotate( moduleMatrix,
1232  glm::pi<float>(),
1233  SFVEC3F( 0.0f, 1.0f, 0.0f ) );
1234 
1235  moduleMatrix = glm::rotate( moduleMatrix,
1236  glm::pi<float>(),
1237  SFVEC3F( 0.0f, 0.0f, 1.0f ) );
1238  }
1239 
1240  const double modelunit_to_3d_units_factor = m_settings.BiuTo3Dunits() *
1242 
1243  moduleMatrix = glm::scale( moduleMatrix,
1244  SFVEC3F( modelunit_to_3d_units_factor,
1245  modelunit_to_3d_units_factor,
1246  modelunit_to_3d_units_factor ) );
1247 
1248 
1249  // Get the list of model files for this model
1250  auto sM = module->Models().begin();
1251  auto eM = module->Models().end();
1252 
1253  while( sM != eM )
1254  {
1255  // get it from cache
1256  const S3DMODEL *modelPtr =
1257  m_settings.Get3DCacheManager()->GetModel( sM->m_Filename );
1258 
1259  // only add it if the return is not NULL
1260  if( modelPtr )
1261  {
1262  glm::mat4 modelMatrix = moduleMatrix;
1263 
1264  modelMatrix = glm::translate( modelMatrix,
1265  SFVEC3F( sM->m_Offset.x,
1266  sM->m_Offset.y,
1267  sM->m_Offset.z ) );
1268 
1269  modelMatrix = glm::rotate( modelMatrix,
1270  (float)-( sM->m_Rotation.z / 180.0f ) *
1271  glm::pi<float>(),
1272  SFVEC3F( 0.0f, 0.0f, 1.0f ) );
1273 
1274  modelMatrix = glm::rotate( modelMatrix,
1275  (float)-( sM->m_Rotation.y / 180.0f ) *
1276  glm::pi<float>(),
1277  SFVEC3F( 0.0f, 1.0f, 0.0f ) );
1278 
1279  modelMatrix = glm::rotate( modelMatrix,
1280  (float)-( sM->m_Rotation.x / 180.0f ) *
1281  glm::pi<float>(),
1282  SFVEC3F( 1.0f, 0.0f, 0.0f ) );
1283 
1284  modelMatrix = glm::scale( modelMatrix,
1285  SFVEC3F( sM->m_Scale.x,
1286  sM->m_Scale.y,
1287  sM->m_Scale.z ) );
1288 
1289  add_3D_models( modelPtr, modelMatrix );
1290  }
1291 
1292  ++sM;
1293  }
1294  }
1295  }
1296 }
S3D_CACHE * Get3DCacheManager() const
Get3DCacheManager - Return the 3d cache manager pointer.
Definition: cinfo3d_visu.h:88
MODULE * Next() const
Definition: class_module.h:122
CINFO3D_VISU & m_settings
settings refrence in use for this render
#define UNITS3D_TO_UNITSPCB
Scale convertion from 3d model units to pcb units.
S3DMODEL * GetModel(const wxString &aModelFileName)
Function GetModel attempts to load the scene data for a model and to translate it into an S3D_MODEL s...
Definition: 3d_cache.cpp:725
MODULE_ATTR_T
Enum MODULE_ATTR_T is the set of attributes allowed within a MODULE, using MODULE::SetAttributes() an...
Definition: class_module.h:73
void add_3D_models(const S3DMODEL *a3DModel, const glm::mat4 &aModelMatrix)
float GetModulesZcoord3DIU(bool aIsFlipped) const
GetModulesZcoord3DIU - Get the position of the module in 3d integer units considering if it is flippe...
const int scale
bool ShouldModuleBeDisplayed(MODULE_ATTR_T aModuleAttributs) const
ShouldModuleBeDisplayed - Test if module should be displayed in relation to attributs and the flags...
DLIST< MODULE > m_Modules
Definition: class_board.h:249
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90
const BOARD * GetBoard() const
GetBoard - Get current board to be rendered.
Definition: cinfo3d_visu.h:128
double BiuTo3Dunits() const
BiuTo3Dunits - Board integer units To 3D units.
Definition: cinfo3d_visu.h:141
void C3D_RENDER_RAYTRACING::opengl_delete_pbo ( )
private

Definition at line 100 of file c3d_render_raytracing.cpp.

References m_opengl_support_vertex_buffer_object, and m_pboId.

Referenced by opengl_init_pbo(), and ~C3D_RENDER_RAYTRACING().

101 {
102  // Delete PBO if it was created
104  {
105  if( glIsBufferARB( m_pboId ) )
106  glDeleteBuffers( 1, &m_pboId );
107 
108  m_pboId = GL_NONE;
109  }
110 }
void C3D_RENDER_RAYTRACING::opengl_init_pbo ( )
private

Definition at line 2040 of file c3d_render_raytracing.cpp.

References C3D_RENDER_BASE::m_logTrace, m_opengl_support_vertex_buffer_object, m_pboDataSize, m_pboId, m_realBufferSize, and opengl_delete_pbo().

Referenced by initialize_block_positions(), and initializeNewWindowSize().

2041 {
2042  if( GLEW_ARB_pixel_buffer_object )
2043  {
2045 
2046  // Try to delete vbo if it was already initialized
2048 
2049  // Learn about Pixel buffer objects at:
2050  // http://www.songho.ca/opengl/gl_pbo.html
2051  // http://web.eecs.umich.edu/~sugih/courses/eecs487/lectures/25-PBO+Mipmapping.pdf
2052  // "create 2 pixel buffer objects, you need to delete them when program exits.
2053  // glBufferDataARB with NULL pointer reserves only memory space."
2054 
2055  // This sets the number of RGBA pixels
2057 
2058  glGenBuffersARB( 1, &m_pboId );
2059  glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, m_pboId );
2060  glBufferDataARB( GL_PIXEL_UNPACK_BUFFER_ARB, m_pboDataSize, 0, GL_STREAM_DRAW_ARB );
2061  glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, 0 );
2062 
2063  wxLogTrace( m_logTrace,
2064  wxT( "C3D_RENDER_RAYTRACING:: GLEW_ARB_pixel_buffer_object is supported" ) );
2065  }
2066 }
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
bool C3D_RENDER_RAYTRACING::Redraw ( bool  aIsMoving,
REPORTER aStatusTextReporter 
)
overridevirtual

Redraw - Ask to redraw the view.

Parameters
aIsMovingif the user is moving the scene, it should be render in preview mode
aStatusTextReportera pointer to the status progress reporter
Returns
it will return true if the render would like to redraw again

Implements C3D_RENDER_BASE.

Definition at line 149 of file c3d_render_raytracing.cpp.

References CINFO3D_VISU::CameraGet(), dummy(), CCAMERA::GetDir(), initialize_block_positions(), initializeOpenGL(), CINFO3D_VISU::m_BgColorBot, CINFO3D_VISU::m_BgColorTop, m_camera_light, C3D_RENDER_BASE::m_is_opengl_initialized, m_oldWindowsSize, m_pboId, m_realBufferSize, C3D_RENDER_BASE::m_reloadRequested, m_rt_render_state, C3D_RENDER_BASE::m_settings, C3D_RENDER_BASE::m_windowSize, m_xoffset, m_yoffset, OGL_DrawBackground(), CCAMERA::ParametersChanged(), reload(), render(), render_preview(), REPORTER::Report(), RT_RENDER_STATE_FINISH, RT_RENDER_STATE_MAX, and CDIRECTIONALLIGHT::SetDirection().

150 {
151  bool requestRedraw = false;
152 
153  // Initialize openGL if need
154  // /////////////////////////////////////////////////////////////////////////
156  {
157  if( !initializeOpenGL() )
158  return false;
159 
160  //aIsMoving = true;
161  requestRedraw = true;
162 
163  // It will assign the first time the windows size, so it will now
164  // revert to preview mode the first time the Redraw is called
167  }
168 
169  wxBusyCursor dummy;
170 
171  // Reload board if it was requested
172  // /////////////////////////////////////////////////////////////////////////
173  if( m_reloadRequested )
174  {
175  if( aStatusTextReporter )
176  aStatusTextReporter->Report( _( "Loading..." ) );
177 
178  //aIsMoving = true;
179  requestRedraw = true;
180  reload( aStatusTextReporter );
181  }
182 
183 
184  // Recalculate constants if windows size was changed
185  // /////////////////////////////////////////////////////////////////////////
187  {
189  aIsMoving = true;
190  requestRedraw = true;
191 
193  }
194 
195 
196  // Clear buffers
197  // /////////////////////////////////////////////////////////////////////////
198  glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
199  glClearDepth( 1.0f );
200  glClearStencil( 0x00 );
201  glClear( GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
202 
203  // 4-byte pixel alignment
204  glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
205 
206  glDisable( GL_STENCIL_TEST );
207  glDisable( GL_LIGHTING );
208  glDisable( GL_COLOR_MATERIAL );
209  glDisable( GL_DEPTH_TEST );
210  glDisable( GL_TEXTURE_2D );
211  glDisable( GL_BLEND );
212 
213 
214  const bool was_camera_changed = m_settings.CameraGet().ParametersChanged();
215 
216  if( requestRedraw || aIsMoving || was_camera_changed )
217  m_rt_render_state = RT_RENDER_STATE_MAX; // Set to an invalid state,
218  // so it will restart again latter
219 
220 
221  // This will only render if need, otherwise it will redraw the PBO on the screen again
222  if( aIsMoving || was_camera_changed )
223  {
224  // Set head light (camera view light) with the oposite direction of the camera
225  if( m_camera_light )
227 
230 
231  // Bind PBO
232  glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, m_pboId );
233 
234  // Get the PBO pixel pointer to write the data
235  GLubyte *ptrPBO = (GLubyte *)glMapBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB,
236  GL_WRITE_ONLY_ARB );
237 
238  if( ptrPBO )
239  {
240  render_preview( ptrPBO );
241 
242  // release pointer to mapping buffer, this initialize the coping to PBO
243  glUnmapBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB );
244  }
245 
246  glWindowPos2i( m_xoffset, m_yoffset );
247  }
248  else
249  {
250  // Bind PBO
251  glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, m_pboId );
252 
254  {
255  // Get the PBO pixel pointer to write the data
256  GLubyte *ptrPBO = (GLubyte *)glMapBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB,
257  GL_WRITE_ONLY_ARB );
258 
259  if( ptrPBO )
260  {
261  render( ptrPBO, aStatusTextReporter );
262 
264  requestRedraw = true;
265 
266  // release pointer to mapping buffer, this initialize the coping to PBO
267  glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB);
268  }
269  }
270 
272  {
273  glClear( GL_COLOR_BUFFER_BIT );
274  // Options if we want draw background instead
275  //OGL_DrawBackground( SFVEC3F(m_settings.m_BgColorTop),
276  // SFVEC3F(m_settings.m_BgColorBot) );
277  }
278 
279  glWindowPos2i( m_xoffset, m_yoffset );
280  }
281 
282  // This way it will blend the progress rendering with the last buffer. eg:
283  // if it was called after a openGL.
284  glEnable( GL_BLEND );
285  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
286  glEnable( GL_ALPHA_TEST );
287 
288  glDrawPixels( m_realBufferSize.x,
290  GL_RGBA,
291  GL_UNSIGNED_BYTE,
292  0 );
293 
294  glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, 0 );
295 
296  return requestRedraw;
297 }
wxSize m_oldWindowsSize
used to see if the windows size changed
SFVEC3D m_BgColorBot
background bottom color
Definition: cinfo3d_visu.h:503
const SFVEC3F & GetDir() const
Definition: ccamera.h:109
CINFO3D_VISU & m_settings
settings refrence in use for this render
SFVEC3D m_BgColorTop
background top color
Definition: cinfo3d_visu.h:504
void OGL_DrawBackground(const SFVEC3F &aTopColor, const SFVEC3F &aBotColor)
OGL_DrawBackground.
Definition: ogl_utils.cpp:179
bool m_is_opengl_initialized
flag if the opengl specific for this render was already initialized
RT_RENDER_STATE m_rt_render_state
State used on quality render.
wxSize m_windowSize
The window size that this camera is working.
CDIRECTIONALLIGHT * m_camera_light
void SetDirection(const SFVEC3F &aDir)
SetDirection - Set directional light orientation.
Definition: clight.h:129
bool m_reloadRequested
!TODO: this must be reviewed in order to flag change types
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
void render_preview(GLubyte *ptrPBO)
void render(GLubyte *ptrPBO, REPORTER *aStatusTextReporter)
bool ParametersChanged()
Function ParametersChanged.
Definition: ccamera.cpp:567
void reload(REPORTER *aStatusTextReporter)
void C3D_RENDER_RAYTRACING::reload ( REPORTER aStatusTextReporter)
private

Definition at line 249 of file c3d_render_createscene.cpp.

References CGENERICCONTAINER::Add(), CGENERICCONTAINER2D::Add(), CLIGHTCONTAINER::Add(), add_3D_vias_and_pads_to_container(), B_Adhes, B_CrtYd, B_Cu, B_Fab, B_Mask, B_Paste, B_SilkS, CINFO3D_VISU::BiuTo3Dunits(), CINFO3D_VISU::CameraGet(), CGENERICCONTAINER::Clear(), CGENERICCONTAINER2D::Clear(), CLIGHTCONTAINER::Clear(), Cmts_User, Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(), ConvertSRGBToLinear(), create_3d_object_from(), CSGITEM_EMPTY, CSGITEM_FULL, Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_CrtYd, F_Cu, F_Fab, F_Mask, F_Paste, F_SilkS, FL_RENDER_RAYTRACING_BACKFLOOR, FL_SHOW_BOARD_BODY, FL_SOLDERMASK, FL_USE_REALISTIC_MODE, Format(), SHAPE_POLY_SET::Fracture(), CGENERICCONTAINER::GetBBox(), COBJECT2D::GetBBox(), CINFO3D_VISU::GetBBox3DU(), CINFO3D_VISU::GetBoard(), CINFO3D_VISU::GetBoardCenter3DU(), COBJECT2D::GetBoardItem(), CINFO3D_VISU::GetBoardPoly(), CBBOX::GetCenter(), COBJECT2D::GetCentroid(), CBBOX2D::GetExtent(), CINFO3D_VISU::GetFlag(), CINFO3D_VISU::GetLayerBottomZpos3DU(), CINFO3D_VISU::GetLayerColor(), CINFO3D_VISU::GetLayerTopZpos3DU(), CGENERICCONTAINER::GetList(), CGENERICCONTAINER2D::GetList(), CBVHCONTAINER2D::GetListObjectsIntersects(), CINFO3D_VISU::GetMapLayers(), CINFO3D_VISU::GetMapLayersHoles(), COBJECT2D::GetObjectType(), GetRunningMicroSecs(), CINFO3D_VISU::GetStats_Med_Hole_Diameter3DU(), CINFO3D_VISU::GetStats_Med_Via_Hole_Diameter3DU(), CINFO3D_VISU::GetStats_Nr_Holes(), CINFO3D_VISU::GetStats_Nr_Vias(), CINFO3D_VISU::GetThroughHole_Outer(), CINFO3D_VISU::InitSettings(), COBJECT3D_STATS::Instance(), COBJECT2D_STATS::Instance(), COBJECT2D::Intersects(), CBBOX::IsInitialized(), load_3D_models(), m_accelerator, CINFO3D_VISU::m_BgColorTop, CINFO3D_VISU::m_BoardBodyColor, m_camera_light, m_containerWithObjectsToDelete, CINFO3D_VISU::m_CopperColor, m_lights, m_materials, m_model_materials, m_object_container, m_outlineBoard2dObjects, C3D_RENDER_BASE::m_reloadRequested, C3D_RENDER_BASE::m_settings, CINFO3D_VISU::m_SilkScreenColor, CINFO3D_VISU::m_SolderMaskColor, CINFO3D_VISU::m_SolderPasteColor, m_stats_converted_dummy_to_plane, m_stats_converted_roundsegment2d_to_roundsegment, Margin, min, CBBOX::Min(), NextFloatDown(), NextFloatUp(), OBJ2D_FILLED_CIRCLE, SHAPE_POLY_SET::PM_FAST, COBJECT3D_STATS::PrintStats(), COBJECT2D_STATS::PrintStats(), RANGE_SCALE_3D, REPORTER::Report(), COBJECT3D_STATS::ResetStats(), COBJECT2D_STATS::ResetStats(), CBBOX::Scale(), CCAMERA::SetBoardLookAtPos(), CLIGHT::SetCastShadows(), CLAYERITEM::SetColor(), CVCYLINDER::SetColor(), CTRIANGLE::SetColor(), COBJECT::SetMaterial(), setupMaterials(), and SphericalToCartesian().

Referenced by Redraw().

250 {
251  m_reloadRequested = false;
252 
253  m_model_materials.clear();
254 
257 
258 #ifdef PRINT_STATISTICS_3D_VIEWER
259  printf("InitSettings...\n");
260 #endif
261 
262  unsigned stats_startReloadTime = GetRunningMicroSecs();
263 
264  m_settings.InitSettings( aStatusTextReporter );
265 
266 #ifdef PRINT_STATISTICS_3D_VIEWER
267  unsigned stats_endReloadTime = GetRunningMicroSecs();
268  unsigned stats_startConvertTime = GetRunningMicroSecs();
269  #endif
270 
271  SFVEC3F camera_pos = m_settings.GetBoardCenter3DU();
272  m_settings.CameraGet().SetBoardLookAtPos( camera_pos );
273 
276 
277 
278  // Create and add the outline board
279  // /////////////////////////////////////////////////////////////////////////
280 
281 #ifdef PRINT_STATISTICS_3D_VIEWER
282  printf("Create outline board...\n");
283 #endif
284 
286 
288 
289  if( ((const SHAPE_POLY_SET &)m_settings.GetBoardPoly()).OutlineCount() == 1 )
290  {
291  float divFactor = 0.0f;
292 
294  divFactor = m_settings.GetStats_Med_Via_Hole_Diameter3DU() * 18.0f;
295  else
297  divFactor = m_settings.GetStats_Med_Hole_Diameter3DU() * 8.0f;
298 
299  SHAPE_POLY_SET boardPolyCopy = m_settings.GetBoardPoly();
300  boardPolyCopy.Fracture( SHAPE_POLY_SET::PM_FAST );
301 
303  boardPolyCopy,
306  divFactor,
307  (const BOARD_ITEM &)*m_settings.GetBoard() );
308 
310  {
311  const LIST_OBJECT2D &listObjects = m_outlineBoard2dObjects->GetList();
312 
313  for( LIST_OBJECT2D::const_iterator object2d_iterator = listObjects.begin();
314  object2d_iterator != listObjects.end();
315  ++object2d_iterator )
316  {
317  const COBJECT2D *object2d_A = static_cast<const COBJECT2D *>(*object2d_iterator);
318 
319  std::vector<const COBJECT2D *> *object2d_B = new std::vector<const COBJECT2D *>();
320 
321  // Check if there are any THT that intersects this outline object part
322  if( !m_settings.GetThroughHole_Outer().GetList().empty() )
323  {
324 
325  CONST_LIST_OBJECT2D intersectionList;
327  object2d_A->GetBBox(),
328  intersectionList );
329 
330  if( !intersectionList.empty() )
331  {
332  for( CONST_LIST_OBJECT2D::const_iterator hole = intersectionList.begin();
333  hole != intersectionList.end();
334  ++hole )
335  {
336  const COBJECT2D *hole2d = static_cast<const COBJECT2D *>(*hole);
337 
338  if( object2d_A->Intersects( hole2d->GetBBox() ) )
339  //if( object2d_A->GetBBox().Intersects( hole2d->GetBBox() ) )
340  object2d_B->push_back( hole2d );
341  }
342  }
343  }
344 
345  if( object2d_B->empty() )
346  {
347  delete object2d_B;
348  object2d_B = CSGITEM_EMPTY;
349  }
350 
351  if( object2d_B == CSGITEM_EMPTY )
352  {
353  #if 0
357  &m_materials.m_EpoxyBoard,
358  g_epoxyColor );
359  #else
360  CLAYERITEM *objPtr = new CLAYERITEM( object2d_A,
363 
364  objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
365  objPtr->SetColor( ConvertSRGBToLinear( (SFVEC3F)m_settings.m_BoardBodyColor ) );
366  m_object_container.Add( objPtr );
367  #endif
368  }
369  else
370  {
371  CITEMLAYERCSG2D *itemCSG2d = new CITEMLAYERCSG2D(
372  object2d_A,
373  object2d_B,
374  CSGITEM_FULL,
375  (const BOARD_ITEM &)*m_settings.GetBoard() );
376 
377  m_containerWithObjectsToDelete.Add( itemCSG2d );
378 
379  CLAYERITEM *objPtr = new CLAYERITEM( itemCSG2d,
382 
383  objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
385  m_object_container.Add( objPtr );
386  }
387  }
388 
389  // Add cylinders of the board body to container
390  // Note: This is actually a workarround for the holes in the board.
391  // The issue is because if a hole is in a border of a divided polygon ( ex
392  // a polygon or dummyblock) it will cut also the render of the hole.
393  // So this will add a full hole.
394  // In fact, that is not need if the hole have copper.
395  // /////////////////////////////////////////////////////////////////////////
396  if( !m_settings.GetThroughHole_Outer().GetList().empty() )
397  {
399 
400  for( LIST_OBJECT2D::const_iterator hole = holeList.begin();
401  hole != holeList.end();
402  ++hole )
403  {
404  const COBJECT2D *hole2d = static_cast<const COBJECT2D *>(*hole);
405 
406  switch( hole2d->GetObjectType() )
407  {
408  case OBJ2D_FILLED_CIRCLE:
409  {
410  const float radius = hole2d->GetBBox().GetExtent().x * 0.5f * 0.999f;
411 
412  CVCYLINDER *objPtr = new CVCYLINDER(
413  hole2d->GetCentroid(),
416  radius );
417 
418  objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
420 
421  m_object_container.Add( objPtr );
422  }
423  break;
424 
425  default:
426  break;
427  }
428  }
429  }
430  }
431  }
432 
433 
434  // Add layers maps (except B_Mask and F_Mask)
435  // /////////////////////////////////////////////////////////////////////////
436 
437 #ifdef PRINT_STATISTICS_3D_VIEWER
438  printf("Add layers maps...\n");
439 #endif
440 
441  for( MAP_CONTAINER_2D::const_iterator ii = m_settings.GetMapLayers().begin();
442  ii != m_settings.GetMapLayers().end();
443  ++ii )
444  {
445  PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first);
446 
447  // Mask kayers are not processed here because they are a special case
448  if( (layer_id == B_Mask) || (layer_id == F_Mask) )
449  continue;
450 
451  CMATERIAL *materialLayer = &m_materials.m_SilkS;
452  SFVEC3F layerColor = SFVEC3F( 0.0f, 0.0f, 0.0f );
453 
454  switch( layer_id )
455  {
456  case B_Adhes:
457  case F_Adhes:
458  break;
459 
460  case B_Paste:
461  case F_Paste:
462  materialLayer = &m_materials.m_Paste;
463 
465  layerColor = m_settings.m_SolderPasteColor;
466  else
467  layerColor = m_settings.GetLayerColor( layer_id );
468  break;
469 
470  case B_SilkS:
471  case F_SilkS:
472  materialLayer = &m_materials.m_SilkS;
473 
475  layerColor = m_settings.m_SilkScreenColor;
476  else
477  layerColor = m_settings.GetLayerColor( layer_id );
478  break;
479 
480  case Dwgs_User:
481  case Cmts_User:
482  case Eco1_User:
483  case Eco2_User:
484  case Edge_Cuts:
485  case Margin:
486  break;
487 
488  case B_CrtYd:
489  case F_CrtYd:
490  break;
491 
492  case B_Fab:
493  case F_Fab:
494  break;
495 
496  default:
497  materialLayer = &m_materials.m_Copper;
498 
500  layerColor = m_settings.m_CopperColor;
501  else
502  layerColor = m_settings.GetLayerColor( layer_id );
503  break;
504  }
505 
506  const CBVHCONTAINER2D *container2d = static_cast<const CBVHCONTAINER2D *>(ii->second);
507  const LIST_OBJECT2D &listObject2d = container2d->GetList();
508 
509  for( LIST_OBJECT2D::const_iterator itemOnLayer = listObject2d.begin();
510  itemOnLayer != listObject2d.end();
511  ++itemOnLayer )
512  {
513  const COBJECT2D *object2d_A = static_cast<const COBJECT2D *>(*itemOnLayer);
514 
515  // not yet used / implemented (can be used in future to clip the objects in the board borders
516  COBJECT2D *object2d_C = CSGITEM_FULL;
517 
518  std::vector<const COBJECT2D *> *object2d_B = CSGITEM_EMPTY;
519 
520  if( true ) // previously, was a option, now holes are always drawn in zones
521  {
522  object2d_B = new std::vector<const COBJECT2D *>();
523 
524  // Check if there are any layerhole that intersects this object
525  // Eg: a segment is cutted by a via hole or THT hole.
526  // /////////////////////////////////////////////////////////////
527  const MAP_CONTAINER_2D &layerHolesMap = m_settings.GetMapLayersHoles();
528 
529  if( layerHolesMap.find(layer_id) != layerHolesMap.end() )
530  {
531  MAP_CONTAINER_2D::const_iterator ii_hole = layerHolesMap.find(layer_id);
532 
533  const CBVHCONTAINER2D *containerLayerHoles2d =
534  static_cast<const CBVHCONTAINER2D *>(ii_hole->second);
535 
536 
537  CONST_LIST_OBJECT2D intersectionList;
538  containerLayerHoles2d->GetListObjectsIntersects( object2d_A->GetBBox(),
539  intersectionList );
540 
541  if( !intersectionList.empty() )
542  {
543  for( CONST_LIST_OBJECT2D::const_iterator holeOnLayer =
544  intersectionList.begin();
545  holeOnLayer != intersectionList.end();
546  ++holeOnLayer )
547  {
548  const COBJECT2D *hole2d = static_cast<const COBJECT2D *>(*holeOnLayer);
549 
550  //if( object2d_A->Intersects( hole2d->GetBBox() ) )
551  //if( object2d_A->GetBBox().Intersects( hole2d->GetBBox() ) )
552  object2d_B->push_back( hole2d );
553  }
554  }
555  }
556 
557  // Check if there are any THT that intersects this object
558  // /////////////////////////////////////////////////////////////
559  if( !m_settings.GetThroughHole_Outer().GetList().empty() )
560  {
561  CONST_LIST_OBJECT2D intersectionList;
562 
564  object2d_A->GetBBox(),
565  intersectionList );
566 
567  if( !intersectionList.empty() )
568  {
569  for( CONST_LIST_OBJECT2D::const_iterator hole = intersectionList.begin();
570  hole != intersectionList.end();
571  ++hole )
572  {
573  const COBJECT2D *hole2d = static_cast<const COBJECT2D *>(*hole);
574 
575  //if( object2d_A->Intersects( hole2d->GetBBox() ) )
576  //if( object2d_A->GetBBox().Intersects( hole2d->GetBBox() ) )
577  object2d_B->push_back( hole2d );
578  }
579  }
580  }
581 
582  if( object2d_B->empty() )
583  {
584  delete object2d_B;
585  object2d_B = CSGITEM_EMPTY;
586  }
587  }
588 
589  if( (object2d_B == CSGITEM_EMPTY) &&
590  (object2d_C == CSGITEM_FULL) )
591  {
592 #if 0
594  object2d_A,
595  m_settings.GetLayerBottomZpos3DU( layer_id ),
596  m_settings.GetLayerTopZpos3DU( layer_id ),
597  materialLayer,
598  layerColor );
599 #else
600  CLAYERITEM *objPtr = new CLAYERITEM( object2d_A,
601  m_settings.GetLayerBottomZpos3DU( layer_id ),
602  m_settings.GetLayerTopZpos3DU( layer_id ) );
603  objPtr->SetMaterial( materialLayer );
604  objPtr->SetColor( ConvertSRGBToLinear( layerColor ) );
605  m_object_container.Add( objPtr );
606 #endif
607  }
608  else
609  {
610 #if 1
611  CITEMLAYERCSG2D *itemCSG2d = new CITEMLAYERCSG2D( object2d_A,
612  object2d_B,
613  object2d_C,
614  object2d_A->GetBoardItem() );
615  m_containerWithObjectsToDelete.Add( itemCSG2d );
616 
617  CLAYERITEM *objPtr = new CLAYERITEM( itemCSG2d,
618  m_settings.GetLayerBottomZpos3DU( layer_id ),
619  m_settings.GetLayerTopZpos3DU( layer_id ) );
620 
621  objPtr->SetMaterial( materialLayer );
622  objPtr->SetColor( ConvertSRGBToLinear( layerColor ) );
623 
624  m_object_container.Add( objPtr );
625 #endif
626  }
627  }
628  }// for each layer on map
629 
630 
631 
632  // Add Mask layer
633  // Solder mask layers are "negative" layers so the elements that we have
634  // (in the container) should remove the board outline.
635  // We will check for all objects in the outline if it intersects any object
636  // in the layer container and also any hole.
637  // /////////////////////////////////////////////////////////////////////////
639  (m_outlineBoard2dObjects->GetList().size() >= 1) )
640  {
641  CMATERIAL *materialLayer = &m_materials.m_SolderMask;
642 
643  for( MAP_CONTAINER_2D::const_iterator ii = m_settings.GetMapLayers().begin();
644  ii != m_settings.GetMapLayers().end();
645  ++ii )
646  {
647  PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first);
648 
649  const CBVHCONTAINER2D *containerLayer2d =
650  static_cast<const CBVHCONTAINER2D *>(ii->second);
651 
652  // Only get the Solder mask layers
653  if( !((layer_id == B_Mask) || (layer_id == F_Mask)) )
654  continue;
655 
656  SFVEC3F layerColor;
658  layerColor = m_settings.m_SolderMaskColor;
659  else
660  layerColor = m_settings.GetLayerColor( layer_id );
661 
662  const float zLayerMin = m_settings.GetLayerBottomZpos3DU( layer_id );
663  const float zLayerMax = m_settings.GetLayerTopZpos3DU( layer_id );
664 
665  // Get the outline board objects
666  const LIST_OBJECT2D &listObjects = m_outlineBoard2dObjects->GetList();
667 
668  for( LIST_OBJECT2D::const_iterator object2d_iterator = listObjects.begin();
669  object2d_iterator != listObjects.end();
670  ++object2d_iterator )
671  {
672  const COBJECT2D *object2d_A = static_cast<const COBJECT2D *>(*object2d_iterator);
673 
674  std::vector<const COBJECT2D *> *object2d_B = new std::vector<const COBJECT2D *>();
675 
676  // Check if there are any THT that intersects this outline object part
677  if( !m_settings.GetThroughHole_Outer().GetList().empty() )
678  {
679 
680  CONST_LIST_OBJECT2D intersectionList;
681 
683  object2d_A->GetBBox(),
684  intersectionList );
685 
686  if( !intersectionList.empty() )
687  {
688  for( CONST_LIST_OBJECT2D::const_iterator hole = intersectionList.begin();
689  hole != intersectionList.end();
690  ++hole )
691  {
692  const COBJECT2D *hole2d = static_cast<const COBJECT2D *>(*hole);
693 
694  if( object2d_A->Intersects( hole2d->GetBBox() ) )
695  //if( object2d_A->GetBBox().Intersects( hole2d->GetBBox() ) )
696  object2d_B->push_back( hole2d );
697  }
698  }
699  }
700 
701  // Check if there are any objects in the layer to subtract with the
702  // corrent object
703  if( !containerLayer2d->GetList().empty() )
704  {
705  CONST_LIST_OBJECT2D intersectionList;
706 
707  containerLayer2d->GetListObjectsIntersects( object2d_A->GetBBox(),
708  intersectionList );
709 
710  if( !intersectionList.empty() )
711  {
712  for( CONST_LIST_OBJECT2D::const_iterator obj = intersectionList.begin();
713  obj != intersectionList.end();
714  ++obj )
715  {
716  const COBJECT2D *obj2d = static_cast<const COBJECT2D *>(*obj);
717 
718  //if( object2d_A->Intersects( obj2d->GetBBox() ) )
719  //if( object2d_A->GetBBox().Intersects( obj2d->GetBBox() ) )
720  object2d_B->push_back( obj2d );
721  }
722  }
723  }
724 
725  if( object2d_B->empty() )
726  {
727  delete object2d_B;
728  object2d_B = CSGITEM_EMPTY;
729  }
730 
731  if( object2d_B == CSGITEM_EMPTY )
732  {
733  #if 0
735  object2d_A,
736  zLayerMin,
737  zLayerMax,
738  materialLayer,
739  layerColor );
740  #else
741  CLAYERITEM *objPtr = new CLAYERITEM( object2d_A,
742  zLayerMin,
743  zLayerMax );
744 
745  objPtr->SetMaterial( materialLayer );
746  objPtr->SetColor( ConvertSRGBToLinear( layerColor ) );
747 
748  m_object_container.Add( objPtr );
749  #endif
750  }
751  else
752  {
753  CITEMLAYERCSG2D *itemCSG2d = new CITEMLAYERCSG2D( object2d_A,
754  object2d_B,
755  CSGITEM_FULL,
756  object2d_A->GetBoardItem() );
757 
758  m_containerWithObjectsToDelete.Add( itemCSG2d );
759 
760  CLAYERITEM *objPtr = new CLAYERITEM( itemCSG2d,
761  zLayerMin,
762  zLayerMax );
763  objPtr->SetMaterial( materialLayer );
764  objPtr->SetColor( ConvertSRGBToLinear( layerColor ) );
765 
766  m_object_container.Add( objPtr );
767  }
768  }
769  }
770  }
771 
773 
774 #ifdef PRINT_STATISTICS_3D_VIEWER
775  unsigned stats_endConvertTime = GetRunningMicroSecs();
776  unsigned stats_startLoad3DmodelsTime = stats_endConvertTime;
777 #endif
778 
779 
780  load_3D_models();
781 
782 
783 #ifdef PRINT_STATISTICS_3D_VIEWER
784  unsigned stats_endLoad3DmodelsTime = GetRunningMicroSecs();
785 #endif
786 
787  // Add floor
788  // /////////////////////////////////////////////////////////////////////////
790  {
791  CBBOX boardBBox = m_settings.GetBBox3DU();
792 
793  if( boardBBox.IsInitialized() )
794  {
795  boardBBox.Scale( 3.0f );
796 
797  if( m_object_container.GetList().size() > 0 )
798  {
799  CBBOX containerBBox = m_object_container.GetBBox();
800 
801  containerBBox.Scale( 1.3f );
802 
803  const SFVEC3F centerBBox = containerBBox.GetCenter();
804 
805  const float minZ = glm::min( containerBBox.Min().z,
806  boardBBox.Min().z );
807 
808  const SFVEC3F v1 = SFVEC3F( -RANGE_SCALE_3D * 4.0f,
809  -RANGE_SCALE_3D * 4.0f,
810  minZ ) +
811  SFVEC3F( centerBBox.x,
812  centerBBox.y,
813  0.0f );
814 
815  const SFVEC3F v3 = SFVEC3F( +RANGE_SCALE_3D * 4.0f,
816  +RANGE_SCALE_3D * 4.0f,
817  minZ ) +
818  SFVEC3F( centerBBox.x,
819  centerBBox.y,
820  0.0f );
821 
822  const SFVEC3F v2 = SFVEC3F( v1.x, v3.y, v1.z );
823  const SFVEC3F v4 = SFVEC3F( v3.x, v1.y, v1.z );
824 
825  CTRIANGLE *newTriangle1 = new CTRIANGLE( v1, v2, v3 );
826  CTRIANGLE *newTriangle2 = new CTRIANGLE( v3, v4, v1 );
827 
828  m_object_container.Add( newTriangle1 );
829  m_object_container.Add( newTriangle2 );
830 
831  newTriangle1->SetMaterial( (const CMATERIAL *)&m_materials.m_Floor );
832  newTriangle2->SetMaterial( (const CMATERIAL *)&m_materials.m_Floor );
833 
836  }
837  }
838  }
839 
840 
841  // Init initial lights
842  // /////////////////////////////////////////////////////////////////////////
843  m_lights.Clear();
844 
845  // This will work as the front camera light.
846  const float light_camera_intensity = 0.20;
847  const float light_top_bottom = 0.25;
848  const float light_directional_intensity = ( 1.0f - ( light_camera_intensity +
849  light_top_bottom * 0.5f ) ) / 4.0f;
850 
851  m_camera_light = new CDIRECTIONALLIGHT( SFVEC3F( 0.0f, 0.0f, 0.0f ),
852  SFVEC3F( light_camera_intensity ) );
853  m_camera_light->SetCastShadows( false );
855 
856  // Option 1 - using Point Lights
857 
858  const SFVEC3F &boarCenter = m_settings.GetBBox3DU().GetCenter();
859 
860  m_lights.Add( new CPOINTLIGHT( SFVEC3F( boarCenter.x, boarCenter.y, +RANGE_SCALE_3D * 2.0f ),
861  SFVEC3F( light_top_bottom ) ) );
862 
863  m_lights.Add( new CPOINTLIGHT( SFVEC3F( boarCenter.x, boarCenter.y, -RANGE_SCALE_3D * 2.0f ),
864  SFVEC3F( light_top_bottom ) ) );
865 
866 
867  // http://www.flashandmath.com/mathlets/multicalc/coords/shilmay23fin.html
868 
869  // Option 2 - Top/Bottom direction lights
870  /*
871  m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 0.03f,
872  glm::pi<float>() * 0.25f ),
873  SFVEC3F( light_top_bottom ) ) );
874 
875  m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 0.97f,
876  glm::pi<float>() * 1.25f ),
877  SFVEC3F( light_top_bottom ) ) );
878  */
879 
880  m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 1.0f / 8.0f,
881  glm::pi<float>() * 1 / 4.0f ),
882  SFVEC3F( light_directional_intensity ) ) );
883  m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 1.0f / 8.0f,
884  glm::pi<float>() * 3 / 4.0f ),
885  SFVEC3F( light_directional_intensity ) ) );
886  m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 1.0f / 8.0f,
887  glm::pi<float>() * 5 / 4.0f ),
888  SFVEC3F( light_directional_intensity ) ) );
889  m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 1.0f / 8.0f,
890  glm::pi<float>() * 7 / 4.0f ),
891  SFVEC3F( light_directional_intensity ) ) );
892 
893 
894  m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 7.0f / 8.0f,
895  glm::pi<float>() * 1 / 4.0f ),
896  SFVEC3F( light_directional_intensity ) ) );
897  m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 7.0f / 8.0f,
898  glm::pi<float>() * 3 / 4.0f ),
899  SFVEC3F( light_directional_intensity ) ) );
900  m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 7.0f / 8.0f,
901  glm::pi<float>() * 5 / 4.0f ),
902  SFVEC3F( light_directional_intensity ) ) );
903  m_lights.Add( new CDIRECTIONALLIGHT( SphericalToCartesian( glm::pi<float>() * 7.0f / 8.0f,
904  glm::pi<float>() * 7 / 4.0f ),
905  SFVEC3F( light_directional_intensity ) ) );
906 
907 
908  // Create an accelerator
909  // /////////////////////////////////////////////////////////////////////////
910 
911 #ifdef PRINT_STATISTICS_3D_VIEWER
912  unsigned stats_startAcceleratorTime = GetRunningMicroSecs();
913 #endif
914 
915  if( m_accelerator )
916  {
917  delete m_accelerator;
918  }
919  m_accelerator = 0;
920 
922 
923 #ifdef PRINT_STATISTICS_3D_VIEWER
924  unsigned stats_endAcceleratorTime = GetRunningMicroSecs();
925 #endif
926 
927  setupMaterials();
928 
929 #ifdef PRINT_STATISTICS_3D_VIEWER
930  printf( "C3D_RENDER_RAYTRACING::reload times:\n" );
931  printf( " Reload board: %.3f ms\n", (float)( stats_endReloadTime -
932  stats_startReloadTime ) /
933 
934  1000.0f );
935  printf( " Convert to 3D objects: %.3f ms\n", (float)( stats_endConvertTime -
936  stats_startConvertTime ) /
937  1000.0f );
938  printf( " Accelerator construction: %.3f ms\n", (float)( stats_endAcceleratorTime -
939  stats_startAcceleratorTime ) /
940  1000.0f );
941  printf( " Load and add 3D models: %.3f ms\n", (float)( stats_endLoad3DmodelsTime -
942  stats_startLoad3DmodelsTime ) /
943  1000.0f );
944  printf( "Optimizations\n" );
945 
946  printf( " m_stats_converted_dummy_to_plane: %u\n",
948 
949  printf( " m_stats_converted_roundsegment2d_to_roundsegment: %u\n",
951 
954 #endif
955 
956  if( aStatusTextReporter )
957  {
958  // Calculation time in seconds
959  const double calculation_time = (double)( GetRunningMicroSecs() -
960  stats_startReloadTime ) / 1e6;
961 
962  aStatusTextReporter->Report( wxString::Format( _( "Reload time %.3f s" ),
963  calculation_time ) );
964  }
965 }
std::map< PCB_LAYER_ID, CBVHCONTAINER2D * > MAP_CONTAINER_2D
A type that stores a container of 2d objects for each layer id.
Definition: cinfo3d_visu.h:55
void GetListObjectsIntersects(const CBBOX2D &aBBox, CONST_LIST_OBJECT2D &aOutList) const override
GetListObjectsIntersects - Get a list of objects that intersects a bbox.
struct C3D_RENDER_RAYTRACING::@37 m_materials
const LIST_OBJECT2D & GetList() const
Definition: ccontainer2d.h:64
SFVEC3F GetLayerColor(PCB_LAYER_ID aLayerId) const
GetLayerColor - get the technical color of a layer.
SFVEC3F ConvertSRGBToLinear(const SFVEC3F &aSRGBcolor)
Directional light - a light based only on a direction vector.
Definition: clight.h:114
void PrintStats()
Definition: cobject2d.cpp:60
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
A base material class that can be used to derive a material implementation.
Definition: cmaterial.h:167
SFVEC3D m_CopperColor
in realistic mode: copper color
Definition: cinfo3d_visu.h:509
const SHAPE_POLY_SET & GetBoardPoly() const
GetBoardPoly - Get the current polygon of the epoxy board.
Definition: cinfo3d_visu.h:252
void create_3d_object_from(CCONTAINER &aDstContainer, const COBJECT2D *aObject2D, float aZMin, float aZMax, const CMATERIAL *aMaterial, const SFVEC3F &aObjColor)
Function create_3d_object_from.
std::list< const COBJECT2D * > CONST_LIST_OBJECT2D
Definition: ccontainer2d.h:38
const BOARD_ITEM & GetBoardItem() const
Definition: cobject2d.h:75
const SFVEC3F & Min() const
Function Min return the minimun vertex pointer.
Definition: cbbox.h:205
void SetMaterial(const CMATERIAL *aMaterial)
Definition: cobject.h:62
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox.cpp:87
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
Definition: cinfo3d_visu.h:63
float GetStats_Med_Via_Hole_Diameter3DU() const
GetStats_Med_Via_Hole_Diameter3DU - Average diameter of the via holes.
Definition: cinfo3d_visu.h:374
void PrintStats()
Definition: cobject.cpp:57
CINFO3D_VISU & m_settings
settings refrence in use for this render
float GetLayerTopZpos3DU(PCB_LAYER_ID aLayerId) const
GetLayerTopZpos3DU - Get the top z position.
Definition: cinfo3d_visu.h:280
SFVEC3D m_BgColorTop
background top color
Definition: cinfo3d_visu.h:504
SFVEC3D m_BoardBodyColor
in realistic mode: FR4 board color
Definition: cinfo3d_visu.h:505
unsigned int m_stats_converted_dummy_to_plane
#define CSGITEM_EMPTY
This class is used to make constructive solig geometry for items objects on layers.
CGENERICACCELERATOR * m_accelerator
void SetColor(const SFVEC3F &aColor)
Definition: ctriangle.cpp:161
const MAP_CONTAINER_2D & GetMapLayersHoles() const
GetMapLayersHoles -Get the map of container that have the holes per layer.
Definition: cinfo3d_visu.h:299
PCB_LAYER_ID
A quick note on layer IDs:
void SetColor(SFVEC3F aObjColor)
Definition: ccylinder.h:51
const SFVEC3F & GetBoardCenter3DU() const
GetBoardCenter - the board center position in 3d units.
Definition: cinfo3d_visu.h:189
float NextFloatDown(float v)
Definition: 3d_fastmath.h:157
float GetLayerBottomZpos3DU(PCB_LAYER_ID aLayerId) const
GetLayerBottomZpos3DU - Get the bottom z position.
Definition: cinfo3d_visu.h:287
Class SHAPE_POLY_SET.
CCONTAINER2D m_containerWithObjectsToDelete
This will store the list of created objects special for RT, that will be clear in the end...
void Add(CLIGHT *aLight)
Add - Add a light to the container.
Definition: clight.h:186
OBJECT2D_TYPE GetObjectType() const
Definition: cobject2d.h:125
Point light based on: http://ogldev.atspace.co.uk/www/tutorial20/tutorial20.html. ...
Definition: clight.h:67
unsigned int m_stats_converted_roundsegment2d_to_roundsegment
#define CSGITEM_FULL
void SetColor(SFVEC3F aObjColor)
Definition: clayeritem.h:46
SFVEC3D m_SolderPasteColor
in realistic mode: solder paste color
Definition: cinfo3d_visu.h:507
A triangle object.
Definition: ctriangle.h:42
CDIRECTIONALLIGHT * m_camera_light
void Add(COBJECT *aObject)
Definition: ccontainer.h:52
SFVEC3D m_SolderMaskColor
in realistic mode: solder mask color
Definition: cinfo3d_visu.h:506
const CBBOX & GetBBox() const
Definition: ccontainer.h:67
void Fracture(POLYGON_MODE aFastMode)
Converts a set of polygons with holes to a singe outline with "slits"/"fractures" connecting the oute...
static COBJECT2D_STATS & Instance()
Definition: cobject2d.h:146
void Scale(float aScale)
Function Scale scales a bounding box by its center.
Definition: cbbox.cpp:194
A vertical cylinder.
Definition: ccylinder.h:38
SFVEC3F GetCenter() const
Function GetCenter return the center point of the bounding box.
Definition: cbbox.cpp:135
void ResetStats()
Definition: cobject.h:106
void Add(COBJECT2D *aObject)
Definition: ccontainer2d.h:52
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
const SFVEC2F & GetCentroid() const
Definition: cobject2d.h:123
SFVEC3D m_SilkScreenColor
in realistic mode: SilkScreen color
Definition: cinfo3d_visu.h:508
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
bool m_reloadRequested
!TODO: this must be reviewed in order to flag change types
std::list< COBJECT2D * > LIST_OBJECT2D
Definition: ccontainer2d.h:37
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
unsigned GetRunningMicroSecs()
Function GetRunningMicroSecs An alternate way to calculate an elapset time (in microsecondes) to clas...
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
float NextFloatUp(float v)
Definition: 3d_fastmath.h:136
void SetBoardLookAtPos(const SFVEC3F &aBoardPos)
Definition: ccamera.h:115
static COBJECT3D_STATS & Instance()
Definition: cobject.h:116
void SetCastShadows(bool aCastShadow)
Definition: clight.h:57
SFVEC3F SphericalToCartesian(float aInclination, float aAzimuth)
SphericalToCartesian.
Definition: 3d_math.h:43
void ResetStats()
Definition: cobject2d.h:135
unsigned int GetStats_Nr_Vias() const
GetStats_Nr_Vias - Get statistics of the nr of vias.
Definition: cinfo3d_visu.h:362
const CBBOX2D & GetBBox() const
Definition: cobject2d.h:121
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
CCONTAINER2D * m_outlineBoard2dObjects
const CBVHCONTAINER2D & GetThroughHole_Outer() const
GetThroughHole_Outer - Get the inflated ThroughHole container.
Definition: cinfo3d_visu.h:305
float GetStats_Med_Hole_Diameter3DU() const
GetStats_Med_Hole_Diameter3DU - Average diameter of holes.
Definition: cinfo3d_visu.h:380
void Clear()
Clear - Remove all lights from the container.
Definition: clight.h:165
SFVEC2F GetExtent() const
Function GetExtent.
Definition: cbbox2d.cpp:127
virtual bool Intersects(const CBBOX2D &aBBox) const =0
Function Intersects.
Class CBBOX manages a bounding box defined by two SFVEC3F min max points.
Definition: cbbox.h:40
MAP_MODEL_MATERIALS m_model_materials
Stores materials of the 3D models.
const BOARD * GetBoard() const
GetBoard - Get current board to be rendered.
Definition: cinfo3d_visu.h:128
double BiuTo3Dunits() const
BiuTo3Dunits - Board integer units To 3D units.
Definition: cinfo3d_visu.h:141
const LIST_OBJECT & GetList() const
Definition: ccontainer.h:63
const MAP_CONTAINER_2D & GetMapLayers() const
GetMapLayers - Get the map of container that have the objects per layer.
Definition: cinfo3d_visu.h:293
#define min(a, b)
Definition: auxiliary.h:85
void InitSettings(REPORTER *aStatusTextReporter)
InitSettings - Function to be called by the render when it need to reload the settings for the board...
void Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(const SHAPE_POLY_SET &aMainPath, CGENERICCONTAINER2D &aDstContainer, float aBiuTo3DunitsScale, float aDivFactor, const BOARD_ITEM &aBoardItem)
Convert_path_polygon_to_polygon_blocks_and_dummy_blocks This function will use a polygon in the forma...
Definition: cpolygon2d.cpp:406
unsigned int GetStats_Nr_Holes() const
GetStats_Nr_Holes - Get statistics of the nr of holes.
Definition: cinfo3d_visu.h:368
const CBBOX & GetBBox3DU() const
GetBBox3DU - Get the bbox of the pcb board.
Definition: cinfo3d_visu.h:147
void C3D_RENDER_BASE::ReloadRequest ( )
inlineinherited

ReloadRequest - !TODO: this must be reviewed to add flags to improve specific render.

Definition at line 73 of file c3d_render_base.h.

References C3D_RENDER_BASE::m_reloadRequested.

Referenced by EDA_3D_CANVAS::ReloadRequest(), EDA_3D_CANVAS::RenderEngineChanged(), and EDA_3D_CANVAS::RenderRaytracingRequest().

73 { m_reloadRequested = true; }
bool m_reloadRequested
!TODO: this must be reviewed in order to flag change types
void C3D_RENDER_RAYTRACING::render ( GLubyte *  ptrPBO,
REPORTER aStatusTextReporter 
)
private

Definition at line 300 of file c3d_render_raytracing.cpp.

References CINFO3D_VISU::CameraGet(), ConvertSRGBToLinear(), Format(), CCAMERA::GetDir(), GetRunningMicroSecs(), i, CINFO3D_VISU::m_BgColorBot, m_BgColorBot_LinearRGB, CINFO3D_VISU::m_BgColorTop, m_BgColorTop_LinearRGB, m_camera_light, m_realBufferSize, m_rt_render_state, C3D_RENDER_BASE::m_settings, m_stats_start_rendering_time, RENDER_ENGINE_OPENGL_LEGACY, CINFO3D_VISU::RenderEngineGet(), REPORTER::Report(), restart_render_state(), rt_render_post_process_blur_finish(), rt_render_post_process_shade(), RT_RENDER_STATE_FINISH, RT_RENDER_STATE_MAX, RT_RENDER_STATE_POST_PROCESS_BLUR_AND_FINISH, RT_RENDER_STATE_POST_PROCESS_SHADE, RT_RENDER_STATE_TRACING, rt_render_tracing(), and CDIRECTIONALLIGHT::SetDirection().

Referenced by Redraw().

301 {
304  {
306 
307  if( m_camera_light )
309 
311  {
312  // Set all pixels of PBO transparent (Alpha to 0)
313  // This way it will draw the full buffer but only shows the updated (
314  // already calculated) squares
315  // /////////////////////////////////////////////////////////////////////
316  unsigned int nPixels = m_realBufferSize.x * m_realBufferSize.y;
317  GLubyte *tmp_ptrPBO = ptrPBO + 3; // PBO is RGBA
318 
319  for( unsigned int i = 0; i < nPixels; ++i )
320  {
321  *tmp_ptrPBO = 0;
322  tmp_ptrPBO += 4; // PBO is RGBA
323  }
324  }
325 
328  }
329 
330  switch( m_rt_render_state )
331  {
333  rt_render_tracing( ptrPBO, aStatusTextReporter );
334  break;
335 
337  rt_render_post_process_shade( ptrPBO, aStatusTextReporter );
338  break;
339 
341  rt_render_post_process_blur_finish( ptrPBO, aStatusTextReporter );
342  break;
343 
344  default:
345  wxASSERT_MSG( false, "Invalid state on m_rt_render_state");
347  break;
348  }
349 
350  if( aStatusTextReporter && (m_rt_render_state == RT_RENDER_STATE_FINISH) )
351  {
352  // Calculation time in seconds
353  const double calculation_time = (double)( GetRunningMicroSecs() -
355 
356  aStatusTextReporter->Report( wxString::Format( _( "Rendering time %.3f s" ),
357  calculation_time ) );
358  }
359 }
SFVEC3F ConvertSRGBToLinear(const SFVEC3F &aSRGBcolor)
void rt_render_post_process_shade(GLubyte *ptrPBO, REPORTER *aStatusTextReporter)
SFVEC3D m_BgColorBot
background bottom color
Definition: cinfo3d_visu.h:503
const SFVEC3F & GetDir() const
Definition: ccamera.h:109
CINFO3D_VISU & m_settings
settings refrence in use for this render
SFVEC3D m_BgColorTop
background top color
Definition: cinfo3d_visu.h:504
RT_RENDER_STATE m_rt_render_state
State used on quality render.
void rt_render_tracing(GLubyte *ptrPBO, REPORTER *aStatusTextReporter)
void rt_render_post_process_blur_finish(GLubyte *ptrPBO, REPORTER *aStatusTextReporter)
CDIRECTIONALLIGHT * m_camera_light
RENDER_ENGINE RenderEngineGet() const
RenderEngineGet.
Definition: cinfo3d_visu.h:234
void SetDirection(const SFVEC3F &aDir)
SetDirection - Set directional light orientation.
Definition: clight.h:129
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
unsigned GetRunningMicroSecs()
Function GetRunningMicroSecs An alternate way to calculate an elapset time (in microsecondes) to clas...
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
unsigned long int m_stats_start_rendering_time
Time that the render starts.
size_t i
Definition: json11.cpp:597
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
void C3D_RENDER_RAYTRACING::render_preview ( GLubyte *  ptrPBO)
private

Definition at line 1084 of file c3d_render_raytracing.cpp.

References BlendColor(), CINFO3D_VISU::CameraGet(), i, RAY::Init(), CGENERICACCELERATOR::Intersect(), COBJECT::Intersect(), m_accelerator, CINFO3D_VISU::m_BgColorBot, CINFO3D_VISU::m_BgColorTop, m_blockPositions, m_blockPositionsFast, HITINFO_PACKET::m_HitInfo, HITINFO::m_HitNormal, m_isPreview, m_realBufferSize, C3D_RENDER_BASE::m_settings, HITINFO::m_tHit, C3D_RENDER_BASE::m_windowSize, m_xoffset, m_yoffset, HITINFO::pHitObject, RAYPACKET_DIM, RAYPACKET_RAYS_PER_PACKET, SetPixel(), and shadeHit().

Referenced by Redraw().

1085 {
1086  m_isPreview = true;
1087 
1088  std::atomic<size_t> nextBlock( 0 );
1089  std::atomic<size_t> threadsFinished( 0 );
1090 
1091  size_t parallelThreadCount = std::min<size_t>(
1092  std::max<size_t>( std::thread::hardware_concurrency(), 2 ),
1093  m_blockPositions.size() );
1094  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
1095  {
1096  std::thread t = std::thread( [&]()
1097  {
1098  for( size_t iBlock = nextBlock.fetch_add( 1 );
1099  iBlock < m_blockPositionsFast.size();
1100  iBlock = nextBlock.fetch_add( 1 ) )
1101  {
1102  const SFVEC2UI &windowPosUI = m_blockPositionsFast[ iBlock ];
1103  const SFVEC2I windowsPos = SFVEC2I( windowPosUI.x + m_xoffset,
1104  windowPosUI.y + m_yoffset );
1105 
1106  RAYPACKET blockPacket( m_settings.CameraGet(), windowsPos, 4 );
1107 
1109 
1110  // Initialize hitPacket with a "not hit" information
1111  for( unsigned int i = 0; i < RAYPACKET_RAYS_PER_PACKET; ++i )
1112  {
1113  hitPacket[i].m_HitInfo.m_tHit = std::numeric_limits<float>::infinity();
1114  hitPacket[i].m_HitInfo.m_acc_node_info = 0;
1115  hitPacket[i].m_hitresult = false;
1116  }
1117 
1118  // Intersect packet block
1119  m_accelerator->Intersect( blockPacket, hitPacket );
1120 
1121 
1122  // Calculate background gradient color
1123  // /////////////////////////////////////////////////////////////////////
1124  SFVEC3F bgColor[RAYPACKET_DIM];
1125 
1126  for( unsigned int y = 0; y < RAYPACKET_DIM; ++y )
1127  {
1128  const float posYfactor = (float)(windowsPos.y + y * 4.0f) / (float)m_windowSize.y;
1129 
1130  bgColor[y] = (SFVEC3F)m_settings.m_BgColorTop * SFVEC3F(posYfactor) +
1131  (SFVEC3F)m_settings.m_BgColorBot * ( SFVEC3F(1.0f) - SFVEC3F(posYfactor) );
1132  }
1133 
1134  CCOLORRGB hitColorShading[RAYPACKET_RAYS_PER_PACKET];
1135 
1136  for( unsigned int i = 0; i < RAYPACKET_RAYS_PER_PACKET; ++i )
1137  {
1138  const SFVEC3F bhColorY = bgColor[i / RAYPACKET_DIM];
1139 
1140  if( hitPacket[i].m_hitresult == true )
1141  {
1142  const SFVEC3F hitColor = shadeHit( bhColorY,
1143  blockPacket.m_ray[i],
1144  hitPacket[i].m_HitInfo,
1145  false,
1146  0,
1147  false );
1148 
1149  hitColorShading[i] = CCOLORRGB( hitColor );
1150  }
1151  else
1152  hitColorShading[i] = bhColorY;
1153  }
1154 
1155  CCOLORRGB cLRB_old[(RAYPACKET_DIM - 1)];
1156 
1157  for( unsigned int y = 0; y < (RAYPACKET_DIM - 1); ++y )
1158  {
1159 
1160  const SFVEC3F bgColorY = bgColor[y];
1161  const CCOLORRGB bgColorYRGB = CCOLORRGB( bgColorY );
1162 
1163  // This stores cRTB from the last block to be reused next time in a cLTB pixel
1164  CCOLORRGB cRTB_old;
1165 
1166  //RAY cRTB_ray;
1167  //HITINFO cRTB_hitInfo;
1168 
1169  for( unsigned int x = 0; x < (RAYPACKET_DIM - 1); ++x )
1170  {
1171  // pxl 0 pxl 1 pxl 2 pxl 3 pxl 4
1172  // x0 x1 ...
1173  // .---------------------------.
1174  // y0 | cLT | cxxx | cLRT | cxxx | cRT |
1175  // | cxxx | cLTC | cxxx | cRTC | cxxx |
1176  // | cLTB | cxxx | cC | cxxx | cRTB |
1177  // | cxxx | cLBC | cxxx | cRBC | cxxx |
1178  // '---------------------------'
1179  // y1 | cLB | cxxx | cLRB | cxxx | cRB |
1180 
1181  const unsigned int iLT = ((x + 0) + RAYPACKET_DIM * (y + 0));
1182  const unsigned int iRT = ((x + 1) + RAYPACKET_DIM * (y + 0));
1183  const unsigned int iLB = ((x + 0) + RAYPACKET_DIM * (y + 1));
1184  const unsigned int iRB = ((x + 1) + RAYPACKET_DIM * (y + 1));
1185 
1186  // !TODO: skip when there are no hits
1187 
1188 
1189  const CCOLORRGB &cLT = hitColorShading[ iLT ];
1190  const CCOLORRGB &cRT = hitColorShading[ iRT ];
1191  const CCOLORRGB &cLB = hitColorShading[ iLB ];
1192  const CCOLORRGB &cRB = hitColorShading[ iRB ];
1193 
1194  // Trace and shade cC
1195  // /////////////////////////////////////////////////////////////
1196  CCOLORRGB cC = bgColorYRGB;
1197 
1198  const SFVEC3F &oriLT = blockPacket.m_ray[ iLT ].m_Origin;
1199  const SFVEC3F &oriRB = blockPacket.m_ray[ iRB ].m_Origin;
1200 
1201  const SFVEC3F &dirLT = blockPacket.m_ray[ iLT ].m_Dir;
1202  const SFVEC3F &dirRB = blockPacket.m_ray[ iRB ].m_Dir;
1203 
1204  SFVEC3F oriC;
1205  SFVEC3F dirC;
1206 
1207  HITINFO centerHitInfo;
1208  centerHitInfo.m_tHit = std::numeric_limits<float>::infinity();
1209 
1210  bool hittedC = false;
1211 
1212  if( (hitPacket[ iLT ].m_hitresult == true) ||
1213  (hitPacket[ iRT ].m_hitresult == true) ||
1214  (hitPacket[ iLB ].m_hitresult == true) ||
1215  (hitPacket[ iRB ].m_hitresult == true) )
1216  {
1217 
1218  oriC = ( oriLT + oriRB ) * 0.5f;
1219  dirC = glm::normalize( ( dirLT + dirRB ) * 0.5f );
1220 
1221  // Trace the center ray
1222  RAY centerRay;
1223  centerRay.Init( oriC, dirC );
1224 
1225  const unsigned int nodeLT = hitPacket[ iLT ].m_HitInfo.m_acc_node_info;
1226  const unsigned int nodeRT = hitPacket[ iRT ].m_HitInfo.m_acc_node_info;
1227  const unsigned int nodeLB = hitPacket[ iLB ].m_HitInfo.m_acc_node_info;
1228  const unsigned int nodeRB = hitPacket[ iRB ].m_HitInfo.m_acc_node_info;
1229 
1230  if( nodeLT != 0 )
1231  hittedC |= m_accelerator->Intersect( centerRay, centerHitInfo, nodeLT );
1232 
1233  if( ( nodeRT != 0 ) &&
1234  ( nodeRT != nodeLT ) )
1235  hittedC |= m_accelerator->Intersect( centerRay, centerHitInfo, nodeRT );
1236 
1237  if( ( nodeLB != 0 ) &&
1238  ( nodeLB != nodeLT ) &&
1239  ( nodeLB != nodeRT ) )
1240  hittedC |= m_accelerator->Intersect( centerRay, centerHitInfo, nodeLB );
1241 
1242  if( ( nodeRB != 0 ) &&
1243  ( nodeRB != nodeLB ) &&
1244  ( nodeRB != nodeLT ) &&
1245  ( nodeRB != nodeRT ) )
1246  hittedC |= m_accelerator->Intersect( centerRay, centerHitInfo, nodeRB );
1247 
1248  if( hittedC )
1249  cC = CCOLORRGB( shadeHit( bgColorY, centerRay, centerHitInfo, false, 0, false ) );
1250  else
1251  {
1252  centerHitInfo.m_tHit = std::numeric_limits<float>::infinity();
1253  hittedC = m_accelerator->Intersect( centerRay, centerHitInfo );
1254 
1255  if( hittedC )
1256  cC = CCOLORRGB( shadeHit( bgColorY,
1257  centerRay,
1258  centerHitInfo,
1259  false,
1260  0,
1261  false ) );
1262  }
1263  }
1264 
1265  // Trace and shade cLRT
1266  // /////////////////////////////////////////////////////////////
1267  CCOLORRGB cLRT = bgColorYRGB;
1268 
1269  const SFVEC3F &oriRT = blockPacket.m_ray[ iRT ].m_Origin;
1270  const SFVEC3F &dirRT = blockPacket.m_ray[ iRT ].m_Dir;
1271 
1272  if( y == 0 )
1273  {
1274  // Trace the center ray
1275  RAY rayLRT;
1276  rayLRT.Init( ( oriLT + oriRT ) * 0.5f,
1277  glm::normalize( ( dirLT + dirRT ) * 0.5f ) );
1278 
1279  HITINFO hitInfoLRT;
1280  hitInfoLRT.m_tHit = std::numeric_limits<float>::infinity();
1281 
1282  if( hitPacket[ iLT ].m_hitresult &&
1283  hitPacket[ iRT ].m_hitresult &&
1284  (hitPacket[ iLT ].m_HitInfo.pHitObject == hitPacket[ iRT ].m_HitInfo.pHitObject) )
1285  {
1286  hitInfoLRT.pHitObject = hitPacket[ iLT ].m_HitInfo.pHitObject;
1287  hitInfoLRT.m_tHit = ( hitPacket[ iLT ].m_HitInfo.m_tHit +
1288  hitPacket[ iRT ].m_HitInfo.m_tHit ) * 0.5f;
1289  hitInfoLRT.m_HitNormal =
1290  glm::normalize( ( hitPacket[ iLT ].m_HitInfo.m_HitNormal +
1291  hitPacket[ iRT ].m_HitInfo.m_HitNormal ) * 0.5f );
1292 
1293  cLRT = CCOLORRGB( shadeHit( bgColorY, rayLRT, hitInfoLRT, false, 0, false ) );
1294  cLRT = BlendColor( cLRT, BlendColor( cLT, cRT) );
1295  }
1296  else
1297  {
1298  if( hitPacket[ iLT ].m_hitresult ||
1299  hitPacket[ iRT ].m_hitresult ) // If any hits
1300  {
1301  const unsigned int nodeLT = hitPacket[ iLT ].m_HitInfo.m_acc_node_info;
1302  const unsigned int nodeRT = hitPacket[ iRT ].m_HitInfo.m_acc_node_info;
1303 
1304  bool hittedLRT = false;
1305 
1306  if( nodeLT != 0 )
1307  hittedLRT |= m_accelerator->Intersect( rayLRT, hitInfoLRT, nodeLT );
1308 
1309  if( ( nodeRT != 0 ) &&
1310  ( nodeRT != nodeLT ) )
1311  hittedLRT |= m_accelerator->Intersect( rayLRT,
1312  hitInfoLRT,
1313  nodeRT );
1314 
1315  if( hittedLRT )
1316  cLRT = CCOLORRGB( shadeHit( bgColorY,
1317  rayLRT,
1318  hitInfoLRT,
1319  false,
1320  0,
1321  false ) );
1322  else
1323  {
1324  hitInfoLRT.m_tHit = std::numeric_limits<float>::infinity();
1325 
1326  if( m_accelerator->Intersect( rayLRT,hitInfoLRT ) )
1327  cLRT = CCOLORRGB( shadeHit( bgColorY,
1328  rayLRT,
1329  hitInfoLRT,
1330  false,
1331  0,
1332  false ) );
1333  }
1334  }
1335  }
1336  }
1337  else
1338  cLRT = cLRB_old[x];
1339 
1340 
1341  // Trace and shade cLTB
1342  // /////////////////////////////////////////////////////////////
1343  CCOLORRGB cLTB = bgColorYRGB;
1344 
1345  if( x == 0 )
1346  {
1347  const SFVEC3F &oriLB = blockPacket.m_ray[ iLB ].m_Origin;
1348  const SFVEC3F &dirLB = blockPacket.m_ray[ iLB ].m_Dir;
1349 
1350  // Trace the center ray
1351  RAY rayLTB;
1352  rayLTB.Init( ( oriLT + oriLB ) * 0.5f,
1353  glm::normalize( ( dirLT + dirLB ) * 0.5f ) );
1354 
1355  HITINFO hitInfoLTB;
1356  hitInfoLTB.m_tHit = std::numeric_limits<float>::infinity();
1357 
1358  if( hitPacket[ iLT ].m_hitresult &&
1359  hitPacket[ iLB ].m_hitresult &&
1360  ( hitPacket[ iLT ].m_HitInfo.pHitObject ==
1361  hitPacket[ iLB ].m_HitInfo.pHitObject ) )
1362  {
1363  hitInfoLTB.pHitObject = hitPacket[ iLT ].m_HitInfo.pHitObject;
1364  hitInfoLTB.m_tHit = ( hitPacket[ iLT ].m_HitInfo.m_tHit +
1365  hitPacket[ iLB ].m_HitInfo.m_tHit ) * 0.5f;
1366  hitInfoLTB.m_HitNormal =
1367  glm::normalize( ( hitPacket[ iLT ].m_HitInfo.m_HitNormal +
1368  hitPacket[ iLB ].m_HitInfo.m_HitNormal ) * 0.5f );
1369  cLTB = CCOLORRGB( shadeHit( bgColorY, rayLTB, hitInfoLTB, false, 0, false ) );
1370  cLTB = BlendColor( cLTB, BlendColor( cLT, cLB) );
1371  }
1372  else
1373  {
1374  if( hitPacket[ iLT ].m_hitresult ||
1375  hitPacket[ iLB ].m_hitresult ) // If any hits
1376  {
1377  const unsigned int nodeLT = hitPacket[ iLT ].m_HitInfo.m_acc_node_info;
1378  const unsigned int nodeLB = hitPacket[ iLB ].m_HitInfo.m_acc_node_info;
1379 
1380  bool hittedLTB = false;
1381 
1382  if( nodeLT != 0 )
1383  hittedLTB |= m_accelerator->Intersect( rayLTB,
1384  hitInfoLTB,
1385  nodeLT );
1386 
1387  if( ( nodeLB != 0 ) &&
1388  ( nodeLB != nodeLT ) )
1389  hittedLTB |= m_accelerator->Intersect( rayLTB,
1390  hitInfoLTB,
1391  nodeLB );
1392 
1393  if( hittedLTB )
1394  cLTB = CCOLORRGB( shadeHit( bgColorY,
1395  rayLTB,
1396  hitInfoLTB,
1397  false,
1398  0,
1399  false ) );
1400  else
1401  {
1402  hitInfoLTB.m_tHit = std::numeric_limits<float>::infinity();
1403 
1404  if( m_accelerator->Intersect( rayLTB, hitInfoLTB ) )
1405  cLTB = CCOLORRGB( shadeHit( bgColorY,
1406  rayLTB,
1407  hitInfoLTB,
1408  false,
1409  0,
1410  false ) );
1411  }
1412  }
1413  }
1414  }
1415  else
1416  cLTB = cRTB_old;
1417 
1418 
1419  // Trace and shade cRTB
1420  // /////////////////////////////////////////////////////////////
1421  CCOLORRGB cRTB = bgColorYRGB;
1422 
1423  // Trace the center ray
1424  RAY rayRTB;
1425  rayRTB.Init( ( oriRT + oriRB ) * 0.5f,
1426  glm::normalize( ( dirRT + dirRB ) * 0.5f ) );
1427 
1428  HITINFO hitInfoRTB;
1429  hitInfoRTB.m_tHit = std::numeric_limits<float>::infinity();
1430 
1431  if( hitPacket[ iRT ].m_hitresult &&
1432  hitPacket[ iRB ].m_hitresult &&
1433  ( hitPacket[ iRT ].m_HitInfo.pHitObject ==
1434  hitPacket[ iRB ].m_HitInfo.pHitObject ) )
1435  {
1436  hitInfoRTB.pHitObject = hitPacket[ iRT ].m_HitInfo.pHitObject;
1437 
1438  hitInfoRTB.m_tHit = ( hitPacket[ iRT ].m_HitInfo.m_tHit +
1439  hitPacket[ iRB ].m_HitInfo.m_tHit ) * 0.5f;
1440 
1441  hitInfoRTB.m_HitNormal =
1442  glm::normalize( ( hitPacket[ iRT ].m_HitInfo.m_HitNormal +
1443  hitPacket[ iRB ].m_HitInfo.m_HitNormal ) * 0.5f );
1444 
1445  cRTB = CCOLORRGB( shadeHit( bgColorY, rayRTB, hitInfoRTB, false, 0, false ) );
1446  cRTB = BlendColor( cRTB, BlendColor( cRT, cRB) );
1447  }
1448  else
1449  {
1450  if( hitPacket[ iRT ].m_hitresult ||
1451  hitPacket[ iRB ].m_hitresult ) // If any hits
1452  {
1453  const unsigned int nodeRT = hitPacket[ iRT ].m_HitInfo.m_acc_node_info;
1454  const unsigned int nodeRB = hitPacket[ iRB ].m_HitInfo.m_acc_node_info;
1455 
1456  bool hittedRTB = false;
1457 
1458  if( nodeRT != 0 )
1459  hittedRTB |= m_accelerator->Intersect( rayRTB, hitInfoRTB, nodeRT );
1460 
1461  if( ( nodeRB != 0 ) &&
1462  ( nodeRB != nodeRT ) )
1463  hittedRTB |= m_accelerator->Intersect( rayRTB, hitInfoRTB, nodeRB );
1464 
1465  if( hittedRTB )
1466  cRTB = CCOLORRGB( shadeHit( bgColorY,
1467  rayRTB,
1468  hitInfoRTB,
1469  false,
1470  0,
1471  false) );
1472  else
1473  {
1474  hitInfoRTB.m_tHit = std::numeric_limits<float>::infinity();
1475 
1476  if( m_accelerator->Intersect( rayRTB, hitInfoRTB ) )
1477  cRTB = CCOLORRGB( shadeHit( bgColorY,
1478  rayRTB,
1479  hitInfoRTB,
1480  false,
1481  0,
1482  false ) );
1483  }
1484  }
1485  }
1486 
1487  cRTB_old = cRTB;
1488 
1489 
1490  // Trace and shade cLRB
1491  // /////////////////////////////////////////////////////////////
1492  CCOLORRGB cLRB = bgColorYRGB;
1493 
1494  const SFVEC3F &oriLB = blockPacket.m_ray[ iLB ].m_Origin;
1495  const SFVEC3F &dirLB = blockPacket.m_ray[ iLB ].m_Dir;
1496 
1497  // Trace the center ray
1498  RAY rayLRB;
1499  rayLRB.Init( ( oriLB + oriRB ) * 0.5f,
1500  glm::normalize( ( dirLB + dirRB ) * 0.5f ) );
1501 
1502  HITINFO hitInfoLRB;
1503  hitInfoLRB.m_tHit = std::numeric_limits<float>::infinity();
1504 
1505  if( hitPacket[ iLB ].m_hitresult &&
1506  hitPacket[ iRB ].m_hitresult &&
1507  ( hitPacket[ iLB ].m_HitInfo.pHitObject ==
1508  hitPacket[ iRB ].m_HitInfo.pHitObject ) )
1509  {
1510  hitInfoLRB.pHitObject = hitPacket[ iLB ].m_HitInfo.pHitObject;
1511 
1512  hitInfoLRB.m_tHit = ( hitPacket[ iLB ].m_HitInfo.m_tHit +
1513  hitPacket[ iRB ].m_HitInfo.m_tHit ) * 0.5f;
1514 
1515  hitInfoLRB.m_HitNormal =
1516  glm::normalize( ( hitPacket[ iLB ].m_HitInfo.m_HitNormal +
1517  hitPacket[ iRB ].m_HitInfo.m_HitNormal ) * 0.5f );
1518 
1519  cLRB = CCOLORRGB( shadeHit( bgColorY, rayLRB, hitInfoLRB, false, 0, false ) );
1520  cLRB = BlendColor( cLRB, BlendColor( cLB, cRB) );
1521  }
1522  else
1523  {
1524  if( hitPacket[ iLB ].m_hitresult ||
1525  hitPacket[ iRB ].m_hitresult ) // If any hits
1526  {
1527  const unsigned int nodeLB = hitPacket[ iLB ].m_HitInfo.m_acc_node_info;
1528  const unsigned int nodeRB = hitPacket[ iRB ].m_HitInfo.m_acc_node_info;
1529 
1530  bool hittedLRB = false;
1531 
1532  if( nodeLB != 0 )
1533  hittedLRB |= m_accelerator->Intersect( rayLRB, hitInfoLRB, nodeLB );
1534 
1535  if( ( nodeRB != 0 ) &&
1536  ( nodeRB != nodeLB ) )
1537  hittedLRB |= m_accelerator->Intersect( rayLRB, hitInfoLRB, nodeRB );
1538 
1539  if( hittedLRB )
1540  cLRB = CCOLORRGB( shadeHit( bgColorY, rayLRB, hitInfoLRB, false, 0, false ) );
1541  else
1542  {
1543  hitInfoLRB.m_tHit = std::numeric_limits<float>::infinity();
1544 
1545  if( m_accelerator->Intersect( rayLRB, hitInfoLRB ) )
1546  cLRB = CCOLORRGB( shadeHit( bgColorY,
1547  rayLRB,
1548  hitInfoLRB,
1549  false,
1550  0,
1551  false ) );
1552  }
1553  }
1554  }
1555 
1556  cLRB_old[x] = cLRB;
1557 
1558 
1559  // Trace and shade cLTC
1560  // /////////////////////////////////////////////////////////////
1561  CCOLORRGB cLTC = BlendColor( cLT , cC );
1562 
1563  if( hitPacket[ iLT ].m_hitresult || hittedC )
1564  {
1565  // Trace the center ray
1566  RAY rayLTC;
1567  rayLTC.Init( ( oriLT + oriC ) * 0.5f,
1568  glm::normalize( ( dirLT + dirC ) * 0.5f ) );
1569 
1570  HITINFO hitInfoLTC;
1571  hitInfoLTC.m_tHit = std::numeric_limits<float>::infinity();
1572 
1573  bool hitted = false;
1574 
1575  if( hittedC )
1576  hitted = centerHitInfo.pHitObject->Intersect( rayLTC, hitInfoLTC );
1577  else
1578  if( hitPacket[ iLT ].m_hitresult )
1579  hitted = hitPacket[ iLT ].m_HitInfo.pHitObject->Intersect( rayLTC,
1580  hitInfoLTC );
1581 
1582  if( hitted )
1583  cLTC = CCOLORRGB( shadeHit( bgColorY, rayLTC, hitInfoLTC, false, 0, false ) );
1584  }
1585 
1586 
1587  // Trace and shade cRTC
1588  // /////////////////////////////////////////////////////////////
1589  CCOLORRGB cRTC = BlendColor( cRT , cC );
1590 
1591  if( hitPacket[ iRT ].m_hitresult || hittedC )
1592  {
1593  // Trace the center ray
1594  RAY rayRTC;
1595  rayRTC.Init( ( oriRT + oriC ) * 0.5f,
1596  glm::normalize( ( dirRT + dirC ) * 0.5f ) );
1597 
1598  HITINFO hitInfoRTC;
1599  hitInfoRTC.m_tHit = std::numeric_limits<float>::infinity();
1600 
1601  bool hitted = false;
1602 
1603  if( hittedC )
1604  hitted = centerHitInfo.pHitObject->Intersect( rayRTC, hitInfoRTC );
1605  else
1606  if( hitPacket[ iRT ].m_hitresult )
1607  hitted = hitPacket[ iRT ].m_HitInfo.pHitObject->Intersect( rayRTC,
1608  hitInfoRTC );
1609 
1610  if( hitted )
1611  cRTC = CCOLORRGB( shadeHit( bgColorY, rayRTC, hitInfoRTC, false, 0, false ) );
1612  }
1613 
1614 
1615  // Trace and shade cLBC
1616  // /////////////////////////////////////////////////////////////
1617  CCOLORRGB cLBC = BlendColor( cLB , cC );
1618 
1619  if( hitPacket[ iLB ].m_hitresult || hittedC )
1620  {
1621  // Trace the center ray
1622  RAY rayLBC;
1623  rayLBC.Init( ( oriLB + oriC ) * 0.5f,
1624  glm::normalize( ( dirLB + dirC ) * 0.5f ) );
1625 
1626  HITINFO hitInfoLBC;
1627  hitInfoLBC.m_tHit = std::numeric_limits<float>::infinity();
1628 
1629  bool hitted = false;
1630 
1631  if( hittedC )
1632  hitted = centerHitInfo.pHitObject->Intersect( rayLBC, hitInfoLBC );
1633  else
1634  if( hitPacket[ iLB ].m_hitresult )
1635  hitted = hitPacket[ iLB ].m_HitInfo.pHitObject->Intersect( rayLBC,
1636  hitInfoLBC );
1637 
1638  if( hitted )
1639  cLBC = CCOLORRGB( shadeHit( bgColorY, rayLBC, hitInfoLBC, false, 0, false ) );
1640  }
1641 
1642 
1643  // Trace and shade cRBC
1644  // /////////////////////////////////////////////////////////////
1645  CCOLORRGB cRBC = BlendColor( cRB , cC );
1646 
1647  if( hitPacket[ iRB ].m_hitresult || hittedC )
1648  {
1649  // Trace the center ray
1650  RAY rayRBC;
1651  rayRBC.Init( ( oriRB + oriC ) * 0.5f,
1652  glm::normalize( ( dirRB + dirC ) * 0.5f ) );
1653 
1654  HITINFO hitInfoRBC;
1655  hitInfoRBC.m_tHit = std::numeric_limits<float>::infinity();
1656 
1657  bool hitted = false;
1658 
1659  if( hittedC )
1660  hitted = centerHitInfo.pHitObject->Intersect( rayRBC, hitInfoRBC );
1661  else
1662  if( hitPacket[ iRB ].m_hitresult )
1663  hitted = hitPacket[ iRB ].m_HitInfo.pHitObject->Intersect( rayRBC,
1664  hitInfoRBC );
1665 
1666  if( hitted )
1667  cRBC = CCOLORRGB( shadeHit( bgColorY, rayRBC, hitInfoRBC, false, 0, false ) );
1668  }
1669 
1670 
1671  // Set pixel colors
1672  // /////////////////////////////////////////////////////////////
1673 
1674  GLubyte *ptr = &ptrPBO[ (4 * x + m_blockPositionsFast[iBlock].x +
1675  m_realBufferSize.x *
1676  (m_blockPositionsFast[iBlock].y + 4 * y)) * 4 ];
1677  SetPixel( ptr + 0, cLT );
1678  SetPixel( ptr + 4, BlendColor( cLT, cLRT, cLTC ) );
1679  SetPixel( ptr + 8, cLRT );
1680  SetPixel( ptr + 12, BlendColor( cLRT, cRT, cRTC ) );
1681 
1682  ptr += m_realBufferSize.x * 4;
1683  SetPixel( ptr + 0, BlendColor( cLT , cLTB, cLTC ) );
1684  SetPixel( ptr + 4, BlendColor( cLTC, BlendColor( cLT , cC ) ) );
1685  SetPixel( ptr + 8, BlendColor( cC, BlendColor( cLRT, cLTC, cRTC ) ) );
1686  SetPixel( ptr + 12, BlendColor( cRTC, BlendColor( cRT , cC ) ) );
1687 
1688  ptr += m_realBufferSize.x * 4;
1689  SetPixel( ptr + 0, cLTB );
1690  SetPixel( ptr + 4, BlendColor( cC, BlendColor( cLTB, cLTC, cLBC ) ) );
1691  SetPixel( ptr + 8, cC );
1692  SetPixel( ptr + 12, BlendColor( cC, BlendColor( cRTB, cRTC, cRBC ) ) );
1693 
1694  ptr += m_realBufferSize.x * 4;
1695  SetPixel( ptr + 0, BlendColor( cLB , cLTB, cLBC ) );
1696  SetPixel( ptr + 4, BlendColor( cLBC, BlendColor( cLB , cC ) ) );
1697  SetPixel( ptr + 8, BlendColor( cC, BlendColor( cLRB, cLBC, cRBC ) ) );
1698  SetPixel( ptr + 12, BlendColor( cRBC, BlendColor( cRB , cC ) ) );
1699  }
1700  }
1701  }
1702 
1703  threadsFinished++;
1704  } );
1705 
1706  t.detach();
1707  }
1708 
1709  while( threadsFinished < parallelThreadCount )
1710  std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
1711 }
#define RAYPACKET_DIM
Definition: raypacket.h:37
SFVEC3F shadeHit(const SFVEC3F &aBgColor, const RAY &aRay, HITINFO &aHitInfo, bool aIsInsideObject, unsigned int aRecursiveLevel, bool is_testShadow) const
void Init(const SFVEC3F &o, const SFVEC3F &d)
Definition: ray.cpp:40
SFVEC3D m_BgColorBot
background bottom color
Definition: cinfo3d_visu.h:503
Definition: ray.h:43
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:42
CINFO3D_VISU & m_settings
settings refrence in use for this render
SFVEC3D m_BgColorTop
background top color
Definition: cinfo3d_visu.h:504
float m_tHit
( 4) distance
Definition: hitinfo.h:43
glm::uvec2 SFVEC2UI
Definition: xv3d_types.h:41
CGENERICACCELERATOR * m_accelerator
virtual bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const =0
HITINFO m_HitInfo
Definition: hitinfo.h:63
wxSize m_windowSize
The window size that this camera is working.
const COBJECT * pHitObject
( 4) Object that was hitted
Definition: hitinfo.h:45
std::vector< SFVEC2UI > m_blockPositionsFast
this encodes the Morton code positions (on fast preview mode)
virtual bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const =0
Functions Intersect.
static void SetPixel(GLubyte *p, const CCOLORRGB &v)
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:40
#define RAYPACKET_RAYS_PER_PACKET
Definition: raypacket.h:40
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
CCOLORRGB BlendColor(const CCOLORRGB &aC1, const CCOLORRGB &aC2)
Definition: ccolorrgb.cpp:42
std::vector< SFVEC2UI > m_blockPositions
this encodes the Morton code positions
size_t i
Definition: json11.cpp:597
SFVEC3F m_HitNormal
(12) normal at the hit point
Definition: hitinfo.h:42
void C3D_RENDER_RAYTRACING::restart_render_state ( )
private

Definition at line 125 of file c3d_render_raytracing.cpp.

References GetRunningMicroSecs(), CPOSTSHADER::InitFrame(), m_blockPositions, m_blockPositionsWasProcessed, m_nrBlocksRenderProgress, m_postshader_ssao, m_rt_render_state, m_stats_start_rendering_time, and RT_RENDER_STATE_TRACING.

Referenced by render().

126 {
128 
131 
133 
135 
136  // Mark the blocks not processed yet
137  std::fill( m_blockPositionsWasProcessed.begin(),
139  0 );
140 }
CPOSTSHADER_SSAO m_postshader_ssao
std::vector< int > m_blockPositionsWasProcessed
this flags if a position was already processed (cleared each new render)
size_t m_nrBlocksRenderProgress
Save the number of blocks progress of the render.
RT_RENDER_STATE m_rt_render_state
State used on quality render.
void InitFrame()
Definition: cpostshader.h:54
unsigned GetRunningMicroSecs()
Function GetRunningMicroSecs An alternate way to calculate an elapset time (in microsecondes) to clas...
std::vector< SFVEC2UI > m_blockPositions
this encodes the Morton code positions
unsigned long int m_stats_start_rendering_time
Time that the render starts.
void C3D_RENDER_RAYTRACING::rt_final_color ( GLubyte *  ptrPBO,
const SFVEC3F rgbColor,
bool  applyColorSpaceConversion 
)
private

Definition at line 463 of file c3d_render_raytracing.cpp.

References color, and convertLinearToSRGB().

Referenced by rt_render_post_process_blur_finish(), and rt_render_trace_block().

466 {
467 
468  SFVEC3F color = rgbColor;
469 
470 #ifdef USE_SRGB_SPACE
471 
472  // This should be used in future when the KiCad support a greater version of
473  // glm lib.
474  // if( applyColorSpaceConversion )
475  // rgbColor = glm::convertLinearToSRGB( rgbColor );
476 
477  if( applyColorSpaceConversion )
478  color = convertLinearToSRGB( rgbColor );
479 #endif
480 
481  ptrPBO[0] = (unsigned int)glm::clamp( (int)(color.r * 255), 0, 255 );
482  ptrPBO[1] = (unsigned int)glm::clamp( (int)(color.g * 255), 0, 255 );
483  ptrPBO[2] = (unsigned int)glm::clamp( (int)(color.b * 255), 0, 255 );
484  ptrPBO[3] = 255;
485 }
int color
Definition: DXF_plotter.cpp:62
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
static SFVEC3F convertLinearToSRGB(const SFVEC3F &aRGBcolor)
void C3D_RENDER_RAYTRACING::rt_render_post_process_blur_finish ( GLubyte *  ptrPBO,
REPORTER aStatusTextReporter 
)
private

Definition at line 965 of file c3d_render_raytracing.cpp.

References CPOSTSHADER_SSAO::ApplyShadeColor(), convertLinearToSRGB(), FL_RENDER_RAYTRACING_POST_PROCESSING, CPOSTSHADER::GetColorAtNotProtected(), CINFO3D_VISU::GetFlag(), m_postshader_ssao, m_realBufferSize, m_rt_render_state, C3D_RENDER_BASE::m_settings, m_shaderBuffer, max, min, rt_final_color(), and RT_RENDER_STATE_FINISH.

Referenced by render().

967 {
968  (void)aStatusTextReporter; //unused
969 
971  {
972  // Now blurs the shader result and compute the final color
973  std::atomic<size_t> nextBlock( 0 );
974  std::atomic<size_t> threadsFinished( 0 );
975 
976  size_t parallelThreadCount = std::max<size_t>( std::thread::hardware_concurrency(), 2 );
977  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
978  {
979  std::thread t = std::thread( [&]()
980  {
981  for( size_t y = nextBlock.fetch_add( 1 );
982  y < m_realBufferSize.y;
983  y = nextBlock.fetch_add( 1 ) )
984  {
985  GLubyte *ptr = &ptrPBO[ y * m_realBufferSize.x * 4 ];
986 
987  const SFVEC3F *ptrShaderY0 =
988  &m_shaderBuffer[ glm::max((int)y - 2, 0) * m_realBufferSize.x ];
989  const SFVEC3F *ptrShaderY1 =
990  &m_shaderBuffer[ glm::max((int)y - 1, 0) * m_realBufferSize.x ];
991  const SFVEC3F *ptrShaderY2 =
993  const SFVEC3F *ptrShaderY3 =
994  &m_shaderBuffer[ glm::min((int)y + 1, (int)(m_realBufferSize.y - 1)) *
995  m_realBufferSize.x ];
996  const SFVEC3F *ptrShaderY4 =
997  &m_shaderBuffer[ glm::min((int)y + 2, (int)(m_realBufferSize.y - 1)) *
998  m_realBufferSize.x ];
999 
1000  for( signed int x = 0; x < (int)m_realBufferSize.x; ++x )
1001  {
1002  // This #if should be 1, it is here that can be used for debug proposes during development
1003  #if 1
1004  int idx = x > 1 ? -2 : 0;
1005  SFVEC3F bluredShadeColor = ptrShaderY0[idx] * 1.0f / 273.0f +
1006  ptrShaderY1[idx] * 4.0f / 273.0f +
1007  ptrShaderY2[idx] * 7.0f / 273.0f +
1008  ptrShaderY3[idx] * 4.0f / 273.0f +
1009  ptrShaderY4[idx] * 1.0f / 273.0f;
1010 
1011  idx = x > 0 ? -1 : 0;
1012  bluredShadeColor += ptrShaderY0[idx] * 4.0f / 273.0f +
1013  ptrShaderY1[idx] * 16.0f / 273.0f +
1014  ptrShaderY2[idx] * 26.0f / 273.0f +
1015  ptrShaderY3[idx] * 16.0f / 273.0f +
1016  ptrShaderY4[idx] * 4.0f / 273.0f;
1017 
1018  bluredShadeColor += (*ptrShaderY0) * 7.0f / 273.0f +
1019  (*ptrShaderY1) * 26.0f / 273.0f +
1020  (*ptrShaderY2) * 41.0f / 273.0f +
1021  (*ptrShaderY3) * 26.0f / 273.0f +
1022  (*ptrShaderY4) * 7.0f / 273.0f;
1023 
1024  idx = (x < (int)m_realBufferSize.x - 1) ? 1 : 0;
1025  bluredShadeColor += ptrShaderY0[idx] * 4.0f / 273.0f +
1026  ptrShaderY1[idx] *16.0f / 273.0f +
1027  ptrShaderY2[idx] *26.0f / 273.0f +
1028  ptrShaderY3[idx] *16.0f / 273.0f +
1029  ptrShaderY4[idx] * 4.0f / 273.0f;
1030 
1031  idx = (x < (int)m_realBufferSize.x - 2) ? 2 : 0;
1032  bluredShadeColor += ptrShaderY0[idx] * 1.0f / 273.0f +
1033  ptrShaderY1[idx] * 4.0f / 273.0f +
1034  ptrShaderY2[idx] * 7.0f / 273.0f +
1035  ptrShaderY3[idx] * 4.0f / 273.0f +
1036  ptrShaderY4[idx] * 1.0f / 273.0f;
1037 
1038  // process next pixel
1039  ++ptrShaderY0;
1040  ++ptrShaderY1;
1041  ++ptrShaderY2;
1042  ++ptrShaderY3;
1043  ++ptrShaderY4;
1044 
1045  #ifdef USE_SRGB_SPACE
1047  #else
1048  const SFVEC3F originColor = m_postshader_ssao.GetColorAtNotProtected( SFVEC2I( x,y ) );
1049  #endif
1050 
1051  const SFVEC3F shadedColor = m_postshader_ssao.ApplyShadeColor( SFVEC2I( x,y ), originColor, bluredShadeColor );
1052  #else
1053  // Debug code
1054  //const SFVEC3F shadedColor = SFVEC3F( 1.0f ) -
1055  // m_shaderBuffer[ y * m_realBufferSize.x + x];
1056  const SFVEC3F shadedColor = m_shaderBuffer[ y * m_realBufferSize.x + x ];
1057  #endif
1058 
1059  rt_final_color( ptr, shadedColor, false );
1060 
1061  ptr += 4;
1062  }
1063  }
1064 
1065  threadsFinished++;
1066  } );
1067 
1068  t.detach();
1069  }
1070 
1071  while( threadsFinished < parallelThreadCount )
1072  std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
1073 
1074 
1075  // Debug code
1076  //m_postshader_ssao.DebugBuffersOutputAsImages();
1077  }
1078 
1079  // End rendering
1081 }
SFVEC3F ApplyShadeColor(const SFVEC2I &aShaderPos, const SFVEC3F &aInputColor, const SFVEC3F &aShadeColor) const override
ApplyShadeColor - apply the final color process using a previous stage color.
const SFVEC3F & GetColorAtNotProtected(const SFVEC2I &aPos) const
void rt_final_color(GLubyte *ptrPBO, const SFVEC3F &rgbColor, bool applyColorSpaceConversion)
CPOSTSHADER_SSAO m_postshader_ssao
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:42
CINFO3D_VISU & m_settings
settings refrence in use for this render
RT_RENDER_STATE m_rt_render_state
State used on quality render.
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
#define max(a, b)
Definition: auxiliary.h:86
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
static SFVEC3F convertLinearToSRGB(const SFVEC3F &aRGBcolor)
#define min(a, b)
Definition: auxiliary.h:85
void C3D_RENDER_RAYTRACING::rt_render_post_process_shade ( GLubyte *  ptrPBO,
REPORTER aStatusTextReporter 
)
private

Definition at line 914 of file c3d_render_raytracing.cpp.

References FL_RENDER_RAYTRACING_POST_PROCESSING, CINFO3D_VISU::GetFlag(), m_postshader_ssao, m_realBufferSize, m_rt_render_state, C3D_RENDER_BASE::m_settings, m_shaderBuffer, REPORTER::Report(), RT_RENDER_STATE_FINISH, RT_RENDER_STATE_POST_PROCESS_BLUR_AND_FINISH, and CPOSTSHADER_SSAO::Shade().

Referenced by render().

916 {
917  (void)ptrPBO; // unused
918 
920  {
921  if( aStatusTextReporter )
922  aStatusTextReporter->Report( _("Rendering: Post processing shader") );
923 
924  std::atomic<size_t> nextBlock( 0 );
925  std::atomic<size_t> threadsFinished( 0 );
926 
927  size_t parallelThreadCount = std::max<size_t>( std::thread::hardware_concurrency(), 2 );
928  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
929  {
930  std::thread t = std::thread( [&]()
931  {
932  for( size_t y = nextBlock.fetch_add( 1 );
933  y < m_realBufferSize.y;
934  y = nextBlock.fetch_add( 1 ) )
935  {
936  SFVEC3F *ptr = &m_shaderBuffer[ y * m_realBufferSize.x ];
937 
938  for( signed int x = 0; x < (int)m_realBufferSize.x; ++x )
939  {
940  *ptr = m_postshader_ssao.Shade( SFVEC2I( x, y ) );
941  ptr++;
942  }
943  }
944 
945  threadsFinished++;
946  } );
947 
948  t.detach();
949  }
950 
951  while( threadsFinished < parallelThreadCount )
952  std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
953 
954  // Set next state
956  }
957  else
958  {
959  // As this was an invalid state, set to finish
961  }
962 }
SFVEC3F Shade(const SFVEC2I &aShaderPos) const override
CPOSTSHADER_SSAO m_postshader_ssao
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:42
CINFO3D_VISU & m_settings
settings refrence in use for this render
RT_RENDER_STATE m_rt_render_state
State used on quality render.
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
void C3D_RENDER_RAYTRACING::rt_render_trace_block ( GLubyte *  ptrPBO,
signed int  iBlock 
)
private

Definition at line 657 of file c3d_render_raytracing.cpp.

References CINFO3D_VISU::CameraGet(), DISP_FACTOR, FL_RENDER_RAYTRACING_ANTI_ALIASING, FL_RENDER_RAYTRACING_POST_PROCESSING, FL_RENDER_RAYTRACING_SHADOWS, CINFO3D_VISU::GetFlag(), HITINFO_PACKET_init(), i, CGENERICACCELERATOR::Intersect(), m_accelerator, m_BgColorBot_LinearRGB, m_BgColorTop_LinearRGB, m_blockPositions, m_postshader_ssao, m_realBufferSize, C3D_RENDER_BASE::m_settings, C3D_RENDER_BASE::m_windowSize, m_xoffset, m_yoffset, RAYPACKET_DIM, RAYPACKET_InitRays_with2DDisplacement(), RAYPACKET_RAYS_PER_PACKET, rt_final_color(), rt_shades_packet(), rt_trace_AA_packet(), and CPOSTSHADER::SetPixelData().

Referenced by rt_render_tracing().

659 {
660  // Initialize ray packets
661  // /////////////////////////////////////////////////////////////////////////
662  const SFVEC2UI &blockPos = m_blockPositions[iBlock];
663  const SFVEC2I blockPosI = SFVEC2I( blockPos.x + m_xoffset,
664  blockPos.y + m_yoffset );
665 
666  RAYPACKET blockPacket( m_settings.CameraGet(),
667  (SFVEC2F)blockPosI + SFVEC2F(DISP_FACTOR, DISP_FACTOR),
668  SFVEC2F(DISP_FACTOR, DISP_FACTOR) // Displacement random factor
669  );
670 
672 
673  HITINFO_PACKET_init( hitPacket_X0Y0 );
674 
675  // Calculate background gradient color
676  // /////////////////////////////////////////////////////////////////////////
677  SFVEC3F bgColor[RAYPACKET_DIM];// Store a vertical gradient color
678 
679  for( unsigned int y = 0; y < RAYPACKET_DIM; ++y )
680  {
681  const float posYfactor = (float)(blockPosI.y + y) / (float)m_windowSize.y;
682 
683  bgColor[y] = m_BgColorTop_LinearRGB * SFVEC3F(posYfactor) +
684  m_BgColorBot_LinearRGB * ( SFVEC3F(1.0f) - SFVEC3F(posYfactor) );
685  }
686 
687  // Intersect ray packets (calculate the intersection with rays and objects)
688  // /////////////////////////////////////////////////////////////////////////
689  if( !m_accelerator->Intersect( blockPacket, hitPacket_X0Y0 ) )
690  {
691 
692  // If block is empty then set shades and continue
694  {
695  for( unsigned int y = 0; y < RAYPACKET_DIM; ++y )
696  {
697  const SFVEC3F &outColor = bgColor[y];
698 
699  const unsigned int yBlockPos = blockPos.y + y;
700 
701  for( unsigned int x = 0; x < RAYPACKET_DIM; ++x )
702  {
703  m_postshader_ssao.SetPixelData( blockPos.x + x,
704  yBlockPos,
705  SFVEC3F( 0.0f ),
706  outColor,
707  SFVEC3F( 0.0f ),
708  0,
709  1.0f );
710  }
711  }
712  }
713 
714  // This will set the output color to be displayed
715  // If post processing is enabled, it will not reflect the final result
716  // (as the final color will be computed on post processing)
717  // but it is used for report progress
718 
719  const bool isFinalColor = !m_settings.GetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING );
720 
721  for( unsigned int y = 0; y < RAYPACKET_DIM; ++y )
722  {
723  const SFVEC3F &outColor = bgColor[y];
724 
725  const unsigned int yConst = blockPos.x +
726  ( (y + blockPos.y) * m_realBufferSize.x);
727 
728  for( unsigned int x = 0; x < RAYPACKET_DIM; ++x )
729  {
730  GLubyte *ptr = &ptrPBO[ (yConst + x) * 4 ];
731 
732  rt_final_color( ptr, outColor, isFinalColor );
733  }
734  }
735 
736  // There is nothing more here to do.. there are no hits ..
737  // just background so continue
738  return;
739  }
740 
741 
742  SFVEC3F hitColor_X0Y0[RAYPACKET_RAYS_PER_PACKET];
743 
744  // Shade original (0, 0) hits ("paint" the intersected objects)
745  // /////////////////////////////////////////////////////////////////////////
746  rt_shades_packet( bgColor,
747  blockPacket.m_ray,
748  hitPacket_X0Y0,
750  hitColor_X0Y0 );
751 
753  {
754  SFVEC3F hitColor_AA_X1Y1[RAYPACKET_RAYS_PER_PACKET];
755 
756 
757  // Intersect one blockPosI + (0.5, 0.5) used for anti aliasing calculation
758  // /////////////////////////////////////////////////////////////////////////
759  HITINFO_PACKET hitPacket_AA_X1Y1[RAYPACKET_RAYS_PER_PACKET];
760  HITINFO_PACKET_init( hitPacket_AA_X1Y1 );
761 
762  RAYPACKET blockPacket_AA_X1Y1( m_settings.CameraGet(),
763  (SFVEC2F)blockPosI + SFVEC2F(0.5f, 0.5f),
764  SFVEC2F(DISP_FACTOR, DISP_FACTOR) // Displacement random factor
765  );
766 
767  if( !m_accelerator->Intersect( blockPacket_AA_X1Y1, hitPacket_AA_X1Y1 ) )
768  {
769  // Missed all the package
770  for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y )
771  {
772  const SFVEC3F &outColor = bgColor[y];
773 
774  for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i )
775  {
776  hitColor_AA_X1Y1[i] = outColor;
777  }
778  }
779  }
780  else
781  {
782  rt_shades_packet( bgColor,
783  blockPacket_AA_X1Y1.m_ray,
784  hitPacket_AA_X1Y1,
786  hitColor_AA_X1Y1
787  );
788  }
789 
790  SFVEC3F hitColor_AA_X1Y0[RAYPACKET_RAYS_PER_PACKET];
791  SFVEC3F hitColor_AA_X0Y1[RAYPACKET_RAYS_PER_PACKET];
792  SFVEC3F hitColor_AA_X0Y1_half[RAYPACKET_RAYS_PER_PACKET];
793 
794  for( unsigned int i = 0; i < RAYPACKET_RAYS_PER_PACKET; ++i )
795  {
796  const SFVEC3F color_average = ( hitColor_X0Y0[i] +
797  hitColor_AA_X1Y1[i] ) * SFVEC3F(0.5f);
798 
799  hitColor_AA_X1Y0[i] = color_average;
800  hitColor_AA_X0Y1[i] = color_average;
801  hitColor_AA_X0Y1_half[i] = color_average;
802  }
803 
804  RAY blockRayPck_AA_X1Y0[RAYPACKET_RAYS_PER_PACKET];
805  RAY blockRayPck_AA_X0Y1[RAYPACKET_RAYS_PER_PACKET];
806  RAY blockRayPck_AA_X1Y1_half[RAYPACKET_RAYS_PER_PACKET];
807 
809  (SFVEC2F)blockPosI + SFVEC2F(0.5f - DISP_FACTOR, DISP_FACTOR),
810  SFVEC2F(DISP_FACTOR, DISP_FACTOR), // Displacement random factor
811  blockRayPck_AA_X1Y0 );
812 
814  (SFVEC2F)blockPosI + SFVEC2F(DISP_FACTOR, 0.5f - DISP_FACTOR),
815  SFVEC2F(DISP_FACTOR, DISP_FACTOR), // Displacement random factor
816  blockRayPck_AA_X0Y1 );
817 
819  (SFVEC2F)blockPosI + SFVEC2F(0.25f - DISP_FACTOR, 0.25f - DISP_FACTOR),
820  SFVEC2F(DISP_FACTOR, DISP_FACTOR), // Displacement random factor
821  blockRayPck_AA_X1Y1_half );
822 
823  rt_trace_AA_packet( bgColor,
824  hitPacket_X0Y0, hitPacket_AA_X1Y1,
825  blockRayPck_AA_X1Y0,
826  hitColor_AA_X1Y0 );
827 
828  rt_trace_AA_packet( bgColor,
829  hitPacket_X0Y0, hitPacket_AA_X1Y1,
830  blockRayPck_AA_X0Y1,
831  hitColor_AA_X0Y1 );
832 
833  rt_trace_AA_packet( bgColor,
834  hitPacket_X0Y0, hitPacket_AA_X1Y1,
835  blockRayPck_AA_X1Y1_half,
836  hitColor_AA_X0Y1_half );
837 
838  // Average the result
839  for( unsigned int i = 0; i < RAYPACKET_RAYS_PER_PACKET; ++i )
840  {
841  hitColor_X0Y0[i] = ( hitColor_X0Y0[i] +
842  hitColor_AA_X1Y1[i] +
843  hitColor_AA_X1Y0[i] +
844  hitColor_AA_X0Y1[i] +
845  hitColor_AA_X0Y1_half[i]
846  ) * SFVEC3F(1.0f / 5.0f);
847  }
848  }
849 
850 
851  // Copy results to the next stage
852  // /////////////////////////////////////////////////////////////////////
853 
854  GLubyte *ptr = &ptrPBO[ ( blockPos.x +
855  (blockPos.y * m_realBufferSize.x) ) * 4 ];
856 
857  const uint32_t ptrInc = (m_realBufferSize.x - RAYPACKET_DIM) * 4;
858 
860  {
861  SFVEC2I bPos;
862  bPos.y = blockPos.y;
863 
864  for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y )
865  {
866  bPos.x = blockPos.x;
867 
868  for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i )
869  {
870  const SFVEC3F &hColor = hitColor_X0Y0[i];
871 
872  if( hitPacket_X0Y0[i].m_hitresult == true )
873  m_postshader_ssao.SetPixelData( bPos.x, bPos.y,
874  hitPacket_X0Y0[i].m_HitInfo.m_HitNormal,
875  hColor,
876  blockPacket.m_ray[i].at(
877  hitPacket_X0Y0[i].m_HitInfo.m_tHit ),
878  hitPacket_X0Y0[i].m_HitInfo.m_tHit,
879  hitPacket_X0Y0[i].m_HitInfo.m_ShadowFactor );
880  else
881  m_postshader_ssao.SetPixelData( bPos.x, bPos.y,
882  SFVEC3F( 0.0f ),
883  hColor,
884  SFVEC3F( 0.0f ),
885  0,
886  1.0f );
887 
888  rt_final_color( ptr, hColor, false );
889 
890  bPos.x++;
891  ptr += 4;
892  }
893 
894  ptr += ptrInc;
895  bPos.y++;
896  }
897  }
898  else
899  {
900  for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y )
901  {
902  for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i )
903  {
904  rt_final_color( ptr, hitColor_X0Y0[i], true );
905  ptr += 4;
906  }
907 
908  ptr += ptrInc;
909  }
910  }
911 }
#define RAYPACKET_DIM
Definition: raypacket.h:37
void rt_shades_packet(const SFVEC3F *bgColorY, const RAY *aRayPkt, HITINFO_PACKET *aHitPacket, bool is_testShadow, SFVEC3F *aOutHitColor)
void rt_final_color(GLubyte *ptrPBO, const SFVEC3F &rgbColor, bool applyColorSpaceConversion)
CPOSTSHADER_SSAO m_postshader_ssao
Definition: ray.h:43
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:42
CINFO3D_VISU & m_settings
settings refrence in use for this render
glm::uvec2 SFVEC2UI
Definition: xv3d_types.h:41
CGENERICACCELERATOR * m_accelerator
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
virtual bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const =0
wxSize m_windowSize
The window size that this camera is working.
void rt_trace_AA_packet(const SFVEC3F *aBgColorY, const HITINFO_PACKET *aHitPck_X0Y0, const HITINFO_PACKET *aHitPck_AA_X1Y1, const RAY *aRayPck, SFVEC3F *aOutHitColor)
static void HITINFO_PACKET_init(HITINFO_PACKET *aHitPacket)
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
void SetPixelData(unsigned int x, unsigned int y, const SFVEC3F &aNormal, const SFVEC3F &aColor, const SFVEC3F &aHitPosition, float aDepth, float aShadowAttFactor)
Definition: cpostshader.cpp:78
#define RAYPACKET_RAYS_PER_PACKET
Definition: raypacket.h:40
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
#define DISP_FACTOR
std::vector< SFVEC2UI > m_blockPositions
this encodes the Morton code positions
size_t i
Definition: json11.cpp:597
void RAYPACKET_InitRays_with2DDisplacement(const CCAMERA &aCamera, const SFVEC2F &aWindowsPosition, const SFVEC2F &a2DWindowsPosDisplacementFactor, RAY *aRayPck)
Definition: raypacket.cpp:174
void C3D_RENDER_RAYTRACING::rt_render_tracing ( GLubyte *  ptrPBO,
REPORTER aStatusTextReporter 
)
private

Definition at line 362 of file c3d_render_raytracing.cpp.

References FL_RENDER_RAYTRACING_POST_PROCESSING, Format(), CINFO3D_VISU::GetFlag(), m_blockPositions, m_blockPositionsWasProcessed, m_isPreview, m_nrBlocksRenderProgress, m_rt_render_state, C3D_RENDER_BASE::m_settings, REPORTER::Report(), RT_RENDER_STATE_FINISH, RT_RENDER_STATE_POST_PROCESS_SHADE, and rt_render_trace_block().

Referenced by render().

364 {
365  m_isPreview = false;
366 
367  auto startTime = std::chrono::steady_clock::now();
368  bool breakLoop = false;
369 
370  std::atomic<size_t> numBlocksRendered( 0 );
371  std::atomic<size_t> currentBlock( 0 );
372  std::atomic<size_t> threadsFinished( 0 );
373 
374  size_t parallelThreadCount = std::min<size_t>(
375  std::max<size_t>( std::thread::hardware_concurrency(), 2 ),
376  m_blockPositions.size() );
377  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
378  {
379  std::thread t = std::thread( [&]()
380  {
381  for( size_t iBlock = currentBlock.fetch_add( 1 );
382  iBlock < m_blockPositions.size() && !breakLoop;
383  iBlock = currentBlock.fetch_add( 1 ) )
384  {
385  if( !m_blockPositionsWasProcessed[iBlock] )
386  {
387  rt_render_trace_block( ptrPBO, iBlock );
388  numBlocksRendered++;
389  m_blockPositionsWasProcessed[iBlock] = 1;
390 
391  // Check if it spend already some time render and request to exit
392  // to display the progress
393  if( std::chrono::duration_cast<std::chrono::milliseconds>(
394  std::chrono::steady_clock::now() - startTime ).count() > 150 )
395  breakLoop = true;
396  }
397  }
398 
399  threadsFinished++;
400  } );
401 
402  t.detach();
403  }
404 
405  while( threadsFinished < parallelThreadCount )
406  std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
407 
408  m_nrBlocksRenderProgress += numBlocksRendered;
409 
410  if( aStatusTextReporter )
411  aStatusTextReporter->Report( wxString::Format( _( "Rendering: %.0f %%" ),
412  (float)(m_nrBlocksRenderProgress * 100) /
413  (float)m_blockPositions.size() ) );
414 
415  // Check if it finish the rendering and if should continue to a post processing
416  // or mark it as finished
418  {
421  else
422  {
424  }
425  }
426 }
std::vector< int > m_blockPositionsWasProcessed
this flags if a position was already processed (cleared each new render)
CINFO3D_VISU & m_settings
settings refrence in use for this render
size_t m_nrBlocksRenderProgress
Save the number of blocks progress of the render.
RT_RENDER_STATE m_rt_render_state
State used on quality render.
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
std::vector< SFVEC2UI > m_blockPositions
this encodes the Morton code positions
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
void rt_render_trace_block(GLubyte *ptrPBO, signed int iBlock)
void C3D_RENDER_RAYTRACING::rt_shades_packet ( const SFVEC3F bgColorY,
const RAY aRayPkt,
HITINFO_PACKET aHitPacket,
bool  is_testShadow,
SFVEC3F aOutHitColor 
)
private

Definition at line 502 of file c3d_render_raytracing.cpp.

References i, RAYPACKET_DIM, and shadeHit().

Referenced by rt_render_trace_block().

507 {
508  for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y )
509  {
510  for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i )
511  {
512  if( aHitPacket[i].m_hitresult == true )
513  {
514  aOutHitColor[i] = shadeHit( bgColorY[y],
515  aRayPkt[i],
516  aHitPacket[i].m_HitInfo,
517  false,
518  0,
519  is_testShadow );
520  }
521  else
522  {
523  aOutHitColor[i] = bgColorY[y];
524  }
525  }
526  }
527 }
#define RAYPACKET_DIM
Definition: raypacket.h:37
SFVEC3F shadeHit(const SFVEC3F &aBgColor, const RAY &aRay, HITINFO &aHitInfo, bool aIsInsideObject, unsigned int aRecursiveLevel, bool is_testShadow) const
size_t i
Definition: json11.cpp:597
void C3D_RENDER_RAYTRACING::rt_trace_AA_packet ( const SFVEC3F aBgColorY,
const HITINFO_PACKET aHitPck_X0Y0,
const HITINFO_PACKET aHitPck_AA_X1Y1,
const RAY aRayPck,
SFVEC3F aOutHitColor 
)
private

Definition at line 530 of file c3d_render_raytracing.cpp.

References FL_RENDER_RAYTRACING_SHADOWS, CINFO3D_VISU::GetFlag(), i, CGENERICACCELERATOR::Intersect(), HITINFO::m_acc_node_info, m_accelerator, HITINFO_PACKET::m_HitInfo, C3D_RENDER_BASE::m_settings, HITINFO::m_tHit, RAYPACKET_DIM, and shadeHit().

Referenced by rt_render_trace_block().

535 {
536  const bool is_testShadow = m_settings.GetFlag( FL_RENDER_RAYTRACING_SHADOWS );
537 
538  for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y )
539  {
540  for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i )
541  {
542  const RAY &rayAA = aRayPck[i];
543 
544  HITINFO hitAA;
545  hitAA.m_tHit = std::numeric_limits<float>::infinity();
546  hitAA.m_acc_node_info = 0;
547 
548  bool hitted = false;
549 
550  const unsigned int idx0y1 = ( x + 0 ) + RAYPACKET_DIM * ( y + 1 );
551  const unsigned int idx1y1 = ( x + 1 ) + RAYPACKET_DIM * ( y + 1 );
552 
553  // Gets the node info from the hit.
554  const unsigned int nodex0y0 = aHitPck_X0Y0[ i ].m_HitInfo.m_acc_node_info;
555  const unsigned int node_AA_x0y0 = aHitPck_AA_X1Y1[ i ].m_HitInfo.m_acc_node_info;
556 
557  unsigned int nodex1y0 = 0;
558 
559  if( x < (RAYPACKET_DIM - 1) )
560  nodex1y0 = aHitPck_X0Y0[ i + 1 ].m_HitInfo.m_acc_node_info;
561 
562  unsigned int nodex0y1 = 0;
563 
564  if( y < (RAYPACKET_DIM - 1) )
565  nodex0y1 = aHitPck_X0Y0[ idx0y1 ].m_HitInfo.m_acc_node_info;
566 
567  unsigned int nodex1y1 = 0;
568 
569  if( ((x < (RAYPACKET_DIM - 1)) &&
570  (y < (RAYPACKET_DIM - 1))) )
571  nodex1y1 = aHitPck_X0Y0[ idx1y1 ].m_HitInfo.m_acc_node_info;
572 
573 
574  if( ((nodex0y0 == nodex1y0) || (nodex1y0 == 0)) && // If all notes are equal we assume there was no change on the object hits
575  ((nodex0y0 == nodex0y1) || (nodex0y1 == 0)) &&
576  ((nodex0y0 == nodex1y1) || (nodex1y1 == 0)) &&
577  (nodex0y0 == node_AA_x0y0) )
578  {
579  // Option 1
580  // This option will give a very good quality on reflections (slow)
581  /*
582  if( m_accelerator->Intersect( rayAA, hitAA, nodex0y0 ) )
583  {
584  aOutHitColor[i] += shadeHit( aBgColorY[y], rayAA, hitAA, false, 0 );
585  }
586  else
587  {
588  if( m_accelerator->Intersect( rayAA, hitAA ) )
589  aOutHitColor[i] += shadeHit( aBgColorY[y], rayAA, hitAA, false, 0 );
590  else
591  aOutHitColor[i] += hitColor[i];
592  }
593  */
594 
595  // Option 2
596  // Trace again with the same node,
597  // then if miss just give the same color as before
598  //if( m_accelerator->Intersect( rayAA, hitAA, nodex0y0 ) )
599  // aOutHitColor[i] += shadeHit( aBgColorY[y], rayAA, hitAA, false, 0 );
600 
601  // Option 3
602  // Use same color
603 
604  }
605  else
606  {
607  // Try to intersect the different nodes
608  // It tests the possible combination of hitted or not hitted points
609  // This will try to get the best hit for this ray
610 
611  if( nodex0y0 != 0 )
612  hitted |= m_accelerator->Intersect( rayAA, hitAA, nodex0y0 );
613 
614  if( ( nodex1y0 != 0 ) &&
615  ( nodex0y0 != nodex1y0 ) )
616  hitted |= m_accelerator->Intersect( rayAA, hitAA, nodex1y0 );
617 
618  if( ( nodex0y1 != 0 ) &&
619  ( nodex0y0 != nodex0y1 ) &&
620  ( nodex1y0 != nodex0y1 ) )
621  hitted |= m_accelerator->Intersect( rayAA, hitAA, nodex0y1 );
622 
623  if( (nodex1y1 != 0 ) &&
624  ( nodex0y0 != nodex1y1 ) &&
625  ( nodex0y1 != nodex1y1 ) &&
626  ( nodex1y0 != nodex1y1 ) )
627  hitted |= m_accelerator->Intersect( rayAA, hitAA, nodex1y1 );
628 
629  if( (node_AA_x0y0 != 0 ) &&
630  ( nodex0y0 != node_AA_x0y0 ) &&
631  ( nodex0y1 != node_AA_x0y0 ) &&
632  ( nodex1y0 != node_AA_x0y0 ) &&
633  ( nodex1y1 != node_AA_x0y0 ) )
634  hitted |= m_accelerator->Intersect( rayAA, hitAA, node_AA_x0y0 );
635 
636  if( hitted )
637  {
638  // If we got any result, shade it
639  aOutHitColor[i] = shadeHit( aBgColorY[y], rayAA, hitAA, false, 0, is_testShadow );
640  }
641  else
642  {
643  // Note: There are very few cases that will end on this situation
644  // so it is not so expensive to trace a single ray from the beginning
645 
646  // It was missed the 'last nodes' so, trace a ray from the beginning
647  if( m_accelerator->Intersect( rayAA, hitAA ) )
648  aOutHitColor[i] = shadeHit( aBgColorY[y], rayAA, hitAA, false, 0, is_testShadow );
649  }
650  }
651  }
652  }
653 }
#define RAYPACKET_DIM
Definition: raypacket.h:37
SFVEC3F shadeHit(const SFVEC3F &aBgColor, const RAY &aRay, HITINFO &aHitInfo, bool aIsInsideObject, unsigned int aRecursiveLevel, bool is_testShadow) const
Definition: ray.h:43
CINFO3D_VISU & m_settings
settings refrence in use for this render
float m_tHit
( 4) distance
Definition: hitinfo.h:43
CGENERICACCELERATOR * m_accelerator
virtual bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const =0
HITINFO m_HitInfo
Definition: hitinfo.h:63
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:40
unsigned int m_acc_node_info
( 4) The acc stores here the node that it hits
Definition: hitinfo.h:47
size_t i
Definition: json11.cpp:597
void C3D_RENDER_RAYTRACING::SetCurWindowSize ( const wxSize &  aSize)
overridevirtual

SetCurWindowSize - Before each render, the canvas will tell the render what is the size of its windows, so render can take actions if it changed.

Parameters
aSizethe current size of the render window

Implements C3D_RENDER_BASE.

Definition at line 113 of file c3d_render_raytracing.cpp.

References initializeNewWindowSize(), and C3D_RENDER_BASE::m_windowSize.

114 {
115  if( m_windowSize != aSize )
116  {
117  m_windowSize = aSize;
118  glViewport( 0, 0, m_windowSize.x, m_windowSize.y );
119 
121  }
122 }
wxSize m_windowSize
The window size that this camera is working.
void C3D_RENDER_RAYTRACING::setupMaterials ( )
private

Definition at line 56 of file c3d_render_createscene.cpp.

References CINFO3D_VISU::BiuTo3Dunits(), ConvertSRGBToLinear(), FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES, CINFO3D_VISU::GetFlag(), CINFO3D_VISU::m_BgColorTop, m_board_normal_perturbator, m_brushed_metal_normal_perturbator, m_copper_normal_perturbator, CINFO3D_VISU::m_CopperColor, m_materials, m_plastic_normal_perturbator, m_plastic_shine_normal_perturbator, C3D_RENDER_BASE::m_settings, CINFO3D_VISU::m_SilkScreenColor, m_solder_mask_normal_perturbator, CINFO3D_VISU::m_SolderMaskColor, and CINFO3D_VISU::m_SolderPasteColor.

Referenced by reload().

57 {
58 
60  {
62 
65 
67 
69 
71 
73  }
74 
75  // http://devernay.free.fr/cours/opengl/materials.html
76 
77  // Copper
80  (SFVEC3F)(0.18f), // ambient
81  SFVEC3F( 0.0f, 0.0f, 0.0f ), // emissive
82  glm::clamp( ((SFVEC3F)(1.0f) -
84  SFVEC3F( 0.0f ),
85  SFVEC3F( 0.35f ) ), // specular
86  0.4f * 128.0f, // shiness
87  0.0f, // transparency
88  0.0f );
89 
91  m_materials.m_Copper.SetNormalPerturbator( &m_copper_normal_perturbator );
92 
96  SFVEC3F( 0.0f, 0.0f, 0.0f ), // emissive
99  0.10f * 128.0f, // shiness
100  0.0f, // transparency
101  0.0f );
102 
104  ConvertSRGBToLinear( SFVEC3F( 0.11f ) ),// ambient
105  SFVEC3F( 0.0f, 0.0f, 0.0f ), // emissive
106  glm::clamp( ((SFVEC3F)(1.0f) -
108  SFVEC3F( 0.0f ),
109  SFVEC3F( 0.10f ) ), // specular
110  0.078125f * 128.0f, // shiness
111  0.0f, // transparency
112  0.0f );
113 
114  const float solderMask_gray = ( m_settings.m_SolderMaskColor.r +
116  m_settings.m_SolderMaskColor.b ) / 3.0f;
117 
118  const float solderMask_transparency = solderMask_gray * 0.40f + 0.005f;
119 
120  m_materials.m_SolderMask = CBLINN_PHONG_MATERIAL(
122  0.10f, // ambient
123  SFVEC3F( 0.0f, 0.0f, 0.0f ), // emissive
124  glm::clamp( ( (SFVEC3F)( 1.0f ) -
126  SFVEC3F( 0.0f ),
127  SFVEC3F( solderMask_gray * 2.0f ) ), // specular
128  0.85f * 128.0f, // shiness
129  solderMask_transparency, // transparency
130  0.16f ); // reflection
131 
132  m_materials.m_SolderMask.SetCastShadows( true );
133  m_materials.m_SolderMask.SetNrRefractionsSamples( 1 );
134  m_materials.m_SolderMask.SetNrReflectionsSamples( 2 );
135 
137  m_materials.m_SolderMask.SetNormalPerturbator( &m_solder_mask_normal_perturbator );
138 
139  m_materials.m_EpoxyBoard = CBLINN_PHONG_MATERIAL(
140  ConvertSRGBToLinear( SFVEC3F( 16.0f / 255.0f,
141  14.0f / 255.0f,
142  10.0f / 255.0f ) ), // ambient
143  SFVEC3F( 0.0f, 0.0f, 0.0f ), // emissive
144  ConvertSRGBToLinear( SFVEC3F( 10.0f / 255.0f,
145  8.0f / 255.0f,
146  10.0f / 255.0f ) ), // specular
147  0.1f * 128.0f, // shiness
148  0.10f, // transparency
149  0.0f ); // reflection
150 
151  m_materials.m_EpoxyBoard.SetAbsorvance( 10.0f );
152  m_materials.m_EpoxyBoard.SetNrRefractionsSamples( 3 );
153 
155  m_materials.m_EpoxyBoard.SetNormalPerturbator( &m_board_normal_perturbator );
156 
158  //SFVEC3F bgBot = (SFVEC3F)m_settings.m_BgColorBot;
159 
161  bgTop * 0.125f, // ambient
162  SFVEC3F( 0.0f, 0.0f, 0.0f ), // emissive
163  (SFVEC3F(1.0f) - bgTop) / 3.0f, // specular
164  0.10f * 128.0f, // shiness
165  0.0f, // transparency
166  0.50f ); // reflection
167 }
struct C3D_RENDER_RAYTRACING::@37 m_materials
CPLASTICNORMAL m_plastic_normal_perturbator
SFVEC3F ConvertSRGBToLinear(const SFVEC3F &aSRGBcolor)
CBOARDNORMAL m_board_normal_perturbator
SFVEC3D m_CopperColor
in realistic mode: copper color
Definition: cinfo3d_visu.h:509
CCOPPERNORMAL m_copper_normal_perturbator
CPLASTICSHINENORMAL m_plastic_shine_normal_perturbator
CMETALBRUSHEDNORMAL m_brushed_metal_normal_perturbator
CINFO3D_VISU & m_settings
settings refrence in use for this render
SFVEC3D m_BgColorTop
background top color
Definition: cinfo3d_visu.h:504
Blinn Phong based material https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model.
Definition: cmaterial.h:248
SFVEC3D m_SolderPasteColor
in realistic mode: solder paste color
Definition: cinfo3d_visu.h:507
SFVEC3D m_SolderMaskColor
in realistic mode: solder mask color
Definition: cinfo3d_visu.h:506
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
SFVEC3D m_SilkScreenColor
in realistic mode: SilkScreen color
Definition: cinfo3d_visu.h:508
CSOLDERMASKNORMAL m_solder_mask_normal_perturbator
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
double BiuTo3Dunits() const
BiuTo3Dunits - Board integer units To 3D units.
Definition: cinfo3d_visu.h:141
SFVEC3F C3D_RENDER_RAYTRACING::shadeHit ( const SFVEC3F aBgColor,
const RAY aRay,
HITINFO aHitInfo,
bool  aIsInsideObject,
unsigned int  aRecursiveLevel,
bool  is_testShadow 
) const
private

Definition at line 1716 of file c3d_render_raytracing.cpp.

References RAY::at(), FL_RENDER_RAYTRACING_ANTI_ALIASING, FL_RENDER_RAYTRACING_POST_PROCESSING, FL_RENDER_RAYTRACING_REFLECTIONS, FL_RENDER_RAYTRACING_REFRACTIONS, CMATERIAL::GetAbsorvance(), CMATERIAL::GetAmbientColor(), CLIGHT::GetCastShadows(), COBJECT::GetDiffuseColor(), CMATERIAL::GetEmissiveColor(), CINFO3D_VISU::GetFlag(), CLIGHT::GetLightParameters(), CLIGHTCONTAINER::GetList(), COBJECT::GetMaterial(), CINFO3D_VISU::GetNonCopperLayerThickness3DU(), CMATERIAL::GetNrReflectionsSamples(), CMATERIAL::GetNrRefractionsSamples(), CMATERIAL::GetReflection(), CMATERIAL::GetSpecularColor(), CMATERIAL::GetTransparency(), i, RAY::Init(), CGENERICACCELERATOR::Intersect(), CGENERICACCELERATOR::IntersectP(), m_accelerator, RAY::m_Dir, HITINFO::m_HitNormal, HITINFO::m_HitPoint, m_isPreview, m_lights, C3D_RENDER_BASE::m_settings, HITINFO::m_ShadowFactor, HITINFO::m_tHit, max, min, NextFloatUp(), HITINFO::pHitObject, Refract(), CMATERIAL::Shade(), and UniformRandomHemisphereDirection().

Referenced by render_preview(), rt_shades_packet(), and rt_trace_AA_packet().

1722 {
1723  if( aRecursiveLevel > 2 )
1724  return SFVEC3F( 0.0f );
1725 
1726  SFVEC3F hitPoint = aHitInfo.m_HitPoint;
1727 
1728  if( !m_isPreview )
1729  hitPoint += aHitInfo.m_HitNormal * m_settings.GetNonCopperLayerThickness3DU() * 1.0f;
1730 
1731  const CMATERIAL *objMaterial = aHitInfo.pHitObject->GetMaterial();
1732  wxASSERT( objMaterial != NULL );
1733 
1734  const SFVEC3F diffuseColorObj = aHitInfo.pHitObject->GetDiffuseColor( aHitInfo );
1735 
1736  SFVEC3F outColor = objMaterial->GetEmissiveColor();
1737 
1738  const LIST_LIGHT &lightList = m_lights.GetList();
1739 
1740 #if USE_EXPERIMENTAL_SOFT_SHADOWS
1741  const bool is_aa_enabled = m_settings.GetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING ) &&
1742  (!m_isPreview);
1743 #endif
1744 
1745  float shadow_att_factor_sum = 0.0f;
1746 
1747  unsigned int nr_lights_that_can_cast_shadows = 0;
1748 
1749  for( LIST_LIGHT::const_iterator ii = lightList.begin();
1750  ii != lightList.end();
1751  ++ii )
1752  {
1753  const CLIGHT *light = (CLIGHT *)*ii;
1754 
1755  SFVEC3F vectorToLight;
1756  SFVEC3F colorOfLight;
1757  float distToLight;
1758 
1759  light->GetLightParameters( hitPoint, vectorToLight, colorOfLight, distToLight );
1760 
1761  if( m_isPreview )
1762  colorOfLight = SFVEC3F( 1.0f );
1763 
1764  /*
1765  if( (!m_isPreview) &&
1766  // Little hack to make randomness to the shading and shadows
1767  m_settings.GetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING ) )
1768  vectorToLight = glm::normalize( vectorToLight +
1769  UniformRandomHemisphereDirection() * 0.1f );
1770  */
1771 
1772  const float NdotL = glm::dot( aHitInfo.m_HitNormal, vectorToLight );
1773 
1774  // Only calc shade if the normal is facing the direction of light,
1775  // otherwise it is in the shadow
1776  if( NdotL >= FLT_EPSILON )
1777  {
1778  float shadow_att_factor_light = 1.0f;
1779 
1780  if( is_testShadow && light->GetCastShadows() )
1781  {
1782  nr_lights_that_can_cast_shadows++;
1783 #if USE_EXPERIMENTAL_SOFT_SHADOWS
1784  if( (!is_aa_enabled) ||
1785 
1786  // For rays that are recursive, just calculate one hit shadow
1787  (aRecursiveLevel > 0) ||
1788 
1789  // Only use soft shadows if using post processing
1791  )
1792  {
1793 #endif
1794  RAY rayToLight;
1795  rayToLight.Init( hitPoint, vectorToLight );
1796 
1797  // Test if point is not in the shadow.
1798  // Test for any hit from the point in the direction of light
1799  if( m_accelerator->IntersectP( rayToLight, distToLight ) )
1800  shadow_att_factor_light = 0.0f;
1801 
1802 #if USE_EXPERIMENTAL_SOFT_SHADOWS
1803  }
1804 
1805  // Experimental softshadow calculation
1806  else
1807  {
1808 
1809  const unsigned int shadow_number_of_samples = 3;
1810  const float shadow_inc_factor = 1.0f / (float)(shadow_number_of_samples);
1811 
1812  for( unsigned int i = 0; i < shadow_number_of_samples; ++i )
1813  {
1814  const SFVEC3F unifVector = UniformRandomHemisphereDirection();
1815  const SFVEC3F disturbed_vector_to_light = glm::normalize( vectorToLight +
1816  unifVector *
1817  0.05f );
1818 
1819  RAY rayToLight;
1820  rayToLight.Init( hitPoint, disturbed_vector_to_light );
1821 
1822  // !TODO: there are multiple ways that this tests can be
1823  // optimized. Eg: by packing rays or to test against the
1824  // latest hit object.
1825 
1826  if( m_accelerator->IntersectP( rayToLight, distToLight ) )
1827  {
1828  shadow_att_factor_light -= shadow_inc_factor;
1829  }
1830  }
1831  }
1832 #endif
1833  shadow_att_factor_sum += shadow_att_factor_light;
1834  }
1835 
1837  {
1838  outColor += objMaterial->Shade( aRay,
1839  aHitInfo,
1840  NdotL,
1841  diffuseColorObj,
1842  vectorToLight,
1843  colorOfLight,
1844  shadow_att_factor_light );
1845  }
1846  else
1847  {
1848  // This is a render hack in order to compensate for the lack of
1849  // ambient and too much darkness when using post process shader
1850  // It will calculate as it was not in shadow
1851  outColor += objMaterial->Shade( aRay,
1852  aHitInfo,
1853  NdotL,
1854  diffuseColorObj,
1855  vectorToLight,
1856  colorOfLight,
1857  // The sampled point will be darkshaded by the post
1858  // processing, so here it compensates to not shadow
1859  // so much
1860  glm::min( shadow_att_factor_light + (3.0f / 6.0f), 1.0f )
1861  );
1862  }
1863  }
1864  else
1865  {
1866  outColor += objMaterial->GetAmbientColor();
1867  }
1868 
1869  // Only use the headlight for preview
1870  if( m_isPreview )
1871  break;
1872  }
1873 
1874  // Improvement: this is not taking in account the lightcolor
1875  if( nr_lights_that_can_cast_shadows > 0 )
1876  {
1877  aHitInfo.m_ShadowFactor = glm::max( shadow_att_factor_sum /
1878  (float)(nr_lights_that_can_cast_shadows * 1.0f), 0.0f );
1879  }
1880  else
1881  {
1882  aHitInfo.m_ShadowFactor = 1.0f;
1883  }
1884 
1885  // Clamp color to not be brighter than 1.0f
1886  outColor = glm::min( outColor, SFVEC3F( 1.0f ) );
1887 
1888  if( !m_isPreview )
1889  {
1890  // Reflections
1891  // /////////////////////////////////////////////////////////////////////
1892 
1893  if( !aIsInsideObject &&
1894  (objMaterial->GetReflection() > 0.0f) &&
1896  {
1897  const unsigned int reflection_number_of_samples = objMaterial->GetNrReflectionsSamples();
1898 
1899  SFVEC3F sum_color = SFVEC3F(0.0f);
1900 
1901  const SFVEC3F reflectVector = aRay.m_Dir -
1902  2.0f * glm::dot( aRay.m_Dir, aHitInfo.m_HitNormal ) *
1903  aHitInfo.m_HitNormal;
1904 
1905  for( unsigned int i = 0; i < reflection_number_of_samples; ++i )
1906  {
1907  // Apply some randomize to the reflected vector
1908  const SFVEC3F random_reflectVector =
1909  glm::normalize( reflectVector +
1911  0.025f );
1912 
1913  RAY reflectedRay;
1914  reflectedRay.Init( hitPoint, random_reflectVector );
1915 
1916  HITINFO reflectedHit;
1917  reflectedHit.m_tHit = std::numeric_limits<float>::infinity();
1918 
1919  if( m_accelerator->Intersect( reflectedRay, reflectedHit ) )
1920  {
1921  sum_color += ( diffuseColorObj + objMaterial->GetSpecularColor() ) *
1922  shadeHit( aBgColor,
1923  reflectedRay,
1924  reflectedHit,
1925  false,
1926  aRecursiveLevel + 1,
1927  is_testShadow ) *
1928  SFVEC3F( objMaterial->GetReflection() *
1929  // Falloff factor
1930  (1.0f / ( 1.0f + 0.75f * reflectedHit.m_tHit *
1931  reflectedHit.m_tHit) ) );
1932  }
1933  }
1934 
1935  outColor += (sum_color / SFVEC3F( (float)reflection_number_of_samples) );
1936  }
1937 
1938 
1939  // Refractions
1940  // /////////////////////////////////////////////////////////////////////
1941 
1942  if( (objMaterial->GetTransparency() > 0.0f) &&
1944  {
1945  const float airIndex = 1.000293f;
1946  const float glassIndex = 1.49f;
1947  const float air_over_glass = airIndex / glassIndex;
1948  const float glass_over_air = glassIndex / airIndex;
1949 
1950  const float refractionRatio = aIsInsideObject?glass_over_air:air_over_glass;
1951 
1952  SFVEC3F refractedVector;
1953 
1954  if( Refract( aRay.m_Dir,
1955  aHitInfo.m_HitNormal,
1956  refractionRatio,
1957  refractedVector ) )
1958  {
1959  const float objTransparency = objMaterial->GetTransparency();
1960 
1961  // This increase the start point by a "fixed" factor so it will work the
1962  // same for all distances
1963  const SFVEC3F startPoint = aRay.at( NextFloatUp(
1964  NextFloatUp(
1965  NextFloatUp( aHitInfo.m_tHit ) ) ) );
1966 
1967  const unsigned int refractions_number_of_samples = objMaterial->GetNrRefractionsSamples();
1968 
1969  SFVEC3F sum_color = SFVEC3F(0.0f);
1970 
1971  for( unsigned int i = 0; i < refractions_number_of_samples; ++i )
1972  {
1973  RAY refractedRay;
1974 
1975  if( refractions_number_of_samples > 1 )
1976  {
1977  // apply some randomize to the refracted vector
1978  const SFVEC3F randomizeRefractedVector = glm::normalize( refractedVector +
1980  0.15f *
1981  (1.0f - objTransparency) );
1982 
1983  refractedRay.Init( startPoint, randomizeRefractedVector );
1984  }
1985  else
1986  {
1987  refractedRay.Init( startPoint, refractedVector );
1988  }
1989 
1990  HITINFO refractedHit;
1991  refractedHit.m_tHit = std::numeric_limits<float>::infinity();
1992 
1993  SFVEC3F refractedColor = objMaterial->GetAmbientColor();
1994 
1995  if( m_accelerator->Intersect( refractedRay, refractedHit ) )
1996  {
1997  refractedColor = shadeHit( aBgColor,
1998  refractedRay,
1999  refractedHit,
2000  true,
2001  aRecursiveLevel + 1,
2002  false );
2003 
2004  const SFVEC3F absorbance = ( SFVEC3F(1.0f) - diffuseColorObj ) *
2005  (1.0f - objTransparency ) *
2006  objMaterial->GetAbsorvance() * // Adjust falloff factor
2007  -refractedHit.m_tHit;
2008 
2009  const SFVEC3F transparency = SFVEC3F( expf( absorbance.r ),
2010  expf( absorbance.g ),
2011  expf( absorbance.b ) );
2012 
2013  sum_color += refractedColor * transparency * objTransparency;
2014  }
2015  else
2016  {
2017  sum_color += refractedColor * objTransparency;
2018  }
2019  }
2020 
2021  outColor = outColor * (1.0f - objTransparency) +
2022  (sum_color / SFVEC3F( (float)refractions_number_of_samples) );
2023  }
2024  }
2025  }
2026 
2027  //outColor += glm::max( -glm::dot( aHitInfo.m_HitNormal, aRay.m_Dir ), 0.0f ) *
2028  // objMaterial->GetAmbientColor();
2029 
2030  return outColor;
2031 }
float m_ShadowFactor
( 4) Shadow attenuation (1.0 no shadow, 0.0f darkness)
Definition: hitinfo.h:50
float GetTransparency() const
Definition: cmaterial.h:183
const LIST_LIGHT & GetList() const
GetList - get light list of this container.
Definition: clight.h:196
const SFVEC3F & GetAmbientColor() const
Definition: cmaterial.h:178
SFVEC3F shadeHit(const SFVEC3F &aBgColor, const RAY &aRay, HITINFO &aHitInfo, bool aIsInsideObject, unsigned int aRecursiveLevel, bool is_testShadow) const
A base material class that can be used to derive a material implementation.
Definition: cmaterial.h:167
void Init(const SFVEC3F &o, const SFVEC3F &d)
Definition: ray.cpp:40
virtual bool IntersectP(const RAY &aRay, float aMaxDistance) const =0
float GetAbsorvance() const
Definition: cmaterial.h:185
float GetNonCopperLayerThickness3DU() const
GetNonCopperLayerThickness3DU - Get the current non copper layers thickness.
Definition: cinfo3d_visu.h:159
SFVEC3F at(float t) const
Definition: ray.h:65
const CMATERIAL * GetMaterial() const
Definition: cobject.h:63
const SFVEC3F & GetSpecularColor() const
Definition: cmaterial.h:180
Definition: ray.h:43
CINFO3D_VISU & m_settings
settings refrence in use for this render
float m_tHit
( 4) distance
Definition: hitinfo.h:43
bool Refract(const SFVEC3F &aInVector, const SFVEC3F &aNormal, float aRin_over_Rout, SFVEC3F &aOutVector)
Refract Based on: https://github.com/mmp/pbrt-v3/blob/master/src/core/reflection.h See also: http://w...
Definition: 3d_math.h:113
virtual SFVEC3F Shade(const RAY &aRay, const HITINFO &aHitInfo, float NdotL, const SFVEC3F &aDiffuseObjColor, const SFVEC3F &aDirToLight, const SFVEC3F &aLightColor, float aShadowAttenuationFactor) const =0
Shade - Shades an intersection point.
SFVEC3F m_HitPoint
(12) hit position
Definition: hitinfo.h:49
CGENERICACCELERATOR * m_accelerator
unsigned int GetNrReflectionsSamples() const
Definition: cmaterial.h:187
virtual bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const =0
unsigned int GetNrRefractionsSamples() const
Definition: cmaterial.h:186
const COBJECT * pHitObject
( 4) Object that was hitted
Definition: hitinfo.h:45
A base light class to derive to implement other light classes.
Definition: clight.h:37
SFVEC3F m_Dir
Definition: ray.h:48
SFVEC3F UniformRandomHemisphereDirection()
Definition: 3d_math.h:54
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
bool GetCastShadows() const
Definition: clight.h:58
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:40
#define max(a, b)
Definition: auxiliary.h:86
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
float NextFloatUp(float v)
Definition: 3d_fastmath.h:136
size_t i
Definition: json11.cpp:597
virtual void GetLightParameters(const SFVEC3F &aHitPoint, SFVEC3F &aOutVectorToLight, SFVEC3F &aOutLightColor, float &aOutDistance) const =0
GetLightParameters - Get parameters from this light.
SFVEC3F m_HitNormal
(12) normal at the hit point
Definition: hitinfo.h:42
std::list< CLIGHT * > LIST_LIGHT
Definition: clight.h:151
const SFVEC3F & GetEmissiveColor() const
Definition: cmaterial.h:179
virtual SFVEC3F GetDiffuseColor(const HITINFO &aHitInfo) const =0
float GetReflection() const
Definition: cmaterial.h:184
#define min(a, b)
Definition: auxiliary.h:85

Member Data Documentation

SFVEC3F C3D_RENDER_RAYTRACING::m_BgColorBot_LinearRGB
private

Definition at line 157 of file c3d_render_raytracing.h.

Referenced by render(), and rt_render_trace_block().

SFVEC3F C3D_RENDER_RAYTRACING::m_BgColorTop_LinearRGB
private

Definition at line 156 of file c3d_render_raytracing.h.

Referenced by render(), and rt_render_trace_block().

std::vector< SFVEC2UI > C3D_RENDER_RAYTRACING::m_blockPositions
private

this encodes the Morton code positions

Definition at line 165 of file c3d_render_raytracing.h.

Referenced by initialize_block_positions(), render_preview(), restart_render_state(), rt_render_trace_block(), and rt_render_tracing().

std::vector< SFVEC2UI > C3D_RENDER_RAYTRACING::m_blockPositionsFast
private

this encodes the Morton code positions (on fast preview mode)

Definition at line 171 of file c3d_render_raytracing.h.

Referenced by initialize_block_positions(), and render_preview().

std::vector< int > C3D_RENDER_RAYTRACING::m_blockPositionsWasProcessed
private

this flags if a position was already processed (cleared each new render)

Definition at line 168 of file c3d_render_raytracing.h.

Referenced by restart_render_state(), and rt_render_tracing().

CBOARDNORMAL C3D_RENDER_RAYTRACING::m_board_normal_perturbator
private

Definition at line 111 of file c3d_render_raytracing.h.

Referenced by setupMaterials().

CMETALBRUSHEDNORMAL C3D_RENDER_RAYTRACING::m_brushed_metal_normal_perturbator
private

Definition at line 116 of file c3d_render_raytracing.h.

Referenced by add_3D_models(), and setupMaterials().

CDIRECTIONALLIGHT* C3D_RENDER_RAYTRACING::m_camera_light
private

Definition at line 140 of file c3d_render_raytracing.h.

Referenced by C3D_RENDER_RAYTRACING(), Redraw(), reload(), and render().

CCONTAINER2D C3D_RENDER_RAYTRACING::m_containerWithObjectsToDelete
private

This will store the list of created objects special for RT, that will be clear in the end.

Definition at line 150 of file c3d_render_raytracing.h.

Referenced by insert3DPadHole(), insert3DViaHole(), and reload().

CBLINN_PHONG_MATERIAL C3D_RENDER_RAYTRACING::m_Copper

Definition at line 107 of file c3d_render_raytracing.h.

CCOPPERNORMAL C3D_RENDER_RAYTRACING::m_copper_normal_perturbator
private

Definition at line 112 of file c3d_render_raytracing.h.

Referenced by setupMaterials().

CBLINN_PHONG_MATERIAL C3D_RENDER_RAYTRACING::m_EpoxyBoard

Definition at line 106 of file c3d_render_raytracing.h.

SFVEC2UI C3D_RENDER_RAYTRACING::m_fastPreviewModeSize
private

Definition at line 174 of file c3d_render_raytracing.h.

Referenced by initialize_block_positions().

HITINFO_PACKET* C3D_RENDER_RAYTRACING::m_firstHitinfo
private

Definition at line 176 of file c3d_render_raytracing.h.

Referenced by C3D_RENDER_RAYTRACING().

CBLINN_PHONG_MATERIAL C3D_RENDER_RAYTRACING::m_Floor

Definition at line 108 of file c3d_render_raytracing.h.