This is the scenario:
- Sun comes up and creates light.
- Light is very bright at source but loses it’s intensity over a distance.
I’ve been experimenting with gradient hacks and they are ugly.
Are there any other solutions to this?
This is the scenario:
I’ve been experimenting with gradient hacks and they are ugly.
Are there any other solutions to this?
light has a 1/r attenuation function, hence you could try a 1/r gradient function, but you’d have to do it by hand IIRC (j2d not offering fn-controlled grads?).
If you want to get really accurate, do some calculations based upon: stick two points inside a circle and draw lines that go from one point to the edge of the circle, then bounce directly towards the other line. The angle of each bounce at the circle perimeter is proportional to the intensity that the observer gets from looking in that direction - this is how sunlight in the sky actually works, and is why the sky changes colour in a gradient, although that’s something of a gross simplification.
Sorry that off the top of my head first thing in the morning I can’t remember what fn that will give you, but you could probably JFGoogleFI.
1/dist is more physically correct for light fall off, but in practice tends to not look realistic (because generally you don’t have proper global illumination, just direct) and generate far too large light bounds. Linear fall off tends to look more realistic (at least in a 3d game) and is easier to control.
A nice compromise if linear is not suitable is to use distance squared.
Thanks guys.
Although what I’m trying to do is get lighting working on my scene.
I’ve been sifting through a lot of online tutorials and Sun’s code samples and it is very difficult to come across any explanations about how to apply lighting on a 2D scene.
A few tutorials were showing the differences between colour spaces, so I figure I would have to create my own color space to get a high dynamic range of RGB values so I can light up my scene.
I read it and it’s pretty much the same as most of the articles I’ve read so far.
This wouldn’t be such a pain in the butt if I was using OGL.
Unfortunately try applying the same effects in your article to J2D.
You will find a lot of error and much more difficult.
For one, I had made a “light” by creating 10 ellipses, darkest colour has the largest radius, and keep decrementing radius and increase brightness until you get something.
It looks banded and doesn’t have a noticeable range in colour.
I would like my scene to be blindingly bright, I’ve read through articles explaining different colour spaces and in the end they didn’t give me all that much more oomph that RGB has given me.
If you want good quality lighting that means doing it per-pixel. Unfortunalty that means doing practically everything manually if you’re using Java2d - it really isn’t cut out for this kind of thing. Basically I’d say you’ve got a few choices:
Use pre-lit tiles and change which tiles you use based on light positions. Should be fast with Java2d but doesnt give great quality, eg. http://rainbow.cs.unipi.gr/~cybernoid/artwork/tiberian/tiberian1.jpg
Do everything manually and just copy that to screen when finished. At a low res and with pallette magic you could probably get a decent speed
Switch to LWJGL and get lots of fast per-pixel magic for free. ;D
I figured that was the worst case scenario. :-/
Thanks for that.
I guess I’ll just stick to my light hack with ellipses.