21#include "gpu_shader_codegen_lib.glsl"
61 render_passes.clear_aovs(uni,
int2(frag_co.xy));
67 .light_closure_count_transmit = 1});
99 if (layer_index == 0u) {
102 else if (layer_index == 1u) {
105 else if (layer_index == 2u) {
129 const int2 texel =
int2(frag_co.xy);
133 constexpr float bias = 2.4e-7f;
135 const float depth =
texelFetch(
hiz.hiz_tx, texel, 0).r - bias;
149 for (uint i = 0u; i < 3; i++) [[
unroll]] {
157 ctx.
texel = frag_co.xy;
165 uint object_id = reader.read_object_id(texel);
174 lights.eval_reflection(ctx, vPz);
176 if (srt.use_transmission) {
179 ClosureUndetermined cl_transmit = gbuf.
layer[0];
183 lights.eval_transmission(ctx_tr, vPz);
188 util_tx, to_closure_subsurface(cl_transmit).sss_radius,
thickness.value());
189 ctx.
stack.cl[0].light_shadowed += ctx_tr.
stack.cl[0].light_shadowed * sss_profile;
190 ctx.
stack.cl[0].light_unshadowed += ctx_tr.
stack.cl[0].light_unshadowed * sss_profile;
193 ctx.
stack.cl[0].light_shadowed = ctx_tr.
stack.cl[0].light_shadowed;
194 ctx.
stack.cl[0].light_unshadowed = ctx_tr.
stack.cl[0].light_unshadowed;
198 if (srt.render_pass_shadow_id != -1) {
201 for (uint i = 0u; i < 3; i++) [[
unroll]] {
203 if (i < closure_count) {
204 radiance_shadowed += ctx.
stack.cl[i].light_shadowed;
205 radiance_unshadowed += ctx.
stack.cl[i].light_unshadowed;
209 float3 shadows = radiance_shadowed *
safe_rcp(radiance_unshadowed);
210 render_passes.store_value(texel, srt.render_pass_shadow_id,
average(shadows));
213 if (srt.use_lightprobe_eval) {
216 float clamp_indirect = uni.uniform_buf.clamp.surface_indirect;
222 for (uint i = 0u; i < 3; i++) [[
unroll]] {
224 if (i < closure_count) {
226 float3 direct_light = ctx.
stack.cl[i].light_shadowed;
227 if (srt.use_split_indirect) {
228 srt.write_radiance_indirect(bin_indices[i], texel, indirect_light);
229 srt.write_radiance_direct(bin_indices[i], texel, direct_light);
232 srt.write_radiance_direct(bin_indices[i], texel, direct_light + indirect_light);
241 for (uint i = 0u; i < 3; i++) [[
unroll]] {
243 if (i < closure_count) {
244 float3 direct_light = ctx.
stack.cl[i].light_shadowed;
245 srt.write_radiance_direct(bin_indices[i], texel, direct_light);
281 frag_out.radiance =
float4(0.0f);
292 for (
int i = 0; i < 3 ; i++) [[
unroll]] {
293 if (i < closure_count) {
294 ClosureUndetermined cl = gbuf.
layer[i];
298 case CLOSURE_BSDF_MICROFACET_GGX_REFLECTION_ID:
299 albedo_front += cl.color;
303 albedo_back += (
thickness.value() != 0.0f) ?
square(cl.color) : cl.color;
306 albedo_back += cl.color;
322 ClosureUndetermined cl;
326 ClosureUndetermined cl_transmit;
333 ctx.
texel = frag_co.xy;
338 ctx.
ray_count = uni.uniform_buf.shadow.ray_count;
341 uint object_id = reader.read_object_id(texel);
350 lights.eval_reflection(ctx, vPz);
352 float3 radiance_front = ctx.
stack.cl[0].light_shadowed;
357 lights.eval_transmission(ctx_tr, vPz);
359 float3 radiance_back = ctx_tr.
stack.cl[0].light_shadowed;
369 frag_out.radiance =
float4(radiance_front * albedo_front + radiance_back * albedo_back, 0.0f);
403 ClosureUndetermined cl_reflect;
404 cl_reflect.type = CLOSURE_BSDF_MICROFACET_GGX_REFLECTION_ID;
405 cl_reflect.color =
float3(0.0);
406 cl_reflect.N =
float3(0.0);
407 cl_reflect.data =
float4(0.0);
408 float reflect_weight = 0.0;
410 ClosureUndetermined cl_refract;
412 cl_refract.color =
float3(0.0);
413 cl_refract.N =
float3(0.0);
414 cl_refract.data =
float4(0.0);
415 float refract_weight = 0.0;
418 for (
int i = 0; i < 3; i++) [[
unroll]] {
419 if (i < closure_count) {
420 ClosureUndetermined cl = gbuf.
layer[i];
422 case CLOSURE_BSDF_MICROFACET_GGX_REFLECTION_ID: {
423 cl_reflect.color += cl.color;
426 cl_reflect.N += cl.N * weight;
427 cl_reflect.data += cl.data * weight;
428 reflect_weight += weight;
433 albedo_front += cl.color;
436 albedo_back += (
thickness.value() != 0.0f) ?
square(cl.color) : cl.color;
439 cl_refract.color += (
thickness.value() != 0.0f) ?
square(cl.color) : cl.color;
442 cl_refract.N += cl.N * weight;
443 cl_refract.data += cl.data * weight;
444 refract_weight += weight;
448 cl_refract.color += cl.color;
451 cl_refract.N += cl.N * weight;
452 cl_refract.data += cl.data * weight;
453 refract_weight += weight;
464 if (reflect_weight > 1e-6) {
465 float inv_weight = 1.0f / reflect_weight;
466 cl_reflect.N *= inv_weight;
467 cl_reflect.data *= inv_weight;
472 cl_reflect.data.xy =
float2(1.0f);
476 if (refract_weight > 1e-6) {
477 float inv_weight = 1.0f / refract_weight;
478 cl_refract.N *= inv_weight;
479 cl_refract.data *= inv_weight;
484 cl_refract.data.xy =
float2(1.0f);
495 ClosureUndetermined cl;
499 ClosureUndetermined cl_transmit;
506 ctx.
texel = frag_co.xy;
511 ctx.
ray_count = uni.uniform_buf.shadow.ray_count;
514 uint object_id = reader.read_object_id(texel);
524 lights.eval_reflection(ctx, vPz);
526 float3 radiance_front = ctx.
stack.cl[0].light_shadowed;
527 float3 radiance_reflect = ctx.
stack.cl[1].light_shadowed;
532 lights.eval_transmission(ctx_tr, vPz);
534 float3 radiance_back = ctx_tr.
stack.cl[0].light_shadowed;
535 float3 radiance_refract = ctx_tr.
stack.cl[1].light_shadowed;
544 radiance_reflect += lightprobes.eval(samp, cl_reflect,
P,
V,
thickness);
545 radiance_refract += lightprobes.eval(samp, cl_refract,
P,
V,
thickness);
548 frag_out.radiance =
float4(0.0f);
549 frag_out.radiance.xyz += radiance_reflect * cl_reflect.color;
550 frag_out.radiance.xyz += radiance_refract * cl_refract.color;
551 frag_out.radiance.xyz += radiance_front * albedo_front;
552 frag_out.radiance.xyz += radiance_back * albedo_back;
560 .light_closure_eval_count_reflect = 1,
561 .light_closure_eval_count_transmit = 1,
562 .light_closure_count_reflect = 1,
563 .light_closure_count_transmit = 1,
566 .shadow_random =
true,
567 .shadow_static_noise =
false,
572 .light_closure_eval_count_reflect = 2,
573 .light_closure_eval_count_transmit = 1,
574 .light_closure_count_reflect = 2,
575 .light_closure_count_transmit = 1,
578 .shadow_random =
true,
579 .shadow_static_noise =
false,
584 .light_closure_eval_count_reflect = 3,
585 .light_closure_eval_count_transmit = 1,
586 .light_closure_count_reflect = 3,
587 .light_closure_count_transmit = 1,
590 .shadow_random =
true,
591 .shadow_static_noise =
false,
596 .light_closure_eval_count_reflect = 1,
597 .light_closure_eval_count_transmit = 1,
598 .light_closure_count_reflect = 1,
599 .light_closure_count_transmit = 1,
602 .shadow_random =
true,
604 .shadow_static_noise =
true,
609 .legacy_sphere_probe_enable =
true,
612 .light_closure_eval_count_reflect = 2,
613 .light_closure_eval_count_transmit = 2,
614 .light_closure_count_reflect = 2,
615 .light_closure_count_transmit = 2,
617 ShadowRenderConstants{
618 .shadow_random =
true,
619 .shadow_static_noise =
false,
uint receiver_light_set_get(ObjectInfos object_infos)
ClosureLight closure_light_new(const UtilityTexture &util_tx, ClosureUndetermined cl, float3 V, Thickness thickness)
#define RAYTRACE_RADIANCE_FORMAT
#define DEFERRED_RADIANCE_FORMAT
float3 subsurface_transmission(const UtilityTexture &util, float3 sss_radii, float thickness)
#define image(slot, qualifiers, format)
#define early_fragment_tests
#define compilation_constant
#define specialization_constant(default_value)
float dot(VecOp< float, D >, VecOp< float, D >) RET
ImageBase< uint, 2, true > uimage2DArray
ImageBase< float, 2 > image2D
IMG_TEMPLATE void imageStore(T &, IntCoord, DataVec)
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
void fullscreen_vertex(int vertex_id, float4 &out_position)
float reduce_add(float2 a)
uint rgb9e5_encode(float3 color)
@ CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID
@ CLOSURE_BSDF_DIFFUSE_ID
@ CLOSURE_BSSRDF_BURLEY_ID
@ CLOSURE_BSDF_THIN_GLASS_TRANSMISSION_ID
@ CLOSURE_BSDF_TRANSLUCENT_ID
void planar_eval_frag(PlanarProbeEval &, LightEvalIterator &lights, const draw::View &views, const draw::Infos &infos, const LightprobeRenderData &lightprobes, const Uniform &uni, const Sampling &sampling, const HiZ &hiz, const UtilityTexture &util_tx, const gbuffer::Reader &reader, const float4 frag_co, const VertOut v_out, FragOut &frag_out)
void aov_clear_frag(RenderPassOutput &render_passes, Uniform &uni, const float4 frag_co)
PipelineGraphic light_single(fullscreen_vert, light_eval_frag, LightEvalConstants{ .light_closure_eval_count_reflect=1,.light_closure_eval_count_transmit=1,.light_closure_count_reflect=1,.light_closure_count_transmit=1, }, ShadowRenderConstants{ .shadow_random=true,.shadow_static_noise=false, })
void sphere_eval_frag(LightEvalIterator &lights, const draw::View &views, const draw::Infos &infos, const Sampling &sampling, const LightprobeVolumeRenderData &lightprobes, const Uniform &uni, const HiZ &hiz, const UtilityTexture &util_tx, const gbuffer::Reader &reader, const float4 frag_co, const VertOut v_out, FragOut &frag_out)
void fullscreen_vert(const int vert_id, float4 &out_position, VertOut &v_out)
PipelineGraphic planar_eval(fullscreen_vert, planar_eval_frag, PlanarProbeEval{ .legacy_sphere_probe_enable=true, }, LightEvalConstants{ .light_closure_eval_count_reflect=2,.light_closure_eval_count_transmit=2,.light_closure_count_reflect=2,.light_closure_count_transmit=2, }, ShadowRenderConstants{ .shadow_random=true,.shadow_static_noise=false, })
PipelineGraphic light_double(fullscreen_vert, light_eval_frag, LightEvalConstants{ .light_closure_eval_count_reflect=2,.light_closure_eval_count_transmit=1,.light_closure_count_reflect=2,.light_closure_count_transmit=1, }, ShadowRenderConstants{ .shadow_random=true,.shadow_static_noise=false, })
PipelineGraphic aov_clear(fullscreen_vert, aov_clear_frag, LightEvalConstants{.light_closure_count_reflect=1,.light_closure_count_transmit=1})
void light_eval_frag(LightEval &srt, LightEvalIterator &lights, const draw::View &views, const draw::Infos &infos, const Uniform &uni, const LightprobeRenderData &lightprobes, const HiZ &hiz, const UtilityTexture &util_tx, const gbuffer::Reader &reader, RenderPassOutput &render_passes, const float4 frag_co, const VertOut v_out)
PipelineGraphic light_triple(fullscreen_vert, light_eval_frag, LightEvalConstants{ .light_closure_eval_count_reflect=3,.light_closure_eval_count_transmit=1,.light_closure_count_reflect=3,.light_closure_count_transmit=1, }, ShadowRenderConstants{ .shadow_random=true,.shadow_static_noise=false, })
PipelineGraphic sphere_eval(fullscreen_vert, sphere_eval_frag, LightEvalConstants{ .light_closure_eval_count_reflect=1,.light_closure_eval_count_transmit=1,.light_closure_count_reflect=1,.light_closure_count_transmit=1, }, ShadowRenderConstants{ .shadow_random=true,.shadow_static_noise=true, })
EvalCtx< true > init_from_reflect_ctx(EvalCtx< false > ctx)
float4 transform(float4 hs_position)
SphericalHarmonicL1< float4 > clamp_energy(SphericalHarmonicL1< float4 > sh, float clamp_value)
float shadow_terminator_normal_offset
float shadow_terminator_geometry_offset
T evaluate_lambert(float3 N) const
float3 point_screen_to_world(float3 ssP) const
float3 world_incident_vector(float3 P) const
int light_closure_eval_count_reflect
LightEvalConstants constants
SphericalHarmonicL1< float4 > volume_irradiance
SphericalHarmonicL1< float4 > sample_probe(const Sampling &sampling, float3 P, float3 V, float3 Ng) const
image2D indirect_radiance_3_img
image2D indirect_radiance_1_img
int shadow_ray_step_count
uimage2DArray direct_radiance_imgs
image2D indirect_radiance_2_img
int render_pass_shadow_id
void write_radiance_indirect(uchar layer_index, int2 texel, float3 radiance)
void write_radiance_direct(uchar layer_index, int2 texel, float3 radiance)
bool legacy_sphere_probe_enable
ClosureStack< is_transmission > stack
float terminator_normal_offset
float terminator_geometry_offset
ClosureUndetermined layer[GBUFFER_LAYER_MAX]
bool has_no_closure() const
CCL_NAMESPACE_BEGIN struct Window V