Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodes: Add more exports to ShaderNode #23901

Merged
merged 30 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
18 changes: 12 additions & 6 deletions examples/jsm/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ import CondNode from './math/CondNode.js';
import LightContextNode from './lights/LightContextNode.js';
import LightNode from './lights/LightNode.js';
import LightsNode from './lights/LightsNode.js';
import ReflectedLightNode from './lights/ReflectedLightNode.js';

// utils
import ArrayElementNode from './utils/ArrayElementNode.js';
import ConvertNode from './utils/ConvertNode.js';
import JoinNode from './utils/JoinNode.js';
import SplitNode from './utils/SplitNode.js';
import SpriteSheetUVNode from './utils/SpriteSheetUVNode.js';
import MatcapUVNode from './utils/MatcapUVNode.js';
import MaxMipLevelNode from './utils/MaxMipLevelNode.js';
import OscNode from './utils/OscNode.js';
import SplitNode from './utils/SplitNode.js';
import SpriteSheetUVNode from './utils/SpriteSheetUVNode.js';
import TimerNode from './utils/TimerNode.js';

// loaders
Expand Down Expand Up @@ -157,15 +159,17 @@ const nodeLib = {
LightContextNode,
LightNode,
LightsNode,
ReflectedLightNode,

// utils
ArrayElementNode,
ConvertNode,
JoinNode,
SplitNode,
SpriteSheetUVNode,
MatcapUVNode,
MaxMipLevelNode,
OscNode,
SplitNode,
SpriteSheetUVNode,
TimerNode,

// procedural
Expand Down Expand Up @@ -252,15 +256,17 @@ export {
LightContextNode,
LightNode,
LightsNode,
ReflectedLightNode,

// utils
ArrayElementNode,
ConvertNode,
JoinNode,
SplitNode,
SpriteSheetUVNode,
MatcapUVNode,
MaxMipLevelNode,
OscNode,
SplitNode,
SpriteSheetUVNode,
TimerNode,

// procedural
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/nodes/accessors/InstanceNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
instanceIndex,
positionLocal,
normalLocal
} from '../shadernode/ShaderNodeElements.js';
} from '../shadernode/ShaderNodeBaseElements.js';

class InstanceNode extends Node {

Expand All @@ -26,7 +26,7 @@ class InstanceNode extends Node {

const instanceBufferNode = buffer( instanceMesh.instanceMatrix.array, 'mat4', instanceMesh.count );

this.instanceMatrixNode = temp( element( instanceBufferNode, instanceIndex ) );
this.instanceMatrixNode = temp( element( instanceBufferNode, instanceIndex ) ); // @TODO: a possible caching issue here?

}

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/nodes/accessors/ReflectNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Node from '../core/Node.js';
import { nodeObject, normalWorld, positionWorld, cameraPosition, sub, normalize, join, negate, reflect } from '../shadernode/ShaderNodeElements.js';
import { nodeObject, normalWorld, positionWorld, cameraPosition, sub, normalize, vec3, negate, reflect } from '../shadernode/ShaderNodeBaseElements.js';

class ReflectNode extends Node {

Expand Down Expand Up @@ -34,7 +34,7 @@ class ReflectNode extends Node {
} else if ( scope === ReflectNode.CUBE ) {

const reflectVec = nodeObject( new ReflectNode( ReflectNode.VECTOR ) );
const cubeUV = join( negate( reflectVec.x ), reflectVec.yz );
const cubeUV = vec3( negate( reflectVec.x ), reflectVec.yz );

return cubeUV.build( builder );

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/nodes/accessors/SkinningNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Node from '../core/Node.js';
import ShaderNode from '../shadernode/ShaderNode.js';
import {
ShaderNode,
attribute,
buffer,
mat4,
Expand All @@ -12,7 +12,7 @@ import {
add,
mul,
transformDirection
} from '../shadernode/ShaderNodeElements.js';
} from '../shadernode/ShaderNodeBaseElements.js';

import { NodeUpdateType } from '../core/constants.js';

Expand Down
2 changes: 0 additions & 2 deletions examples/jsm/nodes/core/VarNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,4 @@ class VarNode extends Node {

}

VarNode.prototype.isVarNode = true;

export default VarNode;
5 changes: 2 additions & 3 deletions examples/jsm/nodes/display/ColorSpaceNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import TempNode from '../core/Node.js';
import ShaderNode from '../shadernode/ShaderNode.js';
import { vec3, pow, mul, sub, mix, join, lessThanEqual } from '../shadernode/ShaderNodeElements.js';
import { ShaderNode, vec3, pow, mul, sub, mix, vec4, lessThanEqual } from '../shadernode/ShaderNodeBaseElements.js';

import { LinearEncoding, sRGBEncoding } from 'three';

Expand All @@ -22,7 +21,7 @@ export const LinearTosRGB = new ShaderNode( ( inputs ) => {

const rgbResult = mix( a, b, factor );

return join( rgbResult.r, rgbResult.g, rgbResult.b, value.a );
return vec4( rgbResult, value.a );

} );

Expand Down
7 changes: 3 additions & 4 deletions examples/jsm/nodes/display/NormalMapNode.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import TempNode from '../core/TempNode.js';
import ModelNode from '../accessors/ModelNode.js';
import ShaderNode from '../shadernode/ShaderNode.js';
import { positionView, normalView, uv, join, cond, add, sub, mul, dFdx, dFdy, cross, max, dot, normalize, inversesqrt, equal } from '../shadernode/ShaderNodeElements.js';
import { ShaderNode, positionView, normalView, uv, vec3, cond, add, sub, mul, dFdx, dFdy, cross, max, dot, normalize, inverseSqrt, equal } from '../shadernode/ShaderNodeBaseElements.js';

import { TangentSpaceNormalMap, ObjectSpaceNormalMap } from 'three';

Expand All @@ -26,7 +25,7 @@ const perturbNormal2ArbNode = new ShaderNode( ( inputs ) => {
const B = add( mul( q1perp, st0.y ), mul( q0perp, st1.y ) );

const det = max( dot( T, T ), dot( B, B ) );
const scale = cond( equal( det, 0 ), 0, mul( faceDirection, inversesqrt( det ) ) );
const scale = cond( equal( det, 0 ), 0, mul( faceDirection, inverseSqrt( det ) ) );

return normalize( add( mul( T, mul( mapN.x, scale ) ), mul( B, mul( mapN.y, scale ) ), mul( N, mapN.z ) ) );

Expand Down Expand Up @@ -57,7 +56,7 @@ class NormalMapNode extends TempNode {
if ( scaleNode !== null ) {

const normalMapScale = mul( normalMap.xy, scaleNode );
normalMap = join( normalMapScale, normalMap.z );
normalMap = vec3( normalMapScale, normalMap.z );
sunag marked this conversation as resolved.
Show resolved Hide resolved

}

Expand Down
3 changes: 1 addition & 2 deletions examples/jsm/nodes/display/ToneMappingNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import TempNode from '../core/Node.js';
import ShaderNode from '../shadernode/ShaderNode.js';
import { mul, float } from '../shadernode/ShaderNodeElements.js';
import { ShaderNode, mul, float } from '../shadernode/ShaderNodeBaseElements.js';

import { LinearToneMapping } from 'three';

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/nodes/fog/FogRangeNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FogNode from './FogNode.js';
import { smoothstep, negate, positionView } from '../shadernode/ShaderNodeElements.js';
import { smoothstep, negate, positionView } from '../shadernode/ShaderNodeBaseElements.js';

class FogRangeNode extends FogNode {

Expand Down
5 changes: 2 additions & 3 deletions examples/jsm/nodes/functions/BSDF/BRDF_GGX.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import F_Schlick from './F_Schlick.js';
import V_GGX_SmithCorrelated from './V_GGX_SmithCorrelated.js';
import D_GGX from './D_GGX.js';
import ShaderNode from '../../shadernode/ShaderNode.js';
import {
dotNV, add, mul, saturate, dot, pow2, normalize,
ShaderNode, dotNV, add, mul, saturate, dot, pow2, normalize,
transformedNormalView, positionViewDirection
} from '../../shadernode/ShaderNodeElements.js';
} from '../../shadernode/ShaderNodeBaseElements.js';

// GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility
const BRDF_GGX = new ShaderNode( ( inputs ) => {
Expand Down
3 changes: 1 addition & 2 deletions examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ShaderNode from '../../shadernode/ShaderNode.js';
import { mul } from '../../shadernode/ShaderNodeElements.js';
import { ShaderNode, mul } from '../../shadernode/ShaderNodeBaseElements.js';

const BRDF_Lambert = new ShaderNode( ( inputs ) => {

Expand Down
3 changes: 1 addition & 2 deletions examples/jsm/nodes/functions/BSDF/D_GGX.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ShaderNode from '../../shadernode/ShaderNode.js';
import { add, sub, mul, div, pow2 } from '../../shadernode/ShaderNodeElements.js';
import { ShaderNode, add, sub, mul, div, pow2 } from '../../shadernode/ShaderNodeBaseElements.js';

// Microfacet Models for Refraction through Rough Surfaces - equation (33)
// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
Expand Down
3 changes: 1 addition & 2 deletions examples/jsm/nodes/functions/BSDF/F_Schlick.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ShaderNode from '../../shadernode/ShaderNode.js';
import { add, sub, mul, exp2 } from '../../shadernode/ShaderNodeElements.js';
import { ShaderNode, add, sub, mul, exp2 } from '../../shadernode/ShaderNodeBaseElements.js';

const F_Schlick = new ShaderNode( ( inputs ) => {

Expand Down
3 changes: 1 addition & 2 deletions examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ShaderNode from '../../shadernode/ShaderNode.js';
import { add, sub, mul, div, pow2, max, sqrt, EPSILON } from '../../shadernode/ShaderNodeElements.js';
import { ShaderNode, add, sub, mul, div, pow2, max, sqrt, EPSILON } from '../../shadernode/ShaderNodeBaseElements.js';

// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2
// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
Expand Down
5 changes: 2 additions & 3 deletions examples/jsm/nodes/functions/PhysicalLightingModel.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import BRDF_Lambert from './BSDF/BRDF_Lambert.js';
import BRDF_GGX from './BSDF/BRDF_GGX.js';
import ShaderNode from '../shadernode/ShaderNode.js';
import {
mul, saturate, dot, transformedNormalView,
ShaderNode, mul, saturate, dot, transformedNormalView,
diffuseColor, specularColor, roughness
} from '../shadernode/ShaderNodeElements.js';
} from '../shadernode/ShaderNodeBaseElements.js';

const RE_Direct_Physical = new ShaderNode( ( inputs ) => {

Expand Down
5 changes: 2 additions & 3 deletions examples/jsm/nodes/functions/light/getDistanceAttenuation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ShaderNode from '../../shadernode/ShaderNode.js';
import {
div, max, sub, mul, saturate, pow, pow2, pow4, cond, greaterThan
} from '../../shadernode/ShaderNodeElements.js';
ShaderNode, div, max, sub, mul, saturate, pow, pow2, pow4, cond, greaterThan
} from '../../shadernode/ShaderNodeBaseElements.js';

const getDistanceAttenuation = new ShaderNode( ( inputs ) => {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ShaderNode from '../../shadernode/ShaderNode.js';
import { max, abs, dFdx, dFdy, normalGeometry } from '../../shadernode/ShaderNodeElements.js';
import { ShaderNode, max, abs, dFdx, dFdy, normalGeometry } from '../../shadernode/ShaderNodeBaseElements.js';

const getGeometryRoughness = new ShaderNode( () => {

Expand Down
3 changes: 1 addition & 2 deletions examples/jsm/nodes/functions/material/getRoughness.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import getGeometryRoughness from './getGeometryRoughness.js';
import ShaderNode from '../../shadernode/ShaderNode.js';
import { add, max, min } from '../../shadernode/ShaderNodeElements.js';
import { ShaderNode, add, max, min } from '../../shadernode/ShaderNodeBaseElements.js';

const getRoughness = new ShaderNode( ( inputs ) => {

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/nodes/lights/LightContextNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ContextNode from '../core/ContextNode.js';
import { reflectedLight } from '../shadernode/ShaderNodeElements.js';
import { reflectedLight } from '../shadernode/ShaderNodeBaseElements.js';

class LightContextNode extends ContextNode {

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/nodes/math/MathNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MathNode extends TempNode {
static LOG = 'log';
static LOG2 = 'log2';
static SQRT = 'sqrt';
static INV_SQRT = 'inversesqrt';
static INVERSE_SQRT = 'inversesqrt';
static FLOOR = 'floor';
static CEIL = 'ceil';
static NORMALIZE = 'normalize';
Expand Down
3 changes: 1 addition & 2 deletions examples/jsm/nodes/procedural/CheckerNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Node from '../core/Node.js';
import ShaderNode from '../shadernode/ShaderNode.js';
import { uv, add, mul, floor, mod, sign } from '../shadernode/ShaderNodeElements.js';
import { ShaderNode, uv, add, mul, floor, mod, sign } from '../shadernode/ShaderNodeBaseElements.js';

const checkerShaderNode = new ShaderNode( ( inputs ) => {

Expand Down
Loading