Godot Version
4.3
Question
Hello I wrote this simple shader to make tiling some seamless textures nicer.
shader_type spatial;
uniform sampler2D tex;
// A shader for tiling (seemingly) without repetition.
#define MAX_TILES 100
// Scales the UV coordinates.
uniform float detail = 1.0;
// The number of tiles that will be rotate
uniform int tile_count = 1;
// Angles for each tile that are used to rotate the UV coordiates inside the tile.
uniform float tile_angles[MAX_TILES];
uniform float roughness = 0.5;
mat2 rotate(float angle) {
return mat2(
vec2(cos(angle), sin(angle)),
vec2(-sin(angle), cos(angle))
);
}
void fragment() {
vec2 uv = UV * detail;
int side = int(ceil(sqrt(float(tile_count))));
for (int i = 0; i < tile_count; i++) {
for (int j = 0; j < tile_count; j++) {
if (int(uv.x) % tile_count == i &&
int (uv.y) % tile_count == j) {
float angle = tile_angles[i * tile_count + j];
ALBEDO = texture(tex, rotate(angle) * uv).rgb;
}
}
}
ROUGHNESS = roughness;
}
It looks as follows in the editor:
However when I run the game it looks like this:
I.e. the scaling of UV values is somehow different. Any idea what I am doing wrong?