Solar Wind 3D Sample

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...

C# (10.4 MB)
 
 
 
 
 
4.4 Star
(8)
9,128 times
Add to favorites
9/12/2011
E-mail Twitter del.icio.us Digg Facebook
//
// This file contains a configurable vertex shader common to
// multiple atmosphere passes.
//

static const float AtmosphereRotationSpeed = -0.19; // Rotate atmosphere slightly slower than Earth

// Vertex shader with rotation
VertexShaderOutput atmosphereVS(VertexData input, float atmosphereSize) 
{	
	VertexShaderOutput output = (VertexShaderOutput)0;

	// Rotation
	float4x4 rotationMatrix = RotateY(TotalSeconds * AtmosphereRotationSpeed);	

	// Light
	output.LightVector = normalize(-LightDir).xyz;

	// Texture
	output.UV = input.UV;

	// Normal
	float4 rotatedNormal = mul(float4(input.Normal, 1.0), rotationMatrix);
	output.WorldNormal = mul(rotatedNormal, WorldInverseTransposeMatrix).xyz;

	// Position
	float4 offsetPosition = float4(input.Position + atmosphereSize * input.Normal, 1.0);	
	float4 rotatedPosition = mul(offsetPosition, rotationMatrix);		
	output.Position = mul(rotatedPosition, WorldViewProjectionMatrix);
		
	// Transform the rotated vertex to world coordinates in order to derive the world view
    float3 worldPosition = mul(rotatedPosition, WorldMatrix).xyz;		// world coordinates
    output.WorldView = normalize(ViewInverseMatrix[3].xyz - worldPosition);	// obj coords

	return output;
}