1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkRenderer.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 /**
16 * @class vtkRenderer
17 * @brief abstract specification for renderers
18 *
19 * vtkRenderer provides an abstract specification for renderers. A renderer
20 * is an object that controls the rendering process for objects. Rendering
21 * is the process of converting geometry, a specification for lights, and
22 * a camera view into an image. vtkRenderer also performs coordinate
23 * transformation between world coordinates, view coordinates (the computer
24 * graphics rendering coordinate system), and display coordinates (the
25 * actual screen coordinates on the display device). Certain advanced
26 * rendering features such as two-sided lighting can also be controlled.
27 *
28 * @sa
29 * vtkRenderWindow vtkActor vtkCamera vtkLight vtkVolume
30 */
31
32 #ifndef vtkRenderer_h
33 #define vtkRenderer_h
34
35 #include "vtkRenderingCoreModule.h" // For export macro
36 #include "vtkViewport.h"
37
38 #include "vtkActorCollection.h" // Needed for access in inline members
39 #include "vtkVolumeCollection.h" // Needed for access in inline members
40
41 #include <array> // To store matrices
42
43 class vtkFXAAOptions;
44 class vtkRenderWindow;
45 class vtkVolume;
46 class vtkCuller;
47 class vtkActor;
48 class vtkActor2D;
49 class vtkCamera;
50 class vtkFrameBufferObjectBase;
51 class vtkInformation;
52 class vtkLightCollection;
53 class vtkCullerCollection;
54 class vtkLight;
55 class vtkHardwareSelector;
56 class vtkRendererDelegate;
57 class vtkRenderPass;
58 class vtkTexture;
59
60 class vtkRecti;
61 class vtkVector3d;
62
63 class VTKRENDERINGCORE_EXPORT vtkRenderer : public vtkViewport
64 {
65 public:
66 vtkTypeMacro(vtkRenderer, vtkViewport);
67 void PrintSelf(ostream& os, vtkIndent indent) override;
68
69 /**
70 * Create a vtkRenderer with a black background, a white ambient light,
71 * two-sided lighting turned on, a viewport of (0,0,1,1), and backface
72 * culling turned off.
73 */
74 static vtkRenderer* New();
75
76 ////@{
77 /**
78 * Add/Remove different types of props to the renderer.
79 * These methods are all synonyms to AddViewProp and RemoveViewProp.
80 * They are here for convenience and backwards compatibility.
81 */
82 void AddActor(vtkProp* p);
83 void AddVolume(vtkProp* p);
84 void RemoveActor(vtkProp* p);
85 void RemoveVolume(vtkProp* p);
86 ////@}
87
88 /**
89 * Add a light to the list of lights.
90 */
91 void AddLight(vtkLight*);
92
93 /**
94 * Remove a light from the list of lights.
95 */
96 void RemoveLight(vtkLight*);
97
98 /**
99 * Remove all lights from the list of lights.
100 */
101 void RemoveAllLights();
102
103 /**
104 * Return the collection of lights.
105 */
106 vtkLightCollection* GetLights();
107
108 /**
109 * Set the collection of lights.
110 * We cannot name it SetLights because of TestSetGet
111 * \pre lights_exist: lights!=0
112 * \post lights_set: lights==this->GetLights()
113 */
114 void SetLightCollection(vtkLightCollection* lights);
115
116 /**
117 * Create and add a light to renderer.
118 */
119 void CreateLight(void);
120
121 /**
122 * Create a new Light sutible for use with this type of Renderer.
123 * For example, a vtkMesaRenderer should create a vtkMesaLight
124 * in this function. The default is to just call vtkLight::New.
125 */
126 virtual vtkLight* MakeLight();
127
128 ////@{
129 /**
130 * Turn on/off two-sided lighting of surfaces. If two-sided lighting is
131 * off, then only the side of the surface facing the light(s) will be lit,
132 * and the other side dark. If two-sided lighting on, both sides of the
133 * surface will be lit.
134 */
135 vtkGetMacro(TwoSidedLighting, vtkTypeBool);
136 vtkSetMacro(TwoSidedLighting, vtkTypeBool);
137 vtkBooleanMacro(TwoSidedLighting, vtkTypeBool);
138 ////@}
139
140 ////@{
141 /**
142 * Turn on/off the automatic repositioning of lights as the camera moves.
143 * If LightFollowCamera is on, lights that are designated as Headlights
144 * or CameraLights will be adjusted to move with this renderer's camera.
145 * If LightFollowCamera is off, the lights will not be adjusted.
146
147 * (Note: In previous versions of vtk, this light-tracking
148 * functionality was part of the interactors, not the renderer. For
149 * backwards compatibility, the older, more limited interactor
150 * behavior is enabled by default. To disable this mode, turn the
151 * interactor's LightFollowCamera flag OFF, and leave the renderer's
152 * LightFollowCamera flag ON.)
153 */
154 vtkSetMacro(LightFollowCamera, vtkTypeBool);
155 vtkGetMacro(LightFollowCamera, vtkTypeBool);
156 vtkBooleanMacro(LightFollowCamera, vtkTypeBool);
157 ////@}
158
159 ////@{
160 /**
161 * Turn on/off a flag which disables the automatic light creation capability.
162 * Normally in VTK if no lights are associated with the renderer, then a light
163 * is automatically created. However, in special circumstances this feature is
164 * undesirable, so the following boolean is provided to disable automatic
165 * light creation. (Turn AutomaticLightCreation off if you do not want lights
166 * to be created.)
167 */
168 vtkGetMacro(AutomaticLightCreation, vtkTypeBool);
169 vtkSetMacro(AutomaticLightCreation, vtkTypeBool);
170 vtkBooleanMacro(AutomaticLightCreation, vtkTypeBool);
171 ////@}
172
173 /**
174 * Ask the lights in the scene that are not in world space
175 * (for instance, Headlights or CameraLights that are attached to the
176 * camera) to update their geometry to match the active camera.
177 */
178 virtual vtkTypeBool UpdateLightsGeometryToFollowCamera(void);
179
180 /**
181 * Return the collection of volumes.
182 */
183 vtkVolumeCollection* GetVolumes();
184
185 /**
186 * Return any actors in this renderer.
187 */
188 vtkActorCollection* GetActors();
189
190 /**
191 * Specify the camera to use for this renderer.
192 */
193 void SetActiveCamera(vtkCamera*);
194
195 /**
196 * Get the current camera. If there is not camera assigned to the
197 * renderer already, a new one is created automatically.
198 * This does *not* reset the camera.
199 */
200 vtkCamera* GetActiveCamera();
201
202 /**
203 * Create a new Camera sutible for use with this type of Renderer.
204 * For example, a vtkMesaRenderer should create a vtkMesaCamera
205 * in this function. The default is to just call vtkCamera::New.
206 */
207 virtual vtkCamera* MakeCamera();
208
209 ////@{
210 /**
211 * When this flag is off, the renderer will not erase the background
212 * or the Zbuffer. It is used to have overlapping renderers.
213 * Both the RenderWindow Erase and Render Erase must be on
214 * for the camera to clear the renderer. By default, Erase is on.
215 */
216 vtkSetMacro(Erase, vtkTypeBool);
217 vtkGetMacro(Erase, vtkTypeBool);
218 vtkBooleanMacro(Erase, vtkTypeBool);
219 ////@}
220
221 ////@{
222 /**
223 * When this flag is off, render commands are ignored. It is used to either
224 * multiplex a vtkRenderWindow or render only part of a vtkRenderWindow.
225 * By default, Draw is on.
226 */
227 vtkSetMacro(Draw, vtkTypeBool);
228 vtkGetMacro(Draw, vtkTypeBool);
229 vtkBooleanMacro(Draw, vtkTypeBool);
230 ////@}
231
232 /**
233 * This function is called to capture an instance of vtkProp that requires
234 * special handling during vtkRenderWindow::CaptureGL2PSSpecialProps().
235 */
236 int CaptureGL2PSSpecialProp(vtkProp*);
237
238 /**
239 * Set the prop collection object used during
240 * vtkRenderWindow::CaptureGL2PSSpecialProps(). Do not call manually, this
241 * is handled automatically by the render window.
242 */
243 void SetGL2PSSpecialPropCollection(vtkPropCollection*);
244
245 /**
246 * Add an culler to the list of cullers.
247 */
248 void AddCuller(vtkCuller*);
249
250 /**
251 * Remove an actor from the list of cullers.
252 */
253 void RemoveCuller(vtkCuller*);
254
255 /**
256 * Return the collection of cullers.
257 */
258 vtkCullerCollection* GetCullers();
259
260 ////@{
261 /**
262 * Set the intensity of ambient lighting.
263 */
264 vtkSetVector3Macro(Ambient, double);
265 vtkGetVectorMacro(Ambient, double, 3);
266 ////@}
267
268 ////@{
269 /**
270 * Set/Get the amount of time this renderer is allowed to spend
271 * rendering its scene. This is used by vtkLODActor's.
272 */
273 vtkSetMacro(AllocatedRenderTime, double);
274 virtual double GetAllocatedRenderTime();
275 ////@}
276
277 /**
278 * Get the ratio between allocated time and actual render time.
279 * TimeFactor has been taken out of the render process.
280 * It is still computed in case someone finds it useful.
281 * It may be taken away in the future.
282 */
283 virtual double GetTimeFactor();
284
285 /**
286 * CALLED BY vtkRenderWindow ONLY. End-user pass your way and call
287 * vtkRenderWindow::Render().
288 * Create an image. This is a superclass method which will in turn
289 * call the DeviceRender method of Subclasses of vtkRenderer.
290 */
291 virtual void Render();
292
293 /**
294 * Create an image. Subclasses of vtkRenderer must implement this method.
295 */
DeviceRender()296 virtual void DeviceRender(){};
297
298 /**
299 * Render opaque polygonal geometry. Default implementation just calls
300 * UpdateOpaquePolygonalGeometry().
301 * Subclasses of vtkRenderer that can deal with, e.g. hidden line removal must
302 * override this method.
303 */
304 virtual void DeviceRenderOpaqueGeometry(vtkFrameBufferObjectBase* fbo = nullptr);
305
306 /**
307 * Render translucent polygonal geometry. Default implementation just call
308 * UpdateTranslucentPolygonalGeometry().
309 * Subclasses of vtkRenderer that can deal with depth peeling must
310 * override this method.
311 * If UseDepthPeeling and UseDepthPeelingForVolumes are true, volumetric data
312 * will be rendered here as well.
313 * It updates boolean ivar LastRenderingUsedDepthPeeling.
314 */
315 virtual void DeviceRenderTranslucentPolygonalGeometry(vtkFrameBufferObjectBase* fbo = nullptr);
316
317 /**
318 * Internal method temporarily removes lights before reloading them
319 * into graphics pipeline.
320 */
ClearLights(void)321 virtual void ClearLights(void) {}
322
323 /**
324 * Clear the image to the background color.
325 */
Clear()326 virtual void Clear() {}
327
328 /**
329 * Returns the number of visible actors.
330 */
331 int VisibleActorCount();
332
333 /**
334 * Returns the number of visible volumes.
335 */
336 int VisibleVolumeCount();
337
338 /**
339 * Compute the bounding box of all the visible props
340 * Used in ResetCamera() and ResetCameraClippingRange()
341 */
342 void ComputeVisiblePropBounds(double bounds[6]);
343
344 /**
345 * Wrapper-friendly version of ComputeVisiblePropBounds
346 */
347 double* ComputeVisiblePropBounds() VTK_SIZEHINT(6);
348
349 /**
350 * Reset the camera clipping range based on the bounds of the
351 * visible actors. This ensures that no props are cut off
352 */
353 virtual void ResetCameraClippingRange();
354
355 ////@{
356 /**
357 * Reset the camera clipping range based on a bounding box.
358 */
359 virtual void ResetCameraClippingRange(const double bounds[6]);
360 virtual void ResetCameraClippingRange(
361 double xmin, double xmax, double ymin, double ymax, double zmin, double zmax);
362 ////@}
363
364 ////@{
365 /**
366 * Specify tolerance for near clipping plane distance to the camera as a
367 * percentage of the far clipping plane distance. By default this will be
368 * set to 0.01 for 16 bit zbuffers and 0.001 for higher depth z buffers
369 */
370 vtkSetClampMacro(NearClippingPlaneTolerance, double, 0, 0.99);
371 vtkGetMacro(NearClippingPlaneTolerance, double);
372 ////@}
373
374 ////@{
375 /**
376 * Specify enlargement of bounds when resetting the
377 * camera clipping range. By default the range is not expanded by
378 * any percent of the (far - near) on the near and far sides
379 */
380 vtkSetClampMacro(ClippingRangeExpansion, double, 0, 0.99);
381 vtkGetMacro(ClippingRangeExpansion, double);
382 ////@}
383
384 /**
385 * Automatically set up the camera based on the visible actors.
386 * The camera will reposition itself to view the center point of the actors,
387 * and move along its initial view plane normal (i.e., vector defined from
388 * camera position to focal point) so that all of the actors can be seen.
389 */
390 virtual void ResetCamera();
391
392 /**
393 * Automatically set up the camera based on a specified bounding box
394 * (xmin, xmax, ymin, ymax, zmin, zmax). Camera will reposition itself so
395 * that its focal point is the center of the bounding box, and adjust its
396 * distance and position to preserve its initial view plane normal
397 * (i.e., vector defined from camera position to focal point). Note: if
398 * the view plane is parallel to the view up axis, the view up axis will
399 * be reset to one of the three coordinate axes.
400 */
401 virtual void ResetCamera(const double bounds[6]);
402
403 /**
404 * Alternative version of ResetCamera(bounds[6]);
405 */
406 virtual void ResetCamera(
407 double xmin, double xmax, double ymin, double ymax, double zmin, double zmax);
408
409 /**
410 * Automatically set up the camera based on the visible actors.
411 * Use a screen space bounding box to zoom closer to the data.
412 */
413 virtual void ResetCameraScreenSpace();
414
415 /**
416 * Automatically set up the camera based on a specified bounding box
417 * (xmin, xmax, ymin, ymax, zmin, zmax).
418 * Use a screen space bounding box to zoom closer to the data.
419 */
420 virtual void ResetCameraScreenSpace(const double bounds[6]);
421
422 using vtkViewport::DisplayToWorld;
423
424 /**
425 * Convert a vtkVector3d from display space to world space.
426 */
427 vtkVector3d DisplayToWorld(const vtkVector3d& display);
428
429 /**
430 * Automatically set up the camera focal point and zoom factor to
431 * observe the \p box in display coordinates.
432 * \p OffsetRatio can be used to add a zoom offset.
433 */
434 void ZoomToBoxUsingViewAngle(const vtkRecti& box, const double offsetRatio = 1.0);
435
436 /**
437 * Alternative version of ResetCameraScreenSpace(bounds[6]);
438 */
439 virtual void ResetCameraScreenSpace(
440 double xmin, double xmax, double ymin, double ymax, double zmin, double zmax);
441
442 ////@{
443 /**
444 * Specify the rendering window in which to draw. This is automatically set
445 * when the renderer is created by MakeRenderer. The user probably
446 * shouldn't ever need to call this method.
447 */
448 void SetRenderWindow(vtkRenderWindow*);
GetRenderWindow()449 vtkRenderWindow* GetRenderWindow() { return this->RenderWindow; }
450 vtkWindow* GetVTKWindow() override;
451 ////@}
452
453 ////@{
454 /**
455 * Turn on/off using backing store. This may cause the re-rendering
456 * time to be slightly slower when the view changes. But it is
457 * much faster when the image has not changed, such as during an
458 * expose event.
459 */
460 vtkSetMacro(BackingStore, vtkTypeBool);
461 vtkGetMacro(BackingStore, vtkTypeBool);
462 vtkBooleanMacro(BackingStore, vtkTypeBool);
463 ////@}
464
465 ////@{
466 /**
467 * Turn on/off interactive status. An interactive renderer is one that
468 * can receive events from an interactor. Should only be set if
469 * there are multiple renderers in the same section of the viewport.
470 */
471 vtkSetMacro(Interactive, vtkTypeBool);
472 vtkGetMacro(Interactive, vtkTypeBool);
473 vtkBooleanMacro(Interactive, vtkTypeBool);
474 ////@}
475
476 ////@{
477 /**
478 * Set/Get the layer that this renderer belongs to. This is only used if
479 * there are layered renderers.
480
481 * Note: Changing the layer will update the PreserveColorBuffer setting. If
482 * the layer is 0, PreserveColorBuffer will be set to false, making the
483 * bottom renderer opaque. If the layer is non-zero, PreserveColorBuffer will
484 * be set to true, giving the renderer a transparent background. If other
485 * PreserveColorBuffer configurations are desired, they must be adjusted after
486 * the layer is set.
487 */
488 virtual void SetLayer(int layer);
489 vtkGetMacro(Layer, int);
490 ////@}
491
492 ////@{
493 /**
494 * By default, the renderer at layer 0 is opaque, and all non-zero layer
495 * renderers are transparent. This flag allows this behavior to be overridden.
496 * If true, this setting will force the renderer to preserve the existing
497 * color buffer regardless of layer. If false, it will always be cleared at
498 * the start of rendering.
499
500 * This flag influences the Transparent() method, and is updated by calls to
501 * SetLayer(). For this reason it should only be set after changing the layer.
502 */
503 vtkGetMacro(PreserveColorBuffer, vtkTypeBool);
504 vtkSetMacro(PreserveColorBuffer, vtkTypeBool);
505 vtkBooleanMacro(PreserveColorBuffer, vtkTypeBool);
506 ////@}
507
508 ////@{
509 /**
510 * By default, the depth buffer is reset for each renderer. If this flag is
511 * true, this renderer will use the existing depth buffer for its rendering.
512 */
513 vtkSetMacro(PreserveDepthBuffer, vtkTypeBool);
514 vtkGetMacro(PreserveDepthBuffer, vtkTypeBool);
515 vtkBooleanMacro(PreserveDepthBuffer, vtkTypeBool);
516 ////@}
517
518 /**
519 * Returns a boolean indicating if this renderer is transparent. It is
520 * transparent if it is not in the deepest layer of its render window.
521 */
522 int Transparent();
523
524 /**
525 * Convert world point coordinates to view coordinates.
526 */
527 void WorldToView() override;
528
529 ////@{
530 /**
531 * Convert view point coordinates to world coordinates.
532 */
533 void ViewToWorld() override;
534 void ViewToWorld(double& wx, double& wy, double& wz) override;
535 ////@}
536
537 /**
538 * Convert world point coordinates to view coordinates.
539 */
540 void WorldToView(double& wx, double& wy, double& wz) override;
541
542 ////@{
543 /**
544 * Convert to from pose coordinates
545 */
546 void WorldToPose(double& wx, double& wy, double& wz) override;
547 void PoseToWorld(double& wx, double& wy, double& wz) override;
548 void ViewToPose(double& wx, double& wy, double& wz) override;
549 void PoseToView(double& wx, double& wy, double& wz) override;
550 ////@}
551
552 /**
553 * Given a pixel location, return the Z value. The z value is
554 * normalized (0,1) between the front and back clipping planes.
555 */
556 double GetZ(int x, int y);
557
558 /**
559 * Return the MTime of the renderer also considering its ivars.
560 */
561 vtkMTimeType GetMTime() override;
562
563 ////@{
564 /**
565 * Get the time required, in seconds, for the last Render call.
566 */
567 vtkGetMacro(LastRenderTimeInSeconds, double);
568 ////@}
569
570 ////@{
571 /**
572 * Should be used internally only during a render
573 * Get the number of props that were rendered using a
574 * RenderOpaqueGeometry or RenderTranslucentPolygonalGeometry call.
575 * This is used to know if something is in the frame buffer.
576 */
577 vtkGetMacro(NumberOfPropsRendered, int);
578 ////@}
579
580 ////@{
581 /**
582 * Return the prop (via a vtkAssemblyPath) that has the highest z value
583 * at the given x, y position in the viewport. Basically, the top most
584 * prop that renders the pixel at selectionX, selectionY will be returned.
585 * If nothing was picked then NULL is returned. This method selects from
586 * the renderers Prop list.
587 */
PickProp(double selectionX,double selectionY)588 vtkAssemblyPath* PickProp(double selectionX, double selectionY) override
589 {
590 return this->PickProp(selectionX, selectionY, selectionX, selectionY);
591 }
592 vtkAssemblyPath* PickProp(
593 double selectionX1, double selectionY1, double selectionX2, double selectionY2) override;
594 ////@}
595
596 /**
597 * Do anything necessary between rendering the left and right viewpoints
598 * in a stereo render. Doesn't do anything except in the derived
599 * vtkIceTRenderer in ParaView.
600 */
StereoMidpoint()601 virtual void StereoMidpoint() { return; }
602
603 /**
604 * Compute the aspect ratio of this renderer for the current tile. When
605 * tiled displays are used the aspect ratio of the renderer for a given
606 * tile may be different that the aspect ratio of the renderer when rendered
607 * in it entirety
608 */
609 double GetTiledAspectRatio();
610
611 /**
612 * This method returns 1 if the ActiveCamera has already been set or
613 * automatically created by the renderer. It returns 0 if the
614 * ActiveCamera does not yet exist.
615 */
IsActiveCameraCreated()616 vtkTypeBool IsActiveCameraCreated() { return (this->ActiveCamera != nullptr); }
617
618 ////@{
619 /**
620 * Turn on/off rendering of translucent material with depth peeling
621 * technique. The render window must have alpha bits (ie call
622 * SetAlphaBitPlanes(1)) and no multisample buffer (ie call
623 * SetMultiSamples(0) ) to support depth peeling.
624 * If UseDepthPeeling is on and the GPU supports it, depth peeling is used
625 * for rendering translucent materials.
626 * If UseDepthPeeling is off, alpha blending is used.
627 * Initial value is off.
628 */
629 vtkSetMacro(UseDepthPeeling, vtkTypeBool);
630 vtkGetMacro(UseDepthPeeling, vtkTypeBool);
631 vtkBooleanMacro(UseDepthPeeling, vtkTypeBool);
632 ////@}
633
634 /**
635 * This flag is on and the GPU supports it, depth-peel volumes along with
636 * the translucent geometry. Only supported on OpenGL2 with dual-depth
637 * peeling. Default is false.
638 */
639 vtkSetMacro(UseDepthPeelingForVolumes, bool);
640 vtkGetMacro(UseDepthPeelingForVolumes, bool);
641 vtkBooleanMacro(UseDepthPeelingForVolumes, bool);
642
643 ////@{
644 /**
645 * In case of use of depth peeling technique for rendering translucent
646 * material, define the threshold under which the algorithm stops to
647 * iterate over peel layers. This is the ratio of the number of pixels
648 * that have been touched by the last layer over the total number of pixels
649 * of the viewport area.
650 * Initial value is 0.0, meaning rendering have to be exact. Greater values
651 * may speed-up the rendering with small impact on the quality.
652 */
653 vtkSetClampMacro(OcclusionRatio, double, 0.0, 0.5);
654 vtkGetMacro(OcclusionRatio, double);
655 ////@}
656
657 ////@{
658 /**
659 * In case of depth peeling, define the maximum number of peeling layers.
660 * Initial value is 4. A special value of 0 means no maximum limit.
661 * It has to be a positive value.
662 */
663 vtkSetMacro(MaximumNumberOfPeels, int);
664 vtkGetMacro(MaximumNumberOfPeels, int);
665 ////@}
666
667 ////@{
668 /**
669 * Tells if the last call to DeviceRenderTranslucentPolygonalGeometry()
670 * actually used depth peeling.
671 * Initial value is false.
672 */
673 vtkGetMacro(LastRenderingUsedDepthPeeling, vtkTypeBool);
674 ////@}
675
676 ////@{
677 /**
678 * Enable or disable Screen Space Ambient Occlusion.
679 * SSAO darkens some pixels to improve depth perception.
680 */
681 vtkSetMacro(UseSSAO, bool);
682 vtkGetMacro(UseSSAO, bool);
683 vtkBooleanMacro(UseSSAO, bool);
684 ////@}
685
686 ////@{
687 /**
688 * When using SSAO, define the SSAO hemisphere radius.
689 * Default is 0.5
690 */
691 vtkSetMacro(SSAORadius, double);
692 vtkGetMacro(SSAORadius, double);
693 ////@}
694
695 ////@{
696 /**
697 * When using SSAO, define the bias when comparing samples.
698 * Default is 0.01
699 */
700 vtkSetMacro(SSAOBias, double);
701 vtkGetMacro(SSAOBias, double);
702 ////@}
703
704 ////@{
705 /**
706 * When using SSAO, define the number of samples.
707 * Default is 32
708 */
709 vtkSetMacro(SSAOKernelSize, unsigned int);
710 vtkGetMacro(SSAOKernelSize, unsigned int);
711 ////@}
712
713 ////@{
714 /**
715 * When using SSAO, define blurring of the ambient occlusion.
716 * Blurring can help to improve the result if samples number is low.
717 * Default is false
718 */
719 vtkSetMacro(SSAOBlur, bool);
720 vtkGetMacro(SSAOBlur, bool);
721 vtkBooleanMacro(SSAOBlur, bool);
722 ////@}
723
724 ////@{
725 /**
726 * Set/Get a custom Render call. Allows to hook a Render call from an
727 * external project.It will be used in place of vtkRenderer::Render() if it
728 * is not NULL and its Used ivar is set to true.
729 * Initial value is NULL.
730 */
731 void SetDelegate(vtkRendererDelegate* d);
732 vtkGetObjectMacro(Delegate, vtkRendererDelegate);
733 ////@}
734
735 ////@{
736 /**
737 * Get the current hardware selector. If the Selector is set, it implies the
738 * current render pass is for selection. Mappers/Properties may choose to
739 * behave differently when rendering for hardware selection.
740 */
741 vtkGetObjectMacro(Selector, vtkHardwareSelector);
742 ////@}
743
744 ////@{
745 /**
746 * Set/Get the texture to be used for the monocular or stereo left eye
747 * background. If set and enabled this gets the priority over the gradient
748 * background.
749 */
750 virtual void SetLeftBackgroundTexture(vtkTexture*);
751 vtkTexture* GetLeftBackgroundTexture();
752 virtual void SetBackgroundTexture(vtkTexture*);
753 vtkGetObjectMacro(BackgroundTexture, vtkTexture);
754 ////@}
755
756 ////@{
757 /**
758 * Set/Get the texture to be used for the right eye background. If set
759 * and enabled this gets the priority over the gradient background.
760 */
761 virtual void SetRightBackgroundTexture(vtkTexture*);
762 vtkGetObjectMacro(RightBackgroundTexture, vtkTexture);
763 ////@}
764
765 ////@{
766 /**
767 * Set/Get whether this viewport should have a textured background.
768 * Default is off.
769 */
770 vtkSetMacro(TexturedBackground, bool);
771 vtkGetMacro(TexturedBackground, bool);
772 vtkBooleanMacro(TexturedBackground, bool);
773 ////@}
774
775 // method to release graphics resources in any derived renderers.
776 virtual void ReleaseGraphicsResources(vtkWindow*);
777
778 ////@{
779 /**
780 * Turn on/off FXAA anti-aliasing, if supported. Initial value is off.
781 */
782 vtkSetMacro(UseFXAA, bool);
783 vtkGetMacro(UseFXAA, bool);
784 vtkBooleanMacro(UseFXAA, bool);
785 ////@}
786
787 ////@{
788 /**
789 * The configuration object for FXAA antialiasing.
790 */
791 vtkGetObjectMacro(FXAAOptions, vtkFXAAOptions);
792 virtual void SetFXAAOptions(vtkFXAAOptions*);
793 ////@}
794
795 ////@{
796 /**
797 * Turn on/off rendering of shadows if supported
798 * Initial value is off.
799 */
800 vtkSetMacro(UseShadows, vtkTypeBool);
801 vtkGetMacro(UseShadows, vtkTypeBool);
802 vtkBooleanMacro(UseShadows, vtkTypeBool);
803 ////@}
804
805 ////@{
806 /**
807 * If this flag is true and the rendering engine supports it, wireframe
808 * geometry will be drawn using hidden line removal.
809 */
810 vtkSetMacro(UseHiddenLineRemoval, vtkTypeBool);
811 vtkGetMacro(UseHiddenLineRemoval, vtkTypeBool);
812 vtkBooleanMacro(UseHiddenLineRemoval, vtkTypeBool);
813 ////@}
814
815 // Set/Get a custom render pass.
816 // Initial value is NULL.
817 void SetPass(vtkRenderPass* p);
818 vtkGetObjectMacro(Pass, vtkRenderPass);
819
820 ////@{
821 /**
822 * Set/Get the information object associated with this algorithm.
823 */
824 vtkGetObjectMacro(Information, vtkInformation);
825 virtual void SetInformation(vtkInformation*);
826 ////@}
827
828 ////@{
829 /**
830 * If this flag is true and the rendering engine supports it, image based
831 * lighting is enabled and surface rendering displays environment reflections.
832 * The input cube map have to be set with SetEnvironmentCubeMap.
833 * If not cubemap is specified, this feature is disable.
834 */
835 vtkSetMacro(UseImageBasedLighting, bool);
836 vtkGetMacro(UseImageBasedLighting, bool);
837 vtkBooleanMacro(UseImageBasedLighting, bool);
838 ////@}
839
840 ////@{
841 /**
842 * Set/Get the environment texture used for image based lighting.
843 * This texture is supposed to represent the scene background.
844 * If it is not a cubemap, the texture is supposed to represent an equirectangular projection.
845 * If used with raytracing backends, the texture must be an equirectangular projection and must be
846 * constructed with a valid vtkImageData.
847 * Warning, this texture must be expressed in linear color space.
848 * If the texture is in sRGB color space, set the color flag on the texture or
849 * set the argument isSRGB to true.
850 * @sa vtkTexture::UseSRGBColorSpaceOn
851 */
852 vtkGetObjectMacro(EnvironmentTexture, vtkTexture);
853 virtual void SetEnvironmentTexture(vtkTexture* texture, bool isSRGB = false);
854 ////@}
855
856 ////@{
857 /**
858 * Set/Get the environment up vector.
859 */
860 vtkGetVector3Macro(EnvironmentUp, double);
861 vtkSetVector3Macro(EnvironmentUp, double);
862 ////@}
863
864 ////@{
865 /**
866 * Set/Get the environment right vector.
867 */
868 vtkGetVector3Macro(EnvironmentRight, double);
869 vtkSetVector3Macro(EnvironmentRight, double);
870 ////@}
871
872 protected:
873 vtkRenderer();
874 ~vtkRenderer() override;
875
876 // internal method to expand bounding box to consider model transform
877 // matrix or model view transform matrix based on whether or not deering
878 // frustum is used. 'bounds' buffer is mutated to the expanded box.
879 virtual void ExpandBounds(double bounds[6], vtkMatrix4x4* matrix);
880
881 vtkCamera* ActiveCamera;
882 vtkLight* CreatedLight;
883
884 vtkLightCollection* Lights;
885 vtkCullerCollection* Cullers;
886
887 vtkActorCollection* Actors;
888 vtkVolumeCollection* Volumes;
889
890 double Ambient[3];
891 vtkRenderWindow* RenderWindow;
892 double AllocatedRenderTime;
893 double TimeFactor;
894 vtkTypeBool TwoSidedLighting;
895 vtkTypeBool AutomaticLightCreation;
896 vtkTypeBool BackingStore;
897 unsigned char* BackingImage;
898 int BackingStoreSize[2];
899 vtkTimeStamp RenderTime;
900
901 double LastRenderTimeInSeconds;
902
903 vtkTypeBool LightFollowCamera;
904
905 // Allocate the time for each prop
906 void AllocateTime();
907
908 // Internal variables indicating the number of props
909 // that have been or will be rendered in each category.
910 int NumberOfPropsRendered;
911
912 // A temporary list of props used for culling, and traversal
913 // of all props when rendering
914 vtkProp** PropArray;
915 int PropArrayCount;
916
917 // Indicates if the renderer should receive events from an interactor.
918 // Typically only used in conjunction with transparent renderers.
919 vtkTypeBool Interactive;
920
921 // Shows what layer this renderer belongs to. Only of interested when
922 // there are layered renderers.
923 int Layer;
924 vtkTypeBool PreserveColorBuffer;
925 vtkTypeBool PreserveDepthBuffer;
926
927 // Holds the result of ComputeVisiblePropBounds so that it is visible from
928 // wrapped languages
929 double ComputedVisiblePropBounds[6];
930
931 /**
932 * Specifies the minimum distance of the near clipping
933 * plane as a percentage of the far clipping plane distance. Values below
934 * this threshold are clipped to NearClippingPlaneTolerance*range[1].
935 * Note that values which are too small may cause problems on systems
936 * with low z-buffer resolution.
937 */
938 double NearClippingPlaneTolerance;
939
940 /**
941 * Specify enlargement of bounds when resetting the
942 * camera clipping range.
943 */
944 double ClippingRangeExpansion;
945
946 /**
947 * When this flag is off, the renderer will not erase the background
948 * or the Zbuffer. It is used to have overlapping renderers.
949 * Both the RenderWindow Erase and Render Erase must be on
950 * for the camera to clear the renderer. By default, Erase is on.
951 */
952 vtkTypeBool Erase;
953
954 /**
955 * When this flag is off, render commands are ignored. It is used to either
956 * multiplex a vtkRenderWindow or render only part of a vtkRenderWindow.
957 * By default, Draw is on.
958 */
959 vtkTypeBool Draw;
960
961 /**
962 * Temporary collection used by vtkRenderWindow::CaptureGL2PSSpecialProps.
963 */
964 vtkPropCollection* GL2PSSpecialPropCollection;
965
966 /**
967 * Gets the ActiveCamera CompositeProjectionTransformationMatrix, only computing it if necessary.
968 * This function expects that this->ActiveCamera is not nullptr.
969 */
970 const std::array<double, 16>& GetCompositeProjectionTransformationMatrix();
971
972 /**
973 * Gets the ActiveCamera ProjectionTransformationMatrix, only computing it if necessary.
974 * This function expects that this->ActiveCamera is not nullptr.
975 */
976 const std::array<double, 16>& GetProjectionTransformationMatrix();
977
978 /**
979 * Gets the ActiveCamera ViewTransformMatrix, only computing it if necessary.
980 * This function expects that this->ActiveCamera is not nullptr.
981 */
982 const std::array<double, 16>& GetViewTransformMatrix();
983
984 /**
985 * Ask all props to update and draw any opaque and translucent
986 * geometry. This includes both vtkActors and vtkVolumes
987 * Returns the number of props that rendered geometry.
988 */
989 virtual int UpdateGeometry(vtkFrameBufferObjectBase* fbo = nullptr);
990
991 /**
992 * Ask all props to update and draw any translucent polygonal
993 * geometry. This includes both vtkActors and vtkVolumes
994 * Return the number of rendered props.
995 * It is called once with alpha blending technique. It is called multiple
996 * times with depth peeling technique.
997 */
998 virtual int UpdateTranslucentPolygonalGeometry();
999
1000 /**
1001 * Ask all props to update and draw any opaque polygonal
1002 * geometry. This includes both vtkActors and vtkVolumes
1003 * Return the number of rendered props.
1004 */
1005 virtual int UpdateOpaquePolygonalGeometry();
1006
1007 /**
1008 * Ask the active camera to do whatever it needs to do prior to rendering.
1009 * Creates a camera if none found active.
1010 */
1011 virtual int UpdateCamera(void);
1012
1013 /**
1014 * Update the geometry of the lights in the scene that are not in world
1015 * space (for instance, Headlights or CameraLights that are attached to the
1016 * camera).
1017 */
1018 virtual vtkTypeBool UpdateLightGeometry(void);
1019
1020 /**
1021 * Ask all lights to load themselves into rendering pipeline.
1022 * This method will return the actual number of lights that were on.
1023 */
UpdateLights(void)1024 virtual int UpdateLights(void) { return 0; }
1025
1026 /**
1027 * Get the current camera and reset it only if it gets created
1028 * automatically (see GetActiveCamera).
1029 * This is only used internally.
1030 */
1031 vtkCamera* GetActiveCameraAndResetIfCreated();
1032
1033 /**
1034 * If this flag is on and the rendering engine supports it, FXAA will be used
1035 * to antialias the scene. Default is off.
1036 */
1037 bool UseFXAA;
1038
1039 /**
1040 * Holds the FXAA configuration.
1041 */
1042 vtkFXAAOptions* FXAAOptions;
1043
1044 /**
1045 * If this flag is on and the rendering engine supports it render shadows
1046 * Initial value is off.
1047 */
1048 vtkTypeBool UseShadows;
1049
1050 /**
1051 * When this flag is on and the rendering engine supports it, wireframe
1052 * polydata will be rendered using hidden line removal.
1053 */
1054 vtkTypeBool UseHiddenLineRemoval;
1055
1056 /**
1057 * If this flag is on and the GPU supports it, depth peeling is used
1058 * for rendering translucent materials.
1059 * If this flag is off, alpha blending is used.
1060 * Initial value is off.
1061 */
1062 vtkTypeBool UseDepthPeeling;
1063
1064 /**
1065 * This flag is on and the GPU supports it, depth-peel volumes along with
1066 * the translucent geometry. Default is false;
1067 */
1068 bool UseDepthPeelingForVolumes;
1069
1070 /**
1071 * In case of use of depth peeling technique for rendering translucent
1072 * material, define the threshold under which the algorithm stops to
1073 * iterate over peel layers. This is the ratio of the number of pixels
1074 * that have been touched by the last layer over the total number of pixels
1075 * of the viewport area.
1076 * Initial value is 0.0, meaning rendering have to be exact. Greater values
1077 * may speed-up the rendering with small impact on the quality.
1078 */
1079 double OcclusionRatio;
1080
1081 /**
1082 * In case of depth peeling, define the maximum number of peeling layers.
1083 * Initial value is 4. A special value of 0 means no maximum limit.
1084 * It has to be a positive value.
1085 */
1086 int MaximumNumberOfPeels;
1087
1088 bool UseSSAO = false;
1089 double SSAORadius = 0.5;
1090 double SSAOBias = 0.01;
1091 unsigned int SSAOKernelSize = 32;
1092 bool SSAOBlur = false;
1093
1094 /**
1095 * Tells if the last call to DeviceRenderTranslucentPolygonalGeometry()
1096 * actually used depth peeling.
1097 * Initial value is false.
1098 */
1099 vtkTypeBool LastRenderingUsedDepthPeeling;
1100
1101 // HARDWARE SELECTION ----------------------------------------
1102 friend class vtkHardwareSelector;
1103
1104 /**
1105 * Called by vtkHardwareSelector when it begins rendering for selection.
1106 */
SetSelector(vtkHardwareSelector * selector)1107 void SetSelector(vtkHardwareSelector* selector)
1108 {
1109 this->Selector = selector;
1110 this->Modified();
1111 }
1112
1113 // End Ivars for visible cell selecting.
1114 vtkHardwareSelector* Selector;
1115
1116 //---------------------------------------------------------------
1117 friend class vtkRendererDelegate;
1118 vtkRendererDelegate* Delegate;
1119
1120 bool TexturedBackground;
1121 vtkTexture* BackgroundTexture;
1122 vtkTexture* RightBackgroundTexture;
1123
1124 friend class vtkRenderPass;
1125 vtkRenderPass* Pass;
1126
1127 // Arbitrary extra information associated with this renderer
1128 vtkInformation* Information;
1129
1130 bool UseImageBasedLighting;
1131 vtkTexture* EnvironmentTexture;
1132
1133 double EnvironmentUp[3];
1134 double EnvironmentRight[3];
1135
1136 private:
1137 /**
1138 * Cache of CompositeProjectionTransformationMatrix.
1139 */
1140 std::array<double, 16> CompositeProjectionTransformationMatrix;
1141
1142 /**
1143 * Tiled Aspect Ratio used to get the transform in this->CompositeProjectionTransformationMatrix.
1144 */
1145 double LastCompositeProjectionTransformationMatrixTiledAspectRatio;
1146
1147 /**
1148 * Modified time from the camera when this->CompositeProjectionTransformationMatrix was set.
1149 */
1150 vtkMTimeType LastCompositeProjectionTransformationMatrixCameraModified;
1151
1152 /**
1153 * Cache of ProjectionTransformationMatrix.
1154 */
1155 std::array<double, 16> ProjectionTransformationMatrix;
1156
1157 /**
1158 * Tiled Aspect Ratio used to get the transform in this->ProjectionTransformationMatrix.
1159 */
1160 double LastProjectionTransformationMatrixTiledAspectRatio;
1161
1162 /**
1163 * Modified time from the camera when this->ProjectionTransformationMatrix was set.
1164 */
1165 vtkMTimeType LastProjectionTransformationMatrixCameraModified;
1166
1167 /**
1168 * Cache of ViewTransformMatrix.
1169 */
1170 std::array<double, 16> ViewTransformMatrix;
1171
1172 /**
1173 * Modified time from the camera when this->ViewTransformMatrix was set.
1174 */
1175 vtkMTimeType LastViewTransformCameraModified;
1176
1177 vtkRenderer(const vtkRenderer&) = delete;
1178 void operator=(const vtkRenderer&) = delete;
1179 };
1180
GetLights()1181 inline vtkLightCollection* vtkRenderer::GetLights()
1182 {
1183 return this->Lights;
1184 }
1185
1186 /**
1187 * Get the list of cullers for this renderer.
1188 */
GetCullers()1189 inline vtkCullerCollection* vtkRenderer::GetCullers()
1190 {
1191 return this->Cullers;
1192 }
1193
1194 #endif
1195