Skip to main content

Microsoft Silverlight

Answered Question Pixel Shader help.RSS Feed

(0)

rickep02
rickep02

Member

Member

1 points

4 Posts

Pixel Shader help.

 Hello all,

 

Im creating a pixel shader but im having problems.  I have 4 input textures  I want to draw them with a shader like below:

Texture Quad

 

I was able to create a Shader that took in 4 textures, but I cant seem to draw them correctly.  here is the code im working with 

 

 

sampler2D tex1 : register(S0) = sampler_state
{
AddressU = WRAP;
AddressV = WRAP;
};


sampler2D tex2 : register(S1) = sampler_state
{
AddressU = CLAMP;
AddressV = WRAP;
};

sampler2D tex3 : register(S2) = sampler_state
{
AddressU = WRAP;
AddressV = WRAP;
};

sampler2D tex4 : register(S3) = sampler_state
{
AddressU = WRAP;
AddressV = WRAP;
};


float4 main(float2 TexCoord : TEXCOORD) : COLOR
{
float4 blendWeight = 0;
float4 color = 0;

blendWeight.x = (TexCoord.x < 0.5 && TexCoord.y < 0.5) ? 1 : 0;
blendWeight.y = (TexCoord.x >= 0.5 && TexCoord.y < 0.5) ? 1 : 0;
blendWeight.z = (TexCoord.x < 0.5 && TexCoord.y >= 0.5) ? 1 : 0;
blendWeight.w = (TexCoord.x >= 0.5 && TexCoord.y >= 0.5) ? 1 : 0;



color += tex2D(tex1, TexCoord * 2)* blendWeight.x ;
color += tex2D(tex2, TexCoord * 2) * blendWeight.y;
color += tex2D(tex3, TexCoord * 2) * blendWeight.z;
color += tex2D(tex4, TexCoord * 2) * blendWeight.w;


return color;
}
  It copys the 4 textures over but it looks wrong.  Its like the sampler_state is CLAMPd.  Anyone know?

Edit: This does work in FX Composer, so im guessing this is a silverlight thing.

ksleung
ksleung

Contributor

Contributor

5366 points

1,028 Posts

Answered Question

Re: Pixel Shader help.

I don't know about all these sampler_state things, but your logic is wrong.

Instead of using TexCoord * 2, you should be using something like frac(TexCoord * 2).

rickep02
rickep02

Member

Member

1 points

4 Posts

Re: Re: Pixel Shader help.

 Yeah, that was exactly what the problem was I somehow removed my % 1 and just never saw it agian.  The final results are.

 

http://72.167.49.233/Pioneers/TestPage.html

 

Although I need to figure out how to rotate to fit my polygon which is supposed to represent a quad, I have no idea if this is possible.  Some how create texture mapping coordinates.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities