ParticleUtility.hlsli 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // Copyright (c) Microsoft. All rights reserved.
  3. // This code is licensed under the MIT License (MIT).
  4. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  5. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  6. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  7. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  8. //
  9. // Developed by Minigraph
  10. //
  11. // Author(s): Julia Careaga
  12. // James Stanard
  13. //
  14. #include "ParticleRS.hlsli"
  15. #define MAX_PARTICLES_PER_BIN 1024
  16. #define BIN_SIZE_X 128
  17. #define BIN_SIZE_Y 64
  18. #define TILE_SIZE 16
  19. #define TILES_PER_BIN_X (BIN_SIZE_X / TILE_SIZE)
  20. #define TILES_PER_BIN_Y (BIN_SIZE_Y / TILE_SIZE)
  21. #define TILES_PER_BIN (TILES_PER_BIN_X * TILES_PER_BIN_Y)
  22. #define MaxTextureSize 64
  23. SamplerState gSampLinearBorder : register(s0);
  24. SamplerState gSampPointBorder : register(s1);
  25. SamplerState gSampPointClamp : register(s2);
  26. cbuffer CBChangesPerView : register(b1)
  27. {
  28. float4x4 gInvView;
  29. float4x4 gViewProj;
  30. float gVertCotangent;
  31. float gAspectRatio;
  32. float gRcpFarZ;
  33. float gInvertZ;
  34. float2 gBufferDim;
  35. float2 gRcpBufferDim;
  36. uint gBinsPerRow;
  37. uint gTileRowPitch;
  38. uint gTilesPerRow;
  39. uint gTilesPerCol;
  40. };
  41. struct ParticleVertex
  42. {
  43. float3 Position;
  44. float4 Color;
  45. float Size;
  46. uint TextureID;
  47. };
  48. // Intentionally left unpacked to allow scalar register loads and ops
  49. struct ParticleScreenData
  50. {
  51. float2 Corner; // Top-left location
  52. float2 RcpSize; // 1/width, 1/height
  53. float4 Color;
  54. float Depth;
  55. float TextureIndex;
  56. float TextureLevel;
  57. uint Bounds;
  58. };
  59. uint InsertZeroBit( uint Value, uint BitIdx )
  60. {
  61. uint Mask = BitIdx - 1;
  62. return (Value & ~Mask) << 1 | (Value & Mask);
  63. }