summaryrefslogtreecommitdiffstats
path: root/tests/vkray/intersection.slang
blob: 358a42e174bfe70f7ee3282cd4a401560d86e98b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// intersection.slang
//TEST:SIMPLE(filecheck=CHECK): -profile glsl_460+GL_NV_ray_tracing -stage intersection -entry main -target spirv-assembly
//TEST:SIMPLE(filecheck=CHECK): -emit-spirv-directly -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);
	}
}

// CHECK: OpEntryPoint Intersection{{NV|KHR}} %main "main"
// CHECK: OpDecorate %{{[a-zA-Z0-9_]+}} BuiltIn RayTmin{{NV|KHR}}

// CHECK-DAG: %[[ATTR:[A-Za-z0-9_]+]] = OpVariable %_ptr_HitAttribute{{NV|KHR}}_SphereHitAttributes{{.*}} HitAttribute{{NV|KHR}}
// CHECK-DAG: %[[VAL:[A-Za-z0-9_]+]] = Op{{.+}} %SphereHitAttributes{{.*}} {{.*}}
// CHECK-DAG: OpStore %[[ATTR]] %[[VAL]]

// CHECK-DAG: OpReportIntersectionKHR