Tilt-Shift Shader (minimal)

Updated version of the Tilt Shift Shader by ChaffDev.

Changes:

  • Updated for Godot 4 to use uniform sampler2D screen_texture.
  • Smooths the blurring amount based on distance from the edge.
  • Removes unused variables and debugger code.
  • Shortened for clarity.

Usage:

This works as a screen shader, and so can be applied to a ColorRect node that is filling the screen, transparent, and drawn last (bottom of the scene tree).

The shader takes two variables:

limit determines the proportion of the screen that will be blurred from the top and bottom. 0.0 – 0.5.

blur determines the maximum amount of blur that occurs on the very top and bottom edge. This drops off to zero as it approaches the limit in the direction of the center.

Known issues:

  • `textureLod()` Does not properly blur if the neighboring pixels are transparent / background color.
Shader code
// Original by ChaffDave : https://godotshaders.com/shader/tilt-shift-shader/

shader_type canvas_item;

uniform float limit: hint_range(0.0,0.5) = 0.2;
uniform float blur: hint_range(0.0,8.0) = 2.0;
uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap;

void fragment(){
	
	if (UV.y<limit){

		float blur_amount = blur * (1.0 - (SCREEN_UV.y / limit));
		COLOR = textureLod(screen_texture, SCREEN_UV, blur_amount);

	} else if (UV.y > 1.0-limit){

		float blur_amount = blur * (1.0 - ((1.0 - SCREEN_UV.y) / limit));
		COLOR = textureLod(screen_texture, SCREEN_UV, blur_amount);

	} else {
		COLOR.a = 0.0;
	}
}
Tags
camera, minimal, tilt-shift
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

2D shadow with bottom offset, image ratio independent shadow direction, and minimal vertex increase

far distance water shader (sea shader)

Fire dissolve shader

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments