//-----------------------------------------------------------------------------
// Name: Sky Shader
// Author: Adrian (adoado)
// For: Free Release. Based on the paper: http://es.geocities.com/kenchoweb/skydomes_en.pdf
//-----------------------------------------------------------------------------
float4x4 matWorldViewProj;
float4 vecSunDir;
float4 vecSunColor;
texture entSkin1;
float4 vecSkill1;
sampler SampSky = sampler_state
{
texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
struct VS_Input
{
float3 position : POSITION;
float4 texcoord : TEXCOORD0;
float4 normal : NORMAL;
};
struct VS_Output
{
float4 position: POSITION;
float4 texcoord: TEXCOORD0;
float4 normal : TEXCOORD1;
};
struct PS_Output
{
float4 color : COLOR;
};
VS_Output VertexShader_Pass0(VS_Input In)
{
VS_Output Out;
Out.position = mul(float4(In.position, 1),matWorldViewProj);
Out.texcoord = (In.texcoord);
Out.normal = normalize(In.normal);
return Out;
}
PS_Output PixelShader_Pass0(VS_Output In)
{
PS_Output Out;
float OneMinute = 0.0444444444; //How many pixels correlate to one standard minute of time: 64/1440 (1440 = 24*60)
float Location = 0.015625 * (OneMinute*vecSkill1.x); //Convert range [1][128] to range [0][1]: 0.015625 = 1/64
float4 TexColor = tex2D(SampSky, float2(Location, In.texcoord.y)); //0.764
Out.color = TexColor;
Out.color *= vecSunColor;
float light = 0.5 + 0.5 * dot(In.normal, vecSunDir);
Out.color *= light;
float4 sun = vecSunColor * 10*pow(light,20); //glowammount
sun += vecSunColor * (dot(In.normal, vecSunDir)>0.7); //diameter of disk
Out.color += sun;
return Out;
}
//-----------------------------------------------------------------------------
// Technique (1 pass, PS/VS 2 compliant)
//-----------------------------------------------------------------------------
technique Technique0
{
pass Pass0
{
VertexShader = compile vs_2_0 VertexShader_Pass0();
PixelShader = compile ps_2_0 PixelShader_Pass0();
}
}