0 votes

Is it possible to modify this spatial mosaic shader so the pixel sizes are consistent with the distance of the object it's applied to? I need the mosaic to be applied to only the mesh and nothing surrounding it (I'm currently using material_overlay) but at a distance the pixels are appear extremely large:

shader_type spatial;
render_mode unshaded;

uniform float size = 20.0;

void fragment( )
{
    vec2 p = floor( FRAGCOORD.xy / size ) * size;
    vec2 quat_x = vec2( size / 4.0, 0 );
    vec2 quat_y = vec2( 0, quat_x.x );
    ALBEDO = (
        texelFetch( SCREEN_TEXTURE, ivec2( p ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_x ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_x * 2.0 ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_x * 3.0 ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_y ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_y + quat_x ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_y + quat_x * 2.0 ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_y + quat_x * 3.0 ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_y * 2.0 ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_y * 2.0 + quat_x ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_y * 2.0 + quat_x * 2.0 ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_y * 2.0 + quat_x * 3.0 ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_y * 3.0 ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_y * 3.0 + quat_x ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_y * 3.0 + quat_x * 2.0 ), 0 ).xyz
    +    texelFetch( SCREEN_TEXTURE, ivec2( p + quat_y * 3.0 + quat_x * 3.0 ), 0 ).xyz
    ) / 16.0;
}
Godot version 3.5
in Engine by (35 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.