KiCad PCB EDA Suite
c3d_render_raytracing.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #ifndef C3D_RENDER_RAYTRACING_H
31 #define C3D_RENDER_RAYTRACING_H
32 
33 #include "../../common_ogl/openGL_includes.h"
36 #include "../c3d_render_base.h"
37 #include "clight.h"
38 #include "../cpostshader_ssao.h"
39 #include "cmaterial.h"
40 #include <plugins/3dapi/c3dmodel.h>
41 
42 #include <map>
43 
45 typedef std::vector< CBLINN_PHONG_MATERIAL > MODEL_MATERIALS;
46 
48 typedef std::map< const S3DMODEL * , MODEL_MATERIALS > MAP_MODEL_MATERIALS;
49 
50 typedef enum
51 {
58 
60 {
61 public:
62  explicit C3D_RENDER_RAYTRACING( CINFO3D_VISU &aSettings );
63 
65 
66  // Imported from C3D_RENDER_BASE
67  void SetCurWindowSize( const wxSize &aSize ) override;
68  bool Redraw(bool aIsMoving, REPORTER *aStatusTextReporter ) override;
69 
70  int GetWaitForEditingTimeOut() override;
71 
72 private:
73  bool initializeOpenGL();
75  void opengl_init_pbo();
76  void opengl_delete_pbo();
77  void reload( REPORTER *aStatusTextReporter );
78 
79  void restart_render_state();
80  void rt_render_tracing( GLubyte *ptrPBO , REPORTER *aStatusTextReporter );
81  void rt_render_post_process_shade( GLubyte *ptrPBO , REPORTER *aStatusTextReporter );
82  void rt_render_post_process_blur_finish( GLubyte *ptrPBO , REPORTER *aStatusTextReporter );
83  void rt_render_trace_block( GLubyte *ptrPBO , signed int iBlock );
84  void rt_final_color( GLubyte *ptrPBO, const SFVEC3F &rgbColor, bool applyColorSpaceConversion );
85 
86  void rt_shades_packet( const SFVEC3F *bgColorY,
87  const RAY *aRayPkt,
88  HITINFO_PACKET *aHitPacket,
89  bool is_testShadow,
90  SFVEC3F *aOutHitColor );
91 
92  void rt_trace_AA_packet( const SFVEC3F *aBgColorY,
93  const HITINFO_PACKET *aHitPck_X0Y0,
94  const HITINFO_PACKET *aHitPck_AA_X1Y1,
95  const RAY *aRayPck,
96  SFVEC3F *aOutHitColor );
97 
98  // Materials
99  void setupMaterials();
100 
101  struct
102  {
109  }m_materials;
110 
117 
119 
120  SFVEC3F shadeHit( const SFVEC3F &aBgColor,
121  const RAY &aRay,
122  HITINFO &aHitInfo,
123  bool aIsInsideObject,
124  unsigned int aRecursiveLevel,
125  bool is_testShadow ) const;
126 
129 
131  unsigned long int m_stats_start_rendering_time;
132 
135 
137 
139 
141 
143  GLuint m_pboId;
145 
147 
151 
153 
155 
158 
159  // Morton codes
160 
163 
165  std::vector< SFVEC2UI > m_blockPositions;
166 
168  std::vector< bool > m_blockPositionsWasProcessed;
169 
171  std::vector< SFVEC2UI > m_blockPositionsFast;
172 
175 
177 
179 
180  // Display Offset
181  unsigned int m_xoffset;
182  unsigned int m_yoffset;
183 
184  // Statistics
187 
188  void create_3d_object_from( CCONTAINER &aDstContainer,
189  const COBJECT2D *aObject2D,
190  float aZMin, float aZMax,
191  const CMATERIAL *aMaterial,
192  const SFVEC3F &aObjColor );
193 
195  void insert3DViaHole( const VIA* aVia );
196  void insert3DPadHole( const D_PAD* aPad );
197  void load_3D_models();
198  void add_3D_models( const S3DMODEL *a3DModel,
199  const glm::mat4 &aModelMatrix );
200 
203 
205 
206  void render( GLubyte *ptrPBO, REPORTER *aStatusTextReporter );
207  void render_preview( GLubyte *ptrPBO );
208 };
209 
210 #define USE_SRGB_SPACE
211 
212 #ifdef USE_SRGB_SPACE
213 extern SFVEC3F ConvertSRGBToLinear( const SFVEC3F &aSRGBcolor );
214 #else
215 #define ConvertSRGBToLinear(v) (v)
216 #endif
217 
218 #endif // C3D_RENDER_RAYTRACING_H
std::vector< bool > m_blockPositionsWasProcessed
this flags if a position was already processed (cleared each new render)
define an internal structure to be used by the 3D renders
long m_nrBlocksRenderProgress
Save the number of blocks progress of the render.
void rt_shades_packet(const SFVEC3F *bgColorY, const RAY *aRayPkt, HITINFO_PACKET *aHitPacket, bool is_testShadow, SFVEC3F *aOutHitColor)
bool Redraw(bool aIsMoving, REPORTER *aStatusTextReporter) override
Redraw - Ask to redraw the view.
CPLASTICNORMAL m_plastic_normal_perturbator
void rt_final_color(GLubyte *ptrPBO, const SFVEC3F &rgbColor, bool applyColorSpaceConversion)
CBOARDNORMAL m_board_normal_perturbator
Directional light - a light based only on a direction vector.
Definition: clight.h:114
CPOSTSHADER_SSAO m_postshader_ssao
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
wxSize m_oldWindowsSize
used to see if the windows size changed
SFVEC3F ConvertSRGBToLinear(const SFVEC3F &aSRGBcolor)
CCOPPERNORMAL m_copper_normal_perturbator
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.
CBLINN_PHONG_MATERIAL m_Floor
void rt_render_post_process_shade(GLubyte *ptrPBO, REPORTER *aStatusTextReporter)
void insert3DViaHole(const VIA *aVia)
CPLASTICSHINENORMAL m_plastic_shine_normal_perturbator
Definition: ray.h:43
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
CMETALBRUSHEDNORMAL m_brushed_metal_normal_perturbator
HITINFO_PACKET * m_firstHitinfo
unsigned int m_stats_converted_dummy_to_plane
CBLINN_PHONG_MATERIAL m_Paste
std::vector< CBLINN_PHONG_MATERIAL > MODEL_MATERIALS
Vector of materials.
glm::uvec2 SFVEC2UI
Definition: xv3d_types.h:41
CGENERICACCELERATOR * m_accelerator
CBLINN_PHONG_MATERIAL m_SilkS
declare and implement light types classes
Blinn Phong based material https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model.
Definition: cmaterial.h:248
RT_RENDER_STATE m_rt_render_state
State used on quality render.
Class CINFO3D_VISU Helper class to handle information needed to display 3D board. ...
Definition: cinfo3d_visu.h:70
CBLINN_PHONG_MATERIAL m_SolderMask
CCONTAINER2D m_containerWithObjectsToDelete
This will store the list of created objects special for RT, that will be clear in the end...
C3D_RENDER_RAYTRACING(CINFO3D_VISU &aSettings)
unsigned int m_stats_converted_roundsegment2d_to_roundsegment
void rt_render_tracing(GLubyte *ptrPBO, REPORTER *aStatusTextReporter)
int GetWaitForEditingTimeOut() override
GetWaitForEditingTimeOut - Give the interface the time (in ms) that it should wait for editing or mov...
void rt_render_post_process_blur_finish(GLubyte *ptrPBO, REPORTER *aStatusTextReporter)
void rt_trace_AA_packet(const SFVEC3F *aBgColorY, const HITINFO_PACKET *aHitPck_X0Y0, const HITINFO_PACKET *aHitPck_AA_X1Y1, const RAY *aRayPck, SFVEC3F *aOutHitColor)
CDIRECTIONALLIGHT * m_camera_light
std::vector< SFVEC2UI > m_blockPositionsFast
this encodes the Morton code positions (on fast preview mode)
void add_3D_models(const S3DMODEL *a3DModel, const glm::mat4 &aModelMatrix)
A light contariner. It will add lights and remove it in the end.
Definition: clight.h:155
CSOLDERMASKNORMAL m_solder_mask_normal_perturbator
CBLINN_PHONG_MATERIAL m_Copper
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:40
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
std::vector< SFVEC2UI > m_blockPositions
this encodes the Morton code positions
unsigned long int m_stats_start_rendering_time
Time that the render starts.
CBLINN_PHONG_MATERIAL m_EpoxyBoard
std::map< const S3DMODEL *, MODEL_MATERIALS > MAP_MODEL_MATERIALS
Maps a S3DMODEL pointer with a created CBLINN_PHONG_MATERIAL vector.
void SetCurWindowSize(const wxSize &aSize) override
SetCurWindowSize - Before each render, the canvas will tell the render what is the size of its window...
CCONTAINER2D * m_outlineBoard2dObjects
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90
void insert3DPadHole(const D_PAD *aPad)
MAP_MODEL_MATERIALS m_model_materials
Stores materials of the 3D models.
void render_preview(GLubyte *ptrPBO)
void render(GLubyte *ptrPBO, REPORTER *aStatusTextReporter)
struct C3D_RENDER_RAYTRACING::@41 m_materials
void rt_render_trace_block(GLubyte *ptrPBO, signed int iBlock)
This is a base class to hold data and functions for render targets.
void reload(REPORTER *aStatusTextReporter)