Files
bluflame/evoke-64k/trunk/ev10/cfg/pssky.txt
2026-04-18 22:31:51 +02:00

98 lines
3.7 KiB
Plaintext

float3 g_vLightDir : register(c1); // = normalize( float3(1.f,-3.f,-2.f) );
float3 g_fTime : register(c3);
sampler3D randomSampler : register(s0);
samplerCUBE envSampler : register(s6);
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);
// { Outside, Cave }
static float g_fSunSize[] = { .0025f, .01f };
static float g_fCoronaSize[] = { .005f, 0.02f };
static float4 g_fSunColor[] = { float4(0.925f, 1.0f, 0.75f, 1.f), float4(0.925f, 1.0f, 0.85f, 1.0f) * 8.0f };
static float cover[] = { 0.275f, 0.0275f };
float4 clouds(float3 d, float4 color, uniform int iConfig)
{
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);
float3 smoothAlpha = float3(cloud.a, cloud1.a, cloud2.a);
smoothAlpha = saturate( smoothAlpha - max(cover[iConfig] - 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[iConfig] - cloud.a, 0.f) * 25.f );
float3 sdd = d + g_vLightDir;
float sd = dot(sdd, sdd);
float s = g_fCoronaSize[iConfig] / ( g_fCoronaSize[iConfig] + saturate(sd - g_fSunSize[iConfig]) );
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[iConfig]));
cloud.xyz = dot(cloud.xyz, .3f) + 0.1f * cloud.xyz;
cloud.xyz = 1.f - .65f * cloud.xyz * (1.f - 0.2f * cover[iConfig]);
cloud.xyz += 0.4f * light * saturate(cover[iConfig]);
cloud.xyz = cloud.a * cloud.xyz + (1 - cloud.a) * color.xyz;
cloud.xyz += (1 - 0.5f * cloud.a) * g_fSunColor[iConfig].xyz * s;
float3 riseColor = float3(0.9,0.8,0) * (1 - cover[iConfig] * 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_sky_temp(float3 w : TEXCOORD4, uniform int iConfig):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, iConfig);
}
float4 ps_sky(float3 w : TEXCOORD4):color { return ps_sky_temp(w, 0); }
float4 ps_cave_sky(float3 w : TEXCOORD4):color { return ps_sky_temp(w, 1); }
float4 ps_env(float3 w : TEXCOORD4):color
{
float4 fColor = texCUBE(envSampler, w);
// Interpret brightness > 1 as glow, ATTENTION: smaller glow value means MORE glow [0,1]
float fGlow = max( 0.65f, saturate( 2.0f - dot(fColor, 0.333f) ) );
// Linear fake "tone mapping", remap color back into range [0,1] (glow will overbright area anyways)
fColor.xyz /= max( 1.0f, dot(fColor.xyz, 0.333f) );
return float4( fColor.xyz, fGlow );
}