LED shader is incomplete, and I'm at a wall.
Asked Answered
E

2

0

I've been working on a shader that should make a viewport display whatever is in it like those old LCD grid screens. The real low pixel ones. It almost works. I can cut it in lines going in one direction fine, but not a full grid cut.

shader_type canvas_item;

uniform float y_float;

uniform float size = 200.0; 

void fragment() {
	vec2 ratio = vec2(1.0, TEXTURE_PIXEL_SIZE.x / TEXTURE_PIXEL_SIZE.y);
	vec2 pixelated_uv = floor(UV * ratio * size) / (size * ratio); 
	vec2 pixels = (fract(UV * size * ratio) - vec2(.5)) * 4.5;
	pixels = (1.0 - dots) * 10.0; 
	pixels = clamp(dots, 0.0, 1.0);
	pixels = floor(dots);
	vec4 matrix1 = mix(texture(SCREEN_TEXTURE, SCREEN_UV), texture(TEXTURE, pixelated_uv), pixels.x); 
	vec4 matrix2 = mix(texture(SCREEN_TEXTURE, SCREEN_UV), texture(TEXTURE, pixelated_uv), pixels.y);
	vec3 ledMatrix = mix(matrix1.rgb, matrix2.rgb, 0.5);
	COLOR.rgb = ledMatrix;
	COLOR.a = texture(TEXTURE, pixelated_uv).a;
	
}

As you can see, I'm using mix for now to combine the horizontal and vertical lines, but it's, well, mixing. I don't want to interpolate between the two.

To the right is what's supposed to be displayed, the left is what I'm getting due to mix and not knowing what a lot of the words in the shader docs mean.

Euphemism answered 3/4, 2022 at 11:9 Comment(0)
P
0

Do you need the culled areas to be transparent? If not, you could overlay the Viewport with a tiling TextureRect that uses a grid pattern texture.

Parkland answered 4/4, 2022 at 18:22 Comment(0)
E
0

so how it works is it pixelates a viewport within a viewport container. It breaks it up into a matrix of square dots, so the result is a viewport that resembles a backlit led, a lot like the original Gameboy. But as you can see, it doesn't cull completely. Each square has faded pixels around it.

Euphemism answered 5/4, 2022 at 10:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.