Skip to main content
Home Forums Silverlight Programming Game Development Pixel Shader help.
2 replies. Latest Post by rickep02 on October 17, 2009.
(0)
rickep02
Member
1 points
4 Posts
10-16-2009 8:50 PM |
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:
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;}
ksleung
Contributor
5366 points
1,028 Posts
10-16-2009 10:42 PM |
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).
10-17-2009 2:14 PM |
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.