Sign in to follow this  
Endemoniada

Disabling Texturing ?

Recommended Posts

Hi guys, I define my custom vertex with D3DFVF_XYZRHW|D3DFVF_DIFFUSE|3DFVF_TEX1, I don't want to use the texture in certain areas so I've just been doing this: g_d3d_device->BeginScene(); // don't want texture g_d3d_device->SetTexture(0,NULL); g_d3d_device->DrawPrimitive(...); // want texture g_d3d_device->SetTexture(0,g_texture); g_d3d_device->DrawPrimitive(...); g_d3d_device->EndScene(); ...and everything seems fine. Am I doing it right ? Thanks.

Share this post


Link to post
Share on other sites
That should be just fine. If you need more detail on where the texture is you could use an alpha map or texture splat. But as long as what you have works thats fine.

Share this post


Link to post
Share on other sites
The results are undefined, so no, not right. And it does vary by card, so you're just lucky so far.

You should change your TextureStageStates to not refer to textures. Each stage has an alphaop and a colorop. Operations have 1, 2, or 3 arguments (oddly, ARG0 is the third rarely used argument).

By default you normally have 1 active stage, which modulates color by texture.
pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
When not using textures you should change this to just use diffuse (result of lighting, or vertex color if lighting is off)
pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);

pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

Share this post


Link to post
Share on other sites
Quote:
Original post by Namethatnobodyelsetook
The results are undefined, so no, not right. And it does vary by card, so you're just lucky so far.

You should change your TextureStageStates to not refer to textures. Each stage has an alphaop and a colorop. Operations have 1, 2, or 3 arguments (oddly, ARG0 is the third rarely used argument).

By default you normally have 1 active stage, which modulates color by texture.*** Source Snippet Removed ***When not using textures you should change this to just use diffuse (result of lighting, or vertex color if lighting is off)
*** Source Snippet Removed ***


Oh yeah :(

Disregard my original post lol.

Share this post


Link to post
Share on other sites
Ahhh, that helps a lot Namethatnobodyelsetook. I was worried about my method.

Does it matter if I call SetTexture() before or after I set the states ?

Also, if I never call SetTexture() with the sampler greater than 0 do I have to worry about disabling those stage states ?

Thanks man.

Share this post


Link to post
Share on other sites
Quote:
Original post by Namethatnobodyelsetook
The results are undefined, so no, not right. And it does vary by card, so you're just lucky so far.

Are you sure about this? I remember from somewhere that the fixed pipeline always returns black for null textures. It is, however, undefined when using pixel shaders.

Share this post


Link to post
Share on other sites
It could be that the fixed pipe does return *white*. I know it's unreliable in a shader, but I didn't know that the fixed pipe way was any better.

It shouldn't matter when you call SetShader. If fact, it probably doesn't matter too much if you call it at all, as the states will already tell it to ignore texturing.

It's a good habit to setup your full effect, including disabling the next stage. At some point you're going to use a 2 stage effect, or one will be set for you by a helper library (fonts, some heightmap library, or whatever). You can either make it the responsiblity of that effect to disable all the stages it setup, or have each effect include a final disable. It doesn't matter to you now, but it will, so it's a good habit to get into.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this