VTK  9.4.20241212
vtkOSPRayRendererNode.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
13#ifndef vtkOSPRayRendererNode_h
14#define vtkOSPRayRendererNode_h
15
16#include "RTWrapper/RTWrapper.h" // for handle types
17#include "vtkInformation.h" // For deprecated function
18#include "vtkOSPRayCache.h" // For common cache infrastructure
19#include "vtkRenderer.h" // For deprecated function
20#include "vtkRendererNode.h"
21#include "vtkRenderingRayTracingModule.h" // For export macro
22
23#include <vector> // for ivars
24
25#ifdef VTKOSPRAY_ENABLE_DENOISER
26#include <OpenImageDenoise/oidn.hpp> // for denoiser structures
27#endif
28
29VTK_ABI_NAMESPACE_BEGIN
35class vtkMatrix4x4;
36class vtkOSPRayRendererNodeInternals;
38
39class VTKRENDERINGRAYTRACING_EXPORT vtkOSPRayRendererNode : public vtkRendererNode
40{
41public:
44 void PrintSelf(ostream& os, vtkIndent indent) override;
45
49 void Build(bool prepass) override;
50
54 void Render(bool prepass) override;
55
59 void Invalidate(bool prepass) override;
60
64 virtual void WriteLayer(unsigned char* buffer, float* zbuffer, int buffx, int buffy, int layer);
65
66 // state beyond rendering core...
67
75
77
80 static void SetSamplesPerPixel(int, vtkRenderer* renderer);
81 static int GetSamplesPerPixel(vtkRenderer* renderer);
83
91
93
96 static void SetMaxContribution(double, vtkRenderer* renderer);
97 static double GetMaxContribution(vtkRenderer* renderer);
99
106
108
111 static void SetMaxDepth(int, vtkRenderer* renderer);
112 static int GetMaxDepth(vtkRenderer* renderer);
114
122
124
127 static void SetMinContribution(double, vtkRenderer* renderer);
128 static double GetMinContribution(vtkRenderer* renderer);
130
138
140
143 static void SetRouletteDepth(int, vtkRenderer* renderer);
144 static int GetRouletteDepth(vtkRenderer* renderer);
146
153
155
158 static void SetVarianceThreshold(double, vtkRenderer* renderer);
159 static double GetVarianceThreshold(vtkRenderer* renderer);
161
169
171
176 static void SetMaxFrames(int, vtkRenderer* renderer);
177 static int GetMaxFrames(vtkRenderer* renderer);
179
187
191 static void SetRendererType(std::string name, vtkRenderer* renderer);
192 static std::string GetRendererType(vtkRenderer* renderer);
194
203
206 static void SetAmbientSamples(int, vtkRenderer* renderer);
207 static int GetAmbientSamples(vtkRenderer* renderer);
209
217
220 static void SetVolumeSamplingRate(double, vtkRenderer* renderer);
221 static double GetVolumeSamplingRate(vtkRenderer* renderer);
223
231
234 static void SetCompositeOnGL(int, vtkRenderer* renderer);
235 static int GetCompositeOnGL(vtkRenderer* renderer);
237
244
247 static void SetNorthPole(double*, vtkRenderer* renderer);
248 static double* GetNorthPole(vtkRenderer* renderer);
250
257
260 static void SetEastPole(double*, vtkRenderer* renderer);
261 static double* GetEastPole(vtkRenderer* renderer);
263
269
271
277
284
287 static void SetViewTime(double, vtkRenderer* renderer);
288 static double GetViewTime(vtkRenderer* renderer);
290
297
300 static void SetTimeCacheSize(int, vtkRenderer* renderer);
301 static int GetTimeCacheSize(vtkRenderer* renderer);
303
307 OSPRenderer GetORenderer() { return this->ORenderer; }
308 void AddLight(OSPLight light) { this->Lights.push_back(light); }
309
313 virtual void* GetBuffer() { return this->Buffer.data(); }
314
318 virtual float* GetZBuffer() { return this->ZBuffer.data(); }
319
320 // Get the last renderer color buffer as an OpenGL texture.
321 virtual int GetColorBufferTextureGL() { return this->ColorBufferTex; }
322
323 // Get the last renderer depth buffer as an OpenGL texture.
324 virtual int GetDepthBufferTextureGL() { return this->DepthBufferTex; }
325
326 // if you want to traverse your children in a specific order
327 // or way override this method
328 void Traverse(int operation) override;
329
336
343
346 static void SetDenoiserThreshold(int, vtkRenderer* renderer);
347 static int GetDenoiserThreshold(vtkRenderer* renderer);
349
351
359 static void SetEnableDenoiser(int, vtkRenderer* renderer);
360 static int GetEnableDenoiser(vtkRenderer* renderer);
362
364 {
369 NumberOfMode
370 };
371
373
384
385 std::vector<OSPGeometricModel> GeometricModels;
386 std::vector<OSPVolumetricModel> VolumetricModels;
387 std::vector<OSPInstance> Instances;
388
389protected:
392
396 void Denoise();
397
398 // internal structures
399 std::vector<float> Buffer;
400 std::vector<float> ZBuffer;
401
404
405 OSPWorld OWorld{ nullptr };
406 OSPRenderer ORenderer{ nullptr };
407 OSPFrameBuffer OFrameBuffer{ nullptr };
408 OSPCamera OCamera{ nullptr };
409 int ImageX, ImageY;
410 std::vector<OSPLight> Lights;
415 bool UseBackplate{ true }; // use bgcolor for pathtracer or use bgcolor light
416 std::vector<float> ODepthBuffer;
421 vtkOSPRayRendererNodeInternals* Internal;
422 std::string PreviousType;
423
424#ifdef VTKOSPRAY_ENABLE_DENOISER
425 oidn::DeviceRef DenoiserDevice;
426 oidn::FilterRef DenoiserFilter;
427#endif
428 bool DenoiserDirty{ true };
429 std::vector<osp::vec4f> ColorBuffer;
430 std::vector<osp::vec3f> NormalBuffer;
431 std::vector<osp::vec3f> AlbedoBuffer;
432 std::vector<osp::vec4f> DenoisedBuffer;
433
435 std::set<OSPWorld> CacheContents;
436
437private:
439 void operator=(const vtkOSPRayRendererNode&) = delete;
440};
441
442VTK_ABI_NAMESPACE_END
443#endif
#define OSPWorld
Definition RTWrapper.h:20
#define OSPLight
Definition RTWrapper.h:25
#define OSPFrameBuffer
Definition RTWrapper.h:31
#define OSPRenderer
Definition RTWrapper.h:19
#define OSPCamera
Definition RTWrapper.h:24
a simple class to control print indentation
Definition vtkIndent.h:108
Key for double values in vtkInformation.
Key for integer values in vtkInformation.
Key for vtkObjectBase values.
Key for string values in vtkInformation.
represent and manipulate 4x4 transformation matrices
temporal cache ospray structures to speed flipbooks
a collection of materials for vtk apps to draw from
links vtkRenderers to OSPRay
static void SetMaxFrames(int, vtkRenderer *renderer)
When present on renderer, controls the number of ospray render calls for each refresh.
static double GetVarianceThreshold(vtkRenderer *renderer)
Convenience method to set/get VARIANCE_THRESHOLD on a vtkRenderer.
static void SetRendererType(std::string name, vtkRenderer *renderer)
Set the OSPRay renderer type to use (e.g.
static vtkOSPRayRendererNode * GetRendererNode(vtkViewNode *)
Convenience method to get and downcast renderable.
std::vector< osp::vec3f > NormalBuffer
std::vector< float > Buffer
RTW::Backend * GetBackend()
static void SetAmbientSamples(int, vtkRenderer *renderer)
Convenience method to set/get AMBIENT_SAMPLES on a vtkRenderer.
virtual float * GetZBuffer()
Get the last rendered ZBuffer.
static int GetRouletteDepth(vtkRenderer *renderer)
Convenience method to set/get ROULETTE_DEPTH on a vtkRenderer.
void Build(bool prepass) override
Builds myself.
static void SetCompositeOnGL(int, vtkRenderer *renderer)
Convenience method to set/get COMPOSITE_ON_GL on a vtkRenderer.
static void SetVolumeSamplingRate(double, vtkRenderer *renderer)
Convenience method VOLUME_SAMPLING_RATE on a vtkRenderer.
~vtkOSPRayRendererNode() override
OSPRenderer GetORenderer()
Methods for other nodes to access.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
std::vector< OSPVolumetricModel > VolumetricModels
std::vector< OSPInstance > Instances
static int GetAmbientSamples(vtkRenderer *renderer)
Convenience method to set/get AMBIENT_SAMPLES on a vtkRenderer.
static void SetMaterialLibrary(vtkOSPRayMaterialLibrary *, vtkRenderer *renderer)
Convenience method to set/get Material library on a renderer.
static void SetVarianceThreshold(double, vtkRenderer *renderer)
Convenience method to set/get VARIANCE_THRESHOLD on a vtkRenderer.
static void SetEastPole(double *, vtkRenderer *renderer)
Convenience method to set/get EAST_POLE on a vtkRenderer.
static void SetMaxContribution(double, vtkRenderer *renderer)
Convenience method to set/get MAX_CONTRIBUTION on a vtkRenderer.
static void SetMaxDepth(int, vtkRenderer *renderer)
Convenience method to set/get MAX_DEPTH on a vtkRenderer.
static double GetMaxContribution(vtkRenderer *renderer)
Convenience method to set/get MAX_CONTRIBUTION on a vtkRenderer.
vtkOSPRayRendererNodeInternals * Internal
static int GetTimeCacheSize(vtkRenderer *renderer)
Convenience method to set/get TIME_CACHE_SIZE on a vtkRenderer.
static void SetMinContribution(double, vtkRenderer *renderer)
Convenience method to set/get MIN_CONTRIBUTION on a vtkRenderer.
static int GetMaxFrames(vtkRenderer *renderer)
When present on renderer, controls the number of ospray render calls for each refresh.
std::vector< float > ODepthBuffer
static int GetMaxDepth(vtkRenderer *renderer)
Convenience method to set/get MAX_DEPTH on a vtkRenderer.
static vtkInformationIntegerKey * BACKGROUND_MODE()
Control use of the path tracer backplate and environmental background.
static BackgroundMode GetBackgroundMode(vtkRenderer *renderer)
Control use of the path tracer backplate and environmental background.
static double GetViewTime(vtkRenderer *renderer)
Convenience method to set/get VIEW_TIME on a vtkRenderer.
static double * GetEastPole(vtkRenderer *renderer)
Convenience method to set/get EAST_POLE on a vtkRenderer.
std::vector< OSPLight > Lights
static std::string GetRendererType(vtkRenderer *renderer)
Set the OSPRay renderer type to use (e.g.
vtkOSPRayCache< vtkOSPRayCacheItemObject > * Cache
static void SetDenoiserThreshold(int, vtkRenderer *renderer)
Convenience method to set/get DENOISER_THRESHOLD on a vtkRenderer.
static double GetVolumeSamplingRate(vtkRenderer *renderer)
Convenience method VOLUME_SAMPLING_RATE on a vtkRenderer.
std::vector< float > ZBuffer
virtual void WriteLayer(unsigned char *buffer, float *zbuffer, int buffx, int buffy, int layer)
Put my results into the correct place in the provided pixel buffer.
virtual void * GetBuffer()
Get the last rendered ColorBuffer.
static double GetMinContribution(vtkRenderer *renderer)
Convenience method to set/get MIN_CONTRIBUTION on a vtkRenderer.
std::set< OSPWorld > CacheContents
std::vector< osp::vec3f > AlbedoBuffer
void AddLight(OSPLight light)
void Render(bool prepass) override
Traverse graph in ospray's preferred order and render.
static vtkOSPRayMaterialLibrary * GetMaterialLibrary(vtkRenderer *renderer)
Convenience method to set/get Material library on a renderer.
static int GetSamplesPerPixel(vtkRenderer *renderer)
Convenience method to set/get SAMPLES_PER_PIXEL on a vtkRenderer.
std::vector< osp::vec4f > ColorBuffer
static void SetNorthPole(double *, vtkRenderer *renderer)
Convenience method to set/get NORTH_POLE on a vtkRenderer.
static double * GetNorthPole(vtkRenderer *renderer)
Convenience method to set/get NORTH_POLE on a vtkRenderer.
static void SetRouletteDepth(int, vtkRenderer *renderer)
Convenience method to set/get ROULETTE_DEPTH on a vtkRenderer.
static int GetCompositeOnGL(vtkRenderer *renderer)
Convenience method to set/get COMPOSITE_ON_GL on a vtkRenderer.
void Traverse(int operation) override
static vtkOSPRayRendererNode * New()
static void SetViewTime(double, vtkRenderer *renderer)
Convenience method to set/get VIEW_TIME on a vtkRenderer.
void Invalidate(bool prepass) override
Invalidates cached rendering data.
static void SetSamplesPerPixel(int, vtkRenderer *renderer)
Convenience method to set/get SAMPLES_PER_PIXEL on a vtkRenderer.
std::vector< osp::vec4f > DenoisedBuffer
void Denoise()
Denoise the colors stored in ColorBuffer and put into Buffer.
std::vector< OSPGeometricModel > GeometricModels
static int GetDenoiserThreshold(vtkRenderer *renderer)
Convenience method to set/get DENOISER_THRESHOLD on a vtkRenderer.
static void SetTimeCacheSize(int, vtkRenderer *renderer)
Convenience method to set/get TIME_CACHE_SIZE on a vtkRenderer.
vtkRenderer * GetRenderer()
static void SetBackgroundMode(BackgroundMode, vtkRenderer *renderer)
Control use of the path tracer backplate and environmental background.
vtkViewNode specialized for vtkRenderers
abstract specification for renderers
a node within a VTK scene graph
Definition vtkViewNode.h:31
static vtkInformationDoubleKey * MIN_CONTRIBUTION()
When present on renderer, sample contributions below this value will be neglected to speedup renderin...
static vtkInformationDoubleKey * MAX_CONTRIBUTION()
When present on renderer, samples are clamped to this value before they are accumulated into the fram...
static vtkInformationIntegerKey * SAMPLES_PER_PIXEL()
When present on renderer, controls the number of primary rays shot per pixel default is 1.
static int GetEnableDenoiser(vtkRenderer *renderer)
Enable denoising (if supported).
static vtkInformationObjectBaseKey * MATERIAL_LIBRARY()
Material Library attached to the renderer.
static vtkInformationDoubleKey * VOLUME_SAMPLING_RATE()
the rate of sampling for volumes, higher numbers increase the number of samples.
static vtkInformationIntegerKey * ROULETTE_DEPTH()
When present on renderer, controls the ray recursion depth at which to start Russian roulette termina...
static vtkInformationIntegerKey * MAX_DEPTH()
When present on renderer, controls the maximum ray recursion depth default is 20.
static vtkInformationIntegerKey * TIME_CACHE_SIZE()
Temporal cache size.
static vtkInformationDoubleKey * VARIANCE_THRESHOLD()
When present on renderer, controls the threshold for adaptive accumulation default is 0....
static vtkInformationIntegerKey * COMPOSITE_ON_GL()
used to make the renderer add ospray's content onto GL rendered content on the window
static vtkInformationIntegerKey * AMBIENT_SAMPLES()
When present on renderer, controls the number of ambient occlusion samples shot per hit.
static vtkInformationIntegerKey * ENABLE_DENOISER()
Enable denoising (if supported).
static vtkInformationDoubleVectorKey * NORTH_POLE()
World space direction of north pole for gradient and texture background.
static vtkInformationIntegerKey * MAX_FRAMES()
When present on renderer, controls the number of ospray render calls for each refresh.
static vtkInformationDoubleVectorKey * EAST_POLE()
World space direction of east pole for texture background.
static void SetEnableDenoiser(int, vtkRenderer *renderer)
Convenience method to set/get ENABLE_DENOISER on a vtkRenderer.
static vtkInformationIntegerKey * DENOISER_THRESHOLD()
Accumulation threshold when above which denoising kicks in.
static vtkInformationStringKey * RENDERER_TYPE()
Set the OSPRay renderer type to use (e.g.
static vtkInformationDoubleKey * VIEW_TIME()
Requested time to show in a renderer and to lookup in a temporal cache.
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270