2
0

RtShadowsHit.ankiprog 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma anki library RtShadows
  6. #pragma anki ray_type 0
  7. #pragma anki mutator ANKI_TECHNIQUE 4
  8. #pragma anki mutator ALPHA_TEXTURE 0 1
  9. #include <AnKi/Shaders/Common.glsl>
  10. #include <AnKi/Shaders/Include/ModelTypes.h>
  11. layout(shaderRecordEXT, scalar) buffer b_model
  12. {
  13. ModelGpuDescriptor u_modelDescriptor;
  14. };
  15. layout(set = 0, binding = 5) uniform sampler u_sampler;
  16. ANKI_BINDLESS_SET(1);
  17. layout(location = 0) rayPayloadInEXT F32 g_payload;
  18. #pragma anki start ahit
  19. hitAttributeEXT vec2 g_attribs;
  20. #if ALPHA_TEXTURE == 1 && ANKI_SUPPORTS_64BIT
  21. ANKI_DEFINE_LOAD_STORE(U16Vec3, 2)
  22. ANKI_DEFINE_LOAD_STORE(MainVertex, ANKI_ALIGNOF(MainVertex))
  23. #endif
  24. void main()
  25. {
  26. #if ALPHA_TEXTURE == 1 && ANKI_SUPPORTS_64BIT
  27. const ModelGpuDescriptor model = u_modelDescriptor;
  28. const MeshGpuDescriptor mesh = model.m_mesh;
  29. const U32 offset = U32(gl_PrimitiveID) * ANKI_SIZEOF(U16Vec3);
  30. U16Vec3 indices16;
  31. load(mesh.m_indexBufferPtr + U64(offset), indices16);
  32. const UVec3 indices = UVec3(indices16);
  33. const U64 vertBufferPtr = mesh.m_vertexBufferPtrs[VERTEX_ATTRIBUTE_BUFFER_ID_NORMAL_TANGENT_UV0];
  34. MainVertex vert0, vert1, vert2;
  35. load(vertBufferPtr + U64(indices[0] * ANKI_SIZEOF(MainVertex)), vert0);
  36. load(vertBufferPtr + U64(indices[1] * ANKI_SIZEOF(MainVertex)), vert1);
  37. load(vertBufferPtr + U64(indices[2] * ANKI_SIZEOF(MainVertex)), vert2);
  38. const Vec3 barycentrics = Vec3(1.0f - g_attribs.x - g_attribs.y, g_attribs.x, g_attribs.y);
  39. const Vec2 uv = vert0.m_uv0 * barycentrics.x + vert1.m_uv0 * barycentrics.y + vert2.m_uv0 * barycentrics.z;
  40. const U32 texIdx = U32(model.m_material.m_bindlessTextureIndices[TEXTURE_CHANNEL_ID_DIFFUSE]);
  41. const F32 alpha = textureLod(u_bindlessTextures2dF32[nonuniformEXT(texIdx)], u_sampler, uv, 3.0).a;
  42. g_payload += alpha;
  43. if(g_payload >= 1.0)
  44. {
  45. terminateRayEXT;
  46. }
  47. #else
  48. terminateRayEXT;
  49. #endif
  50. }
  51. #pragma anki end
  52. #pragma anki start chit
  53. void main()
  54. {
  55. }
  56. #pragma anki end