I made a working pixelated shader and I don't know how. Please help.
Asked Answered
M

4

0

I've studied all the shader docs I could find and I'm still almost clueless. I ran into a problem where bigger images needed a higher amplitude of pixelation to look the same as a smaller image. Makes sense to me but that sounded like it could be complicated later on. I experimented for a day and found that multiplying that amplification value by the divisor(is that the word?) of the texture's longer dimension (x or y) by 100. I really don't know why. I had the idea and it made sense at the moment for a reason I don't remember. I'll post exactly what equations are being used.

GDscript:

pixel_amplification_value = max(texture.get_size.x, texture.get_size.y) / 100

ShaderGL(or whatever it's called) amp = pixel_amplification_value

pixel_uv = ((floor(UV * amp) / amp) * ratio); COLOR = texture(TEXTURE, pixel_uv);

ratio just gets the texture's aspect ratio in GDscript, it works how you'd probably imagine.

I need to keep a notepad, I have these strokes of genius and then I forget how it works.

Manion answered 2/3, 2022 at 2:47 Comment(0)
M
0

Oh no that post looks like garbage. How do I edit it? How did it come out that way?

Manion answered 2/3, 2022 at 2:52 Comment(0)
M
0

I found the edit button.

Manion answered 2/3, 2022 at 2:54 Comment(0)
D
0

There are probably simpler ways to do it, but that code looks correct. The basic idea is that you are talking a floating point value and breaking it up into discrete steps. I haven't tested this code, but it may work as well.

float dx = 160.0 * TEXTURE_PIXEL_SIZE;
float dy = 90.0 * TEXTURE_PIXEL_SIZE;
vec2 uv = vec2(dx * floor(UV.x / dx), dy * floor(UV.y / dy));
COLOR = texture(TEXTURE, uv);
Darden answered 2/3, 2022 at 5:9 Comment(0)
M
0

@cybereality said: There are probably simpler ways to do it, but that code looks correct. The basic idea is that you are talking a floating point value and breaking it up into discrete steps. I haven't tested this code, but it may work as well.

float dx = 160.0 * TEXTURE_PIXEL_SIZE;
float dy = 90.0 * TEXTURE_PIXEL_SIZE;
vec2 uv = vec2(dx * floor(UV.x / dx), dy * floor(UV.y / dy));
COLOR = texture(TEXTURE, uv);

I tried it, it didn't work but I rewrote mine again. I don't have a clue what I did differently, but aspect ratio is no longer needed in the various size images I tried.

Manion answered 2/3, 2022 at 9:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.