Get vertex color value after lighting so I can bake?

Started by
5 comments, last by BlackSeeds 15 years, 8 months ago
I'm new to OpenGL and 3D altogether. I'm trying to make my own simple cheap 3D engine. I like what OpenGL lighting does, but my lights won't be moving so all those calculations are wasteful every frame. I've read how OpenGL does these calculations but I was hoping there is a way to grab the color value that OpenGL lighting gives to my vertices and save them so I can bake(?) in my level editor. Am I in luck or do I have to work out my own calculations?
Advertisement
I think your best bet would be to simulate the lightning using your own functions and then apply that values to each vertex's color.
You could for instance download a GLSL shader that does vertex-lightning and simply "steal" that function to do lighting on the CPU. :)

/Robert
"Game Maker For Life, probably never professional thou." =)
AFAIK it's not possible to get back from OpenGL the results of it's calculations, however, you should be able to calculate the values yourself and set them as a vertex colour, which will directly match that of OpenGL, but will be baked into the model.

Are you sure this is what you want?

Having lighting calculated by OpenGL is not a massive wasteful overhead, especially if one day you move onto Shaders.

Personally, unless you feel like reinventing the wheel, I don't see much point in calculating it yourself. You'd be best to just let OpenGL do what it does, and for you to concentrate on making your scene look pretty ;)

Hope this helps
Ay thanks for the insight. I'll mull over it. I thought positively towards baking since my weak computer and my framerate slowed noticeably when I turned a light on.
One benefit would be to allow for unlimited amounts of ambient lighting, since all lights are blended in along with the vertex color.

The biggest drawback is that it's only vertex lightning, and quite frankly - not an eye-pleaser. :)
Lighting-shaders with OpenGL is rather easy, so your best bet would be to use "real" lighting per-pixel instead.

/Robert
"Game Maker For Life, probably never professional thou." =)
I don't know why this wasn't mentioned but instead of computing per vertex color, you should generate lightmaps. That would require some 3rd party tool, like 3D studio max has a feature called backing.

Quote:Having lighting calculated by OpenGL is not a massive wasteful overhead, especially if one day you move onto Shaders.

If he will be doing per pixel lighting, then he might need to do multiple passes, and overall, it does reduce performance. Lightmaps would be faster.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote:Original post by V-man
I don't know why this wasn't mentioned but instead of computing per vertex color, you should generate lightmaps. That would require some 3rd party tool, like 3D studio max has a feature called backing.

Quote:Having lighting calculated by OpenGL is not a massive wasteful overhead, especially if one day you move onto Shaders.

If he will be doing per pixel lighting, then he might need to do multiple passes, and overall, it does reduce performance. Lightmaps would be faster.


Yeah, I am using 3DS Max at the moment to make a map, then texture it and bake in some nice lighting and shadows, it easy to do and the results are nice, I don't intend on using much OpenGL lighting in my game its just a simple engine with most of the work done in the textures. It sounds like your after a similar result to me so I would certainly recommend texture baking to you.

This topic is closed to new replies.

Advertisement