11#ifndef USE_GPU_SHADER_CREATE_INFO
28class ShadowDirectional;
47# define M_PI 3.14159265358979323846
70 : x(tx[0][0], tx[1][0], tx[2][0], tx[3][0]),
71 y(tx[0][1], tx[1][1], tx[2][1], tx[3][1]),
72 z(tx[0][2], tx[1][2], tx[2][2], tx[3][2])
97 t.
x =
float4(m[0][0], m[1][0], m[2][0], m[3][0]);
98 t.
y =
float4(m[0][1], m[1][1], m[2][1], m[3][1]);
99 t.
z =
float4(m[0][2], m[1][2], m[2][2], m[3][2]);
123 return all(equal(a.x,
b.x)) && all(equal(a.y,
b.y)) && all(equal(a.z,
b.z));
271#define SAMPLING_DIMENSION_COUNT 32
283 return ((in_ring_count * in_ring_count + in_ring_count) / 2) * web_density + 1;
290 float x = 2.0f * (
float(sample_count) - 1.0f) /
float(web_density);
292 float discriminant = 1.0f + 4.0f *
x;
358#define FILM_PRECOMP_SAMPLE_MAX 16
473 float r = sample_distance_sqr / (filter_radius * filter_radius);
474 const float sigma = 0.284;
475 const float fac = -0.5 / (sigma * sigma);
476 float weight =
expf(fac * r);
479 float r = M_TAU *
saturate(0.5 +
sqrtf(sample_distance_sqr) / (2.0 * filter_radius));
480 float weight = 0.35875 - 0.48829 *
cosf(r) + 0.14128 *
cosf(2.0 * r) - 0.01168 *
cosf(3.0 * r);
539#define VELOCITY_INVALID 512.0
590#define MOTION_BLUR_TILE_SIZE 32
591#define MOTION_BLUR_MAX_TILE 512
607struct MotionBlurTileIndirection {
676#define DOF_FAST_GATHER_COC_ERROR 0.05
677#define DOF_GATHER_RING_COUNT 5
678#define DOF_DILATE_RING_COUNT 3
727 depth = (dof.camera_type !=
CAMERA_ORTHO) ? 1.0f / depth : depth;
728 return dof.coc_mul * depth + dof.coc_bias;
733 return 2.0f *
sinf(
M_PI / sides_count);
741 float side_angle = (2.0f *
M_PI) / sides_count;
742 return cosf(side_angle * 0.5f) /
750 float side_angle = (2.0f *
M_PI) / sides_count;
751 float halfside_angle = side_angle * 0.5f;
752 float side =
floorf(theta / side_angle);
757 float local_theta = theta - side * side_angle;
758 float ratio = (local_theta - halfside_angle) / halfside_angle;
761 float opposite = ratio * halfside_len;
764 float final_local_theta =
atanf(opposite / adjacent);
766 return side * side_angle + final_local_theta;
776#define CULLING_MAX_ITEM 65536
778#define CULLING_ZBIN_COUNT 4096
780#define CULLING_TILE_RES 16
817#define LIGHT_NO_SHADOW -1
880#define LOCAL_LIGHT_COMMON \
883 packed_float3 shadow_position; \
886 float shadow_radius; \
888 float shape_radius; \
890 float influence_radius_max; \
892 float influence_radius_invsqr_surface; \
893 float influence_radius_invsqr_volume; \
927struct LightAreaData {
949 int2 clipmap_base_offset_neg;
950 int2 clipmap_base_offset_pos;
967#define SAFE_UNION_ACCESS 0
971# define USE_LIGHT_UNION 1
972#elif defined(GPU_BACKEND_METAL) && !SAFE_UNION_ACCESS
974# define USE_LIGHT_UNION 1
977# define USE_LIGHT_UNION 0
1002 float filter_radius;
1011 uint2 light_set_membership;
1015 uint2 shadow_set_membership;
1049# define CHECK_TYPE_PAIR(a, b)
1050# define CHECK_TYPE(a, b)
1051# define FLOAT_AS_INT floatBitsToInt
1052# define INT_AS_FLOAT intBitsToFloat
1053# define TYPECAST_NOOP
1056# define FLOAT_AS_INT float_as_int
1057# define INT_AS_FLOAT int_as_float
1058# define TYPECAST_NOOP
1065#if SAFE_UNION_ACCESS
1068# if defined(GPU_FRAGMENT_SHADER)
1069# define GARBAGE_VALUE sin(gl_FragCoord.x + gl_FragCoord.y)
1070# elif defined(GPU_COMPUTE_SHADER)
1071# define GARBAGE_VALUE \
1072 sin(float(gl_GlobalInvocationID.x + gl_GlobalInvocationID.y + gl_GlobalInvocationID.z))
1074# define GARBAGE_VALUE sin(float(gl_VertexID))
1081# define GARBAGE_VALUE 0.0f
1084# define SAFE_BEGIN(dst_type, src_type, src_, check) \
1085 src_type _src = src_; \
1087 bool _validity_check = check; \
1088 float _garbage = GARBAGE_VALUE;
1091# define SAFE_ASSIGN_LIGHT_TYPE_CHECK(_type, _value) \
1092 (_validity_check ? (_value) : _type(_garbage))
1094# define SAFE_BEGIN(dst_type, src_type, src_, check) \
1095 UNUSED_VARS(check); \
1096 src_type _src = src_; \
1099# define SAFE_ASSIGN_LIGHT_TYPE_CHECK(_type, _value) _value
1103# define DATA_MEMBER local
1105# define DATA_MEMBER do_not_access_directly
1108#define SAFE_READ_BEGIN(dst_type, light, check) \
1109 SAFE_BEGIN(dst_type, LightLocalData, light.DATA_MEMBER, check)
1110#define SAFE_READ_END() _dst
1112#define SAFE_WRITE_BEGIN(src_type, src, check) SAFE_BEGIN(LightLocalData, src_type, src, check)
1113#define SAFE_WRITE_END(light) light.DATA_MEMBER = _dst;
1115#define ERROR_OFS(a, b) "Offset of " STRINGIFY(a) " mismatch offset of " STRINGIFY(b)
1118#define SAFE_ASSIGN(a, reinterpret_fn, in_type, b) \
1119 CHECK_TYPE_PAIR(_src.b, in_type(_dst.a)); \
1120 CHECK_TYPE_PAIR(_dst.a, reinterpret_fn(_src.b)); \
1121 _dst.a = reinterpret_fn(SAFE_ASSIGN_LIGHT_TYPE_CHECK(in_type, _src.b)); \
1122 BLI_STATIC_ASSERT(offsetof(decltype(_dst), a) == offsetof(decltype(_src), b), ERROR_OFS(a, b))
1124#define SAFE_ASSIGN_FLOAT(a, b) SAFE_ASSIGN(a, TYPECAST_NOOP, float, b);
1125#define SAFE_ASSIGN_FLOAT2(a, b) SAFE_ASSIGN(a, TYPECAST_NOOP, float2, b);
1126#define SAFE_ASSIGN_FLOAT3(a, b) SAFE_ASSIGN(a, TYPECAST_NOOP, float3, b);
1127#define SAFE_ASSIGN_INT(a, b) SAFE_ASSIGN(a, TYPECAST_NOOP, int, b);
1128#define SAFE_ASSIGN_FLOAT_AS_INT(a, b) SAFE_ASSIGN(a, FLOAT_AS_INT, float, b);
1129#define SAFE_ASSIGN_INT_AS_FLOAT(a, b) SAFE_ASSIGN(a, INT_AS_FLOAT, int, b);
1131#if !USE_LIGHT_UNION || IS_CPP
1136namespace do_not_use {
1147 SAFE_ASSIGN_FLOAT(influence_radius_invsqr_surface, influence_radius_invsqr_surface)
1148 SAFE_ASSIGN_FLOAT(influence_radius_invsqr_volume, influence_radius_invsqr_volume)
1165 SAFE_ASSIGN_FLOAT(influence_radius_invsqr_surface, influence_radius_invsqr_surface)
1166 SAFE_ASSIGN_FLOAT(influence_radius_invsqr_volume, influence_radius_invsqr_volume)
1191 SAFE_ASSIGN_FLOAT(influence_radius_invsqr_surface, influence_radius_invsqr_surface)
1192 SAFE_ASSIGN_FLOAT(influence_radius_invsqr_volume, influence_radius_invsqr_volume)
1241# define light_local_data_get(light) light.local
1242# define light_spot_data_get(light) light.spot
1243# define light_area_data_get(light) light.area
1244# define light_sun_data_get(light) light.sun
1252#undef SAFE_ASSIGN_LIGHT_TYPE_CHECK
1255#undef SAFE_ASSIGN_FLOAT
1256#undef SAFE_ASSIGN_FLOAT2
1257#undef SAFE_ASSIGN_INT
1258#undef SAFE_ASSIGN_FLOAT_AS_INT
1259#undef SAFE_ASSIGN_INT_AS_FLOAT
1265 return light.tilemap_index +
1308 return (base_offset * level_relative) / (1 << 16);
1455#define ShadowTileDataPacked uint
1471 return (page.x << 0u) | (page.y << 2u) | (page.z << 4u);
1477 page.x = (data >> 0u) & 3u;
1478 page.y = (data >> 2u) & 3u;
1480 page.z = (data >> 4u) & 255u;
1492 tile.cache_index = (data >> 15u) & 4095u;
1508 data |= (
tile.cache_index & 4095u) << 15u;
1533#define ShadowSamplingTilePacked uint
1556 tile.lod = (data >> 12u) & 15u;
1560 tile.is_valid = data != 0u;
1563 if (
tile.lod == 0) {
1564 tile.lod_offset.
x = 0;
1572 if (!
tile.is_valid) {
1578 if (
tile.lod == 0) {
1579 tile.lod_offset.
x = 1;
1583 data |= (
tile.lod & 15u) << 12u;
1831#define IrradianceBrickPacked uint
1837 return brick_packed;
1993#define SSS_SAMPLE_MAX 64
1994#define SSS_BURLEY_TRUNCATE 16.0
1995#define SSS_BURLEY_TRUNCATE_CDF 0.9963790093708328
1996#define SSS_TRANSMIT_LUT_SIZE 64.0
1997#define SSS_TRANSMIT_LUT_RADIUS 2.0
1998#define SSS_TRANSMIT_LUT_SCALE ((SSS_TRANSMIT_LUT_SIZE - 1.0) / float(SSS_TRANSMIT_LUT_SIZE))
1999#define SSS_TRANSMIT_LUT_BIAS (0.5 / float(SSS_TRANSMIT_LUT_SIZE))
2000#define SSS_TRANSMIT_LUT_STEP_RES 64.0
2020 const float m_1_pi = 0.318309886183790671538;
2024 float3 s = 1.9 - A + 3.5 * ((A - 0.8) * (A - 0.8));
2026 float3 l = 0.25 * m_1_pi * radius;
2036 exp_r_3_d.x =
expf(-r / (3.0 * d.x));
2037 exp_r_3_d.y =
expf(-r / (3.0 * d.y));
2038 exp_r_3_d.z =
expf(-r / (3.0 * d.z));
2039 float3 exp_r_d = exp_r_3_d * exp_r_3_d * exp_r_3_d;
2045 return (exp_r_d + exp_r_3_d) / (4.0 * d);
2125#define UTIL_TEX_SIZE 64
2126#define UTIL_BTDF_LAYER_COUNT 16
2129#define UTIL_TEX_UV_SCALE ((UTIL_TEX_SIZE - 1.0f) / UTIL_TEX_SIZE)
2130#define UTIL_TEX_UV_BIAS (0.5f / UTIL_TEX_SIZE)
2132#define UTIL_BLUE_NOISE_LAYER 0
2133#define UTIL_SSS_TRANSMITTANCE_PROFILE_LAYER 1
2134#define UTIL_LTC_MAT_LAYER 2
2135#define UTIL_BSDF_LAYER 3
2136#define UTIL_BTDF_LAYER 4
2137#define UTIL_DISK_INTEGRAL_LAYER UTIL_SSS_TRANSMITTANCE_PROFILE_LAYER
2138#define UTIL_DISK_INTEGRAL_COMP 3
2142# if defined(GPU_FRAGMENT_SHADER)
2143# define UTIL_TEXEL vec2(gl_FragCoord.xy)
2144# elif defined(GPU_COMPUTE_SHADER)
2145# define UTIL_TEXEL vec2(gl_GlobalInvocationID.xy)
2147# define UTIL_TEXEL vec2(gl_VertexID, 0)
2151float4 utility_tx_fetch(sampler2DArray util_tx,
float2 texel,
float layer)
2157float4 utility_tx_sample(sampler2DArray util_tx,
float2 uv,
float layer)
2159 return textureLod(util_tx,
float3(uv, layer), 0.0);
2163float4 utility_tx_sample_lut(sampler2DArray util_tx,
float2 uv,
float layer)
2167 return textureLod(util_tx,
float3(uv, layer), 0.0);
2171float4 utility_tx_sample_bsdf_lut(sampler2DArray util_tx,
float2 uv,
float layer)
2177 float layer_floored;
2178 float interp = modf(layer, layer_floored);
2180 float4 tex_low = textureLod(util_tx,
float3(uv, layer_floored), 0.0);
2181 float4 tex_high = textureLod(util_tx,
float3(uv, layer_floored + 1.0), 0.0);
2188float4 utility_tx_sample_lut(sampler2DArray util_tx,
float cos_theta,
float roughness,
float layer)
2193 return utility_tx_sample_lut(util_tx, coords, layer);
#define BLI_STATIC_ASSERT_ALIGN(st, align)
#define ENUM_OPERATORS(_type, _max)
@ GPU_SAMPLER_FILTERING_LINEAR
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ccl_device_inline float cos_theta(const float3 w)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
local_group_size(16, 16) .push_constant(Type b
#define SHADOW_PAGE_PER_ROW
#define SHADOW_TILEMAP_MAX_CLIPMAP_LOD
#define SHADOW_PAGE_PER_COL
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
#define SAFE_ASSIGN_FLOAT(a, b)
#define SAFE_ASSIGN_INT_AS_FLOAT(a, b)
#define IrradianceBrickPacked
#define MOTION_BLUR_MAX_TILE
#define ShadowTileDataPacked
#define light_area_data_get(light)
#define SAFE_WRITE_END(light)
#define SAFE_ASSIGN_FLOAT3(a, b)
#define SAFE_WRITE_BEGIN(src_type, src, check)
#define light_sun_data_get(light)
#define light_local_data_get(light)
#define FILM_PRECOMP_SAMPLE_MAX
#define light_spot_data_get(light)
#define UTIL_BTDF_LAYER_COUNT
#define SAMPLING_DIMENSION_COUNT
#define UTIL_TEX_UV_SCALE
#define LOCAL_LIGHT_COMMON
#define SAFE_READ_BEGIN(dst_type, light, check)
#define ShadowSamplingTilePacked
#define SAFE_ASSIGN_FLOAT_AS_INT(a, b)
#define SAFE_ASSIGN_FLOAT2(a, b)
#define SAFE_ASSIGN_INT(a, b)
smooth(Type::VEC3, "prev") .smooth(Type CameraData
ccl_global const KernelWorkTile * tile
ccl_device_inline float2 power(float2 v, float e)
ccl_device_inline float2 interp(const float2 a, const float2 b, float t)
BLI_STATIC_ASSERT(MBC_BATCH_LEN< 32, "Number of batches exceeded the limit of bit fields")
static LightData light_local_data_set(LightData light, LightSpotData spot_data)
static LightData light_sun_data_set(LightData light, LightSunData sun_data)
static LightSpotData light_local_data_get_ex(LightData light, bool check)
constexpr GPUSamplerState no_filter
@ CAMERA_PANO_EQUIDISTANT
static int2 shadow_cascade_grid_offset(int2 base_offset, int level_relative)
static bool is_panoramic(eCameraType type)
static bool is_sphere_light(eLightType type)
static bool is_area_light(eLightType type)
static float film_filter_weight(float filter_radius, float sample_distance_sqr)
static int light_local_tilemap_count(LightData light)
static float3 transform_point_inversed(Transform t, float3 point)
@ GBUF_REFRACTION_COLORLESS
@ GBUF_REFLECTION_COLORLESS
static float3 transform_x_axis(Transform t)
@ LUT_GGX_BTDF_IOR_GT_ONE
@ LUT_RANDOM_WALK_SSS_PROFILE
constexpr GPUSamplerState with_filter
static Transform transform_from_matrix(float4x4 m)
static IrradianceBrickPacked irradiance_brick_pack(IrradianceBrick brick)
static float circle_to_polygon_angle(float sides_count, float theta)
static float regular_polygon_side_length(float sides_count)
static ShadowTileDataPacked shadow_tile_pack(ShadowTileData tile)
static float3 transform_direction_transposed(Transform t, float3 direction)
static ShadowSamplingTilePacked shadow_sampling_tile_pack(ShadowSamplingTile tile)
@ CLOSURE_AMBIENT_OCCLUSION
static float3 light_position_get(LightData light)
static float3 light_y_axis(LightData light)
static bool is_sun_light(eLightType type)
static ShadowTileData shadow_tile_unpack(ShadowTileDataPacked data)
static int light_tilemap_max_get(LightData light)
static uint2 shadow_lod_offset_unpack(uint data)
static float3 transform_z_axis(Transform t)
static int sampling_web_ring_count_get(int web_density, int sample_count)
static float3 light_z_axis(LightData light)
static bool is_spot_light(eLightType type)
static float3 transform_y_axis(Transform t)
static uint3 shadow_page_unpack(uint data)
static bool is_oriented_disk_light(eLightType type)
@ FILM_WEIGHT_LAYER_DISTANCE
@ FILM_WEIGHT_LAYER_ACCUMULATION
static float3 light_x_axis(LightData light)
static IrradianceBrick irradiance_brick_unpack(IrradianceBrickPacked brick_packed)
@ DEBUG_IRRADIANCE_CACHE_SURFELS_VISIBILITY
@ DEBUG_GBUFFER_EVALUATION
@ DEBUG_IRRADIANCE_CACHE_SURFELS_IRRADIANCE
@ DEBUG_IRRADIANCE_CACHE_SURFELS_NORMAL
@ DEBUG_IRRADIANCE_CACHE_VIRTUAL_OFFSET
@ DEBUG_SHADOW_TILE_RANDOM_COLOR
@ DEBUG_IRRADIANCE_CACHE_VALIDITY
@ DEBUG_IRRADIANCE_CACHE_SURFELS_CLUSTER
@ DEBUG_SHADOW_TILEMAP_RANDOM_COLOR
@ PASS_STORAGE_CRYPTOMATTE
static float3 burley_setup(float3 radius, float3 albedo)
static float coc_radius_from_camera_depth(DepthOfFieldData dof, float depth)
static uint shadow_page_pack(uint3 page)
static bool is_local_light(eLightType type)
static float4x4 transform_to_matrix(Transform t)
static float3 burley_eval(float3 d, float r)
static uint shadow_lod_offset_pack(uint2 ofs)
@ LIGHT_TRANSLUCENT_WITH_THICKNESS
static ShadowSamplingTile shadow_sampling_tile_create(ShadowTileData tile_data, uint lod)
draw::StorageArrayBuffer< uint, 1024, true > RayTraceTileBuf
static bool is_point_light(eLightType type)
static int sampling_web_sample_count_get(int web_density, int in_ring_count)
@ SHADOW_PROJECTION_CLIPMAP
@ SHADOW_PROJECTION_CASCADE
@ SHADOW_PROJECTION_CUBEFACE
static float circle_to_polygon_radius(float sides_count, float theta)
static ShadowSamplingTile shadow_sampling_tile_unpack(ShadowSamplingTilePacked data)
@ PASS_CATEGORY_CRYPTOMATTE
static float3 transform_location(Transform t)
T clamp(const T &a, const T &min, const T &max)
VecBase< T, 3 > transform_direction(const MatBase< T, 3, 3 > &mat, const VecBase< T, 3 > &direction)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
VecBase< uint32_t, 2 > uint2
MatBase< float, 4, 4 > float4x4
MatBase< float, 3, 4 > float3x4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
MatBase< float, 3, 3 > float3x3
VecBase< float, 3 > float3
static constexpr GPUSamplerState default_sampler()
bool32_t display_is_value
uint4 hash_value[AOV_MAX]
uint4 hash_color[AOV_MAX]
float2 equirect_scale_inv
float screen_diagonal_length
bool32_t capture_visibility_indirect
SphereProbeUvArea world_atlas_coord
bool32_t capture_indirect
bool32_t capture_visibility_direct
packed_int3 irradiance_grid_size
float4x4 irradiance_grid_world_to_local
float min_distance_to_surface
bool32_t capture_world_indirect
bool32_t capture_emission
float4x4 irradiance_grid_world_to_local_rotation
float4x4 irradiance_grid_local_to_world
bool32_t do_surfel_output
bool32_t capture_world_direct
float scatter_coc_threshold
float2 bokeh_anisotropic_scale_inv
int scatter_sprite_per_row
float2 bokeh_anisotropic_scale
float4 filter_samples_weight
float scatter_neighbor_max_color
float scatter_color_threshold
float filter_center_weight
int cryptomatte_samples_len
ePassStorageType display_storage_type
float samples_weight_total
int cryptomatte_material_id
int cryptomatte_object_id
LOCAL_LIGHT_COMMON float _pad1
LOCAL_LIGHT_COMMON float _pad1
float3x4 world_to_object_transposed
float roughness_mask_scale
float4x4 radiance_persmat
int horizon_resolution_scale
bool32_t trace_refraction
int2 horizon_resolution_bias
float2 full_resolution_inv
float roughness_mask_bias
uint2 shadow_set_membership
Transform object_to_world
eShadowProjectionType projection_type
uint2 shadow_set_membership
ReflectionProbeLowFreqLight low_freq_light
LightProbeShape parallax_shape
float3x4 world_to_probe_transposed
SphereProbeUvArea atlas_coord
LightProbeShape influence_shape
float4 samples[SSS_SAMPLE_MAX]
packed_float3 albedo_front
SurfelRadiance radiance_direct
packed_float3 albedo_back
VelocityGeometryIndex geo
float3x4 world_to_grid_transposed
packed_int3 grid_size_padded
float2 main_view_extent_inv
float4x4 history_winmat_stable
float history_depth_distribution
packed_float3 inv_tex_size
float4x4 curr_view_to_past_view