<p>I may have misunderstood, but it sounds like the frame buffer you're rendering to is only 2×2 pixels? In that case, the fragment shader will be evaluated at each pixel center, which will be at 0.25 and 0.75 in UV space. So with a threshold of 0.95 you will indeed not get any pixels green.</p>

<p>If you use a larger framebuffer, say 100×100, then the last 5 pixels of each row should come out green.</p>

CC BY-SA 3.0
2018-04-11T02:30:11.227Z
2018-04-11T02:30:11.227Z
Nathan Reed
<p>An alternative solution would be to avoid the vertex/geometry shader completely and draw your fullscreen quad with </p>

<pre><code>glRecti(-1, -1, 1, 1);
</code></pre>

<p>then just compile a fragment shader and generate your UVs with:</p>

<pre><code>vec2 uv = gl_FragCoord.xy / framebufferSize.xy;
</code></pre>

<p>I don't know what you're doing but this could be potentially a fast forward solution for what you require. Maybe you're doing something else and you just broke down your problem to the bare minimum, i think in this case my answer should be still helpful for people seeking help in the problem as summarized in the headline.</p>

CC BY-SA 3.0
2018-04-11T15:12:26.943Z
That would pretty much result in the exact same outcome and isn't really related to his issue.
Christian Rau
CC BY-SA 4.0
2018-09-03T18:43:55.557Z
this guy knows more about quad-mapping than everybody else ;) but nathan, you could explain the connection better. did you find a solution for that real 3d quad-mapping shader problem on your blog?
thewhiteambit
CC BY-SA 3.0
2018-04-11T12:41:03.570Z
2018-04-11T12:41:03.570Z
Intrins
<p>I'm rendering a full screen quad using <code>gl_VertexID</code> as <code>GL_TRIANGLE_STRIP</code></p>

<pre><code>const vec2 kVertices[4] = vec2[]
(
 vec2(-1.0,  1.0),
 vec2(-1.0, -1.0),
 vec2( 1.0,  1.0),
 vec2( 1.0, -1.0)
 );

void main() {
    gl_Position = vec4(kVertices[gl_VertexID], 1.0, 1.0);
    vs_out.texCoords = gl_Position.xy / 2.0 + 0.5;
    vs_out.instanceID = gl_InstanceID;
}
</code></pre>

<p>Geometry shader just passes coordinates through into the output called <code>vTexCoords</code>.</p>

<p>Then, in fragment shader, I output red and green into 2x2 texture using following code:</p>

<pre><code>if (vTexCoords.x &gt;= 0.95) {
    oFragData0 = vec4(0.0, 1.0, 0.0, 1.0);
} else {
    oFragData0 = vec4(1.0, 0.0, 0.0, 1.0);
}
</code></pre>

<p>I always assumed texture coordinates (0; 0), (0; 1), (1; 0), (1; 1) would map to the vertices, but the output is completely red, which means X value never reaches 1.0. 
Then I'm trying to use 0.75 (<code>vTexCoords.x &gt;= 0.75</code>), which is a texel center, and half of the texture becomes green, as expected.</p>

<p>What am I misunderstanding here?</p>

<opengl><texture><uv-mapping>
Full screen quad texture coordinates mapping
Pavlo Muratov
# Full screen quad texture coordinates mapping

(Asked by: username_0 on 2018-04-10)

I'm rendering a full screen quad using `gl_VertexID` as `GL_TRIANGLE_STRIP`

```
const vec2 kVertices[4] = vec2[]
(
 vec2(-1.0,  1.0),
 vec2(-1.0, -1.0),
 vec2( 1.0,  1.0),
 vec2( 1.0, -1.0)
 );

void main() {
    gl_Position = vec4(kVertices[gl_VertexID], 1.0, 1.0);
    vs_out.texCoords = gl_Position.xy / 2.0 + 0.5;
    vs_out.instanceID = gl_InstanceID;
}

```

Geometry shader just passes coordinates through into the output called `vTexCoords`.

Then, in fragment shader, I output red and green into 2x2 texture using following code:

```
if (vTexCoords.x >= 0.95) {
    oFragData0 = vec4(0.0, 1.0, 0.0, 1.0);
} else {
    oFragData0 = vec4(1.0, 0.0, 0.0, 1.0);
}

```

I always assumed texture coordinates (0; 0), (0; 1), (1; 0), (1; 1) would map to the vertices, but the output is completely red, which means X value never reaches 1.0.
Then I'm trying to use 0.75 (`vTexCoords.x >= 0.75`), which is a texel center, and half of the texture becomes green, as expected.

What am I misunderstanding here?

**Tags:** opengl, texture, uv-mapping


---

## 2 answers

### Answer by username_1 on 2018-04-11. Score: 1 | Accepted answer

I may have misunderstood, but it sounds like the frame buffer you're rendering to is only 2×2 pixels? In that case, the fragment shader will be evaluated at each pixel center, which will be at 0.25 and 0.75 in UV space. So with a threshold of 0.95 you will indeed not get any pixels green.

If you use a larger framebuffer, say 100×100, then the last 5 pixels of each row should come out green.


---

### Answer by username_2 on 2018-04-11. Score: 1

An alternative solution would be to avoid the vertex/geometry shader completely and draw your fullscreen quad with

```
glRecti(-1, -1, 1, 1);

```

then just compile a fragment shader and generate your UVs with:

```
vec2 uv = gl_FragCoord.xy / framebufferSize.xy;

```

I don't know what you're doing but this could be potentially a fast forward solution for what you require. Maybe you're doing something else and you just broke down your problem to the bare minimum, i think in this case my answer should be still helpful for people seeking help in the problem as summarized in the headline.

> **Comments:**
> **username_3**: That would pretty much result in the exact same outcome and isn't really related to his issue.  
> **username_4**: this guy knows more about quad-mapping than everybody else ;) but username_1, you could explain the connection better. did you find a solution for that real 3d quad-mapping shader problem on your blog?  

---

