Skip to content
Merged
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
45 changes: 32 additions & 13 deletions examples/webgl_mirror.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@
import { OrbitControls } from './jsm/controls/OrbitControls.js';
import { Reflector } from './jsm/objects/Reflector.js';

// scene size
const WIDTH = window.innerWidth;
const HEIGHT = window.innerHeight;

// camera
const VIEW_ANGLE = 45;
const ASPECT = WIDTH / HEIGHT;
let aspect = window.innerWidth / window.innerHeight;
const NEAR = 1;
const FAR = 500;

Expand All @@ -43,6 +39,8 @@

let sphereGroup, smallSphere;

let groundMirror, verticalMirror;

init();
animate();

Expand All @@ -53,14 +51,14 @@
// renderer
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( WIDTH, HEIGHT );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );

// scene
scene = new THREE.Scene();

// camera
camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR );
camera = new THREE.PerspectiveCamera( VIEW_ANGLE, aspect, NEAR, FAR );
camera.position.set( 0, 75, 160 );

cameraControls = new OrbitControls( camera, renderer.domElement );
Expand All @@ -78,21 +76,21 @@
let geometry, material;

geometry = new THREE.CircleGeometry( 40, 64 );
const groundMirror = new Reflector( geometry, {
groundMirror = new Reflector( geometry, {
clipBias: 0.003,
textureWidth: WIDTH * window.devicePixelRatio,
textureHeight: HEIGHT * window.devicePixelRatio,
textureWidth: window.innerWidth * window.devicePixelRatio,
textureHeight: window.innerHeight * window.devicePixelRatio,
color: 0x777777
} );
groundMirror.position.y = 0.5;
groundMirror.rotateX( - Math.PI / 2 );
scene.add( groundMirror );

geometry = new THREE.PlaneGeometry( 100, 100 );
const verticalMirror = new Reflector( geometry, {
verticalMirror = new Reflector( geometry, {
clipBias: 0.003,
textureWidth: WIDTH * window.devicePixelRatio,
textureHeight: HEIGHT * window.devicePixelRatio,
textureWidth: window.innerWidth * window.devicePixelRatio,
textureHeight: window.innerHeight * window.devicePixelRatio,
color: 0x889999
} );
verticalMirror.position.y = 50;
Expand Down Expand Up @@ -168,6 +166,27 @@
blueLight.position.set( 0, 50, 550 );
scene.add( blueLight );

window.addEventListener( "resize", onWindowResize, false );

}

function onWindowResize() {

aspect = window.innerWidth / window.innerHeight;
camera.aspect = aspect;
camera.updateProjectionMatrix();

renderer.setSize( window.innerWidth, window.innerHeight );

groundMirror.getRenderTarget().setSize(
window.innerWidth * window.devicePixelRatio,
window.innerHeight * window.devicePixelRatio
);
verticalMirror.getRenderTarget().setSize(
window.innerWidth * window.devicePixelRatio,
window.innerHeight * window.devicePixelRatio
);

}

function animate() {
Expand Down
49 changes: 39 additions & 10 deletions examples/webgl_mirror_nodes.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@
NormalMapNode,
} from './jsm/nodes/Nodes.js';

// scene size
const WIDTH = window.innerWidth;
const HEIGHT = window.innerHeight;

// camera
const VIEW_ANGLE = 45;
const ASPECT = WIDTH / HEIGHT;
let aspect = window.innerWidth / window.innerHeight;
const NEAR = 1;
const FAR = 500;

Expand All @@ -68,18 +64,21 @@

const frame = new NodeFrame();

let groundMirror;
let blurMirror;

function init() {

// renderer
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( WIDTH, HEIGHT );
renderer.setSize( window.innerWidth, window.innerHeight );

// scene
scene = new THREE.Scene();

// camera
camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR );
camera = new THREE.PerspectiveCamera( VIEW_ANGLE, aspect, NEAR, FAR );
camera.position.set( 0, 75, 160 );

cameraControls = new OrbitControls( camera, renderer.domElement );
Expand All @@ -91,6 +90,29 @@
const container = document.getElementById( 'container' );
container.appendChild( renderer.domElement );

window.addEventListener( "resize", onWindowResize, false );

}

function onWindowResize() {

aspect = window.innerWidth / window.innerHeight;
camera.aspect = aspect;
camera.updateProjectionMatrix();

renderer.setSize( window.innerWidth, window.innerHeight );

groundMirror.getRenderTarget().setSize(
window.innerWidth * window.devicePixelRatio,
window.innerHeight * window.devicePixelRatio
);

blurMirror.size.set(
window.innerWidth * window.devicePixelRatio,
window.innerHeight * window.devicePixelRatio
);
blurMirror.updateFrame()

}

function fillScene() {
Expand All @@ -101,7 +123,11 @@

// reflector/mirror plane
geometry = new THREE.PlaneGeometry( 100, 100 );
const groundMirror = new ReflectorRTT( geometry, { clipBias: 0.003, textureWidth: WIDTH, textureHeight: HEIGHT } );
groundMirror = new ReflectorRTT( geometry, {
clipBias: 0.003,
textureWidth: window.innerWidth * window.devicePixelRatio,
textureHeight: window.innerHeight * window.devicePixelRatio
} );

const mask = new SwitchNode( new TextureNode( decalDiffuse ), 'w' );

Expand All @@ -126,8 +152,11 @@
OperatorNode.MUL
);

const blurMirror = new BlurNode( mirror );
blurMirror.size = new THREE.Vector2( WIDTH, HEIGHT );
blurMirror = new BlurNode( mirror );
blurMirror.size = new THREE.Vector2(
window.innerWidth * window.devicePixelRatio,
window.innerHeight * window.devicePixelRatio
);
blurMirror.uv = new ExpressionNode( "projCoord.xyz / projCoord.q", "vec3" );
blurMirror.uv.keywords[ "projCoord" ] = new OperatorNode( mirror.offset, mirror.uv, OperatorNode.ADD );
blurMirror.radius.x = blurMirror.radius.y = 0;
Expand Down