HairGridNormalize.hlsl 705 B

1234567891011121314151617181920212223242526
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2026 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include "HairGridNormalizeBindings.h"
  5. #include "HairCommon.h"
  6. JPH_SHADER_FUNCTION_BEGIN(void, main, cHairPerGridCellBatch, 1, 1)
  7. JPH_SHADER_PARAM_THREAD_ID(tid)
  8. JPH_SHADER_FUNCTION_END
  9. {
  10. uint index = tid.x;
  11. if (index >= cNumGridPoints)
  12. return;
  13. // Convert from fixed point back to float and divide velocity by density to get average velocity
  14. float4 v = (float4)gVelocityAndDensity[index] * cFixedToFloat;
  15. float density = v.w;
  16. if (density > 1.0e-12f)
  17. {
  18. v.x /= density;
  19. v.y /= density;
  20. v.z /= density;
  21. }
  22. gVelocityAndDensity[index] = asint(v);
  23. }