Created
June 14, 2022 09:25
-
-
Save CoderJackLiu/0ea743ef7c7720e874b0f2a0edafb0cb to your computer and use it in GitHub Desktop.
BlenderFeatherX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//思路 | |
//1.0 当前像素Alpha值>0 | |
//2.0 横向羽化; | |
//2.1 做好uv范围限制 | |
//参数需要 | |
//1.羽化像素个数; | |
//2.图片像素 | |
//图片尺寸 | |
float2 TexSize=0; | |
Tex.GetDimensions(TexSize.x, TexSize.y); | |
//临界Alpha | |
float InEdgeAlpha=clamp(EdgeAlpha,0,1); | |
// | |
float CurrentAlpha=Texture2DSample(Tex,TexSampler,uv).a; | |
//最终Alpha | |
float EndAlpha=CurrentAlpha; | |
//启示UV值 | |
float2 StartUV=float2(clamp(uv.x-PixelSize/TexSize.x,0,1),uv.y); | |
//当前ALpha如果小于边缘alpha,则返回初始值,不做变化 | |
if (CurrentAlpha<=InEdgeAlpha) | |
{ | |
return CurrentAlpha; | |
} | |
if (PixelSize<1) | |
{ | |
return CurrentAlpha; | |
} | |
EndAlpha=CurrentAlpha; | |
[unroll(17)]for (int i = 1; i < 2*PixelSize+1; i++) | |
{ | |
float2 NewUV=float2(clamp(StartUV.x+i/TexSize.x,0,1),uv.y); | |
EndAlpha+=Texture2DSample(Tex,TexSampler,NewUV).a; | |
} | |
EndAlpha/=(2*PixelSize+1); | |
return EndAlpha; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment