Skip to content

Commit

Permalink
Associated with #6012 - first step for light block
Browse files Browse the repository at this point in the history
  • Loading branch information
deltakosh committed Jun 10, 2019
1 parent 169bb32 commit 5053001
Show file tree
Hide file tree
Showing 19 changed files with 173 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/Dual/fogBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ export class FogBlock extends NodeMaterialBlock {
return this._inputs[4];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

public autoConfigure() {
if (this.view.isUndefined) {
this.view.setAsWellKnownValue(NodeMaterialWellKnownValues.View);
Expand Down
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/Fragment/imageProcessingBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export class ImageProcessingBlock extends NodeMaterialBlock {
return this._inputs[0];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

/**
* Initialize the block and prepare the context for build
* @param state defines the state that will be used for the build
Expand Down
3 changes: 2 additions & 1 deletion src/Materials/Node/Blocks/Fragment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export * from "./rgbMergerBlock";
export * from "./rgbaSplitterBlock";
export * from "./rgbSplitterBlock";
export * from "./textureBlock";
export * from "./imageProcessingBlock";
export * from "./imageProcessingBlock";
export * from "./lightBlock";
45 changes: 45 additions & 0 deletions src/Materials/Node/Blocks/Fragment/lightBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { NodeMaterialBlock } from '../../nodeMaterialBlock';
import { NodeMaterialBlockTargets } from '../../nodeMaterialBlockTargets';
import { NodeMaterialBlockConnectionPointTypes } from '../../nodeMaterialBlockConnectionPointTypes';
import { NodeMaterialBuildState } from '../../nodeMaterialBuildState';
import { NodeMaterialConnectionPoint } from '../../nodeMaterialBlockConnectionPoint';

/**
* Block used to add light in the fragment shader
*/
export class LightBlock extends NodeMaterialBlock {
/**
* Create a new LightBlock
* @param name defines the block name
*/
public constructor(name: string) {
super(name, NodeMaterialBlockTargets.Fragment);

this.registerInput("light", NodeMaterialBlockConnectionPointTypes.Light);
this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Float);
}

/**
* Gets the light input component
*/
public get light(): NodeMaterialConnectionPoint {
return this._inputs[0];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

protected _buildBlock(state: NodeMaterialBuildState) {
super._buildBlock(state);

state._emitFunctionFromInclude("lightFragmentDeclaration", `//${this.name}`, {
replaceStrings: [{ search: /{X}/g, replace: "1" }]
});

return this;
}
}
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/Fragment/rgbMergerBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ export class RGBMergerBlock extends NodeMaterialBlock {
return this._inputs[2];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

protected _buildBlock(state: NodeMaterialBuildState) {
super._buildBlock(state);

Expand Down
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/Fragment/rgbaMergerBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ export class RGBAMergerBlock extends NodeMaterialBlock {
return this._inputs[4];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

protected _buildBlock(state: NodeMaterialBuildState) {
super._buildBlock(state);

Expand Down
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/Fragment/textureBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ export class TextureBlock extends NodeMaterialBlock {
return this._inputs[4];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

public autoConfigure() {
if (this.uv.isUndefined) {
this.uv.setAsAttribute();
Expand Down
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/Vertex/bonesBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ export class BonesBlock extends NodeMaterialBlock {
return this._inputs[4];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

public autoConfigure() {
if (this.matricesIndices.isUndefined) {
this.matricesIndices.setAsAttribute();
Expand Down
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/addBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export class AddBlock extends NodeMaterialBlock {
return this._inputs[1];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

protected _buildBlock(state: NodeMaterialBuildState) {
super._buildBlock(state);

Expand Down
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/clampBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export class ClampBlock extends NodeMaterialBlock {
return this._inputs[0];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

protected _buildBlock(state: NodeMaterialBuildState) {
super._buildBlock(state);

Expand Down
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/matrixMultiplicationBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export class MatrixMultiplicationBlock extends NodeMaterialBlock {
return this._inputs[1];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

/**
* Gets the current class name
* @returns the class name
Expand Down
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/multiplyBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export class MultiplyBlock extends NodeMaterialBlock {
return this._inputs[1];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

protected _buildBlock(state: NodeMaterialBuildState) {
super._buildBlock(state);

Expand Down
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/scaleBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ export class ScaleBlock extends NodeMaterialBlock {
return this._inputs[1];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

protected _buildBlock(state: NodeMaterialBuildState) {
super._buildBlock(state);

Expand Down
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/vector2TransformBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ export class Vector2TransformBlock extends NodeMaterialBlock {
return this._inputs[1];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

/**
* Gets the current class name
* @returns the class name
Expand Down
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/vector3TransformBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export class Vector3TransformBlock extends NodeMaterialBlock {
return this._inputs[1];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

/**
* Gets the current class name
* @returns the class name
Expand Down
7 changes: 7 additions & 0 deletions src/Materials/Node/Blocks/vector4TransformBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export class Vector4TransformBlock extends NodeMaterialBlock {
return this._inputs[0];
}

/**
* Gets the output component
*/
public get output(): NodeMaterialConnectionPoint {
return this._outputs[0];
}

/**
* Gets the matrix transform input
*/
Expand Down
21 changes: 19 additions & 2 deletions src/Materials/Node/nodeMaterialBlockConnectionPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,25 @@ export class NodeMaterialConnectionPoint {
* Gets or sets the connection point type (default is float)
*/
public get type(): NodeMaterialBlockConnectionPointTypes {
if (this._type === NodeMaterialBlockConnectionPointTypes.AutoDetect && this._connectedPoint) {
return this._connectedPoint.type;
if (this._type === NodeMaterialBlockConnectionPointTypes.AutoDetect) {
if (this._connectedPoint) {
return this._connectedPoint.type;
}

if (this.isUniform && this.value != null) {
switch (this.value.getClassName()) {
case "Vector2":
return NodeMaterialBlockConnectionPointTypes.Vector2;
case "Vector3":
return NodeMaterialBlockConnectionPointTypes.Vector3;
case "Vector4":
return NodeMaterialBlockConnectionPointTypes.Vector4;
case "Color3":
return NodeMaterialBlockConnectionPointTypes.Color3;
case "Color4":
return NodeMaterialBlockConnectionPointTypes.Color4;
}
}
}

if (this._type === NodeMaterialBlockConnectionPointTypes.BasedOnInput && this._typeConnectionSource) {
Expand Down
4 changes: 3 additions & 1 deletion src/Materials/Node/nodeMaterialBlockConnectionPointTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ export enum NodeMaterialBlockConnectionPointTypes {
/** Detect type based on connection */
AutoDetect = 1024,
/** Output type that will be defined by input type */
BasedOnInput = 2048
BasedOnInput = 2048,
/** Light */
Light = 4096
}
6 changes: 6 additions & 0 deletions src/Materials/Node/nodeMaterialBuildState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ export class NodeMaterialBuildState {
public _emitUniformOrAttributes(point: NodeMaterialConnectionPoint, define?: string) {
define = define || point.define;

// Lights
if (point.type === NodeMaterialBlockConnectionPointTypes.Light) {
// Do nothing
return;
}

// Samplers
if (point.type === NodeMaterialBlockConnectionPointTypes.Texture) {
point.name = this._getFreeVariableName(point.name);
Expand Down

0 comments on commit 5053001

Please sign in to comment.