Blender V5.3
workbench_transparent_resolve.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5/* Based on :
6 * McGuire and Bavoil, Weighted Blended Order-Independent Transparency, Journal of
7 * Computer Graphics Techniques (JCGT), vol. 2, no. 2, 122–141, 2013
8 */
9
10#pragma once
11
13
15
16[[vertex]]
17void vert([[vertex_id]] const int vert_id, [[position]] float4 &position)
18{
20}
21
26
27struct FragOut {
29};
30
31[[fragment]]
33 [[frag_coord]] const float4 frag_co,
34 [[out]] FragOut &frag_out)
35{
36 float2 screen_uv = frag_co.xy / float2(textureSize(srt.transparent_accum, 0).xy);
37 /* Revealage is actually stored in transparent_accum alpha channel.
38 * This is a workaround to older hardware not having separate blend equation per render target.
39 */
40 float4 trans_accum = texture(srt.transparent_accum, screen_uv);
41 float trans_weight = texture(srt.transparent_revealage, screen_uv).r;
42 float trans_reveal = trans_accum.a;
43
44 /* Listing 4 */
45 frag_out.color.rgb = trans_accum.rgb / clamp(trans_weight, 1e-4f, 5e4f);
46 frag_out.color.a = 1.0f - trans_reveal;
47}
48
49} // namespace workbench::transparency
50
#define position
#define frag_coord
#define resource_table
#define sampler(slot)
#define fragment
#define vertex_id
#define vertex
#define frag_color(slot)
constexpr T clamp(T, U, U) RET
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
SamplerBase< float, 2 > sampler2D
TEX_TEMPLATE SizeVec textureSize(T, int) RET
void fullscreen_vertex(int vertex_id, float4 &out_position)
void vert(const int vert_id, float4 &position)
void resolve_weight_blended_order_independant_transparency(const Resolve &srt, const float4 frag_co, FragOut &frag_out)
PipelineGraphic workbench_transparent_resolve(workbench::transparency::vert, workbench::transparency::resolve_weight_blended_order_independant_transparency)