Skip to content

Instantly share code, notes, and snippets.

@faultyagatha
Created August 30, 2020 09:48
Show Gist options
  • Save faultyagatha/336d8ab1fc5c6f0ac7687756fa18e920 to your computer and use it in GitHub Desktop.
Save faultyagatha/336d8ab1fc5c6f0ac7687756fa18e920 to your computer and use it in GitHub Desktop.

Revisions

  1. faultyagatha created this gist Aug 30, 2020.
    10 changes: 10 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    /* in fragment shader, using derivatives extension enabled */

    //vertex:
    vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
    vViewPos = mvPosition.xyz; //pass to the fragment shader

    //fragment:
    vec3 X = dFdx(vViewPos);
    vec3 Y = dFdy(vViewPos);
    vec3 normal = normalize(cross(X, Y));