天天看點

後期材質(PostProcess Material)+ Custom Node 實作"描邊"和"馬賽克"效果【UE4】

參考自: 描邊 馬賽克

描邊效果

靜态:

後期材質(PostProcess Material)+ Custom Node 實作"描邊"和"馬賽克"效果【UE4】
動态:
後期材質(PostProcess Material)+ Custom Node 實作"描邊"和"馬賽克"效果【UE4】
馬賽克效果
後期材質(PostProcess Material)+ Custom Node 實作"描邊"和"馬賽克"效果【UE4】
動态
後期材質(PostProcess Material)+ Custom Node 實作"描邊"和"馬賽克"效果【UE4】
材質編輯器分别如下:
後期材質(PostProcess Material)+ Custom Node 實作"描邊"和"馬賽克"效果【UE4】
後期材質(PostProcess Material)+ Custom Node 實作"描邊"和"馬賽克"效果【UE4】
後期材質(PostProcess Material)+ Custom Node 實作"描邊"和"馬賽克"效果【UE4】
HLSL代碼分别如下:

//input SceneTexSize
//input UV
//input NotUse
//input OutLineSize
//input MaxZ
//input OutLineColor
float3 w=float3(0.2125,0.7154,0.0721);
float2 Sampler[]={float2(-1,-1),float2(-2,0),float2(-1,1),
                    float2(0,-2),float2(0,0),float2(0,2),
                    float2(1,-1),float2(2,0),float2(1,1)};
float2 UVOffset[]={float2(-1,-1),float2(0,-1),float2(1,-1),
                   float2(-1,0),float2(0,0),float2(1,0),
                   float2(-1,1),float2(0,1),float2(1,1),};
float2 Edge=0;
for(int i=0;i<9 ;i++)
{
    Edge+=Sampler[i]*dot(SceneTextureLookup(UV+UVOffset[i]*SceneTexSize*OutLineSize,14,false).xyz,w);
}
//最後的length可以改成1-abs(Edge.x)-abs(Edge.y),這樣可以減少運算量
return lerp(
SceneTextureLookup(UV,14,false),OutLineColor,length(Edge));      
//input BaseUV 螢幕UV
//intput Tiling
//input Ratio
//input NotUse
float2 UV=BaseUV;
 
UV*=Tiling;
UV.y*=Ratio;
UV=ceil(UV);
 
UV/=Tiling;
UV.y/=Ratio;
 
return SceneTextureLookup(UV,14,false);      

(完)

繼續閱讀