Add directional face shading, closes #148

This commit is contained in:
Lukas Rieger (Blue) 2024-11-20 20:00:06 +01:00
parent 93d2dc54ba
commit f9346f40e6
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6
2 changed files with 13 additions and 2 deletions

View File

@ -34,7 +34,7 @@ import {
Texture, Texture,
Vector3 Vector3
} from "three"; } from "three";
import {alert, dispatchEvent, generateCacheHash, getPixel, hashTile, stringToImage, vecArrToObj} from "../util/Utils"; import {alert, dispatchEvent, getPixel, hashTile, stringToImage, vecArrToObj} from "../util/Utils";
import {TileManager} from "./TileManager"; import {TileManager} from "./TileManager";
import {TileLoader} from "./TileLoader"; import {TileLoader} from "./TileLoader";
import {LowresTileLoader} from "./LowresTileLoader"; import {LowresTileLoader} from "./LowresTileLoader";
@ -358,7 +358,6 @@ export class Map {
type: 't', type: 't',
value: texture value: texture
}, },
transparent: { value: transparent },
...animationUniforms ...animationUniforms
}, },
vertexShader: vertexShader, vertexShader: vertexShader,

View File

@ -24,10 +24,15 @@
*/ */
import { ShaderChunk } from 'three'; import { ShaderChunk } from 'three';
// language=GLSL
export const HIRES_VERTEX_SHADER = ` export const HIRES_VERTEX_SHADER = `
#include <common> #include <common>
${ShaderChunk.logdepthbuf_pars_vertex} ${ShaderChunk.logdepthbuf_pars_vertex}
const vec2 lightDirection = normalize(vec2(1.0, 0.5));
uniform float distance;
attribute float ao; attribute float ao;
attribute float sunlight; attribute float sunlight;
attribute float blocklight; attribute float blocklight;
@ -52,6 +57,13 @@ void main() {
vSunlight = sunlight; vSunlight = sunlight;
vBlocklight = blocklight; vBlocklight = blocklight;
// apply directional lighting
if (vNormal.x * vNormal.z == 0.0) {
float distFac = smoothstep(1000.0, 50.0, distance);
vAo *= 1.0 - abs(dot(vNormal.xz, lightDirection)) * 0.4 * distFac;
vAo *= 1.0 - max(0.0, -vNormal.y) * 0.6 * distFac;
}
gl_Position = projectionMatrix * (viewMatrix * modelMatrix * vec4(position, 1)); gl_Position = projectionMatrix * (viewMatrix * modelMatrix * vec4(position, 1));
${ShaderChunk.logdepthbuf_vertex} ${ShaderChunk.logdepthbuf_vertex}