Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / @ Latch - Light mapping?

Author
Message
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 9th Nov 2010 08:06
Hi Latch,


You still don't appear to have an e-mail address, so I'll just post this here. A while back you wrote an amazing light map demo using LightMap maker, but unfortunately, you never released the source for it... This is the thread I am referring to:

http://forum.thegamecreators.com/?m=forum_view&t=149937&b=10

Could you possibly reveal the secrets behind that demo? I am in need of some help for my current project (click my sig)

Cheers,


TheComet

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Nov 2010 17:29
I'd have to dig around for that. I haven't used lightmap maker for a while. It gives good results, but you have to retexture everything - and it's a bit of a pain. I do it all in Blender now, but it's still a pain! But at least I only have to set up the textures once...

Anyway, there are a couple ways to approach this:

1. Grouping faces or objects together, you create a baked texture that includes the lighting of the scene. You apply this texture to the faces/objects.

2. Create two models: 1 with the regular textures, and another with only the light mapping. You then overlap the models and Dark ghost the light mapped model

3. You have a single model and you set up 2 UV sets: 1 with the regular textures, and 1 with the light mapping. You swap the UV sets and render each triangle twice with the different texturing (layered texturing) with alpha.

For single objects, nothing too intricate, number 1 should do in most cases. Here is an example of a tub.



It uses 2 layered textures - the blood, and a white, slightly bump mapped texture. Then lights are placed around, and then a final texture is baked representing the layered textures and the lighting. What makes this work is carefully unwrapping the UVs. None can overlap. That means using UV's greater than 1 to repeat the pattern won't work.

If you are doing an interior environment or something more complicated, then a good method is number 2. Are you still using AC3D ? If so, then I think you'll want to use the render to texture plugin. From what I read, this is texture baking which can be used for lightmapping.

What you would do is:
1. Create your model of the building or environment.
2. Texture it the way you want
3. Save it
4. Using the EXACT same model; there can be no differences in the faces or vertices, remove all of the texture and material information.
5. Set up your lights however they are supposed to look in the scene so that the appropriate shadows and highlights appear on your model.
6. Unwrap the model's UVs so that no UVs overlap. This is very important. This UV map doesn't have to have anything to do with the original textured version. This is it's own thing for the sake of lightmapping.
7. Render the object to a texture using the UVs.
8. Apply the materail with this new texture to the model.
9. Save this as a lightmapped version of your environment.

In DB, load both models. Set the light mapped model to dark ghosting. Turn the collision off for the light mapped model. That should do it.

I don't know AC3D, but this is a generic process that should work with any 3d app that can create a texture from UVs and lighting.

Method 3, you'd have to be able to get into the rendering detail/loop. It ultimately ends up like method 2, it just does it in the rendering process triangle by triangle. This can be a super detailed method for allowing things like LOD control over bump mapping or texture blending on a per triangle basis. I don't know if DBPro allows for that kind of control.

Enjoy your day.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 9th Nov 2010 21:24
Thanks Latch! I downloaded the render to texture plugin, and checked it out, and it proves itself quite useful

Unfortunately, the last thing you said is exactly what I wanted to avoid:

Quote: "In DB, load both models. Set the light mapped model to dark ghosting. Turn the collision off for the light mapped model. That should to it."


Is that really what you used in your demo? In DBP this causes z-fighting...

Quote: "1. Grouping faces or objects together, you create a baked texture that includes the lighting of the scene. You apply this texture to the faces/objects."


This is exactly what I want to achieve. I haven't looked at the AC3D plugin in depth, I hope it has a baking option... Or a way to fuse two objects together. How would I solve this if I had to do it using memblocks?

I also studied Lightmap maker, and I found that it is possible to export the object with textures and lightmap fused, but for some reason I can't select the "Texture X Lightmap" option:



Any idea why this could be?


Anyway, thanks for the reply, I'll research some more stuff. And it would be really awesome if you could show the source for your demo

TheComet

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 10th Nov 2010 06:08
Quote: "Is that really what you used in your demo? In DBP this causes z-fighting..."

Yes. If the models are exactly the same (except for the UVs) - there are no differences at all in terms of verts, faces, scale, there should be no z battle. That means both models have to be made in the same program and textured in the same program so that the faces and verts match up exactly. Cartography shop has this built in. You may want to try that out. It outputs a textured model and a light mapped model.

Quote: "I also studied Lightmap maker, and I found that it is possible to export the object with textures and lightmap fused, but for some reason I can't select the "Texture X Lightmap" option:"

You can't do it for an X file in lightmap maker. The functionality may have been intended, but it's not included. Lightmap maker rebuilds the model into a single mesh based on a series of surfaces (quads instead of tris for faces I believe). If the model was built using limbs or a series of connected meshes, they get converted to surfaces and ultimately to a single mesh. The UV's for the textured part of the mesh are different than the UVs for the lightmapped part of the mesh. So, there ends up being 2 files.

Quote: "This is exactly what I want to achieve. I haven't looked at the AC3D plugin in depth, I hope it has a baking option... Or a way to fuse two objects together. How would I solve this if I had to do it using memblocks?"

From what I read, it IS the baking option. It's just called render to texture - which is what baking is.

Fuse two objects together... Keep in mind that lightmapping works by blending/overlaying textures - alpha blending. If you fuse two objects, you would lose the individual alpha control over one of them. A more ideal solution would be to layer multiple textures and be able to control the blending of the textures. In which case you wouldn't have to fuse two objects. But this is where things get a little bit tricky.

A light map is a texture that represents the lighting of an environment. This is not the textures that determine that a wall looks like a wall, or a floor looks like a floor. Since a light map is the gradation of light of some color towards black or ambient, it can be a single texture and it doesn't have to be very big. It's mapping to the object is determined by it's own set of UV coordinates which differ from the UVs that map the regular textures to the object. In order to have the light map and the textures show up at the same time, both sets of UVs somehow have to be rendered simultaneously with the light map and the textures being alpha blended.

It is possible to combine the light map and the textures together ahead of time. Here's the problem:

If you have a wall that uses a repeating texture, you'll have to blend a lightmap and a very large version of the repeating pattern into 1 very large image so as to retain the detail. You would have to do this for every surface. It's not bad for non repeating textures where the UVs are unwrapped and don't overlap. But, at the end of the day, you would have a whole series of individual light mapped textures that you would have to apply to every surface or object they relate to. Like I stated earlier, this method is ok for carefully unwrapped objects or for a wall or two, but uses far too many resources to be practical for large intricate environments.

Memblocks....
No doubt it is possible with a lot of work and customization. But the default memblock to mesh commands won't get you there without some major intervention from you (like referencing multiple textures/limbs associated with the mesh). The problem comes down to showing the light map and the textures at the same time alpha blended.

Doesn't DBPro have light mapping built in anyway?

Enjoy your day.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 10th Nov 2010 09:35
Quote: "Doesn't DBPro have light mapping built in anyway?"


Yes, it has a lightmap shader, and a command set light mapping on, but from what I've tested, you need the two textures (base texture and light map texture) to have the same coordinates, because the command basically just textures the object with two textures alpha blended together. And this takes us back to that problem:

Quote: "If you have a wall that uses a repeating texture, you'll have to blend a lightmap and a very large version of the repeating pattern into 1 very large image so as to retain the detail."


I see now that I will probably not be able to bake the lightmap onto my object because of the repeating texture problem...

Anyway, thanks a lot for clearing some stuff up, I will try and get the two object method working as you described If I have any problems, or success, I'll post here.

TheComet

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 22nd Nov 2010 20:25
Something that occurred to me along the lines of fusing two objects together.

In a direct x file, you can have multiple meshes referenced. Each mesh can have it's own set of UV's. The file is broken up into sections called templates. There is a template called Material that has colors relating to diffuse, specular, ambient and emissive. The ambient color has an alpha channel. There is also a TextureFilename template within the Material template.

If DBPro recognizes the alpha channel in the direct x files material setting, it may be possible to have the light mapping contained in the x file and the regular texturing . When the object is loaded, both meshes would be rendered simultaneously as a single object, very much like an object and it's limbs. The alpha channel would be set for the lightmapped version of the mesh inside the file.

In theory, the result would be a rendering of a single object with blended texturing.

It may also be possible to have two sets of UVs aplied to a single mesh within the directx file, though I'm under the impression that there is one set per mesh. I've never really tested it so I don't really know. It's something you might want to tinker with if you have time.

Enjoy your day.

Login to post a reply

Server time is: 2024-03-29 02:37:10
Your offset time is: 2024-03-29 02:37:10