Hey guys,
In the process of writing some code to render a cube mapped skybox, used to render a star map in space.
Running into some issues, the texture isn't cooperating, as you can see in the following screenshot:
http://img502.imageshack.us/img502/4474/skyboxbug.jpg
Top and right hand sides seem to be rendering okay, but the rest isn't.
I've looked over everything ten times, double checked all the vertex and index definitions, rewritten the shader... to no avail. So obviously I'm missing something.
It feels like a misplaced texture coordinate, but I've tried replacing the texCUBE in the pixel shader with a color determined by tex coords, and all of them come out how they're intended, so I'm going crazy here. Figured I'd get some outside help.
I'm only sending texture coordinates and building vertex coordinates in the vertex shader.
The following is my cube definition (note that my camera viewing vector is down the Y axis, instead of the usual Z axis, hence the comments on the position of the vertices may seem... misleading):
pPrim->LockVertices((void **)&pVertex); pPrim->LockIndices((void **)&pIndex); // 0 = Top far left pVertex[0].fU = 0.0f; pVertex[0].fV = 0.0f; pVertex[0].fW = 1.0f; // 1 = Bottom far left pVertex[1].fU = 0.0f; pVertex[1].fV = 0.0f; pVertex[1].fW = 0.0f; // 2 = Top close left pVertex[2].fU = 0.0f; pVertex[2].fV = 1.0f; pVertex[2].fW = 1.0f; // 3 = Bottom close left pVertex[3].fU = 0.0f; pVertex[3].fV = 1.0f; pVertex[3].fW = 0.0f; // 4 = Top far right pVertex[4].fU = 1.0f; pVertex[4].fV = 0.0f; pVertex[4].fW = 1.0f; // 5 = Bottom far right pVertex[5].fU = 1.0f; pVertex[5].fV = 0.0f; pVertex[5].fW = 0.0f; // 6 = Top close right pVertex[6].fU = 1.0f; pVertex[6].fV = 1.0f; pVertex[6].fW = 1.0f; // 7 = Bottom close right pVertex[7].fU = 1.0f; pVertex[7].fV = 1.0f; pVertex[7].fW = 0.0f; // 0 = Top far left // 1 = Bottom far left // 2 = Top close left // 3 = Bottom close left // 4 = Top far right // 5 = Bottom far right // 6 = Top close right // 7 = Bottom close right // Left Side pIndex[0] = 0; pIndex[1] = 1; pIndex[2] = 2; pIndex[3] = 1; pIndex[4] = 3; pIndex[5] = 2; // Right side pIndex[6] = 4; pIndex[7] = 6; pIndex[8] = 5; pIndex[9] = 5; pIndex[10] = 6; pIndex[11] = 7; // Top Side pIndex[12] = 0; pIndex[13] = 2; pIndex[14] = 4; pIndex[15] = 2; pIndex[16] = 6; pIndex[17] = 4; // Bottom Side pIndex[18] = 1; pIndex[19] = 5; pIndex[20] = 3; pIndex[21] = 3; pIndex[22] = 5; pIndex[23] = 7; // Far Side pIndex[24] = 0; pIndex[25] = 4; pIndex[26] = 1; pIndex[27] = 1; pIndex[28] = 4; pIndex[29] = 5; // Near Side pIndex[30] = 2; pIndex[31] = 3; pIndex[32] = 6; pIndex[33] = 3; pIndex[34] = 7; pIndex[35] = 6; pPrim->UnlockIndices(); pPrim->UnlockVertices();
And... My shader:
struct VertexOut
{
float4 Position : POSITION;
float3 TexCoords : TEXCOORD0;
};
float4x4 xProjection;
float4x4 xView;
float3 xCameraPos;
Texture Texture;
samplerCUBE TextureSampler = sampler_state{ texture = <Texture> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = CLAMP; AddressV = CLAMP; AddressW = CLAMP;};
VertexOut CubeMapVS(float3 TexCoords : TEXCOORD0)
{
VertexOut Output = (VertexOut)0;
float4x4 Final = (float4x4)0;
Output.Position.x = (((TexCoords.x - 0.5f) * 2) * 50000.0f) + xCameraPos.x;
Output.Position.y = (((TexCoords.y - 0.5f) * 2) * 50000.0f) + xCameraPos.y;
Output.Position.z = (((TexCoords.z - 0.5f) * 2) * 50000.0f) + xCameraPos.z;
Output.Position.w = 1.0f;
Final = mul(xView, xProjection);
Output.Position = mul(Output.Position, Final);
Output.TexCoords = TexCoords;
return Output;
}
float4 CubeMapPS(float3 TexCoords : TEXCOORD0) : COLOR0
{
return texCUBE(TextureSampler, TexCoords);
}
technique CubeMapShader
{
pass Pass0
{
VertexShader = compile vs_2_0 CubeMapVS();
PixelShader = compile ps_2_0 CubeMapPS();
}
}
Any assistance would be greatly appreciated!!
Thanks in advance. ![]()







