HairApplyGlobalPose.hlsl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2026 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include "HairApplyGlobalPoseBindings.h"
  5. #include "HairCommon.h"
  6. #include "HairApplyGlobalPose.h"
  7. JPH_SHADER_FUNCTION_BEGIN(void, main, cHairPerVertexBatch, 1, 1)
  8. JPH_SHADER_PARAM_THREAD_ID(tid)
  9. JPH_SHADER_FUNCTION_END
  10. {
  11. // Check if this is a valid vertex
  12. uint vtx = tid.x + cNumStrands; // Skip the root of each strand, it's fixed
  13. if (vtx >= cNumVertices)
  14. return;
  15. if (IsVertexFixed(gVerticesFixed, vtx))
  16. return;
  17. // Load the material
  18. uint strand_idx = vtx % cNumStrands;
  19. JPH_HairMaterial material = gMaterials[GetStrandMaterialIndex(gStrandMaterialIndex, strand_idx)];
  20. // Load the vertex
  21. float strand_fraction = GetVertexStrandFraction(gStrandFractions, vtx);
  22. float3 initial_pos = gInitialPositions[vtx];
  23. float4 initial_bishop = JPH_QuatDecompress(gInitialBishops[vtx]);
  24. JPH_HairGlobalPoseTransform global_pose_transform = gGlobalPoseTransforms[strand_idx];
  25. // Only apply global pose
  26. JPH_HairPosition pos;
  27. pos.mPosition = float3(0, 0, 0);
  28. pos.mRotation = float4(0, 0, 0, 0);
  29. ApplyGlobalPose(pos, initial_pos, initial_bishop, global_pose_transform, material, strand_fraction);
  30. // Write back vertex
  31. gPositions[vtx] = pos;
  32. }