2D Lighting
I'm looking for a way to get a lighting system working on a 2D Classic looking Role Playing Game, known as HEATHEN,I was wondering if anyone could point me in the right direction for 2d lighting and...... 16bit Alphablitting. Any site or tutorial is appreciated greatly thanks a bunch.
Edited by - Myopic Rhino on 1/19/00 2:01:08 PM
There is a good alphablitting tutorial here on GameDev. I forget the exact URL, but its in the programming section - under general graphics, IIRC.
As for 2D lighting, that depends upon how your graphics engine works in general. Is your game tile based? Massive bitmap based? Different lighting techniques work for different render types. Your target platform is also really important, here.... a lighting system designed for a 120 Mhz Pentium will be very different to that designed for a fast Pentium II/III/Athlon!
Slow computer (ie FAST rendering) 2D lighting ideas: prerendered tiles at different lighting levels. Doesn''t look wonderful, but it works on almost anything.
Fast computer (slower rendering) you could overlay lightmaps on tiles. Pretty easy to do.
A much better approach is to use Direct3D (or OpenGL) with 2D coordinates and use either vertex or lightmap-based lighting.
As for 2D lighting, that depends upon how your graphics engine works in general. Is your game tile based? Massive bitmap based? Different lighting techniques work for different render types. Your target platform is also really important, here.... a lighting system designed for a 120 Mhz Pentium will be very different to that designed for a fast Pentium II/III/Athlon!
Slow computer (ie FAST rendering) 2D lighting ideas: prerendered tiles at different lighting levels. Doesn''t look wonderful, but it works on almost anything.
Fast computer (slower rendering) you could overlay lightmaps on tiles. Pretty easy to do.
A much better approach is to use Direct3D (or OpenGL) with 2D coordinates and use either vertex or lightmap-based lighting.
The game engine is tile based. either way i just would like some lighting tutorials or pages for anything 2D.
thanks
thanks
I haven't seen any really good tutorials on the topic of lighting a tilebased scene (maybe I should write one, since I seem to end up answering questions like this a lot!). After experimenting, I actually found that using Direct3D to light a tile engine was easier than coding a lightmapped system and alpha-blending the lightmap with the tiles under DirectDraw. Going through the latter felt far too much like reinventing the wheel! Here is an outline of how you'd go about lighting a tile-based system with D3D. Email me if you want me to send you sample source code (its written with an isometric, diamond-shaped view - but its a tile engine, and not hard to convert).
For each tile, you will want to store the light level (as an RGB colour using the D3DCOLOR type) at each of the tile's corners. Logically, two of these will be the same as values in neighbouring tiles - or at least for smooth lighting it will be.
During setup you want to acquire a Direct3D interface and device, much as you do with DirectDraw. The SDK includes cut-and-pasteable code to do this for you. You'd then want to load your tiles in as textures - DirectX 7 makes this really easy, DirectX 6 it wasn't exactly hard. Again, the SDK explains it really well. Texture sizes must be powers of 2 to work on all graphics cards.
The actual render phase would be something like this (in psuedocode - again, email me for C++):
(in the DrawPrimitive line the \ is really two vertical lines but this messag board doesn't like those)
An easy optimization would be to not call SetTexture if the texture hasn't changed. A slightly harder one is to batch similar tiles together and only render them when the texture would change (greatly speeds up rendering on SOME cards, not all).
Edited by - Bracket on 1/20/00 12:55:17 PM
Edited by - Bracket on 1/20/00 1:52:12 PM
For each tile, you will want to store the light level (as an RGB colour using the D3DCOLOR type) at each of the tile's corners. Logically, two of these will be the same as values in neighbouring tiles - or at least for smooth lighting it will be.
During setup you want to acquire a Direct3D interface and device, much as you do with DirectDraw. The SDK includes cut-and-pasteable code to do this for you. You'd then want to load your tiles in as textures - DirectX 7 makes this really easy, DirectX 6 it wasn't exactly hard. Again, the SDK explains it really well. Texture sizes must be powers of 2 to work on all graphics cards.
The actual render phase would be something like this (in psuedocode - again, email me for C++):
D3DTLVERTEX Vertex[4];// Sets 0 to top left, 1 to top right// 2 to bottom left, 3 to bottom rightVertex[0].tu = 0.0f;Vertex[0].tv = 0.0f;Vertex[1].tu = 1.0f;Vertex[1].tv = 0.0f;Vertex[2].tu = 0.0f;Vertex[2].tv = 1.0f;Vertex[3].tu = 1.0f;Vertex[3].tv = 1.0f;// This just ensures that everything runs smoothlyVertex[0].rhw = 1.0f;Vertex[1].rhw = 1.0f;Vertex[2].rhw = 1.0f;Vertex[3].rhw = 1.0f;Direct3DDevice->BeginSceneFor each tile you want rendered Direct3DDevice->SetTexture(0,desired texture/tile) Vertex[1].sx = TopLeft X Coordinate Vertex[1].sy = TopLeft Y Coordinate Vertex[1].color = TopLeft Colour // etc. for all 4 vertices using the scheme above Direct3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_TLVERTEX,Vertex,4,D3DDP_DONOTLIGHT / D3DDP_DONOTCLIP ))next tileDirect3DDevice->EndScene
(in the DrawPrimitive line the \ is really two vertical lines but this messag board doesn't like those)
An easy optimization would be to not call SetTexture if the texture hasn't changed. A slightly harder one is to batch similar tiles together and only render them when the texture would change (greatly speeds up rendering on SOME cards, not all).
Edited by - Bracket on 1/20/00 12:55:17 PM
Edited by - Bracket on 1/20/00 1:52:12 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement