Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renderers: move to es6 class syntax #19008

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 63 additions & 100 deletions src/renderers/WebGLCubeRenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,116 +12,79 @@ import { CubeCamera } from '../cameras/CubeCamera.js';
* @author WestLangley / http://github.com/WestLangley
*/

function WebGLCubeRenderTarget( size, options, dummy ) {
class WebGLCubeRenderTarget extends WebGLRenderTarget {

if ( Number.isInteger( options ) ) {
constructor( size, options, dummy ) {

console.warn( 'THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )' );
if ( Number.isInteger( options ) ) {

options = dummy;
console.warn( 'THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )' );
options = dummy;

}
super( size, size, options );

}

WebGLRenderTarget.call( this, size, size, options );
fromEquirectangularTexture( renderer, texture ) {

this.texture.type = texture.type;
this.texture.format = texture.format;
this.texture.encoding = texture.encoding;
var scene = new Scene();
var shader = {
uniforms: {
tEquirect: { value: null },
},
vertexShader: [
"varying vec3 vWorldDirection;",
"vec3 transformDirection( in vec3 dir, in mat4 matrix ) {",
" return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );",
"}",
"void main() {",
" vWorldDirection = transformDirection( position, modelMatrix );",
" #include <begin_vertex>",
" #include <project_vertex>",
"}"
].join( '\n' ),
fragmentShader: [
"uniform sampler2D tEquirect;",
"varying vec3 vWorldDirection;",
"#define RECIPROCAL_PI 0.31830988618",
"#define RECIPROCAL_PI2 0.15915494",
"void main() {",
" vec3 direction = normalize( vWorldDirection );",
" vec2 sampleUV;",
" sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;",
" sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
" gl_FragColor = texture2D( tEquirect, sampleUV );",
"}"
].join( '\n' ),
};
var material = new ShaderMaterial( {
type: 'CubemapFromEquirect',
uniforms: cloneUniforms( shader.uniforms ),
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader,
side: BackSide,
blending: NoBlending
} );
material.uniforms.tEquirect.value = texture;
var mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material );
scene.add( mesh );
var camera = new CubeCamera( 1, 10, 1 );
camera.renderTarget = this;
camera.renderTarget.texture.name = 'CubeCameraTexture';
camera.update( renderer, scene );
mesh.geometry.dispose();
mesh.material.dispose();
return this;

}
}

WebGLCubeRenderTarget.prototype = Object.create( WebGLRenderTarget.prototype );
WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
}

WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;

WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer, texture ) {

this.texture.type = texture.type;
this.texture.format = texture.format;
this.texture.encoding = texture.encoding;

var scene = new Scene();

var shader = {

uniforms: {
tEquirect: { value: null },
},

vertexShader: [

"varying vec3 vWorldDirection;",

"vec3 transformDirection( in vec3 dir, in mat4 matrix ) {",

" return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );",

"}",

"void main() {",

" vWorldDirection = transformDirection( position, modelMatrix );",

" #include <begin_vertex>",
" #include <project_vertex>",

"}"

].join( '\n' ),

fragmentShader: [

"uniform sampler2D tEquirect;",

"varying vec3 vWorldDirection;",

"#define RECIPROCAL_PI 0.31830988618",
"#define RECIPROCAL_PI2 0.15915494",

"void main() {",

" vec3 direction = normalize( vWorldDirection );",

" vec2 sampleUV;",

" sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;",

" sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",

" gl_FragColor = texture2D( tEquirect, sampleUV );",

"}"

].join( '\n' ),
};

var material = new ShaderMaterial( {

type: 'CubemapFromEquirect',

uniforms: cloneUniforms( shader.uniforms ),
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader,
side: BackSide,
blending: NoBlending

} );

material.uniforms.tEquirect.value = texture;

var mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material );

scene.add( mesh );

var camera = new CubeCamera( 1, 10, 1 );

camera.renderTarget = this;
camera.renderTarget.texture.name = 'CubeCameraTexture';

camera.update( renderer, scene );

mesh.geometry.dispose();
mesh.material.dispose();

return this;

};

export { WebGLCubeRenderTarget };
23 changes: 10 additions & 13 deletions src/renderers/WebGLMultisampleRenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,28 @@ import { WebGLRenderTarget } from './WebGLRenderTarget.js';
* @author Matt DesLauriers / @mattdesl
*/

function WebGLMultisampleRenderTarget( width, height, options ) {
class WebGLMultisampleRenderTarget extends WebGLRenderTarget {

WebGLRenderTarget.call( this, width, height, options );
constructor( width, height, options ) {

this.samples = 4;
super( width, height, options );
this.samples = 4;

}

WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {

constructor: WebGLMultisampleRenderTarget,

isWebGLMultisampleRenderTarget: true,
}

copy: function ( source ) {
copy( source ) {

WebGLRenderTarget.prototype.copy.call( this, source );
super().copy( source );

this.samples = source.samples;

return this;

}

} );
}

WebGLMultisampleRenderTarget.prototype.isWebGLMultisampleRenderTarget = true;


export { WebGLMultisampleRenderTarget };
60 changes: 30 additions & 30 deletions src/renderers/WebGLRenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,44 @@ import { Vector4 } from '../math/Vector4.js';
* @author alteredq / http://alteredqualia.com/
* @author Marius Kintel / https://github.com/kintel
*/

/*
In options, we can specify:
* Texture parameters for an auto-generated target texture
* depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
*/
function WebGLRenderTarget( width, height, options ) {

this.width = width;
this.height = height;
class WebGLRenderTarget extends EventDispatcher {

this.scissor = new Vector4( 0, 0, width, height );
this.scissorTest = false;
constructor( width, height, options ) {

this.viewport = new Vector4( 0, 0, width, height );
super();

options = options || {};
this.width = width;
this.height = height;

this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
this.scissor = new Vector4( 0, 0, width, height );
this.scissorTest = false;

this.texture.image = {};
this.texture.image.width = width;
this.texture.image.height = height;
this.viewport = new Vector4( 0, 0, width, height );

this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
options = options || {};

this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
this.texture.image = {};
this.texture.image.width = width;
this.texture.image.height = height;
this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;

}
this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;

WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;

constructor: WebGLRenderTarget,
this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;

isWebGLRenderTarget: true,
}

setSize: function ( width, height ) {
setSize( width, height ) {

if ( this.width !== width || this.height !== height ) {

Expand All @@ -64,15 +62,15 @@ WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prot
this.viewport.set( 0, 0, width, height );
this.scissor.set( 0, 0, width, height );

},
}

clone: function () {
clone() {

return new this.constructor().copy( this );
return new WebGLRenderTarget().copy( this );

},
}

copy: function ( source ) {
copy( source ) {

this.width = source.width;
this.height = source.height;
Expand All @@ -87,15 +85,17 @@ WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prot

return this;

},
}

dispose: function () {
dispose() {

this.dispatchEvent( { type: 'dispose' } );

}

} );
}

WebGLRenderTarget.prototype.isWebGLRenderTarget = true;


export { WebGLRenderTarget };
Loading