cronholio

Hi, I searched and found nothing. I am applying an effect to to sprite and would like to know how to send an additional texture to the effect. How should it be done

This is what I've tried..

In my game

Texture2D normaltex = this.normalTarget.GetTexture();

if (this.efx.Parameters["NormTex"] != null)

   this.efx.Parameters["NormTex"].SetValue(normaltex);

In my .fx file

extern texture NormTex;

sampler NormSampler = sampler_state

{

   texture = <NormTex>;

   AddressU = WRAP;

   AddressV = WRAP;

   MIPFILTER = POINT;

   MINFILTER = POINT;

   MAGFILTER = POINT;

};

 



Re: XNA Game Studio Express Multitexturing in fx

Kyle0654

Define another texture and sampler in your .fx file, and then set that texture through the parameters. Then just have your pixel shader sample both textures and perform whatever combination you want on the retrieved values.




Re: XNA Game Studio Express Multitexturing in fx

cronholio

Heh. If it wasn't obvious by the code I posted, I understand how it should work, I was asking why the code I'd written isn't working.

Anyway it looks like the code I had written does work. For some reason I cannot out and out replace the texel assigned to a sprite with a texel from a different image within a shader.

For instance in the fx file I have two samplers, one for a color render target (which is also assigned to the sprite as it's texture), and another sampler which is derived from a different render target. So if col rpresents the color target and norm represents the other target...

return col;

in the pixel shader works fine.

return col+norm;

returns an the two textures added together.

return norm;

does not return the norm texture. It returns the sprite texture col.

return (norm+col)-col;

returns the sprite texture col (again, I would think it would return the norm texture).

I don't really understand why it works like this. I can live with it though. I justed wanted to return norm to verfiy it was being read by the shader correctly. Ultimately I am going to just be using the norm texture to modify the col texture. 

 

 





Re: XNA Game Studio Express Multitexturing in fx

Shawn Hargreaves - MSFT

I'm happy today :-)

Having finally got our creator club website live to the public, I can now point you to a sample that shows how to do exactly this:

http://creators.xna.com/Headlines/developmentaspx/archive/2007/02/13/Sprite-Effects-Sample.aspx






Re: XNA Game Studio Express Multitexturing in fx

cronholio

Shawn, thank you so much for this sample. Everything is working fantasticly now.