Blender V5.3
eevee_forward_resolve.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
15
16namespace eevee::forward {
17
25
26[[vertex]]
27void fullscreen_vert([[vertex_id]] const int vert_id, [[position]] float4 &out_position)
28{
29 fullscreen_vertex(vert_id, out_position);
30}
31
36
37[[fragment]]
39 [[resource_table]] const eevee::Uniform &uni,
40 [[resource_table]] RenderPassOutput &render_passes,
41 [[frag_coord]] const float4 frag_co,
42 [[out]] ForwardResolveFragOut &frag_out)
43{
44 int2 texel = int2(frag_co.xy);
45
46 if (uni.pipeline_buf.use_monochromatic_transmittance) {
47 float4 data = texelFetch(srt.transparency_r_tx, texel, 0);
48 frag_out.radiance = float4(data.rgb, 0.0f);
49 frag_out.transmittance = data.aaaa;
50 }
51 else {
52 /* The data is stored "transposed". */
53 float2 channel_r = texelFetch(srt.transparency_r_tx, texel, 0).xy;
54 float2 channel_g = texelFetch(srt.transparency_g_tx, texel, 0).xy;
55 float2 channel_b = texelFetch(srt.transparency_b_tx, texel, 0).xy;
56 float2 channel_a = texelFetch(srt.transparency_a_tx, texel, 0).xy;
57
58 /* frag_out.transmittance gets multiplied to the frame-buffer color. */
59 frag_out.transmittance.r = channel_r.y;
60 frag_out.transmittance.g = channel_g.y;
61 frag_out.transmittance.b = channel_b.y;
62 frag_out.transmittance.a = channel_a.y;
63
64 /* frag_out.radiance gets added to the frame-buffer color after the transmittance
65 * multiplication. */
66 frag_out.radiance.r = channel_r.x;
67 frag_out.radiance.g = channel_g.x;
68 frag_out.radiance.b = channel_b.x;
69 frag_out.radiance.a = channel_a.x;
70 }
71
72 /* Since Forward.Transparent is additive, overlapping high emissive values can reach the float16
73 * limit and end up stored as INF, so here we just clamp it to representable values. */
74 const float half_max = 65504.0f;
75 frag_out.radiance = min(frag_out.radiance, half_max);
76
77 render_passes.store_color(texel,
78 uni.uniform_buf.render_pass.transparent_id,
79 float4(frag_out.radiance.rgb, frag_out.transmittance.a));
80}
81
82} // namespace eevee::forward
83
PipelineGraphic eevee_forward_resolve(eevee::forward::fullscreen_vert, eevee::forward::resolve_frag)
#define position
#define index(i)
#define frag_coord
#define resource_table
#define sampler(slot)
#define fragment
#define vertex_id
#define vertex
#define frag_color(slot)
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
SamplerBase< float, 2 > sampler2D
void fullscreen_vertex(int vertex_id, float4 &out_position)
void fullscreen_vert(const int vert_id, float4 &out_position)
void resolve_frag(const ForwardResolve &srt, const eevee::Uniform &uni, RenderPassOutput &render_passes, const float4 frag_co, ForwardResolveFragOut &frag_out)
#define min(a, b)
Definition sort.cc:38
float x
float y