Sign in to follow this  
WinstonPennypacker

Skybox Effect

Recommended Posts

Hey everyone, I'm having some trouble with a skybox effect. I'm just using a modified version of one of the DirectX SDK's skybox.fx files. It renders the skybox to a single plane in screen space so that you don't need an entire box and so it stays the same regardless of the camera's position. However, when we move the camera too far out or up, the skybox freaks out and starts stretching and bending. Here is the source-

//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
float4x4 g_mInvWorldViewProjection : WorldViewProjectionInverse;
float4 g_ColorMod : Diffuse
= { 1.0f,1.0f,1.0f,1.0f };

texture g_EnvironmentTexture
<
	string ResourceType = "Cube";
>;

samplerCUBE EnvironmentSampler = sampler_state
{ 
    Texture = (g_EnvironmentTexture);
    MipFilter = LINEAR;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
};


//-----------------------------------------------------------------------------
// Skybox stuff
//-----------------------------------------------------------------------------
struct SkyboxVS_Input
{
    float4 Pos : POSITION;
};

struct SkyboxVS_Output
{
    float4 Pos : POSITION;
    float3 Tex : TEXCOORD0;
};

SkyboxVS_Output SkyboxVS( SkyboxVS_Input Input )
{
    SkyboxVS_Output Output;
    
    Output.Pos = Input.Pos;
    Output.Tex = normalize( mul(Input.Pos, g_mInvWorldViewProjection) );
    
    return Output;
}

float4 SkyboxPS( SkyboxVS_Output Input ) : COLOR
{
    float4 color = texCUBE( EnvironmentSampler, Input.Tex );
    
    return ( color * g_ColorMod );
}

technique Skybox
{
    pass p0
    {
    	CullMode = None;
        VertexShader = compile vs_2_0 SkyboxVS();
        PixelShader = compile ps_2_0 SkyboxPS();
    }
}


The code is extremely simple, but does anyone see anything thats off? Thanks a lot. [Edited by - WinstonPennypacker on May 2, 2007 9:51:30 PM]

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