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;
}
HLSL Texturing? (Simple)
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:
Any ideas as to why the texture won't show would be much appreaciated!
Thanks in advance,
Dachande
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; }
Hey there dachande,
How are you doing?
You aren't extracting the diffuse color from your Texture :)
Here you go, try this
Hope this helps.
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.
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)
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
Thanks,
Dachande
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement