| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #include "Common.hlsl"
- StructuredBuffer<int> textureIdBuffer : register(t1, space2);
- StructuredBuffer<int> indexBuffer : register(t1, space3);
- StructuredBuffer<VertexData> vertexData : register(t1, space4);
- StructuredBuffer<int> indexOffsetBuffer : register(t1, space5);
- [shader("closesthit")]
- void SimpleBlocksClosestHit(inout RayHits currentPayload, SimpleBlocksAttributes 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
- }
|