Author Topic: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test  (Read 4821 times)

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« on: March 29, 2011, 06:36:20 pm »
Original: http://christophermpark.blogspot.com/2011/03/valley-without-wind-pre-alpha-8-new.html



This video is just a simple lighting test showing off our new way of handling light in AVWW. The older method, using the z buffer, is still available for lower-end graphics cards and computers, but this new model looks way better, and on most computers won't use that much more CPU/GPU!

What We Were Doing: The Z Buffer
The problem with the Z Buffer method is that it winds up with very pixelated edges.  That buffer doesn't support anything except binary write / don't write data, and that's not super conductive to having high quality lighting.  The plus side is that it's super compatible with older graphics cards, and it doesn't use much at all in the way of GPU power.

The #7 video was using the z buffer, but was also using a trick for the "eyesight" part of the view to make it look like a gradient when the z buffer doesn't really support that.  The trouble there is that you can't do that with anything that overlaps in the z buffer; so I could do that for eyesight, but not for lights.

What We Tried Before The Z Buffer
Why not just use the normal 3D lighting model that most 3D games use?  I tried it, but the problem is that this is a 2D game being rendered using 3D quads.  That just really didn't work out, because pixel lighting is incredibly expensive on the GPU, and not supported by every card, while vertex lighting is incredibly coarse and looks really bad.

To make matters worse, the way that we draw things in Unity 3D is by using their Graphics.DrawMeshNow method.  Supposedly that supports lighting, just not certain kinds of lighting, but my experience was that even vertex lighting was fraught with errors.  Based on the materials in use, I'd get random aspects of the lighting shutting on and off in various parts of the scene.

I tried using Graphics.DrawMesh instead, but that in turn doesn't support things that I need to do with uv animations and such for textures.  As I discovered with Tidalis and AI War, Graphics.DrawMeshNow is basically the only possible solution that has any substantial speed for the number of sprites that we need to draw, while also supporting all the functionality we need in terms of fancy texture mappings.

So that meant that a traditional lighting model was basically out.

The New Method
The new method is actually conceptually simpler than any of the others, and doesn't really do anything new technology-wise.  I thought of doing this from way back, but never thought it would look very good or perform very well.  After the #7 video, and some prompting from long-time Arcen community member eRe4s3r, I decided to at least give it a shot.

What I'm actually doing for perfect darkness is rendering an array of big black circles with fading-to-transparent radial gradient edges to them.  These circles are about 256 pixels in outer diameter, but on the pure-black internal diameter they are about 64 pixels.  Each one of these is rendered in a grid that is screen-aligned and 64 pixels per grid tile.

Talk about an inefficient way to draw blackness!  But the cool thing happens when you start "carving out" blackness where there is a light source.  Every frame, each light source writes into that big screen-aligned array if it is providing some light to it (in a framerate-independent manner, of course).  Also every frame, at about half that rate, each tile loses light.

The longer the light is in one location, the closer towards perfectly-invisible that black circle on all the tiles near it get, until they disappear and it seems perfectly bright.  Since the images drawn in each tile are so much larger than they need to be, their gradient edges "hang over" into the nearby tiles.  I also have each image pulsing by about 10% on a 4x speed sine wave, which makes the edge of the darkness seem to pulse in a living, threatening manner.

The other effect of all this is that when you turn move a light source, it takes a minute to fade.  About half the time it took to create the light source in the first place.  This means that things like the fireball, which flicker and sputter in a seizure-inducing fashion if there was no slowdown, instead look graceful and almost liquid.  This is darkness with substance, which is a pretty neat stylistic effect, and in keeping with the visual style and themes of the game.

How Does This Integrate Into The Game?
This new effect adds a lot of extra draw calls into the game, and so on some very old GPUs it might stutter some.  These would be the same computers that would need to turn shadows off in the game, and might even need to turn foliage down.  To make sure those sort of machines can still play the game, we now have a settings option where the lighting model can be chosen.

The z buffer method is functionally equivalent to this new one, it just looks worse, but it's more efficient.  For people with astronomically large screen resolutions, they may also prefer that, as the cost of this lighting model gets linearly higher with the number of pixels in the screen resolution.

On our test machines, we haven't found this new approach to be very heavy at all, though, so we suspect most people will leave this turned on by default, as they will shadows, foliage, and so on.  If you can comfortably run AI War, you can comfortably run this, too.  But in terms of netbooks and other smaller computers that can run Tidalis but not AI War, let's say, we also wanted to have options for them with AVWW.  So far it seems we do!
« Last Edit: March 29, 2011, 08:39:09 pm by x4000 »
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline orzelek

  • Hero Member Mark III
  • *****
  • Posts: 1,096
Re: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« Reply #1 on: March 29, 2011, 07:31:27 pm »
What I can say... it's an amazingly good looking way to make darkness that looks almost.. alive :D

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« Reply #2 on: March 29, 2011, 07:35:47 pm »
That's the goal!  Glad you like it. :)
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline BobTheJanitor

  • Master Member Mark II
  • *****
  • Posts: 1,689
Re: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« Reply #3 on: March 29, 2011, 08:32:07 pm »
Looks so much better. Thanks for taking another stab at it. You really hit the mark here.

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« Reply #4 on: March 29, 2011, 08:35:42 pm »
Thanks! :)
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline RCIX

  • Core Member Mark II
  • *****
  • Posts: 2,808
  • Avatar credit goes to Spookypatrol on League forum
Re: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« Reply #5 on: March 29, 2011, 09:13:20 pm »
Next up on the demands list: Dynamic shadows! :P

J/k, though it did seem odd that there were shadows at night...
Avid League player and apparently back from the dead!

If we weren't going for your money, you wouldn't have gotten as much value for it!

Oh, wait... *causation loop detonates*

Offline superking

  • Hero Member Mark III
  • *****
  • Posts: 1,205
Re: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« Reply #6 on: March 30, 2011, 06:52:53 am »
it looks better, though I think light'll need to fade quicker than it does in that video as when moving between light sources it looked rather off

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« Reply #7 on: March 30, 2011, 09:23:04 am »
it looks better, though I think light'll need to fade quicker than it does in that video as when moving between light sources it looked rather off

I experienced around, and that was what inliked the best for now. Realism isn't my goal, I was going for "liquid and threatening."
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Echo35

  • Master Member Mark II
  • *****
  • Posts: 1,703
  • More turrets! MORE TURRETS!
Re: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« Reply #8 on: March 30, 2011, 01:16:04 pm »
This new effect adds a lot of extra draw calls into the game, and so on some very old GPUs it might stutter some.  These would be the same computers that would need to turn shadows off in the game, and might even need to turn foliage down.  To make sure those sort of machines can still play the game, we now have a settings option where the lighting model can be chosen.

How low end are we talking here? Because outside of REALLY backwoods computers (As it were) I have had no trouble running any of your games on any machine I can find. Is AVWW going to be that much heavier in comparison to AI War and Tidalis, or are you just trying to play on a P3? :P

Offline Zhaine

  • Jr. Member Mark II
  • **
  • Posts: 85
Re: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« Reply #9 on: March 30, 2011, 02:41:31 pm »
Excellent! Not 'realistic', but creepy, atmospheric and in keeping with the rest of the art, which is a very good thing. Well done for plugging away and finding a method that worked (with thanks to eRe4s3r too I think). Maybe some fine tuning on the fade time and how much it pulses (I think it would be even creepier if it pulsed slower), but it seems you've got the model sorted  :)

Offline eRe4s3r

  • Core Member Mark II
  • *****
  • Posts: 2,825
Re: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« Reply #10 on: March 30, 2011, 08:30:48 pm »
I admit this method is what comes to mind when thinking about the whole thing (shadow map sampling and all that) but actually doing it is certainly unique (i wasn't gonna propose this particular method as i never seen it in action and while mocking the image in previous topic up i actually thought about using circles of a set scale, but i wasn't sure how many you'd need and what sizes they should have and if it'd be performance neutral or not). It does produce a very interesting looking effect though. I think this effect would even allow for a scaling up of the whole thing. I mean, higher "shadow" settings with smaller (and more) "circles". but even in the 256px setting it seems to work very well. And indeed it looks alive, never seen something quite like it - which is a good thing ;)

Hehe, now it just needs the desaturation and colorization step for maximum effect - seeing as its now sprites again that should be possible to do (at least the color thing..) - in fact you can now even color the fog of regions right? Should add a lot more possibilities for moody effects.

Glad that my nagging could be of help. ;) This looks vastly superior in all ways ;p ;D
Proud member of the Initiative for Bigger Weapons EV. - Bringer of Additive Blended Doom - Vote for Lore, get free cookie

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« Reply #11 on: March 30, 2011, 11:09:52 pm »
In terms of "how low end are we talking," I was indeed thinking of a PIII-era Celeron laptop, yeah.  Or a modern netbook.  This game isn't any heavier than AI War, and if you have a reasonable graphics card it's actually quite a bit less heavy.  I average between about 90 and 300 fps on my 8800 GTS + Sandy Bridge quad core.

I admit this method is what comes to mind when thinking about the whole thing (shadow map sampling and all that) but actually doing it is certainly unique (i wasn't gonna propose this particular method as i never seen it in action and while mocking the image in previous topic up i actually thought about using circles of a set scale, but i wasn't sure how many you'd need and what sizes they should have and if it'd be performance neutral or not).

Thanks!  Yeah, it's one of those things I've never seen that I know of, either, and I wasn't sure if it would work or not, either.  I've done tile-based shadow maps before (see Alden Ridge 2008), but those were non-overlapping and the effect was very 8bit/16bit.  I took a guess on the circle size, and it actually turned out surprisingly perfect on the first go!  Sometimes luck does favor me, but not often, I guess. ;)

It does produce a very interesting looking effect though. I think this effect would even allow for a scaling up of the whole thing. I mean, higher "shadow" settings with smaller (and more) "circles". but even in the 256px setting it seems to work very well. And indeed it looks alive, never seen something quite like it - which is a good thing ;)

I think that with more precision, the cost of this goes up pretty dramatically.  It adds about as much cost right now as does having the waving grass fields in the exterior areas, less when there's any significant light onscreen, but scaling it down would get much heavier.  Right now on a 1280x1024 screen there are 20x16 = 320 shadow tiles mapped on the screen.  If you went to twice that precision, it becomes 40x32 = 640 shadow tiles, which would drop my setup down to around 40fps with anything else of note going on in the scene at the time, I think.

Anyway, glad you like the look, and thanks for the kind words on not having seen anything like it!  I never expected to invent some new animated darkness effect with this game, that was totally unexpected to me how I was able to make it come out.  I was just trying to cut out the epileptic flickering that I was getting, and I implemented the fades.  Then that was interesting, so I decided to slow it down and see what that looked like.  And it looked pretty cool!

Hehe, now it just needs the desaturation and colorization step for maximum effect - seeing as its now sprites again that should be possible to do (at least the color thing..) - in fact you can now even color the fog of regions right? Should add a lot more possibilities for moody effects.

Yeah, I can color the fog any old way, and I can even have it be animated particle effects.  I do intend to make some swirling fog-like effects in some other area outside much later.  Maybe a foggy seashore or woods or something.  Or a Silent Hill type of town, heh. :)

In terms of the desaturation, I can't really do that directly.  I can put on an overall overlay that draws dimness over the scene, or I could put a gray diffuse color on all the images in general, which would make them look duller.  But the darkness is already fully desaturated, so it would have to be on the actual stuff you see in the scene directly.  The tricky part is that when there are light sources, it would still be desaturated around them, which would kind of kill the point of having a light source inside in terms of it would never give you full illumination. 

I liked having the eyesight be duller in the other method, but I can't think of any way to get that same sort of effect here.  So for now I'm just going with this, and that may be where it winds up, or I might add a slight dulling layer over everything, I'm not sure.

Glad that my nagging could be of help. ;) This looks vastly superior in all ways ;p ;D

As always, thanks for your help!  You've inspired a lot of artistic changes in my games -- when you weren't outright contributing art directly!  It's quite appreciated. :)
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline eRe4s3r

  • Core Member Mark II
  • *****
  • Posts: 2,825
Re: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« Reply #12 on: March 31, 2011, 09:15:37 pm »
Well the reason I do try to give helpful advice is because at least here someone reads it and if its indeed helpful, uses it ;) Only possible because you make the pre-alpha development public.. hope you keep this up, especially with the short videos (those show a lot more than just status updates in text form especially with HD quality) ;)
Proud member of the Initiative for Bigger Weapons EV. - Bringer of Additive Blended Doom - Vote for Lore, get free cookie

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: A Valley Without Wind Pre-Alpha #8 -- New Lighting Test
« Reply #13 on: March 31, 2011, 09:57:31 pm »
You bet! Well keep doing videos. :)
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!