Just a few small changes to get this tutorial working in the new version of XNA

In the new LoadModel() function simply remove the device parameter from effect.Clone(), so replace:

meshPart.Effect = effect.Clone(device);

with this:

meshPart.Effect = effect.Clone();

and change the lines:

device.SamplerStates[0].AddressU = TextureAddressMode.Clamp;
device.SamplerStates[0].AddressV = TextureAddressMode.Clamp;

device.RenderState.DepthBufferWriteEnable = false;


device.SamplerStates[0] = SamplerState.LinearClamp;
device.DepthStencilState = DepthStencilState.DepthRead;

and the this line:

device.RenderState.DepthBufferWriteEnable = true;

changes to:

device.DepthStencilState = DepthStencilState.Default;

As we have seen in earlier tutorials this is just making use of the built-in state objects in XNA 4.

Next step Camera delay.


3 thoughts on “Skybox

  1. I know this is out of the tutorial, but is there a way that i can make/adjust transaparency of the mesh, i know using BasicEffect to using .Alpha property. i found BlendState.Additive but i couldnt set the percentage of opacity. Thanks!!!

    1. Hi again Paul,
      The easiest way to achieve this would be by modifying the shader to allow us to pass in a value for alpha.

      If you open up the effects.fx file and look for
      //——- XNA-to-HLSL variables ——–
      and add these two variables to the bottom of that section
      bool xOverrideAlpha;
      float xAlpha;

      then in the pixel shader for the technique that you want to change the percentage of alpha i.e.
      PixelToFrame ColoredPS(VertexToPixel PSIn)
      PixelToFrame TexturedPS(VertexToPixel PSIn)

      add these lines

      Output.Color.a = xAlpha;

      just before where you see the line
      return Output;

      now in your XNA code in the Draw() method when you are setting the parameters to send to the shader you can just do something like this:


      Then just adjust the xAlpha value to your liking, make sure to use BlendState.Additive before you draw and reset to BlendState.Opaque after you’ve drawn the mesh!

      Regards David.

      1. Got it! Thanks so much! i already tried HLSL Color properties before, what i missed out is that BlendState.Additive before and .Opaque after mesh.Draw(). I also tried BlendState.AlphaBlend and making Ouput.Color.a=1 makes no transparency w/c is different from .Additive. And i didnt taught device.BlendState is similar to currentEffect.GraphicsDevice so i instead put the Blendstate out of the foreach loop of model.meshes and made the same ouput. Thanks again!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s