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 all 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
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
77 changes: 11 additions & 66 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 );
var geometry = new THREE.IcosahedronBufferGeometry( 400, 4 );
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
2 changes: 1 addition & 1 deletion src/Three.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ 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
25 changes: 18 additions & 7 deletions src/renderers/WebGLCubeRenderTarget.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BackSide, NoBlending, RGBAFormat } from '../constants.js';
import { Scene } from '../scenes/Scene.js';
import { BackSide, LinearFilter, LinearMipmapLinearFilter, NoBlending, RGBAFormat } from '../constants.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 @@ -41,8 +42,6 @@ WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer
this.texture.minFilter = texture.minFilter;
this.texture.magFilter = texture.magFilter;

const scene = new Scene();

const shader = {

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

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

const material = new ShaderMaterial( {

name: 'CubemapFromEquirect',
Expand All @@ -103,12 +104,22 @@ 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 currentMinFilter = texture.minFilter;
const currentRenderList = renderer.getRenderList();
const currentRenderTarget = renderer.getRenderTarget();

// Avoid blurred poles
if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;

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

texture.minFilter = currentMinFilter;

renderer.setRenderTarget( currentRenderTarget );
renderer.setRenderList( currentRenderList );

mesh.geometry.dispose();
mesh.material.dispose();
Expand Down
27 changes: 21 additions & 6 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { WebGLBindingStates } from './webgl/WebGLBindingStates.js';
import { WebGLBufferRenderer } from './webgl/WebGLBufferRenderer.js';
import { WebGLCapabilities } from './webgl/WebGLCapabilities.js';
import { WebGLClipping } from './webgl/WebGLClipping.js';
import { WebGLCubeMaps } from './webgl/WebGLCubeMaps.js';
import { WebGLExtensions } from './webgl/WebGLExtensions.js';
import { WebGLGeometries } from './webgl/WebGLGeometries.js';
import { WebGLIndexedBufferRenderer } from './webgl/WebGLIndexedBufferRenderer.js';
Expand Down Expand Up @@ -259,7 +260,7 @@ function WebGLRenderer( parameters ) {
}

let extensions, capabilities, state, info;
let properties, textures, attributes, geometries, objects;
let properties, textures, cubemaps, attributes, geometries, objects;
let programCache, materials, renderLists, renderStates;

let background, morphtargets, bufferRenderer, indexedBufferRenderer;
Expand Down Expand Up @@ -296,17 +297,18 @@ function WebGLRenderer( parameters ) {
info = new WebGLInfo( _gl );
properties = new WebGLProperties();
textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
cubemaps = new WebGLCubeMaps( _this );
attributes = new WebGLAttributes( _gl, capabilities );
bindingStates = new WebGLBindingStates( _gl, extensions, attributes, capabilities );
geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
objects = new WebGLObjects( _gl, geometries, attributes, info );
morphtargets = new WebGLMorphtargets( _gl );
programCache = new WebGLPrograms( _this, extensions, capabilities, bindingStates );
materials = new WebGLMaterials( properties );
programCache = new WebGLPrograms( _this, cubemaps, extensions, capabilities, bindingStates );
materials = new WebGLMaterials( properties, cubemaps );
renderLists = new WebGLRenderLists( properties );
renderStates = new WebGLRenderStates();

background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
background = new WebGLBackground( _this, cubemaps, state, objects, _premultipliedAlpha );

bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
Expand Down Expand Up @@ -596,6 +598,7 @@ function WebGLRenderer( parameters ) {
renderLists.dispose();
renderStates.dispose();
properties.dispose();
cubemaps.dispose();
objects.dispose();
bindingStates.dispose();

Expand Down Expand Up @@ -902,15 +905,15 @@ function WebGLRenderer( parameters ) {

scene.traverse( function ( object ) {

let material = object.material;
const material = object.material;

if ( material ) {

if ( Array.isArray( material ) ) {

for ( let i = 0; i < material.length; i ++ ) {

let material2 = material[ i ];
const material2 = material[ i ];

if ( compiled.has( material2 ) === false ) {

Expand Down Expand Up @@ -1781,6 +1784,18 @@ function WebGLRenderer( parameters ) {

};

this.getRenderList = function () {

return currentRenderList;

};

this.setRenderList = function ( renderList ) {

currentRenderList = renderList;

};

this.getRenderTarget = function () {

return _currentRenderTarget;
Expand Down
8 changes: 0 additions & 8 deletions src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ export default /* glsl */`

vec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );

#elif defined( ENVMAP_TYPE_EQUIREC )

reflectVec = normalize( reflectVec );

vec2 sampleUV = equirectUv( reflectVec );

vec4 envColor = texture2D( envMap, sampleUV );

#else

vec4 envColor = vec4( 0.0 );
Expand Down
Loading