KiCad PCB EDA Suite
Loading...
Searching...
No Matches
render_3d_raytrace.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-2020 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2015-2021 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
25#ifndef RENDER_3D_RAYTRACE_H
26#define RENDER_3D_RAYTRACE_H
27
28#include "../../common_ogl/openGL_includes.h"
31#include "../render_3d_base.h"
32#include "light.h"
33#include "../post_shader_ssao.h"
34#include "material.h"
36
37#include <map>
38
40typedef std::vector< BLINN_PHONG_MATERIAL > MODEL_MATERIALS;
41
43typedef std::map< const S3DMODEL* , MODEL_MATERIALS > MAP_MODEL_MATERIALS;
44
45typedef enum
46{
53
54
56{
57public:
58 // TODO: Take into account board thickness so that the camera won't move inside of the board
59 // when facing it perpendicularly.
60 static constexpr float MIN_DISTANCE_IU = 4 * PCB_IU_PER_MM;
61
62 explicit RENDER_3D_RAYTRACE( EDA_3D_CANVAS* aCanvas, BOARD_ADAPTER& aAdapter, CAMERA& aCamera );
63
65
66 void SetCurWindowSize( const wxSize& aSize ) override;
67 bool Redraw( bool aIsMoving, REPORTER* aStatusReporter, REPORTER* aWarningReporter ) override;
68
69 int GetWaitForEditingTimeOut() override;
70
71 void Reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter,
72 bool aOnlyLoadCopperAndShapes );
73
74 BOARD_ITEM *IntersectBoardItem( const RAY& aRay );
75
76private:
77 bool initializeOpenGL();
79 void initPbo();
80 void deletePbo();
81 void createItemsFromContainer( const BVH_CONTAINER_2D* aContainer2d, PCB_LAYER_ID aLayer_id,
82 const MATERIAL* aMaterialLayer, const SFVEC3F& aLayerColor,
83 float aLayerZOffset );
84
85 void restartRenderState();
86 void renderTracing( GLubyte* ptrPBO, REPORTER* aStatusReporter );
87 void postProcessShading( GLubyte* ptrPBO, REPORTER* aStatusReporter );
88 void postProcessBlurFinish( GLubyte* ptrPBO, REPORTER* aStatusReporter );
89 void renderBlockTracing( GLubyte* ptrPBO , signed int iBlock );
90 void renderFinalColor( GLubyte* ptrPBO, const SFVEC3F& rgbColor,
91 bool applyColorSpaceConversion );
92
93 void renderRayPackets( const SFVEC3F* bgColorY, const RAY* aRayPkt, HITINFO_PACKET* aHitPacket,
94 bool is_testShadow, SFVEC3F* aOutHitColor );
95
96 void renderAntiAliasPackets( const SFVEC3F* aBgColorY, const HITINFO_PACKET* aHitPck_X0Y0,
97 const HITINFO_PACKET* aHitPck_AA_X1Y1, const RAY* aRayPck,
98 SFVEC3F* aOutHitColor );
99
100 // Materials
101 void setupMaterials();
102
103 SFVEC3F shadeHit( const SFVEC3F& aBgColor, const RAY& aRay, HITINFO& aHitInfo,
104 bool aIsInsideObject, unsigned int aRecursiveLevel,
105 bool is_testShadow ) const;
106
113 void createObject( CONTAINER_3D& aDstContainer, const OBJECT_2D* aObject2D, float aZMin,
114 float aZMax, const MATERIAL* aMaterial, const SFVEC3F& aObjColor );
115
116 void addPadsAndVias();
117 void insertHole( const PCB_VIA* aVia );
118 void insertHole( const PAD* aPad );
119 void load3DModels( CONTAINER_3D& aDstContainer, bool aSkipMaterialInformation );
120 void addModels( CONTAINER_3D& aDstContainer, const S3DMODEL* a3DModel,
121 const glm::mat4& aModelMatrix, float aFPOpacity,
122 bool aSkipMaterialInformation, BOARD_ITEM* aBoardItem );
123
124 MODEL_MATERIALS* getModelMaterial( const S3DMODEL* a3DModel );
125
127
128 void render( GLubyte* ptrPBO, REPORTER* aStatusReporter );
129 void renderPreview( GLubyte* ptrPBO );
130
131 struct
132 {
141
150
152
155
157 unsigned long int m_renderStartTime;
158
161
163
164 std::list<LIGHT*> m_lights;
165
167
169
170 GLuint m_pboId;
172
174
177
180
182
185
188
190 std::vector< SFVEC2UI > m_blockPositions;
191
194
196 std::vector< SFVEC2UI > m_blockPositionsFast;
197
200
202
204
205 // Display Offset
206 unsigned int m_xoffset;
207 unsigned int m_yoffset;
208
211
212 // Statistics
215};
216
217#define USE_SRGB_SPACE
218
219#ifdef USE_SRGB_SPACE
220extern SFVEC3F ConvertSRGBToLinear( const SFVEC3F& aSRGBcolor );
221#else
222#define ConvertSRGBToLinear( v ) ( v )
223#endif
224
225#endif // RENDER_3D_RAYTRACE_H
constexpr double PCB_IU_PER_MM
Definition: base_units.h:71
define an internal structure to be used by the 3D renders
Blinn Phong based material https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model.
Definition: material.h:379
Helper class to handle information needed to display 3D board.
Definition: board_adapter.h:70
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
Procedural generation of the shiny brushed metal.
Definition: material.h:195
A class used to derive camera objects from.
Definition: camera.h:78
Procedural generation of the copper normals.
Definition: material.h:76
A light source based only on a directional vector.
Definition: light.h:116
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:49
Base material class that can be used to derive other material implementations.
Definition: material.h:240
Definition: pad.h:58
Procedural generation of the plastic normals.
Definition: material.h:146
Procedural generation of the shiny plastic normals.
Definition: material.h:170
This is a base class to hold data and functions for render targets.
DIRECTIONAL_LIGHT * m_cameraLight
BLINN_PHONG_MATERIAL m_Floor
BLINN_PHONG_MATERIAL m_NonPlatedCopper
PLATED_COPPER_NORMAL m_platedCopperMaterial
SOLDER_MASK_NORMAL m_solderMaskMaterial
void load3DModels(CONTAINER_3D &aDstContainer, bool aSkipMaterialInformation)
unsigned int m_converted2dRoundSegmentCount
std::vector< SFVEC2UI > m_blockPositionsFast
void createItemsFromContainer(const BVH_CONTAINER_2D *aContainer2d, PCB_LAYER_ID aLayer_id, const MATERIAL *aMaterialLayer, const SFVEC3F &aLayerColor, float aLayerZOffset)
int GetWaitForEditingTimeOut() override
Give the interface the time (in ms) that it should wait for editing or movements before (this works f...
void createObject(CONTAINER_3D &aDstContainer, const OBJECT_2D *aObject2D, float aZMin, float aZMax, const MATERIAL *aMaterial, const SFVEC3F &aObjColor)
Create one or more 3D objects form a 2D object and Z positions.
MODEL_MATERIALS * getModelMaterial(const S3DMODEL *a3DModel)
HITINFO_PACKET * m_firstHitinfo
POST_SHADER_SSAO m_postShaderSsao
BRUSHED_METAL_NORMAL m_brushedMetalMaterial
BLINN_PHONG_MATERIAL m_EpoxyBoard
unsigned long int m_renderStartTime
Time that the render starts.
void SetCurWindowSize(const wxSize &aSize) override
Before each render, the canvas will tell the render what is the size of its windows,...
PLASTIC_SHINE_NORMAL m_shinyPlasticMaterial
BOARD_ITEM * IntersectBoardItem(const RAY &aRay)
CONTAINER_2D * m_outlineBoard2dObjects
std::vector< SFVEC2UI > m_blockPositions
Flag if a position was already processed (cleared each new render).
BLINN_PHONG_MATERIAL m_SolderMask
wxSize m_oldWindowsSize
Encode Morton code positions.
struct RENDER_3D_RAYTRACE::@5 m_materials
ACCELERATOR_3D * m_accelerator
unsigned int m_convertedDummyBlockCount
void postProcessShading(GLubyte *ptrPBO, REPORTER *aStatusReporter)
size_t m_blockRenderProgressCount
Save the number of blocks progress of the render.
void renderTracing(GLubyte *ptrPBO, REPORTER *aStatusReporter)
SFVEC3F shadeHit(const SFVEC3F &aBgColor, const RAY &aRay, HITINFO &aHitInfo, bool aIsInsideObject, unsigned int aRecursiveLevel, bool is_testShadow) const
void addModels(CONTAINER_3D &aDstContainer, const S3DMODEL *a3DModel, const glm::mat4 &aModelMatrix, float aFPOpacity, bool aSkipMaterialInformation, BOARD_ITEM *aBoardItem)
PLASTIC_NORMAL m_plasticMaterial
SILK_SCREEN_NORMAL m_silkScreenMaterial
void renderFinalColor(GLubyte *ptrPBO, const SFVEC3F &rgbColor, bool applyColorSpaceConversion)
std::vector< int > m_blockPositionsWasProcessed
Encode the Morton code positions (on fast preview mode).
void renderBlockTracing(GLubyte *ptrPBO, signed int iBlock)
BLINN_PHONG_MATERIAL m_Copper
void postProcessBlurFinish(GLubyte *ptrPBO, REPORTER *aStatusReporter)
CONTAINER_3D m_objectContainer
Store the list of created objects special for RT that will be clear in the end.
BLINN_PHONG_MATERIAL m_Paste
void render(GLubyte *ptrPBO, REPORTER *aStatusReporter)
BOARD_NORMAL m_boardMaterial
SFVEC3F m_backgroundColorBottom
Used to see if the windows size changed.
RT_RENDER_STATE m_renderState
State used on quality render.
void renderRayPackets(const SFVEC3F *bgColorY, const RAY *aRayPkt, HITINFO_PACKET *aHitPacket, bool is_testShadow, SFVEC3F *aOutHitColor)
CONTAINER_2D m_containerWithObjectsToDelete
std::list< LIGHT * > m_lights
static constexpr float MIN_DISTANCE_IU
void renderPreview(GLubyte *ptrPBO)
void Reload(REPORTER *aStatusReporter, REPORTER *aWarningReporter, bool aOnlyLoadCopperAndShapes)
void renderAntiAliasPackets(const SFVEC3F *aBgColorY, const HITINFO_PACKET *aHitPck_X0Y0, const HITINFO_PACKET *aHitPck_AA_X1Y1, const RAY *aRayPck, SFVEC3F *aOutHitColor)
BLINN_PHONG_MATERIAL m_SilkS
MAP_MODEL_MATERIALS m_modelMaterialMap
Stores materials of the 3D models.
BVH_CONTAINER_2D * m_antioutlineBoard2dObjects
bool Redraw(bool aIsMoving, REPORTER *aStatusReporter, REPORTER *aWarningReporter) override
Redraw the view.
void insertHole(const PCB_VIA *aVia)
COPPER_NORMAL m_copperMaterial
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
Procedural generation of the solder mask.
Definition: material.h:126
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
Declare and implement light sources.
SFVEC3F ConvertSRGBToLinear(const SFVEC3F &aSRGBcolor)
std::vector< BLINN_PHONG_MATERIAL > MODEL_MATERIALS
Vector of materials.
RT_RENDER_STATE
@ RT_RENDER_STATE_POST_PROCESS_SHADE
@ RT_RENDER_STATE_POST_PROCESS_BLUR_AND_FINISH
@ RT_RENDER_STATE_FINISH
@ RT_RENDER_STATE_TRACING
@ RT_RENDER_STATE_MAX
std::map< const S3DMODEL *, MODEL_MATERIALS > MAP_MODEL_MATERIALS
Maps a S3DMODEL pointer with a created BLINN_PHONG_MATERIAL vector.
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:36
Definition: ray.h:63
Store the a model based on meshes and materials.
Definition: c3dmodel.h:91
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
glm::uvec2 SFVEC2UI
Definition: xv3d_types.h:38