# I can't seem to use a uniform shader variable if I name it "uAmbientColor"

**URL:** https://discourse.processing.org/t/i-cant-seem-to-use-a-uniform-shader-variable-if-i-name-it-uambientcolor/32593
**Category:** Coding Questions
**Created:** [October 4, 2021, 12:27am UTC](https://discourse.processing.org/t/i-cant-seem-to-use-a-uniform-shader-variable-if-i-name-it-uambientcolor/32593 "2021-10-04T00:27:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![modusponens](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/modusponens/32/13888_2.png) [@modusponens](https://discourse.processing.org/u/modusponens)
#### Post date: [October 4, 2021, 12:27am UTC](https://discourse.processing.org/t/i-cant-seem-to-use-a-uniform-shader-variable-if-i-name-it-uambientcolor/32593/1 "2021-10-04T00:27:18Z")

</div>

Just as the title says, if I make a p5 sketch with `WEBGL` enabled and all that, and I make a shader and try to give it a uniform variable called `uAmbientColor`, I am unable to use it correctly.

Regard this humble sketch:  
[https://editor.p5js.org/modusponens/sketches/q3uLSb2Vk](https://editor.p5js.org/modusponens/sketches/q3uLSb2Vk)

Inside it, you will find `basic.frag`, which defines `uniform vec3 uAmbient`. In `sketch.js`, I set things up so that I use a simple test shader I wrote and draw a square on the screen. The square should be yellow because I have

```auto
theShader.setUniform("uAmbient", [1, 1, 0]);

```

in the sketch file and I have

```auto
gl_FragColor = vec4(uAmbient, 1.0)

```

in the fragment shader.

If you change the name of the variable to `uAmbientColor` in `basic.frag` and `sketch.js`, the square looks black instead of yellow, and nothing you can do with the numbers passed into that function seems to make any difference.

I even went as far as to try turning `uAmbientColor` into a float and adding two additional floats, so that in my shader I had

```auto
uniform float uAmbientColor; // r for red
uniform float uAmbientColog; // g for green
uniform float uAmbientColob; // b for blue
// ... //
gl_FragColor = vec4(uAmbientColor, uAmbientColog, uAmbientColob, 1.0);

```

in the fragment shader, and then I had

```auto
  theShader.setUniform("uAmbientColor", 1);
  theShader.setUniform("uAmbientColog", 1);
  theShader.setUniform("uAmbientColob", 1);

```

in my sketch file. The result was a cyan square, which is consistent with the 1 I’m trying to pass into the R, G, and B channels only making it through to the G and B and being replaced with a 0 in R.

I’m baffled. What might be causing this?

---

<div class="post-metadata">

### Author: ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)
#### Post date: [October 4, 2021, 7:06am UTC](https://discourse.processing.org/t/i-cant-seem-to-use-a-uniform-shader-variable-if-i-name-it-uambientcolor/32593/2 "2021-10-04T07:06:50Z")

</div>

`uAmbientColor` is one of the many uniform names that p5.js uses for its built in shaders. See [p5.RendererGL.js](https://github.com/processing/p5.js/blob/main/src/webgl/p5.RendererGL.js#L1290).

Here’s a full listing of the reserved uniforms:

```auto
uMaterialColor
uSampler
uTint
uSpecular
uEmissive
uShininess
uUseLighting
uPointLightCount
uPointLightLocation
uPointLightDiffuseColors
uPointLightSpecularColors
uDirectionalLightCount
uLightingDirection
uDirectionalDiffuseColors
uDirectionalSpecularColors
uAmbientLightCount
uAmbientColor
uSpotLightCount
uSpotLightAngle
uSpotLightConc
uSpotLightDiffuseColors
uSpotLightSpecularColors
uSpotLightLocation
uSpotLightDirection
uConstantAttenuation
uLinearAttenuation
uQuadraticAttenuation

```

---

<div class="post-metadata">

### Author: ![modusponens](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/modusponens/32/13888_2.png) [@modusponens](https://discourse.processing.org/u/modusponens)
#### Post date: [October 4, 2021, 7:05pm UTC](https://discourse.processing.org/t/i-cant-seem-to-use-a-uniform-shader-variable-if-i-name-it-uambientcolor/32593/3 "2021-10-04T19:05:28Z")

</div>

Oh, okay! So p5 has built-in shaders? It doesn’t support normal mapping through any built-in means, though, does it? This is my ultimate goal.

---

<div class="post-metadata">

### Author: ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)
#### Post date: [October 4, 2021, 8:25pm UTC](https://discourse.processing.org/t/i-cant-seem-to-use-a-uniform-shader-variable-if-i-name-it-uambientcolor/32593/4 "2021-10-04T20:25:44Z")

</div>

Yes, p5.js has a number of basic built in shaders for different scenarios (with or without lights, with or without stroke, and with or without a texture). And all of the uniforms and attributes that are available to the built in shaders are available to your custom shaders.

Here is an example of a shader that manipulates the vertex normal in the fragment shader (as well as deforming the geometry in the vertex shader): [Waving Flag Shader - OpenProcessing](https://openprocessing.org/sketch/1116549)

Similarly, you should be able to make a normal map shader using a `sampler2D` uniform which you provide as a p5.Graphics or p5.Image.

https://www.openprocessing.org/sketch/1116549/embed/
