From 89f963f9a6127ddecb7cce4619ab460108e1b5bc Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Wed, 11 Mar 2026 13:53:23 -0400 Subject: [PATCH] Render world colors from material color lookup texture --- src/scenes/ScreenScene.ts | 3 +++ src/shaders/screenWorld.frag | 18 +++++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/scenes/ScreenScene.ts b/src/scenes/ScreenScene.ts index 40bc485..a641dd2 100644 --- a/src/scenes/ScreenScene.ts +++ b/src/scenes/ScreenScene.ts @@ -38,6 +38,9 @@ export default class ScreenScene extends AbstractScene { value: this.renderer.resources.worldRenderTarget .texture, }, + uMaterialColors: { + value: this.renderer.materialColorTexture, + }, }, vertexShader: vertexShaderGround, fragmentShader: fragmentShaderGround, diff --git a/src/shaders/screenWorld.frag b/src/shaders/screenWorld.frag index 8849fd0..7657b96 100644 --- a/src/shaders/screenWorld.frag +++ b/src/shaders/screenWorld.frag @@ -6,20 +6,18 @@ in vec2 vUv; out vec4 FragColor; uniform sampler2D map; +uniform sampler2D uMaterialColors; void main() { vec4 value = texture(map, vUv); - int cellData = int(value.x); - int isFood = cellData & 1; - int isHome = (cellData & 2) >> 1; - int isObstacle = (cellData & 4) >> 2; + int materialId = int(value.x); float toFood = clamp(value.y, 0., 1.); float toHome = clamp(value.z, 0., 1.); + // pheromone overlay // The part below doen't seem right. // I could figure out a better way to make pheromone colors blend properly on white background :( - vec3 t = vec3(0.95, 0.2, 0.2) * toFood + vec3(0.2, 0.2, 0.95) * toHome; float a = clamp(toHome + toFood, 0., 1.); @@ -29,12 +27,10 @@ void main() { vec3 color = mix(vec3(1, 1, 1), t, a * 0.7); - if (isFood == 1) { - color = vec3(1, 0.1, 0.1); - } else if (isHome == 1) { - color = vec3(0.1, 0.1, 1); - } else if (isObstacle == 1) { - color = vec3(0.6, 0.6, 0.6); + // non-air cells use material color as base, with pheromone tint + if (materialId != MAT_AIR) { + vec4 matColor = texelFetch(uMaterialColors, ivec2(materialId, 0), 0); + color = mix(matColor.rgb, t, a * 0.3); } FragColor = vec4(color, 1);