I am new to opengl and this might be a stupid question. I am trying to make a planet (I am using glad and glfw). So I want to make a icosphere. Now I generated all the vertices (huge amount of them) on the computer and it seems passing them to the GPU (using a vertex array object) makes things slow. So I made a triangle subdivision algorithm in the geometry shader (which I would use instead of such a huge amount of vertices). To generate a terrain, I read that you need tessellation shaders. The problem is that I want to use the subdivision algorithm before tessellating the triangles. So is there a way to change the orders of the shaders (like geometry shader first, then the tessellation shader)? If not, any suggestions on how should I handle this problem?
Asked
Active
Viewed 349 times
0
-
2"*The problem is that I want to use the subdivision algorithm before tessellating the triangles.*" That doesn't make sense. Subdivision is [part of tessellation](https://www.khronos.org/opengl/wiki/Tessellation); why would you want to do it before? – Nicol Bolas May 25 '20 at 21:18
-
The type of subdivision I want to do to make a icosphere is not given by any of the tessellation levels..like dividing a triangle into 4 (a triangle made of the midpoints of the original triangle does this)..hence I want to subdivide before tessellating @NicolBolas – Ridayesh May 25 '20 at 21:28
-
2Are you sure you're not uploading the vertices _every frame_? – Botje May 25 '20 at 22:31
-
@Ridayesh: OpenGL's tessellator has a specific way of tessellating an abstract patch. If you need such strict control over the exact triangles generated, then you're using the wrong tool. – Nicol Bolas May 25 '20 at 22:52
-
Ok, so which tool (or shader) should I use...to get a specify control on the subdivision? @NicolBolas – Ridayesh May 26 '20 at 05:13
-
Nope I am not changing the data in the buffers per frame. Rather I am using the shaders to transform the vertices as per the needs (like multiplying projection view model matrices, etc is done in the shaders)...@Botje – Ridayesh May 26 '20 at 05:15
-
@Ridayesh: "*I am not changing the data in the buffers per frame.*" If you're not changing the amount of tessellation on a frame-by-frame basis, then there's really no reason not to just do the tessellation on the CPU (well, besides how much data the GPU will have to read). – Nicol Bolas May 26 '20 at 05:17
-
Yeah, so I am not changing the data in the buffers, but in the tessellation shader (or subdivision in the geometry shader) the tessellation is done per frame (based on the distance). The issue with doing the tessellation on the cpu is, that the gpu has to read a huge amount of data, which slows things down...can you suggest me something how should I subdivide and tessellate in the gpu? @NicolBolas – Ridayesh May 26 '20 at 05:25
-
@Ridayesh: What makes you so sure that you're vertex data bandwidth limited in performance? Many GPUs can read vertex data faster than they can rasterize triangles, especially if the data is reasonably optimized for consumption. – Nicol Bolas May 26 '20 at 05:53
-
I wrote two programs: using the geometry shader to make a sphere of subdivision = 4 and I also stored all the vertices of the sphere of subdivision = 4 in an array and then the vertex buffer object. The first program ran at a greater fps while for the second, if I use the tessellation shader with it, the fps drops very quickly @NicolBolas – Ridayesh May 26 '20 at 06:21
-
11. some GL implementations have slow geometry shaders. 2. what is huge ammount of vertexes? 3. computing the mesh on CPU is perfectly fine see [Sphere triangulation by mesh subdivision](https://stackoverflow.com/a/29139125/2521214) however if you want to get near surface you would need much more vertexes then reasonable so its better to compute the surface in fragment shader instead of having its mesh see [How can i make gradient sphere on glsl?](https://stackoverflow.com/a/41442375/2521214) – Spektre May 26 '20 at 07:05
-
4. this [Is it possible to make realistic n-body solar system simulation in matter of size and mass?](https://stackoverflow.com/a/28020934/2521214) might interest you. – Spektre May 26 '20 at 07:07
-
Thanks a lot @Spektre and Nicol Bolas. I will look into the posts and follow them! – Ridayesh May 26 '20 at 07:30