Questions tagged [vertex-shader]

Vertex shaders are executable programs that execute as part of the programmable geometry pipeline in modern graphics APIs such as e.g. Direct3D or OpenGL. Vertex shaders are usually hardware accelerated on consumer hardware nowadays. The vertex shader processes one vertex at a time, followed by primitive assembly, optionally geometry shader and transform feedback, clipping, and finally rasterization and fragment processing.

Vertex shaders were introduced as an extension to OpenGL 1.3 and as a feature of Direct3D 8.0 around 2001. They were the first step in making part of the render pipeline on consumer hardware freely programmable as opposed to hardwired functionality like the TnL stage or register combiners which until then were at best configurable in some limited way.

The vertex shader is typically the first programmable part of the pipeline. The scope of a vertex shader is a single vertex without any information about the connectivity between vertices or any other vertices and any state set as "uniform", i.e. data that is constant across everything in the current draw call. A vertex shader cannot create vertices nor discard them, and a vertex shader has no local memory or other way that can be used to communicate data from one vertex to another.

After vertices have been transformed by the vertex shader, they are assembled into primitives and optionally processed by a geometry shader, which runs on the scope of all vertices within a single primitive (such as a triangle) and optionally the surrounding vertices.

Resources:

911 questions
162
votes
5 answers

Vertex shader vs Fragment Shader

I've read some tutorials regarding Cg, yet one thing is not quite clear to me. What exactly is the difference between vertex and fragment shaders? And for what situations is one better suited than the other?
adivasile
  • 2,377
  • 3
  • 24
  • 32
63
votes
4 answers

Is it important to call glDisableVertexAttribArray()?

I'm not entirely clear on the scope of enabling vertex attrib arrays. I've got several different shader programs with differing numbers of vertex attributes. Are glEnableVertexAttribArray calls local to a shader program, or global? Right now I'm…
Grumdrig
  • 16,588
  • 14
  • 58
  • 69
60
votes
1 answer

In OpenGL vertex shaders, what is w, and why do I divide by it?

void main(void) { vec4 clipCoord = glModelViewProjectionmatrix * gl_Vertex; gl_Position = clipCoord; gl_FrontColor = gl_Color; vec3 ndc = clipCoord.xyz / clipCoord.w; So the clipCoord is just doing standard fixed pipeline transforms. Why…
anon
  • 41,035
  • 53
  • 197
  • 293
26
votes
1 answer

Drawing a border on a 2d polygon with a fragment shader

I have some simple polygons (fewer than 20 vertices) rendering flat on a simple xy plane, using GL_TRIANGLES and a flat color, a 2d simulation. I would like to add a border of variable thickness and a different color to these polygons. I have…
23
votes
1 answer

glGetAttribLocation returns -1 when retrieving existing shader attribute

I'm trying to pass in attributes to my vertex shader but for some reason it keeps giving me a -1 on the 3rd attribute location I'm asking openGl to retrieve via glGetAttribLocation(). Currently it keeps giving me a -1 for the texCoord attribute and…
Joey Dewd
  • 1,804
  • 3
  • 20
  • 43
22
votes
2 answers

What is the relationship between gl_Color and gl_FrontColor in both vertex and fragment shaders

I have pass-through vertex and fragment shaders. vertex shader void main(void) { gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } fragment shader void main(void) { gl_FragColor =…
Thomas Vincent
  • 2,214
  • 4
  • 17
  • 25
19
votes
1 answer

Are MTLVertexAttributeDescriptors necessary? Why are they needed?

I've been learning Metal for iOS / OSX, and I began by following a Ray Wenderlich tutorial. This tutorial works fine but it makes no mention of MTLVertexAttributeDescriptors. Now that I'm developing my own app, I'm getting weird glitches and I'm…
bsabiston
  • 721
  • 6
  • 22
16
votes
3 answers

Apply color gradient to material on mesh - three.js

I have an STL file loaded into my scene with a single colour applied to a phong material I'd like a way of applying two colours to this mesh's material with a gradient effect applied on the Z axis a like the example below.Gradient Vase]1 I have a…
Huskie69
  • 795
  • 3
  • 11
  • 31
16
votes
2 answers

Passing uniform 4x4 matrix to vertex shader program

I am trying to learn OpenGL and following this: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/ Up until the point where they started passing matrices to the vertex shader to translate the triangle they where drawing I was…
Andreas Vinter-Hviid
  • 1,482
  • 1
  • 11
  • 27
13
votes
1 answer

Metal Vertex Shader Warning in Swift 5

I got this passthrough vertex shader I used from Apple's sample code: vertex VertexIO vertexPassThrough(device packed_float4 *pPosition [[ buffer(0) ]], device packed_float2 *pTexCoords [[ buffer(1) ]], …
Gizmodo
  • 3,151
  • 7
  • 45
  • 92
13
votes
3 answers

How can I find a list of all the uniforms in OpenGL es 2.0 vertex shader pro

I'm trying to learn how to program vertex shaders. In Apple's sample project they have a line to set a glUniform1f(uniforms[UNIFORM_TRANSLATE], (Glfloat)transY); Then this value is used in // value passt in f //…
Ted pottel
  • 6,869
  • 21
  • 75
  • 134
13
votes
1 answer

Blend two textures with different coordinates and sizes in the same shader

I have two textures with different coordinates and sizes in my fragment shader: varying highp vec2 v_currentTextureCoords; varying highp vec2 v_backgroundTextureCoords; uniform sampler2D u_currentTexture; uniform sampler2D u_backgroundTexture; void…
GuiTeK
  • 1,561
  • 5
  • 20
  • 39
12
votes
2 answers

Set color for each vertex in a triangle

I want to set each three vertex of a triangle from a mesh red, blue and green. As seen in the first part this tutorial which is for another language. This is the code they are using to set red, green and blue to each vertext in the each triangle…
Programmer
  • 121,791
  • 22
  • 236
  • 328
12
votes
6 answers

GLSL vertex shader cancel render

Can the rendering for a pixel be terminated in a vertex shader. For example if a vertex does not meet a certain requirement cancel the rendering of that vertex?
user346443
  • 4,672
  • 15
  • 57
  • 80
11
votes
1 answer

Why does OpenGL drawing fail when vertex attrib array zero is disabled?

I was having extreme trouble getting a vertex shader of mine to run under OpenGL 3.3 core on an ATI driver: #version 150 uniform mat4 graph_matrix, view_matrix, proj_matrix; uniform bool align_origin; attribute vec2 graph_position; attribute vec2…
mrdecemberist
  • 2,631
  • 2
  • 20
  • 23
1
2 3
60 61