perf: bound local mosaic rendering and skip unused tracking grayscale
这个提交包含在:
1 父节点
f07b116398
当前提交
4b7e348ff5
11 个文件已更改
+129
-30
没有与搜索条件相匹配的文件
+34
-5
@@ -105,7 +105,8 @@ inline float dyToolMaskHSLWeight(float3 source,thread const DYMaskParameters& p)
|
||||
if(p.flags&DYMaskLightnessEnabled)weight*=dyToolMaskRangeWeight(hsl.z,p.lightnessRange);
|
||||
return weight;
|
||||
}
|
||||
inline float dyToolMaskShapeWeight(float x,float y,thread const DYMaskParameters& p,device const DYMaskPath& path){
|
||||
inline float dyToolMaskShapeWeight(float x,float y,thread const DYMaskParameters& p,device const DYMaskPath& path,
|
||||
float4 pathBounds=float4(-INFINITY,-INFINITY,INFINITY,INFINITY)){
|
||||
float dx=(x-p.centerX)*p.imageAspect,dy=y-p.centerY,ca=cos(p.angle),sa=sin(p.angle);
|
||||
float px=dx*ca+dy*sa,py=-dx*sa+dy*ca;
|
||||
if(p.kind==DYMaskLinearGradient){
|
||||
@@ -117,7 +118,9 @@ inline float dyToolMaskShapeWeight(float x,float y,thread const DYMaskParameters
|
||||
float shorter=physicalWidth<physicalHeight?physicalWidth:physicalHeight;
|
||||
if(p.kind==DYMaskRectangle){float ax=px<0?-px:px,ay=py<0?-py:py,a=physicalWidth*.5f-ax,b=physicalHeight*.5f-ay;if(p.version==2&&(p.flags&DYMaskFeatherOutsideFlag)){if(p.feather==0)return a>=0&&b>=0?1:0;return dyToolMaskSoftStep(-p.feather*.5f*shorter,0,a<b?a:b);}if(a<0||b<0)return 0;if(p.feather==0)return 1;return dyToolMaskSoftStep(0,p.feather*.5f,(a<b?a:b)/shorter);}
|
||||
if(path.count<3||path.count>256)return 0;
|
||||
float u=px/physicalWidth,v=py/physicalHeight,sx=physicalWidth/shorter,sy=physicalHeight/shorter,distance2=1e10f;bool inside=false;
|
||||
float u=px/physicalWidth,v=py/physicalHeight;
|
||||
if(u<pathBounds.x||v<pathBounds.y||u>pathBounds.z||v>pathBounds.w)return 0;
|
||||
float sx=physicalWidth/shorter,sy=physicalHeight/shorter,distance2=1e10f;bool inside=false;
|
||||
for(int i=0,j=path.count-1;i<path.count;j=i++){
|
||||
float ax=path.x[j],ay=path.y[j],bx=path.x[i],by=path.y[i];if((ay>v)!=(by>v))if(u<(bx-ax)*(v-ay)/(by-ay)+ax)inside=!inside;
|
||||
float ex=(bx-ax)*sx,ey=(by-ay)*sy,xx=(u-ax)*sx,yy=(v-ay)*sy,den=ex*ex+ey*ey,t=den>1e-12f?dyClamp((xx*ex+yy*ey)/den,0,1):0;
|
||||
@@ -426,9 +429,35 @@ kernel void dyCloneStamps(texture2d<float,access::read> input [[texture(0)]],
|
||||
// Block-centre sampling is stable in image coordinates and never feeds back.
|
||||
kernel void dyLocalMosaic(texture2d<float,access::read> input [[texture(0)]],texture2d<float,access::write> output [[texture(1)]],device const DYToolMaskEntry* masks [[buffer(0)]],constant DYToolMaskHeader& h [[buffer(1)]],constant uint& block [[buffer(2)]],uint2 p [[thread_position_in_grid]]) {
|
||||
uint2 size=uint2(output.get_width(),output.get_height());if(any(p>=size))return;
|
||||
float4 original=input.read(p);float2 uv=(float2(p)+.5f)/float2(size);float3 code=dyToolEncode(original.a>0?original.rgb/original.a:float3(0));float coverage=0;
|
||||
if(h.section==-102){float x=h.offsetX+uv.x*h.scaleX,y=h.offsetY+uv.y*h.scaleY;for(uint i=0;i<h.count;i++)if(masks[i].section==-102)coverage=max(coverage,dyToolMask(x,y,code,masks[i].mask));}
|
||||
else if(h.count)coverage=dyToolCoverage(uv,code,masks,h,h.section);
|
||||
float4 original=input.read(p);
|
||||
float2 uv=(float2(p)+.5f)/float2(size);
|
||||
float x=h.offsetX+uv.x*h.scaleX,y=h.offsetY+uv.y*h.scaleY;
|
||||
float coverage=0;
|
||||
if(h.section==-102){
|
||||
for(uint i=0;i<h.count;i++){
|
||||
device const auto &entry=masks[i];
|
||||
if(entry.section==-102&&x>=entry.minX&&x<=entry.maxX&&y>=entry.minY&&y<=entry.maxY)
|
||||
coverage=max(coverage,dyToolMask(x,y,float3(0),entry.mask));
|
||||
}
|
||||
}else{
|
||||
bool found=false,encoded=false;
|
||||
float3 code=0;
|
||||
for(uint i=0;i<h.count;i++){
|
||||
device const auto &entry=masks[i];
|
||||
if(entry.section!=h.section)continue;
|
||||
DYMaskParameters parameters=entry.mask.parameters;
|
||||
if(!encoded&¶meters.kind>=DYMaskHSLKey){
|
||||
code=dyToolEncode(original.a>0?original.rgb/original.a:float3(0));
|
||||
encoded=true;
|
||||
}
|
||||
// Apply levels and inversion even when the path has no geometric coverage.
|
||||
float amount=parameters.kind==DYMaskBezier
|
||||
?dyToolMaskLevels(dyToolMaskShapeWeight(x,y,parameters,entry.mask.path,float4(entry.minX,entry.minY,entry.maxX,entry.maxY)),parameters)
|
||||
:dyToolMaskOperator(x,y,code,parameters,entry.mask.path);
|
||||
coverage=found?1-(1-coverage)*(1-amount):amount;
|
||||
found=true;
|
||||
}
|
||||
}
|
||||
if(coverage<=0){output.write(original,p);return;}
|
||||
uint2 q=min((p/block)*block+block/2,size-1);float4 sample=input.read(q);
|
||||
// Preserve the pixel's original alpha and prevent transparent samples turning
|
||||
|
||||
在新工单中引用
屏蔽一个用户