Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9133801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:32:59+00:00 2026-06-17T08:32:59+00:00

Trying to keep questions and answers simpler, I will reduce my problem from 3d

  • 0

Trying to keep questions and answers simpler, I will reduce my problem from 3d to 2d.

I have a 2d grid with X*Y cells in 2d space. It is defined simply by X, Y, bBoxMin2d and bBoxMax2d.

On the GPU (currently in a VBO), I have X*Y (unsigned 8 bit) integers, which define the brightness of the cells. So, for X=Y=3, if the VBO contains {4, 7, 3, 2, 9, 4, 7, 2, 1}, the grid should be rendered using patches of the following brightness:

4 7 3
2 9 4
7 2 1

I know I could create another VBO containing the world-position of the center of each cell and use the geometry shader to create a patch to be passed on to the fragment shader.

However, I want to be more efficient and do without a second VBO. My thinking is that if every instance of the geometry shader had its own thread index (similar to CUDA), it could create the cell’s patch using only that index, and bBoxMin2d and bBoxMax2d from e.g. a UBO. The fragment shader would then read the color from the VBO and I’d be happy.

But it seems there is no geometry-shader thread-index. So, how can I solve my problem?

Please don’t tell me to use another VBO with the positions – that would increase memory requirements from sizeof(uint8_t) = 1 byte per cell to at least sizeof(float3) + sizeof(uint8_t) = 13 bytes. And I have lots of cells 😐

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:33:00+00:00Added an answer on June 17, 2026 at 8:33 am

    OK, let’s deal with the Elephant in the Room. You have a large grid of 3D cells that you’re rendering. You’re making a Minecraft clone; it’s best to be up-front about this.

    What you’re trying to do will in no way be efficient. Using a geometry shader to generate squares/cubes from a single number and gl_PrimitiveIDIn is not an efficient way to render a bunch of cubes. The efficient way to do so is to do what Minecraft does: creates buffer object(s) containing the visible terrain and render that. This will take up more memory, but you’ll be a lot more likely to get reasonable performance out of rendering “lots of cells”.

    If you want to know how to make your current method work, presumably (I have to presume because you didn’t say), your GS takes as its input points​ and converts this into several triangle_strip​ outputs. So each vertex input becomes an output quad/cube.

    This is simple to deal with: use gl_PrimitiveIDIn. Because you’re taking points as input, the primitive count is the same as the vertex count. So if you have a space of 3×3, and gl_PrimitiveIDIn is 4, you know that you’re in the (1, 1) part of that space:

    vec2 spacePos.xy = vec2(mod(gl_PrimitiveIDIn, space.x), (gl_PrimitiveIDIn / space.y));
    

    That’s the XY index where you are in your abstract space. Note that space should be an ivec2 uniform variable somewhere, which defines the number of indices in X and Y you have. The 3D version is slightly more complex, but also doable.

    Once you have your abstract space index, you can compute vertex positions based on that. I’ll assume you know how to do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have been trying to combine the answers of these two questions: C#
I'm trying to keep Visual Studio from attempting to serialize the datasource of drop
I'm trying to keep the list of values from drop-down selections when the browser
I'm trying to experiment with software defined radio concepts. From this article I've tried
I've been trying to interpret the answers to similar questions but haven't been able
I have two tables question and answers. - questions{id,user_id,question,date} - answers {id,q_id,user_id,answer, date} I
In trying to keep with unobtrusive JavaScript guidelines I moved all the JavaScript out
I am trying to keep elements in header in one row. My current styles
I'm trying to keep my code clean and keep the number of files down.
I'm trying to keep my xsl DRY and as a result I wanted to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.