Film Grain Shader

Full code for the film grain shader tutorial that I wrote. The details of how to implement this shader are discussed in the post. If you simply need the code, its yours & no need for any credit!

Shader code
shader_type canvas_item;

// Uniforms
uniform sampler2D screen_texture : hint_screen_texture;
uniform float grain_amount : hint_range(0.0, 1.0) = 0.05; // Adjust the amount of grain
uniform float grain_size : hint_range(0.1, 10.0) = 1.0; // Adjust the size of the grain

void fragment() {
    // Sample the original screen texture
    vec4 original_color = texture(screen_texture, SCREEN_UV);

    // Generate random noise
    float noise = (fract(sin(dot(UV, vec2(12.9898, 78.233))) * 43758.5453) - 0.5) * 2.0;

    // Add noise to the original color
    original_color.rgb += noise * grain_amount * grain_size;

    // Clamp the final color to make sure it stays in the valid range
    COLOR = clamp(original_color, 0.0, 1.0);
film grain, white noise
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.

More from mujtaba-io

screen space refraction shader

Gerstner Wave Ocean Shader

sine wave camera view shader

Related shaders

Post-Processing, Grain PP effect and Palette Color

Grain (Old Movie)

Speed Lines Shader for Godot 4

Notify of

Inline Feedbacks
View all comments