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 is a vertex shader for drawing the Earth.
//

#include "EarthCommon.hlsl"
#include "EarthCommon_vs.hlsl"

// Vertex shader with rotation
VertexShaderOutput main(VertexData input) 
{
    VertexShaderOutput output;

	// Output texture coordinates and lighting
    output.UV = input.UV.xy;
    output.LightVector = normalize(-LightDir).xyz;

    // rotation matrix created here
    float4x4 rotation = RotateY(TotalSeconds * RotationSpeed);
	
	// normally this would be passed in, derive default
	float3 normal = input.Normal;
	float3 tangent = cross(float3(0.0,1.0,0.0), normal);
	float3 binormal = cross(tangent, normal);
	
	// Rotate normals
	normal = mul(float4(normal,0), rotation).xyz;
	tangent = mul(float4(tangent,0), rotation).xyz;
	binormal = mul(float4(binormal,0), rotation).xyz;

	// Normals are transformed with the inverse transpose instead of the 
	// standard world matrix to eliminate scaling.
    output.WorldNormal = mul(float4(normal,0), WorldInverseTransposeMatrix).xyz;
    output.WorldTangent = mul(float4(tangent,0), WorldInverseTransposeMatrix).xyz;
    output.WorldBinormal = mul(float4(binormal,0), WorldInverseTransposeMatrix).xyz;

	// Get the vertex position
    float4 position = float4(input.Position.xyz, 1.0);	// object coordinates

	// Rotate the vertex, project, and output it
    position = mul(position, rotation);
    output.Position = mul(position, WorldViewProjectionMatrix);	// screen clipspace coords

	// Transform the rotated vertex to world coordinates in order to derive the world view
    float3 worldPosition = mul(position, WorldMatrix).xyz;		// world coordinates
    output.WorldView = normalize(ViewInverseMatrix[3].xyz - worldPosition);	// obj coords

    return output;
}