Last active
April 30, 2025 17:36
-
-
Save partybusiness/3e1186d8745935445ca376df6ea8cfbd to your computer and use it in GitHub Desktop.
Iris shader in godot that can open and close for transitions
This file contains hidden or 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
shader_type canvas_item; | |
render_mode unshaded; | |
// iris shader, apply to a ColorRect that overlays the screen and set iris_size to iris in and out | |
// this one allows you to use a texture to shape the iris | |
// 0.0 = fully close, 1.0 = fully open | |
uniform float iris_size:hint_range(0.0, 1.0, 0.01) = 0.5; | |
// multiply the size of the texture beyond centre | |
uniform float max_size_mult:hint_range(1.0, 10.0, 0.1) = 2.5; | |
// centre point of the iris | |
uniform vec2 centre = vec2(0.5, 0.5); | |
uniform sampler2D iris_texture:repeat_disable; | |
void fragment() { | |
// ratio does assume we're on landscape screen, if you can't assume that this needs more | |
vec2 ratio = vec2(1.0, SCREEN_PIXEL_SIZE.x / SCREEN_PIXEL_SIZE.y); | |
// max distance from centre to corners | |
float max_dist = length(vec2(max(centre.x, 1.0 - centre.x), max(centre.y, 1.0 - centre.y)) * ratio); | |
float radius = mix(0.0, max_dist * max_size_mult, iris_size); | |
vec4 text = texture(iris_texture, (SCREEN_UV - centre) * ratio / radius + 0.5); | |
COLOR = text; // this assumes your texture has transparent hole in middle | |
// you could also use .r value from black-and-white texture as hole shape | |
//COLOR.rgb = vec3(0.0); // black | |
//COLOR.a = 1.0 - text.r; | |
} |
This file contains hidden or 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
shader_type canvas_item; | |
render_mode unshaded; | |
// iris shader, apply to a ColorRect that overlays the screen and set iris_size to iris in and out | |
// 0.0 = fully close, 1.0 = fully open | |
uniform float iris_size:hint_range(0.0, 1.0, 0.01) = 0.5; | |
// how blurry the edge of the iris should be | |
uniform float feather:hint_range(0.0, 0.2, 0.01) = 0.05; | |
// centre point of the iris | |
uniform vec2 centre = vec2(0.5, 0.5); | |
void fragment() { | |
COLOR.rgb = vec3(0.0); // black | |
// ratio does assume we're on landscape screen, if you can't assume that this needs more | |
vec2 ratio = vec2(1.0, SCREEN_PIXEL_SIZE.x / SCREEN_PIXEL_SIZE.y); | |
// max distance from centre to corners | |
float max_dist = length(vec2(max(centre.x, 1.0 - centre.x), max(centre.y, 1.0 - centre.y)) * ratio); | |
float radius = mix(-feather, max_dist, iris_size); | |
float dist = length(ratio * (SCREEN_UV - centre)); | |
COLOR.a = smoothstep(radius, radius + feather, dist); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment