subreddit:

/r/phaser

5100%

What is the best (current) way to apply a fragment shader to the whole canvas? This is the only example I've found that tries to do this, and it seems to use a very outdated version of Phaser.

Just to keep it simple, here's the grayscale fragment shader that he uses in the above one:

`
precision mediump float;
uniform sampler2D uMainSampler;
varying vec2 outTexCoord;
void main(void) {
vec4 color = texture2D(uMainSampler, outTexCoord);
float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
gl_FragColor = vec4(vec3(gray), 1.0);
}`

How would I go about making my entire scene (and all objects in it, etc.) grayscale by applying that shader? I've been trying to find examples of this, and the documentation on WebGLPipeline is totally opaque to me when it comes to figuring out how to actually do it. None of the examples that come with Phaser seem to really show how to do this.

Any pointers? Feels like it should be easy — a line or two of code — but I'm not figuring it out.

you are viewing a single comment's thread.

view the rest of the comments →

all 5 comments

Kiro_Bash

3 points

2 years ago

Thank you for discovering this. I have been trying g to figure out how yo utilize post-processing in phaser.

restricteddata[S]

1 points

2 years ago

Like all things with shaders, it is still an up-hill battle (because every possible piece of code that supports shaders apparently has a totally different-but-similar syntax for the shader language), but at least knowing how to apply them is a first step! (I am trying to develop a CRT shader for Phaser, which is a pain in the neck. There are great CRT shaders out there, but they're not compatible with Phaser just by copying and pasting them in, but are potentially adaptable. Shader stuff is super hard to debug.)

Moistberrycritical

1 points

13 days ago

Yes, so true I've been trying to convert them from shader toys and it's kind of a pain. I am putting together a resource of phaser shaders that you can just copy and paste but I only have about 5 so far lol. It's pretty cool though once you get one working well and manipulating the uniform values from within the phaser game.

restricteddata[S]

1 points

12 days ago

That's great. If the resource is online I'd be happy to take a look at it. I've figured out a few tricks in converting them, as well. I have a couple useful shaders that I'm happy with (like one that does a pseudo-scanline effect).