Skip to main content
GameDev.net gamedev.net
🔒 Locked

Multitexturing without Shaders

Started by directNoob Jul 23, 2006 at 5:35 AM 11 replies 2.1k views
Original Post
directNoob
directNoob
Hello. I want to texture my terrain with multible textures and with their corresponding grayscale maps. I mean, for Example, the 1st texture is dirt and I multiply it with the corresponding grayscale. For the next stage the same and so on. That you can imagine this a bit better, I made this: pic In DX, I use this:

pDev->SetTexture(0, m_tile.m_img[0]);
pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);

pDev->SetTexture(1, m_tile.m_imgMask[0]);
pDev->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
pDev->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
				
pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);

This is the dirt texture. But how can I save the result from this operation? Or how can proceed working with the result of this stages op? I want to add the reslut from the first texture op with the result from the next texture op. And so on. How can I do this? Thanks Alex
Demus79
Demus79

You have to enable the blend operation. That is, blending between the pixel being calculated and the back buffer. Set the SrcBlend to SrcAlpha and DstBlend to InvSrcAlpha.

That should result what you are looking for. This requires however multiple passes, one for each texture/alpha combination.

Cheers
directNoob
directNoob
Hallo.

What I have so far is this:
multi2

It works well with the source code I posted in the first post.
But I need the result from that! I need to save it or something.

Are you sure I have to use the method you mentioned.
I thought I can use the SetTextureStateStage method instead of the
srcblend and alphablend method???
This shouldn´t mean that I won´t try it...

The picture shows what you can see on the first picture above.

Thanks
Alex
directNoob
directNoob
I knew that it would work.

Look at this:
multi3

And this is how I did it:
pDev->SetTexture(0, m_tile.m_img[0]);pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);pDev->SetTexture(1, m_tile.m_imgMask[0]);pDev->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);pDev->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);pDev->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);				pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);// Save the result in the temp register... this works!!!:)))pDev->SetTextureStageState(1, D3DTSS_RESULTARG, D3DTA_TEMP);// load env imagepDev->SetTexture(2, m_tile.m_img[1]);pDev->SetTextureStageState(2, D3DTSS_TEXCOORDINDEX, 0);pDev->SetTextureStageState(2, D3DTSS_COLORARG1, D3DTA_TEXTURE);pDev->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_SELECTARG1);				// load grayscale mappDev->SetTexture(3, m_tile.m_imgMask[1]);pDev->SetTextureStageState(3, D3DTSS_TEXCOORDINDEX, 0);pDev->SetTextureStageState(3, D3DTSS_COLORARG1, D3DTA_TEXTURE);pDev->SetTextureStageState(3, D3DTSS_COLORARG2, D3DTA_CURRENT);				// multiply the env and the gray scale image pDev->SetTextureStageState(3, D3DTSS_COLOROP, D3DTOP_MODULATE);// select the temp saved result.pDev->SetTextureStageState(4, D3DTSS_COLORARG1, D3DTA_TEMP);// Select last result.pDev->SetTextureStageState(4, D3DTSS_COLORARG2, D3DTA_CURRENT);// Add it together.pDev->SetTextureStageState(4, D3DTSS_COLOROP, D3DTOP_ADD);


But, as you may have noticed, you quickly run out on texture stages[ts]!!
What can I do to avoid running out of it?
I mean, I need 1 ts for the dirt. Then I need 1 ts for its grayscale map.
And then multiply it together.
Then I need 1 ts for the grass. Now I am at ts No.3. Now I need 1 for its gray scale map again. Now we are at ts No 4. And last but really not least, I furthermore need 1 for the add action. And that are 5 ts for two textures to blend together! Too much when you ask me!
Can I reuse a ts?

Thanks
Alex
sirob
sirob
With the FFP, you're pretty limited in the number of textures you can simultaneously blend. Even with shaders, you'll eventually hit a limit, especially in the lower shader models.

You'll need to use a multi-pass approach. This is described breifly in this tutorial here on GameDev.net. That should be enough to get you started, though.

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.
directNoob
directNoob
Hello again.

First of all, here is a pic of what I have produced:
DetailTerrain

But I have to say, this is so unsatisfactory to me, you can´t imagine!!!
This is one texture mixed with all colors needed for a particular region.
And then I added the detail texture to the terrain texture, with the fabulous
multitexturing unit, or isn´t it that fabulous?

This is absolutly unsatisfactory to me, (man)!!!

It is not only the texture, it is everything!
What if I want to add more detail maps to my terrain?
What if I don´t want to have my cpu made the terrain texture, but the gpu?
What if I want to add more detail to it?
And what if I just want to use more textures???

The first method I wanted to use, is the better approach, I think. But as I said, this is impossibe with multipass texturing and also with mulittexturing(meaning one pass).
Just imaging you want to use more textures!?
Then you have one alphamap for each texture. I suppose...
And I also suppose one detail map for each texture...

But how to get out of this dilemma???
Shaders?

I mean, I can´t believe it, abosolutely not!

I would prefer to do it with these alphamaps, but definitively not with alpha blending, in terms of SetRenderState(D3DRS_ALPHABLENDENABLE...
When I have 10 textures, then I can render that terrain ten times.
I even disagree to the fact to render the terrain twice!!!
Absolutely unbelievable. I´m telling you...

I´m totally disappointed.
Please help me to find a way out of this tragically dilemma.

It´s
Alex
griffin2000
griffin2000
So what exactly is wrong ? That you cannot blend enough textures ? Or how they are blended ?
directNoob
directNoob
First, look at this...
light
light

Right now, I feel a bit better, because I listen to fabio, radio one, check this. Easy easy easy.
however.

Yes, exacly my point.
I can´t blend enough textures.
How can I do this?
For example 10 to 20 textures?
Do I have to use shaders? I have never worked with shaders before, but I´m ready to lern it!!!
And the other problem is, every f****** book I have, doesn´t work this topic out.
Maybe it is so easy that nobody want to talk about, I can´t understand this...
Please tell me!

Yep, on gameDev and flipcode, I found something, but this is also not satisfying.
This Bloom guy has something which is different, and I haven´t tryed it yet.

I also take the future into account, where I want to implement a tool which can alter the terrain.

I need some help please.

Alex.
ViLiO
ViLiO
With shaders it would almost certainly be possible, but I think you are approaching it from an angle that would be very bad for performance.

- Do you really need 10-20 textures blended together real-time?
- Could you do this as a pre-process and just load it at one larger texture at run-time and then have 2-3 "detail textures" blended underneath?
- Do you need to be performing all these blending operations on the whole terrain? (if your player was at one side of the terrain and there were hills in the distance then this kind of texture detail isn't needed on those hills)
- Could you split your terrain up into nodes (e.g. a quadtree) and impose a limit of 3-5 textures for each node?

I'm sorry I can't really be of more help but I think the reason books and other sites don't work this topic out is because having an such a large number of blended textures isn't really needed [smile]

All the best,
ViLiO
Richard 'ViLiO' Thomasv.net | Twitter | YouTube
SAE Superman
SAE Superman
Why don't you just procedurally generate a new texture and forget about the blending... Here's a link to some examples:

Ultimate Game Programming

Check out the CTerrain::GenerateTextureMap() function in particular.

Hope that helps...
directNoob
directNoob
@SAE Superman:
Thanks for the link, I still wasn´t there. Thanks.

@ViLiO:
Alright, and what do you suggest?
I want good looking terrain texturing. The one texture approach looks to simple.
"pre-process" that sounds good. This was my mind. What is in my mind, is that when you alter the terrain, for example, a tool(future thoughts) alters the alpha map and than the progamme should "regenerate" the terrain texture by blending it together.
But not realtime. Sorry if my posts pretent this thought...
Quadtree? No not right now. I´m working on goemipmapping and when this works, I will go straight to it, quadtree.

So this might be your suggestion, I understand.

Thanks.

Its
Alex

P.S.
@SAE Superman:
But I´m using a procedurally generated texture according to the height map.
SAE Superman
SAE Superman
Quote:
Original post by directNoob
P.S.
@SAE Superman:
But I´m using a procedurally generated texture according to the height map.


Yes, I know...that's exactly what I do. Looking at your first diagram, I think this is the kind of thing you want. I too look at every height value and "blend" two textures together. I have 5 total textures: water, dirt/sand, grass, rocks (mountains), and snow/ice (top of mountains). Each texture has three values associated with them: low height, optimal height and a high height. You then get a percentage of the two closest textures for each height value and blend together whatever percentage for each texture you need. Download the terrain texture generation demo, run it and see if that's what you're looking for. It has 4 textures I believe (doesn't have a water texture). You can step through the code and figure out how to do it. I wish I had a hosting place to upload some pics of the textures I generated from my terrains...

Here's an example:

Dirt texture: low = 100, optimal = 150, high = 200.
Rock texture: low = 151, optimal = 250, high = 300.

Now lets say you have a height value of 160 for a pixel. You would then take a certain percentage of the dirt and the rock textures and blend them together for that pixel. Once you do that for all your height values, you have a texture you can use. That's the jist of it...there's more to it than that but that's the high level concept.
directNoob
directNoob
Hi SAE Superman.

The procedure you described to create a terrain is exactly the same I use.
I have it out of the book "Focus on 3D Terrain Programming". In some way, this book is usefull(OGL to DX conversion is a bit stressy).
But the bad thing of this way of creating terrain textures is, that it burden the CPU. And I don´t want to burden my CPU to much, it has enough to do, you see? I have a nice graphiccard, a ATI X1600. I think it is better to have the graphiccard handle this kind of things. But the multitexturing unit is not the right way, because it has just 8 stages. This means, texture + detailmap + lighting ... is to much for the MT- unit, I think(nobody said that it work).
There must be another way of precreateing the terrain texture!!!

But as ViLiO said, it´s still not good to render so much textures every time/frame.
I think, I should proceed till I have learned some techiques like quadtree or goemipmapping and then see how to apply some textures very intelligent.

There are still some topics I haven´t worked through. For example frustum culling.
I should accept the current situation, till I know more, like PS or VS for example.

And for my task, the CPU can also handle the precreation of the texture.

Thanks and greetings
Alex

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.