Jump to content

  • Log In with Google      Sign In   
  • Create Account


Skybox Rendering Issue


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 TheFallenOne   Members   -  Reputation: 134

Like
0Likes
Like

Posted 05 January 2013 - 02:06 AM

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. smile.png



Sponsor:

#2 iedoc   Members   -  Reputation: 662

Like
0Likes
Like

Posted 05 January 2013 - 05:12 AM

a vertex usually only has one texture coordinate, so if your doing a cube map, you might have to have 4 separate vertices for each side of the cube, it looks like you are only using 8 vertices for the cube, so that every vertex shares 3 sides, that means all 3 sides using a vertex will share the same texture coordinate for that vertex


Edited by iedoc, 05 January 2013 - 05:14 AM.

Braynzar Soft - DirectX Lessons & Game Programming Resources!

#3 Erik Rufelt   Crossbones+   -  Reputation: 3031

Like
0Likes
Like

Posted 05 January 2013 - 06:26 AM

Try not using CLAMP.

Also, try not using camera position at all in the shader, but just the texture coords, and/or set the coords to [-1, 1] directly instead of scaling in the shader. This is just to simplify until it works, then you can add stuff back in.

I guess you use the position in the shader to show very slow but still visible movement against the background cube map. This will probably work, but distortions will be visible as you move away from the center.



#4 eppo   Crossbones+   -  Reputation: 2311

Like
1Likes
Like

Posted 05 January 2013 - 07:04 AM

A cube map isn't sampled using uv(w)s (in the range [0.0, 1.0]), but using an (un)normalized vector, usually a (reflected) vertex surface normal.

Since you are drawing the map unto cube, you can simple use the cube's object space vertices to sample the cube map.

e.g. left top far vertex:

pVertex[0].fU = -50000.0f;
pVertex[0].fV = 50000.0f;
pVertex[0].fW = 50000.0f;

VS: output.Position = float4(TexCoords + xCameraPos, 1.0);
PS: output.Color = texCUBE(TextureSampler, TexCoords);

Edited by eppo, 05 January 2013 - 07:06 AM.


#5 TheFallenOne   Members   -  Reputation: 134

Like
1Likes
Like

Posted 05 January 2013 - 05:29 PM

A cube map isn't sampled using uv(w)s (in the range [0.0, 1.0]), but using an (un)normalized vector, usually a (reflected) vertex surface normal.

Since you are drawing the map unto cube, you can simple use the cube's object space vertices to sample the cube map.

e.g. left top far vertex:

pVertex[0].fU = -50000.0f;
pVertex[0].fV = 50000.0f;
pVertex[0].fW = 50000.0f;

VS: output.Position = float4(TexCoords + xCameraPos, 1.0);
PS: output.Color = texCUBE(TextureSampler, TexCoords);

 

Awesome, this solved the issue! Thanks a million. :D

 

Sad, because I read that it uses a vector to determine texture coordinates in several different places... I guess it just never clicked.

 

Thanks to you other two as well!!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS