41 lines
1.3 KiB
Plaintext
41 lines
1.3 KiB
Plaintext
// Each #kernel tells which function to compile; you can have many kernels
|
|
#pragma kernel CSMain
|
|
|
|
// Create a RenderTexture with enableRandomWrite flag and set it with cs.SetTexture
|
|
RWTexture2D<float4> Result;
|
|
float4 color;
|
|
uint isFill;
|
|
uint isHorizontal;
|
|
uint texSize;
|
|
uint numPoints;
|
|
float minVal;
|
|
float maxVal;
|
|
float4 pointVals[1000];
|
|
|
|
[numthreads(8,8,1)]
|
|
void CSMain (uint3 id : SV_DispatchThreadID)
|
|
{
|
|
Result[id.xy] = float4(0, 0, 0, 0);
|
|
|
|
uint minValScaled = (uint)round(minVal * texSize);
|
|
uint idx = (isHorizontal ? id.y : id.x);
|
|
uint idy = (isHorizontal ? id.x : id.y);
|
|
|
|
for (uint i = 0; i < numPoints; i++) {
|
|
uint px = (uint)round(pointVals[i].x * texSize);
|
|
uint py = (uint)round(pointVals[i].y * texSize);
|
|
if (i > 0) {
|
|
uint ppx = (uint)round(pointVals[i-1].x * texSize);
|
|
uint ppy = (uint)round(pointVals[i-1].y * texSize);
|
|
float slope = (pointVals[i].y - pointVals[i-1].y) / (pointVals[i].x - pointVals[i-1].x);
|
|
uint valFromSlope = (uint)round(slope * (idx - ppx) + ppy);
|
|
|
|
if (idx >= ppx && idx <= px && idy <= valFromSlope && idy >= minValScaled) {
|
|
float alphaScale = isFill ? 1 : (((float)idy / (float)texSize) - minVal) / (maxVal - minVal);
|
|
Result[id.xy] = float4(color.x, color.y, color.z, alphaScale * color.w);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|