The_Dark_Side_of_Earth/buildings/building.gdshader

46 lines
1.5 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()
{
location = ivec2(128. * COLOR.xy);
dimension = ivec2(128. * COLOR.zw);
vec2 myloc = vec2(location) + UV * (vec2(dimension) + vec2(0., .5));
float angle = float(myloc.x) * TAU / 60.;
float height = float(myloc.y) * cell_height + ground_height;
VERTEX = vec2(cos(angle), sin(angle)) * height;
//VERTEX = myloc;
VERTEX = (inverse(MODEL_MATRIX) * vec4(VERTEX, 0, 1)).xy;
2025-09-16 00:19:40 +02:00
world_position = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy;
}
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))/16.;
//COLOR = vec4(1., 1., 1., 1.);
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.
//}