Skip to main content
GameDev.net gamedev.net
🔒 Locked

GS Geometry from texture?

Started by Christoffer Enne Jun 5, 2012 at 8:20 AM 4 replies 2.6k views
Original Post
Christoffer Enne
Christoffer Enne
I resently read about geometry shaders but I only found examples where you pass vertex data to the GS and then create new geometry. I was thinking is it possible to not give the geometry shader any vertrices and have it create new ones by reading a texture? So that the only thing I have to do is give the shader a texture and out comes some nice looking terrain.

If there is? Is there any tutorials or something where I can read about it?
iedoc
iedoc
you have to at least pass a single vertex to the geometry shader, but from that single vertex you'd be able to make your terrain and send it back to your app through the stream output. You might also consider looking into the tesselation shaders

about how to do it, all you have to do is read the texture the same way you would read it in a vertex or pixel shader. you would create a grid, where each texel in the texture represents the height of each vertex in the grid.
japro
japro
Note that the geometry shader is not really meant for massive geometry amplification. Using it to say expand points to quads or so is ok. Using it to create vast amounts of vertices from a texture most likely isn't.
Not sure about dx but at least from OpenGL i know that you can render without using a vertex buffer by essentially using the vertex id as the only input and calculating the rest from there.
iedoc
iedoc
japro's right about a lot of geometry, which is why i mentioned the tesselation shaders. but if your just talking about making terrain, i wouldn't generate it in the shaders anyway if it's not going to be moving around like water. I guess if you wanted to just make the terrain while initializing the scene you could do that, but you could just make your own terrain in your app by making a grid and changing each vertice's height depending on the texture.
Christoffer Enne
Christoffer Enne
Well actually my terrain is dynamic and it is and made to change each frame. Right now every chunk is stored in byte files and loaded on the go as i need them. But I thought that creating it from a texture could help me to get the right light without doing calculations on the cpu or doing multiple passes as the light is depending on the terrain cells neibours.
Nik02
Nik02
Geometry shader is severely limited in the amount of data it can write out per invocation.

You could:

-use a flat grid, and displace it in VS by reading from a heightmap texture
-use a single quad, and tessellate it; in the domain shader, displace the generated geometry like you'd do in vs
-use instancing to render several tessellated quads; use the instance id to look up the quad index to determine the part of the heightmap texture you want to use for that quad
Niko Suni

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.