Advertisement
Zgragselus

Obtain texcoord from tracer

Mar 30th, 2024
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. uint instance = 0;
  2.  
  3. float4 result = TraceRayCompute(Rays[id], instance);
  4.  
  5. float3 bary = float3(result.x, result.y, 1.0f - result.x - result.y);
  6.  
  7. GeometryNode geom = Geometries[instance];
  8. MemoryNode vbo = VertexNodes[geom.VertexBufferNode];
  9. MemoryNode ibo = IndexNodes[geom.IndexBufferNode];
  10.  
  11. uint indices[3] = { IndexData[ibo.Offset / 4 + asuint(result.w) + 0], IndexData[ibo.Offset / 4 + asuint(result.w) + 1], IndexData[ibo.Offset / 4 + asuint(result.w) + 2] };
  12. float2 tc[3] =
  13. {
  14. VertexData[(vbo.Offset / 64 + indices[0]) * 4 + 3].xy,
  15. VertexData[(vbo.Offset / 64 + indices[1]) * 4 + 3].xy,
  16. VertexData[(vbo.Offset / 64 + indices[2]) * 4 + 3].xy
  17. };
  18.  
  19. float2 texCoord = tc[0] * bary.x + tc[1] * bary.y + tc[2] * bary.z;
  20. texCoord.x = frac(texCoord.x);
  21. texCoord.y = frac(texCoord.y);
  22.  
  23. Output[DTid.xy] = float4(bary, 1.0f);
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement