forked from 4ian/GDevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
light-night-pixi-filter.ts
85 lines (85 loc) · 2.5 KB
/
light-night-pixi-filter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
namespace gdjs {
export interface LightNightFilterExtra {
o: number;
}
export class LightNightPixiFilter extends PIXI.Filter {
constructor() {
const vertexShader = undefined;
const fragmentShader = [
'precision mediump float;',
'',
'varying vec2 vTextureCoord;',
'uniform sampler2D uSampler;',
'uniform float opacity;',
'',
'void main(void)',
'{',
' mat3 nightMatrix = mat3(0.6, 0, 0, 0, 0.7, 0, 0, 0, 1.3);',
' gl_FragColor = texture2D(uSampler, vTextureCoord);',
' gl_FragColor.rgb = mix(gl_FragColor.rgb, nightMatrix * gl_FragColor.rgb, opacity);',
'}',
].join('\n');
const uniforms = { opacity: { type: '1f', value: 1 } };
super(vertexShader, fragmentShader, uniforms);
}
}
LightNightPixiFilter.prototype.constructor = gdjs.LightNightPixiFilter;
gdjs.PixiFiltersTools.registerFilterCreator(
'LightNight',
new (class extends gdjs.PixiFiltersTools.PixiFilterCreator {
makePIXIFilter(target: EffectsTarget, effectData) {
const filter = new gdjs.LightNightPixiFilter();
return filter;
}
updatePreRender(filter: PIXI.Filter, target: EffectsTarget) {}
updateDoubleParameter(
filter: PIXI.Filter,
parameterName: string,
value: number
) {
if (parameterName === 'opacity') {
filter.uniforms.opacity = gdjs.PixiFiltersTools.clampValue(
value,
0,
1
);
}
}
getDoubleParameter(filter: PIXI.Filter, parameterName: string): number {
if (parameterName === 'opacity') {
return filter.uniforms.opacity;
}
return 0;
}
updateStringParameter(
filter: PIXI.Filter,
parameterName: string,
value: string
) {}
updateColorParameter(
filter: PIXI.Filter,
parameterName: string,
value: number
): void {}
getColorParameter(filter: PIXI.Filter, parameterName: string): number {
return 0;
}
updateBooleanParameter(
filter: PIXI.Filter,
parameterName: string,
value: boolean
) {}
getNetworkSyncData(filter: PIXI.Filter): LightNightFilterExtra {
return {
o: filter.uniforms.opacity,
};
}
updateFromNetworkSyncData(
filter: PIXI.Filter,
data: LightNightFilterExtra
) {
filter.uniforms.opacity = data.o;
}
})()
);
}