| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #pragma anki library RtShadows
- #pragma anki ray_type 0
- #pragma anki mutator ALPHA_TEXTURE 0 1
- #include <AnKi/Shaders/Common.glsl>
- #include <AnKi/Shaders/Include/ModelTypes.h>
- #if ALPHA_TEXTURE == 1
- layout(shaderRecordEXT, scalar) buffer b_model
- {
- ModelGpuDescriptor u_modelDescriptor;
- };
- layout(set = 0, binding = 5) uniform sampler u_sampler;
- ANKI_BINDLESS_SET(1);
- #endif
- layout(location = 0) rayPayloadInEXT F32 g_payload;
- #pragma anki start ahit
- hitAttributeEXT vec2 g_attribs;
- ANKI_REF(U16Vec3, 2);
- ANKI_REF(MainVertex, ANKI_ALIGNOF(MainVertex));
- void main()
- {
- #if ALPHA_TEXTURE == 1
- const ModelGpuDescriptor model = u_modelDescriptor;
- const MeshGpuDescriptor mesh = model.m_mesh;
- const U32 offset = U32(gl_PrimitiveID) * ANKI_SIZEOF(U16Vec3);
- const UVec3 indices = UVec3(U16Vec3Ref(mesh.m_indexBufferPtr + U64(offset)).m_value);
- const U64 vertBufferPtr = mesh.m_vertexBufferPtrs[VERTEX_ATTRIBUTE_BUFFER_ID_NORMAL_TANGENT_UV0];
- const MainVertex vert0 = MainVertexRef(vertBufferPtr + U64(indices[0] * ANKI_SIZEOF(MainVertex))).m_value;
- const MainVertex vert1 = MainVertexRef(vertBufferPtr + U64(indices[1] * ANKI_SIZEOF(MainVertex))).m_value;
- const MainVertex vert2 = MainVertexRef(vertBufferPtr + U64(indices[2] * ANKI_SIZEOF(MainVertex))).m_value;
- const Vec3 barycentrics = Vec3(1.0f - g_attribs.x - g_attribs.y, g_attribs.x, g_attribs.y);
- const Vec2 uv = vert0.m_uv0 * barycentrics.x + vert1.m_uv0 * barycentrics.y + vert2.m_uv0 * barycentrics.z;
- const U32 texIdx = U32(model.m_material.m_bindlessTextureIndices[TEXTURE_CHANNEL_ID_DIFFUSE]);
- const F32 alpha = textureLod(u_bindlessTextures2dF32[nonuniformEXT(texIdx)], u_sampler, uv, 3.0).a;
- g_payload += alpha;
- if(g_payload >= 1.0)
- {
- terminateRayEXT;
- }
- #else
- terminateRayEXT;
- #endif
- }
- #pragma anki end
- #pragma anki start chit
- void main()
- {
- }
- #pragma anki end
|