1.shadertoy 近大远小效果
//用面积算,因为绘制得依赖uv坐标,所以必须把屏幕考虑进去
float DistLine(vec3 ballPos,vec3 screen,vec3 camPos)
{
return length(cross(camPos - ballPos,screen)) / length(screen);
}
//用距离算
float CamDist(vec3 ballPos,vec3 camPos)
{
return length(camPos - ballPos);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord.xy / iResolution.xy;
uv -= 0.5;
//将uv的x坐标进行放大
uv.x *= iResolution.x / iResolution.y;
vec3 ballPos = vec3(0.0,0.0,-2.0);
vec3 screen = vec3(uv.x,uv.y,0.0) - ballPos;
float t = iTime;
//旋转摄像机
vec3 camPos = vec3(sin(t),0.0,1.0 + cos(t));
//近大远小
float d = DistLine(ballPos,screen,camPos) * 0.5;
d = smoothstep(0.10,0.09,d);
fragColor = vec4(d);
}
效果:
2.unity 旋转摄像机
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotCam : MonoBehaviour
{
private float angle = 15;
private Vector3 axis = new Vector3(0,1,0);
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//transform.RotateAround(Vector3.zero, axis, angle * Time.deltaTime);
float t = Time.time;
transform.position = new Vector3(Mathf.Sin(t) * 15,0,Mathf.Cos(t) * 15 - 35);
}
}