I am trying to add a postProcess step to a shader to pass uniforms such as iTime
to the fragment shader. The shader works fine until I add the following call to PostProcess
:
const postEffect = new BABYLON.PostProcess("post process for customEffect",
"customEffect",
["iTime", "iResolution"],
[], 1, camera);
At which point it errors with Varying `v_uv` has static-use in the frag shader, but is undeclared in the vert shader
. The vertexShader code is:
attribute vec2 uv;
attribute vec3 position;
uniform mat4 worldViewProjection;
varying vec2 v_uv;
void main() {
v_uv = uv;
gl_Position = worldViewProjection * vec4(position, 1.0);
}
And the fragmentShader code is:
precision highp float;
uniform float iTime;
uniform vec2 iResolution;
varying vec2 v_uv;
void main(void) {
gl_FragColor = vec4(v_uv, 0.0, 1.0);
}
Playground: https://playground.babylonjs.com/#VG25E8#11 (set conditional on line 33 to true
to trigger error and check logs to see error)
Alternatively I can add the postProcess step if I replace the reference to v_uv with literal floats e.g. gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
I tried searching the playgrounds for a similar error but I think I 500’d the snippets server
I also tried looking at page in the docs on Putting Shader Code Into Babylon.js and on Custom postprocesses | Use Post Processes for a solution or working example but couldn’t see one?
Thanks!
* edit * fixed playground, had old shader cache locally but wasn’t correct name in playground.