<p>Your vertex data can contain information that you want. When we talk about vertex data, you can imagine a structure in which you can store data. And you can imagine a struct array where all vertex data is stored.</p>
<p>Very commonly used information within the vertices are:</p>
<ul>
<li>Position (vector 3D)</li>
<li>Normal vector (vector 3D)</li>
<li>UV coordinate (vector 2D)</li>
</ul>
<p>But of course you can add further information.
This data is then loaded into the GPU memory in the form of a Vertex Buffer Object (VBO). All vertices are stored there in an array</p>
<p>The <code>Render Program</code> consists of shader stages, which are essentially <code>vertex shader</code> and <code>fragment shader</code>. To be honest, you can also use <code>tessellation shaders</code> and a <code>geometry shader</code>. The <code>fragment shader</code> is called <code>pixel shader</code> when using Direct3D.</p>
<p>The <code>vertex shader</code> code is executed per vertex. Normally, this shader is used to transform the 3D mesh in relation to the camera. You can then simply pass on the UV coordinates to the next shader stage in the pipeline.
Between the <code>vertex shader</code> and the <code>fragment shader</code> is the <code>rasterization</code> step: Imagine a single triangle lying in front of the camera. Within the rasterization step, each pixel located within this triangle is passed to the fragment shader as a fragment. In addition, each <code>varying</code> variable (a variable that is passed from one shader stage to the next) is interpolated with respect to <strong>barycentric coordinates</strong>. In our case, the UV coordinates of the three corner points of the triangle are interpolated in relation to the barycentric coordinates. The <code>fragment shader</code> therefore has the interpolated value as input. The next step would then be to load the pixel of a texture at the interpolated UV coordinate, perform some BRDF calculations, shadow calculations and so on, and output the result.</p>

CC BY-SA 4.0
2024-04-17T08:38:58.727Z
2024-04-17T08:38:58.727Z
Thomas
<p>So in every mesh, the vertices can have UVs, and UVs are a way to store data for each vertex. Basically, at the time of rendering, when the shader runs, it's a way to check some arbitrary data for each vertex.</p>
<p>The mesh holds a UV array. The vertices are mapped (?) to UV coordinates, and this way the shader can get the correct element in the UV array for the vertices. And then, it can get the data that the UV holds. Most commonly,  this data is related to textures. But it can also be about more complex effects.</p>
<p>Is that correct?</p>

<shader><mesh><uv-mapping><vertex-buffer-object>
Vertices are mapped to UV coordinates, but how does the shader access the UV data?
kyopa
# Vertices are mapped to UV coordinates, but how does the shader access the UV data?

(Asked by: username_0 on 2024-04-17)

So in every mesh, the vertices can have UVs, and UVs are a way to store data for each vertex. Basically, at the time of rendering, when the shader runs, it's a way to check some arbitrary data for each vertex.

The mesh holds a UV array. The vertices are mapped (?) to UV coordinates, and this way the shader can get the correct element in the UV array for the vertices. And then, it can get the data that the UV holds. Most commonly, this data is related to textures. But it can also be about more complex effects.

Is that correct?

**Tags:** shader, mesh, uv-mapping, vertex-buffer-object


---

## 1 answers

### Answer by username_1 on 2024-04-17. Score: 1

Your vertex data can contain information that you want. When we talk about vertex data, you can imagine a structure in which you can store data. And you can imagine a struct array where all vertex data is stored.

Very commonly used information within the vertices are:

* Position (vector 3D)
* Normal vector (vector 3D)
* UV coordinate (vector 2D)

But of course you can add further information.
This data is then loaded into the GPU memory in the form of a Vertex Buffer Object (VBO). All vertices are stored there in an array

The `Render Program` consists of shader stages, which are essentially `vertex shader` and `fragment shader`. To be honest, you can also use `tessellation shaders` and a `geometry shader`. The `fragment shader` is called `pixel shader` when using Direct3D.

The `vertex shader` code is executed per vertex. Normally, this shader is used to transform the 3D mesh in relation to the camera. You can then simply pass on the UV coordinates to the next shader stage in the pipeline.
Between the `vertex shader` and the `fragment shader` is the `rasterization` step: Imagine a single triangle lying in front of the camera. Within the rasterization step, each pixel located within this triangle is passed to the fragment shader as a fragment. In addition, each `varying` variable (a variable that is passed from one shader stage to the next) is interpolated with respect to **barycentric coordinates**. In our case, the UV coordinates of the three corner points of the triangle are interpolated in relation to the barycentric coordinates. The `fragment shader` therefore has the interpolated value as input. The next step would then be to load the pixel of a texture at the interpolated UV coordinate, perform some BRDF calculations, shadow calculations and so on, and output the result.


---

