Created
January 19, 2016 14:48
-
-
Save Makio64/739a54ba67bbeceb3b23 to your computer and use it in GitHub Desktop.
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
Stage3d = require('makio/core/Stage3d') | |
class FBO | |
constructor:( width, height, @renderer, @simulation )-> | |
#---------------------------------------------------------------------------------------- Create Render | |
options = { | |
wrapS: THREE.RepeatWrapping | |
wrapT: THREE.RepeatWrapping | |
minFilter: THREE.NearestFilter | |
magFilter: THREE.NearestFilter | |
format: THREE.RGBFormat | |
type: THREE.FloatType | |
stencilBuffer: true | |
depthBuffer: true | |
} | |
@rt = new THREE.WebGLRenderTarget(width, height, options) | |
@rt2 = new THREE.WebGLRenderTarget(width, height, options) | |
@rt3 = new THREE.WebGLRenderTarget(width, height, options) | |
#---------------------------------------------------------------------------------------- Create Scene | |
@scene = new THREE.Scene() | |
@orthoCamera = new THREE.OrthographicCamera( - 0.5, 0.5, 0.5, - 0.5, 0, 1 ) | |
@mesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 1, 1 ) ) | |
@scene.add( @mesh ) | |
@copy() | |
@mesh.material = @simulation | |
@debug() | |
return | |
#---------------------------------------------------------------------------------------- Update | |
update:(dt)=> | |
@renderer.render( @scene, @orthoCamera, @rt, false ) | |
tmp = @rt | |
@rt = @rt2 | |
@rt2 = @rt3 | |
@rt3 = tmp | |
@simulation.uniforms.t_pos.value = @rt3 | |
@simulation.uniforms.t_oPos.value = @rt2 | |
return | |
#---------------------------------------------------------------------------------------- Copy | |
copy:()=> | |
@mesh.material = new THREE.ShaderMaterial( | |
uniforms: { t_pos: { type: "t", value: @simulation.uniforms.t_pos.value } } | |
vertexShader: require( "fbo/copy.vs" ) | |
fragmentShader: require( "fbo/copy.fs" ) | |
) | |
@update() | |
@update() | |
@update() | |
return | |
#---------------------------------------------------------------------------------------- DEBUG | |
debug:()=> | |
@debug1 = new THREE.Mesh(new THREE.PlaneBufferGeometry( 200, 200 ), new THREE.MeshBasicMaterial(map:@rt)) | |
Stage3d.add(@debug1) | |
@debug2 = new THREE.Mesh(new THREE.PlaneBufferGeometry( 200, 200 ), new THREE.MeshBasicMaterial(map:@rt2)) | |
@debug2.position.x = 210 | |
Stage3d.add(@debug2) | |
debug3 = new THREE.Mesh(new THREE.PlaneBufferGeometry( 200, 200 ), new THREE.MeshBasicMaterial(map:@rt3)) | |
debug3.position.x = -210 | |
Stage3d.add(debug3) | |
return | |
module.exports = FBO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment