我想立即说明我不与着色器一起工作,而我正在与我一起玩的基本景色 - 来自Unity论坛中线程的力量野外着色器,是一个较旧的版本。但是,原始的"几乎"可以做我想要的。
我想对其进行修改以添加滚动效果以模拟速度,但是奇怪的是,我得到了"未识别的标识符"输入"。输入是正常的变量。.据说在Unity的着色器中。到目前为止,这是我的代码:
Shader "Custom/SubspaceLook" {
Properties {
_Color ("Main Color", Color) = (1,1,1,0.5)
_MainTex ("Texture", 2D) = "white" {}
_UVScale ("UV Scale", Range (0.05, 4)) = 1
_UVDistortion ("UV Distortion", Range (0.01, 1)) = 0.5
_Rate ("Oscillation Rate", Range (5, 200)) = 10
_Rate2 ("Oscillation Rate Difference", Range (1, 3)) = 1.43
_ZPhase ("Z Phase", Range (0, 3)) = 0.5
_Scale ("Scale", Range (0.02, 2)) = 0.5
_Distortion ("Distortion", Range (0, 20)) = 0.4
_ScrollSpeedX("Scroll X", Range(0, 10)) = 2
_ScrollSpeedY("Scroll Y", Range(0, 10)) = 3
}
SubShader {
ZWrite Off
Tags { "Queue" = "Transparent" }
Blend One One
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#include "UnityCG.cginc"
float4 _Color;
sampler2D _MainTex;
float _Rate;
float _Rate2;
float _Scale;
float _Distortion;
float _ZPhase;
float _UVScale;
float _UVDistortion;
float _ScrollSpeedX;
float _ScrollSpeedY;
struct v2f {
float4 pos : SV_POSITION;
float3 uvsin : TEXCOORD0;
float3 vertsin : TEXCOORD1;
float2 uv : TEXCOORD2;
};
v2f vert (appdata_base v)
{
v2f o;
o.pos = UnityObjectToClipPos (v.vertex);
float s = 1 / _Scale;
float t = (_Time[0]*_Rate*_Scale) / _Distortion;
float2 uv = float2(v.vertex.y * 0.3 + (v.vertex.y - v.vertex.z *
0.0545), v.vertex.x + (v.vertex.z - v.vertex.x * 0.03165));
o.vertsin = sin((v.vertex.xyz + t) * s);
o.uvsin = sin((float3(uv, t * _ZPhase) + (t* _Rate2)) * s) *
_Distortion;
o.uv = uv;
return o;
}
half4 frag (v2f i) : COLOR
{
float3 vert = i.vertsin;
float3 uv = i.uvsin;
float mix = 1 + sin((vert.x - uv.x) + (vert.y - uv.y) + (vert.z -
uv.z));
float mix2 = 1 + sin((vert.x + uv.x) - (vert.y + uv.y) - (vert.z +
uv.z));
return half4( tex2D( _MainTex, (i.uv + (float2(mix, mix2) *
_UVDistortion)) * _UVScale ) * 1.5 * _Color);
}
void surf(Input IN, inout SurfaceOutput o)
{
fixed2 scrolledUV = IN.uv_MainTex;
fixed xScrollValue = _ScrollSpeedX * _Time;
fixed yScrollValue = _ScrollSpeedY * _Time;
scrolledUV += fixed2(xScrollValue, yScrollValue);
half2 c = tex2D(_MainTex, scrolledUV);
o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rbg;
o.Albedo += c.rbg;
half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
o.Emission = _Rimcolor.rgb * pow(rim, _RimPower);
}
ENDCG
}
}
Fallback "Diffuse"
}
我对原始着色器的主要更改是为其添加滚动值和"冲浪"。否则,我没有碰到第一个版本,该版本是由Forestjohnson在2008年撰写的。
您是混合匹配的表面着色器代码和常规着色器:
#pragma vertex vert
#pragma fragment frag
这些用于显式顶点和像素着色器,而Surf()是Unity Surface着色器系统。
编译器指向的错误是您的着色器缺少 input struct surf()函数所引用的,但这不是您需要查看的内容。
struct Input {
float2 uv_MainTex;
};
https://docs.unity3d.com/manual/sl-surfaceshaders.html