LightMapping Techniques
Blitz3D Forums/Blitz3D Programming/LightMapping Techniques
| ||
I been experimenting with Lightmaps, just started out, so if any expert out there, feel free to drop some advice or two ;) My engine is made up by block tiles If i want to make in-built function that light map this, should i add all those tiles into one giant mesh or lightmap it as separate tiles? Which way would be faster or better? Nack |
| ||
Here is what ive done in the past. For all static objects in the level... dynamic entities I use entity color. I have all of my building blocks as OBJ type with position rotation etc. Then I have a type called SECTION. The section is a final mesh built and light mapped. I create a temp copy of each object called a LMOBJ for light mapped objects. Position them into place, add them to a newly created mesh, and then unweld and light map it with YAL(yet another light mapper found in the code archives. If you play with YAL you'll notice the functions being called here. Its kinda a rough way to do things, but it works for me. So for the editor I just have a toggle that Show_final_meshes if true then hide the building blocks and vice versa. Include "source\ray_intersect.bb" Function light_map(section%) first_selection = False For O.obj=Each obj If O\zone% = section% Then LM.lm_obj=New lm_obj LM\entity = CopyMesh (block(O\part%)) LM\X# = O\X# LM\Y# = O\Y# LM\Z# = O\Z# LM\RX# = O\RX# LM\RY# = O\RY# LM\RZ# = O\RZ# LM\texture% = O\texture% EntityFX LM\entity,1 PaintMesh LM\entity,brush_texture( LM\texture% ) RotateMesh LM\entity, LM\RX#, LM\RY#, LM\RZ# PositionMesh LM\entity, LM\X#, LM\Y#, LM\Z# EntityPickMode LM\entity,2 If first_selection = False Then PositionEntity temp_piv,EntityX(O\entity),EntityY(O\entity),EntityZ(O\entity) first_selection = True End If last_x# = O\X# last_y# = O\y# last_z# = O\z# End If Next If first_selection=False Then Return For S.section = Each section If S\number% = section% Then FreeEntity S\mesh S\mesh = CreateMesh() NameEntity( S\mesh, S\number% ) For N.lm_obj = Each lm_obj AddMesh N\entity,S\mesh Next ThisObscurer.LMObscurer = New LMObscurer ThisObscurer\Entity = S\mesh BeginLightMap(Ambient_r%, Ambient_g%, Ambient_b%) For L.light= Each light If L\zone% = section% CreateLMLight( L\X#, L\Y#, L\Z#, L\R%,L\G%,L\B%, L\range%, False, L\brightness%) End If Next tex = LightMapMesh(S\mesh, 2.0, 256, 0, "Lightmapping " + EntityName(S\mesh)) lm_folder$ = "maps\" + map_name$ + "\" If tex SaveLightMap(S\mesh, tex, lm_folder$ + EntityName(S\mesh) + ".bmp", lm_folder$ + EntityName(S\mesh) + ".luv") ApplyLightMap(S\mesh, tex) EndIf EndLightMap() For R.lm_obj=Each lm_obj FreeEntity R\entity Delete R Next For M.LMLight= Each LMLight Delete M Next If Show_final_meshes = -1 Then HideEntity S\mesh End If Next End Function |