2
\$\begingroup\$

I want to know the triangle ID of each rendered pixel is coming from. Is there a way to do this in OpenGL?

\$\endgroup\$
4
  • \$\begingroup\$ Yeah, it's called picking. Are you using modern GL or legacy GL? How big are your IDs? What have you tried? \$\endgroup\$ Commented Feb 20, 2017 at 21:31
  • \$\begingroup\$ I'm using modern opengl, my IDs can get up to millions. I'm in the process of trying gl_primitiveID. \$\endgroup\$ Commented Feb 20, 2017 at 21:34
  • \$\begingroup\$ Ok just bind an integer texture to an FBO, disable all the fancy stuff like blending and shading, and output the primitive ID to the color buffer that has the integer texture bound. I'm too lazy to write a full answer right now. \$\endgroup\$ Commented Feb 20, 2017 at 21:36
  • \$\begingroup\$ create a mapping from triangle ID to color, there are 16 million unique colors to pick from in a 24 bit RGB texture format. \$\endgroup\$ Commented Feb 21, 2017 at 9:05

1 Answer 1

3
\$\begingroup\$

If you are using glsl version 410 or higher, you can use

gl_PrimitiveID

to get a triangle id per pixel on fragment shader. Hope this helps.

\$\endgroup\$
1
  • \$\begingroup\$ Glad to hear that you found a solution! Don't forget to mark it as accepted - it helps others who may run into the same or similar problems. \$\endgroup\$ Commented Aug 6, 2018 at 23:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.