I want to know the triangle ID of each rendered pixel is coming from. Is there a way to do this in OpenGL?
\$\begingroup\$
\$\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\$MickLH– MickLH2017-02-20 21:31:27 +00:00Commented 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\$user109352– user1093522017-02-20 21:34:43 +00:00Commented 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\$MickLH– MickLH2017-02-20 21:36:43 +00:00Commented 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\$ratchet freak– ratchet freak2017-02-21 09:05:49 +00:00Commented Feb 21, 2017 at 9:05
Add a comment
|
1 Answer
\$\begingroup\$
\$\endgroup\$
1
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.
-
\$\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\$Pikalek– Pikalek2018-08-06 23:49:49 +00:00Commented Aug 6, 2018 at 23:49