From 472ef2b8343338a53b3145dab20a474173fbb586 Mon Sep 17 00:00:00 2001 From: Daniel Sturk Date: Wed, 12 Jun 2019 15:44:44 -0400 Subject: [PATCH 1/3] Fixed TextureCubeNode --- examples/js/nodes/misc/TextureCubeNode.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/js/nodes/misc/TextureCubeNode.js b/examples/js/nodes/misc/TextureCubeNode.js index 0d900201688f72..a569da0b136901 100644 --- a/examples/js/nodes/misc/TextureCubeNode.js +++ b/examples/js/nodes/misc/TextureCubeNode.js @@ -26,8 +26,12 @@ TextureCubeNode.prototype.generate = function ( builder, output ) { uv_20 = this.uv.build( builder ) + '.uv_20', t = this.uv.build( builder ) + '.t'; - var color10 = builder.getTexelDecodingFunctionFromTexture( 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_10 + ' )', this.value.value ), - color20 = builder.getTexelDecodingFunctionFromTexture( 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_20 + ' )', this.value.value ); + builder.addContext( { encoding: builder.getTextureEncodingFromMap( this.value ), include: builder.isShader( 'vertex' ) } ); + + var color10 = 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_10 + ' )', + color20 = 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_20 + ' )'; + + builder.removeContext(); return builder.format( 'vec4( mix( ' + color10 + ', ' + color20 + ', ' + t + ' ).rgb, 1.0 )', this.getType( builder ), output ); From 630bc141d4ca378bf0fdfc78c229922105eab4fe Mon Sep 17 00:00:00 2001 From: Daniel Sturk Date: Thu, 13 Jun 2019 13:11:58 -0400 Subject: [PATCH 2/3] Actually fixed TextureCubeNode --- examples/js/nodes/misc/TextureCubeNode.js | 16 +- examples/webgl_materials_envmaps_node.html | 313 +++++++++++++++++++++ 2 files changed, 325 insertions(+), 4 deletions(-) create mode 100644 examples/webgl_materials_envmaps_node.html diff --git a/examples/js/nodes/misc/TextureCubeNode.js b/examples/js/nodes/misc/TextureCubeNode.js index a569da0b136901..116fb82d74a693 100644 --- a/examples/js/nodes/misc/TextureCubeNode.js +++ b/examples/js/nodes/misc/TextureCubeNode.js @@ -4,6 +4,7 @@ import { TempNode } from '../core/TempNode.js'; import { TextureCubeUVNode } from './TextureCubeUVNode.js'; +import { ColorSpaceNode } from '../utils/ColorSpaceNode.js'; function TextureCubeNode( value, uv ) { @@ -26,12 +27,19 @@ TextureCubeNode.prototype.generate = function ( builder, output ) { uv_20 = this.uv.build( builder ) + '.uv_20', t = this.uv.build( builder ) + '.t'; - builder.addContext( { encoding: builder.getTextureEncodingFromMap( this.value ), include: builder.isShader( 'vertex' ) } ); + var format = this.value.value.encoding || THREE.LinearEncoding; + var decoding = ColorSpaceNode.prototype.getDecodingMethod(format); + function decode(input) { + return decoding[0] + '( ' + input + + (decoding[1] !== undefined ? ', ' + decoding[1] : '') + + ' )'; + } - var color10 = 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_10 + ' )', - color20 = 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_20 + ' )'; + var color10 = 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_10 + ' )'; + color10 = decode(color10); - builder.removeContext(); + var color20 = 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_20 + ' )'; + color20 = decode(color20); return builder.format( 'vec4( mix( ' + color10 + ', ' + color20 + ', ' + t + ' ).rgb, 1.0 )', this.getType( builder ), output ); diff --git a/examples/webgl_materials_envmaps_node.html b/examples/webgl_materials_envmaps_node.html new file mode 100644 index 00000000000000..a1a54c579f7207 --- /dev/null +++ b/examples/webgl_materials_envmaps_node.html @@ -0,0 +1,313 @@ + + + + threejs webgl - materials - hdr environment mapping + + + + + + +
+
threejs - High dynamic range (RGBE) Image-based Lighting (IBL)
using run-time generated pre-filtered roughness mipmaps (PMREM)
+ Created by Prashant Sharma and Ben Houston.
+ + + + + + + + + + + + + + + + + + From b1a14ec505b2b56f7e09ba406ed0ab0f9dccf2a8 Mon Sep 17 00:00:00 2001 From: Daniel Sturk Date: Thu, 13 Jun 2019 14:39:16 -0400 Subject: [PATCH 3/3] Stupid-proofed TextureCubeNode a little bit better --- examples/js/nodes/misc/TextureCubeNode.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/js/nodes/misc/TextureCubeNode.js b/examples/js/nodes/misc/TextureCubeNode.js index 116fb82d74a693..ae3ab3a8ccb0a4 100644 --- a/examples/js/nodes/misc/TextureCubeNode.js +++ b/examples/js/nodes/misc/TextureCubeNode.js @@ -27,7 +27,8 @@ TextureCubeNode.prototype.generate = function ( builder, output ) { uv_20 = this.uv.build( builder ) + '.uv_20', t = this.uv.build( builder ) + '.t'; - var format = this.value.value.encoding || THREE.LinearEncoding; + var texture = this.value && this.value.value; + var format = texture && texture.encoding || THREE.LinearEncoding; var decoding = ColorSpaceNode.prototype.getDecodingMethod(format); function decode(input) { return decoding[0] + '( ' + input +