Sha256: 68dfcc6e8b5009ab5799c401ddd7d7300bb94160a2cbb651a57041410d350dfa

Contents?: true

Size: 1.69 KB

Versions: 4

Compression:

Stored size: 1.69 KB

Contents

(function (global, factory) {
  if (typeof define === "function" && define.amd) {
    define(["exports", "three"], factory);
  } else if (typeof exports !== "undefined") {
    factory(exports, require("three"));
  } else {
    var mod = {
      exports: {}
    };
    factory(mod.exports, global.three);
    global.NormalMapShader = mod.exports;
  }
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _three) {
  "use strict";

  Object.defineProperty(_exports, "__esModule", {
    value: true
  });
  _exports.NormalMapShader = void 0;

  /**
   * Normal map shader
   * - compute normals from heightmap
   */
  var NormalMapShader = {
    uniforms: {
      'heightMap': {
        value: null
      },
      'resolution': {
        value: new _three.Vector2(512, 512)
      },
      'scale': {
        value: new _three.Vector2(1, 1)
      },
      'height': {
        value: 0.05
      }
    },
    vertexShader:
    /* glsl */
    "\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",
    fragmentShader:
    /* glsl */
    "\n\n\t\tuniform float height;\n\t\tuniform vec2 resolution;\n\t\tuniform sampler2D heightMap;\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tfloat val = texture2D( heightMap, vUv ).x;\n\n\t\t\tfloat valU = texture2D( heightMap, vUv + vec2( 1.0 / resolution.x, 0.0 ) ).x;\n\t\t\tfloat valV = texture2D( heightMap, vUv + vec2( 0.0, 1.0 / resolution.y ) ).x;\n\n\t\t\tgl_FragColor = vec4( ( 0.5 * normalize( vec3( val - valU, val - valV, height  ) ) + 0.5 ), 1.0 );\n\n\t\t}"
  };
  _exports.NormalMapShader = NormalMapShader;
});

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
opal-js_wrap-three-0.1.5 lib-opal/js_wrap/three/shaders/NormalMapShader.js
opal-js_wrap-three-0.1.4 lib-opal/js_wrap/three/shaders/NormalMapShader.js
opal-js_wrap-three-0.1.3 lib-opal/js_wrap/three/shaders/NormalMapShader.js
opal-js_wrap-three-0.1.2 lib-opal/js_wrap/three/shaders/NormalMapShader.js