Introduction

This sample for Silverilght 5 uses the new 3D features to draw the Earth with day and night transitions, atmosphere layers, and population density overlays. It demonstrates advanced concepts like mipmaps, texture blending, multiple drawing passes, sampler states, and lighting.

Rather than a long write up, check out a video walkthrough of this sample at Silverlight TV: Exploring 3D.

Building the Sample

To compile the solution you will need to install the DirectX SDK and the HLSL Shader Build Task. Afterwards you can open the solution in Visual Studio to build.

Description

  

 

The application can be controlled with the keyboard and mouse. Click and drag to rotate the camera to view the Earth from different perspectives. Use the up / down arrow keys to zoom in and out.

Additional options include:

 

C#
Edit|Remove
public void Draw(GraphicsDevice device, SceneTime time, Camera camera) 
{ 
    // All Earth pass shaders use the same constants so update them each frame 
    UpdateEarthShaderConstants(device, time, camera); 
 
    // 
    // Pass 1 - Draw Earth 
    // 
 
    // Set textures in order of samplers 
    device.Textures[0] = dayTexture; 
    device.Textures[1] = nightTexture; 
    device.Textures[2] = nightLightsTexture; 
    device.Textures[3] = normalTexture; 
    device.Textures[4] = maskTexture; 
 
    // Set states to control sampling 
    device.SamplerStates[0] = SamplerState.AnisotropicClamp; 
    device.SamplerStates[1] = SamplerState.AnisotropicClamp; 
    device.SamplerStates[2] = SamplerState.AnisotropicClamp; 
    device.SamplerStates[3] = SamplerState.AnisotropicClamp; 
    device.SamplerStates[4] = SamplerState.AnisotropicClamp;             
 
    // Set device states 
    device.BlendState = BlendState.Opaque; 
    device.RasterizerState = rasterizerState; 
 
    // Configure shading pipeline 
    device.SetVertexShader(earthVertexShader); 
    device.SetPixelShader(earthPixelShader); 
 
    // Draw the main earth pass 
    mesh.Draw(device); 
 
    // Draw atmosphere layer 
    if (AtmosphereVisible) 
        atmosphereLayer.Draw(device); 
 
    // Draw population layer 
    if (PopulationDensityVisible) 
        populationLayer.Draw(device); 
 
    // Draw magnetic field 
    if (MagneticFieldVisible) 
        field.Draw(device, time, camera); 
} 
 
 

Source Code

More Information

For more information: