基本原理就是判断当前像素位置处于三角面里的位置 这个距离小于某个系数就画颜色,然后可以和另一个颜色插值
下面是核心代码
[maxvertexcount(3)]
void UCLAGL_geom(triangle
UCLAGL_v2g p
[3], inout TriangleStream
<UCLAGL_g2f
> triStream
)
{
float2 p0
= _ScreenParams
.xy
* p
[0].pos
.xy
/ p
[0].pos
.w
;
float2 p1
= _ScreenParams
.xy
* p
[1].pos
.xy
/ p
[1].pos
.w
;
float2 p2
= _ScreenParams
.xy
* p
[2].pos
.xy
/ p
[2].pos
.w
;
float2 v0
= p2
- p1
;
float2 v1
= p2
- p0
;
float2 v2
= p1
- p0
;
float area
= abs(v1
.x
*v2
.y
- v1
.y
* v2
.x
);
float dist0
= area
/ length(v0
);
float dist1
= area
/ length(v1
);
float dist2
= area
/ length(v2
);
UCLAGL_g2f pIn
;
pIn
.pos
= p
[0].pos
;
pIn
.uv
= p
[0].uv
;
pIn
.worldpos
=p
[0].worldPos
;
pIn
.dist
= float3(dist0
,0,0);
triStream
.Append(pIn
);
pIn
.pos
= p
[1].pos
;
pIn
.uv
= p
[1].uv
;
pIn
.worldpos
=p
[1].worldPos
;
pIn
.dist
= float3(0,dist1
,0);
triStream
.Append(pIn
);
pIn
.pos
= p
[2].pos
;
pIn
.uv
= p
[2].uv
;
pIn
.worldpos
=p
[2].worldPos
;
pIn
.dist
= float3(0,0,dist2
);
triStream
.Append(pIn
);
}
float4
UCLAGL_frag(UCLAGL_g2f input
) : COLOR
{
fixed high
=smoothstep(_WorldPos
.x
,_WorldPos
.y
,input
.worldpos
.y
);
fixed4 col
= tex2D(_MainTex
, input
.uv
)*_ColorTint
*0.8;
float val
= min( input
.dist
.x
, min( input
.dist
.y
, input
.dist
.z
));
val
= exp2( -1/_LineThickness
* val
* val
);
float4 targetColor
= _LineColor
* tex2D( _LineMainTex
, input
.uv
);
float4 final
=val
* targetColor
+(1-val
)*col
;
return final
*high
;
}
因为这是一个全息城市的效果 所以还通过顶点高度判断 做了一个渐变效果
转载请注明原文地址: https://lol.8miu.com/read-34093.html