Quellcode durchsuchen

Associated with #6012 - first step for light block

David Catuhe vor 6 Jahren
Ursprung
Commit
50530014bc

+ 7 - 0
src/Materials/Node/Blocks/Dual/fogBlock.ts

@@ -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);

+ 7 - 0
src/Materials/Node/Blocks/Fragment/imageProcessingBlock.ts

@@ -39,6 +39,13 @@ export class ImageProcessingBlock extends NodeMaterialBlock {
     }
 
     /**
+     * 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
      */

+ 2 - 1
src/Materials/Node/Blocks/Fragment/index.ts

@@ -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 - 0
src/Materials/Node/Blocks/Fragment/lightBlock.ts

@@ -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 - 0
src/Materials/Node/Blocks/Fragment/rgbMergerBlock.ts

@@ -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);
 

+ 7 - 0
src/Materials/Node/Blocks/Fragment/rgbaMergerBlock.ts

@@ -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);
 

+ 7 - 0
src/Materials/Node/Blocks/Fragment/textureBlock.ts

@@ -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();

+ 7 - 0
src/Materials/Node/Blocks/Vertex/bonesBlock.ts

@@ -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();

+ 7 - 0
src/Materials/Node/Blocks/addBlock.ts

@@ -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);
 

+ 7 - 0
src/Materials/Node/Blocks/clampBlock.ts

@@ -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);
 

+ 7 - 0
src/Materials/Node/Blocks/matrixMultiplicationBlock.ts

@@ -35,6 +35,13 @@ export class MatrixMultiplicationBlock extends NodeMaterialBlock {
     }
 
     /**
+     * Gets the output component
+     */
+    public get output(): NodeMaterialConnectionPoint {
+        return this._outputs[0];
+    }
+
+    /**
      * Gets the current class name
      * @returns the class name
      */

+ 7 - 0
src/Materials/Node/Blocks/multiplyBlock.ts

@@ -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);
 

+ 7 - 0
src/Materials/Node/Blocks/scaleBlock.ts

@@ -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);
 

+ 7 - 0
src/Materials/Node/Blocks/vector2TransformBlock.ts

@@ -45,6 +45,13 @@ export class Vector2TransformBlock extends NodeMaterialBlock {
     }
 
     /**
+     * Gets the output component
+     */
+    public get output(): NodeMaterialConnectionPoint {
+        return this._outputs[0];
+    }
+
+    /**
      * Gets the current class name
      * @returns the class name
      */

+ 7 - 0
src/Materials/Node/Blocks/vector3TransformBlock.ts

@@ -40,6 +40,13 @@ export class Vector3TransformBlock extends NodeMaterialBlock {
     }
 
     /**
+     * Gets the output component
+     */
+    public get output(): NodeMaterialConnectionPoint {
+        return this._outputs[0];
+    }
+
+    /**
      * Gets the current class name
      * @returns the class name
      */

+ 7 - 0
src/Materials/Node/Blocks/vector4TransformBlock.ts

@@ -41,6 +41,13 @@ export class Vector4TransformBlock extends NodeMaterialBlock {
     }
 
     /**
+     * Gets the output component
+     */
+    public get output(): NodeMaterialConnectionPoint {
+        return this._outputs[0];
+    }
+
+    /**
      * Gets the matrix transform input
      */
     public get transform(): NodeMaterialConnectionPoint {

+ 19 - 2
src/Materials/Node/nodeMaterialBlockConnectionPoint.ts

@@ -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) {

+ 3 - 1
src/Materials/Node/nodeMaterialBlockConnectionPointTypes.ts

@@ -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 - 0
src/Materials/Node/nodeMaterialBuildState.ts

@@ -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);