Jump to content
  • Advertisement
Sign in to follow this  
Michael Anthony Wion

Texturing a cube built using indices?

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

Is this possible? Or would I have to define each individual vertex, reusing some of the same vertex coords with seperate texture coords?
Here's my current shader:
/////////////
// GLOBALS //
/////////////
matrix World;
matrix View;
matrix Projection;
Texture2D shaderTexture;


///////////////////
// SAMPLE STATES //
///////////////////
SamplerState SampleType
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};


//////////////
// TYPEDEFS //
//////////////
struct VertexInputType
{
float4 position : POSITION;
float4 color : COLOR;
float2 tex : TEXCOORD;
};

struct PixelInputType
{
float4 position : SV_POSITION;
float4 color : COLOR0;
float2 tex : TEXCOORD0;
};


////////////////////////////////////////////////////////////////////////////////
// Vertex Shader
////////////////////////////////////////////////////////////////////////////////
PixelInputType TextureVertexShader( VertexInputType input )
{
PixelInputType output = (PixelInputType)0;
input.position.w = 1.0f;

output.position = mul(input.position, World);
output.position = mul(output.position, View);
output.position = mul(output.position, Projection);
output.tex = input.tex;

return output;
}
PixelInputType ColorVertexShader( VertexInputType input )
{
PixelInputType output = (PixelInputType)0;
input.position.w = 1.0f;

output.position = mul( input.position, World );
output.position = mul( output.position, View );
output.position = mul( output.position, Projection );
output.color = input.color;

return output;
}


////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
float4 TexturePixelShader( PixelInputType input ) : SV_Target
{
return shaderTexture.Sample(SampleType, input.tex);
}
float4 ColorPixelShader( PixelInputType input) : SV_Target
{
return input.color;
}


////////////////////////////////////////////////////////////////////////////////
// Technique
////////////////////////////////////////////////////////////////////////////////
technique10 Render
{
pass pass0
{
SetVertexShader( CompileShader(vs_4_0, TextureVertexShader()) );
SetPixelShader( CompileShader(ps_4_0, TexturePixelShader()) );
SetGeometryShader( NULL );
}
}

technique10 RenderColor
{
pass P0
{
SetVertexShader( CompileShader(vs_4_0, ColorVertexShader()) );
SetPixelShader( CompileShader(ps_4_0, ColorPixelShader()) );
SetGeometryShader( NULL );
}
}


... And my vertex struct:
struct Vertex
{
D3DXVECTOR3 pos;
D3DXVECTOR4 color;
D3DXVECTOR2 texcoord;
Vertex( D3DXVECTOR3 p, D3DXVECTOR4 c, D3DXVECTOR2 t ) : pos(p), color(c), texcoord(t) {}
};


I realize that if this is at all possible, I would have to find a way to separate (or change) the texture coords from the vertex coords before mapping them to a buffer.

Share this post


Link to post
Share on other sites
Advertisement
The standard way to do this is to duplicate the vertices so you end up with 3 at each of the 8 corners. That lets you use a separate set of texture coordinates on each face. It also lets you get the vertex normals correct so that when you come to do some lighting it looks as it should.

Share this post


Link to post
Share on other sites
Strangely enough after getting rid of the index buffer and feeding a straightforward triangle list into my vertex buffer, my texture no longer shows up properly.
I'm only rendering a single triangle, and have tried every combination of texture coords to make sure that I'm not crazy.

Here's the texture....................... http://alkaspace.com...56&img=dirt.jpg
And here's how it's coming out... http://alkaspace.com...TextureIssu.jpg

When I change the texture coordinates for each vertex, the only difference it makes is the "direction" of the swipes from the texture.
This is insane. I've spent an entire week just writing a textured cube class. Legacy Direct X versions were much less bothersome.
And before I changed it to include indices, it was working almost 100%.

EDIT:
Turns out that the Color parameter was the culprit. Once I took it out of the layout, the texture rendered just fine. But why?
I thought that switching the technique to use texture coordinates and a sampler instead of a color was possible?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!