Render world colors from material color lookup texture
This commit is contained in:
parent
29e5dbeb06
commit
89f963f9a6
2 changed files with 10 additions and 11 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue