Skip to content

Remove dependency of shadow vertex shader on matrix_normal #4971

@mvaligursky

Description

@mvaligursky

This is a vertex shader we use to render to shadow map.

uniform mat4 matrix_viewProjection;
uniform mat4 matrix_model;
uniform mat3 matrix_normal;

vec3 dPositionW;
mat4 dModelMatrix;
mat3 dNormalMatrix;

mat4 getModelMatrix() {
    return matrix_model;
}

vec4 getPosition() {
    dModelMatrix = getModelMatrix();
    vec3 localPos = vertex_position;

    vec4 posW = dModelMatrix * vec4(localPos, 1.0);
    dPositionW = posW.xyz;

    vec4 screenPos;
    screenPos = matrix_viewProjection * posW;

    return screenPos;
}

vec3 getWorldPosition() {
    return dPositionW;
}

vec3 getNormal() {
    dNormalMatrix = matrix_normal;

    vec3 tempNormal = vertex_normal;
    return normalize(dNormalMatrix * tempNormal);
}

void main(void) {
    gl_Position = getPosition();
   vPositionW    = getWorldPosition();
   vNormalW = getNormal();

}

I added some new warnings to engine (commented out for now), and it triggers this:
Shader [Shader Id 0 standard] requires uniform [matrix_normal] which has not been set

When WebGL translates the shader for the platform, the uniform is not stripped out as dead code, but is compiled out on the driver level.

Ideally we'd change the shader generator to not include it to avoid - as we unnecessarily handle it. On WebGPU we need to allocate space for it in the uniform buffer as well.

When this is done, the warning should be enabled, as it's very helpful to have.

// Debug.warnOnce(`Shader [${shader.label}] requires uniform [${uniform.scopeId.name}] which has not been set, while rendering [${DebugGraphics.toString()}]`);

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions