Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma kernel CSMain
- RWTexture2D<float4> Result;
- float2 playerPos;
- float playerRadius;
- float maxPlayerPosX;
- float minPlayerPosX;
- float maxPlayerPosY;
- float minPlayerPosY;
- float dstSharpness;
- float threshold;
- int width;
- int height;
- float remap(float value, float inputMin, float inputMax, float outputMin, float outputMax)
- {
- return outputMin + (value - inputMin) * (outputMax - outputMin) / (inputMax - inputMin);
- }
- [numthreads(8,8,1)]
- void CSMain (uint3 id : SV_DispatchThreadID)
- {
- if (id.x >= width || id.y >= height) return;
- float2 pixelWorldPos = float2(
- remap((float)id.x, 0.0f, (float)width, minPlayerPosX, maxPlayerPosX),
- remap((float)id.y, 0.0f, (float)height, minPlayerPosY, maxPlayerPosY));
- float2 toPlayer = playerPos - pixelWorldPos;
- float dst = sqrt(dot(toPlayer, toPlayer));
- // Normalize the distance for smoother falloff
- float normalizedDst = clamp(dst / (playerRadius * threshold), 0.0f, 1.0f);
- // Apply smoothstep for smooth falloff
- float falloff = smoothstep(1.0f, 0.0f, pow(normalizedDst, dstSharpness)); // Adjust sharpness by modifying pow
- // Write to the result texture with max blending
- Result[id.xy] = max(falloff, Result[id.xy].r);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement