Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into utsubo/fix/matrice-o…
Browse files Browse the repository at this point in the history
…perator-fix
  • Loading branch information
RenaudRohlinger committed Jan 21, 2025
2 parents 555e729 + 7e76dc4 commit 068ab77
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/Three.TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const atomicOr = TSL.atomicOr;
export const atomicStore = TSL.atomicStore;
export const atomicSub = TSL.atomicSub;
export const atomicXor = TSL.atomicXor;
export const atomicLoad = TSL.atomicLoad;
export const attenuationColor = TSL.attenuationColor;
export const attenuationDistance = TSL.attenuationDistance;
export const attribute = TSL.attribute;
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { NodeUpdateType, defaultBuildStages, shaderStages } from './constants.js

import {
NumberNodeUniform, Vector2NodeUniform, Vector3NodeUniform, Vector4NodeUniform,
ColorNodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
ColorNodeUniform, Matrix2NodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
} from '../../renderers/common/nodes/NodeUniform.js';

import { stack } from './StackNode.js';
Expand Down Expand Up @@ -2366,6 +2366,7 @@ class NodeBuilder {
if ( type === 'vec3' || type === 'ivec3' || type === 'uvec3' ) return new Vector3NodeUniform( uniformNode );
if ( type === 'vec4' || type === 'ivec4' || type === 'uvec4' ) return new Vector4NodeUniform( uniformNode );
if ( type === 'color' ) return new ColorNodeUniform( uniformNode );
if ( type === 'mat2' ) return new Matrix2NodeUniform( uniformNode );
if ( type === 'mat3' ) return new Matrix3NodeUniform( uniformNode );
if ( type === 'mat4' ) return new Matrix4NodeUniform( uniformNode );

Expand Down
18 changes: 17 additions & 1 deletion src/nodes/gpgpu/AtomicFunctionNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ class AtomicFunctionNode extends TempNode {
const params = [];

params.push( `&${ a.build( builder, inputType ) }` );
params.push( b.build( builder, inputType ) );

if ( b !== null ) {

params.push( b.build( builder, inputType ) );


}

const methodSnippet = `${ builder.getMethod( method, type ) }( ${params.join( ', ' )} )`;

Expand Down Expand Up @@ -166,6 +172,16 @@ export const atomicFunc = ( method, pointerNode, valueNode, storeNode = null ) =

};

/**
* Loads the value stored in the atomic variable.
*
* @function
* @param {Node} pointerNode - An atomic variable or element of an atomic buffer.
* @param {Node?} [storeNode=null] - A variable storing the return value of an atomic operation, typically the value of the atomic variable before the operation.
* @returns {AtomicFunctionNode}
*/
export const atomicLoad = ( pointerNode, storeNode = null ) => atomicFunc( AtomicFunctionNode.ATOMIC_LOAD, pointerNode, null, storeNode );

/**
* Stores a value in the atomic variable.
*
Expand Down
19 changes: 15 additions & 4 deletions src/renderers/common/Textures.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,18 @@ class Textures extends DataMap {

const options = { sampleCount };

if ( ( renderTarget.isXRRenderTarget === true && renderTarget.hasExternalTextures === true ) === false ) {
// when using the WebXR Layers API, the render target uses external textures which
// require no manual updates

if ( renderTarget.isXRRenderTarget === true && renderTarget.hasExternalTextures === true ) {

if ( depthTexture && renderTarget.autoAllocateDepthBuffer === true ) {

this.updateTexture( depthTexture, options );

}

} else {

for ( let i = 0; i < textures.length; i ++ ) {

Expand All @@ -139,11 +150,11 @@ class Textures extends DataMap {

}

}
if ( depthTexture ) {

if ( depthTexture && renderTarget.autoAllocateDepthBuffer !== false ) {
this.updateTexture( depthTexture, options );

this.updateTexture( depthTexture, options );
}

}

Expand Down
38 changes: 37 additions & 1 deletion src/renderers/common/Uniform.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Color } from '../../math/Color.js';
import { Matrix2 } from '../../math/Matrix2.js';
import { Matrix3 } from '../../math/Matrix3.js';
import { Matrix4 } from '../../math/Matrix4.js';
import { Vector2 } from '../../math/Vector2.js';
Expand Down Expand Up @@ -256,6 +257,41 @@ class ColorUniform extends Uniform {

}

/**
* Represents a Matrix2 uniform.
*
* @private
* @augments Uniform
*/
class Matrix2Uniform extends Uniform {

/**
* Constructs a new Number uniform.
*
* @param {String} name - The uniform's name.
* @param {Matrix2} value - The uniform's value.
*/
constructor( name, value = new Matrix2() ) {

super( name, value );

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isMatrix2Uniform = true;

this.boundary = 16;
this.itemSize = 4;

}

}


/**
* Represents a Matrix3 uniform.
*
Expand Down Expand Up @@ -327,5 +363,5 @@ class Matrix4Uniform extends Uniform {
export {
NumberUniform,
Vector2Uniform, Vector3Uniform, Vector4Uniform, ColorUniform,
Matrix3Uniform, Matrix4Uniform
Matrix2Uniform, Matrix3Uniform, Matrix4Uniform
};
12 changes: 5 additions & 7 deletions src/renderers/common/XRManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ArrayCamera } from '../../cameras/ArrayCamera.js';
import { EventDispatcher } from '../../core/EventDispatcher.js';
import { RenderTarget } from '../../core/RenderTarget.js';
import { PerspectiveCamera } from '../../cameras/PerspectiveCamera.js';
import { RAD2DEG } from '../../math/MathUtils.js';
import { Vector2 } from '../../math/Vector2.js';
Expand All @@ -9,6 +8,7 @@ import { Vector4 } from '../../math/Vector4.js';
import { WebXRController } from '../webxr/WebXRController.js';
import { DepthFormat, DepthStencilFormat, RGBAFormat, UnsignedByteType, UnsignedInt248Type, UnsignedIntType } from '../../constants.js';
import { DepthTexture } from '../../textures/DepthTexture.js';
import { XRRenderTarget } from './XRRenderTarget.js';

const _cameraLPos = /*@__PURE__*/ new Vector3();
const _cameraRPos = /*@__PURE__*/ new Vector3();
Expand Down Expand Up @@ -316,7 +316,7 @@ class XRManager extends EventDispatcher {
this._xrFrame = null;

/**
* Whether to use projection layers or not.
* Whether to use the WebXR Layers API or not.
*
* @private
* @type {Boolean}
Expand Down Expand Up @@ -624,7 +624,7 @@ class XRManager extends EventDispatcher {
renderer.setPixelRatio( 1 );
renderer.setSize( glProjLayer.textureWidth, glProjLayer.textureHeight, false );

this._xrRenderTarget = new RenderTarget(
this._xrRenderTarget = new XRRenderTarget(
glProjLayer.textureWidth,
glProjLayer.textureHeight,
{
Expand Down Expand Up @@ -657,7 +657,7 @@ class XRManager extends EventDispatcher {
renderer.setPixelRatio( 1 );
renderer.setSize( glBaseLayer.framebufferWidth, glBaseLayer.framebufferHeight, false );

this._xrRenderTarget = new RenderTarget(
this._xrRenderTarget = new XRRenderTarget(
glBaseLayer.framebufferWidth,
glBaseLayer.framebufferHeight,
{
Expand All @@ -670,8 +670,6 @@ class XRManager extends EventDispatcher {

}

this._xrRenderTarget.isXRRenderTarget = true; // TODO Remove this when possible, see #23278

//

this.setFoveation( this.getFoveation() );
Expand Down Expand Up @@ -1116,7 +1114,7 @@ function onAnimationFrame( time, frame ) {
// For side-by-side projection, we only produce a single texture for both eyes.
if ( i === 0 ) {

backend.setRenderTargetTextures(
backend.setXRRenderTargetTextures(
this._xrRenderTarget,
glSubImage.colorTexture,
this._glProjLayer.ignoreDepthValues ? undefined : glSubImage.depthStencilTexture
Expand Down
74 changes: 74 additions & 0 deletions src/renderers/common/XRRenderTarget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { RenderTarget } from '../../core/RenderTarget.js';

/**
* A special type of render target that is used when rendering
* with the WebXR Device API.
*
* @private
* @augments RenderTarget
*/
class XRRenderTarget extends RenderTarget {

/**
* Constructs a new XR render target.
*
* @param {Number} [width=1] - The width of the render target.
* @param {Number} [height=1] - The height of the render target.
* @param {Object} [options={}] - The configuration options.
*/
constructor( width = 1, height = 1, options = {} ) {

super( width, height, options );

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isXRRenderTarget = true;

/**
* Whether the attachments of the render target
* are defined by external textures. This flag is
* set to `true` when using the WebXR Layers API.
*
* @type {Boolean}
* @default false
*/
this.hasExternalTextures = false;

/**
* Whether a depth buffer should automatically be allocated
* for this XR render target or not.
*
* Allocating a depth buffer is the default behavior of XR render
* targets. However, when using the WebXR Layers API, this flag
* must be set to `false` when the `ignoreDepthValues` property of
* the projection layers evaluates to `true`.
*
* Reference: {@link https://www.w3.org/TR/webxrlayers-1/#dom-xrprojectionlayer-ignoredepthvalues}.
*
* @type {Boolean}
* @default true
*/
this.autoAllocateDepthBuffer = true;

}

copy( source ) {

super.copy( source );

this.hasExternalTextures = source.hasExternalTextures;
this.autoAllocateDepthBuffer = source.autoAllocateDepthBuffer;

return this;

}


}

export { XRRenderTarget };
56 changes: 54 additions & 2 deletions src/renderers/common/nodes/NodeUniform.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
NumberUniform, Vector2Uniform, Vector3Uniform, Vector4Uniform,
ColorUniform, Matrix3Uniform, Matrix4Uniform
ColorUniform, Matrix2Uniform, Matrix3Uniform, Matrix4Uniform
} from '../Uniform.js';

/**
Expand Down Expand Up @@ -258,6 +258,58 @@ class ColorNodeUniform extends ColorUniform {

}


/**
* A special form of Matrix2 uniform binding type.
* It's value is managed by a node object.
*
* @private
* @augments Matrix2Uniform
*/
class Matrix2NodeUniform extends Matrix2Uniform {

/**
* Constructs a new node-based Matrix2 uniform.
*
* @param {NodeUniform} nodeUniform - The node uniform.
*/
constructor( nodeUniform ) {

super( nodeUniform.name, nodeUniform.value );

/**
* The node uniform.
*
* @type {NodeUniform}
*/
this.nodeUniform = nodeUniform;

}

/**
* Overwritten to return the value of the node uniform.
*
* @return {Matrix2} The value.
*/
getValue() {

return this.nodeUniform.value;

}

/**
* Returns the node uniform data type.
*
* @return {String} The data type.
*/
getType() {

return this.nodeUniform.type;

}

}

/**
* A special form of Matrix3 uniform binding type.
* It's value is managed by a node object.
Expand Down Expand Up @@ -362,5 +414,5 @@ class Matrix4NodeUniform extends Matrix4Uniform {

export {
NumberNodeUniform, Vector2NodeUniform, Vector3NodeUniform, Vector4NodeUniform,
ColorNodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
ColorNodeUniform, Matrix2NodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
};
10 changes: 6 additions & 4 deletions src/renderers/webgl-fallback/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,15 @@ class WebGLBackend extends Backend {
}

/**
* Configures the render target with external textures.
* Configures the given XR render target with external textures.
*
* @param {RenderTarget} renderTarget - The render target.
* This method is only relevant when using the WebXR Layers API.
*
* @param {XRRenderTarget} renderTarget - The XR render target.
* @param {WebGLTexture} colorTexture - A native color texture.
* @param {WebGLTexture?} [depthTexture=null] - A native depth texture.
*/
setRenderTargetTextures( renderTarget, colorTexture, depthTexture = null ) {
setXRRenderTargetTextures( renderTarget, colorTexture, depthTexture = null ) {

this.set( renderTarget.texture, { textureGPU: colorTexture } );

Expand Down Expand Up @@ -1929,7 +1931,7 @@ class WebGLBackend extends Backend {
const isRenderTarget3D = renderTarget.isRenderTarget3D === true;
const isRenderTargetArray = renderTarget.isRenderTargetArray === true;
const isXRRenderTarget = renderTarget.isXRRenderTarget === true;
const hasExternalTextures = renderTarget.hasExternalTextures === true;
const hasExternalTextures = ( isXRRenderTarget === true && renderTarget.hasExternalTextures === true );

let msaaFb = renderTargetContextData.msaaFrameBuffer;
let depthRenderbuffer = renderTargetContextData.depthRenderbuffer;
Expand Down

0 comments on commit 068ab77

Please sign in to comment.