Lighting in a 2D game and graphics file formats?

Started by
7 comments, last by chippolot 20 years ago
Hi, I am currently working with a team that is going to be working on a 2D game in D3D for next year. We''ve been planning the game so that it resembles a 3rd person zelda like game. One of the big features we''ve been discussing is a day to night cycle where the town would become lighter and darker depending on the time of day. However, we''re all new to this and are confused about how to implement this. So far we''ve thought of: Creating a dynamic system where we use actual light models in D3D to lighten and darken the town. However, this might not work so well using simple flat backgrounds. Also my team has thought of creating a system where the town would be pre-rendered in 3D. They would simply move a light source in 3D Studio Max and save 60+ prerendered images then flip through all of those in the game. Both of these systems have some major flaws... Has anyone done lighting (or a simply day to night cycle) in a 2D game before? What are some ways to do this? Also, we''ve only worked with BMPs as our standard file format before. These are huge and bulky though... What is a better file format to use for a 2D game while still retaining good quality? Thank you! Ben
Advertisement
Bumpmapping comes to mind. Basically, it''s a function that determines the normals to the polygon based on the current texel. That way, you could achieve the effect you seem to be wanting.

Also, should it become really necessary, use displacement mapping. This comes to mind...

I''m planning on creating a 2D game with dynamic lighting effects (actually, the gameplay will be quite based on it, hence the project name : "shadows"). However, this is for PDA platforms so I have no access to hardware acceleration and have to change the pixels myself. I know this is something you can''t do, but on my side I intend on computing lights this way :

Final_Color = Texture_Color * ( Base_shadows + Dynamic_lightmap )

Where the dynamic lightmap is the sum of all lights reaching that pixel, and the base shadows are kept alongside with textures. To change the time of day, you''d normally adjust this by adding in some factors (like daylight value) or multiplying by factors...

As for file formats, I''m using targa (*.tga) right now.

Victor Nicollet, INT13 game programmer

Thank you,
actually though we don''t really need to produce shadows, only change the actual color of the environment, so it can look like day, or look like night. However, we don''t want the colors to be faded of distorted. Is there a way to change the lighting so we can simulate a flat day to night effect while keeping the rich colors of the town?
what about ambient lighting? if everything here is just 2d you could just set the d3drender state for ambient lighting. ambient lighting lights everything in the world equally, its not a directional type light. So during the day the ambient light woudl be white, then as it got to sundown the light would slowly fade to a golden yellow, then to a dark blue.

this should accomplish exactly what you need, and its very easy to implement. I dont think you even need to have vertex normals for your geometry...its been a while so dont quote me on that.

good luck

edit: ambient lighting is "flat", so yeah it should work perfect for you.

[edited by - hlivingstone on March 29, 2004 1:28:46 PM]
Since you said you are using 2d in direct x, I''m going to assume you are using already Transformed and Lit vertecies. Do your vertexes have a diffuse color? If so, a simple day/night effect could be easy. 2 methods you could use:

Method 1:
Render everything as normal, then at the end of your rendering, simply an alpha blended quad ontop of everything with different colors for the different times white(noon), orange/magenta(dawn/dusk), ect.

Method 2:
Send everthing you want to render through a single renderer function that changes all the vertex colors, of all the items sent to it, to the color of that time(kinda like ambient lighting).


I would recommend Method 1 as it is much easier and doesn''t require changes to your rendering pipeline, but Method 2 has it''s advantages. Such as makes it easier to batch and sort your vertecies before you render them for a speed increase, ect.

CD

Jesus is Lord!!
Jesus is Lord!!
quote:Original post by chippolot
Also, we''ve only worked with BMPs as our standard file format before. These are huge and bulky though... What is a better file format to use for a 2D game while still retaining good quality?


Try the PNG format. PNG files use lossless compression, so you don''t lose image quality like JPEG. PNG files also have transparency built into the file format like GIFs. There are a number of open-source libraries that will allow you to read in a PNG file.
Just had an idea!
What if I were to create 3 static light sources above the map: A white, an orange, and a purple one. They''d all be ambient. When it was night, I would turn up the intensity on the purple light, and turn the intensity down on the orange one. The white light would always have the same intensity (to offset the purple at night a bit). Then, as day would go on, I would dim the purple light and brighten the orange one.
I tried to test that out with adobe photoshop and it looked okay... but would it work fine in Direct3D? I haven''t learned much about lights in that yet.... and input to this idea?
It you''re trying to attain the effect of night and day like in old school 2D games you could always blend a large quad that is tinted to the time of day over your maps to give it that illusion.

Then if you wanted more effects you could do lightmaps on windows and lamps.
PNG? no use the DDS file format, there is a photoshop plugin available in the nvidia developers site. DDS files are compressed on the gfx card, which greatly decreases the amount of bandwidth consumed while throwing them around on the card. The other formats are fine for debugging ect, but as for a realease build youll definatly want to use DDS files.

oh yeah my bad, im so used to messing with shaders, i forgot you would probably already be using pre transformed vertices. then yeah go with drawing an alpha blended quad over the top of the screen, that should be the simplest/best way to go.

good luck

edit: yeah you woulndt need to use 3 ambient lights, the same effect can be achived through the quad-over-the-whole-screen method. To get the same effect of the 3 ambient light colors together, just set the vertex color of the quad to be the sum of all the lighting colors you want.

with this method you can also play around with texture blending modes, which control how direct3d blends this quad ontop of your scene. youll be able to get some neat effects out of this, and have more control than you would with the ambient lighting.

[edited by - hlivingstone on March 29, 2004 10:57:04 PM]

This topic is closed to new replies.

Advertisement