RtShadowsHit.ankiprog 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_REF(U16Vec3, 2);
  22. ANKI_REF(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. const UVec3 indices = UVec3(U16Vec3Ref(mesh.m_indexBufferPtr + U64(offset)).m_value);
  30. const U64 vertBufferPtr = mesh.m_vertexBufferPtrs[VERTEX_ATTRIBUTE_BUFFER_ID_NORMAL_TANGENT_UV0];
  31. const MainVertex vert0 = MainVertexRef(vertBufferPtr + U64(indices[0] * ANKI_SIZEOF(MainVertex))).m_value;
  32. const MainVertex vert1 = MainVertexRef(vertBufferPtr + U64(indices[1] * ANKI_SIZEOF(MainVertex))).m_value;
  33. const MainVertex vert2 = MainVertexRef(vertBufferPtr + U64(indices[2] * ANKI_SIZEOF(MainVertex))).m_value;
  34. const Vec3 barycentrics = Vec3(1.0f - g_attribs.x - g_attribs.y, g_attribs.x, g_attribs.y);
  35. const Vec2 uv = vert0.m_uv0 * barycentrics.x + vert1.m_uv0 * barycentrics.y + vert2.m_uv0 * barycentrics.z;
  36. const U32 texIdx = U32(model.m_material.m_bindlessTextureIndices[TEXTURE_CHANNEL_ID_DIFFUSE]);
  37. const F32 alpha = textureLod(u_bindlessTextures2dF32[nonuniformEXT(texIdx)], u_sampler, uv, 3.0).a;
  38. g_payload += alpha;
  39. if(g_payload >= 1.0)
  40. {
  41. terminateRayEXT;
  42. }
  43. #else
  44. terminateRayEXT;
  45. #endif
  46. }
  47. #pragma anki end
  48. #pragma anki start chit
  49. void main()
  50. {
  51. }
  52. #pragma anki end