Skip to content

Commit

Permalink
Fix darkened video-texture-target
Browse files Browse the repository at this point in the history
This commit fixes darkened video-texture-target problem
caused when upgrading our Three.js to r141.

Refer to "Fix darkened camera view" commit for the details
because the root issue is same.

The previous same purpose commit was reverted because
it didn't work correctly because of losing
material.onBeforeRender when cloning materials.
This commit resolves it by copying the function.
  • Loading branch information
takahirox committed Jul 26, 2022
1 parent cce5562 commit baacf7c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/tools/pen-laser.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ AFRAME.registerComponent("pen-laser", {
material = convertStandardMaterial(material, quality);

const tipMaterial = material.clone();
tipMaterial.onBeforeRender = material.onBeforeRender;

const lineCurve = new THREE.LineCurve3(new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, 0, 2));
const geometry = new THREE.TubeBufferGeometry(lineCurve, 2, 0.003, 8, true);
Expand Down
5 changes: 2 additions & 3 deletions src/components/video-texture-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,8 @@ AFRAME.registerComponent("video-texture-target", {
const texture = videoTextureSource.renderTarget.texture;
this.applyTexture(texture);

// Bit of a hack here to only update the renderTarget when the screens are in view
material.map.isVideoTexture = true;
material.map.update = () => {
// Only update the renderTarget when the screens are in view
material.onBeforeRender = () => {
videoTextureSource.textureNeedsUpdate = true;
};
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/material-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class HubsMeshBasicMaterial extends THREE.MeshBasicMaterial {
const material = new HubsMeshBasicMaterial();

THREE.Material.prototype.copy.call(material, source);
material.onBeforeRender = source.onBeforeRender;

material.color.copy(source.color);

Expand Down Expand Up @@ -130,6 +131,7 @@ class HubsMeshPhongMaterial extends THREE.MeshPhongMaterial {
const material = new HubsMeshPhongMaterial();

THREE.Material.prototype.copy.call(material, source);
material.onBeforeRender = source.onBeforeRender;

material.color.copy(source.color);

Expand Down
1 change: 1 addition & 0 deletions src/utils/media-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export function injectCustomShaderChunks(obj) {
return material;

const newMaterial = material.clone();
newMaterial.onBeforeRender = material.onBeforeRender;
newMaterial.onBeforeCompile = (shader, renderer) => {
if (shader.vertexShader.indexOf("#include <skinning_vertex>") == -1) return;

Expand Down

0 comments on commit baacf7c

Please sign in to comment.