Guest User

Intensity Compute

a guest
Jul 31st, 2020
89
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Texture3D<float> _InputBuffer : register(t0);
  2. RWTexture3D<uint> _Result : register(u0);
  3.  
  4. cbuffer VolumeData : register(b0)
  5. {
  6.     float3 _VolumeDimensions;
  7.     float3 _VoxelsPerCell;
  8. };
  9.  
  10. float ReadPixel(uint x, uint y, uint z)
  11. {
  12.     return _InputBuffer.Load(int4(x,y,z, 0));
  13. }
  14.  
  15. void WritePixel(uint3 id, float data)
  16. {
  17.     _Result[id] = data * 255;
  18. }
  19.  
  20. [numthreads(8, 8, 8)]
  21. void CSMain(uint3 id : SV_DispatchThreadID )
  22. {
  23.     // Get start of voxel cube to compute
  24.     uint3 volumePos = _VoxelsPerCell * id;
  25.    
  26.     // Get min and max bounding points
  27.     float3 minVolumePos = max(volumePos - 1, float3(0,0,0));
  28.     float3 maxVolumePos = min(volumePos + _VoxelsPerCell + 1, _VolumeDimensions);
  29.    
  30.     // Find the maz iso value for this chunk of the volume!
  31.     int Width = maxVolumePos.x, Height = maxVolumePos.y, Depth = maxVolumePos.z;
  32.     float fmax = 0;
  33.     for (int z = minVolumePos.z; z < Depth; z++)
  34.     {
  35.         for (int y = minVolumePos.y; y < Height; y++)
  36.         {
  37.             for (int x = minVolumePos.x; x < Width; x++)
  38.             {  
  39.                 fmax = max(fmax, ReadPixel(x, y, z));
  40.             }
  41.         }
  42.     }
  43.    
  44.     WritePixel(id, fmax);
  45. }
RAW Paste Data