68 flip_y_socket_->
value[0] = 1.0f;
69 flip_y_socket_->value[1] = 1.0f;
70 flip_y_socket_->value[2] = 1.0f;
82 node_add_link(ntree, flip_y_mul, flip_y_value_out, rotate_x, rotate_x_vector_in);
91 node_add_link(ntree, rotate_x, rotate_x_out, rotate_z, rotate_z_vector_in);
108 node_add_link(ntree, light_path, is_camera_out, path_mix, path_mix_fac);
109 node_add_link(ntree, coordinate, generated_sock, path_mix, path_mix_in0);
110 node_add_link(ntree, rotate_z, rotate_z_out, path_mix, path_mix_in1);
113 environment_node_ = &environment;
118 node_add_link(ntree, path_mix, path_mix_out, environment, environment_vector_in);
126 node_add_link(ntree, environment, environment_out, background, background_color_in);
140 base_tile->
gen_x = 1;
141 base_tile->
gen_y = 1;
162 if (parameters_changed) {
163 intensity_socket_->value = parameters_.intensity;
166 environment_node_->id =
nullptr;
176 environment_node_->id = &image->id;
180 if (parameters_.camera_space) {
182 flip_y_socket_->value[0] = 1.0f;
183 flip_y_socket_->value[1] = -1.0f;
184 flip_y_socket_->value[2] = 1.0f;
185 *rotation_x_socket_ = -
M_PI / 2.0f;
189 flip_y_socket_->value[0] = 1.0f;
190 flip_y_socket_->value[1] = 1.0f;
191 flip_y_socket_->value[2] = 1.0f;
192 *rotation_x_socket_ = 0.0f;
200 if (rotation_changed || parameters_changed) {
204 return parameters_changed;
218 for (gpu::Batch *batch : sphere_lod_) {
223gpu::Batch *LookdevModule::sphere_get(
const SphereLOD level_of_detail)
225 BLI_assert(level_of_detail >= SphereLOD::LOW && level_of_detail < SphereLOD::MAX);
228#if (defined(__GNUC__) && (__GNUC__ >= 14) && !defined(__clang__))
229 [[assume((level_of_detail >= 0) && (level_of_detail < SphereLOD::MAX))]];
232 if (sphere_lod_[level_of_detail] !=
nullptr) {
233 return sphere_lod_[level_of_detail];
238 switch (level_of_detail) {
254 GPUVertFormat format = {0};
259 float nor_x, nor_y, nor_z;
262 gpu::VertBuf *vbo = GPU_vertbuf_create_with_format(format);
263 int v_len = (lat_res - 1) * lon_res * 6;
266 const float lon_inc = 2 *
M_PI / lon_res;
267 const float lat_inc =
M_PI / lat_res;
273 auto sphere_lat_lon_vert = [&](
float lat,
float lon) {
282 for (
int i = 0; i < lon_res; i++, lon += lon_inc) {
284 for (
int j = 0; j < lat_res; j++, lat += lat_inc) {
285 if (j != lat_res - 1) {
286 sphere_lat_lon_vert(lat + lat_inc, lon + lon_inc);
287 sphere_lat_lon_vert(lat + lat_inc, lon);
288 sphere_lat_lon_vert(lat, lon);
291 sphere_lat_lon_vert(lat, lon + lon_inc);
292 sphere_lat_lon_vert(lat + lat_inc, lon + lon_inc);
293 sphere_lat_lon_vert(lat, lon);
300 return sphere_lod_[level_of_detail];
305 visible_rect_ = *visible_rect;
306 is_camera_view_ = inst_.is_viewport() && inst_.rv3d && (inst_.rv3d->persp ==
RV3D_CAMOB);
307 use_reference_spheres_ = inst_.is_viewport() && inst_.overlays_enabled() &&
308 inst_.use_lookdev_overlay();
310 if (use_reference_spheres_) {
311 const int2 extent_dummy(1);
314 dummy_cryptomatte_tx_.ensure_2d(gpu::TextureFormat::SFLOAT_32_32_32_32, extent_dummy, usage);
315 dummy_aov_color_tx_.ensure_2d_array(
316 gpu::TextureFormat::SFLOAT_16_16_16_16, extent_dummy, 1, usage);
317 dummy_aov_value_tx_.ensure_2d_array(gpu::TextureFormat::SFLOAT_16, extent_dummy, 1, usage);
320 if (inst_.is_viewport()) {
324 inst_.sampling.reset();
327 inst_.sampling.reset();
332float LookdevModule::calc_viewport_scale()
335 const float min_scale = is_camera_view_ ? 0.0f : 0.5f;
339LookdevModule::SphereLOD LookdevModule::calc_level_of_detail(
const float viewport_scale)
342 (
U.lookdev_sphere_size / 400.0f) * viewport_scale *
UI_SCALE_FAC, 0.1f, 1.0f);
344 if (res_scale > 0.7f) {
345 return LookdevModule::SphereLOD::HIGH;
347 if (res_scale > 0.25f) {
348 return LookdevModule::SphereLOD::MEDIUM;
350 return LookdevModule::SphereLOD::LOW;
355 const int sphere_radius =
U.lookdev_sphere_size *
UI_SCALE_FAC * viewport_scale;
356 return max_ii(sphere_radius * 2, 4);
361 if (!use_reference_spheres_) {
364 const float viewport_scale = calc_viewport_scale();
370 if (spheres_[
index].color_tx_.ensure_2d(color_format, extent)) {
372 if (inst_.is_viewport() && inst_.sampling.finished_viewport()) {
373 inst_.sampling.reset();
381 const Camera &cam = inst_.camera;
383 int2 display_extent = inst_.film.display_extent_get();
388 pixel_radius *= sphere_distance;
391 this->sphere_radius_ = (extent.x / 2) * pixel_radius;
392 this->sphere_position_ = cam.
position() -
393 cam.
forward() * (sphere_distance + this->sphere_radius_);
396 model_m4.
location() = this->sphere_position_;
400 gpu::Batch *geom = sphere_get(calc_level_of_detail(viewport_scale));
402 sync_pass(spheres_[0].pass, geom, inst_.materials.metallic_mat, handle);
403 sync_pass(spheres_[1].pass, geom, inst_.materials.diffuse_mat, handle);
407void LookdevModule::sync_pass(
PassSimple &pass,
431 pass.
draw(geom, res_handle, 0);
434void LookdevModule::sync_display()
445 pass.
push_constant(
"invertedViewportSize", 1.0f / viewport_size);
447 pass.
bind_texture(
"metallic_tx", &spheres_[0].color_tx_);
448 pass.
bind_texture(
"diffuse_tx", &spheres_[1].color_tx_);
455 if (!use_reference_spheres_) {
459 inst_.volume_probes.set_view(view);
460 inst_.sphere_probes.set_view(view);
463 inst_.uniform_data.pipeline.push_update();
466 for (Sphere &sphere : spheres_) {
467 sphere.framebuffer.bind();
468 inst_.manager->submit(sphere.pass, view);
474 if (!inst_.is_viewport() || !inst_.use_studio_light()) {
480 if (use_viewspace_lighting_) {
487 inst_.sphere_probes.world_sphere_probe().atlas_coord,
488 inst_.sphere_probes.spherical_harmonics_buf(),
489 inst_.world.sunlight,
496 if (!use_reference_spheres_) {
506 inst_.manager->submit(display_ps_);
522 if (world_sphere_probe_.ensure_2d_array(gpu::TextureFormat::SPHERE_PROBE_FORMAT,
523 in_sphere_probe.
size().xy(),
530 world_sphere_probe_.ensure_mip_views();
537 pass.
push_constant(
"write_coord_mip0_packed",
reinterpret_cast<int4 *
>(&write_coord_mip0));
538 pass.
push_constant(
"write_coord_mip1_packed",
reinterpret_cast<int4 *
>(&write_coord_mip1));
539 pass.
push_constant(
"write_coord_mip2_packed",
reinterpret_cast<int4 *
>(&write_coord_mip2));
540 pass.
push_constant(
"write_coord_mip3_packed",
reinterpret_cast<int4 *
>(&write_coord_mip3));
541 pass.
push_constant(
"write_coord_mip4_packed",
reinterpret_cast<int4 *
>(&write_coord_mip4));
544 pass.
bind_image(
"out_sphere_mip0", world_sphere_probe_.mip_view(0));
545 pass.
bind_image(
"out_sphere_mip1", world_sphere_probe_.mip_view(1));
546 pass.
bind_image(
"out_sphere_mip2", world_sphere_probe_.mip_view(2));
547 pass.
bind_image(
"out_sphere_mip3", world_sphere_probe_.mip_view(3));
548 pass.
bind_image(
"out_sphere_mip4", world_sphere_probe_.mip_view(4));
549 pass.
bind_ssbo(
"in_sh", in_volume_probe);
550 pass.
bind_ssbo(
"out_sh", world_volume_probe_);
552 pass.
bind_ssbo(
"out_sun", world_sunlight_);
558 inst_.manager->submit(pass);
584 pass.
push_constant(
"write_coord_mip0_packed",
reinterpret_cast<int4 *
>(&write_coord_mip0));
585 pass.
push_constant(
"write_coord_mip1_packed",
reinterpret_cast<int4 *
>(&write_coord_mip1));
586 pass.
push_constant(
"write_coord_mip2_packed",
reinterpret_cast<int4 *
>(&write_coord_mip2));
587 pass.
push_constant(
"write_coord_mip3_packed",
reinterpret_cast<int4 *
>(&write_coord_mip3));
588 pass.
push_constant(
"write_coord_mip4_packed",
reinterpret_cast<int4 *
>(&write_coord_mip4));
590 pass.
bind_texture(
"in_sphere_tx", &world_sphere_probe_);
596 pass.
bind_ssbo(
"in_sh", world_volume_probe_);
597 pass.
bind_ssbo(
"out_sh", dst_volume_probe);
598 pass.
bind_ssbo(
"in_sun", world_sunlight_);
605 inst_.manager->submit(pass);
609 inst_.volume_probes.update_world_irradiance();
627 if (v3d ==
nullptr) {
654 return !(*
this == other);
#define SH_NODE_OUTPUT_WORLD
#define SH_NODE_VECTOR_ROTATE
#define SH_NODE_TEX_COORD
#define SH_NODE_VECTOR_MATH
#define SH_NODE_TEX_ENVIRONMENT
#define SH_NODE_VECT_TRANSFORM
#define SH_NODE_BACKGROUND
#define SH_NODE_LIGHT_PATH
#define STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE
#define GPU_BATCH_DISCARD_SAFE(batch)
#define GPU_ATTACHMENT_TEXTURE(_texture)
#define GPU_ATTACHMENT_NONE
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
constexpr IndexRange()=default
constexpr StringRefNull()
int3 size(int miplvl=0) const
gpu::Texture * mip_view(int miplvl)
void draw_procedural(GPUPrimType primitive, uint instance_len, uint vertex_len, uint vertex_first=-1, ResourceIDRange res_id={}, uint custom_id=0)
void bind_resources(U &resources)
void shader_set(gpu::Shader *shader)
void material_set(Manager &manager, GPUMaterial *material, bool deferred_texture_loading=false, GPUSamplerFiltering anisotropic_filtering=GPU_SAMPLER_FILTERING_DEFAULT)
void bind_texture(const char *name, gpu::Texture *texture, GPUSamplerState state=sampler_auto)
void bind_image(const char *name, gpu::Texture *image)
void dispatch(int group_len)
void state_set(DRWState state, int clip_plane_count=0)
void clear_color_depth_stencil(float4 color, float depth, uint8_t stencil)
void push_constant(const char *name, const float &data)
void bind_ssbo(const char *name, gpu::StorageBuf *buffer)
void draw(gpu::Batch *batch, uint instance_len=-1, uint vertex_len=-1, uint vertex_first=-1, ResourceIDRange res_id={}, uint custom_id=0)
static constexpr Value Z_NEG
static constexpr Value Y_POS
static constexpr Value X_POS
const float3 & forward() const
const float3 & position() const
const CameraData & data_get() const
bool is_perspective() const
struct blender::eevee::Film::DepthState depth
struct blender::eevee::HiZBuffer::@342214352322061324133130050175232001060230260232 front
A running instance of the engine.
VolumeProbeModule volume_probes
SphereProbeModule sphere_probes
const DRWContext * draw_ctx
GPUSamplerFiltering anisotropic_filtering
PlanarProbeModule planar_probes
UniformDataModule uniform_data
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)
LookdevModule(Instance &inst)
bool sync(const LookdevParameters &new_parameters)
blender::Material * default_surface
UtilityTexture utility_tx
GPUMaterial * material_shader_get(blender::Material *blender_mat, bNodeTree *nodetree, eMaterialPipeline pipeline_type, eMaterialGeometry geometry_type, bool deferred_compilation, blender::Material *default_mat)
gpu::Shader * static_shader_get(eShaderType shader_type)
static float screen_pixel_radius(const float4x4 &wininv, bool is_perspective, const int2 &extent)
struct blender::eevee::VolumeModule::@235034362354336005016350043217325022302275164354 result
#define RBUFS_UTILITY_TEX_SLOT
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
float3x3 scale(float3x3 mat, float2 scale)
bNode * node_add_static_node(const bContext *C, bNodeTree &ntree, int type)
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
void node_set_active(bNodeTree &ntree, bNode &node)
detail::Pass< command::DrawCommandBuf > PassSimple
static int calc_sphere_extent(const float viewport_scale)
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)
VecBase< T, Size > divide_ceil(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
MatT from_rotation(const RotationT &rotation)
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE
gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, gpu::VertBuf *vertex_buf, gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
VecBase< int32_t, 4 > int4
bool assign_if_different(T &old_value, T &&new_value)
void BKE_studiolight_ensure_flag(StudioLight *sl, int flag)
void BKE_image_assign_gpu_texture(Image *image, gpu::Texture *texture)
ImageTile * BKE_image_get_tile(Image *ima, int tile_number)
MINLINE void copy_v4_fl(float r[4], float f)
MINLINE int max_ii(int a, int b)
ATTR_WARN_UNUSED_RESULT const BMVert * v
MatBase< float, 4, 4 > float4x4
@ V3D_SHADING_SCENE_WORLD
@ V3D_SHADING_STUDIOLIGHT_VIEW_ROTATION
@ V3D_SHADING_SCENE_WORLD_RENDER
struct StudioLight * BKE_studiolight_find(const char *name, int flag)
VecBase< float, 4 > float4
void GPU_texture_mipmap_mode(gpu::Texture *texture, bool use_mipmap, bool use_filter)
void GPU_material_free(ListBaseT< LinkData > *gpumaterial)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_WRITE
@ GPU_TEXTURE_USAGE_GENERAL
void GPU_framebuffer_viewport_reset(gpu::FrameBuffer *fb)
@ NODE_VECTOR_ROTATE_TYPE_AXIS_Z
@ NODE_VECTOR_ROTATE_TYPE_AXIS_X
MatBase< float, 3, 3 > float3x3
void BKE_id_free(Main *bmain, void *idv)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
void GPU_vertbuf_vert_set(gpu::VertBuf *verts, uint v_idx, const void *data)
void BKE_ntree_update_without_main(bNodeTree &tree)
void * BKE_id_new_nomain(short type, const char *name)
@ SHD_VECT_TRANSFORM_SPACE_WORLD
@ SHD_VECT_TRANSFORM_SPACE_CAMERA
void GPU_texture_free(gpu::Texture *texture)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
@ NODE_VECTOR_MATH_MULTIPLY
gpu::Texture * BKE_image_acquire_gpu_texture(Image *image, ImageUser *iuser)
VecBase< float, 3 > float3
const char * IMB_colormanagement_working_space_get()
MINLINE float clamp_f(float value, float min, float max)
void GPU_texture_ref(gpu::Texture *texture)
void vert(const int vert_id, float4 &position)
float2 viewport_size_get() const
gpu::FrameBuffer * default_fb
static MatBase identity()
NodeShaderMixMode factor_mode
eNodeSocketDatatype data_type
gpu::Texture * equirect_radiance_gputexture
float studiolight_background
float studiolight_intensity
ListBaseT< bNodeSocket > inputs
bool operator==(const LookdevParameters &other) const
std::string working_space
bool operator!=(const LookdevParameters &other) const
SphereProbePixelArea as_write_coord(int mip_lvl) const
SphereProbeUvArea as_sampling_coord() const