Note: You must be registered in order to post a reply.
|
EACam |
Posted - Apr 24 2004 : 09:21:23 AM Well...seing as Lucky's forum is having issues...I'll just post here for a while .
I had this same question on lucky's forum...but with little informative feedback...so now i'll try again considering i've done a bit more...
I tried to adapt the "introduction to lighting" tutorial by Jack Hoxley for DX8 (at DirectX4VB obviously) to work with my 2D game. So far I've been able to:
Apply the geometry to my vertices using an UNLIT vertex format. Set the ambient light color Add a light (i'm currently only adding a directional light) Enable the light Eenble DX8's lighting engine Set the vertex shader to the unlit vertex format
and what do i get????
A BIG BLACK SCREEN!!!
I have a few things that aren't using the unlit vertices...so I set the vertex shader to FVF_UNLIT...draw the tiles which use unlit vertices (and yes...i've supposedly set their normals to the correct thing...0,0,1 as i think it should be for 2D). Then I switch the vertex shader back to FVF_LIT and draw the rest of my stuff which is showing up fine...
I have a background surface (not texture) and at one point I could actually see black tiles rotating on that surface. I thought it was because the lights weren't working that the tiles were black. I realized I had forgotten to set the vertex shader to FVF_UNLIT before drawing those...so now i've done that and I don't see ANYTHING.
Any help??? Normals are confusing me to death.
Does anyone have any sample code i could look at for lighting in 2D (NOT 3D!!!!)?
Thanks a bunch.
|
EACam |
Posted - May 02 2004 : 8:37:42 PM Spodi, this example will work ONLY with how it's set up. I've tried changing the range and things get messed up, but the principle is the same...kind of.
I basically did this:
Range = 200
TileGeom(0).Color = D3DColorRGBA(Range - DistanceBetweenLightAndThisVertex, Range - Distance...., ...., 255) ' Notice, the 255 is the alpha value, so it's opaque. This doesn't work with colored lights or anything. It doesn't have customizable attenuation, but it works. TileGeom(1).Color = ... ...for all four vertices.
This is a bad example here, because you have to do something else. You have to have a variable that holds the color because you need to check if it's negative. If it is, just make it 0.
Now, my tiles are 32x32. They were all rotating CC in my test app, and everything looked fine. When I increased the range, I got dark splotches in the middle of the light area. When I decreased the light range, the whole thing got dimmer. I'll work on this and pop a post when its fixed up.
Note, this is TOTALLY UNOPTIMIZED. I did this calculation to ALL of the tiles on the screen, not just those within range like I should have. This only works with ONE light. So basically, this is a pretty lame example, but it was perfectly circular.
Sorry this is so confusing...I'll try to fix it up and post my results. |
SuperC |
Posted - May 02 2004 : 2:07:59 PM This might help
http://www.eastcoastgames.com/articles/2dlight.htm |
Spodi |
Posted - May 02 2004 : 1:59:27 PM Hmm, well I'll try doing it again. Do you think you can send me what you got though for reference? |
EACam |
Posted - May 01 2004 : 6:36:34 PM I did some testing; lighting in 2D [using my method, anyway] works like a charm, with a little optimization it'll be working like Sampson at the treadmill. And Spodi, I don't get the slightest hint of a triangle. It's PERFECTLY attenuated and circular. |
cjb0087 |
Posted - May 01 2004 : 12:10:30 AM you could probably check the inline asm thingo at persistant realities, i *think* there is a squareroot function there |
EACam |
Posted - Apr 29 2004 : 12:26:03 PM Shadows? Sure, that would be a cinch...if I make them look kind of cheap. I would simply loop through that box from the inside out and stop when I get to a barrier (that is, stop for that direction only). It would work, kind of...I'll have to develop it tho, so far this is all theoretical.
Aw, the square root function isn't THAT slow, is it? For the example I gave a while ago, that would be, hmmm, let's see here...area = 7x7 = 49, so 49 tiles to possibly go through, then 49x4 since there are 4 vertices in each tile...that's 196 Sqr operations for one, kinda small light. Ok, so maybe I should try optimizing it somehow. Perhaps in my level editor I could make certain lights be precalculated. Then for the moving ones (i'll have enough of those), i'll do it during run-time. |
Eric Coleman |
Posted - Apr 29 2004 : 09:08:41 AM Are there going to be shadows in the game? |
cjb0087 |
Posted - Apr 29 2004 : 04:58:33 AM but that would require the deadly square root function, because a=sqr(b*b+c*c) (a*a is faster than a^2), if the light is stationary maybe you could calculate the verticies at load time? |
Spodi |
Posted - Apr 28 2004 : 8:55:41 PM OOooooooooooohhhh, okay, that makes sense, thanks. And yeah, I dont think it's "hypotineus", wouldn't trust my spelling. :) |
VBBR |
Posted - Apr 28 2004 : 5:55:24 PM You can use it to calculate the distance between two points by using the x,y coordinates as two of the sides of the triangle and the "hypotineus" (if it's spelled that way) for the distance. |
Spodi |
Posted - Apr 28 2004 : 5:47:06 PM "using pythagoras' good old theorem"
Just wondering, how would "A^2 + B^2 = C^2" help? Isn't this to calculate the hypotineus (or slanty-thingy) of a triangle? |
VBBR |
Posted - Apr 28 2004 : 11:04:43 AM quote: "light it according to its distance" is easier said then done
I think it's not that hard. you just calculate the distance between the center and the desired point, and then make some calculations. Check this out:
http://216.5.163.53/DirectX4VB/Tutorials/GeneralVB/GM_Lighting.asp |
EACam |
Posted - Apr 28 2004 : 09:08:31 AM It should, and i'm almost positive it will. I think your method may be what's causing that. I'm going to do this:
Say, again, the light is O. Now say it has a range of 100. Well, considering my tiles are 32x32, it's range will extend to 4 tiles (1/32=3.1, and remember, if it's even 0.0000001 more than a number, it'll be rounded UP to the next one, since the next tile WILL get SOME lighting.) Ok, so in memory it'll look like this:
XXXXXXX XXXXXXX XXXXXXX XXXOXXX XXXXXXX XXXXXXX XXXXXXX
To ensure ALL lighting is applied, I make sure that the full length is considered in all four cardinal directions (up, down, left, right). Notice the radius is 3, but the diameter is actually 7 (2x3 + 1) because the light takes up one tile, this isn't exactly how it'll look, but text limits what I can draw . Now, some of tiles in the corners of this box will receive NO lighting, but that's ok. So from here, I simply loop through every vertex of every tile in this box and light it according to its distance from the light using pythagoras' good old theorem. This is the hard part, because "light it according to its distance" is easier said then done. But with a little trial and error, i'll get it looking fine...
I hope. |
Spodi |
Posted - Apr 27 2004 : 6:37:44 PM Okay, yeah, it should be possible to do point lights. Though, I've always had a problem with the lighting - it always looks more like a diamond then a triangle. Say you have this for example (each X represents a tile, the O represents the light origin.)
XXX XOX XXX
Okay, so if the middle tile has full lighting (255 argb) then the point(s) of the other tiles that point at the middle have full lighting and the outside points have, lets say 200, it will look like a diamond more then anything. I mainly ran into this problem when trying to apply Fog to DXRE (4 textures, each 1/4 of the screen, using same method as above, ended up looking like CRAP). Theoretically, this should make a circle, or close, right? |
EACam |
Posted - Apr 27 2004 : 08:50:05 AM did i say spot? I totally meant point |
|
|
VBGamer |
© |
|
|
|
|