Cero
|
 |
«
Posted
2009-03-29 14:34:22 » |
|
We are talking about a platformer here, imagine Castlevania.
And what I would like to create is Lightning that is really realistic and reflective. I mean a room, there is a lightsource, objects in the room are lightend the way the should.
If you create just a tile based game, there is not much lightning... but if you were to insert lightsources and stuff like that.
imagine even a broken lamp that flickers. that would really increase authentic and atmosphere
Was something like that ever done / is there even a game like that ? how would you do it ? are there "tricks" ?
|
|
|
|
kevglass
|
 |
«
Reply #1 - Posted
2009-03-29 15:04:57 » |
|
Depends on your technology, however I've found calculating vertex colours of the tiles when using OpenGL how some great effects.  Kev
|
|
|
|
Orangy Tang
|
 |
«
Reply #2 - Posted
2009-03-29 17:01:02 » |
|
I do per-pixel lighting in Rescue Squad 2. Basically there's three passes, first a full bright pass consisting of the visible sprites:  Then there's a lightmap pass where sprites and other light geometry are drawn to:  Both of those are captured to a texture, and the final pass just multiplies the two together:  The nice thing about this is that lights can be any shape (like the search light's cone of light) and quite detailed, since really they're just another sprite. And it works on pretty much any pc hardware too.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Cero
|
 |
«
Reply #3 - Posted
2009-03-29 21:52:06 » |
|
ya but how do you subtract darkness from the lightning map
I mean, most likely you would do it kinda professional =D I would take a black color with an alpha value which is overall very high, and very low at lightsources
which means, since I'm using Java2D Graphics.setColor and fill methods only problem is that I cant render a square which a oval round which is empty =P and I dont even wanna think about reflection in this regard
|
|
|
|
mh114
|
 |
«
Reply #4 - Posted
2009-03-30 06:18:14 » |
|
ya but how do you subtract darkness from the lightning map
I mean, most likely you would do it kinda professional =D I would take a black color with an alpha value which is overall very high, and very low at lightsources
which means, since I'm using Java2D Graphics.setColor and fill methods only problem is that I cant render a square which a oval round which is empty =P and I dont even wanna think about reflection in this regard
But you don't have to.  If you do it like Orangy Tang explained, you can additively combine lights on top of an ambient light, and finally multiply the whole shebang with the unlit scene. You also get colored lights for free with this technique, unlike when you subtract alpha from black.
|
|
|
|
Orangy Tang
|
 |
«
Reply #5 - Posted
2009-03-30 07:28:35 » |
|
Although if you're stuck with Java2d then that's an entirely different kettle of fish - I doubt that method would run fast enough (although I'd be interested in seeing how fast it does run). If you're stuck with j2d, then your best bet is to do the lighting manually per-pixel in a big working buffer - I believe L4kD does this so you might want to poke around the source for that. But you'll probably be limited to quite low resolutions with that method.
|
|
|
|
Cero
|
 |
«
Reply #6 - Posted
2009-03-30 08:50:05 » |
|
I just looked into L4kD
seems awfully tedious to do in j2D Overall I'm not that good of a programmer to do it like he did.
How difficult / how much is it to "convert" a j2d game in JOGL or slick or whatever you guys would suggest ? I mean of course that depends on my game, but afterall its just the rendering processes which isnt as much
|
|
|
|
kappa
|
 |
«
Reply #7 - Posted
2009-03-30 08:58:17 » |
|
Its probably pretty quick to convert to slick since the api is very similar to java2d. However if you decide to use JOGL or LWJGL you'll have to use the opengl api which will take longer to convert too.
|
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
zammbi
|
 |
«
Reply #10 - Posted
2009-03-30 12:02:47 » |
|
Where's more info about this library? I couldn't find much by searching for it...
|
|
|
|
|
skinny boy
|
 |
«
Reply #12 - Posted
2009-09-25 23:48:03 » |
|
I do per-pixel lighting in Rescue Squad 2. Basically there's three passes, first a full bright pass consisting of the visible sprites: Then there's a lightmap pass where sprites and other light geometry are drawn to: Both of those are captured to a texture, and the final pass just multiplies the two together: The nice thing about this is that lights can be any shape (like the search light's cone of light) and quite detailed, since really they're just another sprite. And it works on pretty much any pc hardware too. why cant this multiply be done in j2d?? without considering the performance can someone plz give me a hint or link to the math behind this (pixel by pixel) multiplication?? thank you in advance
|
|
|
|
terloon
Junior Newbie
|
 |
«
Reply #13 - Posted
2009-09-26 06:54:45 » |
|
I'm actually trying to create that affect. =) But, I'm not in that part of my development yet. I've always enjoyed the retro look of sprites, and I wanted to meld this with realistic lighting and shadow affects.
|
gamecodemonkey.blogspot.com towerofinfinity.blogspot.com
|
|
|
Abuse
|
 |
«
Reply #14 - Posted
2009-09-26 09:51:40 » |
|
why cant this multiply be done in j2d?? without considering the performance can someone plz give me a hint or link to the math behind this (pixel by pixel) multiplication??
thank you in advance
The j2d api only* provides out-of-the-box functionality for compositing using the alpha channel, not for colour compositing. You can easily implement your own custom ColorComposite**, but it obviously won't be hw accelerated, so will be all-but useless in relation to performance. I'm sure there is an RFE somewhere in the bug database on the subject, as its absence significantly restricts the usefulness of j2d for many interesting effects. (* Technically there is one color composite operation supported; XOR mode. It's a legacy bit of functionality from the early days of Java; it doesn't use the more modern Composite interface. Also I remember reading somewhere that it doesn't work [very well/at all] in the hw pipeline.) ( ** Though you also need to be aware you will run into all sorts of problems with custom composites if you try and use them when drawing onto a VolatileImage or BufferStrategy.)
|
|
|
|
skinny boy
|
 |
«
Reply #15 - Posted
2009-09-26 12:32:10 » |
|
ok, so i wont use it in a game,,
but i asked "without considering the performance, can someone give me a hint or link or something about the math involved in this type of ColorComposition?"
i mean, does it just uses the src and dest pixel and " +" , or "*", or some binary operator, or.... ?
thank you
|
|
|
|
Abuse
|
 |
«
Reply #16 - Posted
2009-09-26 17:34:43 » |
|
ok, so i wont use it in a game,,
but i asked "without considering the performance, can someone give me a hint or link or something about the math involved in this type of ColorComposition?"
i mean, does it just uses the src and dest pixel and " +" , or "*", or some binary operator, or.... ?
thank you
Each channel of each pixel in the source is multiplied with the corresponding channel of each pixel in the destination, and the result is placed in the destination. i.e. Color resultant = (R src*R dst,G src*G dst,B src*B dst) A quick google found this, which in turn pointed to thisbtw, I guess everybody has noticed but been too polite to mention the mistake in the original question? Realistic Lightning in a 2D game The two are very different problems =) (though not entirely unrelated!)
|
|
|
|
skinny boy
|
 |
«
Reply #17 - Posted
2009-09-27 15:43:40 » |
|
thank you very much for your reply and links
|
|
|
|
Cero
|
 |
«
Reply #18 - Posted
2009-09-27 21:06:11 » |
|
btw, I guess everybody has noticed but been too polite to mention the mistake in the original question? The two are very different problems =) (though not entirely unrelated!)
I guess nobody noticed. Fixed. @ Topic, this is all above my head at this point.
|
|
|
|
skinny boy
|
 |
«
Reply #19 - Posted
2009-09-28 13:58:57 » |
|
Colorresultant = (Rsrc*Rdst,Gsrc*Gdst,Bsrc*Bdst)
if the values are float, then i suppose this works, (with a step of "1.0 (minus) "final result" " perhaps?) if the values of the three channels are integers, i cant seem to work it out for example, a light red, value70, and the light source with value 200. multiplying them, the final result is out of the permitted range [0,255], so i guess there are two options: the multiplication is a logical AND or the programmer decides upon the ratio of the two values (destination, light), perhaps 3/7 meaning that the destination number will be multiplied by 0.3 and the light number by 0.7, bigger values for the destination mean that the difference between illuminated areas and non-illuminated will be smaller... i believe i should make a code example to prove it (to myself mainly, and to all who are interested secondly)... damned university, taking all of my sober time away...
|
|
|
|
rdcarvallo
|
 |
«
Reply #20 - Posted
2009-09-28 15:49:09 » |
|
I did some flashlight effect in J2D for my unfinished entry at LD48. In pseudo code: 1 2 3 4 5
| define cone of light; use cone for clipping; draw scene; define gradient (transparente to black) in the direction of light paint the cone with the gradient; |
The result is something like this image:  Then I added the same logic for a square around the player, and some options to control the ligh focus(distance v/s spread) getting this:   Don't know how is the performace in old machines or old JVM, but in my PC (athlon 64 3000Mhz, 1GB DDR2, nVidia7600GS 256 MB, jdk1.6_XX) it works fine.
|
|
|
|
h3ckboy
|
 |
«
Reply #21 - Posted
2009-09-28 18:46:25 » |
|
hey rdcarvallo, you wouldnt happen to mind sending me/ posting the source code for that would you?
|
|
|
|
skinny boy
|
 |
«
Reply #22 - Posted
2009-09-28 23:29:09 » |
|
1 2 3 4 5
| define cone of light; use cone for clipping; draw scene; define gradient (transparente to black) in the direction of light paint the cone with the gradient; |
thank you for the algorithm
|
|
|
|
rdcarvallo
|
 |
«
Reply #23 - Posted
2009-09-29 06:04:19 » |
|
Here goes the code: 1 2 3 4 5 6 7 8 9 10 11 12 13
|
Arc2D.Double arc = new Arc2D.Double(); arc.setArcByCenter(p.getLightX(), p.getLightY(), radius, p.getAngle()-spread, 2*spread, Arc2D.PIE); GradientPaint gp = new GradientPaint(p.getLightX(),p.getLightY(),new Color(0,0,0,0), p.getLightX()+radius*(float)Math.cos(Math.toRadians(p.getAngle())),p.getLightY()-radius*(float)Math.sin(Math.toRadians(p.getAngle())),new Color(0,0,0)); g2.clip(arc); map.drawTo(g2); g2.setPaint(gp); g2.fill(arc); g2.draw(arc); g2.setClip(null);
|
And the Demo, could you post how it runs on your machines? http://www.demegames.cl/demos/Journey08.jarControls: LEFT, RIGHT: walk UP, DOWN: flashlight angle Z, X: flashlight focus A: Run S: Jump Space: Pause/MiniMap
|
|
|
|
h3ckboy
|
 |
«
Reply #24 - Posted
2009-09-29 11:19:15 » |
|
It freezes right away:P
windows XP
|
|
|
|
skinny boy
|
 |
«
Reply #25 - Posted
2009-09-29 13:48:05 » |
|
same here, windows XP also
the JVM doesnt even start (the small java icon at the bottom right of the screen..)
|
|
|
|
rdcarvallo
|
 |
«
Reply #26 - Posted
2009-09-29 14:42:58 » |
|
Strange... I tested in my home (WinXP SP2, JDK1.6_XX).
I'll recompile for 1.4 and upload again later, now I'm at work.
|
|
|
|
h3ckboy
|
 |
«
Reply #27 - Posted
2009-09-29 14:54:40 » |
|
that wont help, i have 1.6.
the problem is that the main screen appears, but then I get stuck there....
|
|
|
|
Hansdampf
|
 |
«
Reply #28 - Posted
2009-09-29 14:56:45 » |
|
the secret is to press s !!!
|
|
|
|
rdcarvallo
|
 |
«
Reply #29 - Posted
2009-09-29 16:23:15 » |
|
Ha... Press "S" to start  , thanks Hansdampf!!
|
|
|
|
|