-
Notifications
You must be signed in to change notification settings - Fork 21
/
LiquidShaderFillCS.usf
61 lines (48 loc) · 1.43 KB
/
LiquidShaderFillCS.usf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/** Copyright 2023, Universal Tool Compiler */
#include "/Engine/Public/Platform.ush"
int RTargetSize;
Texture2D<float4> RefTexture;
RWTexture2D<float4> OutputTexture;
bool CheckHittedNormal(float3 NormalDirection)
{
float3 PixelDirection = float3(1,0,0);
float HitAngle = acos( dot(NormalDirection, PixelDirection) / length(NormalDirection) * length(PixelDirection) ) * (180 / 3.14159265359);
if(HitAngle < 90)
return false;
return true;
}
bool CheckIfHitNormal(uint2 ThreadId)
{
if (RefTexture[ThreadId].x != 0 || RefTexture[ThreadId].y != 0 || RefTexture[ThreadId].z != 0)
return true;
return false;
}
[numthreads(THREADGROUPSIZE_X, THREADGROUPSIZE_Y, THREADGROUPSIZE_Z)]
void MainCS(uint3 ThreadId : SV_DispatchThreadID)
{
int ThreadIdX = ThreadId.x;
if(CheckIfHitNormal(ThreadId.xy))
{
OutputTexture[ThreadId.xy] = float4(1,1,1,1);
if(CheckHittedNormal(RefTexture[ThreadId.xy].xyz) && !CheckIfHitNormal(uint2(ThreadIdX + 1, ThreadId.y)))
{
uint2 PixelTemp[2048];
for (int i = 1; i < RTargetSize - ThreadIdX; i++)
{
uint2 PixelPosition = uint2(ThreadIdX + i, ThreadId.y);
PixelTemp[i - 1] = PixelPosition;
if( i == RTargetSize - ThreadIdX - 1)
{
for(int j = 0; j <= i - 1; j++)
{
OutputTexture[PixelTemp[j]] = float4(0,0,0,0);
}
break;
}
if(CheckIfHitNormal(PixelPosition))
break;
OutputTexture[PixelPosition] = float4(1,1,1,1);
}
}
}
}