Sign in to follow this  
JSLemming

OpenGL Get vertex color value after lighting so I can bake?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this