2016-07-19 17:35:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-04-25 14:38:41 +00:00
|
|
|
* Copyright (C) 2015-2020 Mario Luzeiro <mrluzeiro@ua.pt>
|
2021-01-13 16:23:09 +00:00
|
|
|
* Copyright (C) 2015-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-07-19 17:35:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-01-03 22:23:00 +00:00
|
|
|
* @file render_3d_raytrace.h
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
#ifndef RENDER_3D_RAYTRACE_H
|
|
|
|
#define RENDER_3D_RAYTRACE_H
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
#include "../../common_ogl/openGL_includes.h"
|
2021-01-03 22:23:00 +00:00
|
|
|
#include "accelerators/container_3d.h"
|
|
|
|
#include "accelerators/accelerator_3d.h"
|
|
|
|
#include "../render_3d_base.h"
|
|
|
|
#include "light.h"
|
|
|
|
#include "../post_shader_ssao.h"
|
|
|
|
#include "material.h"
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <plugins/3dapi/c3dmodel.h>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
/// Vector of materials
|
2021-01-02 21:05:29 +00:00
|
|
|
typedef std::vector< BLINN_PHONG_MATERIAL > MODEL_MATERIALS;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
/// Maps a S3DMODEL pointer with a created BLINN_PHONG_MATERIAL vector
|
|
|
|
typedef std::map< const S3DMODEL* , MODEL_MATERIALS > MAP_MODEL_MATERIALS;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
RT_RENDER_STATE_TRACING = 0,
|
|
|
|
RT_RENDER_STATE_POST_PROCESS_SHADE,
|
|
|
|
RT_RENDER_STATE_POST_PROCESS_BLUR_AND_FINISH,
|
|
|
|
RT_RENDER_STATE_FINISH,
|
|
|
|
RT_RENDER_STATE_MAX
|
2020-12-12 17:29:11 +00:00
|
|
|
} RT_RENDER_STATE;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
class RENDER_3D_RAYTRACE : public RENDER_3D_BASE
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-08-16 14:28:46 +00:00
|
|
|
explicit RENDER_3D_RAYTRACE( EDA_3D_CANVAS* aCanvas, BOARD_ADAPTER& aAdapter, CAMERA& aCamera );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
~RENDER_3D_RAYTRACE();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void SetCurWindowSize( const wxSize& aSize ) override;
|
2020-06-03 23:00:40 +00:00
|
|
|
bool Redraw( bool aIsMoving, REPORTER* aStatusReporter, REPORTER* aWarningReporter ) override;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
int GetWaitForEditingTimeOut() override;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
void Reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter,
|
|
|
|
bool aOnlyLoadCopperAndShapes );
|
2020-09-04 00:00:56 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
BOARD_ITEM *IntersectBoardItem( const RAY& aRay );
|
2020-09-04 00:00:56 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
private:
|
|
|
|
bool initializeOpenGL();
|
|
|
|
void initializeNewWindowSize();
|
2021-01-07 19:33:43 +00:00
|
|
|
void initPbo();
|
|
|
|
void deletePbo();
|
2021-01-02 21:05:29 +00:00
|
|
|
void createItemsFromContainer( const BVH_CONTAINER_2D* aContainer2d, PCB_LAYER_ID aLayer_id,
|
|
|
|
const MATERIAL* aMaterialLayer, const SFVEC3F& aLayerColor,
|
2020-09-07 11:38:05 +00:00
|
|
|
float aLayerZOffset );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
void restartRenderState();
|
|
|
|
void renderTracing( GLubyte* ptrPBO, REPORTER* aStatusReporter );
|
|
|
|
void postProcessShading( GLubyte* ptrPBO, REPORTER* aStatusReporter );
|
|
|
|
void postProcessBlurFinish( GLubyte* ptrPBO, REPORTER* aStatusReporter );
|
|
|
|
void renderBlockTracing( GLubyte* ptrPBO , signed int iBlock );
|
2021-01-13 16:23:09 +00:00
|
|
|
void renderFinalColor( GLubyte* ptrPBO, const SFVEC3F& rgbColor,
|
|
|
|
bool applyColorSpaceConversion );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
void renderRayPackets( const SFVEC3F* bgColorY, const RAY* aRayPkt, HITINFO_PACKET* aHitPacket,
|
2021-01-02 21:05:29 +00:00
|
|
|
bool is_testShadow, SFVEC3F* aOutHitColor );
|
2016-10-22 22:37:13 +00:00
|
|
|
|
2021-01-13 16:23:09 +00:00
|
|
|
void renderAntiAliasPackets( const SFVEC3F* aBgColorY, const HITINFO_PACKET* aHitPck_X0Y0,
|
2021-01-07 19:33:43 +00:00
|
|
|
const HITINFO_PACKET* aHitPck_AA_X1Y1, const RAY* aRayPck,
|
|
|
|
SFVEC3F* aOutHitColor );
|
2016-10-22 22:37:13 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Materials
|
|
|
|
void setupMaterials();
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F shadeHit( const SFVEC3F& aBgColor, const RAY& aRay, HITINFO& aHitInfo,
|
|
|
|
bool aIsInsideObject, unsigned int aRecursiveLevel,
|
2020-12-12 17:29:11 +00:00
|
|
|
bool is_testShadow ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create one or more 3D objects form a 2D object and Z positions.
|
|
|
|
*
|
|
|
|
* It tries to optimize some types of objects that will be faster to trace than the
|
2021-01-02 21:05:29 +00:00
|
|
|
* LAYER_ITEM object.
|
2020-12-12 17:29:11 +00:00
|
|
|
*/
|
2021-01-07 19:33:43 +00:00
|
|
|
void createObject( CONTAINER_3D& aDstContainer, const OBJECT_2D* aObject2D, float aZMin,
|
|
|
|
float aZMax, const MATERIAL* aMaterial, const SFVEC3F& aObjColor );
|
2020-12-12 17:29:11 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
void addPadsAndVias();
|
2021-06-11 21:07:02 +00:00
|
|
|
void insertHole( const PCB_VIA* aVia );
|
2021-01-07 19:33:43 +00:00
|
|
|
void insertHole( const PAD* aPad );
|
2021-08-16 14:28:46 +00:00
|
|
|
void load3DModels( CONTAINER_3D& aDstContainer, bool aSkipMaterialInformation );
|
2021-01-07 19:33:43 +00:00
|
|
|
void addModels( CONTAINER_3D& aDstContainer, const S3DMODEL* a3DModel,
|
|
|
|
const glm::mat4& aModelMatrix, float aFPOpacity,
|
|
|
|
bool aSkipMaterialInformation, BOARD_ITEM* aBoardItem );
|
2020-12-12 17:29:11 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
MODEL_MATERIALS* getModelMaterial( const S3DMODEL* a3DModel );
|
2020-12-12 17:29:11 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
void initializeBlockPositions();
|
2020-12-12 17:29:11 +00:00
|
|
|
|
|
|
|
void render( GLubyte* ptrPBO, REPORTER* aStatusReporter );
|
2021-01-07 19:33:43 +00:00
|
|
|
void renderPreview( GLubyte* ptrPBO );
|
2020-12-12 17:29:11 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
struct
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
BLINN_PHONG_MATERIAL m_Paste;
|
|
|
|
BLINN_PHONG_MATERIAL m_SilkS;
|
|
|
|
BLINN_PHONG_MATERIAL m_SolderMask;
|
|
|
|
BLINN_PHONG_MATERIAL m_EpoxyBoard;
|
|
|
|
BLINN_PHONG_MATERIAL m_Copper;
|
|
|
|
BLINN_PHONG_MATERIAL m_NonPlatedCopper;
|
|
|
|
BLINN_PHONG_MATERIAL m_Floor;
|
2020-12-12 17:29:11 +00:00
|
|
|
} m_materials;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
BOARD_NORMAL m_boardMaterial;
|
|
|
|
COPPER_NORMAL m_copperMaterial;
|
|
|
|
PLATED_COPPER_NORMAL m_platedCopperMaterial;
|
|
|
|
SOLDER_MASK_NORMAL m_solderMaskMaterial;
|
|
|
|
PLASTIC_NORMAL m_plasticMaterial;
|
|
|
|
PLASTIC_SHINE_NORMAL m_shinyPlasticMaterial;
|
|
|
|
BRUSHED_METAL_NORMAL m_brushedMetalMaterial;
|
|
|
|
SILK_SCREEN_NORMAL m_silkScreenMaterial;
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
bool m_isPreview;
|
|
|
|
|
|
|
|
/// State used on quality render
|
2021-01-07 19:33:43 +00:00
|
|
|
RT_RENDER_STATE m_renderState;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
/// Time that the render starts
|
2021-01-07 19:33:43 +00:00
|
|
|
unsigned long int m_renderStartTime;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
/// Save the number of blocks progress of the render
|
2021-01-07 19:33:43 +00:00
|
|
|
size_t m_blockRenderProgressCount;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
POST_SHADER_SSAO m_postShaderSsao;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-07-28 20:04:53 +00:00
|
|
|
std::list<LIGHT*> m_lights;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
DIRECTIONAL_LIGHT* m_cameraLight;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
bool m_openglSupportsVertexBufferObjects;
|
2020-12-12 17:29:11 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
GLuint m_pboId;
|
|
|
|
GLuint m_pboDataSize;
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
CONTAINER_3D m_objectContainer;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
///< Store the list of created objects special for RT that will be clear in the end.
|
2021-01-02 21:05:29 +00:00
|
|
|
CONTAINER_2D m_containerWithObjectsToDelete;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
CONTAINER_2D* m_outlineBoard2dObjects;
|
|
|
|
BVH_CONTAINER_2D* m_antioutlineBoard2dObjects;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
ACCELERATOR_3D* m_accelerator;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
SFVEC3F m_backgroundColorTop;
|
|
|
|
SFVEC3F m_backgroundColorBottom;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
///< Used to see if the windows size changed.
|
2016-07-19 17:35:25 +00:00
|
|
|
wxSize m_oldWindowsSize;
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
///< Encode Morton code positions.
|
2016-07-19 17:35:25 +00:00
|
|
|
std::vector< SFVEC2UI > m_blockPositions;
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
///< Flag if a position was already processed (cleared each new render).
|
2018-09-21 04:23:15 +00:00
|
|
|
std::vector< int > m_blockPositionsWasProcessed;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
///< Encode the Morton code positions (on fast preview mode).
|
2016-07-19 17:35:25 +00:00
|
|
|
std::vector< SFVEC2UI > m_blockPositionsFast;
|
|
|
|
|
|
|
|
SFVEC2UI m_realBufferSize;
|
|
|
|
SFVEC2UI m_fastPreviewModeSize;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
HITINFO_PACKET* m_firstHitinfo;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F* m_shaderBuffer;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Display Offset
|
|
|
|
unsigned int m_xoffset;
|
|
|
|
unsigned int m_yoffset;
|
|
|
|
|
|
|
|
/// Stores materials of the 3D models
|
2021-01-07 19:33:43 +00:00
|
|
|
MAP_MODEL_MATERIALS m_modelMaterialMap;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
// Statistics
|
2021-01-07 19:33:43 +00:00
|
|
|
unsigned int m_convertedDummyBlockCount;
|
|
|
|
unsigned int m_converted2dRoundSegmentCount;
|
2016-07-19 17:35:25 +00:00
|
|
|
};
|
|
|
|
|
2016-11-26 14:38:51 +00:00
|
|
|
#define USE_SRGB_SPACE
|
|
|
|
|
|
|
|
#ifdef USE_SRGB_SPACE
|
2021-01-02 21:05:29 +00:00
|
|
|
extern SFVEC3F ConvertSRGBToLinear( const SFVEC3F& aSRGBcolor );
|
2016-11-26 14:38:51 +00:00
|
|
|
#else
|
2021-01-02 21:05:29 +00:00
|
|
|
#define ConvertSRGBToLinear( v ) ( v )
|
2016-11-26 14:38:51 +00:00
|
|
|
#endif
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
#endif // RENDER_3D_RAYTRACE_H
|