Files
Seele/res/shaders/raytracing/RayGen.slang
T

37 lines
1.2 KiB
Plaintext
Raw Normal View History

2024-07-08 13:46:49 +02:00
import Common;
import RayTracingData;
[shader("raygeneration")]
2024-07-12 13:33:52 +02:00
void raygen()
2024-07-08 13:46:49 +02:00
{
2024-07-15 08:32:50 +02:00
uint3 LaunchID = DispatchRaysIndex();
uint3 LaunchSize = DispatchRaysDimensions();
2024-07-08 13:46:49 +02:00
2024-07-15 08:32:50 +02:00
const float2 pixelCenter = float2(LaunchID.xy) + float2(0.5, 0.5);
const float2 inUV = pixelCenter / float2(LaunchSize.xy);
float2 d = float2(inUV.x, 1 - inUV.y) * 2.0 - 1.0;
2024-10-01 16:56:04 +02:00
float4 target = mul(pViewParams.inverseProjection, float4(d.x, d.y, 1, 1));
2024-07-08 13:46:49 +02:00
2024-07-15 08:32:50 +02:00
RayDesc rayDesc;
2024-10-01 16:56:04 +02:00
rayDesc.Origin = mul(pViewParams.inverseViewMatrix, float4(0, 0, 0, 1)).xyz;
rayDesc.Direction = mul(pViewParams.inverseViewMatrix, float4(normalize(target.xyz), 0)).xyz;
2024-07-15 08:32:50 +02:00
rayDesc.TMin = 0.001;
rayDesc.TMax = 10000.0;
2024-07-17 14:34:00 +02:00
const uint maxRays = 12;
float3 color = float3(0, 0, 0);
float alpha;
for(uint i = 0; i < maxRays; ++i) {
RayPayload payload;
TraceRay(pRayTracingParams.scene, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, rayDesc, payload);
color = color.rgb * alpha + payload.color * payload.alpha;
alpha = alpha + payload.alpha;
rayDesc.Origin = payload.intersection_WS;
if(alpha > 0.9){
break;
}
}
2024-07-08 13:46:49 +02:00
2024-07-17 14:34:00 +02:00
pRayTracingParams.image[int2(LaunchID.xy)] = float4(color, alpha);
2024-07-08 13:46:49 +02:00
}