Shader"Unlit/DepthProjector_Atlas"{Properties{_AtlasTex("Atlas(RGBA)",2D)="black"{}//Intrinsics/image_ImageSize("ImageSize(W,H)",Vector)=(1280,100,0,0)_FxFyCxCy("fx,fy,cx,cy",Vector)=(800,800,640,540)_HalfPixel("Pixel-centeroffset(0or0.5)",Float)=0.5//Depthdecode(near=white)_DepthMode("DepthMode(0=Single,1=SplitHI/LO)",Float)=0_MapType("Map(0=Linear,1=MuLaw)",Float)=0_NearFar("Linearnear,far(m)",V
ector)=(0.5,2.5,0,0)_MuXMax("MuLawmu,xmax",Vector)=(50.0,2048.0,0,0)_WhiteNear("WhiteNear(0/1)",Float)=1//Defloor(undoatlas10-bitfloorbeforeshaping)_DepthFloorCodes("Depthfloor(10-bitcodes)",Float)=0//e.g.120//Unitshaping(EXPANDSdynamicrange)//0None,1=GammaExpand,2=LogExpand,3=ReinhardExpand,4=PivotPowExpand,5=InvLog,6=InvLog+Shoulder_UnitShape("UnitShaping(0=None,1=Gamma,2=Log,3=Reinhard,4=PivotP
ow,5=InvLog,6=InvLogHi)",Float)=0_UnitGamma("Gamma(>1expands)",Float)=2.0_UnitLogA("LogA(>0)",Float)=4.0_UnitReinhardA("ReinhardA(>0)",Float)=1.0_UnitPivot("Pivot(0..1)",Float)=.75_UnitGammaNear("PivotPowGammaNear(>1expand)",Float)=1.6_UnitGammaFar("PivotPowGammaFar(>1expand)",Float)=1.6_UnitInvK("InvLogk(1..30)",Float)=20.0_UnitHiS("InvLogShoulders(0.5..1)",Float)=0.8_UnitMix("Mixwithoriginal(0..
1)",Float)=0.0//Atlastiles(x,yin{0,1})top:COLOR|DEPTH,bottom:MATTE|EMPTY_TileColor("TileCOLOR(x,y)",Vector)=(0,1,0,0)//TL_TileDepth("TileDEPTH(single)",Vector)=(1,1,0,0)//TR_TileMask(TileMATTE(x,y)",Vector)=(0,0,0,0)//BL_TileDepthHI("TileDEPTHHI(x,y)",Vector)=(1,1,0,0)//if_DepthMode=1_TileDepthLO("TileDEPTHLO(x,y)",Vector)=(1,0,0,0)//ifsplit//Masking/orientation_MaskThresh("MaskThreshold",Range(0,
1))=0.0_MaskFromColor("UseCOLORluminanceasmask(0/1)",Float)=0_MaskZeroEps("Treat<=thisaszero",Float)=0.02_UseTLAlpha("UseCOLORAlpha(0/1)",Float)=0_FlipV("FlipV(0/1)",Float)=0_ProjectForward("Projectalong+Z(0=no,1=yes)",Float)=0_FlipX("FlipXgeometry(0/1)",Float)=1_ZOffset("ZOffset(meters)",Float)=0//---Re-introduced:robustmask/edgehelpers---_MaskFeather("MaskFeather(px)",Float)=0.75_MaskErodePx("Ma
skErode(px)",Float)=0.0//Depth-edgecut(disconnectfrombackplane)_CutEnable("Cutbydepthjump(0/1)",Float)=1_CutDZ("Depthjumpthreshold(m)",Float)=0.08_CutFeather("Cutfeather(px)",Float)=1.0_CutPx("Cutsampleradius(px)",Float)=1.0_CutRel("Cutrelativedzfactor",Float)=0.15//Foreshortening:blendXYtowardZRef;optionalZflatten_OrthoBlend("OrthoBlend(0..1)",Range(0,1))=0.0_ZRef("ReferenceZ(m)",Float)=2.0_MinZ(
"MinZClamp(m)",Float)=0.3_AffectZ("ApplyZRemap(0/1)",Float)=0}SubShader{Tags{"RenderType"="Opaque""Queue"="Geometry"}CullOffZWriteOnZTestLEqualLightingOffBlendOneZeroPass{CGPROGRAM#pragmavertexvert#pragmafragmentfrag#pragmatarget3.0#include"UnityCG.cginc"sampler2D_AtlasTex;float4_ImageSize,_FxFyCxCy;float_DepthMode,_MapType,_WhiteNear,_HalfPixel;float4_NearFar,_MuXMax;//defloorfloat_DepthFloorCode
s;//shapingfloat_UnitShape,_UnitGamma,_UnitLogA,_UnitReinhardA;float_UnitPivot,_UnitGammaNear,_UnitGammaFar,UnitInvK,_UnitHiS,_UnitMix;float4_TileColor,_TileMask,_TileDepth,_TileDepthHI,_TileDepthLO;float_MaskThresh,_MaskFromColor,MaskZeroEps,_UseTLAlpha;float_FlipV,_ProjectForward,_FlipX,_ZOffset;//reintroducedhelpersfloat_MaskFeather,_MaskErodePx;float_CutEnable,_CutDZ,_CutFeather,_CutPx,_CutRel
;float_OrthoBlend,_ZRef,_MinZ,_AffectZ;structappdata{float4vertex:POSITION;float2uv:TEXCOORD0;};structv2f{float4pos:SV_POSITION;float2uvColor:TEXCOORD0;float2uvMask:TEXCOORD1;float2uvDepth:TEXCOORD2;//depthtileUVinatlasspacefloat2uv01:TEXCOORD3;//0..1withFlipVapplied(formath)};//---UVhelpers---float2TileUV(float2uv01in,float2tileXY){float2uv=uv01_in;if(_FlipV>0.5)uv.y=1.0-uv.y;constfloat2tileSize=
float2(0.5,0.5);float2origin=tileXY.xy*tileSize;returnorigin+uv*tileSize;}//---reads---floatReadByte(float2uv)floatv=tex2Dlod(_AtlasTex,float4(uv,0,0)).r;returnfloor(v*255.0+0.5);}floatReadUnit_Single(float2uvD)returnsaturate(tex2Dlod(_AtlasTex,float4(uvD,0,0)).r);}floatReadUnit_Split(float2uvHI,float2uvLO)floathi=ReadByte(uvHI),lo=ReadByte(uvLO);return(hi*256.0+lo)/65535.0;}//Defloor(undo10-bitfl
oor)floatDefloorUnit(floatu){floatf=saturate(_DepthFloorCodes/1023.0);//e.g.120/1023floatdenom=max(1.0-f,1e-6);returnsaturate((u-f)/denom);}//Inverse-logstyleexpansionfloatInvLogExpand(floatu,floatk){k=max(k,1e-6);floatdenom=1.0-exp(-k);returnsaturate((1.0-exp(-k*saturate(u)))/denom);}//Inverse-logwithgentlehighlightshoulder(weightslargervaluesabitmore)floatInvLogExpandHi(floatu,floatk,floats){k=m
ax(k,1e-6);s=clamp(s,1e-3,1.0);floatdenom=1.0-exp(-k);floatg=(1.0-exp(-k*saturate(u)))/denom;//baseinverse-logreturnsaturate(1.0-pow(1.0-,s));}//EXPANSIONcurvesfloatShapeExpand(floatu){u=saturate(u);if(_UnitShape<0.5)returnu;floatorig=u;//1)GammaExpandif(_UnitShape<1.5){floatg=max(_UnitGamma,1e-6);u=pow(u,1.0/g);}//2)LogExpand(inverseoflogcompress)elseif(_UnitShape<2.5){floata=max(_UnitLogA,1e-6);
u=(pow(1.0a,u)-1.0)/a;}//3)ReinhardExpand:inverseofu/(1+Au)elseif(_UnitShape<3.5){floatA=max(_UnitReinhardA,1e-6);floatdenom=max(1.0-A*u,1e-6);u=u/denom;}//4)PivotPowExpand(useexponents<1toexpand)elseif(_UnitShape<4.5){floatp=saturate(_UnitPivot);floatgN=max(_UnitGammaNear,1e-6);floatgF=max(_UnitGammaFar,1e-6);floateN=(gN>=1.0)?(1.0/gN):gN;floateF=(gF>=.0)?(1.0/gF):gF;if(u<=p){floatt=(p>1e-6)?(u/p
):0.0;u=p*pow(t,eF);}else{floatt=(1.0-u)/max(1.0-p,1e-6);u=1.0-(1.0-)*pow(t,eN);}}//5)InvLogelseif(_UnitShape<5.5){u=InvLogExpand(u,_UnitInvK);}//6)InvLogwithhighlightshoulderelse{u=InvLogExpandHi(u,UnitInvK,UnitHiS);}//optionalblendbacktowardoriginalu=lerp(u,orig,saturate(_UnitMix));returnsaurate(u);}//unit->meters(assumingnear=whiteif_WhiteNear=1)floatUnitToMeters(floatu){floaty=(_WhiteNear>0.5)
?u:(1.0-u);//enforcenear=whiteif(_MapType<0.5){floatnearZ=_NearFar.x,farZ=_NearFar.y;returnnearZ+(1.0-y)*(farZ-nearZ);}else{floatmu=_MuXMax.x,xmax=_MuXMax.y;floatval=exp(y*log(1.0+mu))-1.0;return(val/mu)*xmax;}}//masksampling(withoptionalerosion+feather)float2TileTexelStep(){returnfloat2(1.0/(_ImageSize.x*2.0),1.0/(_ImageSize.y*2.0));}floatSampleMaskRawAt(float2uvMask,float2uvColor){if(_MaskFromCo
lor>0.5){float3rgb=tex2Dlod(_AtlasTex,float4(uvColor,0,0)).rgb;returndot(rgb,float3(0.2126,0.7152,0.0722));}else{returntex2Dlod(_AtlasTex,float4(uvMask,0,0)).r;}}floatErodeMask(float2uvMask,float2uvColor,float2step){//radiusinwholepixelsfloatrpx=max(0.0,_MaskErodePx);if(rpx<0.5)returnSampleMaskRawAt(uvMask,uvColor);float2d=round(rpx)*step;//8-eighborhoodmin(cheapmorphologicalerosion)floatmC=Sample
MaskRawAt(uvMask,uvColor);floatm=mC;m=min(m,SampleMaskRawAt(uvMask+float2(d.x,0),uvColor+float2(d.x,0)));m=min(m,SampleMaskRawAt(uvask+float2(-d.x,0),uvColor+float2(-d.x,0)));m=min(m,SampleMaskRawAt(uvMask+float2(0,d.y),uvColor+float2(0,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(0,-d.y),uvColor+float2(0,-.y)));m=min(m,SampleMaskRawAt(uvMask+float2(d.x,d.y),uvColor+float2(d.x,d.y)));m=min(m,Sampl
eMaskRawAt(uvMask+float2(d.x,-.y),uvColor+float2(d.x,-d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(-d.x,d.y),uvColor+float2(-d.x,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(-.x,-d.y),uvColor+float2(-d.x,-d.y)));returnm;}floatSampleMaskFeathered(float2uvMask,float2uvColor){float2step=TileTexelStep();floatm=ErodeMask(uvMask,uvColor,step);if(m<=_MaskZeroEps)m=0.0;//Featherinpx→converttoatinyscalarwi
ndowvia1/NwhereN~pixelsacrosstheatlasheight.//Thisisaheuristicjusttosoftendiscard:floateps=max(_MaskFeathr,0.0)/(_ImageSize.y*0.5+1e-6);returnsmoothstep(_MaskThresh-eps,_MaskThresh+eps,m);}v2fvert(appdatav){v2fo;//uv01formath(FlipVhere;TileUValsoflipsforsampling)o.uv01=v.uv;if(_FlipV>0.5)o.uv01.y=1.0-o.uv01.y;//ComputeatlasUVsforeachtileONCEo.uvColor=TileUV(v.uv,_TileColor.xy);o.uvMask=TileUV(v.uv
,_TileMask.xy);o.uvDepth=TileUV(v.uv,TileDepth.xy);//----Depthfetch&shaping(VERTEX)----floatuRaw=(_DepthMode<0.5)?ReadUnit_Single(o.uvDepth):ReadUnit_Split(TileUV(v.uv,_TileDepthHI.xy),TileUV(v.uv,_TileDepthLO.xy));floatuDef=DefloorUnit(uRaw);floatuShaped=ShapeExpand(uDef);floatZm=UnitToMeters(uShaped);//sign/orientation&minimumZfloatcamZ=(ProjectForward>0.5)?+Zm:-Zm;floatzAbs=max(abs(camZ),_MinZ)
;floatzSign=(camZ>=0)?1.0:-1.0;camZ=zSign*zAbs;//pixelcenters(HalfPixel=0.5)float2wh=_ImageSize.xy;floatpx=o.uv01.x*wh.x-_HalfPixel;floatpy=o.uv01.y*wh.y-_HalfPixel;//intrinsicsfloatfx=_FxFyCxCy.x,fy=_FxFyCxCy.y,cx=_FxFyCCy.z,cy=_FxFyCxCy.w;//Foreshortening(XYonlyunless_AffectZ)floatzForXY=lerp(zAbs,_ZRef,saturate(_OrthoBlend));floatX=(px-cx)*((zSign*zForXY)/fx);floatY=(py-cy)*((zSign*zForXY)/fy);
if(_FlipX>0.5)X=-X;floatoutZ=(_AffectZ>0.5)?(zSign*zForXY):camZ;float4objPos=float4(X,-Y,outZ+_ZOffset,1.0);o.pos=UnityObjectToClipPos(objPos);returno;}fixed4frag(v2fi):SV_Target{//1)Mask(witherosion+feather)&colorfloatmSoft=SampleMaskFeathered(i.uvMask,i.uvColor);if(mSoft<=0.0)discard;fixed4col=tex2D(_AtlasTex,i.uvColor);if(_UseTLAlpha>0.5&&col.a<_MaskThresh)discard;//2)Strongdepth-edgecutusingDE
PTHUV(8-eighbors@radiusCutPx)if(_CutEnable>0.5){float2step=TileTexelStep();floatrpx=max(_CutPx,0.0);float2offs=round(max(rpx,1.0))*step;//center+neighborsfloatuC=ReadUnit_Single(i.uvDepth);flotzC=UnitToMeters(ShapeExpand(DefloorUnit(uC)));floatuR=ReadUnit_Single(i.uvDepth+float2(offs.x,0));floatuL=ReadUnit_Single(i.uvDepth+float2(-ffs.x,0));floatuU=ReadUnit_Single(i.uvDepth+float2(0,offs.y));float
uD=ReadUnit_Single(i.uvDepth+float2(0,-offs.y));floatuRU=ReadUnit_Single(i.uvDepth+float2(offs.x,offs.y));floatuRD=ReadUnit_Single(i.uvDepth+float2(offs.x,-offs.y));floatuLU=ReadUnit_Single(i.uvDepth+float2(-offs.x,offs.y));floatuLD=ReadUnit_Single(i.uvDepth+float2(-offs.x,-offs.y));floatzR=UnitToMeters(ShapeExpand(DefloorUnit(uR)));floatzL=UnitToMeters(ShapeExpand(DefloorUnit(uL)));floatzU=UnitTo
Meters(ShapeExpand(DfloorUnit(uU)));floatzD=UnitToMeters(ShapeExpand(DefloorUnit(uD)));floatzRU=UnitToMeters(ShapeExpand(DefloorUnit(uRU)));floatzRD=UnitToMeters(ShaeExpand(DefloorUnit(uRD)));floatzLU=UnitToMeters(ShapeExpand(DefloorUnit(uLU)));floatzLD=UnitToMeters(ShapeExpand(DefloorUnit(uLD)));floatdz=0.0;dz=max(dz,abs(zC-zR));dz=max(dz,abs(zC-zL));dz=max(dz,abs(zC-zU));dz=max(dz,abs(zC-zD));dz
=max(dz,abs(zC-zRU));dz=max(dz,abs(zC-zRD));dz=max(dz,abs(zC-zLU));dz=max(dz,abs(zC-zLD));//absolute+relativethresholdfloatth=_CutDZ+_CutRel*max(zC,1e-6);if(dz>th){if(_CutFeather<=.0)iscard;//softfeatherbasedonexcessoverthresholdfloatw=saturate((dz-th)/(th*0.5+1e-6));if(w>0.0)discard;}}//Output:keepsoftmaskasalpha(helpsatedges)col.a=mSoft;returncol;}ENDCG}}FallBackOff}Shader"Unlit/DepthProjector_A
tlas"{Properties{_AtlasTex("Atlas(RGBA)",2D)="black"{}//Intrinsics/image_ImageSize("ImageSize(W,H)",Vector)=(1280,100,0,0)_FxFyCxCy("fx,fy,cx,cy",Vector)=(800,800,640,540)_HalfPixel("Pixel-centeroffset(0or0.5)",Float)=0.5//Depthdecode(near=white)_DepthMode("DepthMode(0=Single,1=SplitHI/LO)",Float)=0_MapType("Map(0=Linear,1=MuLaw)",Float)=0_NearFar("Linearnear,far(m)",Vector)=(0.5,2.5,0,0)_MuXMax("
MuLawmu,xmax",Vector)=(50.0,2048.0,0,0)_WhiteNear("WhiteNear(0/1)",Float)=1//Defloor(undoatlas10-bitfloorbeforeshaping)_DepthFloorCodes("Depthfloor(10-bitcodes)",Float)=0//e.g.120//Unitshaping(EXPANDSdynamicrange)//0None,1=GammaExpand,2=LogExpand,3=ReinhardExpand,4=PivotPowExpand,5=InvLog,6=InvLog+Shoulder_UnitShape("UnitShaping(0=None,1=Gamma,2=Log,3=Reinhard,4=PivotPow,5=InvLog,6=InvLogHi)",Floa
t)=0_UnitGamma("Gamma(>1expands)",Float)=2.0_UnitLogA("LogA(>0)",Float)=4.0_UnitReinhardA("ReinhardA(>0)",Float)=1.0_UnitPivot("Pivot(0..1)",Float)=.75_UnitGammaNear("PivotPowGammaNear(>1expand)",Float)=1.6_UnitGammaFar("PivotPowGammaFar(>1expand)",Float)=1.6_UnitInvK("InvLogk(1..30)",Float)=20.0_UnitHiS("InvLogShoulders(0.5..1)",Float)=0.8_UnitMix("Mixwithoriginal(0..1)",Float)=0.0//Atlastiles(x,
yin{0,1})top:COLOR|DEPTH,bottom:MATTE|EMPTY_TileColor("TileCOLOR(x,y)",Vector)=(0,1,0,0)//TL_TileDepth("TileDEPTH(single)",Vector)=(1,1,0,0)//TR_TileMask(TileMATTE(x,y)",Vector)=(0,0,0,0)//BL_TileDepthHI("TileDEPTHHI(x,y)",Vector)=(1,1,0,0)//if_DepthMode=1_TileDepthLO("TileDEPTHLO(x,y)",Vector)=(1,0,0,0)//ifsplit//Masking/orientation_MaskThresh("MaskThreshold",Range(0,1))=0.0_MaskFromColor("UseCOL
ORluminanceasmask(0/1)",Float)=0_MaskZeroEps("Treat<=thisaszero",Float)=0.02_UseTLAlpha("UseCOLORAlpha(0/1)",Float)=0_FlipV("FlipV(0/1)",Float)=0_ProjectForward("Projectalong+Z(0=no,1=yes)",Float)=0_FlipX("FlipXgeometry(0/1)",Float)=1_ZOffset("ZOffset(meters)",Float)=0//---Re-introduced:robustmask/edgehelpers---_MaskFeather("MaskFeather(px)",Float)=0.75_MaskErodePx("MaskErode(px)",Float)=0.0//Dept
h-edgecut(disconnectfrombackplane)_CutEnable("Cutbydepthjump(0/1)",Float)=1_CutDZ("Depthjumpthreshold(m)",Float)=0.08_CutFeather("Cutfeather(px)",Float)=1.0_CutPx("Cutsampleradius(px)",Float)=1.0_CutRel("Cutrelativedzfactor",Float)=0.15//Foreshortening:blendXYtowardZRef;optionalZflatten_OrthoBlend("OrthoBlend(0..1)",Range(0,1))=0.0_ZRef("ReferenceZ(m)",Float)=2.0_MinZ("MinZClamp(m)",Float)=0.3_Aff
ectZ("ApplyZRemap(0/1)",Float)=0}SubShader{Tags{"RenderType"="Opaque""Queue"="Geometry"}CullOffZWriteOnZTestLEqualLightingOffBlendOneZeroPass{CGPROGRAM#pragmavertexvert#pragmafragmentfrag#pragmatarget3.0#include"UnityCG.cginc"sampler2D_AtlasTex;float4_ImageSize,_FxFyCxCy;float_DepthMode,_MapType,_WhiteNear,_HalfPixel;float4_NearFar,_MuXMax;//defloorfloat_DepthFloorCodes;//shapingfloat_UnitShape,_U
nitGamma,_UnitLogA,_UnitReinhardA;float_UnitPivot,_UnitGammaNear,_UnitGammaFar,UnitInvK,_UnitHiS,_UnitMix;float4_TileColor,_TileMask,_TileDepth,_TileDepthHI,_TileDepthLO;float_MaskThresh,_MaskFromColor,MaskZeroEps,_UseTLAlpha;float_FlipV,_ProjectForward,_FlipX,_ZOffset;//reintroducedhelpersfloat_MaskFeather,_MaskErodePx;float_CutEnable,_CutDZ,_CutFeather,_CutPx,_CutRel;float_OrthoBlend,_ZRef,_MinZ
,_AffectZ;structappdata{float4vertex:POSITION;float2uv:TEXCOORD0;};structv2f{float4pos:SV_POSITION;float2uvColor:TEXCOORD0;float2uvMask:TEXCOORD1;float2uvDepth:TEXCOORD2;//depthtileUVinatlasspacefloat2uv01:TEXCOORD3;//0..1withFlipVapplied(formath)};//---UVhelpers---float2TileUV(float2uv01in,float2tileXY){float2uv=uv01_in;if(_FlipV>0.5)uv.y=1.0-uv.y;constfloat2tileSize=float2(0.5,0.5);float2origin=
tileXY.xy*tileSize;returnorigin+uv*tileSize;}//---reads---floatReadByte(float2uv)floatv=tex2Dlod(_AtlasTex,float4(uv,0,0)).r;returnfloor(v*255.0+0.5);}floatReadUnit_Single(float2uvD)returnsaturate(tex2Dlod(_AtlasTex,float4(uvD,0,0)).r);}floatReadUnit_Split(float2uvHI,float2uvLO)floathi=ReadByte(uvHI),lo=ReadByte(uvLO);return(hi*256.0+lo)/65535.0;}//Defloor(undo10-bitfloor)floatDefloorUnit(floatu){
floatf=saturate(_DepthFloorCodes/1023.0);//e.g.120/1023floatdenom=max(1.0-f,1e-6);returnsaturate((u-f)/denom);}//Inverse-logstyleexpansionfloatInvLogExpand(floatu,floatk){k=max(k,1e-6);floatdenom=1.0-exp(-k);returnsaturate((1.0-exp(-k*saturate(u)))/denom);}//Inverse-logwithgentlehighlightshoulder(weightslargervaluesabitmore)floatInvLogExpandHi(floatu,floatk,floats){k=max(k,1e-6);s=clamp(s,1e-3,1.0
);floatdenom=1.0-exp(-k);floatg=(1.0-exp(-k*saturate(u)))/denom;//baseinverse-logreturnsaturate(1.0-pow(1.0-,s));}//EXPANSIONcurvesfloatShapeExpand(floatu){u=saturate(u);if(_UnitShape<0.5)returnu;floatorig=u;//1)GammaExpandif(_UnitShape<1.5){floatg=max(_UnitGamma,1e-6);u=pow(u,1.0/g);}//2)LogExpand(inverseoflogcompress)elseif(_UnitShape<2.5){floata=max(_UnitLogA,1e-6);u=(pow(1.0a,u)-1.0)/a;}//3)Re
inhardExpand:inverseofu/(1+Au)elseif(_UnitShape<3.5){floatA=max(_UnitReinhardA,1e-6);floatdenom=max(1.0-A*u,1e-6);u=u/denom;}//4)PivotPowExpand(useexponents<1toexpand)elseif(_UnitShape<4.5){floatp=saturate(_UnitPivot);floatgN=max(_UnitGammaNear,1e-6);floatgF=max(_UnitGammaFar,1e-6);floateN=(gN>=1.0)?(1.0/gN):gN;floateF=(gF>=.0)?(1.0/gF):gF;if(u<=p){floatt=(p>1e-6)?(u/p):0.0;u=p*pow(t,eF);}else{flo
att=(1.0-u)/max(1.0-p,1e-6);u=1.0-(1.0-)*pow(t,eN);}}//5)InvLogelseif(_UnitShape<5.5){u=InvLogExpand(u,_UnitInvK);}//6)InvLogwithhighlightshoulderelse{u=InvLogExpandHi(u,UnitInvK,UnitHiS);}//optionalblendbacktowardoriginalu=lerp(u,orig,saturate(_UnitMix));returnsaurate(u);}//unit->meters(assumingnear=whiteif_WhiteNear=1)floatUnitToMeters(floatu){floaty=(_WhiteNear>0.5)?u:(1.0-u);//enforcenear=whit
eif(_MapType<0.5){floatnearZ=_NearFar.x,farZ=_NearFar.y;returnnearZ+(1.0-y)*(farZ-nearZ);}else{floatmu=_MuXMax.x,xmax=_MuXMax.y;floatval=exp(y*log(1.0+mu))-1.0;return(val/mu)*xmax;}}//masksampling(withoptionalerosion+feather)float2TileTexelStep(){returnfloat2(1.0/(_ImageSize.x*2.0),1.0/(_ImageSize.y*2.0));}floatSampleMaskRawAt(float2uvMask,float2uvColor){if(_MaskFromColor>0.5){float3rgb=tex2Dlod(_
AtlasTex,float4(uvColor,0,0)).rgb;returndot(rgb,float3(0.2126,0.7152,0.0722));}else{returntex2Dlod(_AtlasTex,float4(uvMask,0,0)).r;}}floatErodeMask(float2uvMask,float2uvColor,float2step){//radiusinwholepixelsfloatrpx=max(0.0,_MaskErodePx);if(rpx<0.5)returnSampleMaskRawAt(uvMask,uvColor);float2d=round(rpx)*step;//8-eighborhoodmin(cheapmorphologicalerosion)floatmC=SampleMaskRawAt(uvMask,uvColor);flo
atm=mC;m=min(m,SampleMaskRawAt(uvMask+float2(d.x,0),uvColor+float2(d.x,0)));m=min(m,SampleMaskRawAt(uvask+float2(-d.x,0),uvColor+float2(-d.x,0)));m=min(m,SampleMaskRawAt(uvMask+float2(0,d.y),uvColor+float2(0,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(0,-d.y),uvColor+float2(0,-.y)));m=min(m,SampleMaskRawAt(uvMask+float2(d.x,d.y),uvColor+float2(d.x,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(d.x,
-.y),uvColor+float2(d.x,-d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(-d.x,d.y),uvColor+float2(-d.x,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(-.x,-d.y),uvColor+float2(-d.x,-d.y)));returnm;}floatSampleMaskFeathered(float2uvMask,float2uvColor){float2step=TileTexelStep();floatm=ErodeMask(uvMask,uvColor,step);if(m<=_MaskZeroEps)m=0.0;//Featherinpx→converttoatinyscalarwindowvia1/NwhereN~pixelsacross
theatlasheight.//Thisisaheuristicjusttosoftendiscard:floateps=max(_MaskFeathr,0.0)/(_ImageSize.y*0.5+1e-6);returnsmoothstep(_MaskThresh-eps,_MaskThresh+eps,m);}v2fvert(appdatav){v2fo;//uv01formath(FlipVhere;TileUValsoflipsforsampling)o.uv01=v.uv;if(_FlipV>0.5)o.uv01.y=1.0-o.uv01.y;//ComputeatlasUVsforeachtileONCEo.uvColor=TileUV(v.uv,_TileColor.xy);o.uvMask=TileUV(v.uv,_TileMask.xy);o.uvDepth=Tile
UV(v.uv,TileDepth.xy);//----Depthfetch&shaping(VERTEX)----floatuRaw=(_DepthMode<0.5)?ReadUnit_Single(o.uvDepth):ReadUnit_Split(TileUV(v.uv,_TileDepthHI.xy),TileUV(v.uv,_TileDepthLO.xy));floatuDef=DefloorUnit(uRaw);floatuShaped=ShapeExpand(uDef);floatZm=UnitToMeters(uShaped);//sign/orientation&minimumZfloatcamZ=(ProjectForward>0.5)?+Zm:-Zm;floatzAbs=max(abs(camZ),_MinZ);floatzSign=(camZ>=0)?1.0:-1.
0;camZ=zSign*zAbs;//pixelcenters(HalfPixel=0.5)float2wh=_ImageSize.xy;floatpx=o.uv01.x*wh.x-_HalfPixel;floatpy=o.uv01.y*wh.y-_HalfPixel;//intrinsicsfloatfx=_FxFyCxCy.x,fy=_FxFyCxCy.y,cx=_FxFyCCy.z,cy=_FxFyCxCy.w;//Foreshortening(XYonlyunless_AffectZ)floatzForXY=lerp(zAbs,_ZRef,saturate(_OrthoBlend));floatX=(px-cx)*((zSign*zForXY)/fx);floatY=(py-cy)*((zSign*zForXY)/fy);if(_FlipX>0.5)X=-X;floatoutZ=
(_AffectZ>0.5)?(zSign*zForXY):camZ;float4objPos=float4(X,-Y,outZ+_ZOffset,1.0);o.pos=UnityObjectToClipPos(objPos);returno;}fixed4frag(v2fi):SV_Target{//1)Mask(witherosion+feather)&colorfloatmSoft=SampleMaskFeathered(i.uvMask,i.uvColor);if(mSoft<=0.0)discard;fixed4col=tex2D(_AtlasTex,i.uvColor);if(_UseTLAlpha>0.5&&col.a<_MaskThresh)discard;//2)Strongdepth-edgecutusingDEPTHUV(8-eighbors@radiusCutPx)
if(_CutEnable>0.5){float2step=TileTexelStep();floatrpx=max(_CutPx,0.0);float2offs=round(max(rpx,1.0))*step;//center+neighborsfloatuC=ReadUnit_Single(i.uvDepth);flotzC=UnitToMeters(ShapeExpand(DefloorUnit(uC)));floatuR=ReadUnit_Single(i.uvDepth+float2(offs.x,0));floatuL=ReadUnit_Single(i.uvDepth+float2(-ffs.x,0));floatuU=ReadUnit_Single(i.uvDepth+float2(0,offs.y));floatuD=ReadUnit_Single(i.uvDepth+
float2(0,-offs.y));floatuRU=ReadUnit_Single(i.uvDepth+float2(offs.x,offs.y));floatuRD=ReadUnit_Single(i.uvDepth+float2(offs.x,-offs.y));floatuLU=ReadUnit_Single(i.uvDepth+float2(-offs.x,offs.y));floatuLD=ReadUnit_Single(i.uvDepth+float2(-offs.x,-offs.y));floatzR=UnitToMeters(ShapeExpand(DefloorUnit(uR)));floatzL=UnitToMeters(ShapeExpand(DefloorUnit(uL)));floatzU=UnitToMeters(ShapeExpand(DfloorUnit
(uU)));floatzD=UnitToMeters(ShapeExpand(DefloorUnit(uD)));floatzRU=UnitToMeters(ShapeExpand(DefloorUnit(uRU)));floatzRD=UnitToMeters(ShaeExpand(DefloorUnit(uRD)));floatzLU=UnitToMeters(ShapeExpand(DefloorUnit(uLU)));floatzLD=UnitToMeters(ShapeExpand(DefloorUnit(uLD)));floatdz=0.0;dz=max(dz,abs(zC-zR));dz=max(dz,abs(zC-zL));dz=max(dz,abs(zC-zU));dz=max(dz,abs(zC-zD));dz=max(dz,abs(zC-zRU));dz=max(d
z,abs(zC-zRD));dz=max(dz,abs(zC-zLU));dz=max(dz,abs(zC-zLD));//absolute+relativethresholdfloatth=_CutDZ+_CutRel*max(zC,1e-6);if(dz>th){if(_CutFeather<=.0)iscard;//softfeatherbasedonexcessoverthresholdfloatw=saturate((dz-th)/(th*0.5+1e-6));if(w>0.0)discard;}}//Output:keepsoftmaskasalpha(helpsatedges)col.a=mSoft;returncol;}ENDCG}}FallBackOff}Shader"Unlit/DepthProjector_Atlas"{Properties{_AtlasTex("A
tlas(RGBA)",2D)="black"{}//Intrinsics/image_ImageSize("ImageSize(W,H)",Vector)=(1280,100,0,0)_FxFyCxCy("fx,fy,cx,cy",Vector)=(800,800,640,540)_HalfPixel("Pixel-centeroffset(0or0.5)",Float)=0.5//Depthdecode(near=white)_DepthMode("DepthMode(0=Single,1=SplitHI/LO)",Float)=0_MapType("Map(0=Linear,1=MuLaw)",Float)=0_NearFar("Linearnear,far(m)",Vector)=(0.5,2.5,0,0)_MuXMax("MuLawmu,xmax",Vector)=(50.0,2
048.0,0,0)_WhiteNear("WhiteNear(0/1)",Float)=1//Defloor(undoatlas10-bitfloorbeforeshaping)_DepthFloorCodes("Depthfloor(10-bitcodes)",Float)=0//e.g.120//Unitshaping(EXPANDSdynamicrange)//0None,1=GammaExpand,2=LogExpand,3=ReinhardExpand,4=PivotPowExpand,5=InvLog,6=InvLog+Shoulder_UnitShape("UnitShaping(0=None,1=Gamma,2=Log,3=Reinhard,4=PivotPow,5=InvLog,6=InvLogHi)",Float)=0_UnitGamma("Gamma(>1expan
ds)",Float)=2.0_UnitLogA("LogA(>0)",Float)=4.0_UnitReinhardA("ReinhardA(>0)",Float)=1.0_UnitPivot("Pivot(0..1)",Float)=.75_UnitGammaNear("PivotPowGammaNear(>1expand)",Float)=1.6_UnitGammaFar("PivotPowGammaFar(>1expand)",Float)=1.6_UnitInvK("InvLogk(1..30)",Float)=20.0_UnitHiS("InvLogShoulders(0.5..1)",Float)=0.8_UnitMix("Mixwithoriginal(0..1)",Float)=0.0//Atlastiles(x,yin{0,1})top:COLOR|DEPTH,bott
om:MATTE|EMPTY_TileColor("TileCOLOR(x,y)",Vector)=(0,1,0,0)//TL_TileDepth("TileDEPTH(single)",Vector)=(1,1,0,0)//TR_TileMask(TileMATTE(x,y)",Vector)=(0,0,0,0)//BL_TileDepthHI("TileDEPTHHI(x,y)",Vector)=(1,1,0,0)//if_DepthMode=1_TileDepthLO("TileDEPTHLO(x,y)",Vector)=(1,0,0,0)//ifsplit//Masking/orientation_MaskThresh("MaskThreshold",Range(0,1))=0.0_MaskFromColor("UseCOLORluminanceasmask(0/1)",Float
)=0_MaskZeroEps("Treat<=thisaszero",Float)=0.02_UseTLAlpha("UseCOLORAlpha(0/1)",Float)=0_FlipV("FlipV(0/1)",Float)=0_ProjectForward("Projectalong+Z(0=no,1=yes)",Float)=0_FlipX("FlipXgeometry(0/1)",Float)=1_ZOffset("ZOffset(meters)",Float)=0//---Re-introduced:robustmask/edgehelpers---_MaskFeather("MaskFeather(px)",Float)=0.75_MaskErodePx("MaskErode(px)",Float)=0.0//Depth-edgecut(disconnectfrombackp
lane)_CutEnable("Cutbydepthjump(0/1)",Float)=1_CutDZ("Depthjumpthreshold(m)",Float)=0.08_CutFeather("Cutfeather(px)",Float)=1.0_CutPx("Cutsampleradius(px)",Float)=1.0_CutRel("Cutrelativedzfactor",Float)=0.15//Foreshortening:blendXYtowardZRef;optionalZflatten_OrthoBlend("OrthoBlend(0..1)",Range(0,1))=0.0_ZRef("ReferenceZ(m)",Float)=2.0_MinZ("MinZClamp(m)",Float)=0.3_AffectZ("ApplyZRemap(0/1)",Float
)=0}SubShader{Tags{"RenderType"="Opaque""Queue"="Geometry"}CullOffZWriteOnZTestLEqualLightingOffBlendOneZeroPass{CGPROGRAM#pragmavertexvert#pragmafragmentfrag#pragmatarget3.0#include"UnityCG.cginc"sampler2D_AtlasTex;float4_ImageSize,_FxFyCxCy;float_DepthMode,_MapType,_WhiteNear,_HalfPixel;float4_NearFar,_MuXMax;//defloorfloat_DepthFloorCodes;//shapingfloat_UnitShape,_UnitGamma,_UnitLogA,_UnitReinh
ardA;float_UnitPivot,_UnitGammaNear,_UnitGammaFar,UnitInvK,_UnitHiS,_UnitMix;float4_TileColor,_TileMask,_TileDepth,_TileDepthHI,_TileDepthLO;float_MaskThresh,_MaskFromColor,MaskZeroEps,_UseTLAlpha;float_FlipV,_ProjectForward,_FlipX,_ZOffset;//reintroducedhelpersfloat_MaskFeather,_MaskErodePx;float_CutEnable,_CutDZ,_CutFeather,_CutPx,_CutRel;float_OrthoBlend,_ZRef,_MinZ,_AffectZ;structappdata{float
4vertex:POSITION;float2uv:TEXCOORD0;};structv2f{float4pos:SV_POSITION;float2uvColor:TEXCOORD0;float2uvMask:TEXCOORD1;float2uvDepth:TEXCOORD2;//depthtileUVinatlasspacefloat2uv01:TEXCOORD3;//0..1withFlipVapplied(formath)};//---UVhelpers---float2TileUV(float2uv01in,float2tileXY){float2uv=uv01_in;if(_FlipV>0.5)uv.y=1.0-uv.y;constfloat2tileSize=float2(0.5,0.5);float2origin=tileXY.xy*tileSize;returnorig
in+uv*tileSize;}//---reads---floatReadByte(float2uv)floatv=tex2Dlod(_AtlasTex,float4(uv,0,0)).r;returnfloor(v*255.0+0.5);}floatReadUnit_Single(float2uvD)returnsaturate(tex2Dlod(_AtlasTex,float4(uvD,0,0)).r);}floatReadUnit_Split(float2uvHI,float2uvLO)floathi=ReadByte(uvHI),lo=ReadByte(uvLO);return(hi*256.0+lo)/65535.0;}//Defloor(undo10-bitfloor)floatDefloorUnit(floatu){floatf=saturate(_DepthFloorCo
des/1023.0);//e.g.120/1023floatdenom=max(1.0-f,1e-6);returnsaturate((u-f)/denom);}//Inverse-logstyleexpansionfloatInvLogExpand(floatu,floatk){k=max(k,1e-6);floatdenom=1.0-exp(-k);returnsaturate((1.0-exp(-k*saturate(u)))/denom);}//Inverse-logwithgentlehighlightshoulder(weightslargervaluesabitmore)floatInvLogExpandHi(floatu,floatk,floats){k=max(k,1e-6);s=clamp(s,1e-3,1.0);floatdenom=1.0-exp(-k);floa
tg=(1.0-exp(-k*saturate(u)))/denom;//baseinverse-logreturnsaturate(1.0-pow(1.0-,s));}//EXPANSIONcurvesfloatShapeExpand(floatu){u=saturate(u);if(_UnitShape<0.5)returnu;floatorig=u;//1)GammaExpandif(_UnitShape<1.5){floatg=max(_UnitGamma,1e-6);u=pow(u,1.0/g);}//2)LogExpand(inverseoflogcompress)elseif(_UnitShape<2.5){floata=max(_UnitLogA,1e-6);u=(pow(1.0a,u)-1.0)/a;}//3)ReinhardExpand:inverseofu/(1+Au
)elseif(_UnitShape<3.5){floatA=max(_UnitReinhardA,1e-6);floatdenom=max(1.0-A*u,1e-6);u=u/denom;}//4)PivotPowExpand(useexponents<1toexpand)elseif(_UnitShape<4.5){floatp=saturate(_UnitPivot);floatgN=max(_UnitGammaNear,1e-6);floatgF=max(_UnitGammaFar,1e-6);floateN=(gN>=1.0)?(1.0/gN):gN;floateF=(gF>=.0)?(1.0/gF):gF;if(u<=p){floatt=(p>1e-6)?(u/p):0.0;u=p*pow(t,eF);}else{floatt=(1.0-u)/max(1.0-p,1e-6);u
=1.0-(1.0-)*pow(t,eN);}}//5)InvLogelseif(_UnitShape<5.5){u=InvLogExpand(u,_UnitInvK);}//6)InvLogwithhighlightshoulderelse{u=InvLogExpandHi(u,UnitInvK,UnitHiS);}//optionalblendbacktowardoriginalu=lerp(u,orig,saturate(_UnitMix));returnsaurate(u);}//unit->meters(assumingnear=whiteif_WhiteNear=1)floatUnitToMeters(floatu){floaty=(_WhiteNear>0.5)?u:(1.0-u);//enforcenear=whiteif(_MapType<0.5){floatnearZ=
_NearFar.x,farZ=_NearFar.y;returnnearZ+(1.0-y)*(farZ-nearZ);}else{floatmu=_MuXMax.x,xmax=_MuXMax.y;floatval=exp(y*log(1.0+mu))-1.0;return(val/mu)*xmax;}}//masksampling(withoptionalerosion+feather)float2TileTexelStep(){returnfloat2(1.0/(_ImageSize.x*2.0),1.0/(_ImageSize.y*2.0));}floatSampleMaskRawAt(float2uvMask,float2uvColor){if(_MaskFromColor>0.5){float3rgb=tex2Dlod(_AtlasTex,float4(uvColor,0,0))
.rgb;returndot(rgb,float3(0.2126,0.7152,0.0722));}else{returntex2Dlod(_AtlasTex,float4(uvMask,0,0)).r;}}floatErodeMask(float2uvMask,float2uvColor,float2step){//radiusinwholepixelsfloatrpx=max(0.0,_MaskErodePx);if(rpx<0.5)returnSampleMaskRawAt(uvMask,uvColor);float2d=round(rpx)*step;//8-eighborhoodmin(cheapmorphologicalerosion)floatmC=SampleMaskRawAt(uvMask,uvColor);floatm=mC;m=min(m,SampleMaskRawA
t(uvMask+float2(d.x,0),uvColor+float2(d.x,0)));m=min(m,SampleMaskRawAt(uvask+float2(-d.x,0),uvColor+float2(-d.x,0)));m=min(m,SampleMaskRawAt(uvMask+float2(0,d.y),uvColor+float2(0,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(0,-d.y),uvColor+float2(0,-.y)));m=min(m,SampleMaskRawAt(uvMask+float2(d.x,d.y),uvColor+float2(d.x,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(d.x,-.y),uvColor+float2(d.x,-d.y)
));m=min(m,SampleMaskRawAt(uvMask+float2(-d.x,d.y),uvColor+float2(-d.x,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(-.x,-d.y),uvColor+float2(-d.x,-d.y)));returnm;}floatSampleMaskFeathered(float2uvMask,float2uvColor){float2step=TileTexelStep();floatm=ErodeMask(uvMask,uvColor,step);if(m<=_MaskZeroEps)m=0.0;//Featherinpx→converttoatinyscalarwindowvia1/NwhereN~pixelsacrosstheatlasheight.//Thisisaheuri
sticjusttosoftendiscard:floateps=max(_MaskFeathr,0.0)/(_ImageSize.y*0.5+1e-6);returnsmoothstep(_MaskThresh-eps,_MaskThresh+eps,m);}v2fvert(appdatav){v2fo;//uv01formath(FlipVhere;TileUValsoflipsforsampling)o.uv01=v.uv;if(_FlipV>0.5)o.uv01.y=1.0-o.uv01.y;//ComputeatlasUVsforeachtileONCEo.uvColor=TileUV(v.uv,_TileColor.xy);o.uvMask=TileUV(v.uv,_TileMask.xy);o.uvDepth=TileUV(v.uv,TileDepth.xy);//----D
epthfetch&shaping(VERTEX)----floatuRaw=(_DepthMode<0.5)?ReadUnit_Single(o.uvDepth):ReadUnit_Split(TileUV(v.uv,_TileDepthHI.xy),TileUV(v.uv,_TileDepthLO.xy));floatuDef=DefloorUnit(uRaw);floatuShaped=ShapeExpand(uDef);floatZm=UnitToMeters(uShaped);//sign/orientation&minimumZfloatcamZ=(ProjectForward>0.5)?+Zm:-Zm;floatzAbs=max(abs(camZ),_MinZ);floatzSign=(camZ>=0)?1.0:-1.0;camZ=zSign*zAbs;//pixelcent
ers(HalfPixel=0.5)float2wh=_ImageSize.xy;floatpx=o.uv01.x*wh.x-_HalfPixel;floatpy=o.uv01.y*wh.y-_HalfPixel;//intrinsicsfloatfx=_FxFyCxCy.x,fy=_FxFyCxCy.y,cx=_FxFyCCy.z,cy=_FxFyCxCy.w;//Foreshortening(XYonlyunless_AffectZ)floatzForXY=lerp(zAbs,_ZRef,saturate(_OrthoBlend));floatX=(px-cx)*((zSign*zForXY)/fx);floatY=(py-cy)*((zSign*zForXY)/fy);if(_FlipX>0.5)X=-X;floatoutZ=(_AffectZ>0.5)?(zSign*zForXY)
:camZ;float4objPos=float4(X,-Y,outZ+_ZOffset,1.0);o.pos=UnityObjectToClipPos(objPos);returno;}fixed4frag(v2fi):SV_Target{//1)Mask(witherosion+feather)&colorfloatmSoft=SampleMaskFeathered(i.uvMask,i.uvColor);if(mSoft<=0.0)discard;fixed4col=tex2D(_AtlasTex,i.uvColor);if(_UseTLAlpha>0.5&&col.a<_MaskThresh)discard;//2)Strongdepth-edgecutusingDEPTHUV(8-eighbors@radiusCutPx)if(_CutEnable>0.5){float2step
=TileTexelStep();floatrpx=max(_CutPx,0.0);float2offs=round(max(rpx,1.0))*step;//center+neighborsfloatuC=ReadUnit_Single(i.uvDepth);flotzC=UnitToMeters(ShapeExpand(DefloorUnit(uC)));floatuR=ReadUnit_Single(i.uvDepth+float2(offs.x,0));floatuL=ReadUnit_Single(i.uvDepth+float2(-ffs.x,0));floatuU=ReadUnit_Single(i.uvDepth+float2(0,offs.y));floatuD=ReadUnit_Single(i.uvDepth+float2(0,-offs.y));floatuRU=R
eadUnit_Single(i.uvDepth+float2(offs.x,offs.y));floatuRD=ReadUnit_Single(i.uvDepth+float2(offs.x,-offs.y));floatuLU=ReadUnit_Single(i.uvDepth+float2(-offs.x,offs.y));floatuLD=ReadUnit_Single(i.uvDepth+float2(-offs.x,-offs.y));floatzR=UnitToMeters(ShapeExpand(DefloorUnit(uR)));floatzL=UnitToMeters(ShapeExpand(DefloorUnit(uL)));floatzU=UnitToMeters(ShapeExpand(DfloorUnit(uU)));floatzD=UnitToMeters(S
hapeExpand(DefloorUnit(uD)));floatzRU=UnitToMeters(ShapeExpand(DefloorUnit(uRU)));floatzRD=UnitToMeters(ShaeExpand(DefloorUnit(uRD)));floatzLU=UnitToMeters(ShapeExpand(DefloorUnit(uLU)));floatzLD=UnitToMeters(ShapeExpand(DefloorUnit(uLD)));floatdz=0.0;dz=max(dz,abs(zC-zR));dz=max(dz,abs(zC-zL));dz=max(dz,abs(zC-zU));dz=max(dz,abs(zC-zD));dz=max(dz,abs(zC-zRU));dz=max(dz,abs(zC-zRD));dz=max(dz,abs(
zC-zLU));dz=max(dz,abs(zC-zLD));//absolute+relativethresholdfloatth=_CutDZ+_CutRel*max(zC,1e-6);if(dz>th){if(_CutFeather<=.0)iscard;//softfeatherbasedonexcessoverthresholdfloatw=saturate((dz-th)/(th*0.5+1e-6));if(w>0.0)discard;}}//Output:keepsoftmaskasalpha(helpsatedges)col.a=mSoft;returncol;}ENDCG}}FallBackOff}Shader"Unlit/DepthProjector_Atlas"{Properties{_AtlasTex("Atlas(RGBA)",2D)="black"{}//In
trinsics/image_ImageSize("ImageSize(W,H)",Vector)=(1280,100,0,0)_FxFyCxCy("fx,fy,cx,cy",Vector)=(800,800,640,540)_HalfPixel("Pixel-centeroffset(0or0.5)",Float)=0.5//Depthdecode(near=white)_DepthMode("DepthMode(0=Single,1=SplitHI/LO)",Float)=0_MapType("Map(0=Linear,1=MuLaw)",Float)=0_NearFar("Linearnear,far(m)",Vector)=(0.5,2.5,0,0)_MuXMax("MuLawmu,xmax",Vector)=(50.0,2048.0,0,0)_WhiteNear("WhiteNe
ar(0/1)",Float)=1//Defloor(undoatlas10-bitfloorbeforeshaping)_DepthFloorCodes("Depthfloor(10-bitcodes)",Float)=0//e.g.120//Unitshaping(EXPANDSdynamicrange)//0None,1=GammaExpand,2=LogExpand,3=ReinhardExpand,4=PivotPowExpand,5=InvLog,6=InvLog+Shoulder_UnitShape("UnitShaping(0=None,1=Gamma,2=Log,3=Reinhard,4=PivotPow,5=InvLog,6=InvLogHi)",Float)=0_UnitGamma("Gamma(>1expands)",Float)=2.0_UnitLogA("Log
A(>0)",Float)=4.0_UnitReinhardA("ReinhardA(>0)",Float)=1.0_UnitPivot("Pivot(0..1)",Float)=.75_UnitGammaNear("PivotPowGammaNear(>1expand)",Float)=1.6_UnitGammaFar("PivotPowGammaFar(>1expand)",Float)=1.6_UnitInvK("InvLogk(1..30)",Float)=20.0_UnitHiS("InvLogShoulders(0.5..1)",Float)=0.8_UnitMix("Mixwithoriginal(0..1)",Float)=0.0//Atlastiles(x,yin{0,1})top:COLOR|DEPTH,bottom:MATTE|EMPTY_TileColor("Til
eCOLOR(x,y)",Vector)=(0,1,0,0)//TL_TileDepth("TileDEPTH(single)",Vector)=(1,1,0,0)//TR_TileMask(TileMATTE(x,y)",Vector)=(0,0,0,0)//BL_TileDepthHI("TileDEPTHHI(x,y)",Vector)=(1,1,0,0)//if_DepthMode=1_TileDepthLO("TileDEPTHLO(x,y)",Vector)=(1,0,0,0)//ifsplit//Masking/orientation_MaskThresh("MaskThreshold",Range(0,1))=0.0_MaskFromColor("UseCOLORluminanceasmask(0/1)",Float)=0_MaskZeroEps("Treat<=thisa
szero",Float)=0.02_UseTLAlpha("UseCOLORAlpha(0/1)",Float)=0_FlipV("FlipV(0/1)",Float)=0_ProjectForward("Projectalong+Z(0=no,1=yes)",Float)=0_FlipX("FlipXgeometry(0/1)",Float)=1_ZOffset("ZOffset(meters)",Float)=0//---Re-introduced:robustmask/edgehelpers---_MaskFeather("MaskFeather(px)",Float)=0.75_MaskErodePx("MaskErode(px)",Float)=0.0//Depth-edgecut(disconnectfrombackplane)_CutEnable("Cutbydepthju
mp(0/1)",Float)=1_CutDZ("Depthjumpthreshold(m)",Float)=0.08_CutFeather("Cutfeather(px)",Float)=1.0_CutPx("Cutsampleradius(px)",Float)=1.0_CutRel("Cutrelativedzfactor",Float)=0.15//Foreshortening:blendXYtowardZRef;optionalZflatten_OrthoBlend("OrthoBlend(0..1)",Range(0,1))=0.0_ZRef("ReferenceZ(m)",Float)=2.0_MinZ("MinZClamp(m)",Float)=0.3_AffectZ("ApplyZRemap(0/1)",Float)=0}SubShader{Tags{"RenderTyp
e"="Opaque""Queue"="Geometry"}CullOffZWriteOnZTestLEqualLightingOffBlendOneZeroPass{CGPROGRAM#pragmavertexvert#pragmafragmentfrag#pragmatarget3.0#include"UnityCG.cginc"sampler2D_AtlasTex;float4_ImageSize,_FxFyCxCy;float_DepthMode,_MapType,_WhiteNear,_HalfPixel;float4_NearFar,_MuXMax;//defloorfloat_DepthFloorCodes;//shapingfloat_UnitShape,_UnitGamma,_UnitLogA,_UnitReinhardA;float_UnitPivot,_UnitGam
maNear,_UnitGammaFar,UnitInvK,_UnitHiS,_UnitMix;float4_TileColor,_TileMask,_TileDepth,_TileDepthHI,_TileDepthLO;float_MaskThresh,_MaskFromColor,MaskZeroEps,_UseTLAlpha;float_FlipV,_ProjectForward,_FlipX,_ZOffset;//reintroducedhelpersfloat_MaskFeather,_MaskErodePx;float_CutEnable,_CutDZ,_CutFeather,_CutPx,_CutRel;float_OrthoBlend,_ZRef,_MinZ,_AffectZ;structappdata{float4vertex:POSITION;float2uv:TEX
COORD0;};structv2f{float4pos:SV_POSITION;float2uvColor:TEXCOORD0;float2uvMask:TEXCOORD1;float2uvDepth:TEXCOORD2;//depthtileUVinatlasspacefloat2uv01:TEXCOORD3;//0..1withFlipVapplied(formath)};//---UVhelpers---float2TileUV(float2uv01in,float2tileXY){float2uv=uv01_in;if(_FlipV>0.5)uv.y=1.0-uv.y;constfloat2tileSize=float2(0.5,0.5);float2origin=tileXY.xy*tileSize;returnorigin+uv*tileSize;}//---reads---
floatReadByte(float2uv)floatv=tex2Dlod(_AtlasTex,float4(uv,0,0)).r;returnfloor(v*255.0+0.5);}floatReadUnit_Single(float2uvD)returnsaturate(tex2Dlod(_AtlasTex,float4(uvD,0,0)).r);}floatReadUnit_Split(float2uvHI,float2uvLO)floathi=ReadByte(uvHI),lo=ReadByte(uvLO);return(hi*256.0+lo)/65535.0;}//Defloor(undo10-bitfloor)floatDefloorUnit(floatu){floatf=saturate(_DepthFloorCodes/1023.0);//e.g.120/1023flo
atdenom=max(1.0-f,1e-6);returnsaturate((u-f)/denom);}//Inverse-logstyleexpansionfloatInvLogExpand(floatu,floatk){k=max(k,1e-6);floatdenom=1.0-exp(-k);returnsaturate((1.0-exp(-k*saturate(u)))/denom);}//Inverse-logwithgentlehighlightshoulder(weightslargervaluesabitmore)floatInvLogExpandHi(floatu,floatk,floats){k=max(k,1e-6);s=clamp(s,1e-3,1.0);floatdenom=1.0-exp(-k);floatg=(1.0-exp(-k*saturate(u)))/
denom;//baseinverse-logreturnsaturate(1.0-pow(1.0-,s));}//EXPANSIONcurvesfloatShapeExpand(floatu){u=saturate(u);if(_UnitShape<0.5)returnu;floatorig=u;//1)GammaExpandif(_UnitShape<1.5){floatg=max(_UnitGamma,1e-6);u=pow(u,1.0/g);}//2)LogExpand(inverseoflogcompress)elseif(_UnitShape<2.5){floata=max(_UnitLogA,1e-6);u=(pow(1.0a,u)-1.0)/a;}//3)ReinhardExpand:inverseofu/(1+Au)elseif(_UnitShape<3.5){float
A=max(_UnitReinhardA,1e-6);floatdenom=max(1.0-A*u,1e-6);u=u/denom;}//4)PivotPowExpand(useexponents<1toexpand)elseif(_UnitShape<4.5){floatp=saturate(_UnitPivot);floatgN=max(_UnitGammaNear,1e-6);floatgF=max(_UnitGammaFar,1e-6);floateN=(gN>=1.0)?(1.0/gN):gN;floateF=(gF>=.0)?(1.0/gF):gF;if(u<=p){floatt=(p>1e-6)?(u/p):0.0;u=p*pow(t,eF);}else{floatt=(1.0-u)/max(1.0-p,1e-6);u=1.0-(1.0-)*pow(t,eN);}}//5)I
nvLogelseif(_UnitShape<5.5){u=InvLogExpand(u,_UnitInvK);}//6)InvLogwithhighlightshoulderelse{u=InvLogExpandHi(u,UnitInvK,UnitHiS);}//optionalblendbacktowardoriginalu=lerp(u,orig,saturate(_UnitMix));returnsaurate(u);}//unit->meters(assumingnear=whiteif_WhiteNear=1)floatUnitToMeters(floatu){floaty=(_WhiteNear>0.5)?u:(1.0-u);//enforcenear=whiteif(_MapType<0.5){floatnearZ=_NearFar.x,farZ=_NearFar.y;re
turnnearZ+(1.0-y)*(farZ-nearZ);}else{floatmu=_MuXMax.x,xmax=_MuXMax.y;floatval=exp(y*log(1.0+mu))-1.0;return(val/mu)*xmax;}}//masksampling(withoptionalerosion+feather)float2TileTexelStep(){returnfloat2(1.0/(_ImageSize.x*2.0),1.0/(_ImageSize.y*2.0));}floatSampleMaskRawAt(float2uvMask,float2uvColor){if(_MaskFromColor>0.5){float3rgb=tex2Dlod(_AtlasTex,float4(uvColor,0,0)).rgb;returndot(rgb,float3(0.2
126,0.7152,0.0722));}else{returntex2Dlod(_AtlasTex,float4(uvMask,0,0)).r;}}floatErodeMask(float2uvMask,float2uvColor,float2step){//radiusinwholepixelsfloatrpx=max(0.0,_MaskErodePx);if(rpx<0.5)returnSampleMaskRawAt(uvMask,uvColor);float2d=round(rpx)*step;//8-eighborhoodmin(cheapmorphologicalerosion)floatmC=SampleMaskRawAt(uvMask,uvColor);floatm=mC;m=min(m,SampleMaskRawAt(uvMask+float2(d.x,0),uvColo
r+float2(d.x,0)));m=min(m,SampleMaskRawAt(uvask+float2(-d.x,0),uvColor+float2(-d.x,0)));m=min(m,SampleMaskRawAt(uvMask+float2(0,d.y),uvColor+float2(0,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(0,-d.y),uvColor+float2(0,-.y)));m=min(m,SampleMaskRawAt(uvMask+float2(d.x,d.y),uvColor+float2(d.x,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(d.x,-.y),uvColor+float2(d.x,-d.y)));m=min(m,SampleMaskRawAt(uv
Mask+float2(-d.x,d.y),uvColor+float2(-d.x,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(-.x,-d.y),uvColor+float2(-d.x,-d.y)));returnm;}floatSampleMaskFeathered(float2uvMask,float2uvColor){float2step=TileTexelStep();floatm=ErodeMask(uvMask,uvColor,step);if(m<=_MaskZeroEps)m=0.0;//Featherinpx→converttoatinyscalarwindowvia1/NwhereN~pixelsacrosstheatlasheight.//Thisisaheuristicjusttosoftendiscard:float
eps=max(_MaskFeathr,0.0)/(_ImageSize.y*0.5+1e-6);returnsmoothstep(_MaskThresh-eps,_MaskThresh+eps,m);}v2fvert(appdatav){v2fo;//uv01formath(FlipVhere;TileUValsoflipsforsampling)o.uv01=v.uv;if(_FlipV>0.5)o.uv01.y=1.0-o.uv01.y;//ComputeatlasUVsforeachtileONCEo.uvColor=TileUV(v.uv,_TileColor.xy);o.uvMask=TileUV(v.uv,_TileMask.xy);o.uvDepth=TileUV(v.uv,TileDepth.xy);//----Depthfetch&shaping(VERTEX)----
floatuRaw=(_DepthMode<0.5)?ReadUnit_Single(o.uvDepth):ReadUnit_Split(TileUV(v.uv,_TileDepthHI.xy),TileUV(v.uv,_TileDepthLO.xy));floatuDef=DefloorUnit(uRaw);floatuShaped=ShapeExpand(uDef);floatZm=UnitToMeters(uShaped);//sign/orientation&minimumZfloatcamZ=(ProjectForward>0.5)?+Zm:-Zm;floatzAbs=max(abs(camZ),_MinZ);floatzSign=(camZ>=0)?1.0:-1.0;camZ=zSign*zAbs;//pixelcenters(HalfPixel=0.5)float2wh=_I
mageSize.xy;floatpx=o.uv01.x*wh.x-_HalfPixel;floatpy=o.uv01.y*wh.y-_HalfPixel;//intrinsicsfloatfx=_FxFyCxCy.x,fy=_FxFyCxCy.y,cx=_FxFyCCy.z,cy=_FxFyCxCy.w;//Foreshortening(XYonlyunless_AffectZ)floatzForXY=lerp(zAbs,_ZRef,saturate(_OrthoBlend));floatX=(px-cx)*((zSign*zForXY)/fx);floatY=(py-cy)*((zSign*zForXY)/fy);if(_FlipX>0.5)X=-X;floatoutZ=(_AffectZ>0.5)?(zSign*zForXY):camZ;float4objPos=float4(X,-
Y,outZ+_ZOffset,1.0);o.pos=UnityObjectToClipPos(objPos);returno;}fixed4frag(v2fi):SV_Target{//1)Mask(witherosion+feather)&colorfloatmSoft=SampleMaskFeathered(i.uvMask,i.uvColor);if(mSoft<=0.0)discard;fixed4col=tex2D(_AtlasTex,i.uvColor);if(_UseTLAlpha>0.5&&col.a<_MaskThresh)discard;//2)Strongdepth-edgecutusingDEPTHUV(8-eighbors@radiusCutPx)if(_CutEnable>0.5){float2step=TileTexelStep();floatrpx=max
(_CutPx,0.0);float2offs=round(max(rpx,1.0))*step;//center+neighborsfloatuC=ReadUnit_Single(i.uvDepth);flotzC=UnitToMeters(ShapeExpand(DefloorUnit(uC)));floatuR=ReadUnit_Single(i.uvDepth+float2(offs.x,0));floatuL=ReadUnit_Single(i.uvDepth+float2(-ffs.x,0));floatuU=ReadUnit_Single(i.uvDepth+float2(0,offs.y));floatuD=ReadUnit_Single(i.uvDepth+float2(0,-offs.y));floatuRU=ReadUnit_Single(i.uvDepth+floa
t2(offs.x,offs.y));floatuRD=ReadUnit_Single(i.uvDepth+float2(offs.x,-offs.y));floatuLU=ReadUnit_Single(i.uvDepth+float2(-offs.x,offs.y));floatuLD=ReadUnit_Single(i.uvDepth+float2(-offs.x,-offs.y));floatzR=UnitToMeters(ShapeExpand(DefloorUnit(uR)));floatzL=UnitToMeters(ShapeExpand(DefloorUnit(uL)));floatzU=UnitToMeters(ShapeExpand(DfloorUnit(uU)));floatzD=UnitToMeters(ShapeExpand(DefloorUnit(uD)));
floatzRU=UnitToMeters(ShapeExpand(DefloorUnit(uRU)));floatzRD=UnitToMeters(ShaeExpand(DefloorUnit(uRD)));floatzLU=UnitToMeters(ShapeExpand(DefloorUnit(uLU)));floatzLD=UnitToMeters(ShapeExpand(DefloorUnit(uLD)));floatdz=0.0;dz=max(dz,abs(zC-zR));dz=max(dz,abs(zC-zL));dz=max(dz,abs(zC-zU));dz=max(dz,abs(zC-zD));dz=max(dz,abs(zC-zRU));dz=max(dz,abs(zC-zRD));dz=max(dz,abs(zC-zLU));dz=max(dz,abs(zC-zLD
));//absolute+relativethresholdfloatth=_CutDZ+_CutRel*max(zC,1e-6);if(dz>th){if(_CutFeather<=.0)iscard;//softfeatherbasedonexcessoverthresholdfloatw=saturate((dz-th)/(th*0.5+1e-6));if(w>0.0)discard;}}//Output:keepsoftmaskasalpha(helpsatedges)col.a=mSoft;returncol;}ENDCG}}FallBackOff}Shader"Unlit/DepthProjector_Atlas"{Properties{_AtlasTex("Atlas(RGBA)",2D)="black"{}//Intrinsics/image_ImageSize("Ima
geSize(W,H)",Vector)=(1280,100,0,0)_FxFyCxCy("fx,fy,cx,cy",Vector)=(800,800,640,540)_HalfPixel("Pixel-centeroffset(0or0.5)",Float)=0.5//Depthdecode(near=white)_DepthMode("DepthMode(0=Single,1=SplitHI/LO)",Float)=0_MapType("Map(0=Linear,1=MuLaw)",Float)=0_NearFar("Linearnear,far(m)",Vector)=(0.5,2.5,0,0)_MuXMax("MuLawmu,xmax",Vector)=(50.0,2048.0,0,0)_WhiteNear("WhiteNear(0/1)",Float)=1//Defloor(un
doatlas10-bitfloorbeforeshaping)_DepthFloorCodes("Depthfloor(10-bitcodes)",Float)=0//e.g.120//Unitshaping(EXPANDSdynamicrange)//0None,1=GammaExpand,2=LogExpand,3=ReinhardExpand,4=PivotPowExpand,5=InvLog,6=InvLog+Shoulder_UnitShape("UnitShaping(0=None,1=Gamma,2=Log,3=Reinhard,4=PivotPow,5=InvLog,6=InvLogHi)",Float)=0_UnitGamma("Gamma(>1expands)",Float)=2.0_UnitLogA("LogA(>0)",Float)=4.0_UnitReinhar
dA("ReinhardA(>0)",Float)=1.0_UnitPivot("Pivot(0..1)",Float)=.75_UnitGammaNear("PivotPowGammaNear(>1expand)",Float)=1.6_UnitGammaFar("PivotPowGammaFar(>1expand)",Float)=1.6_UnitInvK("InvLogk(1..30)",Float)=20.0_UnitHiS("InvLogShoulders(0.5..1)",Float)=0.8_UnitMix("Mixwithoriginal(0..1)",Float)=0.0//Atlastiles(x,yin{0,1})top:COLOR|DEPTH,bottom:MATTE|EMPTY_TileColor("TileCOLOR(x,y)",Vector)=(0,1,0,0
)//TL_TileDepth("TileDEPTH(single)",Vector)=(1,1,0,0)//TR_TileMask(TileMATTE(x,y)",Vector)=(0,0,0,0)//BL_TileDepthHI("TileDEPTHHI(x,y)",Vector)=(1,1,0,0)//if_DepthMode=1_TileDepthLO("TileDEPTHLO(x,y)",Vector)=(1,0,0,0)//ifsplit//Masking/orientation_MaskThresh("MaskThreshold",Range(0,1))=0.0_MaskFromColor("UseCOLORluminanceasmask(0/1)",Float)=0_MaskZeroEps("Treat<=thisaszero",Float)=0.02_UseTLAlpha
("UseCOLORAlpha(0/1)",Float)=0_FlipV("FlipV(0/1)",Float)=0_ProjectForward("Projectalong+Z(0=no,1=yes)",Float)=0_FlipX("FlipXgeometry(0/1)",Float)=1_ZOffset("ZOffset(meters)",Float)=0//---Re-introduced:robustmask/edgehelpers---_MaskFeather("MaskFeather(px)",Float)=0.75_MaskErodePx("MaskErode(px)",Float)=0.0//Depth-edgecut(disconnectfrombackplane)_CutEnable("Cutbydepthjump(0/1)",Float)=1_CutDZ("Dept
hjumpthreshold(m)",Float)=0.08_CutFeather("Cutfeather(px)",Float)=1.0_CutPx("Cutsampleradius(px)",Float)=1.0_CutRel("Cutrelativedzfactor",Float)=0.15//Foreshortening:blendXYtowardZRef;optionalZflatten_OrthoBlend("OrthoBlend(0..1)",Range(0,1))=0.0_ZRef("ReferenceZ(m)",Float)=2.0_MinZ("MinZClamp(m)",Float)=0.3_AffectZ("ApplyZRemap(0/1)",Float)=0}SubShader{Tags{"RenderType"="Opaque""Queue"="Geometry"
}CullOffZWriteOnZTestLEqualLightingOffBlendOneZeroPass{CGPROGRAM#pragmavertexvert#pragmafragmentfrag#pragmatarget3.0#include"UnityCG.cginc"sampler2D_AtlasTex;float4_ImageSize,_FxFyCxCy;float_DepthMode,_MapType,_WhiteNear,_HalfPixel;float4_NearFar,_MuXMax;//defloorfloat_DepthFloorCodes;//shapingfloat_UnitShape,_UnitGamma,_UnitLogA,_UnitReinhardA;float_UnitPivot,_UnitGammaNear,_UnitGammaFar,UnitInvK
,_UnitHiS,_UnitMix;float4_TileColor,_TileMask,_TileDepth,_TileDepthHI,_TileDepthLO;float_MaskThresh,_MaskFromColor,MaskZeroEps,_UseTLAlpha;float_FlipV,_ProjectForward,_FlipX,_ZOffset;//reintroducedhelpersfloat_MaskFeather,_MaskErodePx;float_CutEnable,_CutDZ,_CutFeather,_CutPx,_CutRel;float_OrthoBlend,_ZRef,_MinZ,_AffectZ;structappdata{float4vertex:POSITION;float2uv:TEXCOORD0;};structv2f{float4pos:
SV_POSITION;float2uvColor:TEXCOORD0;float2uvMask:TEXCOORD1;float2uvDepth:TEXCOORD2;//depthtileUVinatlasspacefloat2uv01:TEXCOORD3;//0..1withFlipVapplied(formath)};//---UVhelpers---float2TileUV(float2uv01in,float2tileXY){float2uv=uv01_in;if(_FlipV>0.5)uv.y=1.0-uv.y;constfloat2tileSize=float2(0.5,0.5);float2origin=tileXY.xy*tileSize;returnorigin+uv*tileSize;}//---reads---floatReadByte(float2uv)floatv
=tex2Dlod(_AtlasTex,float4(uv,0,0)).r;returnfloor(v*255.0+0.5);}floatReadUnit_Single(float2uvD)returnsaturate(tex2Dlod(_AtlasTex,float4(uvD,0,0)).r);}floatReadUnit_Split(float2uvHI,float2uvLO)floathi=ReadByte(uvHI),lo=ReadByte(uvLO);return(hi*256.0+lo)/65535.0;}//Defloor(undo10-bitfloor)floatDefloorUnit(floatu){floatf=saturate(_DepthFloorCodes/1023.0);//e.g.120/1023floatdenom=max(1.0-f,1e-6);retur
nsaturate((u-f)/denom);}//Inverse-logstyleexpansionfloatInvLogExpand(floatu,floatk){k=max(k,1e-6);floatdenom=1.0-exp(-k);returnsaturate((1.0-exp(-k*saturate(u)))/denom);}//Inverse-logwithgentlehighlightshoulder(weightslargervaluesabitmore)floatInvLogExpandHi(floatu,floatk,floats){k=max(k,1e-6);s=clamp(s,1e-3,1.0);floatdenom=1.0-exp(-k);floatg=(1.0-exp(-k*saturate(u)))/denom;//baseinverse-logreturn
saturate(1.0-pow(1.0-,s));}//EXPANSIONcurvesfloatShapeExpand(floatu){u=saturate(u);if(_UnitShape<0.5)returnu;floatorig=u;//1)GammaExpandif(_UnitShape<1.5){floatg=max(_UnitGamma,1e-6);u=pow(u,1.0/g);}//2)LogExpand(inverseoflogcompress)elseif(_UnitShape<2.5){floata=max(_UnitLogA,1e-6);u=(pow(1.0a,u)-1.0)/a;}//3)ReinhardExpand:inverseofu/(1+Au)elseif(_UnitShape<3.5){floatA=max(_UnitReinhardA,1e-6);fl
oatdenom=max(1.0-A*u,1e-6);u=u/denom;}//4)PivotPowExpand(useexponents<1toexpand)elseif(_UnitShape<4.5){floatp=saturate(_UnitPivot);floatgN=max(_UnitGammaNear,1e-6);floatgF=max(_UnitGammaFar,1e-6);floateN=(gN>=1.0)?(1.0/gN):gN;floateF=(gF>=.0)?(1.0/gF):gF;if(u<=p){floatt=(p>1e-6)?(u/p):0.0;u=p*pow(t,eF);}else{floatt=(1.0-u)/max(1.0-p,1e-6);u=1.0-(1.0-)*pow(t,eN);}}//5)InvLogelseif(_UnitShape<5.5){u
=InvLogExpand(u,_UnitInvK);}//6)InvLogwithhighlightshoulderelse{u=InvLogExpandHi(u,UnitInvK,UnitHiS);}//optionalblendbacktowardoriginalu=lerp(u,orig,saturate(_UnitMix));returnsaurate(u);}//unit->meters(assumingnear=whiteif_WhiteNear=1)floatUnitToMeters(floatu){floaty=(_WhiteNear>0.5)?u:(1.0-u);//enforcenear=whiteif(_MapType<0.5){floatnearZ=_NearFar.x,farZ=_NearFar.y;returnnearZ+(1.0-y)*(farZ-nearZ
);}else{floatmu=_MuXMax.x,xmax=_MuXMax.y;floatval=exp(y*log(1.0+mu))-1.0;return(val/mu)*xmax;}}//masksampling(withoptionalerosion+feather)float2TileTexelStep(){returnfloat2(1.0/(_ImageSize.x*2.0),1.0/(_ImageSize.y*2.0));}floatSampleMaskRawAt(float2uvMask,float2uvColor){if(_MaskFromColor>0.5){float3rgb=tex2Dlod(_AtlasTex,float4(uvColor,0,0)).rgb;returndot(rgb,float3(0.2126,0.7152,0.0722));}else{ret
urntex2Dlod(_AtlasTex,float4(uvMask,0,0)).r;}}floatErodeMask(float2uvMask,float2uvColor,float2step){//radiusinwholepixelsfloatrpx=max(0.0,_MaskErodePx);if(rpx<0.5)returnSampleMaskRawAt(uvMask,uvColor);float2d=round(rpx)*step;//8-eighborhoodmin(cheapmorphologicalerosion)floatmC=SampleMaskRawAt(uvMask,uvColor);floatm=mC;m=min(m,SampleMaskRawAt(uvMask+float2(d.x,0),uvColor+float2(d.x,0)));m=min(m,Sam
pleMaskRawAt(uvask+float2(-d.x,0),uvColor+float2(-d.x,0)));m=min(m,SampleMaskRawAt(uvMask+float2(0,d.y),uvColor+float2(0,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(0,-d.y),uvColor+float2(0,-.y)));m=min(m,SampleMaskRawAt(uvMask+float2(d.x,d.y),uvColor+float2(d.x,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(d.x,-.y),uvColor+float2(d.x,-d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(-d.x,d.y),uvColor
+float2(-d.x,d.y)));m=min(m,SampleMaskRawAt(uvMask+float2(-.x,-d.y),uvColor+float2(-d.x,-d.y)));returnm;}floatSampleMaskFeathered(float2uvMask,float2uvColor){float2step=TileTexelStep();floatm=ErodeMask(uvMask,uvColor,step);if(m<=_MaskZeroEps)m=0.0;//Featherinpx→converttoatinyscalarwindowvia1/NwhereN~pixelsacrosstheatlasheight.//Thisisaheuristicjusttosoftendiscard:floateps=max(_MaskFeathr,0.0)/(_Im
ageSize.y*0.5+1e-6);returnsmoothstep(_MaskThresh-eps,_MaskThresh+eps,m);}v2fvert(appdatav){v2fo;//uv01formath(FlipVhere;TileUValsoflipsforsampling)o.uv01=v.uv;if(_FlipV>0.5)o.uv01.y=1.0-o.uv01.y;//ComputeatlasUVsforeachtileONCEo.uvColor=TileUV(v.uv,_TileColor.xy);o.uvMask=TileUV(v.uv,_TileMask.xy);o.uvDepth=TileUV(v.uv,TileDepth.xy);//----Depthfetch&shaping(VERTEX)----floatuRaw=(_DepthMode<0.5)?Re
adUnit_Single(o.uvDepth):ReadUnit_Split(TileUV(v.uv,_TileDepthHI.xy),TileUV(v.uv,_TileDepthLO.xy));floatuDef=DefloorUnit(uRaw);floatuShaped=ShapeExpand(uDef);floatZm=UnitToMeters(uShaped);//sign/orientation&minimumZfloatcamZ=(ProjectForward>0.5)?+Zm:-Zm;floatzAbs=max(abs(camZ),_MinZ);floatzSign=(camZ>=0)?1.0:-1.0;camZ=zSign*zAbs;//pixelcenters(HalfPixel=0.5)float2wh=_ImageSize.xy;floatpx=o.uv01.x*
wh.x-_HalfPixel;floatpy=o.uv01.y*wh.y-_HalfPixel;//intrinsicsfloatfx=_FxFyCxCy.x,fy=_FxFyCxCy.y,cx=_FxFyCCy.z,cy=_FxFyCxCy.w;//Foreshortening(XYonlyunless_AffectZ)floatzForXY=lerp(zAbs,_ZRef,saturate(_OrthoBlend));floatX=(px-cx)*((zSign*zForXY)/fx);floatY=(py-cy)*((zSign*zForXY)/fy);if(_FlipX>0.5)X=-X;floatoutZ=(_AffectZ>0.5)?(zSign*zForXY):camZ;float4objPos=float4(X,-Y,outZ+_ZOffset,1.0);o.pos=Un
ityObjectToClipPos(objPos);returno;}fixed4frag(v2fi):SV_Target{//1)Mask(witherosion+feather)&colorfloatmSoft=SampleMaskFeathered(i.uvMask,i.uvColor);if(mSoft<=0.0)discard;fixed4col=tex2D(_AtlasTex,i.uvColor);if(_UseTLAlpha>0.5&&col.a<_MaskThresh)discard;//2)Strongdepth-edgecutusingDEPTHUV(8-eighbors@radiusCutPx)if(_CutEnable>0.5){float2step=TileTexelStep();floatrpx=max(_CutPx,0.0);float2offs=round
(max(rpx,1.0))*step;//center+neighborsfloatuC=ReadUnit_Single(i.uvDepth);flotzC=UnitToMeters(ShapeExpand(DefloorUnit(uC)));floatuR=ReadUnit_Single(i.uvDepth+float2(offs.x,0));floatuL=ReadUnit_Single(i.uvDepth+float2(-ffs.x,0));floatuU=ReadUnit_Single(i.uvDepth+float2(0,offs.y));floatuD=ReadUnit_Single(i.uvDepth+float2(0,-offs.y));floatuRU=ReadUnit_Single(i.uvDepth+float2(offs.x,offs.y));floatuRD=R
eadUnit_Single(i.uvDepth+float2(offs.x,-offs.y));floatuLU=ReadUnit_Single(i.uvDepth+float2(-offs.x,offs.y));floatuLD=ReadUnit_Single(i.uvDepth+float2(-offs.x,-offs.y));floatzR=UnitToMeters(ShapeExpand(DefloorUnit(uR)));floatzL=UnitToMeters(ShapeExpand(DefloorUnit(uL)));floatzU=UnitToMeters(ShapeExpand(DfloorUnit(uU)));floatzD=UnitToMeters(ShapeExpand(DefloorUnit(uD)));floatzRU=UnitToMeters(ShapeEx
pand(DefloorUnit(uRU)));floatzRD=UnitToMeters(ShaeExpand(DefloorUnit(uRD)));floatzLU=UnitToMeters(ShapeExpand(DefloorUnit(uLU)));floatzLD=UnitToMeters(ShapeExpand(DefloorUnit(uLD)));floatdz=0.0;dz=max(dz,abs(zC-zR));dz=max(dz,abs(zC-zL));dz=max(dz,abs(zC-zU));dz=max(dz,abs(zC-zD));dz=max(dz,abs(zC-zRU));dz=max(dz,abs(zC-zRD));dz=max(dz,abs(zC-zLU));dz=max(dz,abs(zC-zLD));//absolute+relativethresho
ldfloatth=_CutDZ+_CutRel*max(zC,1e-6);if(dz>th){if(_CutFeather<=.0)iscard;//softfeatherbasedonexcessoverthresholdfloatw=saturate((dz-th)/(th*0.5+1e-6));if(w>0.0)discard;}}//Output:keepsoftmaskasalpha(helpsatedges)col.a=mSoft;returncol;}ENDCG}}FallBackOff}Shader"Unlit/DepthProjector_Atlas"{Properties{_AtlasTex("Atlas(RGBA)",2D)="black"{}//Intrinsics/image_ImageSize("ImageSize(W,H)",Vector)=(1280,10
0,0,0)_FxFyCxCy("fx,fy,cx,cy",Vector)=(800,800,640,540)_HalfPixel("Pixel-centeroffset(0or0.5)",Float)=0.5//Depthdecode(near=white)_DepthMode("DepthMode(0=Single,1=SplitHI/LO)",Float)=0_MapType("Map(0=Linear,1=MuLaw)",Float)=0_NearFar("Linearnear,far(m)",Vector)=(0.5,2.5,0,0)_MuXMax("MuLawmu,xmax",Vector)=(50.0,2048.0,0,0)_WhiteNear("WhiteNear(0/1)",Float)=1//Defloor(undoatlas10-bitfloorbeforeshapi
ng)_DepthFloorCodes("Depthfloor(10-bitcodes)",Float)=0//e.g.120//Unitshaping(EXPANDSdynamicrange)//0None,1=GammaExpand,2=LogExpand,3=ReinhardExpand,4=PivotPowExpand,5=InvLog,6=InvLog+Shoulder_UnitShape("UnitShaping(0=None,1=Gamma,2=Log,3=Reinhard,4=PivotPow,5=InvLog,6=InvLogHi)",Float)=0_UnitGamma("Gamma(>1expands)",Float)=2.0_UnitLogA("LogA(>0)",Float)=4.0_UnitReinhardA("ReinhardA(>0)",Float)=1.0
_UnitPivot("Pivot(0..1)",Float)=.75_UnitGammaNear("PivotPowGammaNear(>1expand)",Float)=1.6_UnitGammaFar("PivotPowGammaFar(>1expand)",Float)=1.6_UnitInvK("InvLogk(1..30)",Float)=20.0_UnitHiS("InvLogShoulders(0.5..1)",Float)=0.8_UnitMix("Mixwithoriginal(0..1)",Float)=0.0//Atlastiles(x,yin{0,1})top:COLOR|DEPTH,bottom:MATTE|EMPTY_TileColor("TileCOLOR(x,y)",Vector)=(0,1,0,0)//TL_TileDepth("TileDEPTH(si
ngle)",Vector)=(1,1,0,0)//TR_TileMask(TileMATTE(x,y)",Vector)=(0,0,0,0)//BL_TileDepthHI("TileDEPTHHI(x,y)",Vector)=(1,1,0,0)//if_DepthMode=1_TileDepthLO("TileDEPTHLO(x,y)",Vector)=(1,0,0,0)//ifsplit//Masking/orientation_MaskThresh("MaskThreshold",Range(0,1))=0.0_MaskFromColor("UseCOLORluminanceasmask(0/1)",Float)=0_MaskZeroEps("Treat<=thisaszero",Float)=0.02_UseTLAlpha("UseCOLORAlpha(0/1)",Float)=
0_FlipV("FlipV(0/1)",Float)=0_ProjectForward("Projectalong+Z(0=no,1=yes)",Float)=0_FlipX("FlipXgeometry(0/1)",Float)=1_ZOffset("ZOffset(meters)",Float)=0//---Re-introduced:robustmask/edgehelpers---_MaskFeather("MaskFeather(px)",Float)=0.75_MaskErodePx("MaskErode(px)",Float)=0.0//Depth-edgecut(disconnectfrombackplane)_CutEnable("Cutbydepthjump(0/1)",Float)=1_CutDZ("Depthjumpthreshold(m)",Float)=0.0
8_CutFeather("Cutfeather(px)",Float)=1.0_CutPx("Cutsampleradius(px)",Float)=1.0_CutRel("Cutrelativedzfactor",Float)=0.15//Foreshortening:blendXYtowardZRef;optionalZflatten_OrthoBlend("OrthoBlend(0..1)",Range(0,1))=0.0_ZRef("ReferenceZ(m)",Float)=2.0_MinZ("MinZClamp(m)",Float)=0.3_AffectZ("ApplyZRemap(0/1)",Float)=0}SubShader{Tags{"RenderType"="Opaque""Queue"="Geometry"}CullOffZWriteOnZTestLEqualLi
ghtingOffBlendOneZeroPass{CGPROGRAM#pragmavertexvert#pragmafragmentfrag#pragmatarget3.0#include"UnityCG.cginc"sampler2D_AtlasTex;float4_ImageSize,_FxFyCxCy;float_DepthMode,_MapType,_WhiteNear,_HalfPixel;float4_NearFar,_MuXMax;//defloorfloat_DepthFloorCodes;//shapingfloat_UnitShape,_UnitGamma,_UnitLogA,_UnitReinhardA;float_UnitPivot,_UnitGammaNear,_UnitGammaFar,UnitInvK,_UnitHiS,_UnitMix;float4_Til
eColor,_TileMask,_TileDepth,_TileDepthHI,_TileDepthLO;float_MaskThresh,_MaskFromColor,MaskZeroEps,_UseTLAlpha;float_FlipV,_ProjectForward,_FlipX,_ZOffset;//reintroducedhelpersfloat_MaskFeather,_MaskErodePx;float_CutEnable,_CutDZ,_CutFeather,_CutPx,_CutRel;float_OrthoBlend,_ZRef,_MinZ,_AffectZ;structappdata{float4vertex:POSITION;float2uv:TEXCOORD0;};structv2f{float4pos:SV_POSITION;float2uvColor:TEX
COORD0;float2uvMask:TEXCOORD1;float2uvDepth:TEXCOORD2;//depthtileUVinatlasspacefloat2uv01:TEXCOORD3;//0..1withFlipVapplied(formath)};//---UVhelpers---float2TileUV(float2uv01in,float2tileXY){float2uv=uv01_in;if(_FlipV>0.5)uv.y=1.0-uv.y;constfloat2tileSize=float2(0.5,0.5);float2origin=tileXY.xy*tileSize;returnorigin+uv*tileSize;}//---reads---floatReadByte(float2uv)floatv=tex2Dlod(_AtlasTex,float4(uv
,0,0)).r;returnfloor(v*255.0+0.5);}floatReadUnit_Single(float2uvD)returnsaturate(tex2Dlod(_AtlasTex,float4(uvD,0,0)).r);}floatReadUnit_Split(float2uvHI,float2uvLO)floathi=ReadByte(uvHI),lo=ReadByte(uvLO);return(hi*256.0+lo)/65535.0;}//Defloor(undo10-bitfloor)floatDefloorUnit(floatu){floatf=saturate(_DepthFloorCodes/1023.0);//e.g.120/1023floatdenom=max(1.0-f,1e-6);returnsaturate((u-f)/denom);}//Inv
erse-logstyleexpansionfloatInvLogExpand(floatu,floatk){k=max(k,1e-6);floatdenom=1.0-exp(-k);returnsaturate((1.0-exp(-k*saturate(u)))/denom);}//Inverse-logwithgentlehighlightshoulder(weightslargervaluesabitmore)floatInvLogExpandHi(floatu,floatk,floats){k=max(k,1e-6);s=clamp(s,1e-3,1.0);floatdenom=1.0-exp(-k);floatg=(1.0-exp(-k*saturate(u)))/denom;//baseinverse-logreturnsaturate(1.0-pow(1.0-,s));}//