VTK  9.7.20261110
vtkWebGPUEnvironmentMap.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
7
8#ifndef vtkWebGPUEnvironmentMap_h
9#define vtkWebGPUEnvironmentMap_h
10
11#include "Private/vtkWebGPUHandle.h" // for vtkWebGPU::Handle
12#include "vtkType.h" // for vtkMTimeType
13
14#include <cstdint> // for std::uint32_t
15#include <string> // for std::string
16
17VTK_ABI_NAMESPACE_BEGIN
19
21{
22public:
26 struct Source
27 {
28 WGPUTextureView View = nullptr;
29 bool IsCubeMap = false;
30 std::uint32_t Height = 0;
31 // True when View holds sRGB encoded values that the generation shaders must linearize
32 // before they filter them.
33 bool ConvertToLinear = false;
34 // Orthonormal basis of the environment, from vtkRenderer::GetEnvironmentRight() and
35 // GetEnvironmentUp(), with Front their cross product. Sample directions are rotated into
36 // this basis so the environment keeps its orientation whatever the camera does.
37 float Right[3] = { 1.0f, 0.0f, 0.0f };
38 float Up[3] = { 0.0f, 1.0f, 0.0f };
39 float Front[3] = { 0.0f, 0.0f, 1.0f };
41 };
42
43 bool Update(vtkWebGPUConfiguration* configuration, const Source& source);
44
45 bool IsReady() const { return this->Ready; }
46
47 WGPUSampler GetSampler() const { return this->Sampler; }
48 WGPUTextureView GetPrefilterView() const { return this->PrefilterCubeView; }
49 WGPUTextureView GetIrradianceView() const { return this->IrradianceCubeView; }
50 WGPUTextureView GetLookupTableView() const { return this->LookupTableView; }
51 WGPUBuffer GetHarmonicsBuffer() const { return this->HarmonicsBuffer; }
52 static constexpr std::uint64_t GetHarmonicsBufferSize() { return 9 * 4 * sizeof(float); }
53
54 std::uint32_t GetPrefilterLevels() const { return this->PrefilterLevels; }
55
61 bool Dump(vtkWebGPUConfiguration* configuration, const std::string& directory);
62
64
65private:
66 bool CreatePipelines(vtkWebGPUConfiguration* configuration);
67 void CreateTextures(vtkWebGPUConfiguration* configuration, std::uint32_t size);
68 void ComputeLookupTable(vtkWebGPUConfiguration* configuration, WGPUCommandEncoder encoder);
69 void ComputeEnvironment(
70 vtkWebGPUConfiguration* configuration, WGPUCommandEncoder encoder, const Source& source);
71
72 bool Ready = false;
73 vtkMTimeType SourceTime = 0;
74 bool SourceConvertToLinear = false;
75 bool SourceIsCubeMap = false;
76 WGPUTextureView SourceView = nullptr;
77 float SourceBasis[9] = {};
78
79 std::uint32_t EnvironmentSize = 0;
80 std::uint32_t EnvironmentLevels = 0;
81 std::uint32_t PrefilterLevels = 5;
82
83 vtkWebGPU::Sampler Sampler;
84 vtkWebGPU::Sampler SourceSampler;
85 vtkWebGPU::Texture EnvironmentCube;
86 vtkWebGPU::TextureView EnvironmentCubeView;
87 vtkWebGPU::Texture PrefilterCube;
88 vtkWebGPU::TextureView PrefilterCubeView;
89 vtkWebGPU::Texture IrradianceCube;
90 vtkWebGPU::TextureView IrradianceCubeView;
91 vtkWebGPU::Texture LookupTable;
92 vtkWebGPU::TextureView LookupTableView;
93 vtkWebGPU::Buffer HarmonicsBuffer;
94
95 vtkWebGPU::BindGroupLayout EnvironmentLayout;
96 vtkWebGPU::ComputePipeline EquirectangularPipeline;
97 vtkWebGPU::BindGroupLayout CubeLayout;
98 vtkWebGPU::ComputePipeline CubePipeline;
99 vtkWebGPU::BindGroupLayout DownsampleLayout;
100 vtkWebGPU::ComputePipeline DownsamplePipeline;
101 vtkWebGPU::BindGroupLayout PrefilterLayout;
102 vtkWebGPU::ComputePipeline PrefilterPipeline;
103 vtkWebGPU::BindGroupLayout IrradianceLayout;
104 vtkWebGPU::ComputePipeline IrradiancePipeline;
105 vtkWebGPU::BindGroupLayout HarmonicsLayout;
106 vtkWebGPU::ComputePipeline HarmonicsPipeline;
107 vtkWebGPU::BindGroupLayout LookupTableLayout;
108 vtkWebGPU::ComputePipeline LookupTablePipeline;
109};
110
111VTK_ABI_NAMESPACE_END
112#endif
113// VTK-HeaderTest-Exclude: vtkWebGPUEnvironmentMap.h
Create a webgpu device for use in rendering and compute pipelines.
Generates the image based lighting textures of a WebGPU renderer.
static constexpr std::uint64_t GetHarmonicsBufferSize()
WGPUTextureView GetPrefilterView() const
bool Dump(vtkWebGPUConfiguration *configuration, const std::string &directory)
Reads the generated textures back and writes them in the given directory: the lookup table,...
WGPUTextureView GetIrradianceView() const
WGPUBuffer GetHarmonicsBuffer() const
WGPUTextureView GetLookupTableView() const
bool Update(vtkWebGPUConfiguration *configuration, const Source &source)
std::uint32_t GetPrefilterLevels() const
The environment texture the lighting textures are generated from.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:321
Reference-counted ownership for WebGPU C API handles.