Sign in to follow this  
Henry00

Creating ingame lighting / using lightmaps

Recommended Posts

Hi we are the programming team 00Laboratories ( [url="http://00laboratories.com/"]http://00laboratories.com/[/url] )

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

[img]http://henry00.ftpaccess.cc/henry00/projects/Wind14_light1.png[/img]

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
[code]
Structure cLight
x.f : y.f : z.f
r.f : g.f : b.f
EndStructure

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
glDeleteTextures(1,@lightmap_tex_num)
glGenTextures(1,@lightmap_tex_num)
EndIf

Vector3D_Sub(@tV,*V2,*V1)
DistX = Vector3D_Length(@tV)

Vector3D_Sub(@tV2,*V3,*V2)
DistY = Vector3D_Length(@tV2)

Vector3D_Cross(@Normal,@tV,@tV2)
;Vector3D_Normalize(@Normal,@Normal)

;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
tmp.f
d.f

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

;Vector3D_Mul(@tV,@Normal,@tV)

Vector3D_Add(@tV,@tV,*V1)
Vector3D_Sub(@tV,@tV,*light)

d = Vector3D_Dot(@tV,@tV) * 16
If d < 1
d = 1
EndIf
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
Next
v + stepY
u = 0
Next

glBindTexture(#GL_TEXTURE_2D, lightmap_tex_num)
glTexEnvf(#GL_TEXTURE_ENV,#GL_TEXTURE_ENV_MODE,#GL_MODULATE)
glPixelStorei(#GL_UNPACK_ALIGNMENT, 1)
glTexParameterf( #GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR)
glTexParameterf( #GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_LINEAR )
glTexParameterf( #GL_TEXTURE_2D, #GL_TEXTURE_WRAP_S, #GL_REPEAT )
glTexParameterf( #GL_TEXTURE_2D, #GL_TEXTURE_WRAP_T, #GL_REPEAT )
glTexImage2D(#GL_TEXTURE_2D, 0, 3, xQuality, yQuality, 0, #GL_RGB, #GL_UNSIGNED_BYTE, @cData())

ProcedureReturn lightmap_tex_num
EndProcedure
[/code]

Thanks! ( other shots are visible [url="http://henry00.ftpaccess.cc/henry00/projects/"]here[/url] )

Share this post


Link to post
Share on other sites
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
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