Blender V5.3
eevee_lookdev_display.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9
10#pragma once
11
12#include "gpu_shader_compat.hh"
13
14namespace eevee::lookdev {
15
20
24
33
34[[vertex]]
36 [[vertex_id]] const int vert_id,
37 [[instance_id]] const int inst_id,
38 [[position]] float4 &out_position,
39 [[out]] DisplayVertOut &v_out)
40{
41 uint vert_index = (vert_id < 3) ? uint(vert_id) : uint(vert_id - 2);
42
43 float2 uv = float2(vert_index / 2, vert_index % 2);
44 v_out.uv_coord = uv;
45 v_out.sphere_id = uint(inst_id);
46
47 float2 sphere_size = float2(textureSize(srt.metallic_tx, 0)) * srt.invertedViewportSize;
48 float2 margin = float2(0.125f, -0.125f) * sphere_size;
49 float2 anchor_point = float2(1.0f, -1.0f) -
50 float2(srt.viewportSize.x - srt.anchor.x, -srt.anchor.y) *
51 srt.invertedViewportSize * float2(2.0f) -
52 margin;
53
54 float2 offset = anchor_point -
55 float2(sphere_size.x * (inst_id + 1) + margin.x * 2.0f * inst_id, 0.0f);
56 float2 co = uv * sphere_size + offset;
57 out_position = float4(co, 0.0f, 1.0f);
58}
59
60[[fragment]]
62 [[in]] const DisplayVertOut &v_out,
63 [[out]] DisplayFragOut &frag_out,
64 [[frag_depth(any)]] float &out_depth)
65{
66 float2 texture_size = float2(textureSize(srt.metallic_tx, 0));
67 float2 texel_size = float2(1.0f) / texture_size;
68
69 float distance_from_center = distance(v_out.uv_coord, float2(0.5f));
70 if (distance_from_center > 0.5f) {
72 return;
73 }
74 float smooth_size = texel_size.x * 1.5f;
75 float smooth_offset = texel_size.x * 0.5f;
76 float factor = (distance_from_center - 0.5f + smooth_offset + smooth_size) *
77 (1.0f / smooth_size);
78 float alpha = clamp(1.0f - factor, 0.0f, 1.0f);
79
80 float4 color = v_out.sphere_id == 0 ? texture(srt.metallic_tx, v_out.uv_coord.xy, 0) :
81 texture(srt.diffuse_tx, v_out.uv_coord.xy, 0);
82 color.a = alpha;
83 frag_out.color = color;
84
85 /* Ensure balls are on top of overlays. */
86 out_depth = 0.0f;
87}
88
89} // namespace eevee::lookdev
90
PipelineGraphic eevee_lookdev_display(eevee::lookdev::display_vert, eevee::lookdev::display_frag)
#define instance_id
#define position
#define flat
#define smooth
#define push_constant
#define resource_table
#define sampler(slot)
#define frag_depth(mode)
#define fragment
#define vertex_id
#define vertex
#define frag_color(slot)
void gpu_discard_fragment()
bool any(VecOp< bool, D >) RET
float distance(float, float) RET
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 display_vert(Display &srt, const int vert_id, const int inst_id, float4 &out_position, DisplayVertOut &v_out)
void display_frag(Display &srt, const DisplayVertOut &v_out, DisplayFragOut &frag_out, float &out_depth)
float x