1
- import { Filter , GlProgram , GpuProgram , PointData } from 'pixi.js' ;
1
+ import { Filter , GlProgram , GpuProgram , PointData , Texture , ViewSystem } from 'pixi.js' ;
2
2
import { vertex , wgslVertex } from '../defaults' ;
3
3
import fragment from './tilt-shift.frag' ;
4
4
import source from './tilt-shift.wgsl' ;
@@ -39,25 +39,30 @@ export class TiltShiftAxisFilter extends Filter
39
39
blur : 100 ,
40
40
/** The strength of the blur gradient */
41
41
gradientBlur : 600 ,
42
- /** The position to start the effect at. */
43
- start : { x : 0 , y : window . innerHeight / 2 } ,
44
- /** The position to end the effect at. */
45
- end : { x : 600 , y : window . innerHeight / 2 } ,
46
42
} ;
47
43
48
44
public uniforms : {
49
45
uBlur : Float32Array ;
50
46
uStart : PointData
51
47
uEnd : PointData ;
52
48
uDelta : Float32Array ;
53
- uTexSize : Float32Array ;
49
+ uDimensions : Float32Array ;
54
50
} ;
55
51
56
52
private _tiltAxis : TiltShiftAxisFilterOptions [ 'axis' ] ;
57
53
58
54
constructor ( options ?: TiltShiftAxisFilterOptions )
59
55
{
60
- options = { ...TiltShiftAxisFilter . DEFAULT_OPTIONS , ...options } as TiltShiftAxisFilterOptions ;
56
+ const { width, height } = ViewSystem . defaultOptions as { width : number , height : number } ;
57
+
58
+ options = {
59
+ ...TiltShiftAxisFilter . DEFAULT_OPTIONS ,
60
+ /** The position to start the effect at. */
61
+ start : { x : 0 , y : height / 2 } ,
62
+ /** The position to end the effect at. */
63
+ end : { x : width , y : height / 2 } ,
64
+ ...options ,
65
+ } as TiltShiftAxisFilterOptions ;
61
66
62
67
const gpuProgram = GpuProgram . from ( {
63
68
vertex : {
@@ -83,25 +88,39 @@ export class TiltShiftAxisFilter extends Filter
83
88
tiltShiftUniforms : {
84
89
uBlur : {
85
90
value : new Float32Array ( [
86
- options . blur ?? 100 ,
87
- options . gradientBlur ?? 600
91
+ options . blur as number ,
92
+ options . gradientBlur as number ,
88
93
] ) , type : 'vec2<f32>'
89
94
} ,
90
95
uStart : { value : options . start , type : 'vec2<f32>' } ,
91
96
uEnd : { value : options . end , type : 'vec2<f32>' } ,
92
- uDelta : { value : new Float32Array ( [ 30 , 30 ] ) , type : 'vec2<f32>' } ,
93
- uTexSize : { value : new Float32Array ( [ window . innerWidth , window . innerHeight ] ) , type : 'vec2<f32>' } ,
97
+ uDelta : { value : new Float32Array ( [ 0 , 0 ] ) , type : 'vec2<f32>' } ,
98
+ uDimensions : { value : new Float32Array ( [ width , height ] ) , type : 'vec2<f32>' } ,
94
99
} ,
95
100
} ,
96
101
} ) ;
97
102
98
103
this . uniforms = this . resources . tiltShiftUniforms . uniforms ;
99
104
this . _tiltAxis = options . axis ;
100
- this . updateDelta ( ) ;
101
105
}
102
106
103
- /** Updates the filter delta values. */
104
- protected updateDelta ( ) : void
107
+ /**
108
+ * Update the dimensions
109
+ * @ignore
110
+ */
111
+ public updateDimensions ( input : Texture ) : void
112
+ {
113
+ const { uDimensions } = this . uniforms ;
114
+
115
+ uDimensions [ 0 ] = input . frame . width ;
116
+ uDimensions [ 1 ] = input . frame . height ;
117
+ }
118
+
119
+ /**
120
+ * Updates the filter delta values.
121
+ * @ignore
122
+ */
123
+ public updateDelta ( ) : void
105
124
{
106
125
this . uniforms . uDelta [ 0 ] = 0 ;
107
126
this . uniforms . uDelta [ 1 ] = 0 ;
@@ -120,60 +139,4 @@ export class TiltShiftAxisFilter extends Filter
120
139
this . uniforms . uDelta [ 0 ] = ! isVert ? dx / d : - dy / d ;
121
140
this . uniforms . uDelta [ 1 ] = ! isVert ? dy / d : dx / d ;
122
141
}
123
-
124
- // /** The strength of the blur. */
125
- // get blur(): number { return this.uniforms.uBlur[0]; }
126
- // set blur(value: number) { this.uniforms.uBlur[0] = value; }
127
-
128
- // /** The strength of the gradient blur. */
129
- // get gradientBlur(): number { return this.uniforms.uBlur[1]; }
130
- // set gradientBlur(value: number) { this.uniforms.uBlur[1] = value; }
131
-
132
- // /** The start position of the effect. */
133
- // get start(): PointData { return this.uniforms.uStart; }
134
- // set start(value: PointData)
135
- // {
136
- // this.uniforms.uStart = value;
137
- // this.updateDelta();
138
- // }
139
-
140
- // /** The start position of the effect on the `x` axis. */
141
- // get startX(): number { return this.start.x; }
142
- // set startX(value: number)
143
- // {
144
- // this.start.x = value;
145
- // this.updateDelta();
146
- // }
147
-
148
- // /** The start position of the effect on the `y` axis. */
149
- // get startY(): number { return this.startY; }
150
- // set startY(value: number)
151
- // {
152
- // this.start.y = value;
153
- // this.updateDelta();
154
- // }
155
-
156
- // /** The end position of the effect. */
157
- // get end(): PointData { return this.uniforms.uEnd; }
158
- // set end(value: PointData)
159
- // {
160
- // this.uniforms.uEnd = value;
161
- // this.updateDelta();
162
- // }
163
-
164
- // /** The end position of the effect on the `x` axis. */
165
- // get endX(): number { return this.end.x; }
166
- // set endX(value: number)
167
- // {
168
- // this.end.x = value;
169
- // this.updateDelta();
170
- // }
171
-
172
- // /** The end position of the effect on the `y` axis. */
173
- // get endY(): number { return this.end.y; }
174
- // set endY(value: number)
175
- // {
176
- // this.end.y = value;
177
- // this.updateDelta();
178
- // }
179
142
}
0 commit comments