Advertisement
JontePonte

updatetexture

Jan 2nd, 2025
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #pragma kernel CSMain
  2.  
  3. RWTexture2D<float4> Result;
  4.  
  5. float2 playerPos;
  6. float playerRadius;
  7.  
  8. float maxPlayerPosX;
  9. float minPlayerPosX;
  10. float maxPlayerPosY;
  11. float minPlayerPosY;
  12.  
  13. float dstSharpness;
  14. float threshold;
  15.  
  16. int width;
  17. int height;
  18.  
  19. float remap(float value, float inputMin, float inputMax, float outputMin, float outputMax)
  20. {
  21. return outputMin + (value - inputMin) * (outputMax - outputMin) / (inputMax - inputMin);
  22. }
  23.  
  24. [numthreads(8,8,1)]
  25. void CSMain (uint3 id : SV_DispatchThreadID)
  26. {
  27. if (id.x >= width || id.y >= height) return;
  28.  
  29. float2 pixelWorldPos = float2(
  30. remap((float)id.x, 0.0f, (float)width, minPlayerPosX, maxPlayerPosX),
  31. remap((float)id.y, 0.0f, (float)height, minPlayerPosY, maxPlayerPosY));
  32.  
  33. float2 toPlayer = playerPos - pixelWorldPos;
  34. float dst = sqrt(dot(toPlayer, toPlayer));
  35.  
  36. // Normalize the distance for smoother falloff
  37. float normalizedDst = clamp(dst / (playerRadius * threshold), 0.0f, 1.0f);
  38.  
  39. // Apply smoothstep for smooth falloff
  40. float falloff = smoothstep(1.0f, 0.0f, pow(normalizedDst, dstSharpness)); // Adjust sharpness by modifying pow
  41.  
  42. // Write to the result texture with max blending
  43. Result[id.xy] = max(falloff, Result[id.xy].r);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement