Created
June 19, 2018 20:48
-
-
Save neiltron/ed64ed7f0dd676937ec8b408baa775c8 to your computer and use it in GitHub Desktop.
Feedback Pass for THREE.EffectComposer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Pass, RenderPass } from 'postprocessing'; | |
const glslify = require('glslify'); | |
const path = require('path'); | |
export default class FeedbackPass extends Pass { | |
constructor() { | |
super("FeedbackPass"); | |
this.time = 0; | |
this.lastUpdate = 0; | |
this.bufferTexture = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter}); | |
this.bufferTexture2 = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter}); | |
this.renderPassLastBuffer = new RenderPass(this.scene, this.camera); | |
this.quad.material = new THREE.ShaderMaterial({ | |
vertexShader: glslify(path.resolve(__dirname, '../shaders/noise.vert')), | |
fragmentShader: glslify(path.resolve(__dirname, '../shaders/noise.frag')), | |
uniforms: { | |
time: { value: 0 }, | |
texture: { value: this.bufferTexture.texture, type: 't' }, | |
texture2: { value: null, type: 't' } | |
} | |
}); | |
} | |
render(renderer, inputBuffer, outputBuffer, delta, stencilTest) { | |
this.time += delta; | |
this.quad.material.uniforms.time.value = this.time; | |
this.quad.material.uniforms.texture2.value = inputBuffer.texture; | |
renderer.render(this.scene, this.camera, this.bufferTexture2); | |
var a = this.bufferTexture2; | |
this.bufferTexture2 = this.bufferTexture; | |
this.bufferTexture = a; | |
this.quad.material.uniforms.texture.value = this.bufferTexture.texture; | |
renderer.render(this.scene, this.camera, this.renderToScreen ? null : outputBuffer); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma glslify: snoise3 = require(glsl-noise/simplex/3d) | |
varying vec3 pos; | |
uniform sampler2D texture; | |
uniform sampler2D texture2; | |
uniform float time; | |
void main () { | |
vec2 texCoord = .5 + pos.xy * .5; | |
vec3 color = texture2D(texture, texCoord).rgb; | |
color = texture2D(texture, texCoord + snoise3(pos.xyx + time) / (100. / color.r)).rgb; | |
vec3 color2 = texture2D(texture2, texCoord).rgb; | |
gl_FragColor = vec4(color * .98 + color2 * .5, 1.0); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
varying vec3 pos; | |
void main () { | |
pos = position.xyz; | |
gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment