Skip to content

Commit

Permalink
feat: Add ViewportNode
Browse files Browse the repository at this point in the history
  • Loading branch information
0b5vr committed Dec 19, 2022
1 parent 40ce9d5 commit 75b0d53
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions types/three/examples/jsm/nodes/Nodes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import FrontFacingNode from './display/FrontFacingNode';
import NormalMapNode from './display/NormalMapNode';
import PosterizeNode from './display/PosterizeNode';
import ToneMappingNode from './display/ToneMappingNode';
import ViewportNode from './display/ViewportNode';

// math
import MathNode, { MathNodeMethod1, MathNodeMethod2, MathNodeMethod3, MathNodeMethod } from './math/MathNode';
Expand Down Expand Up @@ -186,6 +187,7 @@ export {
NormalMapNode,
PosterizeNode,
ToneMappingNode,
ViewportNode,
// math
MathNode,
MathNodeMethod1,
Expand Down
4 changes: 4 additions & 0 deletions types/three/examples/jsm/nodes/core/NodeBuilder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export default abstract class NodeBuilder {

abstract getFrontFacing(): string;

abstract getFragCoord(): string;

isFlipY(): boolean;

abstract getTexture(textureProperty: string, uvSnippet: string): string;

abstract getTextureLevel(textureProperty: string, uvSnippet: string, levelSnippet: string): string;
Expand Down
23 changes: 23 additions & 0 deletions types/three/examples/jsm/nodes/display/ViewportNode.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Node from '../core/Node';

export type ViewportNodeScope =
| typeof ViewportNode.COORDINATE
| typeof ViewportNode.RESOLUTION
| typeof ViewportNode.TOP_LEFT
| typeof ViewportNode.BOTTOM_LEFT
| typeof ViewportNode.TOP_RIGHT
| typeof ViewportNode.BOTTOM_RIGHT;

export default class ViewportNode extends Node {
static COORDINATE: 'coordinate';
static RESOLUTION: 'resolution';
static TOP_LEFT: 'topLeft';
static BOTTOM_LEFT: 'bottomLeft';
static TOP_RIGHT: 'topRight';
static BOTTOM_RIGHT: 'bottomRight';

scope: ViewportNodeScope;
isViewportNode: true;

constructor(scope: ViewportNodeScope);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
TimerNode,
ToneMappingNode,
TriplanarTexturesNode,
ViewportNode,
} from '../Nodes';

//
Expand Down Expand Up @@ -99,6 +100,13 @@ export function toneMapping(

export function posterize(sourceNode: NodeRepresentation, stepsNode: NodeRepresentation): Swizzable<PosterizeNode>;

export const viewportCoordinate: Swizzable<ViewportNode>;
export const viewportResolution: Swizzable<ViewportNode>;
export const viewportTopLeft: Swizzable<ViewportNode>;
export const viewportBottomLeft: Swizzable<ViewportNode>;
export const viewportTopRight: Swizzable<ViewportNode>;
export const viewportBottomRight: Swizzable<ViewportNode>;

// lighting

export function lights(lights: Light[]): Swizzable<LightsNode>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import NodeBuilder from '../../../nodes/core/NodeBuilder';
import { Texture, TextureEncoding, Renderer, Object3D } from '../../../../../src/Three';
import { Renderer, Object3D } from '../../../../../src/Three';
import Node from '../../../nodes/core/Node';
import SlotNode from './SlotNode';
import { NodeShaderStageOption } from '../../../nodes/core/constants';
Expand Down Expand Up @@ -44,10 +44,11 @@ export class WebGLNodeBuilder extends NodeBuilder {

replaceCode(shaderStage: string, source: string, target: string, scope?: this): void;
parseInclude(shaderStage: string, ...includes: string[]): void;
getTextureEncodingFromMap(map: Texture): TextureEncoding;

getInstanceIndex(): string;
getFrontFacing(): string;
getFragCoord(): 'gl_FragCoord';
isFlipY(): true;

buildCode(): void;
build(): this;
Expand Down
8 changes: 8 additions & 0 deletions types/three/test/nodes/nodes-ShaderNodeElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ColorAdjustmentNode from 'three/examples/jsm/nodes/display/ColorAdjustmen
import ColorSpaceNode from 'three/examples/jsm/nodes/display/ColorSpaceNode';
import NormalMapNode from 'three/examples/jsm/nodes/display/NormalMapNode';
import ToneMappingNode from 'three/examples/jsm/nodes/display/ToneMappingNode';
import ViewportNode from 'three/examples/jsm/nodes/display/ViewportNode';

// lighting
import LightsNode from 'three/examples/jsm/nodes/lighting/LightsNode';
Expand Down Expand Up @@ -71,6 +72,13 @@ export const normalMap = nodeProxy(NormalMapNode);
export const toneMapping = (mapping: ToneMapping, exposure: Node, color: Node) =>
nodeObject(new ToneMappingNode(mapping, nodeObject(exposure), nodeObject(color)));

export const viewportCoordinate = nodeImmutable(ViewportNode, ViewportNode.COORDINATE);
export const viewportResolution = nodeImmutable(ViewportNode, ViewportNode.RESOLUTION);
export const viewportTopLeft = nodeImmutable(ViewportNode, ViewportNode.TOP_LEFT);
export const viewportBottomLeft = nodeImmutable(ViewportNode, ViewportNode.BOTTOM_LEFT);
export const viewportTopRight = nodeImmutable(ViewportNode, ViewportNode.TOP_RIGHT);
export const viewportBottomRight = nodeImmutable(ViewportNode, ViewportNode.BOTTOM_RIGHT);

// lighting

// export const lighting = nodeProxy( LightingNode ); // abstract
Expand Down

0 comments on commit 75b0d53

Please sign in to comment.