KiCad PCB EDA Suite
Loading...
Searching...
No Matches
render_3d_raytrace_base.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-2024 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_BASE_H
26#define RENDER_3D_RAYTRACE_BASE_H
27
30#include "../render_3d_base.h"
31#include "light.h"
32#include "../post_shader_ssao.h"
33#include "material.h"
35
36#include <map>
37
39typedef std::vector< BLINN_PHONG_MATERIAL > MODEL_MATERIALS;
40
42typedef std::map< const S3DMODEL* , MODEL_MATERIALS > MAP_MODEL_MATERIALS;
43
44typedef enum
45{
52
53
55{
56public:
57 // TODO: Take into account board thickness so that the camera won't move inside of the board
58 // when facing it perpendicularly.
59 static constexpr float MIN_DISTANCE_IU = 4 * PCB_IU_PER_MM;
60
61 explicit RENDER_3D_RAYTRACE_BASE( BOARD_ADAPTER& aAdapter, CAMERA& aCamera );
62
64
65 int GetWaitForEditingTimeOut() override;
66
67 void Reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter,
68 bool aOnlyLoadCopperAndShapes );
69
70 BOARD_ITEM *IntersectBoardItem( const RAY& aRay );
71
72protected:
73 virtual void initPbo() = 0;
74 virtual void deletePbo() = 0;
75 void createItemsFromContainer( const BVH_CONTAINER_2D* aContainer2d, PCB_LAYER_ID aLayer_id,
76 const MATERIAL* aMaterialLayer, const SFVEC3F& aLayerColor,
77 float aLayerZOffset );
78
79 void restartRenderState();
80 void renderTracing( uint8_t* ptrPBO, REPORTER* aStatusReporter );
81 void postProcessShading( uint8_t* ptrPBO, REPORTER* aStatusReporter );
82 void postProcessBlurFinish( uint8_t* ptrPBO, REPORTER* aStatusReporter );
83 void renderBlockTracing( uint8_t* ptrPBO , signed int iBlock );
84 void renderFinalColor( uint8_t* ptrPBO, const SFVEC4F& rgbColor,
85 bool applyColorSpaceConversion );
86
87 void renderRayPackets( const SFVEC4F* bgColorY, const RAY* aRayPkt, HITINFO_PACKET* aHitPacket,
88 bool is_testShadow, SFVEC4F* aOutHitColor );
89
90 void renderAntiAliasPackets( const SFVEC4F* aBgColorY, const HITINFO_PACKET* aHitPck_X0Y0,
91 const HITINFO_PACKET* aHitPck_AA_X1Y1, const RAY* aRayPck,
92 SFVEC4F* aOutHitColor );
93
94 // Materials
95 void setupMaterials();
96
97 SFVEC4F shadeHit( const SFVEC4F& aBgColor, const RAY& aRay, HITINFO& aHitInfo,
98 bool aIsInsideObject, unsigned int aRecursiveLevel,
99 bool is_testShadow ) const;
100
107 void createObject( CONTAINER_3D& aDstContainer, const OBJECT_2D* aObject2D, float aZMin,
108 float aZMax, const MATERIAL* aMaterial, const SFVEC3F& aObjColor );
109
110 void addPadsAndVias();
111 void insertHole( const PCB_VIA* aVia );
112 void insertHole( const PAD* aPad );
113 void load3DModels( CONTAINER_3D& aDstContainer, bool aSkipMaterialInformation );
114 void addModels( CONTAINER_3D& aDstContainer, const S3DMODEL* a3DModel,
115 const glm::mat4& aModelMatrix, float aFPOpacity,
116 bool aSkipMaterialInformation, BOARD_ITEM* aBoardItem );
117
118 MODEL_MATERIALS* getModelMaterial( const S3DMODEL* a3DModel );
119
121
122 void render( uint8_t* ptrPBO, REPORTER* aStatusReporter );
123 void renderPreview( uint8_t* ptrPBO );
124
125 static SFVEC4F premultiplyAlpha( const SFVEC4F& aInput );
126
127 struct
128 {
137
146
149
152
155
158
160
161 std::list<LIGHT*> m_lights;
162
164
165 /*GLuint m_pboId;
166 GLuint m_pboDataSize;*/
167
169
172
175
177
180
183
185 std::vector< SFVEC2UI > m_blockPositions;
186
189
191 std::vector< SFVEC2UI > m_blockPositionsFast;
192
195
197
199
200 // Display Offset
201 unsigned int m_xoffset;
202 unsigned int m_yoffset;
203
206
207 // Statistics
210};
211
212#define USE_SRGB_SPACE
213
214#ifdef USE_SRGB_SPACE
215extern SFVEC3F ConvertSRGBToLinear( const SFVEC3F& aSRGBcolor );
216extern SFVEC4F ConvertSRGBAToLinear( const SFVEC4F& aSRGBAcolor );
217#else
218#define ConvertSRGBToLinear( v ) ( v )
219#define ConvertSRGBAToLinear( v ) ( v )
220#endif
221
222#endif // RENDER_3D_RAYTRACE_BASE_H
constexpr double PCB_IU_PER_MM
Definition: base_units.h:70
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:73
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
Procedural generation of the shiny brushed metal.
Definition: material.h:195
A class used to derive camera objects from.
Definition: camera.h:103
Procedural generation of the copper normals.
Definition: material.h:76
A light source based only on a directional vector.
Definition: light.h:116
Base material class that can be used to derive other material implementations.
Definition: material.h:240
Definition: pad.h:54
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.
void renderBlockTracing(uint8_t *ptrPBO, signed int iBlock)
virtual void deletePbo()=0
static SFVEC4F premultiplyAlpha(const SFVEC4F &aInput)
BLINN_PHONG_MATERIAL m_NonPlatedCopper
BLINN_PHONG_MATERIAL m_EpoxyBoard
SILK_SCREEN_NORMAL m_silkScreenMaterial
void Reload(REPORTER *aStatusReporter, REPORTER *aWarningReporter, bool aOnlyLoadCopperAndShapes)
void renderFinalColor(uint8_t *ptrPBO, const SFVEC4F &rgbColor, bool applyColorSpaceConversion)
CONTAINER_3D m_objectContainer
Store the list of created objects special for RT that will be clear in the end.
void renderTracing(uint8_t *ptrPBO, REPORTER *aStatusReporter)
void render(uint8_t *ptrPBO, REPORTER *aStatusReporter)
void postProcessBlurFinish(uint8_t *ptrPBO, REPORTER *aStatusReporter)
void renderAntiAliasPackets(const SFVEC4F *aBgColorY, const HITINFO_PACKET *aHitPck_X0Y0, const HITINFO_PACKET *aHitPck_AA_X1Y1, const RAY *aRayPck, SFVEC4F *aOutHitColor)
void load3DModels(CONTAINER_3D &aDstContainer, bool aSkipMaterialInformation)
void insertHole(const PCB_VIA *aVia)
void postProcessShading(uint8_t *ptrPBO, REPORTER *aStatusReporter)
BRUSHED_METAL_NORMAL m_brushedMetalMaterial
std::vector< int > m_blockPositionsWasProcessed
Encode the Morton code positions (on fast preview mode).
static constexpr float MIN_DISTANCE_IU
PLATED_COPPER_NORMAL m_platedCopperMaterial
void createItemsFromContainer(const BVH_CONTAINER_2D *aContainer2d, PCB_LAYER_ID aLayer_id, const MATERIAL *aMaterialLayer, const SFVEC3F &aLayerColor, float aLayerZOffset)
DIRECTIONAL_LIGHT * m_cameraLight
PLASTIC_SHINE_NORMAL m_shinyPlasticMaterial
BOARD_ITEM * IntersectBoardItem(const RAY &aRay)
RT_RENDER_STATE m_renderState
State used on quality render.
void renderRayPackets(const SFVEC4F *bgColorY, const RAY *aRayPkt, HITINFO_PACKET *aHitPacket, bool is_testShadow, SFVEC4F *aOutHitColor)
int GetWaitForEditingTimeOut() override
Give the interface the time (in ms) that it should wait for editing or movements before (this works f...
std::vector< SFVEC2UI > m_blockPositionsFast
struct RENDER_3D_RAYTRACE_BASE::@5 m_materials
SFVEC4F shadeHit(const SFVEC4F &aBgColor, const RAY &aRay, HITINFO &aHitInfo, bool aIsInsideObject, unsigned int aRecursiveLevel, bool is_testShadow) const
SFVEC4F m_backgroundColorBottom
Used to see if the windows size changed.
BVH_CONTAINER_2D * m_antioutlineBoard2dObjects
BLINN_PHONG_MATERIAL m_SolderMask
MODEL_MATERIALS * getModelMaterial(const S3DMODEL *a3DModel)
wxSize m_oldWindowsSize
Encode Morton code positions.
void renderPreview(uint8_t *ptrPBO)
SOLDER_MASK_NORMAL m_solderMaskMaterial
void addModels(CONTAINER_3D &aDstContainer, const S3DMODEL *a3DModel, const glm::mat4 &aModelMatrix, float aFPOpacity, bool aSkipMaterialInformation, BOARD_ITEM *aBoardItem)
MAP_MODEL_MATERIALS m_modelMaterialMap
Stores materials of the 3D models.
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.
virtual void initPbo()=0
size_t m_blockRenderProgressCount
Save the number of blocks progress of the render.
int64_t m_renderStartTime
Time that the render starts.
std::vector< SFVEC2UI > m_blockPositions
Flag if a position was already processed (cleared each new render).
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:72
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_POST_PROCESS_SHADE
@ RT_RENDER_STATE_POST_PROCESS_BLUR_AND_FINISH
@ RT_RENDER_STATE_FINISH
@ RT_RENDER_STATE_TRACING
@ RT_RENDER_STATE_MAX
SFVEC4F ConvertSRGBAToLinear(const SFVEC4F &aSRGBAcolor)
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
glm::vec4 SFVEC4F
Definition: xv3d_types.h:46