@@ -2,6 +2,16 @@ import React from 'react';
2
2
import * as pc from 'playcanvas/build/playcanvas.js' ;
3
3
import { AssetLoader } from '../../app/helpers/loader' ;
4
4
import Example from '../../app/example' ;
5
+ // @ts -ignore: library file import
6
+ import Panel from '@playcanvas/pcui/Panel/component' ;
7
+ // @ts -ignore: library file import
8
+ import SliderInput from '@playcanvas/pcui/SliderInput/component' ;
9
+ // @ts -ignore: library file import
10
+ import LabelGroup from '@playcanvas/pcui/LabelGroup/component' ;
11
+ // @ts -ignore: library file import
12
+ import BindingTwoWay from '@playcanvas/pcui/BindingTwoWay' ;
13
+ // @ts -ignore: library file import
14
+ import { Observer } from '@playcanvas/observer' ;
5
15
6
16
class ShadowCascadesExample extends Example {
7
17
static CATEGORY = 'Graphics' ;
@@ -14,12 +24,36 @@ class ShadowCascadesExample extends Example {
14
24
}
15
25
16
26
// @ts -ignore: override class function
17
- example ( canvas : HTMLCanvasElement ) : void {
27
+ controls ( data : Observer ) {
28
+ return < >
29
+ < Panel headerText = 'Shadow Cascade Settings' >
30
+ < LabelGroup text = 'Count' >
31
+ < SliderInput binding = { new BindingTwoWay ( ) } link = { { observer : data , path : 'settings.light.numCascades' } } min = { 1 } max = { 4 } precision = { 0 } />
32
+ </ LabelGroup >
33
+ < LabelGroup text = 'Resolution' >
34
+ < SliderInput binding = { new BindingTwoWay ( ) } link = { { observer : data , path : 'settings.light.shadowResolution' } } min = { 128 } max = { 2048 } precision = { 0 } />
35
+ </ LabelGroup >
36
+ < LabelGroup text = 'Distribution' >
37
+ < SliderInput binding = { new BindingTwoWay ( ) } link = { { observer : data , path : 'settings.light.cascadeDistribution' } } min = { 0 } max = { 1 } precision = { 2 } />
38
+ </ LabelGroup >
39
+ </ Panel >
40
+ </ > ;
41
+ }
18
42
19
- const app = new pc . Application ( canvas , { } ) ;
43
+ // @ts -ignore: override class function
44
+ example ( canvas : HTMLCanvasElement , assets : any , data :any ) : void {
20
45
46
+ const app = new pc . Application ( canvas , { } ) ;
21
47
app . start ( ) ;
22
48
49
+ data . set ( 'settings' , {
50
+ light : {
51
+ numCascades : 4 , // number of cascades
52
+ shadowResolution : 2048 , // shadow map resolution storing 4 cascades
53
+ cascadeDistribution : 0.7 // distribution of cascade distances to prefer sharpness closer to the camera
54
+ }
55
+ } ) ;
56
+
23
57
// Set the canvas to fill the window and automatically change resolution to be the same as the canvas size
24
58
app . setCanvasFillMode ( pc . FILLMODE_FILL_WINDOW ) ;
25
59
app . setCanvasResolution ( pc . RESOLUTION_AUTO ) ;
@@ -88,28 +122,31 @@ class ShadowCascadesExample extends Example {
88
122
// Create a directional light casting cascaded shadows
89
123
const dirLight = new pc . Entity ( ) ;
90
124
dirLight . addComponent ( "light" , {
91
- type : "directional" ,
92
- color : pc . Color . WHITE ,
93
- shadowBias : 0.3 ,
94
- normalOffsetBias : 0.2 ,
95
- intensity : 1.0 ,
96
-
97
- // enable shadow casting
98
- castShadows : true ,
99
- shadowDistance : 1000 ,
100
-
101
- // shadow map resolution storing 4 cascades
102
- shadowResolution : 2048 ,
103
- numCascades : 4 ,
104
-
105
- // distribution of cascade distances to prefer sharpness closer to the camera
106
- cascadeDistribution : 0.7 ,
107
-
108
- // shadow filtering
109
- shadowType : pc . SHADOW_PCF3
125
+ ...{
126
+ type : "directional" ,
127
+ color : pc . Color . WHITE ,
128
+ shadowBias : 0.3 ,
129
+ normalOffsetBias : 0.2 ,
130
+ intensity : 1.0 ,
131
+
132
+ // enable shadow casting
133
+ castShadows : true ,
134
+ shadowDistance : 1000 ,
135
+
136
+ // shadow filtering
137
+ shadowType : pc . SHADOW_PCF3
138
+ } ,
139
+ ...data . get ( 'settings.light' )
110
140
} ) ;
111
141
app . root . addChild ( dirLight ) ;
112
142
dirLight . setLocalEulerAngles ( 45 , - 20 , 20 ) ;
143
+
144
+ // handle HUD changes - update properties on the light
145
+ data . on ( '*:set' , ( path : string , value : any ) => {
146
+ const pathArray = path . split ( '.' ) ;
147
+ // @ts -ignore
148
+ dirLight . light [ pathArray [ 2 ] ] = value ;
149
+ } ) ;
113
150
}
114
151
}
115
152
0 commit comments