Skip to content

Commit

Permalink
fixes shadow acne issue caused by the lack of normalBias adjustments …
Browse files Browse the repository at this point in the history
…on the scene
  • Loading branch information
TheCodeTherapy committed Aug 14, 2023
1 parent 904dcf0 commit 398ff4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions example/web-client/src/Sun.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { DirectionalLight, Group, OrthographicCamera, Vector3 } from "three";
import { CameraHelper, DirectionalLight, Group, OrthographicCamera, Vector3 } from "three";

export class Sun extends Group {
private readonly debug: boolean = false;
private readonly sunOffset: Vector3 = new Vector3(50, 80, 35);
private readonly shadowResolution: number = 16384;
private readonly shadowCamFrustum: number = 150;
private readonly shadowResolution: number = 8192;
private readonly shadowCamFrustum: number = 50;
private readonly camHelper: CameraHelper | null = null;

private readonly shadowCamera: OrthographicCamera;
private readonly directionalLight: DirectionalLight;
Expand All @@ -17,17 +19,25 @@ export class Sun extends Group {
this.shadowCamFrustum,
this.shadowCamFrustum,
-this.shadowCamFrustum,
0.5,
500,
0.1,
200,
);
this.directionalLight = new DirectionalLight(0xffffff, 0.8);
if (this.debug === true) {
this.camHelper = new CameraHelper(this.shadowCamera);
}
this.directionalLight = new DirectionalLight(0xffffff, 0.5);
this.directionalLight.shadow.normalBias = 0.05;
this.directionalLight.shadow.radius = 1.5;
this.directionalLight.shadow.camera = this.shadowCamera;
this.directionalLight.shadow.mapSize.set(this.shadowResolution, this.shadowResolution);
this.directionalLight.castShadow = true;

this.updateCharacterPosition(new Vector3(0, 0, 0));

this.add(this.directionalLight);
if (this.debug === true && this.camHelper instanceof CameraHelper) {
this.add(this.camHelper);
}
}

public updateCharacterPosition(position: Vector3 | undefined) {
Expand Down
2 changes: 1 addition & 1 deletion example/web-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class App {

constructor() {
this.scene = new Scene();
this.scene.fog = new Fog(0xc7cad0, 30, 150);
this.scene.fog = new Fog(0xc7cad0, 30, 210);
this.collisionsManager = new CollisionsManager(this.scene);

this.audioListener = new AudioListener();
Expand Down

0 comments on commit 398ff4e

Please sign in to comment.