Hi all, I recently moved from Godot to Unity. I’m recreating a procedural skybox shader that I wrote in godot, and I need a fast rand function to use in voronoi and simplex noise functions. I’ve been trying to port over a (output 0->1) rand function from godot (GLSL) into HLSL, but the output value is always zero.
Here’s my code
Shader "Unlit/Sky shader"
{
Properties
{
}
SubShader
{
Tags { "Queue"="Background"}
LOD 100
Pass
{
Tags { "LightMode" = "ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 4.0
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
float3 eyeDir : TEXCOORD0;
};
float4 _SkyColor;
float4 _SunColor;
float _SunAngle;
const uint c = 1103515245u;
const float d = 1103515245;
float rand1 (float position){
// uint bitpos = asuint(position) + 1u;
// bitpos = ((bitpos>>8u) ^ bitpos)*c;
// bitpos = ((bitpos>>8u) ^ bitpos)*c;
// return frac(float(bitpos)/d);
uint bitpos = asuint(position);
bitpos = (bitpos >> 8u) ^ bitpos;
bitpos = (bitpos >> 8u) ^ bitpos;
return frac(asfloat(bitpos));
}
v2f vert (appdata v)
{
v2f o;
return o;
}
float4 frag (v2f i) : SV_Target
{
float rand = rand1(_Time.y);
return float4(rand, 0, 0, 1);
}
ENDCG
}
}
}
…which should result in a random shade of red each frame (which works as expected in godot).
In unity however, the result is just black (zero, not negative)
Any ideas?