Jump to content
  • Advertisement
Sign in to follow this  
laeuchli

Line/Sphere Intersection Vertex Shader Problem

This topic is 4018 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Dear all, I've been trying to get the atmospheric scattering method discribed in GPU gems 2 going for awhile now, and I've been having lots of problems. I've got it narrowed down to the fact that my line/sphere intersection code isnt working properly(listed below) float3 v3Pos = gl_Vertex.xyz; float3 v3Ray = (v3Pos - v3CameraPos); float fFar = length(v3Ray); v3Ray /= fFar; // Calculate the closest intersection of the ray with the outer atmosphere (which is the near point of the ray passing through the atmosphere) float B = 2.0 * dot(v3CameraPos, v3Ray); float C = fCameraHeight2 - fOuterRadius2; float fDet = max(0.0, B*B - 4.0 * C); float fNear = 0.5 * (-B - sqrt(fDet)); Seems simple enough, and copied directly from the book. Also when I run the sample program that he lists online, and have it jsut output fNear, I see what one whould expect, a sphere that fades to black, which grows larger as you zoom in, and smaller as you zoom out. When I run my code, I get a sphere that fades to black, but its sorrunded by another circle, and it gets smaller as you zoom in. Very confusing. I cant think what could be wrong with the code. Does anyone have any suggestions on debugging it? Regards, Jesse

Share this post


Link to post
Share on other sites
Advertisement
I have similar troubles. I dont know why, but I have to divide in.position by skydome radius. Which is wierd, because I do that on the CPU as well.

Length is the magnitude of the camera position from the center of the planet.
fSkydomeRadius == AtmosphereOuterRadius ==10.25

in .cpp
"
fCameraHeight = Length;
vecCamera.x /= AtmosphereOuterRadius;
vecCamera.y /= AtmosphereOuterRadius;
vecCamera.z /= AtmosphereOuterRadius;
"

in .fx
"
float3 v3Pos = IN.Position / fSkydomeRadius; //<----
float3 v3Ray = v3Pos - v3CameraPos;
float fFar = length(v3Ray);
v3Ray /= fFar;

// Calculate the closest intersection of the ray with the outer atmosphere (which is the near point of the ray passing through the atmosphere)
float B = 2.0 * dot(v3CameraPos, v3Ray);
float C = fCameraHeight2 - fOuterRadius2;
float fDet = max(0.0, B*B - 4.0 * C);
float fNear = 0.5 * (-B - sqrt(fDet));
"


Also note that I am unable to get any other scale to work, ie
InnerRadius =10.0
OuterRadius =10.25
Are the only value that work.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!