Skip to content

Commit

Permalink
feat(CSM) : add feature of Cascaded Shadow Map (Orillusion#286)
Browse files Browse the repository at this point in the history
Add feature of Cascaded Shadow Map
Rename boudingBox to boundingBox
  • Loading branch information
hellmor authored Aug 16, 2023
1 parent 63f6cb6 commit d798bd2
Show file tree
Hide file tree
Showing 81 changed files with 911 additions and 490 deletions.
2 changes: 1 addition & 1 deletion public
13 changes: 6 additions & 7 deletions samples/animation/Sample_CurveAnimation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Object3D, Scene3D, AnimationCurve, Engine3D, AtmosphericComponent, CameraUtil, HoverCameraController, View3D, DirectLight, KelvinUtil, Keyframe, Object3DUtil, Time } from "@orillusion/core";
import { GUIHelp } from "@orillusion/debug/GUIHelp";

class Sample_AnimCurve {
lightObj3D: Object3D;
Expand All @@ -12,22 +13,20 @@ class Sample_AnimCurve {
async run() {
await Engine3D.init({ beforeRender: () => this.renderUpdate() });

Engine3D.setting.shadow.shadowBound = 100;
Engine3D.setting.shadow.shadowBias = 0.0001;
Engine3D.setting.shadow.pointShadowBias = 0.6;
Engine3D.setting.shadow.debug = true;

Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.updateFrameRate = 1;
Engine3D.setting.shadow.type = `HARD`;
Engine3D.setting.shadow.csmScatteringExp = 0.5;
GUIHelp.init();

this.scene = new Scene3D();
let sky = this.scene.addComponent(AtmosphericComponent);

let camera = CameraUtil.createCamera3DObject(this.scene);
camera.enableCSM = true;
camera.perspective(60, Engine3D.aspect, 0.01, 5000.0);

camera.object3D.addComponent(HoverCameraController).setCamera(-30, -25, 400);
camera.object3D.addComponent(HoverCameraController).setCamera(-30, -45, 200);

let view = new View3D();
view.scene = this.scene;
Expand All @@ -43,7 +42,7 @@ class Sample_AnimCurve {
/******** light *******/
{
this.lightObj3D = new Object3D();
this.lightObj3D.rotationX = 15;
this.lightObj3D.rotationX = 35;
this.lightObj3D.rotationY = 110;
this.lightObj3D.rotationZ = 0;
let directLight = this.lightObj3D.addComponent(DirectLight);
Expand Down
2 changes: 1 addition & 1 deletion samples/animation/Sample_MorphTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Sample_MorphTarget {
influenceData: { [key: string]: number } = {};

async run() {
Engine3D.setting.shadow.shadowBias = 0.0001;
Engine3D.setting.shadow.shadowBound = 100;

await Engine3D.init();

Expand Down
3 changes: 2 additions & 1 deletion samples/animation/Sample_PropertyAnimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Sample_PropertyAnimation {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.updateFrameRate = 1;
Engine3D.setting.shadow.shadowBound = 20;
Engine3D.setting.shadow.shadowBias = 0.0001;
Engine3D.setting.shadow.shadowSize = 2048;

await Engine3D.init();
let param = createSceneParam();
Expand All @@ -22,6 +22,7 @@ class Sample_PropertyAnimation {
GUIUtil.renderDirLight(exampleScene.light, false);

this.scene = exampleScene.scene;
exampleScene.camera.enableCSM = true;
await this.initScene(this.scene);

Engine3D.startRenderView(exampleScene.view);
Expand Down
1 change: 0 additions & 1 deletion samples/animation/Sample_Skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Sample_Skeleton {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.updateFrameRate = 1;
Engine3D.setting.shadow.shadowBound = 100;
Engine3D.setting.shadow.shadowBias = 0.0001;

await Engine3D.init();

Expand Down
4 changes: 2 additions & 2 deletions samples/animation/Sample_Skeleton2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class Sample_Skeleton2 {

Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.updateFrameRate = 1;
Engine3D.setting.shadow.shadowBound = 500;
Engine3D.setting.shadow.shadowBias = 0.0002;
Engine3D.setting.shadow.shadowSize = 2048;

await Engine3D.init();

Expand All @@ -20,6 +19,7 @@ class Sample_Skeleton2 {
this.scene.exposure = 1;

let mainCamera = CameraUtil.createCamera3DObject(this.scene);
mainCamera.enableCSM = true;
mainCamera.perspective(60, webGPUContext.aspect, 1, 3000.0);

let hoverCameraController = mainCamera.object3D.addComponent(HoverCameraController);
Expand Down
1 change: 0 additions & 1 deletion samples/animation/Sample_Skeleton3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class Sample_Skeleton3 {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.updateFrameRate = 1;
Engine3D.setting.shadow.shadowBound = 100;
Engine3D.setting.shadow.shadowBias = 0.0002;
await Engine3D.init({
renderLoop: () => this.onRenderLoop(),
});
Expand Down
3 changes: 1 addition & 2 deletions samples/ext/Sample_Grass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Sample_Grass {
async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.updateFrameRate = 1;
Engine3D.setting.shadow.shadowBias = 0.0003;
Engine3D.setting.shadow.shadowBound = 500;
Engine3D.setting.shadow.shadowSize = 1024;
// Engine3D.setting.render.zPrePass = true;
Expand All @@ -23,6 +22,7 @@ class Sample_Grass {
this.view.scene.addComponent(AtmosphericComponent);

this.view.camera = CameraUtil.createCamera3DObject(this.view.scene);
this.view.camera.enableCSM = true;
this.view.camera.perspective(60, webGPUContext.aspect, 1, 5000.0);
this.view.camera.object3D.z = -15;
this.view.camera.object3D.addComponent(HoverCameraController).setCamera(35, -20, 500);
Expand Down Expand Up @@ -165,7 +165,6 @@ class Sample_Grass {

GUIHelp.addFolder("shadow");
GUIHelp.add(Engine3D.setting.shadow, "shadowBound", 0.0, 3000, 0.0001);
GUIHelp.add(Engine3D.setting.shadow, "shadowBias", 0.0, 1, 0.0001);
GUIHelp.endFolder();

let globalFog = this.post.getPost(GlobalFog);
Expand Down
4 changes: 1 addition & 3 deletions samples/ext/Sample_Terrain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ class Sample_Terrain {
async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.updateFrameRate = 1;
Engine3D.setting.shadow.shadowBias = 0.0003;
Engine3D.setting.shadow.shadowBound = 500;
Engine3D.setting.shadow.shadowSize = 1024;
Engine3D.setting.shadow.shadowSize = 2048;
// Engine3D.setting.render.zPrePass = true;

GUIHelp.init();
Expand Down Expand Up @@ -81,7 +80,6 @@ class Sample_Terrain {

GUIHelp.addFolder("shadow");
GUIHelp.add(Engine3D.setting.shadow, "shadowBound", 0.0, 3000, 0.0001);
GUIHelp.add(Engine3D.setting.shadow, "shadowBias", 0.0, 1, 0.0001);
GUIHelp.endFolder();

let globalFog = this.post.getPost(GlobalFog);
Expand Down
5 changes: 3 additions & 2 deletions samples/geometry/Sample_ConduitGeometry2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ class Sample_ConduitGeometry2 {
async run() {
GUIHelp.init();
Engine3D.setting.shadow.shadowBound = 50;
Engine3D.setting.shadow.shadowBias = 0.0001;
Engine3D.setting.shadow.shadowSize = 1024;
let param = createSceneParam();
param.camera.distance = 50;
param.camera.distance = 60;
await Engine3D.init();
let exampleScene = createExampleScene(param);
exampleScene.camera.enableCSM = true;
this.scene = exampleScene.scene;
Engine3D.startRenderView(exampleScene.view);
await this.createMaterial();
Expand Down
1 change: 0 additions & 1 deletion samples/geometry/Sample_ConduitGeometry3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class Sample_ConduitGeometry3 {
async run() {
GUIHelp.init();
Engine3D.setting.shadow.shadowBound = 50;
Engine3D.setting.shadow.shadowBias = 0.0001;
let param = createSceneParam();
param.camera.distance = 50;
await Engine3D.init();
Expand Down
1 change: 0 additions & 1 deletion samples/geometry/Sample_CustomGeometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Sample_CustomGeometry {
dirLight: DirectLight;
async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIHelp.init();

Expand Down
1 change: 0 additions & 1 deletion samples/geometry/Sample_InternalGeometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Sample_InternalGeometry {
lightObj: Object3D;
async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;
Engine3D.setting.shadow.shadowBound = 200;
GUIHelp.init();

Expand Down
2 changes: 1 addition & 1 deletion samples/gi/Sample_GI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class Sample_GI {
Engine3D.setting.gi.autoRenderProbe = true;

Engine3D.setting.shadow.shadowBound = 200;
Engine3D.setting.shadow.shadowBias = 0.001;
Engine3D.setting.shadow.debug = true;

Engine3D.setting.shadow.autoUpdate = true;
Expand Down Expand Up @@ -58,6 +57,7 @@ class Sample_GI {
let exampleScene = createExampleScene(param);
exampleScene.atmosphericSky.exposure = 0.5;
this.scene = exampleScene.scene;
exampleScene.camera.enableCSM = true;
Engine3D.startRenderViews([exampleScene.view]);
let job = Engine3D.getRenderJob(exampleScene.view);
await this.initScene();
Expand Down
9 changes: 5 additions & 4 deletions samples/gi/Sample_GICornellBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class Sample_GICornellBox {
Engine3D.setting.gi.depthSharpness = 1;
Engine3D.setting.gi.autoRenderProbe = true;

Engine3D.setting.shadow.shadowBound = 80;
Engine3D.setting.shadow.shadowBias = 0.000035;
Engine3D.setting.shadow.debug = true;

Engine3D.setting.shadow.shadowSize = 1024;
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.updateFrameRate = 1;

Expand All @@ -57,10 +55,11 @@ class Sample_GICornellBox {
}
});
let param = createSceneParam();
param.camera.distance = 40;
param.camera.distance = 100;

let exampleScene = createExampleScene(param);
exampleScene.hoverCtrl.setCamera(0, 0, 20);
exampleScene.camera.enableCSM = true;
this.scene = exampleScene.scene;
this.addGIProbes();
Engine3D.startRenderViews([exampleScene.view]);
Expand All @@ -69,6 +68,8 @@ class Sample_GICornellBox {
postProcessing.addPost(GTAOPost);
postProcessing.addPost(HDRBloomPost);

Engine3D.setting.shadow.csmScatteringExp = 0.8;
GUIHelp.add(Engine3D.setting.shadow, 'csmScatteringExp', 0.5, 1, 0.001);
await this.initScene();
}

Expand Down
3 changes: 2 additions & 1 deletion samples/gui/Sample_POI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Sample_POI {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.updateFrameRate = 1;
Engine3D.setting.shadow.shadowBound = 20;
Engine3D.setting.shadow.shadowBias = 0.0001;
Engine3D.setting.shadow.csmScatteringExp = 1;

await Engine3D.init({ renderLoop: () => { this.loop(); } });
let param = createSceneParam();
Expand All @@ -22,6 +22,7 @@ class Sample_POI {
GUIHelp.init();

this.scene = exampleScene.scene;
exampleScene.camera.enableCSM = true;

Engine3D.startRenderView(exampleScene.view);

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UIButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export class Sample_UIButton {
async run() {

Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIHelp.init();

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UIChangeParent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Engine3D, Object3DUtil, Object3D, ViewPanel, UIImage, ImageType, UIPane
export class Sample_UIChangeParent {
async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIHelp.init();

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UIImageColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export class Sample_UIImageColor {

async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIHelp.init();

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UIImageGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export class Sample_UIImageGroup {

async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIHelp.init();

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UIImageShadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class Sample_UIImageShadow {

async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIHelp.init();

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UIMultiCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Engine3D, Object3DUtil, Object3D, UIImage, ImageType, Color, UIPanel, V
class Sample_UIMultiCanvas {
async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

await Engine3D.init();
await Engine3D.res.loadFont('fnt/0.fnt');
Expand Down
2 changes: 0 additions & 2 deletions samples/gui/Sample_UIMultiPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export class Sample_UIMultiPanel {

async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;
Engine3D.setting.shadow.shadowBound = 100;

GUIHelp.init();

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UIPanelOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export class Sample_UIPanelOrder {

async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIHelp.init();

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UIPanelScissor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class Sample_UIPanelScissor {

async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIHelp.init();

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UIPerformance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export class Sample_UISpriteSheet {

async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIConfig.quadMaxCountForView = 5001;

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UIPerformance2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export class Sample_UIPerformance2 {

async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIConfig.quadMaxCountForView = 5001;

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UISingleImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { GUIUtil } from "@samples/utils/GUIUtil";
export class Sample_UISingleImage {
async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIHelp.init();

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UISpriteSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export class Sample_UISpriteSheet {

async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIHelp.init();

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UITextField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class Sample_UITextField {

async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIHelp.init();

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UIVideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class Sample_UIVideo {

async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIHelp.init();

Expand Down
1 change: 0 additions & 1 deletion samples/gui/Sample_UIVisible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export class Sample_UIVisible {
spriteCount = 10;
async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.002;

GUIHelp.init();

Expand Down
Loading

0 comments on commit d798bd2

Please sign in to comment.