这几天我一直在学习 Unity 着色器,并决定从 Shadertoy移植这个油着色器。
我收到以下错误:
第 69 行的数字类型构造函数的参数数量不正确(在 glcore 上)
这是着色器代码的相关部分:
#define T (_Time/3.+5.)
fixed4 frag(v2f i) : SV_Target
{
float4 fragColor = 0;
float2 fragCoord = i.vertex.xy;
float4 k = fragColor;
float2 p = fragCoord;
float s = 1.;
#define rot(p,a) float2 sc = sin(float2(a,a + 1.6)); p *= float2x2(sc.y,-sc.x,sc);
#define A float3(0,1,157)
#define B {float2 m = frac(p),l = dot(p - m,A.yz) + A.xz,r = lerp(frac(57.*sin(l++)),frac(57.*sin(l)),(m *= m*(3. - m - m)).x); k += lerp(r.x,r.y,m.y) / (s += s); p *= float4(1,1,1,-1);}
p *= log(T) / R.y; // scaling (slow zoom out)
p.x += T; // translation
rot(p, T / 22.); //ERROR HERE
//......the rest of the code below
}
该rot(p, T / 22.);
行是错误所在的位置。有趣的是,当我删除或注释掉这行代码时,着色器会编译并且工作正常。我仍然想知道为什么该行无法编译。
是什么导致了该错误,我该如何解决?
编辑:
正如helium所指出的,float3x3
是一个矩阵。
下面是原始的rot函数:
#define rot(p,a) vec2 sc=sin(vec2(a,a+1.6)); p*=mat2(sc.y,-sc.x,sc);
和移植版本:
#define rot(p,a) float2 sc = sin(float2(a,a + 1.6)); p *= float2x2(sc.y,-sc.x,sc);
请注意我是如何替换为的mat2
,float2x2
因为这是 HLSL 中的等效类型。
我相信问题出在float2x2(sc.y,-sc.x,sc);
. 执行此操作的适当方法是什么,并且仍然3
像原始代码一样使用参数?