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 / Multiple detail maps on .x object

Author
Message
Lemonade
17
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 27th Apr 2010 02:43
If I have a .x terrain object object in DBP with a single 1024x1024 texture on it (see texture image below), how can I apply different detail maps to the differently textured areas?

Fantasy Multimedia
16
Years of Service
User Offline
Joined: 20th Apr 2010
Location: Reno, NV
Posted: 27th Apr 2010 05:21
I think Green Gandalf made a shader that accomplishes this. It looks really nice and handles the lighting/shading as well.
Lemonade
17
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 27th Apr 2010 23:11
I looked up his terrain shader thread and tried the demos, but none of them actually added separate detail images to an existing texture. One demo added shading, another manually textured the terrain based on height, etc.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Apr 2010 00:48
You might be able to use the set blend mapping on command.

The easiest way is probably to use a shader as Fantasy Multimedia suggests - although not the particular ones on the terrain shader thread.
Lemonade
17
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 28th Apr 2010 01:05
I'll try blend mapping later, but unfortunately I am shader illiterate.

Thanks for the advice guys.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Apr 2010 01:10
Quote: "I'll try blend mapping later"


Look at the Dark Basic Professional\Projects\Snippets\LerpingTextures code snippet. I think that is exactly what you want - and it uses both methods so you have a difficult choice to make.
Lemonade
17
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 3rd May 2010 22:37 Edited at: 3rd May 2010 22:41
Sorry for the late reply. I tried loading my object into that snippet and I loaded two detail textures in, replacing the "camA" and "camB" .png files. The problem is, that project simply merges two textures onto an object using a mask. What I'm trying to do is to keep my base texture, but layer two *detail* textures on top of it, be it by using that masking technique or something else.

Maybe this will help:



edit: oops, sorry for the big image.

Also, as you can see, the detail texture is only repeating once across the entire terrain. I would need it to repeat multiple times within the area defined my the mask so that it actually adds detail.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd May 2010 23:27 Edited at: 3rd May 2010 23:34
I'm not sure I understand what you're trying to do. Could you explain what you want in more detail? [Edit Actually, thinking about it I probably do know what you want. Do you mean you have a single "base" texture which you want to blend with a two-part detail texture where the two-part detail texture is constructed using two detail maps and a mask texture? If so I'm sure you can just modify the snippet I gave you earlier. If you can confirm this I'll see if I can set it up for you.]

Why can't you use the set blend mapping on command?

You can easily change the tiling using the scale object texture command.
Lemonade
17
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 3rd May 2010 23:55 Edited at: 3rd May 2010 23:56
Thanks for the quick reply! I appreciate whatever help you can give me. Yes, that is exactly what I need. I described it poorly. The option for more than 2 detail maps would be ideal, but that would only complicate things.

I haven't used set blend mapping on because I am unfamiliar with all the blend modes and with the command itself.

I am using blender terrains because they allow for much more detail than advanced terrains. Overhangs, ledges, etc. The problem is, currently it looks great from far above, but from the ground level the texture is blurry. If you can help me get detail maps working then I will be very grateful!

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th May 2010 00:13
OK, I'll see what I can do. I'm fairly sure the existing snippet just needs an extra blending stage at the end using your base texture.

I haven't tried Blender, perhaps I ought to have a look?
Lemonade
17
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 4th May 2010 00:59
Thanks! You should definitely try Blender. Its so powerful that I can't believe it is free. I can post a quick tut sometime on how I sculpt terrains if you want.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th May 2010 01:13
Quote: "I can post a quick tut sometime on how I sculpt terrains if you want."


Yes please! I'm sure many people will find it useful.

Here's the new snippet. I've just modified the blending option (the cube on the right) to show the tiling of the two detail maps plus the blending with a base texture. You may need to change the blend mode for the last blending stage - without your images I had to make a guess as to which would look best. Post back if you have problems with it. The blending looks a bit odd because of the textures used but I think it's close to what you want if you use suitable images.
Lemonade
17
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 4th May 2010 02:46 Edited at: 4th May 2010 02:55
Well...it almost works.

Alright, first off, this is the code I am using:



(note, still using blend mode 5)

And here are the results:



Blend mode 4, otherwise same code:



You'll notice that with both blend modes, there is no text on the right side. Is it only using a part of the textures, like a corner or something?

Second, scaling textures doesn't seem to do anything. Note that I remmed out that "scale object texture" line you added just so I could make sure it wasn't messing anything up.

I'm not sure what is going on here. Do you want the files?

EDIT:

Here it is: http://www.mediafire.com/?fn0gg3iqmzm

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th May 2010 13:00
The demo I gave you assumes that the object's vertices are all in limb 0. You'll need to modify the code so that each limb has the extra stage UV data - and if your object already has stage 1 UV coords (for a lightmap perhaps) then you'll need to modify the code to use a different stage. My guess is that your object doesn't have any vertices in stage 0 - or has many limbs of which limb 0 is only a small part.

What you probably need to do is something like the following (assuming your object doesn't already have stage 1 UV coords).

Instead of



use



If that doesn't work (untested, so you may need to fix minor errors ) post your X file or email it to me and I'll see what the problem is.

[Ah! Just seen your edit at the end. I'll look at the link and post back soon. ]
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th May 2010 13:07 Edited at: 4th May 2010 13:07
Yes. I think that fixed it. Here's a screenshot.

Lemonade
17
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 4th May 2010 20:29 Edited at: 4th May 2010 20:44
Thank you, it works beautifully! I've been trying to get details maps working for so long.

One final question. If I wanted the detail textures to be from texture stage 3 and up (to leave stages 1-2 open to experiment with shaders like bump\parallax), what would I need to modify? All I know for sure is that I would have to change the texture stages of the set blend mapping on lines to something like this:



That way stage 0 is the base texture, but the other detail textures start at 3, leaving stages 1-2 open.

However, would I need to change:

set vertexdata UV v,1,get vertexdata U(v,0),get vertexdata V(v,0)

to

set vertexdata UV v,1,get vertexdata U(v,3),get vertexdata V(v,3)

?

And this line just confuses me.

convert object fvf 2, 530 ` = XYZ+NORMAL+UV0+UV1 = 0x002+0x010+0x200 = 2+16+512

How would I need to change that?

Sorry for more questions, but I promise, they are my last.

EDIT:

Here's a screen of multiple detail textures in action:



Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th May 2010 23:07 Edited at: 5th May 2010 00:09
***EDIT!! Sorry!!. Just noticed that your second parameter is wrong too. Must eat supper now - but will come back and edit the rest of this post as soon as I can.***

2nd Edit The second parameter of the set blend mapping on is the texture blending stage and should be numbered consecutively from 0. In your case you are using four blending stages so the second argument should be 0, 1, 2 and 3 for the four blending stages used in your snippet. (I'm not sure what happens if you miss stages out - you might get strange results as you will be relying on default behaviour for the those missing blending stages.)

Original reply follows.

OK. Several questions there. I'll try to answer them.

Question 1

Quote: "If I wanted the detail textures to be from texture stage 3 and up (to leave stages 1-2 open to experiment with shaders like bump\parallax), what would I need to modify?"


You need to make sure that the TexCoordMode parameter (the fourth parameter) of the set blend mapping on command is pointing to the right set of UV coords. You want four I believe, i.e. stages 0 to 3. The earlier demo had two, i.e. stages 0 and 1. So let's look at your suggestion:



The first blending stage (stage 0) has TexCoordMode set to 3 - i.e. "Steal UV Data From Stage Zero". This means that the first blending stage in your snippet uses the UV0 coords. TexCoordMode 0 would have had the same effect in this case.

The second blending stage in your snippet has TexCoordMode set to 0, i.e. "Regular UV Stage Match". Since this is stage 1 (remember blending stages start with 0 so stage 1 is the SECOND blending stage ) it's telling DirectX to use the UV1 coords. This is not what you want - you want it to use the stage 3 coords for the detail texture. To do this you need to specify TexCoordMode = 13 (as 3 = 13-10 - see Help file).

The third blending stage in your snippet also needs to use the stage 3 UV coords so that should also have TexCoordMode = 13. At the moment it is 11 which means use the stage 1 (= 11-10) UV coords which you say will be reserved for something else.

The fourth blending stage in your snippet has TexCoordMode = 3 which means "Steal UV Data From Stage Zero". Since this is the base texture that is what you want.

One word of caution. You should think about whether you really need two extra sets of UV coords - i.e. are you sure you can't use the existing stage 0 or stage 1 coords? Don't worry, it's quite possible you do need them.

Question 2

Quote: "However, would I need to change:

set vertexdata UV v,1,get vertexdata U(v,0),get vertexdata V(v,0)

to

set vertexdata UV v,1,get vertexdata U(v,3),get vertexdata V(v,3)

?"


No. You want the existing stage 0 coords to be copied into stage 3, i.e.



Question 3

Quote: "And this line just confuses me.

convert object fvf 2, 530 ` = XYZ+NORMAL+UV0+UV1 = 0x002+0x010+0x200 = 2+16+512

How would I need to change that?
"


In that line 0x002 means that the vertex data will contain the familiar position data, i.e. the XYZ coords. Similarly, 0x010 means the vertex data will contain normals (I assumed you needed these) and 0x200 means use two sets of texture UV coords, i.e. UV0 and UV1. In your case your want four sets of UV coords (UV0, UV1, UV2 and UV3) so you need the hexadecimal value 0x400 which is 1024 in decimal. Assuming you need normals then your FVF format needs to be 0x002 + 0x010 + 0x400, i.e. 2 + 16 + 1024 in decimal, i.e. 1042. The Help file tells you what the different values correspond to (it is somewhat opaque I agree ).

Quote: "One final question."


Can you count?

Quote: "Sorry for more questions,"


No problem.

Quote: "but I promise, they are my last."


Lemonade
17
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 5th May 2010 01:10 Edited at: 5th May 2010 01:11
Quote: "Can you count? "


Umm...I guess not.

OK...so I'm going to try this out. The whole reason I need to do this is because I found a awesome parallax\lighting shader that, combined with detail maps, would be amazing. It requires the diffuse, height, and normal maps to be in the first three texture stages to work.

Thanks for the detailed explanation (yet again!).

I'm hoping this will work.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th May 2010 01:54
Quote: "The whole reason I need to do this is because I found a awesome parallax\lighting shader that, combined with detail maps, would be amazing. It requires the diffuse, height, and normal maps to be in the first three texture stages to work."


I'm fairly sure you'll need to do the detail mapping in the shader because the shader will replace the DirectX pipeline texture blending used by DBPro. Shouldn't be too difficult to fix the shader once it's clear what you're trying to do - for example, what relation do the detail maps have to the height and normal maps?
Lemonade
17
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 5th May 2010 02:03
Quote: "I'm fairly sure you'll need to do the detail mapping in the shader because the shader will replace the DirectX pipeline texture blending used by DBPro."




Quote: "Shouldn't be too difficult to fix the shader once it's clear what you're trying to do - for example, what relation do the detail maps have to the height and normal maps?"


Well, I was trying to decide whether the base texture or the detail textures should be bumped. I think bumping the base would be better. If that were the case, then the detail maps would simply need to be overlaid after the bump\height maps? I don't wan't you to do more work though, you've done enough.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th May 2010 17:08 Edited at: 5th May 2010 17:22
Quote: "Well, I was trying to decide whether the base texture or the detail textures should be bumped"


It's only worth using the base texture if it has much higher resolution than the terrain itself. If not then you might as well use the terrain's normals.

Quote: "I don't wan't you to do more work though, you've done enough."




[Edited spelling. ]

Login to post a reply

Server time is: 2026-07-28 03:05:11
Your offset time is: 2026-07-28 03:05:11