# Why is the result fo the shader black?

**URL:** <https://discourse.processing.org/t/why-is-the-result-fo-the-shader-black/10850>\
**Category:** Coding Questions\
**Created:** [May 2, 2019, 7:14pm UTC](https://discourse.processing.org/t/why-is-the-result-fo-the-shader-black/10850 "2019-05-02T19:14:54Z")\
**Posts on this page:** 2\
**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:** [May 2, 2019, 7:14pm UTC](https://discourse.processing.org/t/why-is-the-result-fo-the-shader-black/10850/1 "2019-05-02T19:14:54Z")

</div>

I try to port:

[https://www.shadertoy.com/view/XssSzN](https://www.shadertoy.com/view/XssSzN)

Here is the sketch:

```auto

PShader shader;

void setup() {
  size(800, 600, P2D);
  
  shader = loadShader("metaballs.frag");
  
}

void draw() {
  shader.set("iTime", (float) millis() / 1000);
  shader.set("iResolution", new PVector(width, height));
  shader(shader);
  rect(0, 0, width, height);
}

```

```auto
#version 330

#ifdef GL_ES
precision highp float;
precision highp int;
#endif

uniform vec3 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)

in vec4 vertTexCoord;
out vec4 fragColor;

void main() {
	vec2 uv = (-iResolution.xy+2.0*vertTexCoord.xy)/iResolution.y;

    // anim
	vec2 c1 = 0.8*sin( iTime*1.0 + vec2(4.0,0.5) + 1.0);
	vec2 c2 = 0.8*sin( iTime*1.3 + vec2(1.0,2.0) + 2.0);
	vec2 c3 = 0.8*sin( iTime*1.5 + vec2(0.0,2.0) + 4.0);
	
    // potential (3 metaballs)
    float v = 0.0;	
	v += 1.0-smoothstep(0.0,0.7,length(uv-c1));
	v += 1.0-smoothstep(0.0,0.7,length(uv-c2));
	v += 1.0-smoothstep(0.0,0.7,length(uv-c3));

    // color	
	vec3 col = mix( vec3(v), vec3(1.0,0.6,0.0), smoothstep(0.9,0.91,v) );
	
	fragColor = vec4(col,1.0);

}

```

It seems to be always black.  
I think the problem is with v, it seems to be 0 but I could be wrong.

Also, fragCoord is what processing calls vertTexCoord right? (And if so, processing choose a horrible name).

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [May 2, 2019, 8:41pm UTC](https://discourse.processing.org/t/why-is-the-result-fo-the-shader-black/10850/2 "2019-05-02T20:41:25Z")

</div>

The uv was wrong. Should be:

```
vec2 uv = iResolution.x*(-1.0+2.0*vertTexCoord.xy)/iResolution.y;

```

because `vertTexCoord` is already normalized or

```
vec2 uv = (-iResolution.xy+2.0*gl_FragCoord.xy)/iResolution.y;

```

I suggest adding something like this to your sketch:

```auto
void mousePressed() {
  try {
    shader = loadShader("metaballs.frag");
    shader(shader);
  } catch(Exception e) {
    println(e.getMessage());
  }
}

```

so you can quickly test changes in your shader.

I figured out the error by adding `col.rg = uv;` before `fragColor = ...` to visualize `uv` and it was black, so I figured that the uv coordinates are wrong.
