Texture Glow ***************************************** based in https://catlikecoding.com/unity/tutorials/advanced-rendering/bloom/
500609
function LGraphTextureGlow() {
            this.addInput("in", "Texture");
            this.addInput("dirt", "Texture");
            this.addOutput("out", "Texture");
            this.addOutput("glow", "Texture");
            this.properties = {
                enabled: true,
                intensity: 1,
                persistence: 0.99,
                iterations: 16,
                threshold: 0,
                scale: 1,
                dirt_factor: 0.5,
                precision: LGraphTexture.DEFAULT
            };
            this._textures = [];
            this._uniforms = {
                u_intensity: 1,
                u_texture: 0,
                u_glow_texture: 1,
                u_threshold: 0,
                u_texel_size: vec2.create()
            };
        }
78041
function SpriteMaskFilter(sprite)
{
    var maskMatrix = new math.Matrix();

    AbstractFilter.call(this,
        fs.readFileSync(__dirname + '/spriteMaskFilter.vert', 'utf8'),
        fs.readFileSync(__dirname + '/spriteMaskFilter.frag', 'utf8'),
        {
            mask:           { type: 'sampler2D', value: sprite._texture },
            alpha:          { type: 'f', value: 1},
            otherMatrix:    { type: 'mat3', value: maskMatrix.toArray(true) }
        }
    );

    this.maskSprite = sprite;
    this.maskMatrix = maskMatrix;
}
89989
function ( materialNode, textureMap, ID ) {

			var parameters = {};

			if ( materialNode.BumpFactor ) {

				parameters.bumpScale = materialNode.BumpFactor.value;

			}
			if ( materialNode.Diffuse ) {

				parameters.color = new THREE.Color().fromArray( materialNode.Diffuse.value );

			} else if ( materialNode.DiffuseColor && materialNode.DiffuseColor.type === 'Color' ) {

				// The blender exporter exports diffuse here instead of in materialNode.Diffuse
				parameters.color = new THREE.Color().fromArray( materialNode.DiffuseColor.value );

			}
			if ( materialNode.DisplacementFactor ) {

				parameters.displacementScale = materialNode.DisplacementFactor.value;

			}
			if ( materialNode.Emissive ) {

				parameters.emissive = new THREE.Color().fromArray( materialNode.Emissive.value );

			} else if ( materialNode.EmissiveColor && materialNode.EmissiveColor.type === 'Color' ) {

				// The blender exporter exports emissive color here instead of in materialNode.Emissive
				parameters.emissive = new THREE.Color().fromArray( materialNode.EmissiveColor.value );

			}
			if ( materialNode.EmissiveFactor ) {

				parameters.emissiveIntensity = parseFloat( materialNode.EmissiveFactor.value );

			}
			if ( materialNode.Opacity ) {

				parameters.opacity = parseFloat( materialNode.Opacity.value );

			}
			if ( parameters.opacity < 1.0 ) {

				parameters.transparent = true;

			}
			if ( materialNode.ReflectionFactor ) {

				parameters.reflectivity = materialNode.ReflectionFactor.value;

			}
			if ( materialNode.Shininess ) {

				parameters.shininess = materialNode.Shininess.value;

			}
			if ( materialNode.Specular ) {

				parameters.specular = new THREE.Color().fromArray( materialNode.Specular.value );

			} else if ( materialNode.SpecularColor && materialNode.SpecularColor.type === 'Color' ) {

				// The blender exporter exports specular color here instead of in materialNode.Specular
				parameters.specular = new THREE.Color().fromArray( materialNode.SpecularColor.value );

			}

			var self = this;
			connections.get( ID ).children.forEach( function ( child ) {

				var type = child.relationship;

				switch ( type ) {

					case 'Bump':
						parameters.bumpMap = self.getTexture( textureMap, child.ID );
						break;

					case 'DiffuseColor':
						parameters.map = self.getTexture( textureMap, child.ID );
						break;

					case 'DisplacementColor':
						parameters.displacementMap = self.getTexture( textureMap, child.ID );
						break;


					case 'EmissiveColor':
						parameters.emissiveMap = self.getTexture( textureMap, child.ID );
						break;

					case 'NormalMap':
						parameters.normalMap = self.getTexture( textureMap, child.ID );
						break;

					case 'ReflectionColor':
						parameters.envMap = self.getTexture( textureMap, child.ID );
						parameters.envMap.mapping = THREE.EquirectangularReflectionMapping;
						break;

					case 'SpecularColor':
						parameters.specularMap = self.getTexture( textureMap, child.ID );
						break;

					case 'TransparentColor':
						parameters.alphaMap = self.getTexture( textureMap, child.ID );
						parameters.transparent = true;
						break;

					case 'AmbientColor':
					case 'ShininessExponent': // AKA glossiness map
					case 'SpecularFactor': // AKA specularLevel
					case 'VectorDisplacementColor': // NOTE: Seems to be a copy of DisplacementColor
					default:
						console.warn( 'THREE.FBXLoader: %s map is not supported in three.js, skipping texture.', type );
						break;

				}

			} );

			return parameters;

		}
781106
function RenderTexture (opts) {
    RenderTexture.superclass.constructor.call(this, opts)

    var width = opts.width,
        height = opts.height

    evt.addPropertyListener(this, 'contentSize', 'change', this._resizeCanvas.bind(this))

    this.canvas = document.createElement('canvas')
    this.context = this.canvas.getContext('2d')

    var atlas = new TextureAtlas({canvas: this.canvas})
    this.sprite = new Sprite({textureAtlas: atlas, rect: {origin: ccp(0, 0), size: {width: width, height: height}}})

    this.contentSize = geo.sizeMake(width, height)
    this.addChild(this.sprite)
    this.anchorPoint = ccp(0, 0)
    this.sprite.anchorPoint = ccp(0, 0)

}
694713
function (xy, yz) { // function for pure rendering. No rendering elsewhere!!
    var CP = colorPicker.CP,
      cP = colorPicker.cP,
      a = 0,
      b = 0,
      c = 0,
      ctrDif, colDif, tmpHSV, nCtr, nrCtr, cPCtr, WS; // cP & CP = scope shifting
    // display all the nice colors in sliders
    if (xy) { // left slider -> right
      if (CP.xyz[0] > CP.xyz[1]) b = 1;
      else a = 1;
      if (CP.mode == 'S' || CP.mode == 'V') {
        cP.cPSR2s.backgroundColor = 'rgb(' + HSV2RGB(CP.xyz[0], 255, 255) + ')';
        b = 1;
        c = 255
      } else if (CP.mode != 'H' && !CP.modeRGB[CP.mode]) cP.cPSR2.className = 'cPSR' + (2 + a) + CP.mode + ' cPOP' + Math.round((CP.xyz[a] - CP.xyz[b]) / (255 - CP.xyz[b]) * 100 || 0);
      if (CP.mode != 'H' && !CP.modeRGB[CP.mode]) cP.cPSR3.className = 'cPSR4' + CP.mode + ' cPOP' + Math.round(Math.abs(c - CP.xyz[b]) / 2.55);
      cP.cPSLCs.cssText = 'left:' + (CP.xyz[0] / sX - 5) + 'px;top:' + Math.ceil(250 - CP.xyz[1] / sX / sZ - xyzCorr) + 'px'; // change cursor
    }
    if (!xy || yz) { // right slider -> left
      if (CP.mode == 'H') {
        tmpHSV = HSV2RGB(CP.xyz[2], 255, 255);
        cP.cPSL1s.backgroundColor = 'rgb(' + tmpHSV + ')'
      } else cP.cPSL3.className = 'cPSL3' + CP.mode + ' cPOP' + (100 - Math.round(CP.xyz[2] / 2.55));
      cP.cPSRCLs.top = c = +Math.ceil(252 - CP.xyz[2] / sX / sZ - xyzCorr) + 'px'; // change right-left cursor ... recycle var c
      if (yz) cP.cPSRCRs.top = c; // change right-right cursor
    }

    // switch brightness if contrast changes
    cPCtr = getBrightness(CP.rgbRND);
    nCtr = cPCtr > 128;
    if (cCtr !== nCtr) {
      if (nCtr) {
        if (expColor) cP.cObjs.color = '#222';
        cP.cPSLC.className = 'cPSLCB';
        CP.cPM0CN = 'cPM0 cPM0B';
        if (CP.mode != 'H' && !CP.modeRGB[CP.mode]) {
          cP.cPSRCL.className = 'cPSRCLB';
          if (xy) cP.cPSRCR.className = 'cPSRCRB'
        }
      } else {
        if (expColor) cP.cObjs.color = '#ddd';
        cP.cPSLC.className = 'cPSLCW';
        CP.cPM0CN = 'cPM0';
        if (CP.mode != 'H' && !CP.modeRGB[CP.mode]) {
          cP.cPSRCL.className = 'cPSRCLW';
          if (xy) cP.cPSRCR.className = 'cPSRCRW'
        }
      }
    }
    cCtr = nCtr;
    if (!xy || yz) { // only right
      if (CP.modeRGB[CP.mode]) {
        nrCtr = CP.xyz[2] > 153;
        if (crCtr !== nrCtr) { // RGB special mode
          if (nrCtr && CP.mode == 'G') {
            cP.cPSRCL.className = 'cPSRCLB';
            if (xy) cP.cPSRCR.className = 'cPSRCRB';
          } else {
            cP.cPSRCL.className = 'cPSRCLW';
            if (xy) cP.cPSRCR.className = 'cPSRCRW'
          }
        }
      } else if (CP.mode == 'H') { // HSB_H mode extra rules
        nrCtr = getBrightness(tmpHSV || HSV2RGB(CP.hsv[0], 255, 255)) > 128;
        if (crCtr !== nrCtr) {
          if (nrCtr) cP.cPSRCL.className = 'cPSRCLB';
          else cP.cPSRCL.className = 'cPSRCLW'
        }
      }
      crCtr = nrCtr;
    }

    // display brightness/color match bar
    colDif = getColorDifference(CP.CB2Color, CP.rgb) / 765 * difWidth; // 765 = 3 colors * 255 possible values
    ctrDif = Math.abs((cPCtr - CP.iCtr) / 255 * difWidth);
    cP.cPCTRTs.cssText = 'width:' + ctrDif + 'px;' + ((colDif > ctrDif) ? cP.CTRTop : '');
    cP.cPCDs.cssText = 'width:' + colDif + 'px;' + ((ctrDif < difWidth / 2 && colDif < difWidth / 3 * 2) ? '' : ((ctrDif < difWidth / 2 || colDif < difWidth / 3 * 2) ? cP.cPCD1 : cP.cPCD2));

    // display color values // this also touches the DOM
    cP.cPIR.value = CP.rgbRND[0];
    cP.cPIG.value = CP.rgbRND[1];
    cP.cPIB.value = CP.rgbRND[2];
    cP.cPIH.value = Math.round(CP.hsv[0] / 255 * 360);
    cP.cPIS.value = Math.round(CP.hsv[1] / 2.55);
    cP.cPIV.value = Math.round(CP.hsv[2] / 2.55);
    cP.cPIC.value = CP.cmyk[0];
    cP.cPIM.value = CP.cmyk[1];
    cP.cPIY.value = CP.cmyk[2];
    cP.cPIK.value = CP.cmyk[3];
    cP.cPIX.value = CP.hex;

    // display WEBSave/WEBSmart/otherColor button
    WS = (CP.rgbRND[0] % 51 == 0 && CP.rgbRND[1] % 51 == 0 && CP.rgbRND[2] % 51 == 0) ? 'W' : (CP.rgbRND[0] % 17 == 0 && CP.rgbRND[1] % 17 == 0 && CP.rgbRND[2] % 17 == 0) ? 'M' : '!';
    if (WS != CP.WS) cP.cPBRX.firstChild.data = CP.WS = WS;

    // display value/color in initField swatch and left/background
    cP.cPCB1s.backgroundColor = 'rgb(' + CP.rgbRND + ')';
    if (expColor) cP.cObjs.backgroundColor = 'rgb(' + CP.rgbRND + ')';
    if (expHEX) cP.cObj.value = CP.valPrefix + CP.hex;
    if (CP.bd) document.body.style.background = 'rgb(' + CP.rgbRND + ')';

    if (colorPicker.exportColor) colorPicker.exportColor();
    if (xy && yz) { // stopRender
      cP.cPSRCR.className = cP.cPSRCL.className.replace('L', 'R'); // ;o)
      cP.cPM0s.backgroundColor = 'rgb(' + CP.rgbRND + ')';
      if (CP.cPM0CN) {
        cP.cPM0.className = CP.cPM0CN;
        CP.cPM0CN = ''
      }
    }
  }
1188611
function LGraphTextureBlur() {
            this.addInput("Texture", "Texture");
            this.addInput("Iterations", "number");
            this.addInput("Intensity", "number");
            this.addOutput("Blurred", "Texture");
            this.properties = {
                intensity: 1,
                iterations: 1,
                preserve_aspect: false,
                scale: [1, 1],
                precision: LGraphTexture.DEFAULT
            };
        }
1296526
private void renderDot( int cx , int cy , float Z , int rgb ) {
		for (int i = -dotRadius; i <= dotRadius; i++) {
			int y = cy+i;
			if( y < 0 || y >= imageRgb.height )
				continue;
			for (int j = -dotRadius; j <= dotRadius; j++) {
				int x = cx+j;
				if( x < 0 || x >= imageRgb.width )
					continue;

				int pixelIndex = imageDepth.getIndex(x,y);
				float depth = imageDepth.data[pixelIndex];
				if( depth > Z ) {
					imageDepth.data[pixelIndex] = Z;
					imageRgb.data[pixelIndex] = rgb;
				}
			}
		}
	}
495723
function(unit) {
    gl.activeTexture(gl.TEXTURE0 + (unit || 0));
    gl.bindTexture(gl.TEXTURE_2D, this.id);
  }
653422
function bindTextureToFramebuffer(gl, fbo, texture) {
  gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
  gl.bindTexture(gl.TEXTURE_2D, texture);

  gl.texImage2D(
    gl.TEXTURE_2D,
    0,
    gl.RGBA,
    fbo.width,
    fbo.height,
    0,
    gl.RGBA,
    gl.UNSIGNED_BYTE,
    null
  );

  gl.framebufferTexture2D(
    gl.FRAMEBUFFER,
    gl.COLOR_ATTACHMENT0,
    gl.TEXTURE_2D,
    texture,
    0
  );

  // Check fbo status
  const fbs = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
  if (fbs !== gl.FRAMEBUFFER_COMPLETE) {
    console.log('ERROR: There is a problem with the framebuffer:', fbs);
  }

  // Clear the bindings we created in this function.
  gl.bindTexture(gl.TEXTURE_2D, null);
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
}
348456
function(x, y, tileData){
            var light = this.ambientLight;
            var lighting = this.get(x, y);

            var overlay = function(c1, c2){
                var out = c1.slice();
                for (var i = 0; i < 3; i++) {
                    var a = c1[i],
                        b = c2[i];
                    if(b < 128){
                        out[i] = Math.round(2 * a * b / 255);
                    } else {
                        out[i] = Math.round(255 - 2 * (255 - a) * (255 - b) / 255);
                    }
                }
                return out;
            };

            if(lighting){
                light = ROT.Color.add(this.ambientLight, lighting);
            }

            if(tileData.color){
                var color = ROT.Color.fromString(tileData.color);
                color = overlay(light, color);
                tileData.color = ROT.Color.toRGB(color);
            }

            if(tileData.bgColor){
                var bgColor = ROT.Color.fromString(tileData.bgColor);
                bgColor = overlay(light, bgColor);
                tileData.bgColor = ROT.Color.toRGB(bgColor);
            }
            return tileData;
        }
546085
function brightColor(layerId, alpha) {
  var luminosity = 'bright';
  var hue = null;

  if (/water|ocean|lake|sea|river/.test(layerId)) {
    hue = 'blue';
  }

  if (/state|country|place/.test(layerId)) {
    hue = 'pink';
  }

  if (/road|highway|transport/.test(layerId)) {
    hue = 'orange';
  }

  if (/contour|building/.test(layerId)) {
    hue = 'monochrome';
  }

  if (/building/.test(layerId)) {
    luminosity = 'dark';
  }

  if (/contour|landuse/.test(layerId)) {
    hue = 'yellow';
  }

  if (/wood|forest|park|landcover/.test(layerId)) {
    hue = 'green';
  }

  var rgb = randomColor({
    luminosity: luminosity,
    hue: hue,
    seed: layerId,
    format: 'rgbArray'
  });

  var rgba = rgb.concat([alpha || 1]);
  return 'rgba(' + rgba.join(', ') + ')';
}
616990
function LGraphTextureDepthRange() {
            this.addInput("Texture", "Texture");
            this.addInput("Distance", "number");
            this.addInput("Range", "number");
            this.addOutput("Texture", "Texture");
            this.properties = {
                distance: 100,
                range: 50,
                only_depth: false,
                high_precision: false
            };
            this._uniforms = {
                u_texture: 0,
                u_distance: 100,
                u_range: 50,
                u_camera_planes: null
            };
        }
181548
function LGraphTextureLUT() {
            this.addInput("Texture", "Texture");
            this.addInput("LUT", "Texture");
            this.addInput("Intensity", "number");
            this.addOutput("", "Texture");
            this.properties = {
                intensity: 1,
                precision: LGraphTexture.DEFAULT,
                texture: null
            };

            if (!LGraphTextureLUT._shader) {
                LGraphTextureLUT._shader = new GL.Shader(
                    Shader.SCREEN_VERTEX_SHADER,
                    LGraphTextureLUT.pixel_shader
                );
            }
        }
1249390
function (texture, attachment, target) {

        if (!texture.width) {
            throw new Error('The texture attached to color buffer is not a valid.');
        }
        // TODO width and height check

        // If the depth_texture extension is enabled, developers
        // Can attach a depth texture to the depth buffer
        // http://blog.tojicode.com/2012/07/using-webgldepthtexture.html
        attachment = attachment || GL_COLOR_ATTACHMENT0;
        target = target || glenum.TEXTURE_2D;

        var boundRenderer = this._boundRenderer;
        var _gl = boundRenderer && boundRenderer.gl;
        var attachedTextures;

        if (_gl) {
            var cache = this._cache;
            cache.use(boundRenderer.__uid__);
            attachedTextures = cache.get('attached_textures');
        }

        // Check if texture attached
        var previous = this._textures[attachment];
        if (previous && previous.target === target
            && previous.texture === texture
            && (attachedTextures && attachedTextures[attachment] != null)
        ) {
            return;
        }

        var canAttach = true;
        if (boundRenderer) {
            canAttach = this._doAttach(boundRenderer, texture, attachment, target);
            // Set viewport again incase attached to different size textures.
            if (!this.viewport) {
                boundRenderer.setViewport(0, 0, texture.width, texture.height, 1);
            }
        }

        if (canAttach) {
            this._textures[attachment] = this._textures[attachment] || {};
            this._textures[attachment].texture = texture;
            this._textures[attachment].target = target;
        }
    }
27358
function FrameBuffer(gl, width, height, options) {
		var frameBuffer,
			renderBuffer,
			tex,
			status,
			useFloat = options === true ? options : (options && options.useFloat);

		useFloat = false;//useFloat && !!gl.getExtension("OES_texture_float"); //useFloat is not ready!
		if (useFloat) {
			this.type = gl.FLOAT;
		} else {
			this.type = gl.UNSIGNED_BYTE;
		}

		frameBuffer = gl.createFramebuffer();
		gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);

		if (options && options.texture) {
			this.texture = options.texture;
			gl.bindTexture(gl.TEXTURE_2D, this.texture);
			this.ownTexture = false;
		} else {
			this.texture = gl.createTexture();
			gl.bindTexture(gl.TEXTURE_2D, this.texture);
			gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
			gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
			gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
			gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
			this.ownTexture = true;
		}

		try {
			if (this.type === gl.FLOAT) {
				tex = new Float32Array(width * height * 4);
				gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.FLOAT, tex);
			} else {
				gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
				this.type = gl.UNSIGNED_BYTE;
			}
		} catch (e) {
			// Null rejected
			this.type = gl.UNSIGNED_BYTE;
			tex = new Uint8Array(width * height * 4);
			gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, tex);
		}

		renderBuffer = gl.createRenderbuffer();
		gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
		gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
		gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderBuffer);

		gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0);

		status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);

		if (status === gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
			throw('Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT');
		}

		if (status === gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
			throw('Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT');
		}

		if (status === gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS) {
			throw('Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS');
		}

		if (status === gl.FRAMEBUFFER_UNSUPPORTED) {
			throw('Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED');
		}

		if (status !== gl.FRAMEBUFFER_COMPLETE) {
			throw('Incomplete framebuffer: ' + status);
		}

		//clean up
		gl.bindTexture(gl.TEXTURE_2D, null);
		gl.bindRenderbuffer(gl.RENDERBUFFER, null);
		gl.bindFramebuffer(gl.FRAMEBUFFER, null);

		this.gl = gl;
		this.frameBuffer = frameBuffer;
		this.renderBuffer = renderBuffer;
		this.width = width;
		this.height = height;
	}
1357118
function LGraphTextureChannels() {
            this.addInput("Texture", "Texture");

            this.addOutput("R", "Texture");
            this.addOutput("G", "Texture");
            this.addOutput("B", "Texture");
            this.addOutput("A", "Texture");

            this.properties = { use_luminance: true };
            if (!LGraphTextureChannels._shader) {
                LGraphTextureChannels._shader = new GL.Shader(
                    Shader.SCREEN_VERTEX_SHADER,
                    LGraphTextureChannels.pixel_shader
                );
            }
        }
517424
function colorBlend(mode, color1, color2) {
    var ab = color1.alpha, cb, // backdrop
        as = color2.alpha, cs, // source
        ar, cr, r = [];        // result

    ar = as + ab * (1 - as);
    for (var i = 0; i < 3; i++) {
        cb = color1.rgb[i] / 255;
        cs = color2.rgb[i] / 255;
        cr = mode(cb, cs);
        if (ar) {
            cr = (as * cs + ab * (cb
                - as * (cb + cs - cr))) / ar;
        }
        r[i] = cr * 255;
    }

    return new(tree.Color)(r, ar);
}