Custom Shadergraph shader error

When exporting a shader and opening the sceen in browser I receive this error:
[.WebGL-0x2dfc02218e00] GL_INVALID_OPERATION: glUniform2fv: Only array uniforms may have count > 1.

I am using Unity 2022.3.43f1 and Needle 4.4.3.
This is the generated vertex and fragment shaders. I suppose the issue is the _GlobalMipBias as its the only vec2. Any suggestions as what to do?

Shadergraph:

VERT:

#version 300 es
// downgraded version from 310 (unsupported shader version)

// #define HLSLCC_ENABLE_UNIFORM_BUFFERS 1
// #if HLSLCC_ENABLE_UNIFORM_BUFFERS
// #define UNITY_UNIFORM
// #else
// #define UNITY_UNIFORM uniform
// #endif
// #define UNITY_SUPPORTS_UNIFORM_LOCATION 1
// #if UNITY_SUPPORTS_UNIFORM_LOCATION
// #define UNITY_LOCATION(x) layout(location = x)
// #define UNITY_BINDING(x) layout(binding = x, std140)
// #else
// #define UNITY_LOCATION(x)
// #define UNITY_BINDING(x) layout(std140)
// #endif
uniform 	vec4 hlslcc_mtx4x4unity_MatrixVP[4];
// #if HLSLCC_ENABLE_UNIFORM_BUFFERS

// removed unsupported block: uniform UnityPerDraw {
// #endif
uniform vec4                hlslcc_mtx4x4unity_ObjectToWorld[4];
uniform vec4                hlslcc_mtx4x4unity_WorldToObject[4];
uniform vec4 Xhlslcc_UnusedXunity_LODFade;
uniform vec4                unity_WorldTransformParams;
uniform vec4 Xhlslcc_UnusedXunity_RenderingLayer;
uniform vec4 Xhlslcc_UnusedXunity_LightData;
uniform vec4 Xhlslcc_UnusedXunity_LightIndices[2];
uniform vec4 Xhlslcc_UnusedXunity_ProbesOcclusion;
uniform vec4                unity_SpecCube0_HDR;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube1_HDR;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube0_BoxMax;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube0_BoxMin;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube0_ProbePosition;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube1_BoxMax;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube1_BoxMin;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube1_ProbePosition;
uniform vec4 Xhlslcc_UnusedXunity_LightmapST;
uniform vec4 Xhlslcc_UnusedXunity_DynamicLightmapST;
uniform vec4 Xhlslcc_UnusedXunity_SHAr;
uniform vec4 Xhlslcc_UnusedXunity_SHAg;
uniform vec4 Xhlslcc_UnusedXunity_SHAb;
uniform vec4 Xhlslcc_UnusedXunity_SHBr;
uniform vec4 Xhlslcc_UnusedXunity_SHBg;
uniform vec4 Xhlslcc_UnusedXunity_SHBb;
uniform vec4 Xhlslcc_UnusedXunity_SHC;
uniform vec4 Xhlslcc_UnusedXunity_RendererBounds_Min;
uniform vec4 Xhlslcc_UnusedXunity_RendererBounds_Max;
uniform vec4 Xhlslcc_UnusedXhlslcc_mtx4x4unity_MatrixPreviousM[4];
uniform vec4 Xhlslcc_UnusedXhlslcc_mtx4x4unity_MatrixPreviousMI[4];
uniform vec4 Xhlslcc_UnusedXunity_MotionVectorsParams;
// #if HLSLCC_ENABLE_UNIFORM_BUFFERS
// #endif
#ifdef USE_INSTANCING
  in mat4 instanceMatrix;
#endif
in highp vec3 position;
in highp vec3 normal;
in highp vec4 tangent;
in highp vec4 uv;
out highp vec4 vs_INTERP0;
out highp vec4 vs_INTERP1;
out highp vec3 vs_INTERP2;
out highp vec3 vs_INTERP3;
vec3 u_xlat0;
vec4 u_xlat1;
float u_xlat6;
void main() {
vec4 osw[4] = hlslcc_mtx4x4unity_ObjectToWorld;
#ifdef USE_INSTANCING
mat4 _osw;
_osw[0] = hlslcc_mtx4x4unity_ObjectToWorld[0];
_osw[1] = hlslcc_mtx4x4unity_ObjectToWorld[1];
_osw[2] = hlslcc_mtx4x4unity_ObjectToWorld[2];
_osw[3] = hlslcc_mtx4x4unity_ObjectToWorld[3];
_osw = instanceMatrix * _osw;
osw[0] = _osw[0];
osw[1] = _osw[1];
osw[2] = _osw[2];
osw[3] = _osw[3];
#endif
    u_xlat0.xyz = position.yyy * osw[1].xyz;
    u_xlat0.xyz = osw[0].xyz * position.xxx + u_xlat0.xyz;
    u_xlat0.xyz = osw[2].xyz * position.zzz + u_xlat0.xyz;
    u_xlat0.xyz = u_xlat0.xyz + osw[3].xyz;
    u_xlat1 = u_xlat0.yyyy * hlslcc_mtx4x4unity_MatrixVP[1];
    u_xlat1 = hlslcc_mtx4x4unity_MatrixVP[0] * u_xlat0.xxxx + u_xlat1;
    u_xlat1 = hlslcc_mtx4x4unity_MatrixVP[2] * u_xlat0.zzzz + u_xlat1;
    vs_INTERP2.xyz = u_xlat0.xyz;
    gl_Position = u_xlat1 + hlslcc_mtx4x4unity_MatrixVP[3];
    u_xlat0.xyz = tangent.yyy * osw[1].xyz;
    u_xlat0.xyz = osw[0].xyz * tangent.xxx + u_xlat0.xyz;
    u_xlat0.xyz = osw[2].xyz * tangent.zzz + u_xlat0.xyz;
    u_xlat6 = dot(u_xlat0.xyz, u_xlat0.xyz);
    u_xlat6 = max(u_xlat6, 1.17549435e-38);
    u_xlat6 = inversesqrt(u_xlat6);
    vs_INTERP0.xyz = vec3(u_xlat6) * u_xlat0.xyz;
    vs_INTERP0.w = tangent.w;
    vs_INTERP1 = uv;
    u_xlat0.x = dot(normal.xyz, hlslcc_mtx4x4unity_WorldToObject[0].xyz);
    u_xlat0.y = dot(normal.xyz, hlslcc_mtx4x4unity_WorldToObject[1].xyz);
    u_xlat0.z = dot(normal.xyz, hlslcc_mtx4x4unity_WorldToObject[2].xyz);
    u_xlat6 = dot(u_xlat0.xyz, u_xlat0.xyz);
    u_xlat6 = max(u_xlat6, 1.17549435e-38);
    u_xlat6 = inversesqrt(u_xlat6);
    vs_INTERP3.xyz = vec3(u_xlat6) * u_xlat0.xyz;
    return;
}

FRAG:

#version 300 es
// downgraded version from 310 (unsupported shader version)
// // #ifdef GL_EXT_shader_texture_lod
// #extension GL_EXT_shader_texture_lod : enable
// #endif
// // #ifdef GL_EXT_shader_framebuffer_fetch
// #extension GL_EXT_shader_framebuffer_fetch : enable
// #endif

precision highp float;
precision highp int;
// #define HLSLCC_ENABLE_UNIFORM_BUFFERS 1
// #if HLSLCC_ENABLE_UNIFORM_BUFFERS
// #define UNITY_UNIFORM
// #else
// #define UNITY_UNIFORM uniform
// #endif
// #define UNITY_SUPPORTS_UNIFORM_LOCATION 1
// #if UNITY_SUPPORTS_UNIFORM_LOCATION
// #define UNITY_LOCATION(x) layout(location = x)
// #define UNITY_BINDING(x) layout(binding = x, std140)
// #else
// #define UNITY_LOCATION(x)
// #define UNITY_BINDING(x) layout(std140)
// #endif
uniform 	vec2 _GlobalMipBias;
uniform 	vec3 _WorldSpaceCameraPos;
uniform 	vec4 unity_OrthoParams;
uniform 	vec4 hlslcc_mtx4x4unity_MatrixV[4];
// #if HLSLCC_ENABLE_UNIFORM_BUFFERS

// removed unsupported block: uniform UnityPerDraw {
// #endif
uniform vec4                hlslcc_mtx4x4unity_ObjectToWorld[4];
uniform vec4                hlslcc_mtx4x4unity_WorldToObject[4];
uniform vec4 Xhlslcc_UnusedXunity_LODFade;
uniform vec4                unity_WorldTransformParams;
uniform vec4 Xhlslcc_UnusedXunity_RenderingLayer;
uniform vec4 Xhlslcc_UnusedXunity_LightData;
uniform vec4 Xhlslcc_UnusedXunity_LightIndices[2];
uniform vec4 Xhlslcc_UnusedXunity_ProbesOcclusion;
uniform vec4                unity_SpecCube0_HDR;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube1_HDR;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube0_BoxMax;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube0_BoxMin;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube0_ProbePosition;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube1_BoxMax;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube1_BoxMin;
uniform vec4 Xhlslcc_UnusedXunity_SpecCube1_ProbePosition;
uniform vec4 Xhlslcc_UnusedXunity_LightmapST;
uniform vec4 Xhlslcc_UnusedXunity_DynamicLightmapST;
uniform vec4 Xhlslcc_UnusedXunity_SHAr;
uniform vec4 Xhlslcc_UnusedXunity_SHAg;
uniform vec4 Xhlslcc_UnusedXunity_SHAb;
uniform vec4 Xhlslcc_UnusedXunity_SHBr;
uniform vec4 Xhlslcc_UnusedXunity_SHBg;
uniform vec4 Xhlslcc_UnusedXunity_SHBb;
uniform vec4 Xhlslcc_UnusedXunity_SHC;
uniform vec4 Xhlslcc_UnusedXunity_RendererBounds_Min;
uniform vec4 Xhlslcc_UnusedXunity_RendererBounds_Max;
uniform vec4 Xhlslcc_UnusedXhlslcc_mtx4x4unity_MatrixPreviousM[4];
uniform vec4 Xhlslcc_UnusedXhlslcc_mtx4x4unity_MatrixPreviousMI[4];
uniform vec4 Xhlslcc_UnusedXunity_MotionVectorsParams;
// #if HLSLCC_ENABLE_UNIFORM_BUFFERS
// #endif
// #if HLSLCC_ENABLE_UNIFORM_BUFFERS

// removed unsupported block: uniform UnityPerMaterial {
// #endif
uniform vec4                _Color0;
uniform float                _ColorAngleExponent;
uniform float                _ReflWeightAngleExponent;
uniform float                _ReflWeight1;
uniform float                _ReflWeight0;
uniform vec4                _ReflColor;
uniform vec4                _Color1;
uniform vec4 Xhlslcc_UnusedX_BumpMap_TexelSize;
uniform vec4 Xhlslcc_UnusedX_BaseMap_TexelSize;
// #if HLSLCC_ENABLE_UNIFORM_BUFFERS
// #endif
uniform mediump samplerCube unity_SpecCube0;
uniform mediump sampler2D _BumpMap;
uniform mediump sampler2D _BaseMap;
in highp vec4 vs_INTERP0;
in highp vec4 vs_INTERP1;
in highp vec3 vs_INTERP2;
in highp vec3 vs_INTERP3;
// // #ifdef GL_EXT_shader_framebuffer_fetch
// inout highp vec4 SV_Target0;
// #else
out highp vec4 SV_Target0;
// #endif
vec3 u_xlat0;
bvec2 u_xlatb0;
vec4 u_xlat1;
vec4 u_xlat2;
vec4 u_xlat3;
vec4 u_xlat4;
vec3 u_xlat5;
float u_xlat6;
float u_xlat10;
float u_xlat15;
bool u_xlatb15;
void main()
{
    u_xlatb0.x = 0.0<vs_INTERP0.w;
    u_xlatb0.y = unity_WorldTransformParams.w>=0.0;
    u_xlat0.x = (u_xlatb0.x) ? float(1.0) : float(-1.0);
    u_xlat0.y = (u_xlatb0.y) ? float(1.0) : float(-1.0);
    u_xlat0.x = u_xlat0.y * u_xlat0.x;
    u_xlat5.xyz = vs_INTERP0.yzx * vs_INTERP3.zxy;
    u_xlat5.xyz = vs_INTERP3.yzx * vs_INTERP0.zxy + (-u_xlat5.xyz);
    u_xlat0.xyz = u_xlat5.xyz * u_xlat0.xxx;
    u_xlat15 = dot(vs_INTERP3.xyz, vs_INTERP3.xyz);
    u_xlat15 = sqrt(u_xlat15);
    u_xlat15 = float(1.0) / u_xlat15;
    u_xlat0.xyz = u_xlat0.xyz * vec3(u_xlat15);
    u_xlat1.xyz = texture(_BumpMap, vs_INTERP1.xy, _GlobalMipBias.x).xyw;
    u_xlat1.x = u_xlat1.x * u_xlat1.z;
    u_xlat1.xy = u_xlat1.xy * vec2(2.0, 2.0) + vec2(-1.0, -1.0);
    u_xlat0.xyz = u_xlat0.xyz * u_xlat1.yyy;
    u_xlat2.xyz = vec3(u_xlat15) * vs_INTERP0.xyz;
    u_xlat3.xyz = vec3(u_xlat15) * vs_INTERP3.xyz;
    u_xlat0.xyz = u_xlat1.xxx * u_xlat2.xyz + u_xlat0.xyz;
    u_xlat15 = dot(u_xlat1.xy, u_xlat1.xy);
    u_xlat15 = min(u_xlat15, 1.0);
    u_xlat15 = (-u_xlat15) + 1.0;
    u_xlat15 = sqrt(u_xlat15);
    u_xlat15 = max(u_xlat15, 1.00000002e-16);
    u_xlat0.xyz = vec3(u_xlat15) * u_xlat3.xyz + u_xlat0.xyz;
    u_xlat1.x = dot(u_xlat0.xyz, hlslcc_mtx4x4unity_ObjectToWorld[0].xyz);
    u_xlat1.y = dot(u_xlat0.xyz, hlslcc_mtx4x4unity_ObjectToWorld[1].xyz);
    u_xlat1.z = dot(u_xlat0.xyz, hlslcc_mtx4x4unity_ObjectToWorld[2].xyz);
    u_xlat0.x = dot(u_xlat1.xyz, u_xlat1.xyz);
    u_xlat0.x = max(u_xlat0.x, 1.17549435e-38);
    u_xlat0.x = inversesqrt(u_xlat0.x);
    u_xlat0.xyz = u_xlat0.xxx * u_xlat1.xyz;
    u_xlat1.xyz = (-vs_INTERP2.xyz) + _WorldSpaceCameraPos.xyz;
    u_xlat15 = dot(u_xlat1.xyz, u_xlat1.xyz);
    u_xlat15 = inversesqrt(u_xlat15);
    u_xlat1.xyz = vec3(u_xlat15) * u_xlat1.xyz;
    u_xlatb15 = unity_OrthoParams.w==0.0;
    u_xlat6 = (u_xlatb15) ? u_xlat1.y : hlslcc_mtx4x4unity_MatrixV[1].z;
    u_xlat2.xyz = vec3(u_xlat6) * hlslcc_mtx4x4unity_WorldToObject[1].xyz;
    u_xlat1.x = (u_xlatb15) ? u_xlat1.x : hlslcc_mtx4x4unity_MatrixV[0].z;
    u_xlat15 = (u_xlatb15) ? u_xlat1.z : hlslcc_mtx4x4unity_MatrixV[2].z;
    u_xlat1.xyz = hlslcc_mtx4x4unity_WorldToObject[0].xyz * u_xlat1.xxx + u_xlat2.xyz;
    u_xlat1.xyz = hlslcc_mtx4x4unity_WorldToObject[2].xyz * vec3(u_xlat15) + u_xlat1.xyz;
    u_xlat15 = dot(u_xlat1.xyz, u_xlat1.xyz);
    u_xlat15 = inversesqrt(u_xlat15);
    u_xlat1.xyz = vec3(u_xlat15) * u_xlat1.xyz;
    u_xlat15 = dot((-u_xlat1.xyz), u_xlat0.xyz);
    u_xlat15 = u_xlat15 + u_xlat15;
    u_xlat2.xyz = u_xlat0.xyz * (-vec3(u_xlat15)) + (-u_xlat1.xyz);
    u_xlat0.x = dot(u_xlat1.xyz, u_xlat0.xyz);
    u_xlat0.x = clamp(u_xlat0.x, 0.0, 1.0);
    u_xlat0.x = log2(u_xlat0.x);
    u_xlat0.xy = u_xlat0.xx * vec2(_ColorAngleExponent, _ReflWeightAngleExponent);
    u_xlat0.xy = exp2(u_xlat0.xy);
    u_xlat1 = textureLod(unity_SpecCube0, u_xlat2.xyz, 0.0);
    u_xlat10 = u_xlat1.w + -1.0;
    u_xlat10 = unity_SpecCube0_HDR.w * u_xlat10 + 1.0;
    u_xlat10 = max(u_xlat10, 0.0);
    u_xlat10 = log2(u_xlat10);
    u_xlat10 = u_xlat10 * unity_SpecCube0_HDR.y;
    u_xlat10 = exp2(u_xlat10);
    u_xlat10 = u_xlat10 * unity_SpecCube0_HDR.x;
    u_xlat1.xyz = u_xlat1.xyz * vec3(u_xlat10);
    u_xlat1.xyz = u_xlat1.xyz * _ReflColor.xyz;
    u_xlat10 = (-_ReflWeight0) + _ReflWeight1;
    u_xlat5.x = u_xlat0.y * u_xlat10 + _ReflWeight0;
    u_xlat2 = (-_Color0) + _Color1;
    u_xlat2 = u_xlat0.xxxx * u_xlat2 + _Color0;
    u_xlat3.xyz = u_xlat2.xyz;
    u_xlat3.w = 1.0;
    u_xlat4 = texture(_BaseMap, vs_INTERP1.xy, _GlobalMipBias.x);
    u_xlat3 = u_xlat3 + (-u_xlat4);
    u_xlat2 = u_xlat2.wwww * u_xlat3 + u_xlat4;
    SV_Target0.xyz = u_xlat1.xyz * u_xlat5.xxx + u_xlat2.xyz;
    SV_Target0.w = u_xlat2.w;
    return;
}

Hi Martin, the error indicates that the uniform _GlobalMipBias is being assigned more than one element even though it’s declared as a single vec2. In WebGL, glUniform2fv requires that when you pass a count greater than 1 the uniform must be declared as an array.

A practical workaround is to change your uniform declaration by explicitly making it an array, even if it only has one element. For example, instead of

uniform vec2 _GlobalMipBias;

you would write

uniform vec2 _GlobalMipBias[1];

This tells the WebGL runtime that you’re intentionally using an array, and glUniform2fv will then interpret the count correctly.

If modifying the shader code directly isn’t straightforward through Shadergraph, double-check that the property is set up correctly in your Shadergraph settings and verify in your export settings that it isn’t being inadvertently treated as an array.

Since you’re using Unity 2022.3.43f1 with Needle 4.4.3, if the issue persists you might consider generating a minimal reproducible example (for instance via Needle-engine - Vite Template (duplicated) - StackBlitz) and filing a bug report using the Needle Engine bug reporting option from Unity. This helps the team address it in future updates.

Hope this helps! Let me know if you have any further questions.

1 replies left - Become PRO for more replies.
thread_YicCTtQDdWNvwMGKClNWoJ05
Reply to this post directly if you need further help (bottom right button)

Sounds a bit like for some reason data is passed to the shader in the wrong format; the export looks ok from a quick glance.

Could you send us a small bug report project via the Needle Engine menu? Thanks!

I have uploaded the bug report.

1 Like

Hi is there any update to this?