Skip to content

Commit

Permalink
equirect shader: support decoding, tonemapping, and output encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
WestLangley committed Nov 28, 2018
1 parent 653a5ec commit 3dc950d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
24 changes: 24 additions & 0 deletions examples/webgl_materials_envmaps.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,19 @@
textureCube = new THREE.CubeTextureLoader().load( urls );
textureCube.format = THREE.RGBFormat;
textureCube.mapping = THREE.CubeReflectionMapping;
textureCube.encoding = THREE.sRGBEncoding;

var textureLoader = new THREE.TextureLoader();

textureEquirec = textureLoader.load( "textures/2294472375_24a3b8ef46_o.jpg" );
textureEquirec.mapping = THREE.EquirectangularReflectionMapping;
textureEquirec.magFilter = THREE.LinearFilter;
textureEquirec.minFilter = THREE.LinearMipMapLinearFilter;
textureEquirec.encoding = THREE.sRGBEncoding;

textureSphere = textureLoader.load( "textures/metal.jpg" );
textureSphere.mapping = THREE.SphericalReflectionMapping;
textureSphere.encoding = THREE.sRGBEncoding;

// Materials

Expand All @@ -103,6 +106,16 @@
} );

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( {
Expand All @@ -114,6 +127,15 @@
} );

cubeMaterial.uniforms[ "tCube" ].value = textureCube;
Object.defineProperty( cubeMaterial, 'map', {

get: function () {

return this.uniforms.tCube.value;

}

} );

// Skybox

Expand All @@ -136,6 +158,8 @@
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

renderer.gammaOutput = true;

//

var params = {
Expand Down
7 changes: 6 additions & 1 deletion src/renderers/shaders/ShaderLib/equirect_frag.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ void main() {
sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;
gl_FragColor = texture2D( tEquirect, sampleUV );
vec4 texColor = texture2D( tEquirect, sampleUV );
gl_FragColor = mapTexelToLinear( texColor );
#include <tonemapping_fragment>
#include <encodings_fragment>
}
`;

0 comments on commit 3dc950d

Please sign in to comment.