Atmospheric Scattering using DirectCompute

Started by
5 comments, last by isu diss 6 years, 3 months ago

 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);
	}

}

 

Advertisement

bump. no response for my issue

bump

help me to solve this problem

Seems you need to do your debugging yourself :P

Did you try to output variables to screen one after another, something like:

SkyColors[DTID.xy] = float4(X,Y,r, 1);

You can make some conclusions based at the colors you see.

If this does not help you can create a debug buffer, store variables there, read back to CPU and print them so you can spot NaNs or infinites. That's annoying but once set up you can use that debugging for each shader.

It worked!!!

This topic is closed to new replies.

Advertisement