[SOLVED] No point light after vertex shader

Hi, All

I’ve added vertex shader to bend perspective. But after adding this shader all my point and spot lights stops working, there is no light on materials where I apply my vertex shader. Works only directional light. What the issue it can be? Thanks for help! Here is my vertex shader code.

uniform float bendX;
uniform float bendY;
uniform float cameraZ;
uniform mat4 matrix_view;

mat4 getModelMatrix() {
    #ifdef DYNAMICBATCH
    return getBoneMatrix(vertex_boneIndices);
    #elif defined(SKIN)
    return matrix_model * getSkinMatrix(vertex_boneIndices, vertex_boneWeights);
    #elif defined(INSTANCING)
    return mat4(instance_line1, instance_line2, instance_line3, instance_line4);
    #else
    return matrix_model;
    #endif
}

vec4 getPosition() {
    dModelMatrix = getModelMatrix();
    vec3 localPos = vertex_position;
    vec4 posW = dModelMatrix * vec4(localPos, 1.0);
    float depth = posW.z - cameraZ;
    depth *= depth;
    posW.y += depth * bendY;
    posW.x += depth * bendX;
    vec4 mvPosition = matrix_view * vec4(posW.xyz, 1.0);
    gl_Position = matrix_viewProjection * mvPosition;
    dPositionW = gl_Position.xyz;
    vec4 screenPos = matrix_viewProjection * posW;
    return screenPos;
}

vec3 getWorldPosition() {
    return dPositionW;
}

Thanks,
Maksym

Hi @koroldev and welcome,

Not sure if that’s the problem but:

Try doing your calculations against the localPos variable, that is the vertex_position attribute, before calculating the world position (posW).

I have a curved effect example here, that seems to work fine with point lights:

https://playcanvas.com/editor/scene/1353984

3 Likes

Thanks, a lot :grinning:
I just commented two lines and it helped.

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

    vec4 posW = dModelMatrix * vec4(localPos, 1.0);
    
    float depth = posW.z - cameraZ;
    depth *= depth;
    posW.y += depth * bendY;
    posW.x += depth * bendX;

    //vec4 mvPosition = matrix_view * vec4(posW.xyz, 1.0);
    //gl_Position = matrix_viewProjection * mvPosition;
    
    dPositionW = posW.xyz;//gl_Position.xyz;

    vec4 screenPos = matrix_viewProjection * posW;
    return screenPos;
}
1 Like