From 0426cf02769996c346a3aa58a5a0c5d58b196497 Mon Sep 17 00:00:00 2001 From: sunag Date: Thu, 18 Oct 2018 23:48:47 -0300 Subject: [PATCH 1/3] triplanar-mapping --- examples/webgl_materials_nodes.html | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/examples/webgl_materials_nodes.html b/examples/webgl_materials_nodes.html index 85dc81a9906cbc..45e3970ac5a991 100644 --- a/examples/webgl_materials_nodes.html +++ b/examples/webgl_materials_nodes.html @@ -186,6 +186,7 @@ 'adv / soft-body': 'soft-body', 'adv / wave': 'wave', 'adv / triangle-blur': 'triangle-blur', + 'adv / triplanar-mapping': 'triplanar-mapping', 'adv / render-to-texture': 'rtt', 'adv / temporal-blur': 'temporal-blur', 'adv / conditional': 'conditional', @@ -2385,6 +2386,56 @@ break; + case 'triplanar-mapping': + + // MATERIAL + + mtl = new THREE.PhongNodeMaterial(); + + var scale = new THREE.FloatNode( .02 ); + + var triplanarMapping = new THREE.FunctionNode( [ + // Reference: https://github.com/keijiro/StandardTriplanar + // Blending factor of triplanar mapping + "vec4 triplanar_mapping( sampler2D texture, vec3 normal, vec3 position, float scale ) {", + + " vec3 bf = normalize( abs( normal ) );", + " bf /= dot( bf, vec3( 1.0 ) );", + + // Triplanar mapping + " vec2 tx = position.yz * scale;", + " vec2 ty = position.zx * scale;", + " vec2 tz = position.xy * scale;", + + // Base color texture2D( texture, uv + delta * percent ) + " vec4 cx = tex2D(texture, tx) * bf.x;", + " vec4 cy = tex2D(texture, ty) * bf.y;", + " vec4 cz = tex2D(texture, tz) * bf.z;", + + " return cx + cy + cz;", + + "}" + ].join( "\n" ) ); + + var triplanarMappingTexture = new THREE.FunctionCallNode( triplanarMapping, { + texture: new THREE.TextureNode( getTexture( "brick" ) ), + normal: new THREE.NormalNode( THREE.NormalNode.WORLD ), + position: new THREE.PositionNode( THREE.PositionNode.WORLD ), + scale: scale, + } ); + + mtl.color = triplanarMappingTexture; + + // GUI + + addGui( 'scale', scale.value, function ( val ) { + + scale.value = val; + + }, false, 0.001, .1 ); + + break; + case 'firefly': // MATERIAL From 27e67ae613646c44eb166d2398b9e1c121d6e711 Mon Sep 17 00:00:00 2001 From: sunag Date: Thu, 18 Oct 2018 23:55:27 -0300 Subject: [PATCH 2/3] cleanup --- examples/webgl_materials_nodes.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/webgl_materials_nodes.html b/examples/webgl_materials_nodes.html index 45e3970ac5a991..2bfe541464fe81 100644 --- a/examples/webgl_materials_nodes.html +++ b/examples/webgl_materials_nodes.html @@ -2407,10 +2407,10 @@ " vec2 ty = position.zx * scale;", " vec2 tz = position.xy * scale;", - // Base color texture2D( texture, uv + delta * percent ) - " vec4 cx = tex2D(texture, tx) * bf.x;", - " vec4 cy = tex2D(texture, ty) * bf.y;", - " vec4 cz = tex2D(texture, tz) * bf.z;", + // Base color + " vec4 cx = texture2D(texture, tx) * bf.x;", + " vec4 cy = texture2D(texture, ty) * bf.y;", + " vec4 cz = texture2D(texture, tz) * bf.z;", " return cx + cy + cz;", From 806102dee61fd789ddd223157cd3bef58717c976 Mon Sep 17 00:00:00 2001 From: sunag Date: Thu, 18 Oct 2018 23:56:55 -0300 Subject: [PATCH 3/3] blend factor comments --- examples/webgl_materials_nodes.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/webgl_materials_nodes.html b/examples/webgl_materials_nodes.html index 2bfe541464fe81..f396e0062482b8 100644 --- a/examples/webgl_materials_nodes.html +++ b/examples/webgl_materials_nodes.html @@ -2396,9 +2396,9 @@ var triplanarMapping = new THREE.FunctionNode( [ // Reference: https://github.com/keijiro/StandardTriplanar - // Blending factor of triplanar mapping "vec4 triplanar_mapping( sampler2D texture, vec3 normal, vec3 position, float scale ) {", + // Blending factor of triplanar mapping " vec3 bf = normalize( abs( normal ) );", " bf /= dot( bf, vec3( 1.0 ) );",