The_Dark_Side_of_Earth/buildings/building.gdshader

40 lines
1.2 KiB
Text
Raw Normal View History

2025-09-16 00:19:40 +02:00
shader_type canvas_item;
varying flat ivec2 location;
varying flat ivec2 dimension;
2025-09-16 00:19:40 +02:00
uniform float ground_height = 3000.;
uniform float cell_height = 300.;
uniform int num_cells = 60;
varying vec2 world_position;
void vertex()
{
world_position = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy;
location = ivec2(256. * COLOR.xy);
dimension = ivec2(256. * COLOR.zw);
//location = ivec2(45, 1);
//dimension = ivec2(1, 1);
2025-09-16 00:19:40 +02:00
}
void fragment() {
float radius = sqrt(world_position.x * world_position.x + world_position.y * world_position.y);
float angle = atan(world_position.y, world_position.x);
float sample_y = 1. - ((radius - ground_height) / cell_height - float( location.y)) / float(dimension.y);
float sample_x = mod(fract(angle / TAU + 1.) * float(num_cells) - float(location.x) + float(num_cells), float(num_cells)) / float(dimension.x);
if(sample_y > 1. || sample_y < 0. || sample_x > 1. || sample_x < 0.) {
discard;
}
COLOR = texture(TEXTURE, vec2(sample_x, sample_y));
//COLOR = vec4(ivec4(location, dimension));
2025-09-16 00:19:40 +02:00
}
//void light() {
// // Called for every pixel for every light affecting the CanvasItem.
// // Uncomment to replace the default light processing function with this one.
//}