0029076: Visualization - implement element shrinking Shader
[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   //! If not specified otherwise, the counter value is computed for a single rendered frame.
50   enum PerfCounters
51   {
52     PerfCounters_NONE        = 0x000, //!< no stats
53     PerfCounters_FrameRate   = 0x001, //!< Frame Rate,        frames per second (number of frames within elapsed time)
54     PerfCounters_CPU         = 0x002, //!< CPU utilization as frames per second (number of frames within CPU utilization time (rendering thread))
55     PerfCounters_Layers      = 0x004, //!< count layers (groups of structures)
56     PerfCounters_Structures  = 0x008, //!< count low-level Structures (normal unhighlighted Presentable Object is usually represented by 1 Structure)
57     //
58     PerfCounters_Groups      = 0x010, //!< count primitive Groups (1 Structure holds 1 or more primitive Group)
59     PerfCounters_GroupArrays = 0x020, //!< count Arrays within Primitive Groups (optimal primitive Group holds 1 Array)
60     //
61     PerfCounters_Triangles   = 0x040, //!< count Triangles
62     PerfCounters_Points      = 0x080, //!< count Points
63     //
64     PerfCounters_EstimMem    = 0x100, //!< estimated GPU memory usage
65     //
66     PerfCounters_FrameTime   = 0x200, //!< frame CPU utilization time (rendering thread); @sa Graphic3d_FrameStatsTimer
67     PerfCounters_FrameTimeMax= 0x400, //!< maximum frame times
68     //
69     PerfCounters_SkipImmediate = 0x800, //!< do not include immediate viewer updates (e.g. lazy updates without redrawing entire view content)
70     //! show basic statistics
71     PerfCounters_Basic = PerfCounters_FrameRate | PerfCounters_CPU | PerfCounters_Layers | PerfCounters_Structures,
72     //! extended (verbose) statistics
73     PerfCounters_Extended = PerfCounters_Basic
74                           | PerfCounters_Groups | PerfCounters_GroupArrays
75                           | PerfCounters_Triangles | PerfCounters_Points
76                           | PerfCounters_EstimMem,
77     //! all counters
78     PerfCounters_All = PerfCounters_Extended
79                      | PerfCounters_FrameTime
80                      | PerfCounters_FrameTimeMax,
81   };
82
83   //! State of frustum culling optimization.
84   enum FrustumCulling
85   {
86     FrustumCulling_Off,     //!< culling is disabled
87     FrustumCulling_On,      //!< culling is active, and the list of culled entities is automatically updated before redraw
88     FrustumCulling_NoUpdate //!< culling is active, but the list of culled entities is not updated
89   };
90
91 public:
92
93   //! Creates default rendering parameters.
94   Graphic3d_RenderingParams()
95   : Method                      (Graphic3d_RM_RASTERIZATION),
96     TransparencyMethod          (Graphic3d_RTM_BLEND_UNORDERED),
97     LineFeather                 (1.0f),
98     OitDepthFactor              (0.0f),
99     NbMsaaSamples               (0),
100     RenderResolutionScale       (1.0f),
101     ToEnableDepthPrepass        (Standard_False),
102     ToEnableAlphaToCoverage     (Standard_True),
103     // ray tracing parameters
104     IsGlobalIlluminationEnabled (Standard_False),
105     RaytracingDepth             (THE_DEFAULT_DEPTH),
106     IsShadowEnabled             (Standard_True),
107     IsReflectionEnabled         (Standard_False),
108     IsAntialiasingEnabled       (Standard_False),
109     IsTransparentShadowEnabled  (Standard_False),
110     UseEnvironmentMapBackground (Standard_False),
111     CoherentPathTracingMode     (Standard_False),
112     AdaptiveScreenSampling      (Standard_False),
113     AdaptiveScreenSamplingAtomic(Standard_False),
114     ShowSamplingTiles           (Standard_False),
115     TwoSidedBsdfModels          (Standard_False),
116     RadianceClampingValue       (30.0),
117     RebuildRayTracingShaders    (Standard_False),
118     RayTracingTileSize          (32),
119     NbRayTracingTiles           (16 * 16),
120     CameraApertureRadius        (0.0f),
121     CameraFocalPlaneDist        (1.0f),
122     FrustumCullingState         (FrustumCulling_On),
123     ToneMappingMethod           (Graphic3d_ToneMappingMethod_Disabled),
124     Exposure                    (0.f),
125     WhitePoint                  (1.f),
126     // stereoscopic parameters
127     StereoMode (Graphic3d_StereoMode_QuadBuffer),
128     AnaglyphFilter (Anaglyph_RedCyan_Optimized),
129     ToReverseStereo (Standard_False),
130     //
131     StatsPosition (new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_UPPER,  Graphic3d_Vec2i (20, 20))),
132     ChartPosition (new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_RIGHT_UPPER, Graphic3d_Vec2i (20, 20))),
133     ChartSize (-1, -1),
134     StatsTextAspect (new Graphic3d_AspectText3d()),
135     StatsUpdateInterval (1.0),
136     StatsTextHeight (16),
137     StatsNbFrames (1),
138     StatsMaxChartTime (0.1f),
139     CollectedStats (PerfCounters_Basic),
140     ToShowStats (Standard_False),
141     //
142     Resolution (THE_DEFAULT_RESOLUTION)
143   {
144     const Graphic3d_Vec4 aZero (0.0f, 0.0f, 0.0f, 0.0f);
145     AnaglyphLeft .SetRow (0, Graphic3d_Vec4 (1.0f,  0.0f,  0.0f, 0.0f));
146     AnaglyphLeft .SetRow (1, aZero);
147     AnaglyphLeft .SetRow (2, aZero);
148     AnaglyphLeft .SetRow (3, aZero);
149     AnaglyphRight.SetRow (0, aZero);
150     AnaglyphRight.SetRow (1, Graphic3d_Vec4 (0.0f,  1.0f,  0.0f, 0.0f));
151     AnaglyphRight.SetRow (2, Graphic3d_Vec4 (0.0f,  0.0f,  1.0f, 0.0f));
152     AnaglyphRight.SetRow (3, aZero);
153
154     StatsTextAspect->SetColor (Quantity_NOC_WHITE);
155     StatsTextAspect->SetColorSubTitle (Quantity_NOC_BLACK);
156     StatsTextAspect->SetFont (Font_NOF_ASCII_MONO);
157     StatsTextAspect->SetDisplayType (Aspect_TODT_SHADOW);
158     StatsTextAspect->SetTextZoomable (Standard_False);
159     StatsTextAspect->SetTextFontAspect (Font_FA_Regular);
160   }
161
162   //! Returns resolution ratio.
163   Standard_ShortReal ResolutionRatio() const
164   {
165     return Resolution / static_cast<Standard_ShortReal> (THE_DEFAULT_RESOLUTION);
166   }
167
168 public:
169
170   Graphic3d_RenderingMode           Method;                      //!< specifies rendering mode, Graphic3d_RM_RASTERIZATION by default
171   Graphic3d_RenderTransparentMethod TransparencyMethod;          //!< specifies rendering method for transparent graphics
172   Standard_ShortReal                LineFeather;                 //!< line feater width in pixels (> 0.0), 1.0 by default;
173                                                                  //!  high values produce blurred results, small values produce sharp (aliased) edges
174   Standard_ShortReal                OitDepthFactor;              //!< scalar factor [0-1] controlling influence of depth of a fragment to its final coverage
175   Standard_Integer                  NbMsaaSamples;               //!< number of MSAA samples (should be within 0..GL_MAX_SAMPLES, power-of-two number), 0 by default
176   Standard_ShortReal                RenderResolutionScale;       //!< rendering resolution scale factor, 1 by default;
177                                                                  //!  incompatible with MSAA (e.g. NbMsaaSamples should be set to 0)
178   Standard_Boolean                  ToEnableDepthPrepass;        //!< enables/disables depth pre-pass, False by default
179   Standard_Boolean                  ToEnableAlphaToCoverage;     //!< enables/disables alpha to coverage, True by default
180
181   Standard_Boolean                  IsGlobalIlluminationEnabled; //!< enables/disables global illumination effects (path tracing)
182   Standard_Integer                  SamplesPerPixel;             //!< number of samples per pixel (SPP)
183   Standard_Integer                  RaytracingDepth;             //!< maximum ray-tracing depth, 3 by default
184   Standard_Boolean                  IsShadowEnabled;             //!< enables/disables shadows rendering, True by default
185   Standard_Boolean                  IsReflectionEnabled;         //!< enables/disables specular reflections, False by default
186   Standard_Boolean                  IsAntialiasingEnabled;       //!< enables/disables adaptive anti-aliasing, False by default
187   Standard_Boolean                  IsTransparentShadowEnabled;  //!< enables/disables light propagation through transparent media, False by default
188   Standard_Boolean                  UseEnvironmentMapBackground; //!< enables/disables environment map background
189   Standard_Boolean                  CoherentPathTracingMode;     //!< enables/disables 'coherent' tracing mode (single RNG seed within 16x16 image blocks)
190   Standard_Boolean                  AdaptiveScreenSampling;      //!< enables/disables adaptive screen sampling mode for path tracing, FALSE by default
191   Standard_Boolean                  AdaptiveScreenSamplingAtomic;//!< enables/disables usage of atomic float operations within adaptive screen sampling, FALSE by default
192   Standard_Boolean                  ShowSamplingTiles;           //!< enables/disables debug mode for adaptive screen sampling, FALSE by default
193   Standard_Boolean                  TwoSidedBsdfModels;          //!< forces path tracing to use two-sided versions of original one-sided scattering models
194   Standard_ShortReal                RadianceClampingValue;       //!< maximum radiance value used for clamping radiance estimation.
195   Standard_Boolean                  RebuildRayTracingShaders;    //!< forces rebuilding ray tracing shaders at the next frame
196   Standard_Integer                  RayTracingTileSize;          //!< screen tile size, 32 by default (adaptive sampling mode of path tracing);
197   Standard_Integer                  NbRayTracingTiles;           //!< maximum number of screen tiles per frame, 256 by default (adaptive sampling mode of path tracing);
198                                                                  //!  this parameter limits the number of tiles to be rendered per redraw, increasing Viewer interactivity,
199                                                                  //!  but also increasing the time for achieving a good quality; -1 means no limit
200   Standard_ShortReal                CameraApertureRadius;        //!< aperture radius of perspective camera used for depth-of-field, 0.0 by default (no DOF) (path tracing only)
201   Standard_ShortReal                CameraFocalPlaneDist;        //!< focal  distance of perspective camera used for depth-of field, 1.0 by default (path tracing only)
202   FrustumCulling                    FrustumCullingState;         //!< state of frustum culling optimization; FrustumCulling_On by default
203
204   Graphic3d_ToneMappingMethod       ToneMappingMethod;           //!< specifies tone mapping method for path tracing, Graphic3d_ToneMappingMethod_Disabled by default
205   Standard_ShortReal                Exposure;                    //!< exposure value used for tone mapping (path tracing), 0.0 by default
206   Standard_ShortReal                WhitePoint;                  //!< white point value used in filmic tone mapping (path tracing), 1.0 by default
207
208   Graphic3d_StereoMode              StereoMode;                  //!< stereoscopic output mode, Graphic3d_StereoMode_QuadBuffer by default
209   Anaglyph                          AnaglyphFilter;              //!< filter for anaglyph output, Anaglyph_RedCyan_Optimized by default
210   Graphic3d_Mat4                    AnaglyphLeft;                //!< left  anaglyph filter (in normalized colorspace), Color = AnaglyphRight * theColorRight + AnaglyphLeft * theColorLeft;
211   Graphic3d_Mat4                    AnaglyphRight;               //!< right anaglyph filter (in normalized colorspace), Color = AnaglyphRight * theColorRight + AnaglyphLeft * theColorLeft;
212   Standard_Boolean                  ToReverseStereo;             //!< flag to reverse stereo pair, FALSE by default
213
214   Handle(Graphic3d_TransformPers)   StatsPosition;               //!< location of stats, upper-left position by default
215   Handle(Graphic3d_TransformPers)   ChartPosition;               //!< location of stats chart, upper-right position by default
216   Graphic3d_Vec2i                   ChartSize;                   //!< chart size in pixels, (-1, -1) by default which means that chart will occupy a portion of viewport
217   Handle(Graphic3d_AspectText3d)    StatsTextAspect;             //!< stats text aspect
218   Standard_ShortReal                StatsUpdateInterval;         //!< time interval between stats updates in seconds, 1.0 second by default;
219                                                                  //!  too often updates might impact performance and will smear text within widgets
220                                                                  //!  (especially framerate, which is better averaging);
221                                                                  //!  0.0 interval will force updating on each frame
222   Standard_Integer                  StatsTextHeight;             //!< stats text size; 16 by default
223   Standard_Integer                  StatsNbFrames;               //!< number of data frames to collect history; 1 by default
224   Standard_ShortReal                StatsMaxChartTime;           //!< upper time limit within frame chart in seconds; 0.1 seconds by default (100 ms or 10 FPS)
225   PerfCounters                      CollectedStats;              //!< performance counters to collect, PerfCounters_Basic by default;
226                                                                  //!  too verbose options might impact rendering performance,
227                                                                  //!  because some counters might lack caching optimization (and will require expensive iteration through all data structures)
228   Standard_Boolean                  ToShowStats;                 //!< display performance statistics, FALSE by default;
229                                                                  //!  note that counters specified within CollectedStats will be updated nevertheless
230                                                                  //!  of visibility of widget managed by ToShowStats flag (e.g. stats can be retrieved by application for displaying using other methods)
231
232   unsigned int                      Resolution;                  //!< Pixels density (PPI), defines scaling factor for parameters like text size
233                                                                  //!  (when defined in screen-space units rather than in 3D) to be properly displayed
234                                                                  //!  on device (screen / printer). 72 is default value.
235                                                                  //!  Note that using difference resolution in different Views in same Viewer
236                                                                  //!  will lead to performance regression (for example, text will be recreated every time).
237 };
238
239 #endif // _Graphic3d_RenderingParams_HeaderFile