yum-mirror/slang

Making it easier to work with shaders

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

Ellie HermaszewskaSPIR-V image operations (#3163)2c2294d33

master
3.7 KiB131 linesraw
1#version 460
2#extension GL_EXT_ray_tracing : require
3layout(row_major) uniform;
4layout(row_major) buffer;
5layout(binding = 0)
6uniform texture2D samplerPosition_0;
7
8layout(binding = 2)
9uniform sampler sampler_0;
10
11layout(binding = 1)
12uniform texture2D samplerNormal_0;
13
14struct Light_0
15{
16    vec4 position_0;
17    vec4 color_0;
18};
19
20struct Uniforms_0
21{
22    Light_0 light_0;
23    vec4 viewPos_0;
24    mat4x4 view_0;
25    mat4x4 model_0;
26};
27
28layout(binding = 3)
29layout(std140) uniform _S1
30{
31    Light_0 light_0;
32    vec4 viewPos_0;
33    mat4x4 view_0;
34    mat4x4 model_0;
35}ubo_0;
36layout(binding = 5)
37uniform accelerationStructureEXT as_0;
38
39layout(rgba32f)
40layout(binding = 4)
41uniform image2D outputImage_0;
42
43struct ReflectionRay_0
44{
45    float color_1;
46};
47
48layout(location = 0)
49rayPayloadEXT
50ReflectionRay_0 p_0;
51
52struct ShadowRay_0
53{
54    float hitDistance_0;
55};
56
57layout(location = 1)
58rayPayloadEXT
59ShadowRay_0 p_1;
60
61struct RayDesc_0
62{
63    vec3 Origin_0;
64    float TMin_0;
65    vec3 Direction_0;
66    float TMax_0;
67};
68
69void TraceRay_0(accelerationStructureEXT AccelerationStructure_0, uint RayFlags_0, uint InstanceInclusionMask_0, uint RayContributionToHitGroupIndex_0, uint MultiplierForGeometryContributionToHitGroupIndex_0, uint MissShaderIndex_0, RayDesc_0 Ray_0, inout ShadowRay_0 Payload_0)
70{
71    p_1 = Payload_0;
72    traceRayEXT(AccelerationStructure_0, RayFlags_0, InstanceInclusionMask_0, RayContributionToHitGroupIndex_0, MultiplierForGeometryContributionToHitGroupIndex_0, MissShaderIndex_0, Ray_0.Origin_0, Ray_0.TMin_0, Ray_0.Direction_0, Ray_0.TMax_0, (1));
73    Payload_0 = p_1;
74    return;
75}
76
77void TraceRay_1(accelerationStructureEXT AccelerationStructure_1, uint RayFlags_1, uint InstanceInclusionMask_1, uint RayContributionToHitGroupIndex_1, uint MultiplierForGeometryContributionToHitGroupIndex_1, uint MissShaderIndex_1, RayDesc_0 Ray_1, inout ReflectionRay_0 Payload_1)
78{
79    p_0 = Payload_1;
80    traceRayEXT(AccelerationStructure_1, RayFlags_1, InstanceInclusionMask_1, RayContributionToHitGroupIndex_1, MultiplierForGeometryContributionToHitGroupIndex_1, MissShaderIndex_1, Ray_1.Origin_0, Ray_1.TMin_0, Ray_1.Direction_0, Ray_1.TMax_0, (0));
81    Payload_1 = p_0;
82    return;
83}
84
85float saturate_0(float x_0)
86{
87    return clamp(x_0, 0.0, 1.0);
88}
89
90void main()
91{
92    uvec3 _S2 = ((gl_LaunchIDEXT));
93    float _S3 = float(_S2.x) + 0.5;
94    uvec3 _S4 = ((gl_LaunchSizeEXT));
95    float _S5 = _S3 / float(_S4.x);
96    uvec3 _S6 = ((gl_LaunchIDEXT));
97    float _S7 = float(_S6.y) + 0.5;
98    uvec3 _S8 = ((gl_LaunchSizeEXT));
99    vec2 inUV_0 = vec2(_S5, _S7 / float(_S8.y));
100    vec3 P_0 = (texture(sampler2D(samplerPosition_0,sampler_0), (inUV_0))).xyz;
101    vec3 N_0 = (texture(sampler2D(samplerNormal_0,sampler_0), (inUV_0))).xyz * 2.0 - 1.0;
102    vec3 lightDelta_0 = ubo_0.light_0.position_0.xyz - P_0;
103    float lightDist_0 = length(lightDelta_0);
104    vec3 L_0 = normalize(lightDelta_0);
105    float _S9 = 1.0 / (lightDist_0 * lightDist_0);
106    RayDesc_0 ray_0;
107    ray_0.Origin_0 = P_0;
108    ray_0.TMin_0 = 0.00000099999999747524;
109    ray_0.Direction_0 = lightDelta_0;
110    ray_0.TMax_0 = lightDist_0;
111    ShadowRay_0 shadowRay_0;
112    shadowRay_0.hitDistance_0 = 0.0;
113    TraceRay_0(as_0, 1U, 255U, 0U, 0U, 2U, ray_0, shadowRay_0);
114    float atten_0;
115    if(shadowRay_0.hitDistance_0 < lightDist_0)
116    {
117        atten_0 = 0.0;
118    }
119    else
120    {
121        atten_0 = _S9;
122    }
123    vec3 color_2 = ubo_0.light_0.color_0.xyz * saturate_0(dot(N_0, L_0)) * atten_0;
124    ReflectionRay_0 reflectionRay_0;
125    TraceRay_1(as_0, 1U, 255U, 0U, 0U, 2U, ray_0, reflectionRay_0);
126    vec3 color_3 = color_2 + reflectionRay_0.color_1;
127    uvec3 _S10 = ((gl_LaunchIDEXT));
128    imageStore((outputImage_0), ivec2((uvec2(ivec2(_S10.xy)))), vec4(color_3, 1.0));
129    return;
130}
131