Skip to content

Commit a3b67c4

Browse files
committed
Create set shader uniform.js
1 parent e187347 commit a3b67c4

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
class Example extends Phaser.Scene
2+
{
3+
constructor ()
4+
{
5+
super();
6+
}
7+
8+
preload ()
9+
{
10+
this.load.image('checker', 'assets/pics/bw-face.png');
11+
}
12+
13+
create ()
14+
{
15+
const frag = `
16+
precision mediump float;
17+
18+
uniform float time;
19+
uniform vec2 resolution;
20+
uniform sampler2D iChannel0;
21+
uniform float pixelSize;
22+
23+
varying vec2 fragCoord;
24+
25+
vec4 texture(sampler2D s, vec2 c) { return texture2D(s,c); }
26+
27+
void mainImage (out vec4 fragColor, in vec2 fragCoord)
28+
{
29+
vec2 uv = fragCoord / resolution.xy;
30+
31+
uv = floor(uv * resolution.x * pixelSize) / (resolution.x * pixelSize);
32+
33+
fragColor = texture(iChannel0, uv);
34+
}
35+
36+
void main (void)
37+
{
38+
mainImage(gl_FragColor, fragCoord.xy);
39+
}
40+
`;
41+
42+
const base = new Phaser.Display.BaseShader(
43+
'simpleTexture',
44+
frag,
45+
null,
46+
{
47+
pixelSize: { type: '1f', value: 0.2 }
48+
}
49+
);
50+
51+
const shader = this.add.shader(base, 400, 300, 800, 600, [ 'checker' ]);
52+
53+
shader.setUniform('pixelSize.value', 0.2);
54+
55+
console.log(shader);
56+
}
57+
}
58+
59+
const game = new Phaser.Game({
60+
type: Phaser.WEBGL,
61+
parent: 'phaser-example',
62+
width: 800,
63+
height: 600,
64+
scene: Example
65+
});

0 commit comments

Comments
 (0)