81 lines
2.9 KiB
Plaintext
81 lines
2.9 KiB
Plaintext
float3 g_vLightDir : register(c1); // = normalize( float3(1.f,-3.f,-2.f) );
|
|
float3 g_fTime : register(c3);
|
|
|
|
sampler3D randomSampler : register(s0);
|
|
|
|
static float4 g_fSky = float4(0.392f, 0.502f, 0.702f, 0.7f);
|
|
static float4 g_fHaze = float4(0.765f, 0.808f, 0.871f, -0.3f);
|
|
//static float4 g_fAbyss = float4(0.01f, 0.01f, 0.04f, -1.0f);
|
|
|
|
static float g_fSunSize = .0025f;
|
|
static float g_fCoronaSize = .005f;
|
|
static float4 g_fSunColor = float4(0.925f, 1.0f, 0.75f, 1.f);
|
|
|
|
float4 clouds(float3 d, float4 color)
|
|
{
|
|
float3 t = float3(g_fTime.x*0.001, 0, 0);
|
|
|
|
float3 bumpOffset = float3(0.f, .07f, 0.f);
|
|
|
|
float3 d1 = normalize(d + bumpOffset), d2 = normalize(d + cross(bumpOffset, d));
|
|
|
|
float4 cloud = tex3D(randomSampler, float3(0.2,0.6,0.2) * d);
|
|
float4 cloud1 = tex3D(randomSampler, float3(0.2,0.6,0.2) * d1);
|
|
float4 cloud2 = tex3D(randomSampler, float3(0.2,0.6,0.2) * d2);
|
|
|
|
float cover = g_fTime.z;
|
|
|
|
float3 smoothAlpha = float3(cloud.a, cloud1.a, cloud2.a);
|
|
smoothAlpha = saturate( smoothAlpha - max(cover - smoothAlpha, 0.f) * .25f );
|
|
|
|
float bumpDepth = .5f;
|
|
|
|
float3 cloudel = d + d * (bumpDepth - bumpDepth * smoothAlpha.x);
|
|
float3 cloudel1 = d1 + d1 * (bumpDepth - bumpDepth * smoothAlpha.y);
|
|
float3 cloudel2 = d2 + d2 * (bumpDepth - bumpDepth * smoothAlpha.z);
|
|
float3 normal = normalize( cross(cloudel1 - cloudel, cloudel2 - cloudel) );
|
|
|
|
cloud *= 0.5;
|
|
cloud += tex3D(randomSampler, float3(0.4,1.2,0.4) * (d + t)) * 0.25;
|
|
cloud += tex3D(randomSampler, float3(0.8,2.4,0.8) * d) * 0.125;
|
|
cloud += tex3D(randomSampler, float3(1.6,4.8,1.6) * (d + t)) * 0.0625;
|
|
|
|
cloud.a = saturate( saturate( cloud.a * 2.5f ) - max(cover - cloud.a, 0.f) * 25.f );
|
|
|
|
float3 sdd = d + g_vLightDir;
|
|
float sd = dot(sdd, sdd);
|
|
float s = g_fCoronaSize / ( g_fCoronaSize + saturate(sd - g_fSunSize) );
|
|
|
|
float light = 0.5f + 0.7f * dot(normal, -g_vLightDir);
|
|
float3 stormNormal = normalize(cloud.xyz * 2 - 1);
|
|
float stormLight = 0.5f + 0.5f * dot(stormNormal, g_vLightDir);
|
|
|
|
cloud.xyz = lerp(cloud.xyz, stormLight, 0.3f * saturate(1.f - cover));
|
|
cloud.xyz = dot(cloud.xyz, .3f) + 0.1f * cloud.xyz;
|
|
cloud.xyz = 1.f - .65f * cloud.xyz * (1.f - 0.2f * cover);
|
|
cloud.xyz += 0.4f * light * saturate(cover);
|
|
|
|
cloud.xyz = cloud.a * cloud.xyz + (1 - cloud.a) * color.xyz;
|
|
cloud.xyz += (1 - 0.5f * cloud.a) * g_fSunColor.xyz * s;
|
|
|
|
float3 riseColor = float3(0.9,0.8,0) * (1 - g_fTime.z * 0.5);
|
|
float a = pow( max(0, dot(g_vLightDir, -d)), 2 ) * 0.7 * (1.f - .9f * abs(g_vLightDir.y));
|
|
float risefac = -1.f - g_vLightDir.y;
|
|
if (sign(dot(g_vLightDir, d)) > 0)
|
|
risefac = -1.0;
|
|
cloud.xyz += max( 0, a * lerp( riseColor, 1, min(1.0, risefac*1.5) + risefac ) );
|
|
cloud.a = 1.f;
|
|
return cloud;
|
|
}
|
|
|
|
float4 ps_main(float3 w : TEXCOORD4):color
|
|
{
|
|
float4 fColor = g_fSky;
|
|
|
|
float3 d = normalize(w);
|
|
float g1 = saturate( (d.y - g_fSky.w) / (g_fHaze.w - g_fSky.w) );
|
|
fColor.xyz = lerp(g_fSky.xyz, g_fHaze.xyz, g1);
|
|
|
|
return clouds(d, fColor);
|
|
}
|