17f4913bcd98d9dcfc183d2e8ad3f7857d28626b
[occt.git] / src / Graphic3d / Graphic3d_RenderingParams.hxx
1 // Created on: 2014-05-14
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _Graphic3d_RenderingParams_HeaderFile
17 #define _Graphic3d_RenderingParams_HeaderFile
18
19 #include <Graphic3d_AspectText3d.hxx>
20 #include <Graphic3d_TransformPers.hxx>
21 #include <Graphic3d_RenderTransparentMethod.hxx>
22 #include <Graphic3d_RenderingMode.hxx>
23 #include <Graphic3d_StereoMode.hxx>
24 #include <Graphic3d_ToneMappingMethod.hxx>
25 #include <Graphic3d_Vec4.hxx>
26
27 //! Helper class to store rendering parameters.
28 class Graphic3d_RenderingParams
29 {
30 public:
31   //! Default pixels density.
32   static const unsigned int THE_DEFAULT_RESOLUTION = 72u;
33
34   //! Default ray-tracing depth.
35   static const Standard_Integer THE_DEFAULT_DEPTH = 3;
36
37   //! Anaglyph filter presets.
38   enum Anaglyph
39   {
40     Anaglyph_RedCyan_Simple,       //!< simple    filter for Red-Cyan      glasses (R+GB)
41     Anaglyph_RedCyan_Optimized,    //!< optimized filter for Red-Cyan      glasses (R+GB)
42     Anaglyph_YellowBlue_Simple,    //!< simple    filter for Yellow-Blue   glasses (RG+B)
43     Anaglyph_YellowBlue_Optimized, //!< optimized filter for Yellow-Blue   glasses (RG+B)
44     Anaglyph_GreenMagenta_Simple,  //!< simple    filter for Green-Magenta glasses (G+RB)
45     Anaglyph_UserDefined           //!< use externally specified matrices
46   };
47
48   //! Statistics display flags.
49   enum PerfCounters
50   {
51     PerfCounters_NONE        = 0x000, //!< no stats
52     PerfCounters_FrameRate   = 0x001, //!< Frame Rate
53     PerfCounters_CPU         = 0x002, //!< CPU utilization
54     PerfCounters_Layers      = 0x004, //!< count layers (groups of structures)
55     PerfCounters_Structures  = 0x008, //!< count low-level Structures (normal unhighlighted Presentable Object is usually represented by 1 Structure)
56     //
57     PerfCounters_Groups      = 0x010, //!< count primitive Groups (1 Structure holds 1 or more primitive Group)
58     PerfCounters_GroupArrays = 0x020, //!< count Arrays within Primitive Groups (optimal primitive Group holds 1 Array)
59     //
60     PerfCounters_Triangles   = 0x040, //!< count Triangles
61     PerfCounters_Points      = 0x080, //!< count Points
62     //
63     PerfCounters_EstimMem    = 0x100, //!< estimated GPU memory usage
64     //! show basic statistics
65     PerfCounters_Basic = PerfCounters_FrameRate | PerfCounters_CPU | PerfCounters_Layers | PerfCounters_Structures,
66     //! extended (verbose) statistics
67     PerfCounters_Extended = PerfCounters_Basic
68                           | PerfCounters_Groups | PerfCounters_GroupArrays
69                           | PerfCounters_Triangles | PerfCounters_Points
70                           | PerfCounters_EstimMem,
71   };
72
73 public:
74
75   //! Creates default rendering parameters.
76   Graphic3d_RenderingParams()
77   : Method                      (Graphic3d_RM_RASTERIZATION),
78     TransparencyMethod          (Graphic3d_RTM_BLEND_UNORDERED),
79     OitDepthFactor              (0.0f),
80     NbMsaaSamples               (0),
81     RenderResolutionScale       (1.0f),
82     ToEnableDepthPrepass        (Standard_False),
83     // ray tracing parameters
84     IsGlobalIlluminationEnabled (Standard_False),
85     RaytracingDepth             (THE_DEFAULT_DEPTH),
86     IsShadowEnabled             (Standard_True),
87     IsReflectionEnabled         (Standard_False),
88     IsAntialiasingEnabled       (Standard_False),
89     IsTransparentShadowEnabled  (Standard_False),
90     UseEnvironmentMapBackground (Standard_False),
91     CoherentPathTracingMode     (Standard_False),
92     AdaptiveScreenSampling      (Standard_False),
93     ShowSamplingTiles           (Standard_False),
94     TwoSidedBsdfModels          (Standard_False),
95     RadianceClampingValue       (30.0),
96     RebuildRayTracingShaders    (Standard_False),
97     NbRayTracingTiles           (16 * 16),
98     CameraApertureRadius        (0.0f),
99     CameraFocalPlaneDist        (1.0f),
100     ToneMappingMethod           (Graphic3d_ToneMappingMethod_Disabled),
101     Exposure                    (0.f),
102     WhitePoint                  (1.f),
103     // stereoscopic parameters
104     StereoMode (Graphic3d_StereoMode_QuadBuffer),
105     AnaglyphFilter (Anaglyph_RedCyan_Optimized),
106     ToReverseStereo (Standard_False),
107     //
108     StatsPosition (new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_UPPER, Graphic3d_Vec2i (20, 20))),
109     StatsTextAspect (new Graphic3d_AspectText3d()),
110     StatsUpdateInterval (1.0),
111     StatsTextHeight (16),
112     CollectedStats (PerfCounters_Basic),
113     ToShowStats (Standard_False),
114     //
115     Resolution (THE_DEFAULT_RESOLUTION)
116   {
117     const Graphic3d_Vec4 aZero (0.0f, 0.0f, 0.0f, 0.0f);
118     AnaglyphLeft .SetRow (0, Graphic3d_Vec4 (1.0f,  0.0f,  0.0f, 0.0f));
119     AnaglyphLeft .SetRow (1, aZero);
120     AnaglyphLeft .SetRow (2, aZero);
121     AnaglyphLeft .SetRow (3, aZero);
122     AnaglyphRight.SetRow (0, aZero);
123     AnaglyphRight.SetRow (1, Graphic3d_Vec4 (0.0f,  1.0f,  0.0f, 0.0f));
124     AnaglyphRight.SetRow (2, Graphic3d_Vec4 (0.0f,  0.0f,  1.0f, 0.0f));
125     AnaglyphRight.SetRow (3, aZero);
126
127     StatsTextAspect->SetColor (Quantity_NOC_WHITE);
128     StatsTextAspect->SetColorSubTitle (Quantity_NOC_BLACK);
129     StatsTextAspect->SetFont (Font_NOF_ASCII_MONO);
130     StatsTextAspect->SetDisplayType (Aspect_TODT_SHADOW);
131     StatsTextAspect->SetTextZoomable (Standard_False);
132     StatsTextAspect->SetTextFontAspect (Font_FA_Regular);
133   }
134
135   //! Returns resolution ratio.
136   Standard_ShortReal ResolutionRatio() const
137   {
138     return Resolution / static_cast<Standard_ShortReal> (THE_DEFAULT_RESOLUTION);
139   }
140
141 public:
142
143   Graphic3d_RenderingMode           Method;                      //!< specifies rendering mode, Graphic3d_RM_RASTERIZATION by default
144   Graphic3d_RenderTransparentMethod TransparencyMethod;          //!< specifies rendering method for transparent graphics
145   Standard_ShortReal                OitDepthFactor;              //!< scalar factor [0-1] controlling influence of depth of a fragment to its final coverage
146   Standard_Integer                  NbMsaaSamples;               //!< number of MSAA samples (should be within 0..GL_MAX_SAMPLES, power-of-two number), 0 by default
147   Standard_ShortReal                RenderResolutionScale;       //!< rendering resolution scale factor, 1 by default;
148                                                                  //!  incompatible with MSAA (e.g. NbMsaaSamples should be set to 0)
149   Standard_Boolean                  ToEnableDepthPrepass;        //!< enables/disables depth pre-pass, False by default
150
151   Standard_Boolean                  IsGlobalIlluminationEnabled; //!< enables/disables global illumination effects (path tracing)
152   Standard_Integer                  SamplesPerPixel;             //!< number of samples per pixel (SPP)
153   Standard_Integer                  RaytracingDepth;             //!< maximum ray-tracing depth, 3 by default
154   Standard_Boolean                  IsShadowEnabled;             //!< enables/disables shadows rendering, True by default
155   Standard_Boolean                  IsReflectionEnabled;         //!< enables/disables specular reflections, False by default
156   Standard_Boolean                  IsAntialiasingEnabled;       //!< enables/disables adaptive anti-aliasing, False by default
157   Standard_Boolean                  IsTransparentShadowEnabled;  //!< enables/disables light propagation through transparent media, False by default
158   Standard_Boolean                  UseEnvironmentMapBackground; //!< enables/disables environment map background
159   Standard_Boolean                  CoherentPathTracingMode;     //!< enables/disables 'coherent' tracing mode (single RNG seed within 16x16 image blocks)
160   Standard_Boolean                  AdaptiveScreenSampling;      //!< enables/disables adaptive screen sampling mode for path tracing, FALSE by default
161   Standard_Boolean                  ShowSamplingTiles;           //!< enables/disables debug mode for adaptive screen sampling, FALSE by default
162   Standard_Boolean                  TwoSidedBsdfModels;          //!< forces path tracing to use two-sided versions of original one-sided scattering models
163   Standard_ShortReal                RadianceClampingValue;       //!< maximum radiance value used for clamping radiance estimation.
164   Standard_Boolean                  RebuildRayTracingShaders;    //!< forces rebuilding ray tracing shaders at the next frame
165   Standard_Integer                  NbRayTracingTiles;           //!< total number of screen tiles used in adaptive sampling mode (PT only)
166   Standard_ShortReal                CameraApertureRadius;        //!< aperture radius of perspective camera used for depth-of-field, 0.0 by default (no DOF) (path tracing only)
167   Standard_ShortReal                CameraFocalPlaneDist;        //!< focal  distance of perspective camera used for depth-of field, 1.0 by default (path tracing only)
168
169   Graphic3d_ToneMappingMethod       ToneMappingMethod;           //!< specifies tone mapping method for path tracing, Graphic3d_ToneMappingMethod_Disabled by default
170   Standard_ShortReal                Exposure;                    //!< exposure value used for tone mapping (path tracing), 0.0 by default
171   Standard_ShortReal                WhitePoint;                  //!< white point value used in filmic tone mapping (path tracing), 1.0 by default
172
173   Graphic3d_StereoMode              StereoMode;                  //!< stereoscopic output mode, Graphic3d_StereoMode_QuadBuffer by default
174   Anaglyph                          AnaglyphFilter;              //!< filter for anaglyph output, Anaglyph_RedCyan_Optimized by default
175   Graphic3d_Mat4                    AnaglyphLeft;                //!< left  anaglyph filter (in normalized colorspace), Color = AnaglyphRight * theColorRight + AnaglyphLeft * theColorLeft;
176   Graphic3d_Mat4                    AnaglyphRight;               //!< right anaglyph filter (in normalized colorspace), Color = AnaglyphRight * theColorRight + AnaglyphLeft * theColorLeft;
177   Standard_Boolean                  ToReverseStereo;             //!< flag to reverse stereo pair, FALSE by default
178
179   Handle(Graphic3d_TransformPers)   StatsPosition;               //!< location of stats, upper-left position by default
180   Handle(Graphic3d_AspectText3d)    StatsTextAspect;             //!< stats text aspect
181   Standard_ShortReal                StatsUpdateInterval;         //!< time interval between stats updates in seconds, 1.0 second by default;
182                                                                  //!  too often updates might impact performance and will smear text within widgets
183                                                                  //!  (especially framerate, which is better averaging);
184                                                                  //!  0.0 interval will force updating on each frame
185   Standard_Integer                  StatsTextHeight;             //!< stats text size; 16 by default
186   PerfCounters                      CollectedStats;              //!< performance counters to collect, PerfCounters_Basic by default;
187                                                                  //!  too verbose options might impact rendering performance,
188                                                                  //!  because some counters might lack caching optimization (and will require expensive iteration through all data structures)
189   Standard_Boolean                  ToShowStats;                 //!< display performance statistics, FALSE by default;
190                                                                  //!  note that counters specified within CollectedStats will be updated nevertheless
191                                                                  //!  of visibility of widget managed by ToShowStats flag (e.g. stats can be retrieved by application for displaying using other methods)
192
193   unsigned int                      Resolution;                  //!< Pixels density (PPI), defines scaling factor for parameters like text size
194                                                                  //!  (when defined in screen-space units rather than in 3D) to be properly displayed
195                                                                  //!  on device (screen / printer). 72 is default value.
196                                                                  //!  Note that using difference resolution in different Views in same Viewer
197                                                                  //!  will lead to performance regression (for example, text will be recreated every time).
198 };
199
200 #endif // _Graphic3d_RenderingParams_HeaderFile