I’m trying to port this shader into CG for Unity, but I’m getting the following error:
Shader error in 'Custom/PixelNoiseFade': GLSL vertex shader: 359: ERROR: '' : non-square matrices not supported (3x1) at line 15
I’ve tried changing the declaration but nothing worked, and according to the documentation online my declaration looks OK.
What am I doing wrong?
Shader "Custom/PixelNoiseFade" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Cutoff ("Cutoff", Range(0, 1) ) = 0
}
SubShader {
Tags { "Queue"="Transparent" }
LOD 200
ZWrite On
Blend SrcAlpha OneMinusSrcAlpha
Pass {
Lighting Off
CGPROGRAM
#include "UnityCG.cginc"
#pragma vertex vert
#pragma fragment frag
uniform float _Cutoff;
// Noise functions from IQfloat
float hash(float n) {
return frac(sin(n) * 43758.5453123);
}
// 3d noise
float noise( float3 v ) {
float3 p = floor(v);
float3 f = frac(p);
f = f*f*(3.0-2.0*f);
float n = p.x + 57.0*p.y + 113.0*p.z;
float res = lerp(lerp(lerp( hash(n+ 0.0), hash(n+ 1.0), f.x),
lerp( hash(n+ 57.0), hash(n+ 58.0), f.x),
f.y),
lerp(lerp( hash(n+113.0), hash(n+114.0), f.x),
lerp( hash(n+170.0), hash(n+171.0), f.x),
f.y),
f.z);
return res;
}
// 2d noise
float noise(float2 v) {
float2 p = floor(v);
float2 f = frac(v);
float n = p.x + 57.0*p.y;
float res = lerp(lerp( hash(n+ 0.0), hash(n+ 1.0), f.x),
lerp( hash(n+57.0), hash(n+58.0), f.x),
f.y);
return res;
}
float squares( float2 p, int o) {
float n = 0.0;
float w = 1.0;
for (int i=0; i<32; i++) {
if (i<o) {
w /= 2.0;
n += w * noise(float3(p, 0.0));
p *= 2.0; // two squares per axis on each subdivision
}
else break;
}
return (n / (1.0 - w));
}
float3x3 m3 = float3x3(0.0, *0.8, *0.6, -0.8, 0.36, -0.48, -0.6, -0.48, 0.64);
float fbm(float3 p, int o) {
float n = 0.0;
float w = 1.0;
for (int i=0; i<32; i++) {
if (i<o) {
w = 1.0 / float(o);
n += w * noise(p);
p *= m3 * 2.02;
}
else break;
}
return (n / (1.0 - w));
}
struct v2f {
float4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
};
v2f vert(appdata_img v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord;
return o;
}
float4 frag(v2f i) : COLOR {
float2 position = i.uv.xy / _ScreenParams.zw - 0.5;
position.x *= _ScreenParams.z / _ScreenParams.w;
float n = smoothstep(0.3, 1.0, squares(position * 16.01, 4));
return float4(n, n, n, 1.0);
}
ENDCG
}
}
FallBack "Diffuse"
}