File: c3d_render_raytracing.h

package info (click to toggle)
kicad 5.0.2%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 234,592 kB
  • sloc: cpp: 505,330; ansic: 57,038; python: 4,886; sh: 879; awk: 294; makefile: 253; xml: 103; perl: 5
file content (218 lines) | stat: -rw-r--r-- 7,128 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
 * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * 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
 */

/**
 * @file  c3d_render_raytracing.h
 * @brief
 */

#ifndef C3D_RENDER_RAYTRACING_H
#define C3D_RENDER_RAYTRACING_H

#include "../../common_ogl/openGL_includes.h"
#include "accelerators/ccontainer.h"
#include "accelerators/caccelerator.h"
#include "../c3d_render_base.h"
#include "clight.h"
#include "../cpostshader_ssao.h"
#include "cmaterial.h"
#include <plugins/3dapi/c3dmodel.h>

#include <map>

/// Vector of materials
typedef std::vector< CBLINN_PHONG_MATERIAL > MODEL_MATERIALS;

/// Maps a S3DMODEL pointer with a created CBLINN_PHONG_MATERIAL vector
typedef std::map< const S3DMODEL * , MODEL_MATERIALS > MAP_MODEL_MATERIALS;

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
}RT_RENDER_STATE;

class C3D_RENDER_RAYTRACING : public C3D_RENDER_BASE
{
public:
    explicit C3D_RENDER_RAYTRACING( CINFO3D_VISU &aSettings );

    ~C3D_RENDER_RAYTRACING();

    // Imported from C3D_RENDER_BASE
    void SetCurWindowSize( const wxSize &aSize ) override;
    bool Redraw(bool aIsMoving, REPORTER *aStatusTextReporter ) override;

    int GetWaitForEditingTimeOut() override;

private:
    bool initializeOpenGL();
    void initializeNewWindowSize();
    void opengl_init_pbo();
    void opengl_delete_pbo();
    void reload( REPORTER *aStatusTextReporter );

    void restart_render_state();
    void rt_render_tracing( GLubyte *ptrPBO , REPORTER *aStatusTextReporter );
    void rt_render_post_process_shade( GLubyte *ptrPBO , REPORTER *aStatusTextReporter );
    void rt_render_post_process_blur_finish( GLubyte *ptrPBO , REPORTER *aStatusTextReporter );
    void rt_render_trace_block( GLubyte *ptrPBO , signed int iBlock );
    void rt_final_color( GLubyte *ptrPBO, const SFVEC3F &rgbColor, bool applyColorSpaceConversion );

    void rt_shades_packet( const SFVEC3F *bgColorY,
                           const RAY *aRayPkt,
                           HITINFO_PACKET *aHitPacket,
                           bool is_testShadow,
                           SFVEC3F *aOutHitColor );

    void rt_trace_AA_packet( const SFVEC3F *aBgColorY,
                             const HITINFO_PACKET *aHitPck_X0Y0,
                             const HITINFO_PACKET *aHitPck_AA_X1Y1,
                             const RAY *aRayPck,
                             SFVEC3F *aOutHitColor );

    // Materials
    void setupMaterials();

    struct
    {
        CBLINN_PHONG_MATERIAL m_Paste;
        CBLINN_PHONG_MATERIAL m_SilkS;
        CBLINN_PHONG_MATERIAL m_SolderMask;
        CBLINN_PHONG_MATERIAL m_EpoxyBoard;
        CBLINN_PHONG_MATERIAL m_Copper;
        CBLINN_PHONG_MATERIAL m_Floor;
    }m_materials;

    CBOARDNORMAL        m_board_normal_perturbator;
    CCOPPERNORMAL       m_copper_normal_perturbator;
    CSOLDERMASKNORMAL   m_solder_mask_normal_perturbator;
    CPLASTICNORMAL      m_plastic_normal_perturbator;
    CPLASTICSHINENORMAL m_plastic_shine_normal_perturbator;
    CMETALBRUSHEDNORMAL m_brushed_metal_normal_perturbator;

    bool m_isPreview;

    SFVEC3F shadeHit( const SFVEC3F &aBgColor,
                      const RAY &aRay,
                      HITINFO &aHitInfo,
                      bool aIsInsideObject,
                      unsigned int aRecursiveLevel,
                      bool is_testShadow ) const;

    /// State used on quality render
    RT_RENDER_STATE m_rt_render_state;

    /// Time that the render starts
    unsigned long int m_stats_start_rendering_time;

    /// Save the number of blocks progress of the render
    size_t m_nrBlocksRenderProgress;

    CPOSTSHADER_SSAO m_postshader_ssao;

    CLIGHTCONTAINER m_lights;

    CDIRECTIONALLIGHT *m_camera_light;

    bool m_opengl_support_vertex_buffer_object;
    GLuint m_pboId;
    GLuint m_pboDataSize;

    CCONTAINER m_object_container;

    /// This will store the list of created objects special for RT,
    /// that will be clear in the end
    CCONTAINER2D m_containerWithObjectsToDelete;

    CCONTAINER2D *m_outlineBoard2dObjects;

    CGENERICACCELERATOR *m_accelerator;

    SFVEC3F m_BgColorTop_LinearRGB;
    SFVEC3F m_BgColorBot_LinearRGB;

    // Morton codes

    /// used to see if the windows size changed
    wxSize m_oldWindowsSize;

    /// this encodes the Morton code positions
    std::vector< SFVEC2UI > m_blockPositions;

    /// this flags if a position was already processed (cleared each new render)
    std::vector< int > m_blockPositionsWasProcessed;

    /// this encodes the Morton code positions (on fast preview mode)
    std::vector< SFVEC2UI > m_blockPositionsFast;

    SFVEC2UI m_realBufferSize;
    SFVEC2UI m_fastPreviewModeSize;

    HITINFO_PACKET *m_firstHitinfo;

    SFVEC3F *m_shaderBuffer;

    // Display Offset
    unsigned int m_xoffset;
    unsigned int m_yoffset;

    // Statistics
    unsigned int m_stats_converted_dummy_to_plane;
    unsigned int m_stats_converted_roundsegment2d_to_roundsegment;

    void create_3d_object_from( CCONTAINER &aDstContainer,
                                const COBJECT2D *aObject2D,
                                float aZMin, float aZMax,
                                const CMATERIAL *aMaterial,
                                const SFVEC3F &aObjColor );

    void add_3D_vias_and_pads_to_container();
    void insert3DViaHole( const VIA* aVia );
    void insert3DPadHole( const D_PAD* aPad );
    void load_3D_models();
    void add_3D_models( const S3DMODEL *a3DModel,
                        const glm::mat4 &aModelMatrix );

    /// Stores materials of the 3D models
    MAP_MODEL_MATERIALS m_model_materials;

    void initialize_block_positions();

    void render( GLubyte *ptrPBO, REPORTER *aStatusTextReporter );
    void render_preview( GLubyte *ptrPBO );
};

#define USE_SRGB_SPACE

#ifdef USE_SRGB_SPACE
extern SFVEC3F ConvertSRGBToLinear( const SFVEC3F &aSRGBcolor );
#else
#define ConvertSRGBToLinear(v) (v)
#endif

#endif // C3D_RENDER_RAYTRACING_H