# The shader doesn't have a uniform called "textur

**URL:** <https://discourse.processing.org/t/the-shader-doesnt-have-a-uniform-called-textur/10045>\
**Category:** Coding Questions\
**Created:** [April 7, 2019, 11:13am UTC](https://discourse.processing.org/t/the-shader-doesnt-have-a-uniform-called-textur/10045 "2019-04-07T11:13:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![clankill3r](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/clankill3r/32/1098_2.png) [@clankill3r](https://discourse.processing.org/u/clankill3r)\
**Post date:** [April 7, 2019, 11:13am UTC](https://discourse.processing.org/t/the-shader-doesnt-have-a-uniform-called-textur/10045/1 "2019-04-07T11:13:36Z")

</div>

I have this really simple fragment shader (this is just the starting point…):

```auto
out vec4 fragColor;

uniform sampler2D texture;

void main() {

	fragColor = texture2D(texture, vec2(0.5, 0.5));
}

```

```auto
PShader shader;
PImage img;
PImage img2;

public void settings() {
  size(600, 600, P3D);
}

public void setup() {
  img = loadImage("/Users/doekewartena/Desktop/1098_2.png");
  img2 = loadImage("/Users/doekewartena/Desktop/1098_3.png");
  shader = loadShader("frag.glsl"); // "vert.glsl"
  shader.set("texture", img2);
}

void draw() {
  background(0);
  shader(shader);
  image(img, 0, 0);
}

```

When compiling I get the following error:

> The shader doesn’t have a uniform called “texture” OR the uniform was removed during compilation because it was unused.

Why is that? cause it clearly is used.

---

<div class="post-metadata">

**Author:** ![clankill3r](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/clankill3r/32/1098_2.png) [@clankill3r](https://discourse.processing.org/u/clankill3r)\
**Post date:** [April 7, 2019, 6:19pm UTC](https://discourse.processing.org/t/the-shader-doesnt-have-a-uniform-called-textur/10045/2 "2019-04-07T18:19:05Z")

</div>

Specifying the shader version worked for me.

`#version 330`

I wish I had time to make better documentation of how to use shaders in processing.

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [April 8, 2019, 10:06am UTC](https://discourse.processing.org/t/the-shader-doesnt-have-a-uniform-called-textur/10045/3 "2019-04-08T10:06:00Z")

</div>

You need to use the Shader implementation of Processing to use shader, if don’t do the code writing is more complexe, below an example:  
glsl

```auto
// Processing implementation
#ifdef GL_ES
precision highp float;
#endif
#define PROCESSING_TEXTURE_SHADER
varying vec4 vertColor;
varying vec4 vertTexCoord;
uniform vec2 resolution; // WARNING VERY IMPORTANT // need this name for unknow reason :( here your pass your resolution texture
// vec2 texOffset = vec2(1) / resolution; // only work with uniform resolution

// Rope implementation
uniform sampler2D texture;

void main() {
  vec2 uv = vertTexCoord.st;
  uv.y = 1.-uv.y;
  gl_FragColor = texture2D(texture,uv);
}

```

sketch

```auto
PShader shader;
PImage img;

public void setup() {
  size(100, 100, P3D);
  img = loadImage("small_puros_girl.jpg");
  surface.setSize(img.width,img.height);
  shader = loadShader("data/simple_shader.glsl"); // "vert.glsl"
  shader.set("texture", img);
}

void draw() {
  background(0);
  shader(shader);
  image(img, 0, 0);
}

```

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [April 8, 2019, 10:14am UTC](https://discourse.processing.org/t/the-shader-doesnt-have-a-uniform-called-textur/10045/4 "2019-04-08T10:14:57Z")

</div>

> [@clankill3r](#):
>
> ```auto
> out vec4 fragColor;
> 
> uniform sampler2D texture;
> 
> void main() {
> 
> fragColor = texture2D(texture, vec2(0.5, 0.5));
> }
> 
> ```
> 
> ```auto
> 
> ```

When I change the name `texture`to `tex` console return no error, but that’s don’t work too 🙂 maybe the work texture is reserved ?

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [April 8, 2019, 10:17am UTC](https://discourse.processing.org/t/the-shader-doesnt-have-a-uniform-called-textur/10045/5 "2019-04-08T10:17:50Z")

</div>

> [@clankill3r](#):
>
> #version 330

and this one only almost work with `texture()`not with old `texture2D()` on my laptop.

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [April 8, 2019, 10:56am UTC](https://discourse.processing.org/t/the-shader-doesnt-have-a-uniform-called-textur/10045/6 "2019-04-08T10:56:06Z")

</div>

This is almost certainly to do with the code at [https://github.com/processing/processing/blob/master/core/src/processing/opengl/PGL.java#L1904](https://github.com/processing/processing/blob/master/core/src/processing/opengl/PGL.java#L1904) that does automatic rewriting of shaders to match the underlying OpenGL version unless you specify `#version`

Incidentally, looking at that and then changing your code to `shader.set("texMap", img);` seems to “work”.
