0

I'm trying to create a pixelation shader which I can view through the camera2D node
something like this but instead of black and white I need pixelation

using this answer I got a pixelation shader but how do I view it through the camera?

shader_type canvas_item;

uniform float size_x = 32.0; // blocks by x direction
uniform float size_y = 32.0; // blocks by y direction

void fragment() {
    COLOR = texture(TEXTURE, vec2(floor(UV.x * size_x) / (size_x - 1.0), floor(UV.y * size_y) / (size_y - 1.0)));
}

the structure of my nodes is same as in the above video link:

enter image description here

The end product should maybe look something like this: enter image description here

cak3_lover
  • 1,440
  • 5
  • 26
  • 1
    I believe the video explains the setup, you would only have to replace the shader code. By the way. that is not the node structure I see in the video. Furthermore, the video also has the code for a pixelation shader. Try following the video more closely. I'm confident you can figure it out. In fact, if you write the answer explaining it, I'll up-vote it. – Theraot Feb 06 '22 at 15:00
  • thanks @Theraot ! btw while I have your attention, I'm not really sure about the approach I'm taking for pixelation, my current plan is to create a 2D cutout character and then pixelate the character with the pixelation shader but I've been told that might take too much computation power, is that true? if so is there some other approach I can take? (I'm using cut out animation instead of sprite based animation because I'm trying to create intricate animations) – cak3_lover Feb 07 '22 at 08:08
  • Post process shaders (and additional viewports) have a cost. Yet, it isn't a problem for desktop. But it can be a problem for mobile, depending on the device and how complex the shader is. About alternatives, if you are applying pixelation to the whole screen, and not animating the pixelation, you are probably better off rendering to a smaller target and up-scaling. Refer to [Multiple resolutions](https://docs.godotengine.org/en/stable/tutorials/rendering/multiple_resolutions.html). See also [How to make a silky smooth camera for pixelart games in Godot](https://youtu.be/zxVQsi9wnw8). – Theraot Feb 07 '22 at 08:31

1 Answers1

0

ah I found my mistake, I accidentally had use parent material selected

the shader code was the same:

shader_type canvas_item;

uniform float size_x = 0.008;
uniform float size_y = 0.008;

void fragment() {
    vec2 uv = SCREEN_UV;
    uv -= mod(uv, vec2(size_x, size_y));
    
    COLOR.rgb = textureLod(SCREEN_TEXTURE, uv, 0.0).rgb;
}
cak3_lover
  • 1,440
  • 5
  • 26
  • To be clear, `use_parent_material` is a property of the nodes, and this is the shader from the video. – Theraot Feb 07 '22 at 08:33