Jump to content
  • Advertisement
isu diss

DX11 Atmospheric Scattering using DirectCompute

Recommended Posts

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



Edited by isu diss

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!