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 pixel shader common to
// multiple atmosphere passes.
//

// Sampler to read the texture
sampler2D AtmosphereSampler : register(s0);

static const float DiffuseIntensity = 1.2f;
static const float SpecularIntensity = 1.0f;
static const float SpecularPower = 1.0f;

// Pixel Shader
float4 atmospherePS(VertexShaderOutput input, bool upper) : COLOR 
{
	// Sample texture
	float4 color = tex2D(AtmosphereSampler, input.UV);

	// Calculate normals
	float3 Nn = normalize(input.WorldNormal);
	float3 Ln = input.LightVector;
	float3 Vn = input.WorldView;
    float3 Hn = normalize(Vn + Ln);

	// Calculate lighting coefficient vector (ambient, diffuse, specular, 1)
	float hdn = dot(Hn, Nn);
	float ldn = dot(Ln, Nn);
	float4 litVec = lit(ldn, hdn, SpecularPower);

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

	float light = 0;
	if(!upper)
	{
		light = saturate(1 - litVec.y) * .125;
		color.a *= light;
	}
	else
	{
		//light = 1 - saturate(1.1 + hdn);
		//color *= light;

		light = 1 - saturate(0.8 + litVec.y);
		color *= light;
	}
	
	return color;
}