Skip to content

Conversation

@mrxz
Copy link
Contributor

@mrxz mrxz commented Feb 8, 2024

Description:
Preparation work for #5449. Both utils.materials.updateMap and utils.materials.updateDistortionMap are used for setting texture maps. These methods had similar, but slightly different implementations. This PR unifies them by letting updateDistortionMap call updateMapMaterialFromData.

Removing these maps or changing texture properties are now also correctly handle. Before only the diffuse map could be removed when changing the map properties of the standard and phong shader. In case texture properties are changed that require a texture update, the needsUpdate flag is now also set. Note: textures are still shared based on their initial properties, this will be addressed in upcoming PRs.

Changes proposed:

  • Use updateMapMaterialFromData in updateDistortionMap aligning it with updateMap
  • Always call texture map update methods to allow removing textures (standard and phong shaders)
  • Let setTextureProperties set needsUpdate on the texture when a property changes that requires it
  • Add unit tests for testing unsetting maps and changing texture property requiring needsUpdate

update: function (data) {
this.updateMaterial(data);
utils.material.updateMap(this, data);
if (data.normalMap) { utils.material.updateDistortionMap('normal', this, data); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guards no longer needed?

Copy link
Contributor Author

@mrxz mrxz Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guards prevented these textures from being removed. Similar to how the main (diffuse) map is handled, the underlying implementation of updateMapMaterialFromData checks if the texture is added, changed or removed, or if only the texture properties are updated.

texture.repeat.set(repeat.x, repeat.y);
}
// Don't bother setting offset if it is 0/0.
if (offset.x !== 0 || offset.y !== 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guard no longer needed?

Copy link
Contributor Author

@mrxz mrxz Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guard actually prevented offset from being set back to 0/0 after being set to something else. On top of that, changing the offset doesn't require a texture update, so there's nothing gained by skipping this.

update: function (data) {
this.updateMaterial(data);
utils.material.updateMap(this, data);
if (data.normalMap) { utils.material.updateDistortionMap('normal', this, data); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checks no needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for standard.js

this.textureSrc = null;
getMaterialData(data, this.materialData);
this.material = new THREE.MeshPhongMaterial(this.materialData);
utils.material.updateMap(this, data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove because of redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this is in the init method, which is followed by update which also calls updateMap. Both flat and standard let the update handle this and phong was the odd one out.

@dmarcos
Copy link
Member

dmarcos commented Feb 9, 2024

Thanks!

@dmarcos dmarcos merged commit 580d94a into aframevr:master Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants