Unkown vector format

Hello forum,

Today I’m trying to port a shader from Shadertoy that has some strange looking functions.
uvec3 and ivec3.

I can easily convert a lot of other shaders but cannot figure out how to replace uvec3 and ivec3

            float3 hash33(float3 p)
            {
                const float UIF = (1.0/ float(0xffffffffU));
                const uvec3 UI3 = uvec3(1597334673U, 3812015801U, 2798796415U);
                uvec3 q = uvec3(ivec3(p)) * UI3;
                q = (q.x ^ q.y ^ q.z)*UI3;
                return float3(q) * UIF;
            }

Anybody got a clue as to how to get this working with Unity?
Thanks in advance!

glsl uvec = hlsl uint
glsl ivec = hlsl int

2 Likes

Shader "Unlit/colorburst"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"
            #define iTime _Time.y
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            float hash( float n )
            {
                return frac(sin(n)*758.5453)*2.;
            }

            float noise( in float3 x )
            {
                float3 p = floor(x);
                float3 f = frac(x);
                //f = f*f*(3.0-2.0*f);
                float n = p.x + p.y*57.0 + p.z*800.0;
                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+800.0), hash(n+801.0),f.x), lerp( hash(n+857.0), hash(n+858.0),f.x),f.y),f.z);
                return res;
            }

            float fbm(float3 p)
            {
                float f = 0.0;
                f += 0.50000*noise( p ); p = p*2.02+0.15;
                f -= 0.25000*noise( p ); p = p*2.03+0.15;
                f += 0.12500*noise( p ); p = p*2.01+0.15;
                f += 0.06250*noise( p ); p = p*2.04+0.15;
                f -= 0.03125*noise( p );
                return f/0.984375;
            }

            float cloud(float3 p)
            {
                p-=fbm(float3(p.x,p.y,0.0)*0.5)*0.7;
  
                float a =0.0;
                a-=fbm(p*3.0)*2.2-1.1;
                if (a<0.0) a=0.0;
                a=a*a;
                return a;
            }

            float2x2 rot( float th ){ float2 a = sin(float2(1.5707963, 0) + th); return float2x2(a, -a.y, a.x); }


            float3 hash33(float3 p)
            {
                const float UIF = (1.0/ float(0xffffffffU));
                const uint3 UI3 = uint3(1597334673U, 3812015801U, 2798796415U);
                uint3 q = uint3(int3(p)) * UI3;
                q = (q.x ^ q.y ^ q.z)*UI3;
                return float3(q) * UIF;
            }


            // 3D Voronoi- (IQ)
            float voronoi(float3 p){

                float3 b, r, g = floor(p);
                p = frac(p);
                float d = 1.;
                for(int j = -1; j <= 1; j++)
                {
                    for(int i = -1; i <= 1; i++)
                    {
                        b = float3(i, j, -1);
                        r = b - p + hash33(g+b);
                        d = min(d, dot(r,r));
                        b.z = 0.0;
                        r = b - p + hash33(g+b);
                        d = min(d, dot(r,r));
                        b.z = 1.;
                        r = b - p + hash33(g+b);
                        d = min(d, dot(r,r));
                    }
                }
                return d;
            }

            // fbm layer
            float noiseLayers(in float3 p) {

                float3 pp = float3(0., 0., p.z + iTime*.09);
                float t = 0.;
                float s = 0.;
                float amp = 1.;
                for (int i = 0; i < 5; i++)
                {
                    t += voronoi(p + pp) * amp;
                    p *= 2.;
                    pp *= 1.5;
                    s += amp;
                    amp *= .5;
                }
                return t/s;
            }

            float3 n2 (float2 fragCoord)
            {
                float2 iResolution = float2(256,256); //texture resolution
                float2 uv = (fragCoord.xy - 0.5 * iResolution.xy) / iResolution.y;
                    float dd = length(uv*uv)*.025;
  
                float3 rd = float3(uv.x, uv.y, 1.0);
  
                float rip = 0.5+sin(length(uv)*20.0+iTime)*0.5;
                rip = pow(rip*.38,4.15);
                rd.z=1.0+rip*1.15;// apply a subtle ripple
                rd = normalize(rd);
                //rd.xy *= rot(dd-iTime*.025);
                rd*=2.0;
  
                float c = noiseLayers(rd*1.85);
                float oc = c;
                c = max(c + dot(hash33(rd)*2. - 1., float3(.006,.006,.006)), 0.);
                c = pow(c*1.55,2.5);  
                float3 col =  float3(.55,0.85,.25);
                float3 col2 =  float3(1.4,1.4,1.4)*5.0;
                float pulse2 = voronoi(float3((rd.xy*1.5),iTime*.255));
                float pulse = pow(oc*1.35,4.0);
                col = lerp(col,col2,pulse*pulse2)*c;
                return col;

            }

            fixed4 frag (v2f i) : SV_Target
            {
                float time = iTime;
                float2 fragCoord = i.uv;
                float2 iResolution = float2(256,256); //texture resolution
                float2 position = (fragCoord.xy - 0.5 * iResolution.xy) / iResolution.y;
                float ss = sin(length(position*3.0)+time*0.125);
                ss+=5.0;
  
  
                   float2 coord = ss*position;
                    coord = mul(rot(ss*0.1+time*0.037),coord);
  
  
                coord+=fbm(sin(float3(coord*8.0,time*0.001)))*0.08;
                coord+=time*0.0171;
                float q = cloud((float3(coord*1.0,0.222)));
                coord+=time*0.0171;
                q += cloud((float3(coord*0.6,0.722)));
                coord+=time*0.0171;
                q += cloud(float3(coord*0.3,.722));
                coord+=time*0.1171;
                q += cloud((float3(coord*0.1,0.722)));
  
  
                float vv1 = sin(time+ss+coord.x)*0.3;
                float vv2 = sin(time*0.9+ss+coord.y)*0.2;

            float3    col = float3(1.7-vv2,1.7,1.7+vv1) + float3(q*float3(0.7+vv1,0.5,0.3+vv2*1.15));
                col = pow(col,float3(2.2,2.2,2.2));
  
                float dd = length(col*.48)+vv1;
  
                float nn = 0.5+sin(ss*2.7+position.x*2.41+time*0.9)*0.5;
  
                float3 col2 = n2(fragCoord)*12.0;
                col2+=col;
                col = lerp(col,col2,nn);
  
                return float4( col*0.08, 1.0 );
            }
            ENDCG
        }
    }
}
1 Like