itun
itun

Reputation: 3521

OpenGL: Add vertices with vertex shader

Tell me, please, how I can add new vertex in vertex shader?

Upvotes: 7

Views: 6221

Answers (4)

Yun
Yun

Reputation: 3837

It's not possible to create new vertices using a vertex shader; it can only transform vertices. The Khronos documentation for the vertex shader states:

A vertex shader receives a single vertex from the vertex stream and generates a single vertex to the output vertex stream. There must be a 1:1 mapping from input vertices to output vertices.

There are several options for adding new vertices:

  • Generate the new vertices on the CPU before rendering them.
  • Use a geometry shader for creating new vertices based on a given primitive.
  • Use tessellation for creating new vertices based on a given patch.

Upvotes: 0

genpfault
genpfault

Reputation: 52167

You can't. That's what geometry shaders are for.

Upvotes: 3

Roy T.
Roy T.

Reputation: 9648

You can add vertices using a geometry shader http://www.opengl.org/wiki/Geometry_Shader

"A GS can create new primitives, unlike vertex shaders, which are limited to a 1:1 input to output ratio."

Upvotes: 3

pmr
pmr

Reputation: 59841

The vertex shader only transforms vertices. If you need to output additional geometry based on the input vertices a geometry shader is what you need.

Upvotes: 7

Related Questions