Lightmapping question

Blitz3D Forums/Blitz3D Programming/Lightmapping question

*(Posted 2004) [#1]
I know it can be done in Blitz3d (decorator does it :) ) but how do you change a lightmap from one lightmap to the other, could someone explain it to me.

Thanks in advance :)


jfk EO-11110(Posted 2004) [#2]
I don't understand that question - change a lightmap? You simply have to assign an other lightmap textue to the second coords set of the meshs UVs. So tell the texture to use the second UV set with

Texturecoords tex,1

and assign it to the mesh:

Entitytexture mesh,tex,0,1

To save the mesh with the new lightmap you can simply replace the filename in the file, or use a B3D Mesh exporter that will handle lightmaps. In that case you need to define the brushes with 2 Textures, where the 2nd will be the lightmap for all brushes. the blending mode must be 2 if I remember right and the entityFX must be 1=fullbright.


*(Posted 2004) [#3]
The problem I get is this, when I change a lightmap I get the lightmap image ie the square texture and not the lighting as required. It would be the same as if I had gone throughout the level and assigned a square texture.

What I want to do is simply (within Blitz) change one lightmap for another one. EntityTexture doesnt seems to work unfortunately, this is why im asking.


*(Posted 2004) [#4]
This is what I get with my entitytexturing (this is a Quill3d mesh):


Working (just loading the mesh with LoadMesh



Not working, applying texture with EntityTexture etc.


What I want is to be able to apply lightmaps in Blitz and get results like the Working picture.


Ross C(Posted 2004) [#5]
I imagine the two lightmaps are produce by the same program?


Ross C(Posted 2004) [#6]
Also, as jfk says, are you changing the tex co-ords to the second set?

Texturecoords tex,1


*(Posted 2004) [#7]
Yup TextureCoords are set to 1 and I use Entitytexture mesh, texture, 0, 1 too and fullbright.


jfk EO-11110(Posted 2004) [#8]
maybe quill is using the lightmap on the set 0 ?


*(Posted 2004) [#9]
Tried that one, unfortunately that just changes the backing texture :|


jfk EO-11110(Posted 2004) [#10]
did you visually compare the two lightmap textures, i mean as images? do they use the same UVs? how did you produce the second lightmap? If you exported the lihtmap from quill then maybe you have to ask Dave, he only knows if quill would save the same lightmap in diffrent ways, depending on weather or daytime...


*(Posted 2004) [#11]
The first lightmap and second lightmap are exactly the same image, but applying with the EntityTexture method yeilds the second result. Loading the mesh as standard loads it as the first piccy.


JaviCervera(Posted 2004) [#12]
Probably the UV coordinates required for the 2nd lightmap are different to the coordinates required for the 1st?


*(Posted 2004) [#13]
possibly but is there a way of sorting this?


Richard Betson(Posted 2004) [#14]
EdzUp,

Have loaded or created a texture with the Texture UV clamped? For example LoadTexture("lightmap.bmp",16+32).

L8r,


jfk EO-11110(Posted 2004) [#15]
if the lightmap looks the same then the uv coordinates required for the second lightmap are the same. If you are using the same mesh and the 2 lightmaps are looking the same, it's only a question of the assignment.

maybe you need to spy the mesh structure...

m=loadmesh("level.b3d")
surfs=countsurfaces(m)
for i=1 to surfs
 s=getsurface(m,i)
 b=getsurfacebrush(s)
 t0=getbrushtexture(b,0)
 t1=getbrushtexture(b,1)
 print "Brush "+i+" uses:" 
 print " texure set 0: "+texturename$(t0)
 print " texure set 1: "+texturename$(t1)
next
waitkey()



*(Posted 2004) [#16]
thanks guys will have a look :)


*(Posted 2004) [#17]
I have created this function:
Function SwitchLightMap( Mesh, NewTexture )
	;this function changes the lightmap on a mesh to a selected lightmap
	Local SurfS=CountSurfaces( Mesh ) 
	Local SurfI=0
	
	For SurfI=1 To Surfs
		s=GetSurface( Mesh, SurfI ) 
		b=GetSurfaceBrush(s) 
		t0=GetBrushTexture( b, 0 ) 
		t1=GetBrushTexture( b, 1 )
		
		BrushTexture b, t0, 0, 0
		BrushTexture b, newtexture, 0, 1
		
		PaintSurface s, b
	Next 
End Function


I still get the same result tho, anyone have any ideas?


jfk EO-11110(Posted 2004) [#18]
can you post the mesh?


Richard Betson(Posted 2004) [#19]
Yeah.. somthing we can test. :)

L8r,


*(Posted 2004) [#20]
I will create a demo mesh as the current mesh is over 2Mb in size (inc lightmap)


starfox(Posted 2004) [#21]
maybe you should unweld the mesh?


*(Posted 2004) [#22]
I have located the problem, it seems the mesh I have is to complex (ATM it has over 40 different textures and is 1.05Mb in size). I have created a very simple mesh (a box with a pedestal and four pillars) and that lightmaps perfectly :|. This means basically I have to break up the levels if I want to do anything with the lightmapping stuff.


MSW(Posted 2004) [#23]
Those two lightmaps...they look the same right?...but are they the exact same pixel size...the exact same color depth...even if they are, how much video memory is left after loading in the mesh, the textures, the original lightmap, and the lightmap you want to swap it with and anything else that's loaded in video memory when the problem occurs...

Try this...load in the level...swap the lightmaps so the problem occurs (use entitytexture)...then swap back to the original lightmap(again useing entitytexture)...if doing this restores the original lighting then the problem is most likely related to the second lightmap...either it's not the same pixel size, or Blitz has had to do something funky to match up color depths (or even reduce the texture size so it can fit into videomemory)...but if you can't get back to the original lightmap after swapping them then possably the UVs are getting messed up...


*(Posted 2004) [#24]
MSW: I think its the UV's as the lightmap is the original one for the level, im just swapping it back and forth. Strange tho it works perfectly on simple levels but not on complex ones.


MSW(Posted 2004) [#25]
EdzUp - so you can take your complex level...put the original lightmap on it, and it looks as you expect...but when you swap to the second lightmap it gets messed up...that I understand...but is it still messed up if you then swap back to the original lightmap?


*(Posted 2004) [#26]
MSW: when I load the level it looks as expected, when I apply the lightmap for that level (that it was loaded with, I reload it as a texture) and apply that to the same level it gets screwed up.


*(Posted 2004) [#27]
(Here) is a demo of what im trying to do, use 1 and 2 to turn on and off the lights at either end. Keypad 4, 6, 2, 8 to rotate and move forward and back.


MSW(Posted 2004) [#28]

MSW: when I load the level it looks as expected, when I apply the lightmap for that level (that it was loaded with, I reload it as a texture) and apply that to the same level it gets screwed up.



Yes I fully realise that...what I have been asking is once it gets screwed up, can you at that point apply the original lightmap that was loaded in and have it return to the way it was?


Make a copy of your complex level .B3D file...in this copy strip out the refrence to the lightmap so that it doesn't load it with the level...if you can't do that then make a copy of the level textures, open them in some image editor and reduce all of them (except the lightmap) to half or quarter thier size (if they are 512 X 512, reduce them to 128 X 128 or even 64 X 64) set it up so the level will use these smaller test textures...or set up the graphics to run in 320 X 240 X 16 or 32-bit mode...
then use your example demo to load the level and two copies of the lightmap...then run that.


*(Posted 2004) [#29]
I will give it a go :)