float4 g_fResolution : register(c0); float3 g_vLightDir : register(c1); sampler2D randomSampler : register(s0); sampler1D diffSampler : register(s2); sampler2D shadowSampler : register(s4); sampler2D depthSampler : register(s5); static float3 g_fColor = float3(0.45f, 0.5f, 0.18f); // float3(.2f, .5f, .1f); static float g_fTexScale = .25f; static float g_fDensity = 3.f; static float2 g_fInnerOuterRadiusSq = float2(240.f * 240.f, 380.f * 380.f); static float4 g_fHaze = float4(0.765f, 0.808f, 0.871f, -0.3f); static float2 g_fHazeDensityIntensity = float2(0.25f, 0.6f); struct psIn { float2 t : TEXCOORD0; float3 n : TEXCOORD1; float3 v : TEXCOORD2; float4 s : TEXCOORD3; float3 w : TEXCOORD4; }; float noise(float2 t) { float4 r = tex2D(randomSampler, .03125f * t); float lr = dot(r, float4(1.f, 10.f, 100.f, 1000.f)); return lr * 2.f / 1111.f - 1.f; } float abs_noise(float2 t) { return abs( noise(t) ); } float4 ps_main(psIn i):color { float2 t = i.w.xz * g_fTexScale; float fCenterDist = dot(i.w.xz, i.w.xz) - g_fInnerOuterRadiusSq.x; fCenterDist /= g_fInnerOuterRadiusSq.y - g_fInnerOuterRadiusSq.x; // Texturing float4 fColor = abs_noise(t) / 2.f; fColor.xyz = 0.5f + 0.1f * fColor.xyz; fColor.zw += noise(2.f * t) / float2(32.f, 4.f); fColor.xw += noise(4.f * t) / float2(64.f, 8.f); fColor.yw += noise(8.f * t) / float2(16.f, 16.f); fColor.xyz += noise(16.f * t) / 16.f; fColor.xyz += noise(32.f * t) / 32.f; fColor.xyz += noise(128.f * t) / 32.f; fColor.xyz += noise(1024.f * t) / 32.f; // Color fColor.xyz *= 2.f * fColor.xyz; fColor.xyz *= g_fColor; // Density fColor.w = saturate(g_fDensity * fColor.w + fCenterDist); // Shadow (AA) float2 sc = i.s.xy / i.s.w; float aa = abs( tex2D(depthSampler, sc).x - i.s.z ); float2 ddaa = float2(ddx(aa), ddy(aa)); float2 aaetc = sign(-ddaa) * g_fResolution.zw; sc += aaetc * saturate(4.f * aa); float fShadow = 0.2f + 0.8f * (float)tex2D(shadowSampler, sc); // Diffuse light fColor.xyz *= tex1D( diffSampler, fShadow * (0.5f + 0.5f * dot(normalize(i.n), -g_vLightDir)) ).xyz; // Haze fColor.xyz = lerp( fColor.xyz, g_fHaze, saturate(g_fHazeDensityIntensity.x * fCenterDist) * g_fHazeDensityIntensity.y ); // Premultiplied alpha fColor.xyz *= fColor.a; return fColor; }