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,133 times
Add to favorites
9/12/2011
E-mail Twitter del.icio.us Digg Facebook
//
// This file is a vertex shader for drawing magnetic fields
//

#include "Noise.hlsl"

float4x4 WorldViewProjection : register(c0);
float TotalSeconds : register(c4);

// min = 0.0, max = 2.0, step = 0.01
static const float Displacement = 1.6f;

// min = 0.1, max = 5.0, step = 0.1
static const float Sharpness = 1.90f;

// min = 0.1, max = 5.0, step = 0.1
static const float ColorSharpness = 3.0f;

// min = 0.01, max = 1.0, step = 0.001
static const float Speed = 0.3f;

// min = 0.01, max = 8.0, step = 0.001
static const float TurbulenceDensity = 2.27f;

// min = -6.0, max = 6.0, step = 0.01
static const float ColorRange = -2.0f;

// Coordinate system for noise
static const float4x4 NoiseTransform = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};

// Structs

// application vertex buffer
struct VertexData
{
    float3 Position     : POSITION;
    float3 Normal       : NORMAL;
    float2 UV		    : TEXCOORD0;
};

// define outputs from vertex shader
struct VertexShaderData
{
    float4 Position		: POSITION;
    float4 Color		: COLOR;
};

// Vertex shader
VertexShaderData main(VertexData input) 
{
    VertexShaderData output;

	// Get a displacement vector
    float4 noisePos = TurbulenceDensity * mul(float4(input.Position,1) + (Speed * TotalSeconds), NoiseTransform);
    float i = (noise(noisePos.xyz, NTab) + 1.0f) * 0.5f;

	// Calculate color
    float cr = 1.0 - (0.5 + ColorRange * (i - 0.5));
    cr = pow(abs(cr), ColorSharpness);
    output.Color = float4(cr.xxx, 1.0f);

    // displacement along normal
    float ni = pow(abs(i),Sharpness);

    // we will use our own "normal" vector because the default geom is a sphere
    //float4 Nn = float4(normalize(input.Normal).xyz, 0);
	float4 Nn = float4(normalize(input.Position).xyz, 0);

    float4 TargetPosition = float4(input.Position, 1.0f) - (Nn * (ni-0.5) * Displacement);
    output.Position = mul(TargetPosition, WorldViewProjection);

    return output;
}