-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render backgrounds in sub-viewports and transition them using shaders (…
…#1839) This keeps all the new viewport and shader stuff but offloads most of the work to behind the scenes. This means background scenes can work just as they did previously. However they are manually put into subvieports+subviewportcontainers. The backgrounds-holder is now also the background-displayer. _fade_out() and _fade_in() have been renamed to _custom_fade_out() and _custom_fade_in(). Right now they work "additionally" to the default fade which happens as well. If you know what you are doing you can work around this though. I have to put further thought into custom transitions as I have no real idea what the best user-experience/use case might be. --------- Co-authored-by: Jowan-Spooner <raban-loeffler@posteo.de>
- Loading branch information
1 parent
c8e2334
commit a7f565c
Showing
8 changed files
with
202 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
addons/dialogic/Modules/Background/default_background_transition.gdshader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
shader_type canvas_item; | ||
|
||
// Indicates how far the transition is (0 start, 1 end). | ||
uniform float progress : hint_range(0.0, 1.0); | ||
// The previous background, transparent if there was none. | ||
uniform sampler2D previous_background : source_color, hint_default_transparent; | ||
// The next background, transparent if there is none. | ||
uniform sampler2D next_background : source_color, hint_default_transparent; | ||
|
||
// The texture used to determine how far along the progress has to be for bending in the new background. | ||
uniform sampler2D whipe_texture : source_color; | ||
// The size of the trailing smear of the transition. | ||
uniform float feather : hint_range(0.0, 1.0, 0.0001) = 0.1; | ||
// Determines if the whipe texture should keep it's aspect ratio when scaled to the screen's size. | ||
uniform bool keep_aspect_ratio = false; | ||
|
||
void fragment() { | ||
vec2 frag_coord = UV; | ||
if(keep_aspect_ratio) { | ||
vec2 ratio = (SCREEN_PIXEL_SIZE.x > SCREEN_PIXEL_SIZE.y) // determine how to scale | ||
? vec2(SCREEN_PIXEL_SIZE.y / SCREEN_PIXEL_SIZE.x, 1) // fit to width | ||
: vec2(1, SCREEN_PIXEL_SIZE.x / SCREEN_PIXEL_SIZE.y); // fit to height | ||
frag_coord *= ratio; | ||
} | ||
|
||
// get the blend factor between the previous and next background. | ||
float alpha = (texture(whipe_texture, frag_coord).r) - progress; | ||
float blend_factor = 1. - smoothstep(0., feather, alpha + (feather * (1. -progress))); | ||
|
||
vec4 old_frag = texture(previous_background, UV); | ||
vec4 new_frag = texture(next_background, UV); | ||
|
||
COLOR = mix(old_frag, new_frag, blend_factor); | ||
} |
17 changes: 17 additions & 0 deletions
17
addons/dialogic/Modules/Background/default_background_transition.tres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[gd_resource type="ShaderMaterial" load_steps=4 format=3 uid="uid://0wc7bedn7ee8"] | ||
|
||
[ext_resource type="Shader" path="res://addons/dialogic/Modules/Background/default_background_transition.gdshader" id="1_uctph"] | ||
|
||
[sub_resource type="Gradient" id="Gradient_4flwl"] | ||
offsets = PackedFloat32Array(0.496403) | ||
colors = PackedColorArray(0.524751, 0.524751, 0.524751, 1) | ||
|
||
[sub_resource type="GradientTexture1D" id="GradientTexture1D_gkpb1"] | ||
gradient = SubResource("Gradient_4flwl") | ||
|
||
[resource] | ||
shader = ExtResource("1_uctph") | ||
shader_parameter/progress = 0.035 | ||
shader_parameter/feather = 1.0 | ||
shader_parameter/keepAspectRatio = false | ||
shader_parameter/whipeTexture = SubResource("GradientTexture1D_gkpb1") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
class_name DialogicNode_BackgroundHolder | ||
extends CanvasLayer | ||
extends ColorRect | ||
|
||
|
||
func _ready(): | ||
add_to_group('dialogic_background_holders') | ||
if material == null: | ||
material = load("res://addons/dialogic/Modules/Background/default_background_transition.tres") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.