Jump to content

  • Log In with Google      Sign In   
  • Create Account


Texture Splatting Using SetTextureStageState() and SetRenderState()


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
22 replies to this topic

#1 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 23 April 2013 - 02:49 AM

If I have 2 different textures and want to blend them together with blending map:

device->SetTexture(0, &blendingMapTexture);
device->SetTexture(1, &grassTexture);
device->SetTexture(2, &stoneTexture);
 
I want someone to tell me what should I give to:
device->SetTextureStageState() and device->SetRenderState()
 
To make it work.


Sponsor:

#2 belfegor   Crossbones+   -  Reputation: 2495

Like
0Likes
Like

Posted 23 April 2013 - 04:17 AM

Texture Splatting in Direct3D This is exactly what you need.



#3 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 23 April 2013 - 04:20 AM

I tried the tutorial before, but couldn't get it to work, can you directly give me what device->SetTextureStageState() and device->SetRenderState() values that I need to set to make the following works:device->SetTexture(0, &blendingMapTexture);

device->SetTexture(0, &blendingMapTexture);
device->SetTexture(1, &grassTexture);
device->SetTexture(2, &stoneTexture);

Edited by Medo3337, 23 April 2013 - 04:25 AM.


#4 belfegor   Crossbones+   -  Reputation: 2495

Like
0Likes
Like

Posted 23 April 2013 - 04:43 AM

OMG. Medo3337, there is a demo with source, you just have to copy-paste relevant parts that you need:

//-----------------------------------------------------------------------------
// Render using the fixed function pipeline
//-----------------------------------------------------------------------------
void RenderWithoutShader() {
    // Alphamap: take the alpha from the alphamap, we don't care about the color
    g_Direct3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
    g_Direct3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

    // Texture: take the color from the texture, take the alpha from the previous stage
    g_Direct3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
    g_Direct3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
    g_Direct3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
    g_Direct3DDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);

    // Disable textures from the pixel shader mode
    g_Direct3DDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
    g_Direct3DDevice->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

    // Disable the pixel shader
    g_Direct3DDevice->SetPixelShader(NULL);

    g_Direct3DDevice->SetTexture(0, g_Alphamap1);
    g_Direct3DDevice->SetTexture(1, g_Texture1);
    g_Direct3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Vertices, sizeof(QuadVertex));

    g_Direct3DDevice->SetTexture(0, g_Alphamap2);
    g_Direct3DDevice->SetTexture(1, g_Texture2);
    g_Direct3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Vertices, sizeof(QuadVertex));

    g_Direct3DDevice->SetTexture(0, g_Alphamap3);
    g_Direct3DDevice->SetTexture(1, g_Texture3);
    g_Direct3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Vertices, sizeof(QuadVertex));

    g_Direct3DDevice->SetTexture(0, g_Alphamap4);
    g_Direct3DDevice->SetTexture(1, g_Texture4);
    g_Direct3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Vertices, sizeof(QuadVertex));
}


#5 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 23 April 2013 - 05:24 AM

The way that I'm drawing the terrain differ from the sample.

 

I have exported terrain and drawing it ONCE, in the above example, it's drawing the terrain 4 times to set 4 textures which I think it's not a good idea for performance.

 

I want to accomplish texture splatting without Shader and draw the terrain once.

 

The way that I want to do it is exactly as I mentioned:

 

device->SetTexture(0, &blendingMapTexture);
device->SetTexture(1, &grassTexture);
device->SetTexture(2, &stoneTexture);
// Code to draw terrain here...

and NOT this:

device->SetTexture(0, &blendingMapTexture);
device->SetTexture(1, &grassTexture);
// Code to draw terrain...
device->SetTexture(0, &blendingMapTexture);
device->SetTexture(1, &stoneTexture);
// Code to draw terrain again...


#6 belfegor   Crossbones+   -  Reputation: 2495

Like
0Likes
Like

Posted 23 April 2013 - 06:02 AM

I am currently playing with FFP texture splatting, although i am not familiar with it as i am doing this same thing with shaders.

Try this (one pass):

NOTE: blendmap should be grayscale image with no alpha!

 

d3d9device->SetTexture(0, terrBlendTex);
        d3d9device->SetTexture(1, terr1Tex);
        d3d9device->SetTexture(2, terr2Tex);

        d3d9device->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
        d3d9device->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
        d3d9device->SetTextureStageState( 2, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );

        D3DXMATRIX blendmapTrans, tex1Trans, tex2Trans;
        D3DXMatrixScaling(&blendmapTrans, 1.f, 1.f, 1.f);
        D3DXMatrixScaling(&tex1Trans, 32.f, 32.f, 32.f);
        D3DXMatrixScaling(&tex2Trans, 4.f, 4.f, 4.f);
        d3d9device->SetTransform( D3DTS_TEXTURE0, &blendmapTrans );
        d3d9device->SetTransform( D3DTS_TEXTURE1, &tex1Trans );
        d3d9device->SetTransform( D3DTS_TEXTURE2, &tex2Trans );

        d3d9device->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
        d3d9device->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 0 );
        d3d9device->SetTextureStageState( 2, D3DTSS_TEXCOORDINDEX, 0 );

        d3d9device->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 2, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );

        d3d9device->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
        d3d9device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
        d3d9device->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
        d3d9device->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_MODULATE );
        d3d9device->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
        d3d9device->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
        d3d9device->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
        d3d9device->SetTextureStageState( 2, D3DTSS_COLOROP,   D3DTOP_MODULATE );
        d3d9device->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_TEXTURE );
        d3d9device->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_CURRENT | D3DTA_COMPLEMENT );
        d3d9device->SetTextureStageState( 2, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );

        TerrMesh->DrawSubset(0);

        d3d9device->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
        d3d9device->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
        d3d9device->SetTextureStageState( 2, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );

 

Its not yet finished, i can't figure out how to set different texcoord scale to each stage/texture set, by some logic it should be like this:

 

d3d9device->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
        d3d9device->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1 );
        d3d9device->SetTextureStageState( 2, D3DTSS_TEXCOORDINDEX, 2 );

 

but then it doesn't show other 2 textures, like there is a always 0,0 for texcoords.

 

If i got it working i'll post it here.

 

EDIT: Forget everything above, i think this is all correct:

d3d9device->SetTexture(0, terrBlendTex);
        d3d9device->SetTexture(1, terr1Tex);
        d3d9device->SetTexture(2, terr2Tex);

        d3d9device->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
        d3d9device->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
        d3d9device->SetTextureStageState( 2, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );

        D3DXMATRIX blendmapTrans, tex1Trans, tex2Trans;
        D3DXMatrixScaling(&blendmapTrans, 1.f, 1.f, 1.f);
        D3DXMatrixScaling(&tex1Trans, 4.f, 4.f, 1.f);
        D3DXMatrixScaling(&tex2Trans, 16.f, 16.f, 1.f);
        d3d9device->SetTransform( D3DTS_TEXTURE0, &blendmapTrans );
        d3d9device->SetTransform( D3DTS_TEXTURE1, &tex1Trans );
        d3d9device->SetTransform( D3DTS_TEXTURE2, &tex2Trans );

        d3d9device->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
        d3d9device->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 0 );
        d3d9device->SetTextureStageState( 2, D3DTSS_TEXCOORDINDEX, 0 );

        d3d9device->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 2, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );

        d3d9device->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
        d3d9device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
        d3d9device->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
        d3d9device->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
        d3d9device->SetTextureStageState( 0, D3DTSS_RESULTARG, D3DTA_TEMP );
        d3d9device->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_MODULATE );
        d3d9device->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
        d3d9device->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_TEMP );
        d3d9device->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
        d3d9device->SetTextureStageState( 2, D3DTSS_COLOROP,   D3DTOP_MULTIPLYADD );
        d3d9device->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_TEXTURE );
        d3d9device->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_TEMP | D3DTA_COMPLEMENT );
        d3d9device->SetTextureStageState( 2, D3DTSS_COLORARG0, D3DTA_CURRENT );
        d3d9device->SetTextureStageState( 2, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );

        TerrMesh->DrawSubset(0);

        d3d9device->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
        d3d9device->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
        d3d9device->SetTextureStageState( 2, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );

Edited by belfegor, 23 April 2013 - 07:43 AM.


#7 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 23 April 2013 - 08:17 AM

Unfortunately, I tried the above code but couldn't get it to work.

 

I see that the terrain texture in the results is only the one that I set in d3d9device->SetTexture(1, terr1Tex);



#8 VladR   Members   -  Reputation: 722

Like
0Likes
Like

Posted 23 April 2013 - 08:19 AM

I would strongly suggest you do this first:

 

1. Learn the Texture Blending Cascade by experimenting with it, step by step.

 

Then come back and we can have a discussion why something you did does not work.

 

Otherwise, it's just a waste of time...


VladR    My 3rd person action RPG on GreenLight:    http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

 


#9 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 23 April 2013 - 08:38 AM

@VladR: I do have ALOT of things to do with the engine, so I'm trying to get the code work and figure out what's going on.



#10 VladR   Members   -  Reputation: 722

Like
0Likes
Like

Posted 23 April 2013 - 08:57 AM

@VladR: I do have ALOT of things to do with the engine, so I'm trying to get the code work and figure out what's going on.

 

It certainly doesn't look that way from your other threads here.

 

Here's how it looks: "Gimme the code that works and will work when copypasted into my code"

 

Well, guess what - texturing cascade is a process that is pretty complex and can be broken very easily.

 

 

I can, however, suggest you have a separate project, just for trying out the texturing cascade stuff (and absolutely nothing else - just blend 2-3 TSS and that's it). Because with the rest of the game and engine running, there will 10 other things that will try to break the blending/transparency (HUD, foliage, particles, 3D cursors,  ...).

 

 

Otherwise, even the stuff that works elsewhere, won't work in your code simply because your render states are not what you think they are - are you defaulting their states after every change ? If not, you have a mess and need to reset them to their default values.


VladR    My 3rd person action RPG on GreenLight:    http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

 


#11 belfegor   Crossbones+   -  Reputation: 2495

Like
0Likes
Like

Posted 23 April 2013 - 09:34 AM

Unfortunately, I tried the above code but couldn't get it to work.

Is your blend image something like grayscale (no need for alpha channel) ?

 

blendmap.png

 

Here is some utility program (from old dx9.b  sdk) mfctex that you can play with, since you force to use FFP.

 

mfctex.jpg

 

It even generates code from provided input in controls.


Edited by belfegor, 23 April 2013 - 09:35 AM.


#12 VladR   Members   -  Reputation: 722

Like
0Likes
Like

Posted 23 April 2013 - 11:03 AM

Out of curiosity, why does it need to work on an ancient pre-shader-era FFP HW ?


VladR    My 3rd person action RPG on GreenLight:    http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

 


#13 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 24 April 2013 - 02:55 AM

Okay, since I couldn't get it to work correctly and I don't want to spend much time trying to solve this issue, I tried using Pixel Shader and it's working now, I have a little problem, the blending map SHOULD be based on the whole terrain not each tile, see the screenshot:

r.png



#14 belfegor   Crossbones+   -  Reputation: 2495

Like
0Likes
Like

Posted 24 April 2013 - 03:58 AM

You have issues with mipmaps as i can tell from the image.

If you want help, give more details.

 

How do you create your terrain? Or is it exported from some modeling program? Did you applied correct texcoords (with just "1 tile")? Show your shader.



#15 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 24 April 2013 - 02:07 PM

I'm currently creating the terrain in 3Ds Max and using UVW Map modifier to set the tiling UVW.

 

When I remove the UVW Map modifier in 3Ds Max, I get no tiling at all which is a problem, I want the tiling to be based on the grass and stone texture and the blending map should be applied to the whole terrain not each tile.

 

 

Here is the code:

device->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR);
device->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR);
device->SetSamplerState(1, D3DSAMP_ADDRESSW, D3DTADDRESS_MIRROR);

device->SetSamplerState(2, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR);
device->SetSamplerState(2, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR);
device->SetSamplerState(2, D3DSAMP_ADDRESSW, D3DTADDRESS_MIRROR);

device->SetSamplerState(3, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR);
device->SetSamplerState(3, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR);
device->SetSamplerState(3, D3DSAMP_ADDRESSW, D3DTADDRESS_MIRROR);

device->SetSamplerState(4, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR);
device->SetSamplerState(4, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR);
device->SetSamplerState(4, D3DSAMP_ADDRESSW, D3DTADDRESS_MIRROR);

device->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
device->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
device->SetTextureStageState(2, D3DTSS_TEXCOORDINDEX, 0);
device->SetTextureStageState(3, D3DTSS_TEXCOORDINDEX, 0);
device->SetTextureStageState(4, D3DTSS_TEXCOORDINDEX, 0);

device->SetTexture(0, texBlendingMap);
device->SetTexture(1, tex1);
device->SetTexture(2, tex2);
device->SetTexture(3, tex3);
device->SetTexture(4, tex4);

device->SetPixelShader(splatPixelShader);
// Code to render terrain here...

 

Pixel shader:

ps_1_4

////////////////////////////////
// r0: alphamaps
// r1 - r4: textures
////////////////////////////////

// Sample textures
texld r0, t0
texld r1, t1
texld r2, t1
texld r3, t1
texld r4, t1

// Combine textures together based off of their alphamaps
mul r1, r1, r0.x
lrp r2, r0.y, r2, r1
lrp r3, r0.z, r3, r2
lrp r0, r0.w, r4, r3


#16 belfegor   Crossbones+   -  Reputation: 2495

Like
1Likes
Like

Posted 24 April 2013 - 03:11 PM

In 3ds max set one texture to repeat only once (no tiling), then in code you just scale texcoords for textures other then blendmap and it should be as what you have asked.

 

        d3d9device->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
        d3d9device->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
        d3d9device->SetTextureStageState( 2, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
        d3d9device->SetTextureStageState( 3, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
        d3d9device->SetTextureStageState( 4, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );

        D3DXMATRIX blendmapScale, texScale;
        D3DXMatrixScaling(&blendmapScale, 1.f, 1.f, 1.f);
        D3DXMatrixScaling(&texScale, 16.f, 16.f, 1.f);
        d3d9device->SetTransform( D3DTS_TEXTURE0, &blendmapScale );
        d3d9device->SetTransform( D3DTS_TEXTURE1, &texScale );
        d3d9device->SetTransform( D3DTS_TEXTURE2, &texScale );
        d3d9device->SetTransform( D3DTS_TEXTURE3, &texScale );
        d3d9device->SetTransform( D3DTS_TEXTURE4, &texScale );

 

I don't see that you have set mipmap filtering, so in the image that you showed might be point, try to set like these:

        d3d9device->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 2, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 3, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 3, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 3, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 4, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 4, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
        d3d9device->SetSamplerState( 4, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );


#17 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 25 April 2013 - 12:56 AM

Ok, Great! I'm getting confused with creating the blending map in photoshop, I made the following image to try to use it as a blending map, but I'm only getting to see 2 textures, I also tried to play around with it but couldn't get to find out how it should work:

MU.png

 

I thought it should be RGBA, R = Texture1, G = Texture2, B = Texture3, A = Texture4.



#18 belfegor   Crossbones+   -  Reputation: 2495

Like
0Likes
Like

Posted 25 April 2013 - 02:25 AM

I will try to use my psychic powers to solve your problem.

You have declaration for your 5 textures somewhere and set them to NULL ?

 

LPDIRECT3DTEXTURE9 terrBlendTex = NULL;
LPDIRECT3DTEXTURE9 terr1Tex = NULL;
LPDIRECT3DTEXTURE9 terr2Tex = NULL;
LPDIRECT3DTEXTURE9 terr3Tex = NULL;
LPDIRECT3DTEXTURE9 terr4Tex = NULL;

 

And then in part of code when you load them, you have copied code that loads first 2 because you have that from previous tests:

 

    hr = D3DXCreateTextureFromFile(d3d9device, "blendmap.png", &terrBlendTex);
    ...// check for error
    hr = D3DXCreateTextureFromFile(d3d9device, "texture1.png", &terr1Tex); // copied this
    ...// check for error
    hr = D3DXCreateTextureFromFile(d3d9device, "texture2.png", &terr2Tex); // and this
    ...// check for error
    hr = D3DXCreateTextureFromFile(d3d9device, "texture3.png", &terr1Tex); // here
    ...// check for error
    hr = D3DXCreateTextureFromFile(d3d9device, "texture4.png", &terr2Tex); // and here
    ...// check for error

But forget to change pointer variable names?

 

And then when you set those:

 

        d3d9device->SetTexture(0, terrBlendTex);
        d3d9device->SetTexture(1, terr1Tex);
        d3d9device->SetTexture(2, terr2Tex);
        d3d9device->SetTexture(3, terr3Tex); // NULL
        d3d9device->SetTexture(4, terr4Tex); // NULL

3rd & 4th textures are now showing as white?

 

Is that a problem?

 

Try this as blendmap.


Edited by belfegor, 25 April 2013 - 02:28 AM.


#19 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 25 April 2013 - 03:01 AM

Your blending map is working perfectly, I tried to create my own in Photoshop with no success, see the blending map that I have created that doesn't work:

http://depositfiles.com/files/2gglzsp9c

 

You can also take a look at my PSD file for the blending map:

http://depositfiles.com/files/uwc8vqycg



#20 belfegor   Crossbones+   -  Reputation: 2495

Like
1Likes
Like

Posted 25 April 2013 - 03:19 AM

It is simple process in Photoshop

 

1. File->New and set your desired size (default RGB color)

2. Paint whole image with pure black

3. Go to "channels" tab and add alpha channel

4. Set painting color to pure white

5. Select RED channel only, and paint one part of the image

6. Select GREEN channel, and paint some other part of the image

7. Select BLUE channel,  -||-

8. Select ALPHA channel,  -||-

9. Save






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS