Sign in to follow this  
Hurp

Post Process Multitexture

Recommended Posts

I started using a very basic Post Processing technique and I was wondering how I would do multi-texturing for post processing. My following (very slimmed down basic code) right now is
sampler2D gTexture;

float4 ps_main( float2 Tex : TEXCOORD0 ) : COLOR0
{

    return tex2D( gTexture, Tex.xy);
}
In the end I would like to have the second texture (with I suppose the first texture being my texture that is created from my back buffer, then is drawn with the D3D Device's sprite option) be set partially transparent.

Share this post


Link to post
Share on other sites


sampler2D gTexture : register ( s0 );
sampler2D gTexture2 : register ( s1 );

float4 ps_main( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 color = tex2D( gTexture, Tex.xy ) + tex2D( gTexture2, Tex.xy );
return color / 2.0f;
}



The HLSL is very simple. You can of course do whatever blending technique you wish, you can even emulate standard fixed-function alpha-blending if you prefer. What I posted just weights the two textures equally.

As for outside your app, I don't think you're going to be able to make the D3DX sprite interface work for you. It's not really designed for these kinds of uses, so you're better off just making your own screen-sized code and working with that. See the PostProcess sample in the SDK if you need to see how to do that.

Also note that I added the register bit to the samplers, with this your samplers correspond directly to the texture stage you set a texture to.

Share this post


Link to post
Share on other sites
Well, rather then using the fixed functions SetTexture couldn't I just set the texture with effect->SetTexture ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Hurp
Well, rather then using the fixed functions SetTexture couldn't I just set the texture with effect->SetTexture ?


Absolutely, you'll just have to set your sampler to use that texture.

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