Drawing vertices without actual vertices?

Started by
8 comments, last by ryutenchi 10 years, 4 months ago

Namely, I want to write a vertex shader something akin to this:


in vec3 vertex;

void main()
{
	vertex.x = gl_VertexID % vertexWidth;
	vertex.y = gl_VertexID / vertexWidth;
        //vertex.z = someProceduralFunction(...);
	gl_Position = projection * modelview * vec4(vertex, 1.0);
}

Ignoring the question of whether the code even compiles, it's abundantly clear that I don't actually need any VBOs in the theoretical sense, so is it possible to just pump some kind of shadow vertices to this shader? Or do I need to allocate the space in the buffer regardless?

Advertisement

I've never tried this in GL, but yep, this trick is completely valid in D3D! In D3D, you basically just make sure that no VBOs or vertex attributes are bound/exist.

you will need at the very least 1 vertex and an index buffer with a length == to the number of vertices you want to generate. I could be wrong, but I'm almost positive that the vertex shader only runs and only runs once per vertex in the VBO.

I did ask something very similar on OpenGL.org and got an answer.

http://www.opengl.org/discussion_boards/showthread.php/182969-Draw-with-fragment-shader-without-vertices

You dont have to glEnableVertexAttribArray( 0); the vertex attribute but define a default value with glVertexAttrib1f( 0, 0);

Define the input attribute in the shader: layout(location = 0) in float dummy_attrib;

....and then just use gl_VertexID as you said.

I dont use any VBOs when I do this but if you are afraid of broken drivers then use one.

Fancy, though what is the use?

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

you will need at the very least 1 vertex and an index buffer with a length == to the number of vertices you want to generate. I could be wrong, but I'm almost positive that the vertex shader only runs and only runs once per vertex in the VBO.

No, you don't. It is perfectly valid to draw without a single attribute.

Fancy, though what is the use?

Rendering without attributes (not without vertices, since it is impossible) is an awfully powerfully rendering method. In last 3 or 4 years I have almost everything drawn without a single attribute. From screen-aligned quads and 2D charts to some very complex geometries. For simple shapes index buffer is not required, but complex ones need "scheme" for "vertex distribution". For my purposes, attributless rendering is more powerful than tesselation shaders since there is no limitations for patch size.


No, you don't. It is perfectly valid to draw without a single attribute.

Ok, then I'm confussed how does the GPU know how many times to call the vertex shader? How does one invoke this black mage?^^

The primitive type as well as the number of vertices (or entries in the index buffer) are the parameters of draw calls.

No, you don't. It is perfectly valid to draw without a single attribute.


Ok, then I'm confussed how does the GPU know how many times to call the vertex shader? How does one invoke this black mage?^^
Even when you are using VBOs, it's the actual draw call itself that specifies the number of vertices to be drawn (or the number of triangles/etc, but that's the same thing).


Even when you are using VBOs, it's the actual draw call itself that specifies the number of vertices to be drawn (or the number of triangles/etc, but that's the same thing).

ooooh... I aways thought that would lead to an exception because of trying to access a null pointer... interesting^^ Learn something new everyday^^

This topic is closed to new replies.

Advertisement