Blender V5.3
eevee_lookdev.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12#pragma once
13
14#include <string>
15
16#include "DNA_image_types.h"
17#include "DNA_vec_types.h"
18#include "DNA_world_types.h"
19
21
22#include "DRW_gpu_wrapper.hh"
23
24#include "eevee_light_shared.hh"
25#include "eevee_lightprobe.hh"
27
28#include "draw_pass.hh"
29
30namespace blender {
31
32struct bNode;
35struct View3D;
36
37namespace eevee {
38
39class Instance;
40class LookdevView;
41
42using draw::Framebuffer;
44using draw::ResourceHandleRange;
45using draw::Texture;
46using draw::View;
47
48/* -------------------------------------------------------------------- */
55 std::string hdri;
56 std::string working_space;
57 float rot_z = 0.0f;
58 float background_opacity = 0.0f;
59 float intensity = 1.0f;
60 float blur = 0.0f;
61 bool show_scene_world = true;
62 bool camera_space = true;
63
66 bool operator==(const LookdevParameters &other) const;
67 bool operator!=(const LookdevParameters &other) const;
68};
69
71
72/* -------------------------------------------------------------------- */
77
79 private:
80 bNode *environment_node_ = nullptr;
81 bNodeSocketValueFloat *intensity_socket_ = nullptr;
82 bNodeSocketValueFloat *angle_socket_ = nullptr;
83 /* Vector multiply socket for flipping Y axes when transforming to camera space. */
84 bNodeSocketValueVector *flip_y_socket_ = nullptr;
85 /* Vector transform socket `convert_to`. */
86 int *xform_socket_ = nullptr;
87 /* Set to M_PI/2 for rotating the HDRI horizon line in camera space mode. */
88 float *rotation_x_socket_ = nullptr;
89 blender::Image *image = nullptr;
90 blender::World *world = nullptr;
91
92 LookdevParameters parameters_;
93
94 public:
97
98 /* Returns true if an update was detected. */
99 bool sync(const LookdevParameters &new_parameters);
100
102 {
103 return world;
104 }
105
107 {
108 return parameters_.background_opacity;
109 }
110
112 {
113 return parameters_.blur;
114 }
115
116 float intensity_get() const
117 {
118 return parameters_.intensity;
119 }
120};
121
123
124/* -------------------------------------------------------------------- */
128
129using namespace draw;
130
132 private:
133 Instance &inst_;
134
135 bool use_reference_spheres_ = false;
136
137 bool use_viewspace_lighting_ = false;
138 /* Used for update detection. */
139 float4x4 last_rotation_matrix_ = float4x4::identity();
140 float studio_light_rotation_z_ = 0.0f;
141
142 static constexpr int num_spheres = 2;
143
147 enum SphereLOD {
148 LOW = 0,
149 MEDIUM = 1,
150 HIGH = 2,
151
152 MAX, /* Max number of level of detail */
153 };
154
155 std::array<gpu::Batch *, MAX> sphere_lod_ = {};
156
157 /* Size and position of the look-dev spheres in world space. */
158 float sphere_radius_;
159 float3 sphere_position_;
160
161 rcti visible_rect_;
162 bool is_camera_view_ = false;
163
164 /* Dummy textures: required to reuse forward mesh shader and avoid another shader variation. */
165 Texture dummy_cryptomatte_tx_;
166 Texture dummy_aov_color_tx_;
167 Texture dummy_aov_value_tx_;
168
169 struct Sphere {
170 Framebuffer framebuffer = {"Lookdev.Framebuffer"};
171 Texture color_tx_ = {"Lookdev.Color"};
172 PassSimple pass = {"Lookdev.Sphere"};
173 };
174
175 Sphere spheres_[num_spheres];
176 PassSimple display_ps_ = {"Lookdev.Display"};
177
183 Texture world_sphere_probe_ = {"world_sphere_probe_"};
184 StorageBuffer<SphereProbeHarmonic, true> world_volume_probe_ = {"world_volume_probe_"};
185 UniformArrayBuffer<LightData, 2> world_sunlight_ = {"world_sunlight_"};
186
187 public:
188 LookdevModule(Instance &inst);
190
191 void init(const rcti *visible_rect);
192 void sync();
193
194 void draw(View &view);
195
196 void display();
197
198 void rotate_world();
199
200 void store_world_probe_data(Texture &in_sphere_probe,
201 const SphereProbeAtlasCoord &atlas_coord,
204
205 void rotate_world_probe_data(Texture &dst_sphere_probe,
206 const SphereProbeAtlasCoord &atlas_coord,
209 float4x4 &rotation);
210
211 private:
212 void sync_pass(PassSimple &pass,
213 gpu::Batch *geom,
215 ResourceHandleRange res_handle);
216 void sync_display();
217
218 float calc_viewport_scale();
219 SphereLOD calc_level_of_detail(const float viewport_scale);
220 gpu::Batch *sphere_get(const SphereLOD level_of_detail);
221
222 friend class LookdevView;
223};
224
226
227} // namespace eevee
228} // namespace blender
A running instance of the engine.
void store_world_probe_data(Texture &in_sphere_probe, const SphereProbeAtlasCoord &atlas_coord, StorageBuffer< SphereProbeHarmonic, true > &in_volume_probe, UniformArrayBuffer< LightData, 2 > &in_sunlight)
void rotate_world_probe_data(Texture &dst_sphere_probe, const SphereProbeAtlasCoord &atlas_coord, StorageBuffer< SphereProbeHarmonic, true > &dst_volume_probe, UniformArrayBuffer< LightData, 2 > &dst_sunlight, float4x4 &rotation)
void init(const rcti *visible_rect)
bool sync(const LookdevParameters &new_parameters)
detail::Pass< command::DrawCommandBuf > PassSimple
BMesh Iterators.
MatBase< float, 4, 4 > float4x4
VecBase< float, 3 > float3
bool operator==(const LookdevParameters &other) const
bool operator!=(const LookdevParameters &other) const