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 Professional Discussion / Implementing a lightmapped object?

Author
Message
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Sep 2010 00:31
So here's the problem. I have two models, one of them is the normal model, and the other one is the lightmapped model.



The lightmapped model has the following texture:



And the normal model has multiple textures. Is there any way I can get the two "fused" together in DBP to form a nice lightmapped model? set light map on doesn't seem to do the trick :/

TheComet

Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 29th Sep 2010 01:52
If using "TEXTURE OBJECT" on the model makes it look like the lightmapped one in your first picture, then I'm sure the SET BLEND MAPPING ON command could handle this. I'm not sure what parameters one would use, but I think there was an investigation of this command conducted recently be someone. Try doing a quick search .


Guns, cinematics, stealth, items and more!
Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 29th Sep 2010 02:08
Is that from CShop? The UV values are different. Not sure if the two meshes are otherwise the same. If so you can use vertexdata to copy the UVs from one object to the UVs of the second texture stage of the other object, then use blend mapping or a shader to multiply the textures.

I seem to remember someone trying to do this fairly recently in the shader thread. Not sure if they succeeded.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Sep 2010 02:34
I think it was here in the main board.

Quote: "so you can use vertexdata to copy the UVs from one object to the UVs of the second texture stage of the other object, then use blend mapping"


That's what I would do.
Duke E
17
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 29th Sep 2010 10:10
Think you could use "Set Blend Mapping On" and use the Texture coordinate mode 3. (3 - Steal UV Data From Stage Zero)

Something like so:


Regards
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Sep 2010 13:17
There's no need for that complicated version of the command.

The thing we need to know is whether the lightmapped version has different UV coordinates - and it probably has. TheComet can check this easily by using the vertexdata commands and printing out the UV coords for the first few vertices for each model. If they are different, and I expect they are, then the neatest solution is what Dr Tank suggested.

It should take just a few minutes for one of us to fix if TheComet posted the two models and textures.

I'll see if I can find the thread where this was discussed recently.
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 29th Sep 2010 14:28
Is it just me, or that lightmap seems quite inefficient with usage of bitmap space...
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Sep 2010 17:23
I doubt it's the lightmapper's fault. In DarkLIGHTS, for example, the user controls the bitmap size and the quality of the lightmap.
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 29th Sep 2010 18:35
I'm not talking about whose fault it is, but just look at it how big that image is and the actual data in it is a small row... much memory for ugly results if you ask me.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Sep 2010 18:48
Yes.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Sep 2010 19:58
I checked, and the models have different UV data, but they are identical in shape.

I made the lightmap with "LightMapMaker", not quite sure where that came from in the first place.

Quote: "It should take just a few minutes for one of us to fix if TheComet posted the two models and textures."


Ah, third person speech, I like it

I don't think I want to post that particular model, but if it would help I could recreate the same problem using a cube model or something

So how would I go about with copying the UV data using vertexdata commands, and then use blendmapping?

Thanks,

TheComet

Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 29th Sep 2010 20:04 Edited at: 29th Sep 2010 20:11
I've got this working with models exported from CShop. Will post example when tidied up.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Sep 2010 20:23
That's the "one of us" to whom I was referring.
Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 29th Sep 2010 20:42 Edited at: 29th Sep 2010 21:08
Hope this works. Project folder attached. Glad I did this. Will be useful for me too.



Quote: "That's the "one of us" to whom I was referring. "

Took longer than a few minutes though.
Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 29th Sep 2010 20:58
I've spotted a bug! Vertexdata should go from 0 to vertex count-1, instead of 1 to vertex count.

Lines that say
for v=1 to vertcount(1,limb)

should say

for v=0 to vertcount(1,limb)-1
Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 29th Sep 2010 21:07 Edited at: 29th Sep 2010 21:09
File updated. Sorry for triple post.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Sep 2010 21:11
You are not alone. I forget how many times I've had to change



to



Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 29th Sep 2010 21:28
We'll learn eventually.

Currently my project is limited to using one lightmap image. CShop can use more than one though. Most of the example models have 2.

I found a DBP command I hadn't noticed before: limb texture name. Should be able to use this to use multiple lightmaps. Back in a bit.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Sep 2010 21:40
I think limb texture name merely tells you the name of the texture that's applied. If you have multiple light maps you need to think about how they are to be blended with the main texture - I would guess add them together first then modulate the result with the base texture.
Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 29th Sep 2010 21:51 Edited at: 29th Sep 2010 21:52
Quote: "I think limb texture name merely tells you the name of the texture that's applied. If you have multiple light maps you need to think about how they are to be blended with the main texture - I would guess add them together first then modulate the result with the base texture. "

In CShop, it's not a different lightmap for each light. It just makes another lightmap when the current one runs out of space.

What I plan to do is use the command to find what texture each limb of the lightmap object uses, and then apply that texture to stage 1 (base tex is stage 0) of the equivalent limb of the "combined" object.

I've hit a snag in trying to use the cshop example files: the "prefabs", like pieces of furniture, use vertex lighting instead of lightmaps. Not sure how exported models are. Presumably to get a combined model would need to copy across vertex colours or something.

For now will make example with multiple lightmaps but avoid using the prefabs.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Sep 2010 22:13
Thanks a lot Dr Tank!

One thing still left. I just noticed after running Dr Tank's code with my models in it's place that the normal world object has 38 limbs, but the lightmapped object only has 1 limb... :/ Is it possible to change Dr Tank's code a little so it will accept that too?

Thanks,

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Sep 2010 22:14 Edited at: 29th Sep 2010 22:16
Quote: "In CShop, it's not a different lightmap for each light. It just makes another lightmap when the current one runs out of space. "


Sorry - I was forgetting about that. DarkLIGHTS works the same way.

One thing I'm not sure about is whether the lightmapping uses multi-texturing per limb. DBpro probably displays such objects correctly but doesn't allow you to fiddle with them. If it's one texture per limb then no problem - but what would the limb texture name command report in the multi-textured limb case? "One of us" should do a simple experiment.

Edit Actually, there's a perfectly good example from Wilf being discussed right now on the Learning to write shaders thread.
Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 29th Sep 2010 22:33 Edited at: 29th Sep 2010 22:38
Quote: "but what would the limb texture name command report in the multi-textured limb case? "One of us" should do a simple experiment. "

It returns the filename of the texture. The texture filenames are in the model file. You can specify texture stage, but that doesn't matter- the original models have a single texture stage. I don't know whether the command works for objects you're textured in DBP either but again I don't need that.

Quote: "One thing still left. I just noticed after running Dr Tank's code with my models in it's place that the normal world object has 38 limbs, but the lightmapped object only has 1 limb... :/ Is it possible to change Dr Tank's code a little so it will accept that too?"

It depends. It could be that the vertices, despite being lumped together in the same limb, are the same in number, order and position in each model. If so then that should be pretty trivial to implement. I can simulate that by meshing together my lightmap object but can't guarantee it will work for yours.

Light Map Maker looks good BTW. CShop doesn't have radiosity.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Sep 2010 22:46
You've missed the point I was getting at. What does that function return when stage 0 for a given limb has several textures applied, i.e. different "materials" applied to different sets of polys within a limb?
Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 29th Sep 2010 23:06 Edited at: 29th Sep 2010 23:54
Not sure. Good question. It seems that where there are more than 1 texture for a limb, it puts them in different stages, and "limb texture name" allows you to find that. Don't know how they are blended together in DBP. Can't find blend weights in vertexdata. Seems to be a major problem.

What's curious is that the base object can have a number of textures per limb, but then i load the lightmap into stage 0 and it doesn't mess anything up.

First I'll do something that might load Comet's object.
Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 30th Sep 2010 00:22 Edited at: 30th Sep 2010 00:25
Quote: "the normal world object has 38 limbs, but the lightmapped object only has 1 limb... :/ Is it possible to change Dr Tank's code a little so it will accept that too?"

I think it's possible to change the code i posted by swapping 2 1s for 0s, but here's a more understandable version. Hopefully your base and lightmap models have the same number of vertices in the same order. Otherwise it's a much bigger job.

(or you can just make one dark ghosted)

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 30th Sep 2010 14:53
Thanks Dr Tank, but unfortunately that didn't work either... I have decided to attach the 2 models to this post, I hope someone can help me find a solution

Quote: "(or you can just make one dark ghosted)"


I gave that a go, but I only got horrible scrapes through the model, as seen in the following picture:



TheComet

Screen
15
Years of Service
User Offline
Joined: 24th Sep 2010
Location:
Posted: 30th Sep 2010 15:11 Edited at: 30th Sep 2010 15:29
Is it okay for you to load both models?

Not actually shading the textured one, but putting the lightmapped on top of the textured one and make the lighter areas in it transparent.

rem white color is the most transparent:
set image colorkey 255,255,255

rem object that is loaded last will be on top:
load object "textured model", 1
load object "lightmapped model", 2


rem lightmapped model is made transparent.
rem I remember I made it work with the flag being 6,
rem but I dont have DBPro on my computer right now.
rem try different flags from 1 to 6 if not working.
rem what this does is make the lighter areas of the object to
rem be transparent and thus showing the textured object
rem on those areas:
set object transparency 2, 6


btw, I had the textured model as .x -model and so was the lightmapped one. I think this simple way is easy to understand and you may modify this method to your liking.

Please post picture when you get it working. Nice castle.
Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 30th Sep 2010 16:38
That makes things easier. You don't have the same number of vertices in each model, and my above method assumes it did. Wasn't a total waste of time though becuase I can use it for my stuff.

The old ghost method works with a trick though. Don't know why, but objects exported from CShop don't need the trick. Here's the code.



Your models do have the same number of indices though. Think this means they have the same poly count. Counterintuitively the lightmap model has more verts. Maybe you could get a blendmap working by matching up the vert positions, or the polys. Big job though. Perhaps by welding stuff in a modelling program you could get stuff to match.

I imagine you just want this working though. When I read "fused together" in your first post I went off on one.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 30th Sep 2010 17:50
Wow, thank you so much Dr Tank and everyone that helped! I will add this straight to my game now.

TheComet

Login to post a reply

Server time is: 2026-07-24 00:18:32
Your offset time is: 2026-07-24 00:18:32