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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef RENDER_3D_RAYTRACE_BASE_H
22#define RENDER_3D_RAYTRACE_BASE_H
23
26#include "../render_3d_base.h"
27#include "light.h"
28#include "../post_shader_ssao.h"
29#include "material.h"
31
32#include <map>
33
34class PAD;
35class PCB_VIA;
36
38typedef std::vector< BLINN_PHONG_MATERIAL > MODEL_MATERIALS;
39
41typedef std::map< const S3DMODEL* , MODEL_MATERIALS > MAP_MODEL_MATERIALS;
42
51
52
54{
55public:
56 // TODO: Take into account board thickness so that the camera won't move inside of the board
57 // when facing it perpendicularly.
58 static constexpr float MIN_DISTANCE_IU = 4 * PCB_IU_PER_MM;
59
60 explicit RENDER_3D_RAYTRACE_BASE( BOARD_ADAPTER& aAdapter, CAMERA& aCamera );
61
63
64 int GetWaitForEditingTimeOut() override;
65
66 void Reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter,
67 bool aOnlyLoadCopperAndShapes );
68
69 BOARD_ITEM *IntersectBoardItem( const RAY& aRay );
70
71protected:
72 virtual void initPbo() = 0;
73 virtual void deletePbo() = 0;
74 void createItemsFromContainer( const BVH_CONTAINER_2D* aContainer2d, PCB_LAYER_ID aLayer_id,
75 const MATERIAL* aMaterialLayer, const SFVEC3F& aLayerColor,
76 float aLayerZOffset );
77
78 void restartRenderState();
79 void renderTracing( uint8_t* ptrPBO, REPORTER* aStatusReporter );
80 void postProcessShading( uint8_t* ptrPBO, REPORTER* aStatusReporter );
81 void postProcessBlurFinish( uint8_t* ptrPBO, REPORTER* aStatusReporter );
82 void renderBlockTracing( uint8_t* ptrPBO , signed int iBlock );
83 void renderFinalColor( uint8_t* ptrPBO, const SFVEC4F& rgbColor,
84 bool applyColorSpaceConversion );
85
86 void renderRayPackets( const SFVEC4F* bgColorY, const RAY* aRayPkt, HITINFO_PACKET* aHitPacket,
87 bool is_testShadow, SFVEC4F* aOutHitColor );
88
89 void renderAntiAliasPackets( const SFVEC4F* aBgColorY, const HITINFO_PACKET* aHitPck_X0Y0,
90 const HITINFO_PACKET* aHitPck_AA_X1Y1, const RAY* aRayPck,
91 SFVEC4F* aOutHitColor );
92
93 // Materials
94 void setupMaterials();
95
96 SFVEC4F shadeHit( const SFVEC4F& aBgColor, const RAY& aRay, HITINFO& aHitInfo,
97 bool aIsInsideObject, unsigned int aRecursiveLevel,
98 bool is_testShadow ) const;
99
106 void createObject( CONTAINER_3D& aDstContainer, const OBJECT_2D* aObject2D, float aZMin,
107 float aZMax, const MATERIAL* aMaterial, const SFVEC3F& aObjColor );
108
109 void addPadsAndVias();
110 void insertHole( const PCB_VIA* aVia );
111 void insertHole( const PAD* aPad );
112 void addCounterborePlating( const BOARD_ITEM& aSource, const SFVEC2F& aCenter,
113 float aInnerRadius, float aDepth, float aSurfaceZ,
114 bool aIsFront );
115 void addCountersinkPlating( const SFVEC2F& aCenter, float aTopInnerRadius,
116 float aBottomInnerRadius, float aSurfaceZ, float aDepth,
117 bool aIsFront );
118 void backfillPostMachine();
119 void load3DModels( CONTAINER_3D& aDstContainer, bool aSkipMaterialInformation );
120 void addPlaceholderToRaytracer( CONTAINER_3D& aDstContainer, const FOOTPRINT* aFootprint,
121 const glm::mat4& aFpMatrix, bool aHasExtrudedBody = false );
122 bool addExtrudedBodyToRaytracer( CONTAINER_3D& aDstContainer, const FOOTPRINT* aFootprint );
123 void addModels( CONTAINER_3D& aDstContainer, const S3DMODEL* a3DModel,
124 const glm::mat4& aModelMatrix, float aFPOpacity,
125 bool aSkipMaterialInformation, BOARD_ITEM* aBoardItem );
126
127 MODEL_MATERIALS* getModelMaterial( const S3DMODEL* a3DModel );
128
130
131 void render( uint8_t* ptrPBO, REPORTER* aStatusReporter );
132 void renderPreview( uint8_t* ptrPBO );
133
134 static SFVEC4F premultiplyAlpha( const SFVEC4F& aInput );
135
136 struct
137 {
146
147 std::vector<std::unique_ptr<BLINN_PHONG_MATERIAL>> m_extrusionMaterials;
148
157
160
163
166
169
171
172 std::list<LIGHT*> m_lights;
173
175
176 /*GLuint m_pboId;
177 GLuint m_pboDataSize;*/
178
180
183
186
188
191
194
196 std::vector< SFVEC2UI > m_blockPositions;
197
200
202 std::vector< SFVEC2UI > m_blockPositionsFast;
203
206
208
210
211 // Display Offset
212 unsigned int m_xoffset;
213 unsigned int m_yoffset;
214
217
218 // Statistics
221};
222
223#define USE_SRGB_SPACE
224
225#ifdef USE_SRGB_SPACE
226extern SFVEC3F ConvertSRGBToLinear( const SFVEC3F& aSRGBcolor );
227extern SFVEC4F ConvertSRGBAToLinear( const SFVEC4F& aSRGBAcolor );
228#else
229#define ConvertSRGBToLinear( v ) ( v )
230#define ConvertSRGBAToLinear( v ) ( v )
231#endif
232
233#endif // RENDER_3D_RAYTRACE_BASE_H
constexpr double PCB_IU_PER_MM
Pcbnew IU is 1 nanometer.
Definition base_units.h:68
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:375
Helper class to handle information needed to display 3D board.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
Procedural generation of the shiny brushed metal.
Definition material.h:191
A class used to derive camera objects from.
Definition camera.h:99
Procedural generation of the copper normals.
Definition material.h:72
A light source based only on a directional vector.
Definition light.h:112
Base material class that can be used to derive other material implementations.
Definition material.h:236
Definition pad.h:61
Procedural generation of the plastic normals.
Definition material.h:142
Procedural generation of the shiny plastic normals.
Definition material.h:166
RENDER_3D_BASE(BOARD_ADAPTER &aBoardAdapter, CAMERA &aCamera)
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
struct RENDER_3D_RAYTRACE_BASE::@013206213056006125230376122042346155134272177300 m_materials
void Reload(REPORTER *aStatusReporter, REPORTER *aWarningReporter, bool aOnlyLoadCopperAndShapes)
RENDER_3D_RAYTRACE_BASE(BOARD_ADAPTER &aAdapter, CAMERA &aCamera)
void renderFinalColor(uint8_t *ptrPBO, const SFVEC4F &rgbColor, bool applyColorSpaceConversion)
void addCountersinkPlating(const SFVEC2F &aCenter, float aTopInnerRadius, float aBottomInnerRadius, float aSurfaceZ, float aDepth, bool aIsFront)
void addPlaceholderToRaytracer(CONTAINER_3D &aDstContainer, const FOOTPRINT *aFootprint, const glm::mat4 &aFpMatrix, bool aHasExtrudedBody=false)
std::vector< std::unique_ptr< BLINN_PHONG_MATERIAL > > m_extrusionMaterials
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
Flag if a position was already processed (cleared each new render).
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)
PLASTIC_SHINE_NORMAL m_shinyPlasticMaterial
BOARD_ITEM * IntersectBoardItem(const RAY &aRay)
RT_RENDER_STATE m_renderState
State used on quality render.
bool addExtrudedBodyToRaytracer(CONTAINER_3D &aDstContainer, const FOOTPRINT *aFootprint)
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...
void addCounterborePlating(const BOARD_ITEM &aSource, const SFVEC2F &aCenter, float aInnerRadius, float aDepth, float aSurfaceZ, bool aIsFront)
std::vector< SFVEC2UI > m_blockPositionsFast
Encode the Morton code positions (on fast preview mode).
SFVEC4F shadeHit(const SFVEC4F &aBgColor, const RAY &aRay, HITINFO &aHitInfo, bool aIsInsideObject, unsigned int aRecursiveLevel, bool is_testShadow) const
BVH_CONTAINER_2D * m_antioutlineBoard2dObjects
CONTAINER_2D m_containerWithObjectsToDelete
Store the list of created objects special for RT that will be clear in the end.
BLINN_PHONG_MATERIAL m_SolderMask
MODEL_MATERIALS * getModelMaterial(const S3DMODEL *a3DModel)
wxSize m_oldWindowsSize
Used to see if the windows size changed.
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
Encode Morton code positions.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:71
Procedural generation of the solder mask.
Definition material.h:122
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
Declare and implement light sources.
Implements a post shader screen space ambient occlusion on software.
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:32
Definition ray.h:59
Store the a model based on meshes and materials.
Definition c3dmodel.h:91
glm::vec2 SFVEC2F
Definition xv3d_types.h:38
glm::vec3 SFVEC3F
Definition xv3d_types.h:40
glm::uvec2 SFVEC2UI
Definition xv3d_types.h:34
glm::vec4 SFVEC4F
Definition xv3d_types.h:42