Sign in to follow this  

Texturing a cube built using indices?

This topic is 2083 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:
[code]/////////////
// 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 );
}
}[/code]

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

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
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 [i]every[/i] combination of texture coords to make sure that I'm not crazy.

Here's the texture....................... [url="http://alkaspace.com/is.php?i=136756&img=dirt.jpg"]http://alkaspace.com...56&img=dirt.jpg[/url]
And here's how it's coming out... [url="http://alkaspace.com/is.php?i=136759&img=TextureIssu.jpg"]http://alkaspace.com...TextureIssu.jpg[/url]

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

This topic is 2083 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.

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