Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Each #kernel tells which function to compile; you can have many kernels
- #pragma kernel CSMain
- #pragma kernel CSStraight
- #pragma kernel Blur
- // Create a RenderTexture with enableRandomWrite flag and set it
- // with cs.SetTexture
- RWTexture2D<float4> Result;
- float2 size;
- float radius;
- float pixelPerUnit;
- int maxAngles;
- RWStructuredBuffer<float> startAngles;
- RWStructuredBuffer<float> magAngles;
- [numthreads(32, 32,1)]
- void CSMain (uint3 id : SV_DispatchThreadID)
- {
- // TODO: insert actual code here!
- // /!\ pixelPerUnit est le nombre de pixelPerUnit
- //Vecteur du pixel
- float2 dir = float2(size[0] / 2 - id.x, size[1] / 2 - id.y);
- //Distance du pixel au centre
- float mag = sqrt(dir[0] * dir[0] + dir[1] * dir[1]);
- //Normal du vecteur (pour le calcul d'angle)
- float2 dirNorm = float2(dir[0] / mag, dir[1] / mag);
- //Couleur de base pour le dégradé
- float color = 1-mag/(pixelPerUnit*radius);
- //Si la distance est supérieure au rayon (coin) c'est noir
- if (mag > (radius * pixelPerUnit))
- {
- color = 0;
- }
- else
- {
- color = 0;
- //Sinon on calcul l'angle
- float a = atan2(dirNorm[0], dirNorm[1]);
- a = a + 3.14;
- //On compare l'angle au angles enregistré
- for (int i = 0; i < maxAngles; i = i + 1) {
- if (abs(a) < startAngles[i+1] && abs(a) > startAngles[i] || abs(a) >= 6.26 && startAngles[i] >= 6.26 || abs(a) <= 0.03 && startAngles[i] <= 0.03)
- {
- color = 1-mag / (pixelPerUnit * radius);
- //On récupére la magnitude de l'angle enregistré et on vérifie si notre pixel est plus loin
- if (mag > (radius * pixelPerUnit * magAngles[i])) {
- color = 0;
- }
- }
- }
- }
- Result[id.xy] = float4(1, 1, 1, color);
- }
- RWTexture2D<float4> BlurredTexture;
- RWTexture2D<float4> BlurredResult;
- [numthreads(32, 32, 1)]
- void Blur(uint3 id : SV_DispatchThreadID)
- {
- BlurredResult = Result;
- float2 center = size * pixelPerUnit / 2;
- float2 dir = id.xy - center;
- float4 zero = float4(0, 0, 0, 0);
- int count = 0;
- float4 up;
- float4 down;
- float4 right;
- float4 left;
- if (dir.y > 0) {
- up = Result[float2(id.x, id.y + 1)];
- count = count + 1;
- }
- else {
- up = zero;
- }
- if (dir.y < 0) {
- down = Result[float2(id.x, id.y - 1)];
- count = count + 1;
- }
- else {
- down = zero;
- }
- if (dir.x < 0) {
- left = Result[float2(id.x - 1, id.y)];
- count = count + 1;
- }
- else {
- left = zero;
- }
- if (dir.x > 0) {
- right = Result[float2(id.x + 1, id.y)];
- count = count + 1;
- }
- else {
- right = zero;
- }
- up = Result[float2(id.x, id.y + 1)];
- down = Result[float2(id.x, id.y -1)];
- left = Result[float2(id.x -1, id.y)];
- right = Result[float2(id.x + 1, id.y)];
- float sum = (up.w + down.w + left.w + right.w) / 4;
- //sum = up.w / 2;
- //BlurredResult[id.xy] = Result[id.xy];
- BlurredResult[id.xy] = float4(1, 1, 1, sum);
- Result = BlurredResult;
- }
- float width;
- float realWidth;
- float height;
- int precision;
- RWStructuredBuffer<float> points;
- float rP(float x) {
- return x * (realWidth*pixelPerUnit) / width;
- }
- float realPos(float x) {
- float offset = (width - (realWidth*pixelPerUnit)) / 2;
- return rP(x) - rP(offset);
- }
- [numthreads(32, 32, 1)]
- void CSStraight(uint3 id : SV_DispatchThreadID)
- {
- float color = 1;
- float magnitude = height-(height-id.y);
- float offset = (width - (realWidth*pixelPerUnit))/2;
- float offsetBis = realWidth * pixelPerUnit + offset;
- float realX = realPos(id.x)-realPos(offset);
- /* if (id.x < offset || id.x > realWidth*pixelPerUnit + offset)
- realX = 0;*/
- if (realX < 0 || realX > realPos(realWidth*pixelPerUnit+offset))
- realX = 0;
- //int o = round(id.x / (float)pixelPerUnit);
- //int o = round((realX / (float)pixelPerUnit)*realWidth-(offset/(realWidth*5000)));
- int o = round(realX/realPos(offsetBis)*precision);
- if (magnitude < points[clamp(o, 0, precision -1)]*height)
- {
- color = 1;
- }
- else
- {
- color = 0;
- }
- if (id.x <= offset || id.x >= width- (offset)) {
- color = 0;
- }
- if (id.y <= 1 || id.y >= height-2) {
- color = 0;
- }
- //color = realX;
- //color = magnitude;
- //color = 0.5;
- Result[id.xy] = float4(color, color, color, color);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement