Sign in to follow this  

Creating ingame lighting / using lightmaps

Recommended Posts

Henry00    100
Hi we are the programming team 00Laboratories ( [url=""][/url] )

We are currently writing a game engine + game, but we now have a little situation, the ingame lighting.


As you can see we attempted some light maps, but this is unusable, we are really lost at how we should implent lighting, I will add the snippet of source code creating the current ligting surface.
Is lightmaps the best way to go? Are the better ways that are managable within a few days that anyone could help with? It would be greatly appreciated!

Language = PureBasic
Structure cLight
x.f : y.f : z.f
r.f : g.f : b.f

Global lightmaptexture

Procedure generateLightmap(*V1.Vector3D,*V2.Vector3D,*V3.Vector3D,*light.cLight)
Define.f DistX,DistY
Define.Vector3D tV,tV2,Normal

lightmap_tex_num = 0
If lightmap_tex_num <> 0

DistX = Vector3D_Length(@tV)

DistY = Vector3D_Length(@tV2)


;quality of lightmap
xQuality = 16 ;DistX / 2 -1
yQuality = 16 ;DistY / 2 -1

;array containing pixel colors
Dim cData.c(xQuality*yQuality*3)

Define.f u,v,stepX,stepY
stepX = 1 / xQuality
stepY = 1 / yQuality

For i=0 To xQuality - 1
For i2=0 To yQuality - 1

tV\x = DistX * u
tV\y = Disty * v
tV\z = 0



d = Vector3D_Dot(@tV,@tV) * 16
If d < 1
d = 1
tmp = 1 / d

cData(i * xQuality * 3 + i2 * 3 + 0) = 255 * tmp * *light\r
cData(i * xQuality * 3 + i2 * 3 + 1) = 255 * tmp * *light\g
cData(i * xQuality * 3 + i2 * 3 + 2) = 255 * tmp * *light\b

u + stepX
v + stepY
u = 0

glBindTexture(#GL_TEXTURE_2D, lightmap_tex_num)
glPixelStorei(#GL_UNPACK_ALIGNMENT, 1)
glTexImage2D(#GL_TEXTURE_2D, 0, 3, xQuality, yQuality, 0, #GL_RGB, #GL_UNSIGNED_BYTE, @cData())

ProcedureReturn lightmap_tex_num

Thanks! ( other shots are visible [url=""]here[/url] )

Share this post

Link to post
Share on other sites
Surp    103
We for some reason want the game to work on very low end old pc's so we'd like low cost lighting , static lightmaps. But i've a hard time finding good articles about it.please help us.

Share this post

Link to post
Share on other sites
Henry00    100
Is there anyone here that can help us on our specific problem with some resources or code snippets, instead of complaining about why we would like anyone who has a less modern performance computer to be able to play our game? There must be someone here who has written a static lightmap system before, I appologize if this sounds offensive, it's not meant that way.
We could still implent more fascinating lighting after we get opengl > 1.5 working for integrated graphics or whatever reason there is such a low version.
Thanks for any help possible!! :)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this