|
Realtime Lighting |
Mallie
Member #8,742
June 2007
|
My engine is perfect so far, and I want to take it another step up. I was wondering what anyone knows about lighting, be it approaches to doing so, Like if you're walking round in an RPG, or something, to enter a room, turn on a light or be in a cae and walk by a torch etc and get at least the basic effects. I have some things in mind for simple stuff, but I'd really like more input on such things if anyone has some. |
Jonatan Hedborg
Member #4,886
July 2004
|
2d - Top down/isometric? 3d?
|
Mallie
Member #8,742
June 2007
|
it's all 2D. I'm not good enough at math to do 3D, unfortunately. |
Jonatan Hedborg
Member #4,886
July 2004
|
mostly, yes. There are a few different ways to do it. You can render a "light blob" (gradient in the shape of your light, in the color of your light) with multiplicative blending or additive blending. Or, you could render tiles with gouraud shading (for 2d top-down). In any event, you will probably need to use fblend or openlayer if you want decent performance.
|
Mallie
Member #8,742
June 2007
|
yeah thats what I use. I've done some amazing things with it. OpenLayer's really nice. ^^ yes, yes, I see.....I could make different shapes, and just size and place them appropriately. How would I do it for saay...an animated torchlight, so that the flickering flame has effect on the lighting as well? perhaps just use the animation itself (expanded to light distance size) as the light source itself? hmm...that might not be right, just thinking off the top of my head here. ^^;;; |
HardTranceFan
Member #7,317
June 2006
|
Quote: perhaps just use the animation itself (expanded to light distance size) as the light source itself? Use a different 'light blob' for each flame animation frame? -- |
Mallie
Member #8,742
June 2007
|
yeah, that might work! ^^ Do they have to be made at run time, or can I have preset shapes in a datafile as well?? I have another idea.... If one was to enter a dark house, isn't it wierd if turing on the light makes only this round light source and the rest of the room stays dark. I was thinking of doing does that sound correct? I'm still only guessing a bit here. I'm trying to find ways of making it a bit more lifelike. maybe I need to do shadows as well?? |
Audric
Member #907
January 2001
|
The game "The Project 2" uses a general light level for each level (it currently does not change during play, but it could), somewhere between full dark and full light. At the beginning of each redraw, it blits a solid rectangle of this light on a screen-sized bitmap. Then this layer is blit on the actual game screen, again in additive/multiply mode. -- Shadows are often not computed together with lights, because generally you want lights 'over' sprites and background, and shadows between the sprites and background. |
Mallie
Member #8,742
June 2007
|
Ahh, ok. well I can give all these things a try. How would I blit in Multiply mode? Openlayer seems not to have such an option in it's blenders... |
CursedTyrant
Member #7,080
April 2006
|
I remember I made a thread about it a long time ago. You can search for it, if you want. Here's a game I never finished, which is using dynamic shadows and lighting: http://www.allegro.cc/forums/thread/586618 --------- |
Mallie
Member #8,742
June 2007
|
heheh, pretty cool! I had a good ol' time making things blow up with that G key. I looked at the shadow code. I really like how the light from the explosion thingie goes around walls. thats the part I didn't know how to do. I have such a hard time understanding other people's code tho. x.x Mainly cuz I usually work beast in my head. I just come up with these designs, and I know just what I'm doing, but when I have to read stuff someone else wrote and really think about it alot, it's a little harder. I kinda got lost at the math stuff. I really suck at that. Were ya creating the light poly's in realtime? cuz I was just using preset shapes in a datafile because I'm not very good at it otherwise yet. |
Fladimir da Gorf
Member #1,565
October 2001
|
There's no multiply mode, but subtractive mode comes close. Also, Blenders::Set( GL_ZERO, GL_ONE_MINUS_SRC_COLOR ) might work as a multiplicative blender... OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Mallie
Member #8,742
June 2007
|
Ok, I'll give that a try! ^^ Btw, how does multiply mode work/is used for as opposed to using additive? |
Fladimir da Gorf
Member #1,565
October 2001
|
In multiply mode, for each color component of every pixel: result = (1.0 - srcComp) * dstComp; (src is the image you're rendering and dst is the surface (screen)) The first parameter of Blenders::Set is the src factor and the second parameter is the dest factor. Now Blenders::Set(GL_ZERO, GL_ONE_MINUS_SRC_COLOR) should be: result = 0 * srcComp + (1.0 - srcComp) * dstComp; which is the same as the multiplicative blender. Did that make any sense? By the way, you asked if OpenLayer can do page flipping. In fact it can't do anything else since everything happens in the video card (double buffering in video card is called page flipping) OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Mallie
Member #8,742
June 2007
|
Ahh, I think I get it, yes. ^^ Oh yeah! I kinda thought that myself, that it was already doing what it needed to. Wow, I really thank everyone for the input so far! I'll give people a look at my....very interesting...game engine when I'm ready with it. |
Fladimir da Gorf
Member #1,565
October 2001
|
Multiply blender is used to darken the areas that don't have much light. Additive blending, on the other hand, is used to lit areas that have an excessive amount of light. Which one you want to use depends on what you want to get. OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Jonatan Hedborg
Member #4,886
July 2004
|
the "perfect" solution would be to render all lights using additive blending to a "buffer" (not sure how this would be done, if at all possible, in openlayer), which you then render onto the screen in multiply mode. This way you would create all your sprites as if they were 100% lit and they would come out fine (anything not covered by a light would be suitably darker). If you use just additive on the other hand, everything will be very "washed out" and there will be no "unlit" areas - only "lit" and "superbright" One option would be to create sprites at, say, 50% illumination. It might be a suitable middle ground if it's not possible to do the first option, even though you lose some details (i think).
|
Fladimir da Gorf
Member #1,565
October 2001
|
Using Canvas or copying the contents of the back buffer to a Bitmap would work, but would also have a slight performance penalty. OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Mallie
Member #8,742
June 2007
|
That sounds very interesting! Hmm...well, actually, what I was going to do was something very similar, but For some odd reason, using more than one Canvas always renders garbage to the screen for me. Do I set Canvas to a buffer bitmap, do my blitting and then refresh that one? am I doing it wrong? |
Jonatan Hedborg
Member #4,886
July 2004
|
I took the liberty of trying this out myself (yes, I am aware there is no error checking/handling).
It works. You will need a png, preferably the same size as the window (800*600). I used a beach
|
Mallie
Member #8,742
June 2007
|
I tried the code in my game engine. It was really neat! ^^ How do I make it so I can control that black so that I can adjust it to the general light level of the screen? (btw, not telling it to Fill() it made for some neat and funny fx. ) |
Jonatan Hedborg
Member #4,886
July 2004
|
Yeah, change the lightmap Fill to some other color to have an "ambient light".
|
Mallie
Member #8,742
June 2007
|
Yup, that worked! Looks like everything is working fine now. I think I'm ready to fully implement the lighting. Thanks very much to everyone who helped! |
Paul whoknows
Member #5,081
September 2004
|
Any screenshots?:) ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
Mallie
Member #8,742
June 2007
|
Well, I guess I can show this engine's work in screenshots or a download or something. I still need to finish up a few things before I do so though. But I can at least state it's features here: hires hand drawn 2D graphics (1280x1024 screen) Hopefully a demo will be available soon. Probably at least a screenshot or two in the next couple of days, for demo it's hard to say; I don't know when the editor will be finished. I really need to get that all done to make more progress on it. |
|