Jump to content
  • Advertisement
Sign in to follow this  
dachande

HLSL Texturing? (Simple)

This topic is 4842 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

Hey, I'm using HLSL to create a verrrry simple vertex shader, simply to replace the FFP when drawing a simple triangle... I have position data and texture coord data... the position data is working fine... but my triangles appear black! The FFP version is texturing fine, the the shader fails to do so... The code is as follows:
  float4x4 matWorldViewProj : WORLDVIEWPROJECTION;

  struct CIn
  { 
    float4 Position : POSITION;
    float2 Texcoord : TEXCOORD0;
  };

  struct COut
  {
    float4 Position  : POSITION;
    float2 Texcoord  : TEXCOORD0;
  };


  COut main( CIn IN)
  {
	COut OUT;

	OUT.Position = mul(IN.Position, matWorldViewProj);
	OUT.Texcoord = IN.Texcoord;

	return OUT;
  }

Any ideas as to why the texture won't show would be much appreaciated! Thanks in advance, Dachande

Share this post


Link to post
Share on other sites
Advertisement
Try adding diffuse color to the output structure and set it to float4(1.0f,1.0f,1.0f,1.0f).


float4x4 matWorldViewProj : WORLDVIEWPROJECTION;

struct CIn
{
float4 Position : POSITION;
float2 Texcoord : TEXCOORD0;
};

struct COut
{
float4 Position : POSITION;
float2 Texcoord : TEXCOORD0;
float4 Diffuse : COLOR0;
};


COut main( CIn IN)
{
COut OUT;
OUT = (COut)0;

OUT.Position = mul(IN.Position, matWorldViewProj);
OUT.Texcoord = IN.Texcoord;
OUT.Diffuse = float4(1.0f,1.0f,1.0f,1.0f); // white and opaque

return OUT;
}

Share this post


Link to post
Share on other sites
Hey there dachande,
How are you doing?

You aren't extracting the diffuse color from your Texture :)

Here you go, try this

[source lang = cpp]
float4x4 ModelViewProj;

sampler2D texSampler0 = sampler_state
{
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
struct a2v
{
float4 position : POSITION;
float4 normal : NORMAL;
float4 tex : TEXCOORD0;
};
struct v2p
{
float4 position : POSITION;
float4 color : COLOR0;
float4 tex : TEXCOORD0;
};
void vs( in a2v IN, out v2p OUT )
{
OUT.position = mul(IN.position, ModelViewProj);
OUT.tex = IN.tex;
}
void ps( in v2p IN, out p2f OUT )
{
OUT.color = tex2D(texSampler0, IN.tex);
}
technique test
{
pass p0
{
vertexshader = compile vs_2_0 vs();
pixelshader = compile ps_2_0 ps();
}
}




Hope this helps.

Share this post


Link to post
Share on other sites
I assumed that was a vertex shader and that he was already using a working pixel shader. I had the same problem two weeks ago and it was the diffuse color in the vertex shader (by doing what I wrote you ignore material diffuse color, but getting the texel is a matter of the pixel shader)

Share this post


Link to post
Share on other sites
Thank you kindly :) The texture now displays. I guess the default diffuse colour is black, which makes sense. Can I set a colour outside of the shader, or is it a requirement to specify this when wanting to use textures? I'm pretty sure this is a stupid question... but I'm new to shaders, so I'll bask in my naivety!

Thanks,

Dachande

Share this post


Link to post
Share on other sites
Quote:
Can I set a colour outside of the shader?

I am not sure if I have understood what you mean. Can you please tell exactly what the color you want to set is for?

@vNistelrooy: I rarely use the fixed pipeline for doing anything that exceeds drawing a simple textured triangle, so I don't know well its functions.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!