more than 8 lights in jogl

How do i do more than 8 lights in jogl? I’ve heard jogl can only have 8 lights. i’ve looked around, and it says that you need some sort of GLSL shader, and that you can’t do shadows. is this true? and how do i do shadows?

Thanks in advance!

It has nothing to do with JOGL, it is a limitation of OpenGL that you can overcome by the same way. JOGL is only an OpenGL binding. If you want to implement shadows, maybe look at the examples available on the website of JOGL :
http://jogamp.org/

Some engines relying on JOGL might support more than 8 lights, look at how they implement such a feature, for example Ardor3D, JMonkeyEngine, Xith3D, Aviatrix3D, 3DzzD, etc…

dynamic lightmapping sounds good. I can figure out how to generate the lightmaps myself, but how do i apply them to the textures?

I’m not a specialist of lights… You will need this to use your colors or textures as materials if you don’t want to define any material separately:

gl.glEnable(GL.GL_COLOR_MATERIAL);

I don’t know the details of implementation of the dynamic lightmapping.

Lightmapping is just texturing where you fill the texture information with the computed values of your light equations. Most times, lightmapping is used for static light maps because they’re quite slow to compute, especially if you take advantage of using much more complicated light equations to get better looking light maps. Dynamic lightmaps are updated more frequently.

8 lights is the required minimum (and often also the max) number of lights available in the fixed function pipeline. When you use GLSL shaders, you can declare your own variables, so if the hardware is good enough you could have enough variables to store more than 8 lights.

If you really need more than 8 lights, one of the simplest ways to do it is to render the object multiple times, each time with a different set of lights. The extra renderings have to have additive blending enabled so that the end result appears as though it was lit with all 16 lights, etc. This works with shaders and with the fixed function pipeline.

Another technique, that I don’t recommend you start with, but just so that you know about it is to look into deferred rendering.

As far as I know, shadowing can work with any of these mechanisms because you really only need to have shadows from a couple of lights and shadowing is a per-light operation.

Also, it is rare that a single rendered object will need to be lit by more than 8 lights. This is a very rare occurrence in the real world and if it does, often lower numbers of lights can get almost the same appearance. What a lot of engines do is take the 8 most powerful lights in the scene, affecting the current shape to render, render it with those lights and then move to the next object (which has a new set of 8 lights, etc.)

HTH

Opengl can’t render shadows directly. aparrently there IS a way using the stencil buffer. is this better than lightmapping? if so, how do i do this?

The technique that uses the stencil buffer is called shadow volumes, it was what was used in Doom 3. Stencil volumes have the advantage that they always have really nice crisp edges and don’t suffer from aliasing like shadow maps can (if you’ve ever looked at the jagged/blocky shadows in a lot of newer games).

However, this comes with a price to pay. There is a lot of CPU intensive math needed to basically detect the silhouette of the rendered objects from the lights point of view. Then there is a lot of stencil filling which can be really slow. It is also very difficult to do soft shadowing.

Given that it is relatively easy to make soft shadows and reduce the aliasing of shadow maps, and shadow maps scale better with scene complexity, I would recommend pursuing shadow mapping. It seems to be the trend that most game engines are going nowadays, too.

i kind of get how shadow mapping works. my only concern is that multiple renderings would slow down the program. the question is would shadow mapping be simpler than generating lightmaps with java2d, loading them into a texture, then applying it?

Light maps and shadow maps are both used in lighting, but they are really meant for different things. It is certainly possible to store shadow information in your light map, or compute really high quality shadows offline and then map them normally. Quality light mapping basically requires you to implement a ray tracer that runs offline to generate the light values stored in the texture.

That would certainly be slower than generating shadow maps. Also, consider that when generating the shadow map, everything you draw only stores depth values. So no lighting, texturing or complex shaders are executed. Even when using just the fixed pipeline, shadow maps take way less time to render than the colored scene in my experience. Once you do shader-based lighting, shadow maps are going to be even faster in comparison.

know any good sample java tutorials? everything i’ve found is in c++. i’m no good at porting

For that stuff, no. But a lot of C/C++ ports with OpenGL are pretty straight forward on the opengl side, all the calls are the same once you have a window up.

say i use a point light. would i be correct in assuming that to shadowmap a point light i would just map as if it’s 6 directional lights pointing outwards?

Yep, except that it would be 6 spot lights instead of direction lights. Direction light shadow maps usually use an orthogonal projection in the direction of the light. Spot lights are placed at the light and have a perspective projection in the light’s direction with a field of view set for the spread of the light (for 6 spot lights in this situation, I believe it’s 90 degrees).

\facepalm i meant spot lights. but thanks for the tip on directional lights.

do you guys think you could help me figure out how to do shader lighting and shadow maps?

I’d be happy to help with improving things you’ve put together but it takes a fair amountof work to get the full thing working and I don’t have the time that. My recommendation is that you should work first on getting a glsl shaded working that does simple per pixel lighting. Once thats done we can go from there. Alternatively you can go through the code in my signature which can show you the math and workflow to get shadows in the fixed function pipeline.

Or you can just use a 3D engine and save yourself a lot of time.
jMonkeyEngine 3 has both shader lighting and shadow maps, as well as tons of other features.

Engines like that also have mechanisms in place already to handle more than 8 lights. Looking into an engine’s code can be a useful way to learn many things, including the graphics algorithm as well as techniques for code structure, etc. It depends on what you’re looking for: to learn opengl and how 3D really works? or to get a 3D game up and running easily.

I agree with you. It is more pedagogical to use plain OpenGL directly but using a 3D engine like JMonkeyEngine 3 is easier to get something up and running. This engine has an excellent support of JOGL, better than what I did in JMonkeyEngine 2 and it has a fully integrated game development environment.

Ardor3D is a good option too. Some people have already worked in a version using JOGL 2 and when it becomes more reliable, we will be ready to switch to it :slight_smile:

for now, let’s get a shader loaded into JOGL