<commit_before><html>
  <head>
    <meta charset="utf-8">
    <script type="text/javascript" src="Three.js"></script>
    <script src="TrackballControls.js"></script>

  </head>
  <body onload="start()" style="background:#888888; margin:0px; padding:0px" onmousemove="update()">

  <div id="container"></div>


    
    

  <!-- ----- VERTEX SHADER ----- -->
  <script id="vertex_shader" type="x-shader/x-vertex">

    uniform float p2x;
    uniform float p2y;
    uniform float p3x;
    uniform float p3y;

    attribute vec4 tangent; 
    attribute float amplitude;
    attribute float displacement;

    varying vec3 vTangent;
    varying vec3 vBinormal;
    varying vec3 vNormal;
    varying vec2 vUv;

    varying vec3 vPointLightVector;
    varying vec3 vViewPosition;

    uniform vec3 uPointLightPos;

    #ifdef VERTEX_TEXTURES

      uniform sampler2D tDisp;
      uniform float uDisplacementScale;
      uniform float uDisplacementBias;
      uniform float uDisplacementPostScale;

    #endif
    
    
    void main() {

      vec4 mPosition = modelMatrix * vec4( position, 1.0 );     // from ninja demo

      vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
      vNormal = normalize( normalMatrix * normal );

      // tangent and binormal vectors
      vTangent = normalize( normalMatrix * tangent.xyz );

      vBinormal = cross( vNormal, vTangent ) * tangent.w;
      vBinormal = normalize( vBinormal );

      vUv = uv;

      // point light
      vec4 lPosition      = viewMatrix * vec4( uPointLightPos, 1.0 );
      vPointLightVector   = normalize( lPosition.xyz - mvPosition.xyz );

      #ifdef VERTEX_TEXTURES
        vec3 dv                 = texture2D( tDisp, vUv ).xyz;
        float df                = uDisplacementScale * dv.x + uDisplacementBias;
        vec4 displacedPosition  = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;

        gl_Position             = projectionMatrix * displacedPosition;

        vViewPosition = -displacedPosition.xyz; // from webgl_cubes_indexed demo
      #else
        gl_Position = projectionMatrix * mvPosition;

        //vViewPosition = cameraPosition - mPosition.xyz; // original
      vViewPosition = -mvPosition.xyz; // from webgl_cubes_indexed demo

      #endif
    }

  </script>

    
    
    
  <!-- ----- FRAGMENT SHADER ----- -->    
  
    <script id="fragment_shader" type="x-shader/x-fragment">

    uniform vec3 uPointLightPos;

    uniform vec3 uAmbientLightColor;
    uniform vec3 uPointLightColor;

    uniform vec3 uAmbientColor;
    uniform vec3 uDiffuseColor;
    uniform vec3 uSpecularColor;
    uniform float uShininess; //
    
    uniform sampler2D tDiffuse;
    uniform sampler2D tNormal;
    uniform sampler2D tSpec;  //
    uniform sampler2D tOcc; //

    uniform float uNormalScale; //

    varying vec3 vTangent;
    varying vec3 vBinormal;
    varying vec3 vNormal;
    varying vec2 vUv;

    varying vec3 vPointLightVector;
    varying vec3 vViewPosition;
    
    void main() {

      vec3 diffuseTex     = texture2D( tDiffuse, vUv ).xyz;
      
      vec3 normalTex      = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;
      mat3 tsb            = mat3( vTangent, vBinormal, vNormal );
      vec3 viewPosition   = normalize( vViewPosition );
      
      // toggle these lines depending on whether you're using a normal texture:
      
      //vec3 finalNormal    = tsb * normalTex.rgb;       // works with tNormal
      vec3 finalNormal       = vec3( vNormal );           // works without tNormal

      
      // toggle these lines for experimental normal recaculation:
      
      // vec3 normal         = normalize( finalNormal );  // original; light position is correct, but normals ignore displacement
      vec3 normal = normalize( cross( dFdx( vViewPosition ), dFdy( vViewPosition ) ) );    // from webgl_cubes_indexed demo; normals recaculated, still seem to be flat

      
      // point light

      vec4 pointDiffuse           = vec4( 0.0, 0.0, 0.0, 0.0 );
      vec4 pointSpecular          = vec4( 0.0, 0.0, 0.0, 0.0 ); //
      
      vec3 pointVector            = normalize( vPointLightVector );
      vec3 pointHalfVector        = normalize( vPointLightVector - vViewPosition );

      float pointDotNormalHalf    = dot( normal, pointHalfVector );  //
      float pointDiffuseWeight    = max( dot( normal * 2.0, pointVector ), 0.0 );

      float pointSpecularWeight   = 0.0;  //
      if ( pointDotNormalHalf >= 0.0 )    pointSpecularWeight = pow( pointDotNormalHalf, 60.0 );  // no spectex

      pointDiffuse               += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;
      pointSpecular              += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight; //

      // all lights contribution summation

      vec4 totalLight             = vec4( uAmbientLightColor * uAmbientColor , 1.0 );
      totalLight                 += vec4( uPointLightColor, 1.0 ) * ( pointDiffuse + pointSpecular );

      gl_FragColor = vec4( totalLight.xyz, 1.0 );
                    
    }
  </script>
    
    
<commit_msg>experimental normal recalculation<commit_after><html>
  <head>
    <meta charset="utf-8">
    <script type="text/javascript" src="Three.js"></script>
    <script src="TrackballControls.js"></script>

  </head>
  <body onload="start()" style="background:#888888; margin:0px; padding:0px" onmousemove="update()">

  <div id="container"></div>


    
    

  <!-- ----- VERTEX SHADER ----- -->
  <script id="vertex_shader" type="x-shader/x-vertex">

    uniform float p2x;
    uniform float p2y;
    uniform float p3x;
    uniform float p3y;

    attribute vec4 tangent; 
    attribute float amplitude;
    attribute float displacement;

    varying vec3 vTangent;
    varying vec3 vBinormal;
    varying vec3 vNormal;
    varying vec2 vUv;

    varying vec3 vPointLightVector;
    varying vec3 vViewPosition;

    uniform vec3 uPointLightPos;

    #ifdef VERTEX_TEXTURES

      uniform sampler2D tDisp;
      uniform float uDisplacementScale;
      uniform float uDisplacementBias;
      uniform float uDisplacementPostScale;

    #endif
    
    
    void main() {

      vec4 mPosition = modelMatrix * vec4( position, 1.0 );     // from ninja demo

      vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
      vNormal = normalize( normalMatrix * normal );

      // tangent and binormal vectors
      vTangent = normalize( normalMatrix * tangent.xyz );

      vBinormal = cross( vNormal, vTangent ) * tangent.w;
      vBinormal = normalize( vBinormal );

      vUv = uv;

      // point light
      vec4 lPosition      = viewMatrix * vec4( uPointLightPos, 1.0 );
      vPointLightVector   = normalize( lPosition.xyz - mvPosition.xyz );

      #ifdef VERTEX_TEXTURES
        vec3 dv                 = texture2D( tDisp, vUv ).xyz;
        float df                = uDisplacementScale * dv.x + uDisplacementBias;
        vec4 displacedPosition  = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;

        gl_Position             = projectionMatrix * displacedPosition;

        vViewPosition = -displacedPosition.xyz; // from webgl_cubes_indexed demo
      #else
        gl_Position = projectionMatrix * mvPosition;

        //vViewPosition = cameraPosition - mPosition.xyz; // original
      vViewPosition = -mvPosition.xyz; // from webgl_cubes_indexed demo

      #endif
    }

  </script>

    
    
    
  <!-- ----- FRAGMENT SHADER ----- -->    
  
    <script id="fragment_shader" type="x-shader/x-fragment">

    uniform vec3 uPointLightPos;

    uniform vec3 uAmbientLightColor;
    uniform vec3 uPointLightColor;

    uniform vec3 uAmbientColor;
    uniform vec3 uDiffuseColor;
    uniform vec3 uSpecularColor;
    uniform float uShininess; //
    
    uniform sampler2D tDiffuse;
    uniform sampler2D tNormal;
    uniform sampler2D tSpec;  //
    uniform sampler2D tOcc; //

    uniform float uNormalScale; //

    varying vec3 vTangent;
    varying vec3 vBinormal;
    varying vec3 vNormal;
    varying vec2 vUv;

    varying vec3 vPointLightVector;
    varying vec3 vViewPosition;
    
    void main() {

      vec3 diffuseTex     = texture2D( tDiffuse, vUv ).xyz;
      
      vec3 normalTex      = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;
      mat3 tsb            = mat3( vTangent, vBinormal, vNormal );
      vec3 viewPosition   = normalize( vViewPosition );
      
      // toggle these lines depending on whether you're using a normal texture:
      
      //vec3 finalNormal    = tsb * normalTex.rgb;       // works with tNormal
      vec3 finalNormal       = vec3( vNormal );           // works without tNormal

      
      // toggle these lines for hard normal recaculation:
      
      // vec3 normal         = normalize( finalNormal );  // original; light position is correct, but normals ignore displacement
      vec3 normal = normalize( cross( dFdx( vViewPosition ), dFdy( vViewPosition ) ) );    // from webgl_cubes_indexed demo; normals recaculated post-displacement, hard only

      
      // point light

      vec4 pointDiffuse           = vec4( 0.0, 0.0, 0.0, 0.0 );
      vec4 pointSpecular          = vec4( 0.0, 0.0, 0.0, 0.0 ); //
      
      vec3 pointVector            = normalize( vPointLightVector );
      vec3 pointHalfVector        = normalize( vPointLightVector - vViewPosition );

      float pointDotNormalHalf    = dot( normal, pointHalfVector );  //
      float pointDiffuseWeight    = max( dot( normal * 2.0, pointVector ), 0.0 );

      float pointSpecularWeight   = 0.0;  //
      if ( pointDotNormalHalf >= 0.0 )    pointSpecularWeight = pow( pointDotNormalHalf, 60.0 );  // no spectex

      pointDiffuse               += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;
      pointSpecular              += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight; //

      // all lights contribution summation

      vec4 totalLight             = vec4( uAmbientLightColor * uAmbientColor , 1.0 );
      totalLight                 += vec4( uPointLightColor, 1.0 ) * ( pointDiffuse + pointSpecular );

      gl_FragColor = vec4( totalLight.xyz, 1.0 );
                    
    }
  </script>
    
    

{'fraction_non_alphanumeric': 0.09482758620689655, 'fraction_numerical': 0.02397938961553706, 'mean_word_length': 2.193987341772152, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2036012', 'n_tokens_mistral': 3254, 'n_tokens_neox': 3036, 'n_words': 806}