PDA

View Full Version : How to get vertex color ?



alexnai
11-18-2015, 06:47 AM
I'm looking for some simple method to get color of a given vertex without reading
pixels. I mean, color of a vertex in smooth shading that take into account all light sources and material properties.

Alfonse Reinheart
11-18-2015, 07:35 AM
Well, there isn't one (in general). Information in OpenGL flows in one direction: from the user to the screen, in accord with the OpenGL rendering pipeline (https://www.opengl.org/wiki/Rendering_Pipeline_Overview). You can't interrupt this process and have OpenGL spit out some arbitrary values for you.

To be fair, via image load/store, SSBOs or transform feedback, you can coerce OpenGL into spitting out data of various kinds. But none of these are a "simple method"; they require shader logic. Well, except for TF, which can work in the fixed-function pipeline. That would probably be your best bet, but even then, it's hardly "simple".

GClements
11-18-2015, 11:47 AM
I'm looking for some simple method to get color of a given vertex without reading
pixels. I mean, color of a vertex in smooth shading that take into account all light sources and material properties.

If you're using the fixed-function pipeline, you can use glRenderMode(GL_FEEDBACK). Note that this applies after culling; no data will be returned for culled polygons. Polygons and quads may be decomposed to triangles.

The modern equivalent is transform-feedback mode (glBeginTransformFeedback() etc).

alexnai
11-19-2015, 05:17 AM
Thanks for replies ! I see, it isn't so simple as I thought.

I'll try GL_FEEDBACK, but probably, it will be easier to compute vertex colors by myself.
So another related question: How can I get all the relevant data about the lighting ( position of all light sources and their parameters ) ?

carsten neumann
11-19-2015, 07:30 AM
In theory you should now them, because your application has to set them at some point. To query them from OpenGL you can use glGetLight (https://www.opengl.org/sdk/docs/man2/xhtml/glGetLight.xml). Lighting normally operates on the colors specified by the current material (query settings with glGetMaterial (https://www.opengl.org/sdk/docs/man2/xhtml/glGetMaterial.xml)), unless you enable GL_COLOR_MATERIAL to make use of the per-vertex color instead (see glColorMaterial (https://www.opengl.org/sdk/docs/man2/xhtml/glColorMaterial.xml)).

In any case recreating the entire lighting calculations (especially if you need them to be correct for all kinds of state combinations) is also quite some work, although the formulae are all documented. Perhaps there is a different way to do what you want?