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,131 times
Add to favorites
9/12/2011
E-mail Twitter del.icio.us Digg Facebook
//
// This file is a pixel shader for drawing the clouds
// of the Earth.
//

#include "EarthCommon.hlsl"

//
// Textures and Samplers
//

sampler2D CloudSampler : register(s0);

static const float3 AmbientColor = float3(0.5f, 0.75f, 1.0f);
static const float3 LampColor = float3(1.0f, 1.0f, 1.0f);

static const float AmbientIntensity = 0.1f;
static const float DiffuseIntensity = 1.2f;
static const float SpecularIntensity = 0.05f;

static const float SpecularPower = 10.0f;

//
// Pixel Shader
//
float4 main(VertexShaderOutput input) : COLOR 
{
	// Sample clouds
	float3 clouds = tex2D(CloudSampler, input.UV).rgb;

	// The image doesn't have real alpha, use the grayscale instead
	float alpha = clouds.r;	

	// Normalize vertex normals
    float3 Nn = normalize(input.WorldNormal);

	// Calculate lighting coefficient vector (ambient, diffuse, specular, 1)
    float3 Vn = input.WorldView;
    float3 Ln = input.LightVector;
    float3 Hn = normalize(Vn + 2*Ln);
    float hdn = dot(Hn, Nn);
    float ldn = dot(Ln, Nn);
    float4 litVec = lit(ldn, hdn, SpecularPower);

	// Update intensities
    litVec.x *= AmbientIntensity;
    litVec.y *= DiffuseIntensity;
    litVec.z *= SpecularIntensity;

	// Apply lighting and coloring
    float3 ambient = litVec.x * AmbientColor;    
    float3 specular = pow(litVec.z, 1.5) * LampColor;
    float3 diffuse = saturate(litVec.y) * LampColor * clouds;

    // Final color calculation
    float3 result = ambient + diffuse + specular;
    return float4(result.rgb, alpha);
}