From 77a712c033faef713c9fd9878a18f4d9cc688bf4 Mon Sep 17 00:00:00 2001 From: Ada Rose Cannon Date: Tue, 21 Sep 2021 12:39:06 +0100 Subject: [PATCH 1/2] set the same wrapping properties for distortionTextures so that they match the main source texture --- src/systems/material.js | 32 +------------------------------- src/utils/material.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/systems/material.js b/src/systems/material.js index fa4de1d7a1c..a142f68d79a 100755 --- a/src/systems/material.js +++ b/src/systems/material.js @@ -2,6 +2,7 @@ var registerSystem = require('../core/system').registerSystem; var THREE = require('../lib/three'); var utils = require('../utils/'); var isHLS = require('../utils/material').isHLS; +var setTextureProperties = require('../utils/material').setTextureProperties; var bind = utils.bind; var debug = utils.debug; @@ -317,37 +318,6 @@ function loadImageTexture (src, data) { } } -/** - * Set texture properties such as repeat and offset. - * - * @param {object} data - With keys like `repeat`. - */ -function setTextureProperties (texture, data) { - var offset = data.offset || {x: 0, y: 0}; - var repeat = data.repeat || {x: 1, y: 1}; - var npot = data.npot || false; - - // To support NPOT textures, wrap must be ClampToEdge (not Repeat), - // and filters must not use mipmaps (i.e. Nearest or Linear). - if (npot) { - texture.wrapS = THREE.ClampToEdgeWrapping; - texture.wrapT = THREE.ClampToEdgeWrapping; - texture.magFilter = THREE.LinearFilter; - texture.minFilter = THREE.LinearFilter; - } - - // Don't bother setting repeat if it is 1/1. Power-of-two is required to repeat. - if (repeat.x !== 1 || repeat.y !== 1) { - texture.wrapS = THREE.RepeatWrapping; - texture.wrapT = THREE.RepeatWrapping; - texture.repeat.set(repeat.x, repeat.y); - } - // Don't bother setting offset if it is 0/0. - if (offset.x !== 0 || offset.y !== 0) { - texture.offset.set(offset.x, offset.y); - } -} - /** * Create video element to be used as a texture. * diff --git a/src/utils/material.js b/src/utils/material.js index 6270a121500..e5ce651b388 100644 --- a/src/utils/material.js +++ b/src/utils/material.js @@ -9,6 +9,36 @@ var COLOR_MAPS = new Set([ 'specularMap' ]); +/** + * Set texture properties such as repeat and offset. + * + * @param {object} data - With keys like `repeat`. +*/ +module.exports.setTextureProperties = function (texture, data) { + var offset = data.offset || {x: 0, y: 0}; + var repeat = data.repeat || {x: 1, y: 1}; + var npot = data.npot || false; + // To support NPOT textures, wrap must be ClampToEdge (not Repeat), + // and filters must not use mipmaps (i.e. Nearest or Linear). + if (npot) { + texture.wrapS = THREE.ClampToEdgeWrapping; + texture.wrapT = THREE.ClampToEdgeWrapping; + texture.magFilter = THREE.LinearFilter; + texture.minFilter = THREE.LinearFilter; + } + + // Don't bother setting repeat if it is 1/1. Power-of-two is required to repeat. + if (repeat.x !== 1 || repeat.y !== 1) { + texture.wrapS = THREE.RepeatWrapping; + texture.wrapT = THREE.RepeatWrapping; + texture.repeat.set(repeat.x, repeat.y); + } + // Don't bother setting offset if it is 0/0. + if (offset.x !== 0 || offset.y !== 0) { + texture.offset.set(offset.x, offset.y); + } +}; + /** * Update `material` texture property (usually but not always `map`) * from `data` property (usually but not always `src`) @@ -118,6 +148,9 @@ module.exports.updateDistortionMap = function (longType, shader, data) { if (texture && COLOR_MAPS.has(slot)) { rendererSystem.applyColorCorrection(texture); } + if (texture) { + module.exports.setTextureProperties(texture, data); + } material.needsUpdate = true; handleTextureEvents(el, texture); } From 8455ab2982b98ac4261565567b485bbb55f2bf27 Mon Sep 17 00:00:00 2001 From: Ada Rose Cannon Date: Tue, 21 Sep 2021 18:31:29 +0100 Subject: [PATCH 2/2] tidy function call --- src/utils/material.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/material.js b/src/utils/material.js index e5ce651b388..489ca3c54b3 100644 --- a/src/utils/material.js +++ b/src/utils/material.js @@ -14,7 +14,7 @@ var COLOR_MAPS = new Set([ * * @param {object} data - With keys like `repeat`. */ -module.exports.setTextureProperties = function (texture, data) { +function setTextureProperties (texture, data) { var offset = data.offset || {x: 0, y: 0}; var repeat = data.repeat || {x: 1, y: 1}; var npot = data.npot || false; @@ -37,7 +37,8 @@ module.exports.setTextureProperties = function (texture, data) { if (offset.x !== 0 || offset.y !== 0) { texture.offset.set(offset.x, offset.y); } -}; +} +module.exports.setTextureProperties = setTextureProperties; /** * Update `material` texture property (usually but not always `map`) @@ -149,7 +150,7 @@ module.exports.updateDistortionMap = function (longType, shader, data) { rendererSystem.applyColorCorrection(texture); } if (texture) { - module.exports.setTextureProperties(texture, data); + setTextureProperties(texture, data); } material.needsUpdate = true; handleTextureEvents(el, texture);