Skip to content

Could this work in a post processing shader? #1

@EeroMutka

Description

@EeroMutka

My game is a pixel-art game where you can zoom around, but I want to make stuff like fire shaders or dust particles with that same pixel-art style. If I use the window mode 'viewport', it works, but zooming gets messed up. If I use '2d', those things are rendered at too high resolution.

Now this isn't directly related to your shader, but I thought it could be also combined to this and you could maybe help. What if I used a post processing shader that pixelates everything in world space? This way you also wouldn't have to apply your material to every sprite in the game

The first annoyance is that godot canvas item shaders won't give you world coordinates as inputs so you need to use a trick. Here's the rest of my code (I made the screen resolution 256x256 and preview res 1024x1024 for simplicity)

void fragment()
{
	vec2 coord = SCREEN_UV + fract(world_pos)/vec2(-256, 256);
	vec4 color = texture(SCREEN_TEXTURE, coord);

	COLOR = color;
}

This code sort of works, but the sampling isn't perfect, it samples a bit of nearby pixels. I'm not sure why. Also when you zoom in and out there are artifacts which can be fixed by switching to textureLod(). If I use your texturePointSmooth function, the flickering disappears, but there are some artifacts when zooming as well as that nearby pixel blurriness

any help is appreciated, would be awesome to get this to work
edit: messing around a bit more as I noticed some issues with my code, sending a project once I'm ready

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions