Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/webgpu_compute_particles_snow.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@

const rippleOnSurface = texture( collisionPosRT.texture, getCoord( position.xz ) ).toInspector( 'Collision Test', () => {

return texture( collisionPosRT.texture ).r; // .div( collisionCamera.position.y );
return texture( collisionPosRT.texture ); // .div( collisionCamera.position.y );

} );

const rippleFloorArea = rippleOnSurface.r.add( scale.x.mul( surfaceOffset ) );
const rippleFloorArea = rippleOnSurface.add( scale.x.mul( surfaceOffset ) );

If( position.y.greaterThan( rippleFloorArea ), () => {

Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_postprocessing_ssgi.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
const ao = giPass.getAONode().toInspector( 'SSGI.AO' );
const gi = giPass.getGINode().toInspector( 'SSGI.GI' );

const compositePass = vec4( add( scenePassColor.rgb.mul( ao.r ), ( scenePassDiffuse.rgb.mul( gi.rgb ) ) ), scenePassColor.a );
const compositePass = vec4( add( scenePassColor.rgb.mul( ao ), ( scenePassDiffuse.rgb.mul( gi.rgb ) ) ), scenePassColor.a );
compositePass.name = 'Composite';

// traa
Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_postprocessing_ssgi_ballpool.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
const gi = giPass.getGINode().toInspector( 'SSGI.GI' );

const compositePass = vec4(
add( scenePassColor.rgb.mul( ao.r ), scenePassDiffuse.rgb.mul( gi.rgb ) ),
add( scenePassColor.rgb.mul( ao ), scenePassDiffuse.rgb.mul( gi.rgb ) ),
scenePassColor.a
);

Expand Down
39 changes: 18 additions & 21 deletions src/nodes/accessors/TextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { maxMipLevel } from '../utils/MaxMipLevelNode.js';
import { nodeProxy, vec3, nodeObject, int, Fn } from '../tsl/TSLBase.js';
import { step } from '../math/MathNode.js';
import { NodeUpdateType } from '../core/constants.js';
import { getTextureType } from '../core/NodeUtils.js';

import { Compatibility, GreaterCompare, GreaterEqualCompare, IntType, LessCompare, LessEqualCompare, NearestFilter, UnsignedIntType } from '../../constants.js';

Expand Down Expand Up @@ -228,25 +229,13 @@ class TextureNode extends UniformNode {
*/
generateNodeType( /*builder*/ ) {

if ( this.value.isDepthTexture === true ) {

if ( this.gatherNode === null ) return 'float';
if ( this.gatherNode !== null ) {

return 'vec4';

}

if ( this.value.type === UnsignedIntType ) {

return 'uvec4';

} else if ( this.value.type === IntType ) {

return 'ivec4';

}

return 'vec4';
return getTextureType( this.value );

}

Expand Down Expand Up @@ -566,7 +555,7 @@ class TextureNode extends UniformNode {

const nodeData = builder.getDataFromNode( this );

let nodeType = this.getNodeType( builder );
const nodeType = this.getNodeType( builder );

let propertyName = nodeData.propertyName;

Expand All @@ -585,12 +574,6 @@ class TextureNode extends UniformNode {
const offsetSnippet = offsetNode ? this.generateOffset( builder, offsetNode ) : null;
const flipYSnippet = this._flipYUniform ? this._flipYUniform.build( builder, 'bool' ) : null;

if ( gatherSnippet ) {

nodeType = 'vec4';

}

let finalDepthSnippet = depthSnippet;

if ( finalDepthSnippet === null && texture.isArrayTexture && this.isTexture3DNode !== true ) {
Expand All @@ -605,6 +588,20 @@ class TextureNode extends UniformNode {

let snippet = this.generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, biasSnippet, finalDepthSnippet, compareSnippet, gradSnippet, gatherSnippet, offsetSnippet, flipYSnippet );

let snippetType;

if ( texture.isDepthTexture === true && gatherSnippet === null ) {

snippetType = 'float';

} else {

snippetType = texture.type === UnsignedIntType ? 'uvec4' : ( texture.type === IntType ? 'ivec4' : 'vec4' );

}

snippet = builder.format( snippet, snippetType, nodeType );

if ( compareStepSnippet !== null ) {

const compareFunction = texture.compareFunction;
Expand Down
43 changes: 4 additions & 39 deletions src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ParameterNode from './ParameterNode.js';
import StructType from './StructType.js';
import FunctionNode from '../code/FunctionNode.js';
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
import { getDataFromObject, getTypeFromLength, hashString } from './NodeUtils.js';
import { getDataFromObject, getTypeFromLength, getTextureType, hashString } from './NodeUtils.js';
import { NodeUpdateType, defaultBuildStages, shaderStages } from './constants.js';

import {
Expand All @@ -23,7 +23,7 @@ import CubeRenderTarget from '../../renderers/common/CubeRenderTarget.js';

import BindGroup from '../../renderers/common/BindGroup.js';

import { REVISION, IntType, UnsignedIntType, LinearFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter, NormalBlending, RedFormat, RGFormat, RGBFormat, RedIntegerFormat, RGIntegerFormat, RGBIntegerFormat } from '../../constants.js';
import { REVISION, IntType, UnsignedIntType, LinearFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter, NormalBlending } from '../../constants.js';
import { RenderTarget } from '../../core/RenderTarget.js';
import { Color } from '../../math/Color.js';
import { Vector2 } from '../../math/Vector2.js';
Expand Down Expand Up @@ -573,50 +573,15 @@ class NodeBuilder {
*/
getOutputType( index = 0 ) {

let type = 'vec4';

const renderTarget = this.renderer.getRenderTarget();

if ( renderTarget !== null ) {

const renderTargetType = renderTarget.textures[ index ].type;
const renderTargetFormat = renderTarget.textures[ index ].format;

let typeStr = 'vec';

if ( renderTargetType === IntType ) {

typeStr = 'ivec';

} else if ( renderTargetType === UnsignedIntType ) {

typeStr = 'uvec';

}

if ( renderTargetFormat === RedFormat || renderTargetFormat === RedIntegerFormat ) {

if ( renderTargetType === IntType ) type = 'int';
else if ( renderTargetType === UnsignedIntType ) type = 'uint';
else type = 'float';

} else if ( renderTargetFormat === RGFormat || renderTargetFormat === RGIntegerFormat ) {

type = `${ typeStr }2`;

} else if ( renderTargetFormat === RGBFormat || renderTargetFormat === RGBIntegerFormat ) {

type = `${ typeStr }3`;

} else {

type = `${ typeStr }4`;

}
return getTextureType( renderTarget.textures[ index ] );

}

return type;
return 'vec4';

}

Expand Down
82 changes: 82 additions & 0 deletions src/nodes/core/NodeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ import { Vector2 } from '../../math/Vector2.js';
import { Vector3 } from '../../math/Vector3.js';
import { Vector4 } from '../../math/Vector4.js';

import {
IntType,
UnsignedIntType,
AlphaFormat,
RedFormat,
RedIntegerFormat,
RGFormat,
RGIntegerFormat,
RGBFormat,
RGBIntegerFormat,
DepthFormat,
DepthStencilFormat
} from '../../constants.js';

import { error } from '../../utils.js';
import StackTrace from '../core/StackTrace.js';

Expand Down Expand Up @@ -276,6 +290,74 @@ export function getValueType( value ) {

}

/**
* Returns the node data type for the given texture.
*
* @private
* @method
* @param {Texture} texture - The texture.
* @return {string} The data type.
*/
export function getTextureType( texture ) {

if ( texture.isDepthTexture === true ) {

return 'float';

}

const format = texture.format;

let length;

if ( format === RedFormat || format === RedIntegerFormat || format === DepthFormat || format === DepthStencilFormat || format === AlphaFormat ) {

length = 1;

} else if ( format === RGFormat || format === RGIntegerFormat ) {

length = 2;

} else if ( format === RGBFormat || format === RGBIntegerFormat ) {

length = 3;

} else {

length = 4;

}

let componentType;

if ( texture.type === UnsignedIntType ) {

componentType = 'uint';

} else if ( texture.type === IntType ) {

componentType = 'int';

} else {

componentType = 'float';

}

if ( length === 1 ) return componentType;

let baseType = getTypeFromLength( length );

if ( componentType !== 'float' ) {

baseType = componentType[ 0 ] + baseType;

}

return baseType;

}

/**
* Returns the value/object for the given data type and parameters.
*
Expand Down
Loading