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

Make equirectangular reflections / refractions backwards compatible. #19911

Merged
merged 28 commits into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e52d7cb
Remove Equirect Reflection/Refraction Mapping
WestLangley Jul 16, 2020
895b78f
Merge branch 'dev_equirect_refl_mapping' of https://github.com/WestLa…
mrdoob Jul 22, 2020
6c5a7f2
Reverted EquirectangularReflectionMapping and EquirectangularRefracti…
mrdoob Jul 22, 2020
95b43cd
Added EquirectangularTexture and EquirectangularTextureLoader.
mrdoob Jul 22, 2020
23e0192
WebGLCubeRenderTarget: Avoid using renderer.render() in fromEquirecta…
mrdoob Jul 22, 2020
ddd9a46
WebGLBackground: Support EquirectangularTextures as background.
mrdoob Jul 22, 2020
74e4d98
Examples: Simplified webgl_materials_envmaps example.
mrdoob Jul 22, 2020
d50a5f0
Fixed EquirectangularTextureLoader.d.ts
mrdoob Jul 22, 2020
d6bc2e8
Removed EquirectangularTextureLoader
mrdoob Jul 23, 2020
88c1757
WebGLBackground: Fixed breaking when using Color as background.
mrdoob Jul 23, 2020
dbd0646
Examples: Fixed FBXLoader and LWOLoader.
mrdoob Jul 23, 2020
9e8588d
WebGLTextures: Moved cubeTexture code to its own class.
mrdoob Jul 23, 2020
99ca2b3
WebGLCubeMaps: Handle CubeUVReflectionMapping and CubeUVRefractionMap…
mrdoob Jul 23, 2020
36d2384
WebGLCubeRenderTarget: Renamed isWebGLCubeTexture hack to isWebGLCube…
mrdoob Jul 23, 2020
48df1ea
Removed EquirectangularTexture
mrdoob Jul 23, 2020
108a399
WebGLCubeMaps: Simplified and fixed some breakage.
mrdoob Jul 24, 2020
1526e83
Reverted more removals.
mrdoob Jul 24, 2020
f601b75
Merge branch 'dev' into dev_equirect_refl_mapping
mrdoob Jul 27, 2020
f3adff7
WebGLRenderer: Check object.geometry before updating attributes.
mrdoob Jul 27, 2020
99a6e91
WebGLRenderer: Added getRenderList and setRenderList.
mrdoob Jul 27, 2020
833b170
WebGLBackground: Added WebGLCubeRenderTarget support back.
mrdoob Jul 27, 2020
c005069
Reverted comment removal.
mrdoob Jul 27, 2020
f25ccec
WebGLCubeRenderTarget: Avoid using mipmaps in fromEquirectangularText…
mrdoob Jul 27, 2020
c40361a
WebGLCubeRenderTarget: Reverted generateMipmaps/migFilter/magFilter r…
mrdoob Aug 1, 2020
271bdb2
WebGLCubeMaps: Added DataTexture support.
mrdoob Aug 1, 2020
e638a1d
Examples: Added more detail to sphere in webgl_materials_envmap.
mrdoob Aug 2, 2020
8e7bcf2
WebGLCubeRenderTarget: Improved LinearMipmapLinearFilter handling.
mrdoob Aug 8, 2020
7024543
WebGLCubeMaps: Added support for CompressedTextures.
mrdoob Aug 8, 2020
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
8 changes: 0 additions & 8 deletions docs/api/en/constants/Textures.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ <h2>Mapping Modes</h2>
THREE.UVMapping
THREE.CubeReflectionMapping
THREE.CubeRefractionMapping
THREE.EquirectangularReflectionMapping
THREE.EquirectangularRefractionMapping
THREE.CubeUVReflectionMapping
THREE.CubeUVRefractionMapping
</code>
Expand All @@ -31,12 +29,6 @@ <h2>Mapping Modes</h2>
use with a [page:CubeTexture CubeTexture], which is made up of six textures, one for each face of the cube.
[page:Constant CubeReflectionMapping] is the default for a [page:CubeTexture CubeTexture]. <br /><br />

[page:Constant EquirectangularReflectionMapping] and [page:Constant EquirectangularRefractionMapping]
are for use with an equirectangular environment map. Also called a lat-long map, an equirectangular
texture represents a 360-degree view along the horizontal centerline, and a 180-degree view along the
vertical axis, with the top and bottom edges of the image corresponding to the north and south poles
of a mapped sphere.<br /><br />

See the [example:webgl_materials_envmaps materials / envmaps] example.
</p>

Expand Down
2 changes: 1 addition & 1 deletion docs/api/en/materials/MeshBasicMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h3>[property:Float reflectivity]</h3>
<h3>[property:Float refractionRatio]</h3>
<p>
The index of refraction (IOR) of air (approximately 1) divided by the index of refraction of the material.
It is used with environment mapping modes [page:Textures THREE.CubeRefractionMapping] and [page:Textures THREE.EquirectangularRefractionMapping].
It is used with environment mapping mode [page:Textures THREE.CubeRefractionMapping].
The refraction ratio should not exceed 1. Default is *0.98*.
</p>

Expand Down
2 changes: 1 addition & 1 deletion docs/api/en/materials/MeshLambertMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ <h3>[property:Float reflectivity]</h3>
<h3>[property:Float refractionRatio]</h3>
<p>
The index of refraction (IOR) of air (approximately 1) divided by the index of refraction of the material.
It is used with environment mapping modes [page:Textures THREE.CubeRefractionMapping] and [page:Textures THREE.EquirectangularRefractionMapping].
It is used with environment mapping mode [page:Textures THREE.CubeRefractionMapping].
The refraction ratio should not exceed 1. Default is *0.98*.
</p>

Expand Down
2 changes: 1 addition & 1 deletion docs/api/en/materials/MeshPhongMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ <h3>[property:Float reflectivity]</h3>
<h3>[property:Float refractionRatio]</h3>
<p>
The index of refraction (IOR) of air (approximately 1) divided by the index of refraction of the material.
It is used with environment mapping modes [page:Textures THREE.CubeRefractionMapping] and [page:Textures THREE.EquirectangularRefractionMapping].
It is used with environment mapping mode [page:Textures THREE.CubeRefractionMapping].
The refraction ratio should not exceed 1. Default is *0.98*.
</p>

Expand Down
2 changes: 1 addition & 1 deletion docs/api/en/materials/MeshStandardMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ <h3>[property:Vector2 normalScale]</h3>
<h3>[property:Float refractionRatio]</h3>
<p>
The index of refraction (IOR) of air (approximately 1) divided by the index of refraction of the material.
It is used with environment mapping modes [page:Textures THREE.CubeRefractionMapping] and [page:Textures THREE.EquirectangularRefractionMapping].
It is used with environment mapping mode [page:Textures THREE.CubeRefractionMapping].
The refraction ratio should not exceed 1. Default is *0.98*.
</p>

Expand Down
6 changes: 0 additions & 6 deletions docs/api/zh/constants/Textures.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ <h2>映射模式</h2>
THREE.UVMapping
THREE.CubeReflectionMapping
THREE.CubeRefractionMapping
THREE.EquirectangularReflectionMapping
THREE.EquirectangularRefractionMapping
THREE.CubeUVReflectionMapping
THREE.CubeUVRefractionMapping
</code>
Expand All @@ -33,10 +31,6 @@ <h2>映射模式</h2>

对于[page:CubeTexture CubeTexture]来说,[page:Constant CubeReflectionMapping]是其默认值。<br /><br />

[page:Constant EquirectangularReflectionMapping] 和 [page:Constant EquirectangularRefractionMapping]
用于等距圆柱投影的环境贴图,也被叫做经纬线映射贴图。等距圆柱投影贴图表示沿着其水平中线360°的视角,以及沿着其垂直轴向180°的视角。贴图顶部和底部的边缘分别对应于它所映射的球体的北极和南极。
<br /><br />

请查看示例:[example:webgl_materials_envmaps materials / envmaps] 。
</p>

Expand Down
2 changes: 2 additions & 0 deletions docs/api/zh/materials/MeshBasicMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ <h3>[property:Float reflectivity]</h3>
<h3>[property:Float refractionRatio]</h3>
<p> 空气的折射率(IOR)(约为1)除以材质的折射率。它与环境映射模式[page:Textures THREE.CubeRefractionMapping]
和[page:Textures THREE.EquirectangularRefractionMapping]一起使用。
The index of refraction (IOR) of air (approximately 1) divided by the index of refraction of the material.
It is used with environment mapping mode [page:Textures THREE.CubeRefractionMapping].
折射率不应超过1。默认值为*0.98*。
</p>

Expand Down
2 changes: 2 additions & 0 deletions docs/api/zh/materials/MeshLambertMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ <h3>[property:Float reflectivity]</h3>
<h3>[property:Float refractionRatio]</h3>
<p>空气的折射率(IOR)(约为1)除以材质的折射率。它与环境映射模式[page:Textures THREE.CubeRefractionMapping]
和[page:Textures THREE.EquirectangularRefractionMapping]一起使用。
The index of refraction (IOR) of air (approximately 1) divided by the index of refraction of the material.
It is used with environment mapping mode [page:Textures THREE.CubeRefractionMapping].
折射率不应超过1。默认值为*0.98*。
</p>

Expand Down
2 changes: 2 additions & 0 deletions docs/api/zh/materials/MeshPhongMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ <h3>[property:Float reflectivity]</h3>
<h3>[property:Float refractionRatio]</h3>
<p> 空气的折射率(IOR)(约为1)除以材质的折射率。它与环境映射模式[page:Textures THREE.CubeRefractionMapping]
和[page:Textures THREE.EquirectangularRefractionMapping]一起使用。
The index of refraction (IOR) of air (approximately 1) divided by the index of refraction of the material.
It is used with environment mapping mode [page:Textures THREE.CubeRefractionMapping].
折射率不应超过1。默认值为*0.98*。
</p>

Expand Down
2 changes: 2 additions & 0 deletions docs/api/zh/materials/MeshStandardMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ <h3>[property:Vector2 normalScale]</h3>
<h3>[property:Float refractionRatio]</h3>
<p> 空气的折射率(IOR)(约为1)除以材质的折射率。它与环境映射模式[page:Textures THREE.CubeRefractionMapping]
和[page:Textures THREE.EquirectangularRefractionMapping]一起使用。
The index of refraction (IOR) of air (approximately 1) divided by the index of refraction of the material.
It is used with environment mapping mode [page:Textures THREE.CubeRefractionMapping].
折射率不应超过1。默认值为*0.98*。
</p>

Expand Down
75 changes: 10 additions & 65 deletions examples/webgl_materials_envmaps.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
import { OrbitControls } from './jsm/controls/OrbitControls.js';

var controls, camera, scene, renderer;
var cameraCube, sceneCube;
var textureEquirec, textureCube;
var cubeMesh, sphereMesh;
var sphereMaterial;
var sphereMesh, sphereMaterial;

init();
animate();
Expand All @@ -36,12 +34,10 @@

camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 100000 );
camera.position.set( 0, 0, 1000 );
cameraCube = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 100000 );

// SCENE

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

// Lights

Expand All @@ -50,12 +46,10 @@

// Textures

var r = 'textures/cube/Bridge2/';
var urls = [ r + 'posx.jpg', r + 'negx.jpg',
r + 'posy.jpg', r + 'negy.jpg',
r + 'posz.jpg', r + 'negz.jpg' ];
var loader = new THREE.CubeTextureLoader();
loader.setPath( 'textures/cube/Bridge2/' );

textureCube = new THREE.CubeTextureLoader().load( urls );
textureCube = loader.load( [ 'posx.jpg', 'negx.jpg', 'posy.jpg', 'negy.jpg', 'posz.jpg', 'negz.jpg' ] );
textureCube.encoding = THREE.sRGBEncoding;

var textureLoader = new THREE.TextureLoader();
Expand All @@ -64,65 +58,22 @@
textureEquirec.mapping = THREE.EquirectangularReflectionMapping;
textureEquirec.encoding = THREE.sRGBEncoding;

// Materials

var equirectShader = THREE.ShaderLib[ 'equirect' ];

var equirectMaterial = new THREE.ShaderMaterial( {
uniforms: THREE.UniformsUtils.clone( equirectShader.uniforms ),
fragmentShader: equirectShader.fragmentShader,
vertexShader: equirectShader.vertexShader,
depthWrite: false,
side: THREE.BackSide
} );

equirectMaterial.uniforms[ 'tEquirect' ].value = textureEquirec;

// enable code injection for non-built-in material
Object.defineProperty( equirectMaterial, 'map', {

get: function () {

return this.uniforms.tEquirect.value;

}

} );

var cubeShader = THREE.ShaderLib[ 'cube' ];

var cubeMaterial = new THREE.ShaderMaterial( {
uniforms: THREE.UniformsUtils.clone( cubeShader.uniforms ),
fragmentShader: cubeShader.fragmentShader,
vertexShader: cubeShader.vertexShader,
depthWrite: false,
side: THREE.BackSide
} );

cubeMaterial.envMap = textureCube;

// Skybox

cubeMesh = new THREE.Mesh( new THREE.BoxBufferGeometry( 100, 100, 100 ), cubeMaterial );
sceneCube.add( cubeMesh );
scene.background = textureCube;

//

var geometry = new THREE.SphereBufferGeometry( 400.0, 48, 24 );
sphereMaterial = new THREE.MeshLambertMaterial( { envMap: textureCube } );
sphereMesh = new THREE.Mesh( geometry, sphereMaterial );

scene.add( sphereMesh );

//

renderer = new THREE.WebGLRenderer();
renderer.autoClear = false;
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

renderer.outputEncoding = THREE.sRGBEncoding;
document.body.appendChild( renderer.domElement );

//

Expand All @@ -135,16 +86,16 @@
var params = {
Cube: function () {

cubeMesh.material = cubeMaterial;
cubeMesh.visible = true;
scene.background = textureCube;

sphereMaterial.envMap = textureCube;
sphereMaterial.needsUpdate = true;

},
Equirectangular: function () {

cubeMesh.material = equirectMaterial;
cubeMesh.visible = true;
scene.background = textureEquirec;

sphereMaterial.envMap = textureEquirec;
sphereMaterial.needsUpdate = true;

Expand Down Expand Up @@ -183,9 +134,6 @@
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();

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

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

}
Expand All @@ -203,9 +151,6 @@
function render() {

camera.lookAt( scene.position );
cameraCube.rotation.copy( camera.rotation );

renderer.render( sceneCube, cameraCube );
renderer.render( scene, camera );

}
Expand Down
16 changes: 0 additions & 16 deletions examples/webgl_materials_envmaps_parallax.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,6 @@

vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );

#elif defined( ENVMAP_TYPE_EQUIREC )

vec2 sampleUV = equirectUv( reflectVec );

#ifdef TEXTURE_LOD_EXT

vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );

#else

vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );

#endif

envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;

#endif

return envMapColor.rgb * envMapIntensity;
Expand Down
3 changes: 2 additions & 1 deletion src/Three.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ export { CompressedTexture } from './textures/CompressedTexture.js';
export { CubeTexture } from './textures/CubeTexture.js';
export { CanvasTexture } from './textures/CanvasTexture.js';
export { DepthTexture } from './textures/DepthTexture.js';
export { EquirectangularTexture } from './textures/EquirectangularTexture.js';
export { Texture } from './textures/Texture.js';
export * from './geometries/Geometries.js';
export * from './materials/Materials.js';
export { AnimationLoader } from './loaders/AnimationLoader.js';
export { CompressedTextureLoader } from './loaders/CompressedTextureLoader.js';
export { DataTextureLoader } from './loaders/DataTextureLoader.js';
export { CubeTextureLoader } from './loaders/CubeTextureLoader.js';
export { DataTextureLoader } from './loaders/DataTextureLoader.js';
export { TextureLoader } from './loaders/TextureLoader.js';
export { ObjectLoader } from './loaders/ObjectLoader.js';
export { MaterialLoader } from './loaders/MaterialLoader.js';
Expand Down
39 changes: 29 additions & 10 deletions src/renderers/WebGLCubeRenderTarget.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BackSide, NoBlending } from '../constants.js';
import { Scene } from '../scenes/Scene.js';
import { Mesh } from '../objects/Mesh.js';
import { BoxBufferGeometry } from '../geometries/BoxGeometry.js';
import { ShaderMaterial } from '../materials/ShaderMaterial.js';
Expand All @@ -24,6 +23,8 @@ function WebGLCubeRenderTarget( size, options, dummy ) {

WebGLRenderTarget.call( this, size, size, options );

this.texture.isWebGLCubeRenderTargetTexture = true; // HACK Why is texture not a CubeTexture?

}

WebGLCubeRenderTarget.prototype = Object.create( WebGLRenderTarget.prototype );
Expand All @@ -37,12 +38,6 @@ WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer
this.texture.format = texture.format;
this.texture.encoding = texture.encoding;

this.texture.generateMipmaps = texture.generateMipmaps;
this.texture.minFilter = texture.minFilter;
this.texture.magFilter = texture.magFilter;

const scene = new Scene();

const shader = {

uniforms: {
Expand Down Expand Up @@ -89,6 +84,8 @@ WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer
`
};

const geometry = new BoxBufferGeometry( 5, 5, 5 );

const material = new ShaderMaterial( {

name: 'CubemapFromEquirect',
Expand All @@ -103,12 +100,34 @@ WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer

material.uniforms.tEquirect.value = texture;

const mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material );
const mesh = new Mesh( geometry, material );

scene.add( mesh );
//

const camera = new CubeCamera( 1, 10, this );
camera.update( renderer, scene );
camera.updateMatrixWorld();

const currentRenderTarget = renderer.getRenderTarget();
const generateMipmaps = this.texture.generateMipmaps;

this.texture.generateMipmaps = false;
Copy link
Collaborator

@Mugen87 Mugen87 Jul 27, 2020

Choose a reason for hiding this comment

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

Doing this means generateMipmaps will always be false and thus using LinearMipmapLinearFilter is invalid. Is this intended?

This will break existing code (webgl_materials_cubemap_dynamic) that used to generate the background like so:

var options = {
	generateMipmaps: true,
	minFilter: THREE.LinearMipmapLinearFilter,
	magFilter: THREE.LinearFilter
};

scene.background = new THREE.WebGLCubeRenderTarget( 1024, options ).fromEquirectangularTexture( renderer, texture );

Copy link
Owner Author

Choose a reason for hiding this comment

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

For this particular case.... I don't think we need mipmaps for the background? 🤔


renderer.compile( mesh, camera );

for ( let i = 0; i < 6; i ++ ) {

if ( i === 5 ) this.texture.generateMipmaps = generateMipmaps;

const camera2 = camera.children[ i ];

mesh.modelViewMatrix.multiplyMatrices( camera2.matrixWorldInverse, mesh.matrixWorld );

renderer.setRenderTarget( this, i );
renderer.renderBufferDirect( camera2, null, geometry, material, mesh, null );

}

renderer.setRenderTarget( currentRenderTarget );

mesh.geometry.dispose();
mesh.material.dispose();
Expand Down
Loading