ChunkAnyHit.hlsl 817 B

1234567891011121314151617181920212223242526272829303132
  1. #include "Common.hlsl"
  2. [shader("anyhit")]
  3. void ChunkAnyHit(inout RayHits rayPayload, ChunkHitAttributes attrib)
  4. {
  5. Texture2D<float4> texture = textures[attrib.textureId];
  6. float4 color = texture.SampleLevel(gSampler, attrib.texCoord, 0);
  7. if (color.w == 0.f)
  8. {
  9. IgnoreHit();
  10. return;
  11. }
  12. if (rayPayload.hitCount < 0)
  13. { // shadow ray
  14. rayPayload.hitCount = 0;
  15. // TODO: transparent objects should lead to half shadows
  16. AcceptHitAndEndSearch();
  17. return;
  18. }
  19. SingleHit hit;
  20. hit.color = color;
  21. hit.normal = attrib.normal;
  22. hit.distance = RayTCurrent();
  23. hit.dayLight = attrib.dayLight;
  24. hit.dynamicLight = attrib.dynamicLight;
  25. applyHit(rayPayload, hit);
  26. if (color.w < 1.f)
  27. {
  28. IgnoreHit();
  29. return;
  30. }
  31. }