Jump to content
  • Advertisement
Sign in to follow this  
andy176822

HLSL problem

This topic is 3719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm a total newbie when it comes to HLSL and I have and error that I just can't work out. I have scaled down my app to almost nothing and the problems still exists. I am drawing a triangle fan to create a square and without using any shaders it looks fine, the texture is drawn on the square in the correct way. However, when I apply my shader the texture does not appear correctly on any tiangle where all 3 vertices are not in the viewport. The texture will stretch in a strange way. I've commented out my pixel shader and the problem still exists. Below are two screenshots showing the problems, one image has the textures (however ugly) in the correct place, the other shows the errors when I move the viewport slightly right (note : the middle vertex is not visible). The shader is shown below. Can anyone shed any light? Thanks alot AP Free Image Hosting at www.ImageShack.us Free Image Hosting at www.ImageShack.us
float4x4 matViewProjection : WORLDVIEWPROJ;

sampler2D mySampler;

struct VS_INPUT 
{
   float4 pos : POSITION0;
   float3 norm : NORMAL0;
   float2 tex : TEXCOORD0;  
};

struct V2P 
{
   float4 pos : POSITION0;
   float2 tex : TEXCOORD0;
};

struct P2F
{
   float4 col : COLOR0;
};

void mainVS(in VS_INPUT IN, out V2P OUT)
{
   OUT.pos = mul(IN.pos, matViewProjection);
   OUT.tex = IN.tex;
}

void mainPS( in V2P IN, out P2F OUT)
{
   float4 tempCol = tex2D(mySampler, IN.tex.xy);
   OUT.col = tempCol;
}

//--------------------------------------------------------------//
// Technique Section for Effect Group 1
//--------------------------------------------------------------//
technique Effect1
{
   pass Pass_0
   {
      VertexShader = compile vs_3_0 mainVS();
      //PixelShader = compile ps_3_0 mainPS();
   }

}

[Edited by - andy176822 on March 17, 2008 3:45:59 PM]

Share this post


Link to post
Share on other sites
Advertisement
Hi, I'm also new to HLSL so this may be the blind leading the blind but It may be you need to set the sampler up something like this.

sampler TexS = sampler_state
{
Texture = <gTex>;
MinFilter = Anisotropic;
MagFilter = LINEAR;
MipFilter = LINEAR;
MaxAnisotropy = 8;
AddressU = WRAP;
AddressV = WRAP;
};

Share this post


Link to post
Share on other sites
It doesn't look like you're setting up your sampler correctly. A sampler has to either be bound to a texture (like in ankhd's definition), or to an explicit sampler register. If you bind it to a texture you set the texture using ID3DXEffect::SetTexture, or for a register you use IDirect3DDevice9::SetTexture and specify the index that corresponds to the sampler register.

Also, in the future you should use the "source" tags when posting long bits of code. It makes things much more pretty! [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!