Created
October 31, 2012 02:18
-
-
Save awreece/3984422 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rtDeclareVariable( float4, sphere, , ); | |
rtDeclareVariable( optix::Ray, ray, rtCurrentRay, ); | |
rtDeclareVariable( float3, normal, attribute normal ); | |
RT_PROGRAM void intersect_sphere( int prim_index ) { | |
float3 center = make_float3( sphere.x, sphere.y, sphere.z ); | |
float radius = sphere.w; | |
float3 O = ray.origin - center; | |
float b = dot( O, ray.direction ); float c = dot( O, O ) - radius*radius; float disc = b*b - c; | |
if( disc > 0.0f ) { | |
float sdisc = sqrtf( disc ); | |
float root1 = (-b - sdisc); | |
bool check_second = true; | |
if( rtPotentialIntersection( root1 ) ) { | |
shading_normal = geometric_normal = (O + root1*D) / radius; | |
if( rtReportIntersection( 0 ) ) check_second = false; | |
} | |
if( check_second ) { | |
float root2 = (-b + sdisc); | |
if( rtPotentialIntersection( root2 ) ) { | |
shading_normal = geometric_normal = (O + root2*D) / radius; | |
rtReportIntersection( 0 ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment