Unity Shader学习:简单RayMarching(光线步进)
简单raymarching实现,还是很好玩的,当然和Shadertoy上的大佬比不了。
shader部分:
Shader "Custom/RayMarching"
{
Properties
{
_MainTex("MainTex",2D)="white"{
}
//相机位置
_CamPos("CamPos",Vector) = (0,0,0,0)
//球体位置,w分量为半径
_SpherePos("SpherePos",Vector) = (0,0,0,0)
_BoxPos("BoxPos",Vector)=(0,0,0,0)
//立方体旋转
_BoxRotation("BoxRotation",Vector)=(0,0,0,0)
//光源位置,w分量为强度
_LightPos("LightPos",Vector)=(0,0,0,0)
//抗锯齿采样数
_AAFactor("AAFactor",Range(1,5))=3
}
SubShader
{
Tags{
"RenderType" = "Opaque"}
Pass{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
#include "Lighting.cginc"
float4 _CamPos;
float4 _SpherePos;
float4 _TargetPos;
float4 _LightPos;
float4 _BoxPos