Sign in to follow this  
briantsim

using HLSL move uv with xna problem?

Recommended Posts

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(); } }

Share this post


Link to post
Share on other sites
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;
};

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