Render world colors from material color lookup texture

This commit is contained in:
Jared Miller 2026-03-11 13:53:23 -04:00
parent 29e5dbeb06
commit 89f963f9a6
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 10 additions and 11 deletions

View file

@ -38,6 +38,9 @@ export default class ScreenScene extends AbstractScene {
value: this.renderer.resources.worldRenderTarget value: this.renderer.resources.worldRenderTarget
.texture, .texture,
}, },
uMaterialColors: {
value: this.renderer.materialColorTexture,
},
}, },
vertexShader: vertexShaderGround, vertexShader: vertexShaderGround,
fragmentShader: fragmentShaderGround, fragmentShader: fragmentShaderGround,

View file

@ -6,20 +6,18 @@ in vec2 vUv;
out vec4 FragColor; out vec4 FragColor;
uniform sampler2D map; uniform sampler2D map;
uniform sampler2D uMaterialColors;
void main() { void main() {
vec4 value = texture(map, vUv); vec4 value = texture(map, vUv);
int cellData = int(value.x); int materialId = int(value.x);
int isFood = cellData & 1;
int isHome = (cellData & 2) >> 1;
int isObstacle = (cellData & 4) >> 2;
float toFood = clamp(value.y, 0., 1.); float toFood = clamp(value.y, 0., 1.);
float toHome = clamp(value.z, 0., 1.); float toHome = clamp(value.z, 0., 1.);
// pheromone overlay
// The part below doen't seem right. // The part below doen't seem right.
// I could figure out a better way to make pheromone colors blend properly on white background :( // 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; 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.); float a = clamp(toHome + toFood, 0., 1.);
@ -29,12 +27,10 @@ void main() {
vec3 color = mix(vec3(1, 1, 1), t, a * 0.7); vec3 color = mix(vec3(1, 1, 1), t, a * 0.7);
if (isFood == 1) { // non-air cells use material color as base, with pheromone tint
color = vec3(1, 0.1, 0.1); if (materialId != MAT_AIR) {
} else if (isHome == 1) { vec4 matColor = texelFetch(uMaterialColors, ivec2(materialId, 0), 0);
color = vec3(0.1, 0.1, 1); color = mix(matColor.rgb, t, a * 0.3);
} else if (isObstacle == 1) {
color = vec3(0.6, 0.6, 0.6);
} }
FragColor = vec4(color, 1); FragColor = vec4(color, 1);