three#DataTexture JavaScript Examples

The following examples show how to use three#DataTexture. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlitchPass.js    From Computer-Graphics with MIT License 7 votes vote down vote up
generateHeightmap( dt_size ) {

		const data_arr = new Float32Array( dt_size * dt_size );
		const length = dt_size * dt_size;

		for ( let i = 0; i < length; i ++ ) {

			const val = MathUtils.randFloat( 0, 1 );
			data_arr[ i ] = val;

		}

		const texture = new DataTexture( data_arr, dt_size, dt_size, RedFormat, FloatType );
		texture.needsUpdate = true;
		return texture;

	}
Example #2
Source File: SSAOPass.js    From Computer-Graphics with MIT License 6 votes vote down vote up
generateRandomKernelRotations() {

		const width = 4, height = 4;

		if ( SimplexNoise === undefined ) {

			console.error( 'THREE.SSAOPass: The pass relies on SimplexNoise.' );

		}

		const simplex = new SimplexNoise();

		const size = width * height;
		const data = new Float32Array( size );

		for ( let i = 0; i < size; i ++ ) {

			const x = ( Math.random() * 2 ) - 1;
			const y = ( Math.random() * 2 ) - 1;
			const z = 0;

			data[ i ] = simplex.noise3d( x, y, z );

		}

		this.noiseTexture = new DataTexture( data, width, height, RedFormat, FloatType );
		this.noiseTexture.wrapS = RepeatWrapping;
		this.noiseTexture.wrapT = RepeatWrapping;
		this.noiseTexture.needsUpdate = true;

	}
Example #3
Source File: Body.js    From sketch-webcam with MIT License 6 votes vote down vote up
updateSegmentation(segmentation) {
    const texture = this.material.uniforms.segmentation;
    if (texture.value === null) {
      texture.value = new DataTexture(
        segmentation.data,
        segmentation.width,
        segmentation.height,
        LuminanceFormat,
        UnsignedByteType
      );
      texture.value.magFilter = NearestFilter;
      texture.value.minFilter = NearestFilter;
    } else {
      texture.value.image.data.set(segmentation.data);
    }
    texture.value.needsUpdate = true;
  }
Example #4
Source File: Glitchpass.js    From r3f-website with MIT License 5 votes vote down vote up
GlitchPass.prototype = Object.assign(Object.create(Pass.prototype), {
  constructor: GlitchPass,

  render: function(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
    const factor = Math.max(0, this.factor)
    this.uniforms['tDiffuse'].value = readBuffer.texture
    this.uniforms['seed'].value = Math.random() * factor //default seeding
    this.uniforms['byp'].value = 0
    if (factor) {
      this.uniforms['amount'].value = (Math.random() / 90) * factor
      this.uniforms['angle'].value = _Math.randFloat(-Math.PI, Math.PI) * factor
      this.uniforms['distortion_x'].value = _Math.randFloat(0, 1) * factor
      this.uniforms['distortion_y'].value = _Math.randFloat(0, 1) * factor
      this.uniforms['seed_x'].value = _Math.randFloat(-0.3, 0.3) * factor
      this.uniforms['seed_y'].value = _Math.randFloat(-0.3, 0.3) * factor
    } else this.uniforms['byp'].value = 1
    this.quad.material = this.material
    if (this.renderToScreen) {
      renderer.setRenderTarget(null)
      renderer.render(this.scene, this.camera)
    } else {
      renderer.setRenderTarget(writeBuffer)
      if (this.clear) renderer.clear()
      renderer.render(this.scene, this.camera)
    }
  },

  generateHeightmap: function(dt_size) {
    var data_arr = new Float32Array(dt_size * dt_size * 3)
    var length = dt_size * dt_size

    for (var i = 0; i < length; i++) {
      var val = _Math.randFloat(0, 1)
      data_arr[i * 3 + 0] = val
      data_arr[i * 3 + 1] = val
      data_arr[i * 3 + 2] = val
    }

    var texture = new DataTexture(data_arr, dt_size, dt_size, RGBFormat, FloatType)
    texture.needsUpdate = true
    return texture
  }
})