yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Jay KwakUpdate spirv-header and spirv-tools to Jun/2024 (#4679)ad379b7c5

master
1.3 KiB56 linesraw
1// intersection.slang
2//TEST:SIMPLE(filecheck=CHECK): -profile glsl_460+GL_NV_ray_tracing -stage intersection -entry main -target spirv-assembly
3//TEST:SIMPLE(filecheck=CHECK): -emit-spirv-directly -stage intersection -entry main -target spirv-assembly
4struct Sphere
5{
6	float3 position;
7	float radius;
8};
9
10struct SphereHitAttributes
11{
12	float3 normal;
13};
14
15bool rayIntersectsSphere(
16	RayDesc 				ray,
17	Sphere 					sphere,
18	out float 				tHit,
19	out SphereHitAttributes attrs)
20{
21	// HACK: this is obviously incorrect,
22	// but we just need some code for testing
23	tHit = sphere.radius;
24	attrs.normal = sphere.position;
25	return tHit >= ray.TMin;
26}
27
28cbuffer U
29{
30	Sphere gSphere;
31}
32
33void main()
34{
35	RayDesc ray;
36	ray.Origin = ObjectRayOrigin();
37	ray.Direction = ObjectRayDirection();
38	ray.TMin = RayTMin();
39	ray.TMax = RayTCurrent();
40
41	float tHit;
42	SphereHitAttributes attrs;
43	if(rayIntersectsSphere(ray, gSphere, tHit, attrs))
44	{
45		ReportHit(tHit, 0, attrs);
46	}
47}
48
49// CHECK: OpEntryPoint Intersection{{NV|KHR}} %main "main"
50// CHECK: OpDecorate %{{[a-zA-Z0-9_]+}} BuiltIn RayTmin{{NV|KHR}}
51
52// CHECK-DAG: %[[ATTR:[A-Za-z0-9_]+]] = OpVariable %_ptr_HitAttribute{{NV|KHR}}_SphereHitAttributes{{.*}} HitAttribute{{NV|KHR}}
53// CHECK-DAG: %[[VAL:[A-Za-z0-9_]+]] = Op{{.+}} %SphereHitAttributes{{.*}} {{.*}}
54// CHECK-DAG: OpStore %[[ATTR]] %[[VAL]]
55
56// CHECK-DAG: OpReportIntersectionKHR