XNA Creators Club Online
Page 1 of 1 (8 items)
Sort Posts: Previous Next

Enlarging a skybox

Last post 11/22/2009 9:21 PM by Craig Martin. 7 replies.
  • 11/22/2009 5:53 PM

    Enlarging a skybox

    So, I have managed to get a skybox working, after using many bits and pieces.  Happy though, because I have learnt a lot from this difficulty.  I have a new question now.  I create a skybox, but for some reason, it was far away from my aircraft, and really small.  To solve this, I went into the content pipeline of the skybox.x file, and increased the scale by 1000.  Now the aircradt is inside the skybox.  My problem is that the skybox seems really small.  Not a lot of room for my plane to fly about.  I cant scale it anymore, otherwise it disappears for some reason.  Is there anyway of increasing the size of the skybox, throught a model method or somthing.  Or would I have to load the skybox into a 3d app and change the size there?

    cheers
  • 11/22/2009 5:58 PM In reply to

    Re: Enlarging a skybox

    Enlarging it this way is fine, but what you're running into is the camera's far plane which is clipping the large skybox. What you need to do is find where you create the camera's projection matrix, and increase its FarPlane parameter. For example:
    Matrix CameraProjectionMatrix = Matrix.CreateProjectionFieldOfView(whatever, whatever, whatever, farplane); 

    "Software is never finished, it is in varying states of 'less broken'" because "If it ain't broke, it doesn't have enough features yet"

    In Playtest: Avatar Land | The MANLY Game for MANLY Men

    The signature that was too big for the 512 char limit
  • 11/22/2009 6:24 PM In reply to

    Re: Enlarging a skybox

    Ok.  So I am following the Chase camera example, so I have my own Camera class.  In it, I have
    private void UpdateMatrices() 
            { 
                view = Matrix.CreateLookAt(this.Position, this.LookAt, this.Up); 
                projection = Matrix.CreatePerspectiveFieldOfView(FieldOfView, 
                    AspectRatio, NearPlaneDistance, FarPlaneDistance); 
            } 

    And this is then called in the Cameras update method.  In my Game class, I do

    camera = new Camera(); 
     
    camera.DesiredPositionOffset = new Vector3(0.0f, 2000.0f, 3500.0f); 
    camera.LookAtOffset = new Vector3(0.0f, 150.0f, 0.0f); 
     
    camera.NearPlaneDistance = 10.0f; 
    camera.FarPlaneDistance = 100000.0f; 

    And I call the Cameras update method in Game1 Update method.  If I change the FarPlaneDistance, nothing appears to happen.  I have even changed the value to 1 million, but it is still the same as before.  Maybe there is a problem when I draw my Skybox

    currentEffect.Parameters["xWorld"].SetValue(worldMatrix);
    currentEffect.Parameters["xView"].SetValue(camera.View);
    currentEffect.Parameters["xProjection"].SetValue(camera.Projection);
                   

    Maybe its not getting the correct value?  Or maybe you know of another reason nothing is changing?

    cheers
  • 11/22/2009 6:41 PM In reply to

    Re: Enlarging a skybox

    Go into your shader, look at the vertex shader.  

    Somewhere in that vertex shader there is a float4 variable that is assigned to or going out of the POSITION0 register.   

    Try setting the Z component of that variable equal to the W component of the same variable.   That will functionally make the skybox draw on the far clip plane, regardless of the size of the model or the distance of the far clip plane in your C# code.

    Best,
    Byron


    ..shaders make you feel... powerful, or very very stupid.
    http://drjbn.spaces.live.com/
  • 11/22/2009 6:52 PM In reply to

    Re: Enlarging a skybox

    Sorry, not to sure what one is the vertex shader, there are quite a few in there.  This is the file provided by riemers

    //------------------------------------------------------ 
    //--                                                    -- 
    //--                www.riemers.net         -- 
    //--                Basic shaders           -- 
    //--            Use/modify as you like              -- 
    //--                                                    -- 
    //------------------------------------------------------ 
     
    struct VertexToPixel 
        float4 Position     : POSITION;     
        float4 Color        : COLOR0; 
        float LightingFactor: TEXCOORD0; 
        float2 TextureCoords: TEXCOORD1; 
    }; 
     
    struct PixelToFrame 
        float4 Color : COLOR0; 
    }; 
     
    //------- XNA-to-HLSL variables -------- 
    float4x4 xView; 
    float4x4 xProjection; 
    float4x4 xWorld; 
    float3 xLightDirection; 
    float xAmbient; 
    bool xEnableLighting; 
    bool xShowNormals; 
     
    //------- Texture Samplers -------- 
     
    Texture xTexture; 
    sampler TextureSampler = sampler_state { texture = <xTexture>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;}; 
     
    //------- Technique: Pretransformed -------- 
     
    VertexToPixel PretransformedVS( float4 inPos : POSITION, float4 inColor: COLOR) 
    {    
        VertexToPixel Output = (VertexToPixel)0; 
         
        Output.Position = inPos; 
        Output.Color = inColor; 
         
        return Output;     
     
    PixelToFrame PretransformedPS(VertexToPixel PSIn)  
        PixelToFrame Output = (PixelToFrame)0;       
         
        Output.Color = PSIn.Color; 
     
        return Output; 
     
    technique Pretransformed_2_0 
        pass Pass0 
        {    
            VertexShader = compile vs_2_0 PretransformedVS(); 
            PixelShader  = compile ps_2_0 PretransformedPS(); 
        } 
     
    technique Pretransformed 
        pass Pass0 
        {    
            VertexShader = compile vs_1_1 PretransformedVS(); 
            PixelShader  = compile ps_1_1 PretransformedPS(); 
        } 
     
    //------- Technique: Colored -------- 
     
    VertexToPixel ColoredVS( float4 inPos : POSITION, float4 inColor: COLOR, float3 inNormal: NORMAL) 
    {    
        VertexToPixel Output = (VertexToPixel)0; 
        float4x4 preViewProjection = mul (xView, xProjection); 
        float4x4 preWorldViewProjection = mul (xWorld, preViewProjection); 
         
        Output.Position = mul(inPos, preWorldViewProjection); 
        Output.Color = inColor; 
         
        float3 Normal = normalize(mul(normalize(inNormal), xWorld));     
        Output.LightingFactor = 1; 
        if (xEnableLighting) 
            Output.LightingFactor = saturate(dot(Normal, -xLightDirection)); 
         
        return Output;     
     
    PixelToFrame ColoredPS(VertexToPixel PSIn)  
        PixelToFrame Output = (PixelToFrame)0;       
         
        Output.Color = PSIn.Color; 
        Output.Color.rgb *= saturate(PSIn.LightingFactor + xAmbient); 
         
        return Output; 
     
    technique Colored_2_0 
        pass Pass0 
        {    
            VertexShader = compile vs_2_0 ColoredVS(); 
            PixelShader  = compile ps_2_0 ColoredPS(); 
        } 
     
    technique Colored 
        pass Pass0 
        {    
            VertexShader = compile vs_1_1 ColoredVS(); 
            PixelShader  = compile ps_1_1 ColoredPS(); 
        } 
     
     
    //------- Technique: Textured -------- 
     
    VertexToPixel TexturedVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float2 inTexCoords: TEXCOORD0) 
    {    
        VertexToPixel Output = (VertexToPixel)0; 
        float4x4 preViewProjection = mul (xView, xProjection); 
        float4x4 preWorldViewProjection = mul (xWorld, preViewProjection); 
         
        Output.Position = mul(inPos, preWorldViewProjection);    
        Output.TextureCoords = inTexCoords; 
         
        float3 Normal = normalize(mul(normalize(inNormal), xWorld));     
        Output.LightingFactor = 1; 
        if (xEnableLighting) 
            Output.LightingFactor = saturate(dot(Normal, -xLightDirection)); 
         
        return Output;     
     
    PixelToFrame TexturedPS(VertexToPixel PSIn)  
        PixelToFrame Output = (PixelToFrame)0;       
         
        Output.Color = tex2D(TextureSampler, PSIn.TextureCoords); 
        Output.Color.rgb *= saturate(PSIn.LightingFactor + xAmbient); 
     
        return Output; 
     
    technique Textured_2_0 
        pass Pass0 
        {    
            VertexShader = compile vs_2_0 TexturedVS(); 
            PixelShader  = compile ps_2_0 TexturedPS(); 
        } 
     
    technique Textured 
        pass Pass0 
        {    
            VertexShader = compile vs_1_1 TexturedVS(); 
            PixelShader  = compile ps_1_1 TexturedPS(); 
        } 
     
    //------- Technique: PointSprites -------- 
     
    struct SpritesVertexOut 
        float4 Position     : POSITION0; 
        float1 Size         : PSIZE; 
    }; 
     
    struct SpritesPixelIn 
        #ifdef XBOX 
            float4 TexCoord : SPRITETEXCOORD; 
        #else 
            float2 TexCoord : TEXCOORD0; 
        #endif 
    }; 
     
    SpritesVertexOut PointSpritesVS (float4 Position : POSITION, float4 Color : COLOR0, float1 Size : PSIZE) 
        SpritesVertexOut Output = (SpritesVertexOut)0; 
          
        float4x4 preViewProjection = mul (xView, xProjection); 
        float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);  
        Output.Position = mul(Position, preWorldViewProjection);     
        Output.Size = 1/(pow(Output.Position.z,2)+1 ) * Size; 
         
        return Output;     
     
    PixelToFrame PointSpritesPS(SpritesPixelIn PSIn) 
    {  
        PixelToFrame Output = (PixelToFrame)0;     
        #ifdef XBOX 
            float2 texCoord = abs(PSIn.TexCoord.zw); 
        #else 
            float2 texCoord = PSIn.TexCoord.xy; 
        #endif 
     
        Output.Color = tex2D(TextureSampler, texCoord); 
         
        return Output; 
     
    technique PointSprites_2_0 
        pass Pass0 
        {    
            PointSpriteEnable = true
            VertexShader = compile vs_2_0 PointSpritesVS(); 
            PixelShader  = compile ps_2_0 PointSpritesPS(); 
        } 
     
    technique PointSprites 
        pass Pass0 
        {    
            PointSpriteEnable = true
            VertexShader = compile vs_1_1 PointSpritesVS(); 
            PixelShader  = compile ps_1_1 PointSpritesPS(); 
        } 
     
     

    I dont know if you mean TexturedVS, or what I should be doing.  To be honest, I really havnt learnt a lot about shading languages yet, just use ones which I find useful.  I am not to sure what the coding shows, and how to change it.
  • 11/22/2009 7:10 PM In reply to

    Re: Enlarging a skybox

    The help documentation for XNA 3.0/3.1 (probably even 2.0) has an article on how to create a skysphere (not box, but they seem to work better anyway).
    Under the XNA Game Studio->Programming Guide->Graphics->3D Graphics->"How To" Articles->How To: Create a SkySphere
  • 11/22/2009 7:51 PM In reply to

    Re: Enlarging a skybox

    Kool, works really well with a sphere instead of cube.  And all this hassle over the last couple of days has made it so easy to implement now.  I have one question to anyone who may know the answer.  I have been following the chase camera example on the xna site.  I removed their simple ground model, and have now added a skysphere.  Now, my aircraft can rotate and stuff, but it wont move forward, everything is done on the spot.  What may have caused somthing like this to happen.  As I say, all the code is the same as the chase camera example, just with a sky sphere instead.

    cheers
  • 11/22/2009 9:21 PM In reply to

    Re: Enlarging a skybox

    If your sky sphere is always rendered on the far clip plane, it doesn't matter where you move, the sky will always seem the same distance away, so it will seem like you are not moving forward :p

    Thats ok, thats how a sky sphere should be rendered, but depending on what your game is, you will need some other visual to give the appearence of movement - sounds like you need some clouds and ground or something like this.
    Game hobbyist hell-bent on coding a diabolical Matrix
Page 1 of 1 (8 items) Previous Next