Cero
JGO Neuromancer     Posts: 1050 Medals: 18
|
 |
«
on:
2009-03-29 10: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
« League of Dukes » JGO Kernel      Posts: 5214 Medals: 49
Mentally unstable, best avoided.
|
 |
«
Reply #1 on:
2009-03-29 11: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
JGO Kernel      Posts: 2960 Medals: 37
Monkey for a head
|
 |
«
Reply #2 on:
2009-03-29 13: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! Go get 'em!
|
|
Cero
JGO Neuromancer     Posts: 1050 Medals: 18
|
 |
«
Reply #3 on:
2009-03-29 17: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
Jr. Member   Posts: 85
|
 |
«
Reply #4 on:
2009-03-30 02: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
JGO Kernel      Posts: 2960 Medals: 37
Monkey for a head
|
 |
«
Reply #5 on:
2009-03-30 03: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
JGO Neuromancer     Posts: 1050 Medals: 18
|
 |
«
Reply #6 on:
2009-03-30 04: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
« League of Dukes » JGO Kernel      Posts: 2360 Medals: 59
★★★★★
|
 |
«
Reply #7 on:
2009-03-30 04: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! Go get 'em!
|
|
zammbi
JGO Strike Force    Posts: 963 Medals: 9
|
 |
«
Reply #10 on:
2009-03-30 08:02:47 » |
|
Where's more info about this library? I couldn't find much by searching for it...
|
|
|
|
|
|
skinny boy
Jr. Member   Posts: 85
|
 |
«
Reply #12 on:
2009-09-25 19: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
JGO n00b  Posts: 5
|
 |
«
Reply #13 on:
2009-09-26 02: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
JGO Kernel      Posts: 1866 Medals: 5
falling into the abyss of reality
|
 |
«
Reply #14 on:
2009-09-26 05: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
Jr. Member   Posts: 85
|
 |
«
Reply #15 on:
2009-09-26 08: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
JGO Kernel      Posts: 1866 Medals: 5
falling into the abyss of reality
|
 |
«
Reply #16 on:
2009-09-26 13: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
Jr. Member   Posts: 85
|
 |
«
Reply #17 on:
2009-09-27 11:43:40 » |
|
thank you very much for your reply and links
|
|
|
|
|
Cero
JGO Neuromancer     Posts: 1050 Medals: 18
|
 |
«
Reply #18 on:
2009-09-27 17: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
Jr. Member   Posts: 85
|
 |
«
Reply #19 on:
2009-09-28 09: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
Sr. Member   Posts: 300
2D Java games forever!
|
 |
«
Reply #20 on:
2009-09-28 11: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
JGO Kernel      Posts: 1645 Medals: 4
|
 |
«
Reply #21 on:
2009-09-28 14:46:25 » |
|
hey rdcarvallo, you wouldnt happen to mind sending me/ posting the source code for that would you?
|
|
|
|
|
skinny boy
Jr. Member   Posts: 85
|
 |
«
Reply #22 on:
2009-09-28 19: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
Sr. Member   Posts: 300
2D Java games forever!
|
 |
«
Reply #23 on:
2009-09-29 02: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
JGO Kernel      Posts: 1645 Medals: 4
|
 |
«
Reply #24 on:
2009-09-29 07:19:15 » |
|
It freezes right away:P
windows XP
|
|
|
|
|
skinny boy
Jr. Member   Posts: 85
|
 |
«
Reply #25 on:
2009-09-29 09:48:05 » |
|
same here, windows XP also
the JVM doesnt even start (the small java icon at the bottom right of the screen..)
|
|
|
|
|
rdcarvallo
Sr. Member   Posts: 300
2D Java games forever!
|
 |
«
Reply #26 on:
2009-09-29 10: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
JGO Kernel      Posts: 1645 Medals: 4
|
 |
«
Reply #27 on:
2009-09-29 10:54:40 » |
|
that wont help, i have 1.6.
the problem is that the main screen appears, but then I get stuck there....
|
|
|
|
|
Hansdampf
Sr. Member   Posts: 412 Medals: 2
too offending?
|
 |
«
Reply #28 on:
2009-09-29 10:56:45 » |
|
the secret is to press s !!!
|
|
|
|
rdcarvallo
Sr. Member   Posts: 300
2D Java games forever!
|
 |
«
Reply #29 on:
2009-09-29 12:23:15 » |
|
Ha... Press "S" to start  , thanks Hansdampf!!
|
|
|
|
|
|