14#include "gpu_shader_codegen_lib.glsl"
53 int2 texel =
int2(global_thread_id.xy);
55 if (local_thread_index == 0u) {
56 srt.has_visible_sss = 0u;
64 ClosureUndetermined cl = gbuf.
layer[0];
70 ClosureSubsurface closure = to_closure_subsurface(cl);
71 float max_radius =
reduce_max(closure.sss_radius);
73 uint object_id = reader.read_object_id(texel);
75 if (srt.use_split_radiance) {
87 float homogenous_coord = view.
winmat[2][3] * vPz + view.
winmat[3][3];
88 float sample_scale = view.
winmat[0][0] * (0.5f * max_radius / homogenous_coord);
89 float pixel_footprint = sample_scale *
float(
textureSize(reader.gbuf_header_tx, 0).x);
90 if (pixel_footprint > 1.0f) {
92 srt.has_visible_sss = 1u;
96 if (srt.use_split_radiance) {
110 if (local_thread_index == 0u) {
111 if (srt.has_visible_sss > 0u) {
112 uint tile_id =
atomicAdd(srt.convolve_dispatch_buf.num_groups_x, 1u);
113 srt.convolve_tile_buf[tile_id] =
packUvec2x16(group_id.xy);
115 srt.convolve_dispatch_buf.num_groups_y = 1;
116 srt.convolve_dispatch_buf.num_groups_z = 1;
171 texel -= tile_coord * SUBSURFACE_GROUP_SIZE;
202 constexpr uint tile_size = uint(SUBSURFACE_GROUP_SIZE);
204 int2 texel =
int2(local_thread_id.xy + tile_coord * tile_size);
208 srt.cache_populate(center_uv, local_thread_id.xy);
221 const uint object_id = reader.read_object_id(texel);
223 const ClosureSubsurface closure = to_closure_subsurface(gbuf.
layer[0]);
224 float max_radius =
reduce_max(closure.sss_radius);
226 float homogenous_coord = view.
winmat[2][3] * vP.
z + view.
winmat[3][3];
228 (0.5f * max_radius / homogenous_coord);
230 float pixel_footprint = sample_scale.
x *
textureSize(srt.depth_tx, 0).x;
231 if (pixel_footprint <= 1.0f) {
238 closure.sss_radius / max_radius) *
242 float3 d = burley_setup(clamped_sss_radius, albedo);
245 float golden_angle =
M_PI * (3.0f -
sqrt(5.0f));
254 for (
int i = 0; i < srt.subsurface_buf.sample_len; i++) {
255 float2 sample_uv = center_uv + sample_space * srt.subsurface_buf.samples[i].xy;
256 float pdf_inv = srt.subsurface_buf.samples[i].z;
260 if (samp.
sss_id != object_id) {
266 float3 weight = burley_eval(d, r) * pdf_inv;
268 accum_radiance += samp.
radiance * weight;
269 accum_weight += weight;
271 if (srt.use_split_radiance) {
272 accum_radiance_indirect +=
textureLod(srt.radiance_tx,
float3(sample_uv, 1.0f), 0.0f).rgb *
278 accum_radiance *= accum_weight_inv;
279 accum_radiance_indirect *= accum_weight_inv;
#define SUBSURFACE_RADIANCE_FORMAT
#define RAYTRACE_RADIANCE_FORMAT
#define SUBSURFACE_BUF_SLOT
#define DEFERRED_RADIANCE_FORMAT
#define SUBSURFACE_OBJECT_ID_FORMAT
#define local_invocation_index
#define storage(slot, qualifiers)
#define image(slot, qualifiers, format)
#define specialization_constant(default_value)
#define global_invocation_id
#define local_invocation_id
VecBase< bool, D > greaterThanEqual(VecOp< T, D >, VecOp< T, D >) RET
bool any(VecOp< bool, D >) RET
float distance(float, float) RET
int atomicAdd(int &, int) RET
ImageBase< uint, 2 > uimage2D
ImageBase< uint, 2, true > uimage2DArray
ImageBase< float, 2, true > image2DArray
ImageBase< float, 2 > image2D
IMG_TEMPLATE void imageStore(T &, IntCoord, DataVec)
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
TEX_TEMPLATE DataVec textureLod(T, FltCoord, float) RET
SamplerBase< float, 2, false, false, false, true > sampler2DDepth
SamplerBase< float, 2, false, true > sampler2DArray
TEX_TEMPLATE SizeVec textureSize(T, int) RET
SamplerBase< uint, 2 > usampler2D
float2x2 from_scale(float2 scale)
float2x2 from_rotation(AngleRadian rotation)
float reduce_max(float2 a)
uint rgb9e5_encode(float3 color)
float3 rgb9e5_decode(uint data)
uint2 unpackUvec2x16(uint a)
uint packUvec2x16(uint2 a)
@ CLOSURE_BSSRDF_BURLEY_ID
MatBase< float, 2, 2 > float2x2
PipelineCompute setup(setup_main)
void setup_main(Setup &srt, const draw::View &views, const gbuffer::Reader &reader, const uint3 group_id, const uint3 global_thread_id, const uint local_thread_index)
void convolve_main(Convolve &srt, const draw::View &views, const gbuffer::Reader &reader, const uint3 group_id, const uint3 local_thread_id)
PipelineCompute convolve(convolve_main)
float interleaved_gradient(float2 pixel, float seed, float offset)
T read(T depth_buffer_value)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
float depth_screen_to_view(float ss_depth) const
float3 point_screen_to_view(float3 ssP) const
const uint(& tiles_coord_buf)[]
float3 cached_radiance[SUBSURFACE_GROUP_SIZE][SUBSURFACE_GROUP_SIZE]
image2D out_indirect_light_img
SubSurfaceSample sample_neighborhood(float2 sample_uv, uint3 group_id) const
uint cached_sss_id[SUBSURFACE_GROUP_SIZE][SUBSURFACE_GROUP_SIZE]
bool cache_sample(uint2 texel, uint3 group_id, SubSurfaceSample &samp) const
void cache_populate(float2 local_uv, uint2 texel)
sampler2DArray radiance_tx
float cached_depth[SUBSURFACE_GROUP_SIZE][SUBSURFACE_GROUP_SIZE]
const SubsurfaceData & subsurface_buf
uimage2DArray out_direct_light_img
const bool use_split_radiance
DispatchCommand & convolve_dispatch_buf
uint(& convolve_tile_buf)[]
const uimage2DArray direct_light_img
const image2D indirect_light_img
image2DArray radiance_img
const bool use_split_radiance
ClosureUndetermined layer[GBUFFER_LAYER_MAX]