# Varying \`v\_uv\` has static-use in the frag shader, but is undeclared in the vert shader

**URL:** <https://forum.babylonjs.com/t/varying-v-uv-has-static-use-in-the-frag-shader-but-is-undeclared-in-the-vert-shader/37244>\
**Category:** Questions\
**Tags:** shader, postprocessing\
**Created:** [January 10, 2023, 5:42pm UTC](https://forum.babylonjs.com/t/varying-v-uv-has-static-use-in-the-frag-shader-but-is-undeclared-in-the-vert-shader/37244 "2023-01-10T17:42:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajp](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ajp/32/9504_2.png) [@ajp](https://forum.babylonjs.com/u/ajp)\
**Post date:** [January 10, 2023, 5:42pm UTC](https://forum.babylonjs.com/t/varying-v-uv-has-static-use-in-the-frag-shader-but-is-undeclared-in-the-vert-shader/37244/1 "2023-01-10T17:42:17Z")

</div>

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`:

```typescript
        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:

```plaintext
    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:

```plaintext
    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](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](https://doc.babylonjs.com/playground?q=Varying%20has%20static-use%20in%20the%20frag%20shader,%20but%20is%20undeclared%20in%20the%20vert%20shader&type=name) 😬

I also tried looking at page in the docs on [Putting Shader Code Into Babylon.js](https://doc.babylonjs.com/features/featuresDeepDive/materials/shaders/shaderCodeInBjs) and on [Custom postprocesses | Use Post Processes](https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/usePostProcesses) 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.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [January 11, 2023, 10:29am UTC](https://forum.babylonjs.com/t/varying-v-uv-has-static-use-in-the-frag-shader-but-is-undeclared-in-the-vert-shader/37244/2 "2023-01-11T10:29:22Z")

</div>

The post process class is using a default vertex fragment which is using a uv variable named `vUV`, not `v_uv`. So you must use this name in your shader:

> **[Babylon.js Playground](https://playground.babylonjs.com/#VG25E8%2315)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Note that you can use your own vertex shader with a post process by giving a value to the 11th parameter, but your existing vertex shader won’t work because the post process class is drawing a full screen 2D quad and the “position” attribute reflects that (it directly passes vertices for a triangle in the NDC coordinate system). The default vertex shader used by the post process class is:

```plaintext
attribute vec2 position;

uniform vec2 scale;

varying vec2 vUV;

const vec2 madd = vec2(0.5, 0.5);

void main(void) {
	vUV = (position * madd + madd) * scale;
	gl_Position = vec4(position, 0.0, 1.0);
}

```

---

<div class="post-metadata">

**Author:** ![ajp](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ajp/32/9504_2.png) [@ajp](https://forum.babylonjs.com/u/ajp)\
**Post date:** [January 12, 2023, 12:54pm UTC](https://forum.babylonjs.com/t/varying-v-uv-has-static-use-in-the-frag-shader-but-is-undeclared-in-the-vert-shader/37244/3 "2023-01-12T12:54:49Z")

</div>

A quick follow up for those looking for `vUV` in the documentation. It’s under the section [“Introduction To Shaders → Running Shader Code”](https://doc.babylonjs.com/features/featuresDeepDive/materials/shaders/introToShaders#running-shader-code) which shows `vUV` being set by the vertex shader and passed to the fragment shader.

 ![Introduction_to_Shaders___Babylon_js_Documentation](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/9/6/9602fe3c4dfddaf489c08f04d207b1e74db3e8fd.jpeg)

---

<div class="post-metadata">

**Author:** ![ajp](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ajp/32/9504_2.png) [@ajp](https://forum.babylonjs.com/u/ajp)\
**Post date:** [January 12, 2023, 2:10pm UTC](https://forum.babylonjs.com/t/varying-v-uv-has-static-use-in-the-frag-shader-but-is-undeclared-in-the-vert-shader/37244/4 "2023-01-12T14:10:31Z")

</div>

And this playground shows an example of a custom shader applied to a custom mesh (no postprocess step required) [https://playground.babylonjs.com/#VG25E8#19](https://playground.babylonjs.com/#VG25E8#19)

Thanks to @Evgeni_Popov for pointing out the postProcess interacts with the whole screen so that my previous approach was not going to work. And to this page for showing me how to set uniforms for a material’s custom shader: [Passing Uniforms to your custom Babylon.js shader. Where's my u\_resolution? - Big Tex Hog Tech Blog](https://bigtexhog.com/babylonjs-shader-uniforms) and I now see that the `material.setFloat("abc", 1.0)` is documented towards the bottom of this page: [Shader Material | Babylon.js Documentation](https://doc.babylonjs.com/features/featuresDeepDive/materials/shaders/shaderMaterial)

PostProcessing step is blurry but solving that’s for another time / another question.

Video from version [#17 of the playground](https://playground.babylonjs.com/#VG25E8#17) where the custom mesh was a simple plane (and no postprocessing was applied):

[https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/a/a/aa08ca1f3b46f6ba3f207cef84827222243db2c9.mp4](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/a/a/aa08ca1f3b46f6ba3f207cef84827222243db2c9.mp4)
