0

I have an idea and I want to know if this would be possible in any way. I want to render a scene and use the resulting image to find out which triangles were or are visible from my current point of view.

Let me give you an example: I would render the scene into a custom framebuffer and store a certain ID to every pixel, the ID would be an identifier to the original primitive. Now my problem is that I don't know how to find out which pixel belonged to which triangle. My first idea was to just pass an ID along the shader stages, but I don't know if that would be possible. If I can find out which primitives were drawn, I could cull the others. Is there any way to find out which pixel belonged to which (original) triangle?

There is a similar question here on Stackoverflow, but it does not really answer my question (see question).

Why do I want to do this?

I have a server-client scenario where my server is very powerful whereas my client is not. The server sends the model data to the client and the client renders it locally. To reduce the rendering time and the amount of memory needed, I want to do precalculations on the server and only send certain parts of the model to the client.

Edit: Changed my question because I misunderstood some concepts.

killexe
  • 357
  • 4
  • 16
  • Maybe I'm misunderstanding what you're after, but in shadow mapping we generate the shadow depth map by rendering the scene from the light's point of view (i.e. light position as a camera). When you say you want to use the 'camera position as a light source' you're essentially saying you want to use the camera as a camera. It sounds like you want to pass your geometry through the depth testing phase, read back gl_PrimitiveID to the CPU, then try to figure out which verts this corresponds to. IMO you would be better off just rendering a Gbuffer and sending that to the client for lighting etc. – Fibbs Apr 16 '19 at 12:44
  • Yes thank you for your comment, I realized that just now. So actually shadow mapping wouldn't be doing anything. _It sounds like you want to pass your geometry through the depth testing phase, read back gl_PrimitiveID to the CPU and then try to figure out which verts this corresponds to_. This is exactly what I am trying to do. Could you explain what you mean with the GBuffer? – killexe Apr 16 '19 at 12:50
  • 1
    A Gbuffer is a series of textures that represent the scene from the camera's PoV. E.g. you have separate textures for diffuse colouring, object normals, depth, etc. It allows you to then perform the expensive lighting calcs only on what is visible. The downside is that it's bandwidth heavy. You're possibly optimizing in the wrong place. Depth testing and culling is the cheapest part of the rendering process. Offloading it to the server wont gain you much if anything. Scenegraph culling on the server might gain you a lot for complex scenes but this isn't done on the GPU. – Fibbs Apr 16 '19 at 13:02
  • 1
    @killexe The ID will be rendered to custom buffer so aux or stencil... just read it with `glReadPixels` either read the whole frame or just single pixel from it (depends on what you need) here example of this: [OpenGL 3D-raypicking with high poly meshes](https://stackoverflow.com/a/51764105/2521214) look for `glReadPixels(sx,sy,1,1,GL_STENCIL_INDEX,GL_INT,&_id); ` in the code – Spektre Apr 17 '19 at 07:46
  • Thank you very much. Yesterday I was trying to encode the ID into a unique color value, but this approach is much better. – killexe Apr 17 '19 at 08:01

0 Answers0