Skip to content

Commit f9346f4

Browse files
committed
Add directional face shading, closes #148
1 parent 93d2dc5 commit f9346f4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

common/webapp/src/js/map/Map.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
Texture,
3535
Vector3
3636
} from "three";
37-
import {alert, dispatchEvent, generateCacheHash, getPixel, hashTile, stringToImage, vecArrToObj} from "../util/Utils";
37+
import {alert, dispatchEvent, getPixel, hashTile, stringToImage, vecArrToObj} from "../util/Utils";
3838
import {TileManager} from "./TileManager";
3939
import {TileLoader} from "./TileLoader";
4040
import {LowresTileLoader} from "./LowresTileLoader";
@@ -358,7 +358,6 @@ export class Map {
358358
type: 't',
359359
value: texture
360360
},
361-
transparent: { value: transparent },
362361
...animationUniforms
363362
},
364363
vertexShader: vertexShader,

common/webapp/src/js/map/hires/HiresVertexShader.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@
2424
*/
2525
import { ShaderChunk } from 'three';
2626

27+
// language=GLSL
2728
export const HIRES_VERTEX_SHADER = `
2829
#include <common>
2930
${ShaderChunk.logdepthbuf_pars_vertex}
3031
32+
const vec2 lightDirection = normalize(vec2(1.0, 0.5));
33+
34+
uniform float distance;
35+
3136
attribute float ao;
3237
attribute float sunlight;
3338
attribute float blocklight;
@@ -52,6 +57,13 @@ void main() {
5257
vSunlight = sunlight;
5358
vBlocklight = blocklight;
5459
60+
// apply directional lighting
61+
if (vNormal.x * vNormal.z == 0.0) {
62+
float distFac = smoothstep(1000.0, 50.0, distance);
63+
vAo *= 1.0 - abs(dot(vNormal.xz, lightDirection)) * 0.4 * distFac;
64+
vAo *= 1.0 - max(0.0, -vNormal.y) * 0.6 * distFac;
65+
}
66+
5567
gl_Position = projectionMatrix * (viewMatrix * modelMatrix * vec4(position, 1));
5668
5769
${ShaderChunk.logdepthbuf_vertex}

0 commit comments

Comments
 (0)