| 123456789101112131415161718192021222324252627282930313233343536 |
- #include "Common.hlsl"
- [shader("closesthit")]
- void ChunkClosestHit(inout RayHits currentPayload, ChunkHitAttributes attrib)
- {
- if (currentPayload.hitCount == 0)
- {
- return; // already inside of shadow ray
- }
- RayHits tmpPayload;
- // shadow rays
- for (int i = 0; i < currentPayload.hitCount; i++)
- {
- tmpPayload.hitCount = -1; // shadow ray
- RayDesc ray;
- ray.Origin = WorldRayOrigin() + (currentPayload.hits[i].distance - 0.001) * WorldRayDirection();
- ray.Direction = dayLightDirection;
- ray.TMin = 0.00001;
- ray.TMax = 1000;
- TraceRay(TLAS,
- 0, 0xFF, 0,
- 0, 0, ray, tmpPayload);
- float normalFactor = saturate(dot(normalize(currentPayload.hits[i].normal), normalize(dayLightDirection)));
- float3 color = unpackLight(currentPayload.hits[i].dayLight) * dayLightFactor;
- if (tmpPayload.hitCount == 0)
- {
- color = color / 2;
- }
- else
- {
- color = dayLightFactor * (0.5 + normalFactor / 2);
- }
- currentPayload.hits[i].dayLight = packLight(color);
- }
- // TODO: reflection rays
- }
|