一、Value noise值噪声
在a和b之间插值
static functionLerp (from : float, to : float, t : float) : float
基于浮点数t返回a到b之间的插值,t限制在0~1之间。当t = 0返回from,当t = 1 返回to。当t = 0.5 返回from和to的平均值。
即返回值为a+(b-a) * t
如果我们想要平滑的效果,就要用smoothstep函数
然而为了实现我们想要的效果,需要用3D值噪声
建立8个随机数,然后在之间平滑插值
第一步:创建相应的属性
Shader "TYX/09RaymarchCloudsVolume"
{
Properties
{
_Scale ("Scale",Range(0.1,10.0))=2.0
_StepScale ("Step Scale",Range(0.1,100.0))=1
_Steps("Steps",Range(1,200))=60
_MinHeight("Min Height",Range(0.0,5.0)) = 0
_MaxHeight("Max Height",Range(6.0,10.0)) = 10
_FadeDist("Fade Distance",Range(0.0,10.0)) = 0.5
_SunDir("Sun Direction",Vector)=(1,0,0,0)
}
SubShader
{
Tags {
"Queue"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
Cull off Lighting Off ZWrite Off
ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 pos:SV_POSITION; //裁剪坐标
float3 view:TEXCOORD0;
float4 projPos:TEXCOORD1; //屏幕坐标
float3 wPos:TEXCOORD2; //世界坐标
};
float _MinHeight;
float _MaxHeight;
float _FadeDist;
float _Scale;
float _StepScale;
float _Steps;
float4 _SunDir;
sampler2D _CameraDepthTexture;
v2f vert (appdata v)
{
v2f o;
o.wPos = mul(unity_ObjectToWorld,v.vertex).xyz;
o.pos = UnityObjectToClipPos(v.vertex);
o.view = o.wPos- _WorldSpaceCameraPos;
o.projPos = ComputeScreenPos(o.pos);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
return fixed4(1,1,1,1);
}
ENDCG
}
}
}
第二步:raymach函数、MARCH、map1
#