• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
TheFallenOne

Skybox Rendering Issue

4 posts in this topic

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

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites
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
1

Share this post


Link to post
Share on other sites
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!!

1

Share this post


Link to post
Share on other sites

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  
Followers 0