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 / Texture splatting in DBpro

Author
Message
DaveC9000
18
Years of Service
User Offline
Joined: 15th Jan 2006
Location:
Posted: 8th Jun 2006 11:22
I've noticed that texture splatting (single-pass multitexturing) is a topic that's never raised on this board. I figured it is either because nobody thinks it's possible, or everyone but me already knows how to do it. Advanced Terrain is nice, but there's only so much you can do with one detail texture. Well after days of shader-writing in Notepad and a ton of 3D memory errors I ended up with the contents of the attached image.

How great would it be if someone wrote an Advanced terrain-like DLL that could do this.

Attachments

Login to view attachments
Thebeely
18
Years of Service
User Offline
Joined: 4th May 2005
Location: Croatia
Posted: 8th Jun 2006 14:27
Whoa! Nice terrain, m8! But I'm not sure what are you trying to do here...


Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 8th Jun 2006 14:42
I desperately would like to be able to do this, but don't have the faintest idea where to start.

Any clues Dave?
DaveC9000
18
Years of Service
User Offline
Joined: 15th Jan 2006
Location:
Posted: 9th Jun 2006 01:09 Edited at: 9th Jun 2006 01:11
TheBeely: I am trying to break the silence on this issue. Nobody ever talks about texture splatting on here, which I find strange considering that this is a method that most commercial games use. There are a lot of people who are way better at this stuff than I am, and I'm hopeing to see how other people have approached this in DBPro.

Dream And Death: You should check out my shader. Even if you don't want to use it (it's far from perfect, but it works) it may give you some ideas. Here's how it's used:

In DB, load the fx file and set some options

Load your terrain object. If your terrain is one large object then you may have to split it up, as the shader dosen't seem to be able to render really large objects.

Texture the object. The layers should go as follows:
layer 0 - lightmap
layer 1 - base texture
layer 2 - layer 2 alpha map
layer 3 - layer 2 texture
layer 4 - layer 3 alpha map
layer 5 - layer 3 texture
layer 6 - layer 4 alpha map
layer 7 - layer 4 texture

If you do not have a lightmap, you can simply texture layer0 with a white image, or you can change the technique to "mt3a" (the default is "mt3aLM"). If you only wanted to use...say...the base texture and one alpha layer you would have to change the "layers" variable to 2.

After that you just set the effect like so:


The fx file is attached to this post.

Attachments

Login to view attachments
jrowe
21
Years of Service
User Offline
Joined: 12th Oct 2002
Location: Here
Posted: 9th Jun 2006 01:43
WOW, that looks GREAT! I've been hoping for a way to do this in DBpro. Can you tell me which shader version the .fx file requires?

Tinnedhead Productions

For Fathers and Sons who enjoy wholy spirits.
DaveC9000
18
Years of Service
User Offline
Joined: 15th Jan 2006
Location:
Posted: 9th Jun 2006 03:13
This one requires pixel shader 2.0, but maybe someone who's good at writing shaders (This is my first one ever) could make one that works below that.
jasonhtml
20
Years of Service
User Offline
Joined: 20th Mar 2004
Location: OC, California, USA
Posted: 9th Jun 2006 04:42
i dont get it.. it just looks like a normal terrain to me...

Deathquest (MMORPG)
Deathquest Thread: http://forum.thegamecreators.com/?m=forum_view&t=61108&b=8
DD Studios Website: http://www.geocities.com/jasonhtml/
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 9th Jun 2006 05:44
Quote: "i dont get it.. it just looks like a normal terrain to me..."



also , i made a topic about this only i used the term multi texture layers as my ideas would be usefull for more than just terrains, however nothing really came of the topic, i got a link to van-b`s terrain layer system, which isnt bad just a very slow method as each layer duplicated the terrain, i know this can be done in dbp as ive had megaton be my pawn and make some terrains in 3dws one with 1 texture layer and another with 10 layers, the 10layer one only had a slightly fps drop which is greatm and i really hope tgc add uv layer and opacity commands to the vertex manipulation commands as they are currently of limited use.

Hallowed are the ori.
jasonhtml
20
Years of Service
User Offline
Joined: 20th Mar 2004
Location: OC, California, USA
Posted: 9th Jun 2006 06:18
o, a face... SO helpful

Deathquest (MMORPG)
Deathquest Thread: http://forum.thegamecreators.com/?m=forum_view&t=61108&b=8
DD Studios Website: http://www.geocities.com/jasonhtml/
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 9th Jun 2006 07:18
perhaps if your iq was above that of bread, then you would realise that isnt normal terrain and the fact that he even made+posted the shader to make it shows that it definently isnt soooo,
Quote: "SO helpful"
take your own advice..

Hallowed are the ori.
DaveC9000
18
Years of Service
User Offline
Joined: 15th Jan 2006
Location:
Posted: 9th Jun 2006 08:08
Quote: "which isnt bad just a very slow method as each layer duplicated the terrain"


Yeah that sounds like multi-pass multitexturing. It is way slower than using shaders, however it gives you the advantage of unlimited texture layers. I've actualy been working on another shader like this that looks in the texture's alpha channel for the alpha map. Maybe have a DBPro function that stores a grayscale image in another image's alpha channel, then you could have a lightmap AND base texture in layer 1 with 7 alpha layers. I'm just not sure how to write that function in DBPro.
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 9th Jun 2006 15:04
jasonhtml: In short what Dave's code allows you to do is put multiple textures on a terrain. Eg. Grass, dirt, roads, and detail.

Sure as hell blows my socks off with the possibilities!

Dave - maximum of 8 I'm guessing?
adr
20
Years of Service
User Offline
Joined: 21st May 2003
Location: Job Centre
Posted: 9th Jun 2006 19:30
I've read several articles on Texture Splatting - including the infamous one on flipcode... Unfortunately, as I enter my 57th working hour so far this week I can't remember the specifics.

All other languages seem to be able to do it without shaders. They seem to just be able to access the texture stages ... which we can also do:


What we need to do is find out what all the freakin magical numbers do in set texture blend mode and we'll be well on our way.

[center]
But you see, I have the will of the warrior. Therefore, the battle is already over. The winner? Me!
jrowe
21
Years of Service
User Offline
Joined: 12th Oct 2002
Location: Here
Posted: 9th Jun 2006 19:44
Quote: "What we need to do is find out what all the freakin magical numbers do in set texture blend mode and we'll be well on our way.
"


Is this a new command, or do you mean Set Blend Mapping On??

http://dbp.tgchelp.com/index.php?nav=dbhelp&command=149

Tinnedhead Productions

For Fathers and Sons who enjoy wholy spirits.
adr
20
Years of Service
User Offline
Joined: 21st May 2003
Location: Job Centre
Posted: 9th Jun 2006 19:55 Edited at: 9th Jun 2006 19:59
Quote: "Is this a new command, or do you mean Set Blend Mapping On?"

I do mean Set Blend Mapping On - thank you.

This article here makes an interesting case for using a PS1.4 shader to do the blending for us.

I don't get what's happening though. Would I be right in thinking you've got say, 3 tileable textures - grass, dirt, and rock. Those are applied to sepearate stages or UV layers, and are tiled across the entire terrain. The objective here is to let certain layers "peek" through to the top, using alpha blending.

Do you have a giant, terrain-sized alpha map per texture (one for grass, one for rock, one for dirt)? If this were the case, then you could have up to 4 layers. (one alpha map per texture = 8 stages, the max number of stages/UV layers imposed by DX)

this also mentions this technique ... but instead of using monochrome alpha maps, it uses the R G and B components.

I'm struggling to put it all together.... if someone could explain that would be greatly appreciated.

[center]
But you see, I have the will of the warrior. Therefore, the battle is already over. The winner? Me!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 9th Jun 2006 20:50
Wouldn't it just be easier if DB would finally support the extra texture layers of X model files?

Quote: "3 tileable textures - grass, dirt, and rock. Those are applied to sepearate stages or UV layers, and are tiled across the entire terrain. The objective here is to let certain layers "peek" through to the top, using alpha blending. "

yea you got it.

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
adr
20
Years of Service
User Offline
Joined: 21st May 2003
Location: Job Centre
Posted: 10th Jun 2006 01:05
Quote: "yea you got it."

It's the "how you blend the layers" bit I don't get - i.e.

Quote: "Do you have a giant, terrain-sized alpha map per texture (one for grass, one for rock, one for dirt)? If this were the case, then you could have up to 4 layers. (one alpha map per texture = 8 stages, the max number of stages/UV layers imposed by DX)"

Assuming that's the case, how would you get DBPro to do the stuff there?

[center]
But you see, I have the will of the warrior. Therefore, the battle is already over. The winner? Me!
DaveC9000
18
Years of Service
User Offline
Joined: 15th Jan 2006
Location:
Posted: 10th Jun 2006 02:59
The alpha map is a grayscale image that determines how much of the next texture to draw on each pixel. Think of it as black being transparent and white being opaque. The value of the alpha map is used to interpolate between the current texture and the next texture. The usual method is to stretch these across the entire object, but really you could do it however you want.

And yes, This does limit you to 4 layers. There are ways to extend that however, such as packing the alpha maps into one image. You only need one channel of the map anyway, so you could store one in the R,G,B,and A channels of an image. I'm also looking into the possibility of reading the alpha maps from the alpha channel of the textures themselves. The bad side would be that your texture and alpha maps would have to be the same size, but you could get 8 layers out of it if it worked.
jasonhtml
20
Years of Service
User Offline
Joined: 20th Mar 2004
Location: OC, California, USA
Posted: 10th Jun 2006 03:08
@dark coder, ur never helpful...

@Dream and Death and everyone else helpful: well, i know thats what his shader is SUPPOSED to do, but whats the point? thats what i dont get? can't you just make 1 texture with all of it in it?

Deathquest (MMORPG)
Deathquest Thread: http://forum.thegamecreators.com/?m=forum_view&t=61108&b=8
DD Studios Website: http://www.geocities.com/jasonhtml/
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 10th Jun 2006 03:45
Quote: "i know thats what his shader is SUPPOSED to do, but whats the point? thats what i dont get? can't you just make 1 texture with all of it in it?"


clearly you dont know its purpose, and afouce you cant just use one texture as it would be incredibly ineffiecient and take up too much disc space if you wanted a texture larget than 10m.

and @DaveC9000, no van-b`s method just duplicated the terrain mesh which made it a almost usless method

Hallowed are the ori.
Chenak
21
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United Kingdom
Posted: 10th Jun 2006 03:53
Great peice of work! Shame there doesn't seem to be a nice and easy way to do this on none or low shader compatible cards.

@jasonhtml:

If you were making an mmorpg then you would know exactly what this does and you would be praising the shader. It enables you to use more than one texture on a terrain object with blending using an alpha map. In otherwords texture splatting, a method used by pretty much all games with terrains.

It is helpful because DBpro does NOT allow this in it's terrains, they only can have one big texture and one detail map. Look it up if you still don't understand, it is not a very difficult concept.
jasonhtml
20
Years of Service
User Offline
Joined: 20th Mar 2004
Location: OC, California, USA
Posted: 10th Jun 2006 04:07
@dark coder and chenak: well, i understand now, but you dont have to act like im stupid for not knowing something; im sorry i dont know absolutely everything there is to know about programming.

Deathquest (MMORPG)
Deathquest Thread: http://forum.thegamecreators.com/?m=forum_view&t=61108&b=8
DD Studios Website: http://www.geocities.com/jasonhtml/
adr
20
Years of Service
User Offline
Joined: 21st May 2003
Location: Job Centre
Posted: 10th Jun 2006 14:08 Edited at: 10th Jun 2006 14:22
Quote: "I'm also looking into the possibility of reading the alpha maps from the alpha channel of the textures themselves. The bad side would be that your texture and alpha maps would have to be the same size, but you could get 8 layers out of it if it worked."

The beauty of not doing it that way is that you can have very high resolution repeating textures, rather than several huge 2048x2048, badly stretched textures.

JasonHTML > to put it more pleasantly, one large texture over the entire terrain looks ugly, and also requires a lot of texture memory. Using "texture splatting" gives you a nice solution, in that all your textures are tileable, so they look incredibly detailed. But, unlike a DBPro Matrix, you don't have to have "transition" tiles in order to change from one texture to another, you use alpha mapping. Now, that can either be carried out by the engine "manually" or you can get a shader to work it out for you. The shader will do a much more efficient job, and will therefore be faster.

Without someone from the TGC Dev team piping up, it looks like our only hope to do this is with shaders.

[center]
But you see, I have the will of the warrior. Therefore, the battle is already over. The winner? Me!
Chenak
21
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United Kingdom
Posted: 10th Jun 2006 14:57
@jasonhtml:
I was actually being serious and not calling you stupid (not meaning to anyway ). It is actually a fairly difficult thing to do and understand (in dbpro anyway), and if you don't understand it look it up on gamedev or something because it is a very handy thing to have. You can use this method to produce some interesting effects on levels too.

I'd have thought you'd have known about it since you are making an mmo with large terrains, unless you are using a different method to produce worlds (or making one set in space ). Terrains just look kinda crappy with one texture and a detail map /poke tgc
DaveC9000
18
Years of Service
User Offline
Joined: 15th Jan 2006
Location:
Posted: 11th Jun 2006 08:40 Edited at: 11th Jun 2006 14:21
Here is an updated version of my shader. I even wrote a short manual for it that shows how to use it. Here are some of the changes:

- Added the "lightmap" variable to turn lightmapping on and off.
- Changed the mt3a technique to support color lightmaps.
- Removed the mt3aLM technique because it is no longer necessary.
- Added these new techniques:
mt5a - gives you six layers total by packing alpha maps into the R,G and B channels of an image. This has not been fully tested yet. Check out the manual for more info.
mt7a - Uses the alpha channel of the textures themselves for the alpha map, which gives you a total of 8 layers! I've tested this one and it does work.

These new techniques are nice, but it would be ideal if I could come up with a function in DBPro that combines the images at runtime, but I haven't had time to look into that yet.

Attachments

Login to view attachments
DaveC9000
18
Years of Service
User Offline
Joined: 15th Jan 2006
Location:
Posted: 11th Jun 2006 08:45
Here is another screenshot of a terrain with six textures using the mt7a technique. I made the lightmap slightly orange to make it look like sunset, but the lack of a sky in my test program kills the effect.

Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Jun 2006 10:11
looks great, i sure hope those are frame rate numbers.

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 11th Jun 2006 12:07
Actually with two, I'm guessing they are co-ordinates!
adr
20
Years of Service
User Offline
Joined: 21st May 2003
Location: Job Centre
Posted: 11th Jun 2006 12:29
Quote: "looks great, i sure hope those are frame rate numbers."

In theory, if a shader's doing it, then the framerate should be high. If not, then the shader could be optimised to get some more frames out of it.

@DaveC9000
That looks super sweet dude. You've tempted me into moving back onto my terrain project.

[center]
But you see, I have the will of the warrior. Therefore, the battle is already over. The winner? Me!
DaveC9000
18
Years of Service
User Offline
Joined: 15th Jan 2006
Location:
Posted: 11th Jun 2006 21:52
That program was actually made to test building memblock meshes from RAW files. The terrain is split up into sections based on how big it is. That first number there is the width of one section. I can't seem to get Object in screen to work with the sections, so I had to turn off my culling function to test the shader. The second number is the framerate, but it fluctuates wildly with or without textures because my terrain isn't working right (yet).

Login to post a reply

Server time is: 2024-04-30 22:21:01
Your offset time is: 2024-04-30 22:21:01