Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c4dcfc5
WIP: Added hdr support to cubeTexturePass
DanielSturk Jun 24, 2019
5cc50bc
Added hdr support to cubeTexturePass
DanielSturk Jun 24, 2019
ade17f9
Replaced ShaderMaterial(ShaderLib.cube) with MeshCubeMaterial in WebG…
DanielSturk Jun 24, 2019
a853125
Merge remote-tracking branch 'mrdoob/dev' into mainline-cube-texture-…
DanielSturk Jun 24, 2019
799bf1c
Merge remote-tracking branch 'mrdoob/dev' into mainline-cube-texture-…
DanielSturk Jun 24, 2019
bac05aa
Added changes to /examples/jsm. Fixed declarations
DanielSturk Jun 24, 2019
0905e1f
Fixed CI formatting errors
DanielSturk Jun 24, 2019
d18e36e
Added newline for CI check
DanielSturk Jun 25, 2019
a204d66
Forgot to flip cube maps
DanielSturk Jun 25, 2019
bf973aa
Renamed MeshCubeMaterial to SkyboxMaterial
DanielSturk Jul 3, 2019
989fdd2
Missed a couple spaces in the last commit
DanielSturk Jul 3, 2019
3099b18
Removed clipping planes and log depth buffer
DanielSturk Jul 3, 2019
8939d85
Renamed variable
DanielSturk Jul 3, 2019
70a4dc6
Removed comment
DanielSturk Jul 3, 2019
8d32c8a
Undid changes to WebGLBackground
DanielSturk Jul 3, 2019
b183d9e
Merge remote-tracking branch 'mrdoob/dev' into mainline-cube-texture-…
DanielSturk Jul 3, 2019
e62e9cc
Removed unnecessary varying 'vViewPosition'
DanielSturk Jul 8, 2019
00a14a1
Merge remote-tracking branch 'mrdoob/dev' into mainline-cube-texture-…
DanielSturk Jul 8, 2019
f33550e
Update webgl_postprocessing_backgrounds.html
DanielSturk Jul 10, 2019
3161d6d
reverted gammaOutput, changed default hdr parameters
DanielSturk Jul 24, 2019
a99287d
Fixed import convention
DanielSturk Jul 25, 2019
0a473c8
Added back gammaOutput=true and sRGB encoding to demo
DanielSturk Jul 30, 2019
e4ada7d
Fixed background not aligning with reflection in objects
DanielSturk Aug 7, 2019
2b6a568
Copied changes from examples/jsm to examples/js
DanielSturk Aug 7, 2019
3520706
Removed commented code
DanielSturk Oct 11, 2019
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
38 changes: 22 additions & 16 deletions examples/js/postprocessing/CubeTexturePass.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ THREE.CubeTexturePass = function ( camera, envMap, opacity ) {

this.needsSwap = false;

this.cubeShader = THREE.ShaderLib[ 'cube' ];
this.cubeMaterial = new THREE.SkyboxMaterial();

this.cubeMesh = new THREE.Mesh(
new THREE.BoxBufferGeometry( 10, 10, 10 ),
new THREE.ShaderMaterial( {
uniforms: this.cubeShader.uniforms,
vertexShader: this.cubeShader.vertexShader,
fragmentShader: this.cubeShader.fragmentShader,
depthTest: false,
depthWrite: false,
side: THREE.BackSide
} )
this.cubeMaterial
);

this.envMap = envMap;
this.envMapIntensity = 1.0;
this.opacity = ( opacity !== undefined ) ? opacity : 1.0;
this.roughness = 0.0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps blurriness is a better property name in this case.


this.cubeScene = new THREE.Scene();
this.cubeCamera = new THREE.PerspectiveCamera();
Expand All @@ -38,18 +34,28 @@ THREE.CubeTexturePass.prototype = Object.assign( Object.create( THREE.Pass.proto

render: function ( renderer, writeBuffer, readBuffer/*, deltaTime, maskActive*/ ) {

var camera = this.camera;

var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;

this.cubeCamera.projectionMatrix.copy( this.camera.projectionMatrix );
this.cubeCamera.quaternion.setFromRotationMatrix( this.camera.matrixWorld );

this.cubeMesh.material.uniforms[ "tCube" ].value = this.envMap;
this.cubeMesh.material.uniforms[ "opacity" ].value = this.opacity;
this.cubeMesh.material.transparent = ( this.opacity < 1.0 );
this.cubeCamera.copy( camera );
this.cubeCamera.near = 0.01;
this.cubeCamera.far = 20;
this.cubeCamera.position.set(0, 0, 0);
this.cubeCamera.quaternion.setFromRotationMatrix( camera.matrixWorld );
this.cubeCamera.updateProjectionMatrix();
if( this.cubeMaterial.envMap != this.envMap ) {
this.cubeMaterial.envMap = this.envMap;
this.cubeMaterial.needsUpdate = true;
}
this.cubeMaterial.envMapIntensity = this.envMapIntensity;
this.cubeMaterial.roughness = this.roughness;
this.cubeMaterial.opacity = this.opacity;
this.cubeMaterial.transparent = ( this.opacity < 1.0 );

renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
if ( this.clear ) renderer.clear();
if( this.clear ) renderer.clear();
renderer.render( this.cubeScene, this.cubeCamera );

renderer.autoClear = oldAutoClear;
Expand Down
42 changes: 23 additions & 19 deletions examples/jsm/postprocessing/CubeTexturePass.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
*/

import {
BackSide,
BoxBufferGeometry,
Mesh,
PerspectiveCamera,
Scene,
ShaderLib,
ShaderMaterial
SkyboxMaterial
} from "../../../build/three.module.js";
import { Pass } from "../postprocessing/Pass.js";

Expand All @@ -21,21 +19,17 @@ var CubeTexturePass = function ( camera, envMap, opacity ) {

this.needsSwap = false;

this.cubeShader = ShaderLib[ 'cube' ];
this.cubeMaterial = new SkyboxMaterial();

this.cubeMesh = new Mesh(
new BoxBufferGeometry( 10, 10, 10 ),
new ShaderMaterial( {
uniforms: this.cubeShader.uniforms,
vertexShader: this.cubeShader.vertexShader,
fragmentShader: this.cubeShader.fragmentShader,
depthTest: false,
depthWrite: false,
side: BackSide
} )
this.cubeMaterial
);

this.envMap = envMap;
this.envMapIntensity = 1.0;
this.opacity = ( opacity !== undefined ) ? opacity : 1.0;
this.roughness = 0.0;

this.cubeScene = new Scene();
this.cubeCamera = new PerspectiveCamera();
Expand All @@ -49,18 +43,28 @@ CubeTexturePass.prototype = Object.assign( Object.create( Pass.prototype ), {

render: function ( renderer, writeBuffer, readBuffer/*, deltaTime, maskActive*/ ) {

var camera = this.camera;

var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;

this.cubeCamera.projectionMatrix.copy( this.camera.projectionMatrix );
this.cubeCamera.quaternion.setFromRotationMatrix( this.camera.matrixWorld );

this.cubeMesh.material.uniforms[ "tCube" ].value = this.envMap;
this.cubeMesh.material.uniforms[ "opacity" ].value = this.opacity;
this.cubeMesh.material.transparent = ( this.opacity < 1.0 );
this.cubeCamera.copy( camera );
this.cubeCamera.near = 0.01;
this.cubeCamera.far = 20;
this.cubeCamera.position.set(0, 0, 0);
this.cubeCamera.quaternion.setFromRotationMatrix( camera.matrixWorld );
this.cubeCamera.updateProjectionMatrix();
if( this.cubeMaterial.envMap != this.envMap ) {
this.cubeMaterial.envMap = this.envMap;
this.cubeMaterial.needsUpdate = true;
}
this.cubeMaterial.envMapIntensity = this.envMapIntensity;
this.cubeMaterial.roughness = this.roughness;
this.cubeMaterial.opacity = this.opacity;
this.cubeMaterial.transparent = ( this.opacity < 1.0 );

renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
if ( this.clear ) renderer.clear();
if( this.clear ) renderer.clear();
renderer.render( this.cubeScene, this.cubeCamera );

renderer.autoClear = oldAutoClear;
Expand Down
40 changes: 34 additions & 6 deletions examples/webgl_postprocessing_backgrounds.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
<div id="container"></div>

<script type="module">

import * as THREE from '../build/three.module.js';
import * as THREE from "../build/three.module.js";

import Stats from './jsm/libs/stats.module.js';

Expand All @@ -29,10 +28,14 @@
import { ClearPass } from './jsm/postprocessing/ClearPass.js';
import { CopyShader } from './jsm/shaders/CopyShader.js';
import { OrbitControls } from './jsm/controls/OrbitControls.js';
import { HDRCubeTextureLoader } from './jsm/loaders/HDRCubeTextureLoader.js';

var scene, renderer, composer;
var clearPass, texturePass, renderPass;
var cameraP, cubeTexturePassP;
var material;
var ldrCubeMap, hdrCubeMap;
//var cameraO, cubeTexturePassO;
var gui, stats;

var params = {
Expand All @@ -47,7 +50,12 @@
cubeTexturePass: true,
cubeTexturePassOpacity: 1.0,

renderPass: true
renderPass: true,

exposure: 1,

hdr: false

};

init();
Expand All @@ -73,6 +81,10 @@

gui.add( params, "renderPass" );

gui.add( params, "exposure", 0, 2 );

gui.add( params, "hdr" );

gui.open();

}
Expand All @@ -90,6 +102,7 @@
renderer.setPixelRatio( devicePixelRatio );
renderer.setSize( width, height );
document.body.appendChild( renderer.domElement );
renderer.gammaOutput = true;

stats = new Stats();
container.appendChild( stats.dom );
Expand Down Expand Up @@ -124,7 +137,7 @@

var geometry = new THREE.SphereBufferGeometry( 1, 48, 24 );

var material = new THREE.MeshStandardMaterial();
material = new THREE.MeshStandardMaterial();
material.roughness = 0.5 * Math.random() + 0.25;
material.metalness = 0;
material.color.setHSL( Math.random(), 1.0, 0.3 );
Expand Down Expand Up @@ -163,11 +176,23 @@
composer.addPass( cubeTexturePassP );

var ldrUrls = genCubeUrls( "textures/cube/pisa/", ".png" );
new THREE.CubeTextureLoader().load( ldrUrls, function ( ldrCubeMap ) {
ldrCubeMap = new THREE.CubeTextureLoader().load( ldrUrls, function ( ) {

cubeTexturePassP.envMap = ldrCubeMap;
console.log( "loaded ldr envmap" );

} );
ldrCubeMap.encoding = THREE.sRGBEncoding;

var hdrUrls = [ 'px.hdr', 'nx.hdr', 'py.hdr', 'ny.hdr', 'pz.hdr', 'nz.hdr' ];
hdrCubeMap = new HDRCubeTextureLoader()
.setPath( './textures/cube/pisaHDR/' )
.setDataType( THREE.UnsignedByteType )
.load( hdrUrls, function () {

hdrCubeMap.magFilter = THREE.LinearFilter;
console.log( "loaded hdr envmap" );

} );

renderPass = new RenderPass( scene, cameraP );
renderPass.clear = false;
Expand Down Expand Up @@ -227,6 +252,9 @@

renderPass.enabled = params.renderPass;

renderer.toneMappingExposure = params.exposure;
cubeTexturePassP.envMap = params.hdr ? hdrCubeMap : ldrCubeMap;

composer.render();

stats.end();
Expand Down
1 change: 1 addition & 0 deletions src/materials/Materials.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export * from './MeshBasicMaterial';
export * from './MeshMatcapMaterial';
export * from './LineDashedMaterial';
export * from './LineBasicMaterial';
export * from './SkyboxMaterial';
export * from './Material';
1 change: 1 addition & 0 deletions src/materials/Materials.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export { MeshBasicMaterial } from './MeshBasicMaterial.js';
export { MeshMatcapMaterial } from './MeshMatcapMaterial.js';
export { LineDashedMaterial } from './LineDashedMaterial.js';
export { LineBasicMaterial } from './LineBasicMaterial.js';
export { SkyboxMaterial } from './SkyboxMaterial.js';
export { Material } from './Material.js';
23 changes: 23 additions & 0 deletions src/materials/SkyboxMaterial.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Texture } from './../textures/Texture';
import { MaterialParameters, Material } from './Material';
/**
* parameters is an object with one or more properties defining the material's appearance.
*/
export interface SkyboxMaterialParameters extends MaterialParameters {
envMap?: Texture;
envMapIntensity?: number;
opacity: number;
}

export class SkyboxMaterial extends Material {

constructor( parameters?: SkyboxMaterialParameters );

envMap?: Texture;
envMapIntensity?: number;
opacity: number;
roughness: number;

setValues( parameters: SkyboxMaterialParameters ): void;

}
51 changes: 51 additions & 0 deletions src/materials/SkyboxMaterial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Material } from './Material';
import { BackSide } from '../constants';

/**
* @author bhouston / https://clara.io
*
* parameters = {
*
* }
*/

function SkyboxMaterial( parameters ) {

Material.call( this );

this.type = 'SkyboxMaterial';

this.envMap = null;
this.envMapIntensity = 1.0;

this.roughness = 0.0;

this.depthTest = false;
this.depthWrite = false;
this.side = BackSide;

this.lights = false;

this.setValues( parameters );

}

SkyboxMaterial.prototype = Object.create( Material.prototype );
SkyboxMaterial.prototype.constructor = SkyboxMaterial;

SkyboxMaterial.prototype.isSkyboxMaterial = true;

SkyboxMaterial.prototype.copy = function ( source ) {

Material.prototype.copy.call( this, source );

this.envMap = source.envMap;
this.envMapIntensity = source.envMapIntensity;

this.roughness = source.roughness;

return this;

};

export { SkyboxMaterial };
14 changes: 14 additions & 0 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,11 @@ function WebGLRenderer( parameters ) {

refreshUniformsPoints( m_uniforms, material );

} else if ( material.isSkyboxMaterial ) {

refreshUniformsCommon( m_uniforms, material );
refreshUniformsSkybox( m_uniforms, material );

} else if ( material.isSpriteMaterial ) {

refreshUniformsSprites( m_uniforms, material );
Expand Down Expand Up @@ -2077,6 +2082,15 @@ function WebGLRenderer( parameters ) {

}

function refreshUniformsSkybox( uniforms, material ) {

uniforms.roughness.value = material.roughness;
uniforms.opacity.value = material.opacity;
uniforms.envMapIntensity.value = material.envMapIntensity;
uniforms.tFlip.value = material.envMap.isCubeTexture ? - 1 : 1;

}

function refreshUniformsLine( uniforms, material ) {

uniforms.diffuse.value.copy( material.color );
Expand Down
2 changes: 2 additions & 0 deletions src/renderers/shaders/ShaderChunk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export let ShaderChunk: {
common: string;
cube_frag: string;
cube_vert: string;
skybox_frag: string;
skybox_vert: string;
cube_uv_reflection_fragment: string;
defaultnormal_vertex: string;
depth_frag: string;
Expand Down
4 changes: 4 additions & 0 deletions src/renderers/shaders/ShaderChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ import background_frag from './ShaderLib/background_frag.glsl.js';
import background_vert from './ShaderLib/background_vert.glsl.js';
import cube_frag from './ShaderLib/cube_frag.glsl.js';
import cube_vert from './ShaderLib/cube_vert.glsl.js';
import skybox_frag from './ShaderLib/skybox_frag.glsl.js';
import skybox_vert from './ShaderLib/skybox_vert.glsl.js';
import depth_frag from './ShaderLib/depth_frag.glsl.js';
import depth_vert from './ShaderLib/depth_vert.glsl.js';
import distanceRGBA_frag from './ShaderLib/distanceRGBA_frag.glsl.js';
Expand Down Expand Up @@ -214,6 +216,8 @@ export var ShaderChunk = {
background_vert: background_vert,
cube_frag: cube_frag,
cube_vert: cube_vert,
skybox_frag: skybox_frag,
skybox_vert: skybox_vert,
depth_frag: depth_frag,
depth_vert: depth_vert,
distanceRGBA_frag: distanceRGBA_frag,
Expand Down
1 change: 1 addition & 0 deletions src/renderers/shaders/ShaderLib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export let ShaderLib: {
cube: Shader;
equirect: Shader;
distanceRGBA: Shader;
cubeEnv: Shader;
shadow: Shader;
physical: Shader;
};
Loading