using HLSL move uv with xna problem?

Started by
0 comments, last by ldeej 16 years, 11 months ago
Hi all, i tired to use HLSL move my texture uv with xna. But the texture move uv has some problem. Below is problem sceen-dump and HLSL code. Hope somebody help. Problem screen-dump: http://hk.geocities.com/brian_tsim/error.PNG HLSL Coding =============================================================== float4x4 worldViewProj : WorldViewProjection; float time; texture testTexture; sampler Sampler0 = sampler_state { Texture = (testTexture); MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; }; struct VS_INPUT { float3 normal : NORMAL; float2 texture0 : TEXCOORD0; float4 position OSITION0; }; struct VS_OUTPUT { float4 position OSITION0; float2 texture0 :TEXCOORD0; }; struct PS_OUTPUT { float4 color : COLOR; }; //----------------------------------------------------------------------------- // Simple Vertex Shader //----------------------------------------------------------------------------- void vs(in VS_INPUT IN, out VS_OUTPUT OUT) { OUT.position= mul(IN.position , worldViewProj); OUT.texture0 = IN.texture0; } //----------------------------------------------------------------------------- // Simple Pixel Shader //----------------------------------------------------------------------------- void ps(in VS_OUTPUT IN, out PS_OUTPUT OUT ) { IN.texture0.x += time/10; float4 color = tex2D(Sampler0, IN.texture0); OUT.color = color ; } //----------------------------------------------------------------------------- // Simple Effect (1 technique with 1 pass) //----------------------------------------------------------------------------- technique Technique0 { pass Pass0 { VertexShader = compile vs_1_1 vs(); PixelShader = compile ps_2_0 ps(); } }
Advertisement
The problem seems to be that you are sampling outside the 0..1 UV range, going outside the border of the texture when the default address mode seems to be "border"

Solution 1 is to force the uvs to be in the right range using your own code, solution 2 is to use sampler states to do it for you:

sampler Sampler0 = sampler_state
{
Texture = (testTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};

This topic is closed to new replies.

Advertisement