Add per-pixel hash noise to material colors

This commit is contained in:
Jared Miller 2026-03-11 20:57:13 -04:00
parent aa3c94091b
commit 4c11924580
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -8,6 +8,12 @@ out vec4 FragColor;
uniform sampler2D map; uniform sampler2D map;
uniform sampler2D uMaterialColors; uniform sampler2D uMaterialColors;
float hash(ivec2 p) {
int h = p.x * 374761393 + p.y * 668265263;
h = (h ^ (h >> 13)) * 1274126177;
return float(h & 0x7fffffff) / float(0x7fffffff);
}
void main() { void main() {
vec4 value = texture(map, vUv); vec4 value = texture(map, vUv);
@ -30,7 +36,10 @@ void main() {
// non-air cells use material color as base, with pheromone tint // non-air cells use material color as base, with pheromone tint
if (materialId != MAT_AIR) { if (materialId != MAT_AIR) {
vec4 matColor = texelFetch(uMaterialColors, ivec2(materialId, 0), 0); vec4 matColor = texelFetch(uMaterialColors, ivec2(materialId, 0), 0);
color = mix(matColor.rgb, t, a * 0.3); // per-pixel color variation: +/-4% brightness noise
float colorNoise = hash(ivec2(gl_FragCoord.xy)) * 0.08 - 0.04;
vec3 variedColor = matColor.rgb + colorNoise;
color = mix(variedColor, t, a * 0.3);
} }
FragColor = vec4(color, 1); FragColor = vec4(color, 1);