I’m experimenting with PostProcesses, and I wanted to apply a vertex shader to a custom PostProcess, but when I try to add it to the PostProcess instance, everything disappears.
tl;dr: Post-processing should probably only use pixel shaders.
I don’t think you can apply a vertex shader to the post-process – or, rather, I don’t think you’re supposed to. According to the docs, the post-process constructor specifically requests fragmentUrl, indicating it wants a fragment (or pixel) shader. The reason for this is that post-processing manipulates the pixels that have already been rendered to the screen. Vertex shaders manipulate vertices; so in the case of post-processes, where we’ve already rendered everything to the screen and everything’s already where it should be, we actually don’t want a vertex shader to do anything at all.
Since the screen (at the point of post-processing) is effectively a quad right in front of a camera, and because vertex shaders move vertices, if you did manage to put a vertex shader on the post-process, it would probably actually move the screen away from the camera – causing everything to disappear. Note that I don’t think this is how it currently works: I get shader compilation errors (see below) when trying to run the case in your Playground, presumably because the constructor is specifically looking for a fragment shader, as mentioned above. Nevertheless, it is an interesting thought experiment. Hope this helps!
@syntheticmagus it wasn’t working because I haven’t declared the vUV uniform in the vertex shader; it now compiles without errors (but still don’t see anything).
But the PostProcess class accepts vertexUrl as its 11th parameter; I’m wondering what’s its purpose
You need a CustomShader Material
@Pryme8 I have to apply the shader to the whole scene, I don’t think I can use a ShaderMaterial in this case (unless there’s something I don’t know, which is probable).
When you say whole scene, do you mean every object or the screen space?
What are you trying to do? I mean technically if you don’t change anything with a bjs scenes materials then the whole scene is just the standard shader if that helps clear things up.
If you are looking to deform meshes on the fly you will need to assign the mesh a custom shader which will handle that stuff.
Things that are like filters that are applied to the whole screen are post effects
In my head I thought that I could treat the scene as a plane which I could modify its vertices with a vertex shader (since it has that vertexUrl), that’s why I said “the whole scene”.
I was trying to apply a vertex shader with a fisheye effect (instead of a fragment shader), it seemed the simplest way to do that.