Skip to content

Commit

Permalink
LightingModel: New class struct (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
Methuselah96 authored Jan 20, 2024
1 parent bf36f1d commit bb4c8d3
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 32 deletions.
11 changes: 9 additions & 2 deletions types/three/examples/jsm/nodes/Nodes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export { default as BypassNode, bypass } from './core/BypassNode.js';
export { default as CacheNode, cache } from './core/CacheNode.js';
export { default as ConstNode } from './core/ConstNode.js';
export { default as ContextNode, context, label } from './core/ContextNode.js';
export {
default as LightingModel,
LightingModelReflectedLight,
LightingModelDirectInput,
LightingModelIndirectInput,
} from './core/LightingModel.js';
export { default as Node } from './core/Node.js';
export { default as NodeAttribute } from './core/NodeAttribute.js';
export { default as NodeBuilder } from './core/NodeBuilder.js';
Expand Down Expand Up @@ -330,7 +336,7 @@ export { default as PointLightNode } from './lighting/PointLightNode.js';
export { default as SpotLightNode } from './lighting/SpotLightNode.js';
export { default as LightsNode, lights } from './lighting/LightsNode.js';
export { default as LightingNode } from './lighting/LightingNode.js';
export { default as LightingContextNode, lightingContext, LightingModelNode } from './lighting/LightingContextNode.js';
export { default as LightingContextNode, lightingContext } from './lighting/LightingContextNode.js';
export { default as HemisphereLightNode } from './lighting/HemisphereLightNode.js';
export { default as EnvironmentNode } from './lighting/EnvironmentNode.js';
export { default as AONode } from './lighting/AONode.js';
Expand Down Expand Up @@ -363,4 +369,5 @@ export { getDistanceAttenuation } from './lighting/LightUtils.js';
export { default as getGeometryRoughness } from './functions/material/getGeometryRoughness.js';
export { default as getRoughness } from './functions/material/getRoughness.js';

export { default as physicalLightingModel } from './functions/PhysicalLightingModel.js';
export { default as PhongLightingModel } from './functions/PhongLightingModel.js';
export { default as PhysicalLightingModel } from './functions/PhysicalLightingModel.js';
36 changes: 36 additions & 0 deletions types/three/examples/jsm/nodes/core/LightingModel.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Node from './Node.js';
import NodeBuilder from './NodeBuilder.js';
import StackNode from './StackNode.js';

export interface LightingModelReflectedLight {
directDiffuse: Node;
directSpecular: Node;
indirectDiffuse: Node;
indirectSpecular: Node;
}

export interface LightingModelDirectInput {
lightDirection: Node;
lightColor: Node;
reflectedLight: LightingModelReflectedLight;
}

export interface LightingModelIndirectInput {
radiance: Node;
irradiance: Node;
iblIrradiance: Node;
ambientOcclusion: Node;
reflectedLight: LightingModelReflectedLight;
backdrop: Node;
backdropAlpha: Node;
outgoingLight: Node;
}

export default class LightingModel {
start(input: LightingModelIndirectInput, stack: StackNode, builder: NodeBuilder): void;
finish(input: LightingModelIndirectInput, stack: StackNode, builder: NodeBuilder): void;
direct(input: LightingModelDirectInput, stack: StackNode, builder: NodeBuilder): void;
indirectDiffuse(input: LightingModelIndirectInput, stack: StackNode, builder: NodeBuilder): void;
indirectSpecular(input: LightingModelIndirectInput, stack: StackNode, builder: NodeBuilder): void;
ambientOcclusion(input: LightingModelIndirectInput, stack: StackNode, builder: NodeBuilder): void;
}
3 changes: 2 additions & 1 deletion types/three/examples/jsm/nodes/core/NodeBuilder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import NodeParser from './NodeParser.js';
import NodeUniform from './NodeUniform.js';
import NodeVar from './NodeVar.js';
import NodeVarying from './NodeVarying.js';
import StackNode from './StackNode.js';

export type BuildStageOption = 'construct' | 'analyze' | 'generate';

Expand Down Expand Up @@ -60,7 +61,7 @@ export default abstract class NodeBuilder {

shaderStage: NodeShaderStage | null;
buildStage: BuildStageOption | null;
stack: Node[];
stack: StackNode;

setHashNode(node: Node, hash: string): void;
addNode(node: Node): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import LightingModel from '../core/LightingModel.js';

export default class PhongLightingModel extends LightingModel {
specular: boolean;

constructor(specular?: boolean);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { ShaderNode } from '../shadernode/ShaderNode.js';
import LightingModel from '../core/LightingModel.js';
import Node from '../core/Node.js';

declare const PhysicalLightingModel: {
direct: ShaderNode<{ lightDirection: Node; lightColor: Node; reflectedLight: Node }>;
indirectDiffuse: ShaderNode<{ irradiance: Node; reflectedLight: Node }>;
indirectSpecular: ShaderNode<{ radiance: Node; iblIrradiance: Node; reflectedLight: Node }>;
ambientOcclusion: ShaderNode<{ ambientOcclusion: Node; reflectedLight: Node }>;
};
export default class PhysicalLightingModel extends LightingModel {
clearcoat: boolean;
sheen: boolean;
iridescence: boolean;

export default PhysicalLightingModel;
clearcoatRadiance: Node | null;
clearcoatSpecularDirect: Node | null;
clearcoatSpecularIndirect: Node | null;
sheenSpecularDirect: Node | null;
sheenSpecularIndirect: Node | null;
iridescenceFresnel: Node | null;
iridescenceF0: Node | null;

constructor(clearcoat?: boolean, sheen?: boolean, iridescence?: boolean);

computeMultiscattering(singleScatter: Node, multiScatter: Node, specularF90?: Node): void;
}
27 changes: 14 additions & 13 deletions types/three/examples/jsm/nodes/lighting/LightingContextNode.d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import ContextNode from '../core/ContextNode.js';
import Node from '../core/Node.js';
import { ShaderNode, ShaderNodeObject } from '../shadernode/ShaderNode.js';

export interface LightingModelNode {
indirectDiffuse?: ShaderNode;
indirectSpecular?: ShaderNode;
ambientOcclusion?: ShaderNode;
}
import { ShaderNodeObject } from '../shadernode/ShaderNode.js';
import LightingModel, { LightingModelIndirectInput } from '../core/LightingModel.js';

export default class LightingContextNode extends ContextNode {
lightingModelNode: LightingModelNode | null;
lightingModelNode: LightingModel | null;
backdropNode: Node | null;
backdropAlphaNode: Node | null;

constructor(
node: Node,
lightingModel?: LightingModel | null,
backdropNode?: Node | null,
backdropAlphaNode?: Node | null,
);

constructor(node: Node, lightingModelNode?: LightingModelNode | null);
getContext(): LightingModelIndirectInput;
}

export const lightingContext: (
node: Node,
lightingModelNode?: LightingModelNode,
) => ShaderNodeObject<LightingContextNode>;
export const lightingContext: (node: Node, lightingModelNode?: LightingModel) => ShaderNodeObject<LightingContextNode>;

declare module '../shadernode/ShaderNode.js' {
interface NodeElements {
Expand Down
18 changes: 10 additions & 8 deletions types/three/examples/jsm/nodes/materials/NodeMaterial.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import MeshPhysicalNodeMaterial from './MeshPhysicalNodeMaterial.js';
import MeshStandardNodeMaterial from './MeshStandardNodeMaterial.js';
import PointsNodeMaterial from './PointsNodeMaterial.js';
import SpriteNodeMaterial from './SpriteNodeMaterial.js';
import LightsNode from '../lighting/LightsNode.js';
import LightingModel from '../core/LightingModel.js';

export default class NodeMaterial extends ShaderMaterial {
readonly isNodeMaterial: true;
Expand All @@ -24,7 +26,7 @@ export default class NodeMaterial extends ShaderMaterial {

colorSpaced: boolean;

lightsNode: Node | null;
lightsNode: LightsNode | null;
envNode: Node | null;

colorNode: Node | null;
Expand All @@ -48,15 +50,15 @@ export default class NodeMaterial extends ShaderMaterial {
build(builder: NodeBuilder): void;
setup(builder: NodeBuilder): void;
setupDepth(builder: NodeBuilder): void;
setupPosition(builder: NodeBuilder): void;
setupPosition(builder: NodeBuilder): Node;
setupDiffuseColor(builder: NodeBuilder): void;
setupVariants(builder: NodeBuilder): void;
setupNormal(): void;
getEnvNode(builder: NodeBuilder): void;
setupLights(builder: NodeBuilder): void;
setupLightingModel(builder: NodeBuilder): void;
setupLighting(builder: NodeBuilder): void;
setupOutput(builder: NodeBuilder, outputNode: Node): void;
setupNormal(builder: NodeBuilder): void;
getEnvNode(builder: NodeBuilder): Node | null;
setupLights(builder: NodeBuilder): LightsNode;
setupLightingModel(builder: NodeBuilder): LightingModel;
setupLighting(builder: NodeBuilder): Node;
setupOutput(builder: NodeBuilder, outputNode: Node): Node;

setDefaultValues(material: Material): void;

Expand Down

0 comments on commit bb4c8d3

Please sign in to comment.