Blender V5.3
eevee_shadow.bsl.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
5#pragma once
6
7#include "draw_view.bsl.hh"
10#include "eevee_uniform.bsl.hh"
13
14namespace eevee {
15
18 /* Use a fixed seed for the noise input. */
20};
21
22/* Any entry point function using this should also use `[[texture_atomic]]`. */
25
28
33
34 float read_depth(ShadowCoordinates coord) const
35 {
36 ShadowSamplingTile tile = shadow_tile_load(
38 if (!tile.is_valid) {
39 return -1.0f;
40 }
41 /* Using bitwise ops is way faster than integer ops. */
42 constexpr uint page_shift = uint(SHADOW_PAGE_LOD);
43 constexpr uint page_mask = ~(0xFFFFFFFFu << uint(SHADOW_PAGE_LOD));
44
45 uint2 texel = coord.tilemap_texel;
46 /* Shift LOD0 pixels so that they get wrapped at the right position for the given LOD. */
47 texel += uint2(tile.lod_offset << SHADOW_PAGE_LOD);
48 /* Scale to LOD pixels (merge LOD0 pixels together) then mask to get pixel in page. */
49 uint2 texel_page = (texel >> tile.lod) & page_mask;
50 texel = (uint2(tile.page.xy) << page_shift) | texel_page;
51
52 return uintBitsToFloat(texelFetch(shadow_atlas_tx, int3(int2(texel), int(tile.page.z)), 0).r);
53 }
54
55 float punctual_sample_get(LightData light, float3 P) const
56 {
57 float3 shadow_position = light.local.local.shadow_position;
58 float3 lP = transform_point_inversed(light.object_to_world, P);
59 lP -= shadow_position;
60 int face_id = shadow_punctual_face_index_get(lP);
63
64 float radial_dist = read_depth(coord);
65 if (radial_dist == -1.0f) {
66 return 1e10f;
67 }
68 float receiver_dist = length(lP);
69 float occluder_dist = radial_dist;
70 return receiver_dist - occluder_dist;
71 }
72
73 float directional_sample_get(LightData light, float3 P) const
74 {
75 float3 lP = transform_direction_transposed(light.object_to_world, P);
77
78 float depth = read_depth(coord);
79 if (depth == -1.0f) {
80 return 1e10f;
81 }
82 /* Use increasing distance from the light. */
83 float receiver_dist = -lP.z - orderedIntBitsToFloat(light.clip_near);
84 float occluder_dist = depth;
85 return receiver_dist - occluder_dist;
86 }
87
88 float shadow_sample(const bool is_directional, LightData light, float3 P) const
89 {
90 if (is_directional) {
92 }
94 }
95};
96
97} // namespace eevee
#define SHADOW_ATLAS_TEX_SLOT
#define SHADOW_TILEMAPS_TEX_SLOT
ShadowCoordinates shadow_punctual_coordinates(LightData light, float3 lP, int face_id)
int shadow_punctual_face_index_get(float3 lL)
ShadowCoordinates shadow_directional_coordinates(LightData light, float3 lP)
ShadowSamplingTile shadow_tile_load(usampler2D tilemaps_tx, uint2 tile_co, int tilemap_index)
float3 shadow_punctual_local_position_to_face_local(int face_id, float3 lL)
#define compilation_constant
#define resource_table
#define sampler(slot)
#define condition(cond)
VecBase< float, D > uintBitsToFloat(VecOp< uint, D >) RET
float length(VecOp< float, D >) RET
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
SamplerBase< uint, 2, false, true, true > usampler2DArrayAtomic
SamplerBase< uint, 2 > usampler2D
float orderedIntBitsToFloat(int int_value)
const ccl_global KernelWorkTile * tile
usampler2DArrayAtomic shadow_atlas_tx
float directional_sample_get(LightData light, float3 P) const
float read_depth(ShadowCoordinates coord) const
float punctual_sample_get(LightData light, float3 P) const
ShadowRenderConstants constants
float shadow_sample(const bool is_directional, LightData light, float3 P) const
float z
Definition sky_math.h:136
ccl_device_inline T transform_direction_transposed(const ccl_private Transform *t, const T a)
Definition transform.h:176