RtShadowsHit.ankiprog 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (C) 2009-2021, 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 ALPHA_TEXTURE 0 1
  8. #include <AnKi/Shaders/Common.glsl>
  9. #include <AnKi/Shaders/Include/ModelTypes.h>
  10. #if ALPHA_TEXTURE == 1
  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. #endif
  18. layout(location = 0) rayPayloadInEXT F32 g_payload;
  19. #pragma anki start ahit
  20. hitAttributeEXT vec2 g_attribs;
  21. ANKI_DEFINE_LOAD_STORE(U16Vec3, 2)
  22. ANKI_DEFINE_LOAD_STORE(MainVertex, ANKI_ALIGNOF(MainVertex))
  23. void main()
  24. {
  25. #if ALPHA_TEXTURE == 1
  26. const ModelGpuDescriptor model = u_modelDescriptor;
  27. const MeshGpuDescriptor mesh = model.m_mesh;
  28. const U32 offset = U32(gl_PrimitiveID) * ANKI_SIZEOF(U16Vec3);
  29. U16Vec3 indices16;
  30. load(mesh.m_indexBufferPtr + U64(offset), indices16);
  31. const UVec3 indices = UVec3(indices16);
  32. const U64 vertBufferPtr = mesh.m_vertexBufferPtrs[VERTEX_ATTRIBUTE_BUFFER_ID_NORMAL_TANGENT_UV0];
  33. MainVertex vert0, vert1, vert2;
  34. load(vertBufferPtr + U64(indices[0] * ANKI_SIZEOF(MainVertex)), vert0);
  35. load(vertBufferPtr + U64(indices[1] * ANKI_SIZEOF(MainVertex)), vert1);
  36. load(vertBufferPtr + U64(indices[2] * ANKI_SIZEOF(MainVertex)), vert2);
  37. const Vec3 barycentrics = Vec3(1.0f - g_attribs.x - g_attribs.y, g_attribs.x, g_attribs.y);
  38. const Vec2 uv = vert0.m_uv0 * barycentrics.x + vert1.m_uv0 * barycentrics.y + vert2.m_uv0 * barycentrics.z;
  39. const U32 texIdx = U32(model.m_material.m_bindlessTextureIndices[TEXTURE_CHANNEL_ID_DIFFUSE]);
  40. const F32 alpha = textureLod(u_bindlessTextures2dF32[nonuniformEXT(texIdx)], u_sampler, uv, 3.0).a;
  41. g_payload += alpha;
  42. if(g_payload >= 1.0)
  43. {
  44. terminateRayEXT;
  45. }
  46. #else
  47. terminateRayEXT;
  48. #endif
  49. }
  50. #pragma anki end
  51. #pragma anki start chit
  52. void main()
  53. {
  54. }
  55. #pragma anki end