I'm trying to code Rayleigh part of Nishita's model (Display Method of the Sky Color Taking into Account Multiple Scattering). I get black screen no colors. Can anyone find the issue for me?
[numthreads(32, 32, 1)] //disptach 8, 8, 1 it's 256 by 256 image
void ComputeSky(uint3 DTID : SV_DispatchThreadID)
{
float X = ((2 * DTID.x) / 255) - 1;
float Y = 1 - ((2 * DTID.y) / 255);
float r = sqrt(((X*X)+(Y*Y)));
float Theta = r * (PI);
float Phi = atan2(Y, X);
static float3 Eye = float3(0, 10, 0);
float ViewOD = 0, SunOD = 0, tmpDensity = 0;
float3 Attenuation = 0, tmp = 0, Irgb = 0;
//if (r<=1)
{
float3 ViewDir = normalize(float3(sin(Theta)*cos(Phi), cos(Theta),sin(Theta)*sin(Phi) ));
float ViewRayLength = RaySphereIntersection(Eye, ViewDir, float3(0, 0, 0), OutterRadius);
float SampleLength = ViewRayLength / Ksteps;
//vSunDir = normalize(vSunDir);
float cosTheta = dot(normalize(vSunDir), ViewDir);
float3 tmpPos = Eye + 0.5 * SampleLength * ViewDir;
for(int k=0; k<Ksteps; k++)
{
float SunRayLength = RaySphereIntersection(tmpPos, vSunDir, float3(0, 0, 0), OutterRadius);
float3 TopAtmosphere = tmpPos + SunRayLength*vSunDir;
ViewOD = OpticalDepth(Eye, tmpPos);
SunOD = OpticalDepth(tmpPos, TopAtmosphere);
tmpDensity = Density(length(tmpPos)-InnerRadius);
Attenuation = exp(-RayleighCoeffs*(ViewOD+SunOD));
tmp += tmpDensity*Attenuation;
tmpPos += SampleLength * ViewDir;
}
Irgb = RayleighCoeffs*RayleighPhaseFunction(cosTheta)*tmp*SampleLength;
SkyColors[DTID.xy] = float4(Irgb, 1);
}
}