Jump to navigation Jump to search

dFdx/dFdy method

You can calculate normals in the fragment shader without passing any vertex normals either to or from the vertex shader. However, that these normals will not interpolate across faces.

in vec3 vertex_coord;

vec3 normal()
    vec3 x = dFdx(vertex_coord);
    vec3 y = dFdy(vertex_coord);
    return normalize(cross(x, y));

See also