【发布时间】:2016-09-13 23:30:55
【问题描述】:
我一直在尝试使用着色器创建 2D“假行星”类效果,但我得到的结果虽然有效,但效果并不好。
void vert(inout appdata_full v)
{
//Get vertex world coordinates
float4 worldV = mul(unity_ObjectToWorld, v.vertex);
//Get target coordinates relative to vertex world
worldV.xyz -= _TargetPos.xyz;
//Transform vertex based on x distance from target
worldV = float4(0.0f, (worldV.x * worldV.x) * -_Curvature, 0.0f, 0.0f);
//Add this offset to vertex
v.vertex += mul(unity_WorldToObject, worldV);
}
上面的代码是我用来产生这种效果的顶点函数,但由于它只根据玩家的 X 偏移 Y 上的顶点,它会在屏幕边缘附近产生失真。它只是看起来不太好,因为所有垂直线都保持完全垂直。
我想让它看起来更像一颗行星:
但我不知道该怎么做。
编辑:我已经尝试了几个小时来解决这个问题,我以为我已经解决了:
。
但是不,这不起作用。水平似乎在随机的地方弯曲和下降。
【问题讨论】:
标签: unity3d 2d shader vertex-shader