You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-24 15:26:15 +00:00
Implement distance fade and transparency
The built-in ALPHA in spatial shaders comes pre-set with a per-instance
transparency value. Multiply by it if you want to keep it.
The transparency value of any given GeometryInstance3D is affected by:
- Its new "transparency" property.
- Its own visiblity range when the new "visibility_range_fade_mode"
property is set to "Self".
- Its parent visibility range when the parent's fade mode is
set to "Dependencies".
The "Self" mode will fade-out the instance when reaching the visibility
range limits, while the "Dependencies" mode will fade-in its
dependencies.
Per-instance transparency is only implemented in the forward clustered
renderer, support for mobile should be added in the future.
Co-authored-by: reduz <reduzio@gmail.com>
This commit is contained in:
@@ -95,7 +95,7 @@ layout(location = 8) out float dp_clip;
|
||||
|
||||
#endif
|
||||
|
||||
layout(location = 9) out flat uint instance_index;
|
||||
layout(location = 9) out flat uint instance_index_interp;
|
||||
|
||||
invariant gl_Position;
|
||||
|
||||
@@ -107,7 +107,8 @@ void main() {
|
||||
color_interp = color_attrib;
|
||||
#endif
|
||||
|
||||
instance_index = draw_call.instance_index;
|
||||
uint instance_index = draw_call.instance_index;
|
||||
instance_index_interp = instance_index;
|
||||
|
||||
bool is_multimesh = bool(instances.data[instance_index].flags & INSTANCE_FLAGS_MULTIMESH);
|
||||
if (!is_multimesh) {
|
||||
@@ -410,7 +411,7 @@ layout(location = 8) in float dp_clip;
|
||||
|
||||
#endif
|
||||
|
||||
layout(location = 9) in flat uint instance_index;
|
||||
layout(location = 9) in flat uint instance_index_interp;
|
||||
|
||||
//defines to keep compatibility with vertex
|
||||
|
||||
@@ -564,6 +565,12 @@ void main() {
|
||||
discard;
|
||||
#endif
|
||||
|
||||
#ifdef USE_SUBGROUPS
|
||||
//ensures instance_index is in sgpr
|
||||
uint instance_index = subgroupBroadcastFirst(instance_index_interp);
|
||||
#else
|
||||
uint instance_index = instance_index_interp;
|
||||
#endif
|
||||
//lay out everything, whathever is unused is optimized away anyway
|
||||
vec3 vertex = vertex_interp;
|
||||
vec3 view = -normalize(vertex_interp);
|
||||
@@ -593,7 +600,7 @@ void main() {
|
||||
float ao = 1.0;
|
||||
float ao_light_affect = 0.0;
|
||||
|
||||
float alpha = 1.0;
|
||||
float alpha = float(instances.data[instance_index].flags >> INSTANCE_FLAGS_FADE_SHIFT) / float(255.0);
|
||||
|
||||
#if defined(TANGENT_USED) || defined(NORMAL_MAP_USED) || defined(LIGHT_ANISOTROPY_USED)
|
||||
vec3 binormal = normalize(binormal_interp);
|
||||
@@ -1897,7 +1904,6 @@ void main() {
|
||||
|
||||
// Draw "fixed" fog before volumetric fog to ensure volumetric fog can appear in front of the sky.
|
||||
frag_color.rgb = mix(frag_color.rgb, fog.rgb, fog.a);
|
||||
;
|
||||
|
||||
#endif //MODE_MULTIPLE_RENDER_TARGETS
|
||||
|
||||
|
||||
Reference in New Issue
Block a user