https://github.com/shader-slang/slang
Raw File
Tip revision: ec530b300524635dfe0fd86949b0a4fc5c19a984 authored by Yong He on 27 April 2022, 20:58:55 UTC
gfx: Add interop API to control descriptor heap binding. (#2211)
Tip revision: ec530b3
intersection.slang
// intersection.slang
//TEST:CROSS_COMPILE: -profile glsl_460+GL_NV_ray_tracing -stage intersection -entry main -target spirv-assembly

struct Sphere
{
	float3 position;
	float radius;
};

struct SphereHitAttributes
{
	float3 normal;
};

bool rayIntersectsSphere(
	RayDesc 				ray,
	Sphere 					sphere,
	out float 				tHit,
	out SphereHitAttributes attrs)
{
	// HACK: this is obviously incorrect,
	// but we just need some code for testing
	tHit = sphere.radius;
	attrs.normal = sphere.position;
	return tHit >= ray.TMin;
}

cbuffer U
{
	Sphere gSphere;
}

void main()
{
	RayDesc ray;
	ray.Origin = ObjectRayOrigin();
	ray.Direction = ObjectRayDirection();
	ray.TMin = RayTMin();
	ray.TMax = RayTCurrent();

	float tHit;
	SphereHitAttributes attrs;
	if(rayIntersectsSphere(ray, gSphere, tHit, attrs))
	{
		ReportHit(tHit, 0, attrs);
	}
}
back to top