Skip to content

Commit

Permalink
Merge pull request #13328 from Popov72/nme-imageprocessing
Browse files Browse the repository at this point in the history
NME: Add a rgb output to the ImageProcessing block
Former-commit-id: c91258f2be027a1f4233a803d6d182d8822a0f38
  • Loading branch information
sebavan authored Dec 8, 2022
2 parents 0ffb88d + f2cb338 commit 8bcce96
Show file tree
Hide file tree
Showing 24 changed files with 167 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class CurrentScreenBlock extends NodeMaterialBlock {

this._isUnique = false;

this.registerInput("uv", NodeMaterialBlockConnectionPointTypes.Vector2, false, NodeMaterialBlockTargets.VertexAndFragment);
this.registerInput("uv", NodeMaterialBlockConnectionPointTypes.AutoDetect, false, NodeMaterialBlockTargets.VertexAndFragment);

this.registerOutput("rgba", NodeMaterialBlockConnectionPointTypes.Color4, NodeMaterialBlockTargets.Neutral);
this.registerOutput("rgb", NodeMaterialBlockConnectionPointTypes.Color3, NodeMaterialBlockTargets.Neutral);
Expand All @@ -57,8 +57,9 @@ export class CurrentScreenBlock extends NodeMaterialBlock {
this.registerOutput("b", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);
this.registerOutput("a", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);

this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector3);
this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector4);
this._inputs[0].addExcludedConnectionPointFromAllowedTypes(
NodeMaterialBlockConnectionPointTypes.Vector2 | NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4
);

this._inputs[0]._prioritizeVertex = false;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/dev/core/src/Materials/Node/Blocks/Dual/fogBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export class FogBlock extends NodeMaterialBlock {
this.registerInput("view", NodeMaterialBlockConnectionPointTypes.Matrix, false, NodeMaterialBlockTargets.Vertex);

// Fragment
this.registerInput("input", NodeMaterialBlockConnectionPointTypes.Color3, false, NodeMaterialBlockTargets.Fragment);
this.registerInput("fogColor", NodeMaterialBlockConnectionPointTypes.Color3, false, NodeMaterialBlockTargets.Fragment);
this.registerInput("input", NodeMaterialBlockConnectionPointTypes.AutoDetect, false, NodeMaterialBlockTargets.Fragment);
this.registerInput("fogColor", NodeMaterialBlockConnectionPointTypes.AutoDetect, false, NodeMaterialBlockTargets.Fragment);

this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Color3, NodeMaterialBlockTargets.Fragment);

this.input.acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Color4);
this.fogColor.acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Color4);
this.input.addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Color3 | NodeMaterialBlockConnectionPointTypes.Color4);
this.fogColor.addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Color3 | NodeMaterialBlockConnectionPointTypes.Color4);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ReflectionTextureBlock extends ReflectionTextureBaseBlock {
public constructor(name: string) {
super(name);

this.registerInput("position", NodeMaterialBlockConnectionPointTypes.Vector3, false, NodeMaterialBlockTargets.Vertex);
this.registerInput("position", NodeMaterialBlockConnectionPointTypes.AutoDetect, false, NodeMaterialBlockTargets.Vertex);
this.registerInput("worldPosition", NodeMaterialBlockConnectionPointTypes.Vector4, false, NodeMaterialBlockTargets.Vertex);
this.registerInput("worldNormal", NodeMaterialBlockConnectionPointTypes.Vector4, false, NodeMaterialBlockTargets.Fragment); // Flagging as fragment as the normal can be changed by fragment code
this.registerInput("world", NodeMaterialBlockConnectionPointTypes.Matrix, false, NodeMaterialBlockTargets.Vertex);
Expand All @@ -58,7 +58,7 @@ export class ReflectionTextureBlock extends ReflectionTextureBaseBlock {
this.registerOutput("b", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Fragment);
this.registerOutput("a", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Fragment);

this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector4);
this._inputs[0].addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ export class SceneDepthBlock extends NodeMaterialBlock {

this._isUnique = true;

this.registerInput("uv", NodeMaterialBlockConnectionPointTypes.Vector2, false, NodeMaterialBlockTargets.VertexAndFragment);
this.registerInput("uv", NodeMaterialBlockConnectionPointTypes.AutoDetect, false, NodeMaterialBlockTargets.VertexAndFragment);

this.registerOutput("depth", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);

this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector3);
this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector4);
this._inputs[0].addExcludedConnectionPointFromAllowedTypes(
NodeMaterialBlockConnectionPointTypes.Vector2 | NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4
);

this._inputs[0]._prioritizeVertex = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class TextureBlock extends NodeMaterialBlock {

this._fragmentOnly = fragmentOnly;

this.registerInput("uv", NodeMaterialBlockConnectionPointTypes.Vector2, false, NodeMaterialBlockTargets.VertexAndFragment);
this.registerInput("uv", NodeMaterialBlockConnectionPointTypes.AutoDetect, false, NodeMaterialBlockTargets.VertexAndFragment);
this.registerInput(
"source",
NodeMaterialBlockConnectionPointTypes.Object,
Expand All @@ -162,8 +162,9 @@ export class TextureBlock extends NodeMaterialBlock {

this.registerOutput("level", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);

this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector3);
this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector4);
this._inputs[0].addExcludedConnectionPointFromAllowedTypes(
NodeMaterialBlockConnectionPointTypes.Vector2 | NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4
);

this._inputs[0]._prioritizeVertex = !fragmentOnly;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class TBNBlock extends NodeMaterialBlock {
public constructor(name: string) {
super(name, NodeMaterialBlockTargets.Fragment, true);

this.registerInput("normal", NodeMaterialBlockConnectionPointTypes.Vector4, false);
this.normal.acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector3);
this.registerInput("normal", NodeMaterialBlockConnectionPointTypes.AutoDetect, false);
this.normal.addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Vector4 | NodeMaterialBlockConnectionPointTypes.Vector3);
this.registerInput("tangent", NodeMaterialBlockConnectionPointTypes.Vector4, false);
this.registerInput("world", NodeMaterialBlockConnectionPointTypes.Matrix, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export class FragmentOutputBlock extends NodeMaterialBlock {
super(name, NodeMaterialBlockTargets.Fragment, true);

this.registerInput("rgba", NodeMaterialBlockConnectionPointTypes.Color4, true);
this.registerInput("rgb", NodeMaterialBlockConnectionPointTypes.Color3, true);
this.registerInput("rgb", NodeMaterialBlockConnectionPointTypes.AutoDetect, true);
this.registerInput("a", NodeMaterialBlockConnectionPointTypes.Float, true);

this.rgb.acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Float);
this.rgb.addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Color3 | NodeMaterialBlockConnectionPointTypes.Float);
}

/** Gets or sets a boolean indicating if content needs to be converted to gamma space */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class HeightToNormalBlock extends NodeMaterialBlock {
this.registerInput("input", NodeMaterialBlockConnectionPointTypes.Float);
this.registerInput("worldPosition", NodeMaterialBlockConnectionPointTypes.Vector3);
this.registerInput("worldNormal", NodeMaterialBlockConnectionPointTypes.Vector3);
this.registerInput("worldTangent", NodeMaterialBlockConnectionPointTypes.Vector3, true);
this.registerInput("worldTangent", NodeMaterialBlockConnectionPointTypes.AutoDetect, true);
this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Vector4);
this.registerOutput("xyz", NodeMaterialBlockConnectionPointTypes.Vector3);

this._inputs[3].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector4);
this._inputs[3].addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ export class ImageProcessingBlock extends NodeMaterialBlock {
public constructor(name: string) {
super(name, NodeMaterialBlockTargets.Fragment);

this.registerInput("color", NodeMaterialBlockConnectionPointTypes.Color4);
this.registerInput("color", NodeMaterialBlockConnectionPointTypes.AutoDetect);
this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Color4);

this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Color3);
this.registerOutput("rgb", NodeMaterialBlockConnectionPointTypes.Color3);

this._inputs[0].addExcludedConnectionPointFromAllowedTypes(
NodeMaterialBlockConnectionPointTypes.Color3 |
NodeMaterialBlockConnectionPointTypes.Color4 |
NodeMaterialBlockConnectionPointTypes.Vector3 |
NodeMaterialBlockConnectionPointTypes.Vector4
);
}

/**
Expand Down Expand Up @@ -60,6 +66,13 @@ export class ImageProcessingBlock extends NodeMaterialBlock {
return this._outputs[0];
}

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

/**
* Initialize the block and prepare the context for build
* @param state defines the state that will be used for the build
Expand Down Expand Up @@ -139,23 +152,29 @@ export class ImageProcessingBlock extends NodeMaterialBlock {
state._emitFunctionFromInclude("imageProcessingDeclaration", comments);
state._emitFunctionFromInclude("imageProcessingFunctions", comments);

if (color.connectedPoint!.type === NodeMaterialBlockConnectionPointTypes.Color4 || color.connectedPoint!.type === NodeMaterialBlockConnectionPointTypes.Vector4) {
state.compilationString += `${this._declareOutput(output, state)} = ${color.associatedVariableName};\r\n`;
} else {
state.compilationString += `${this._declareOutput(output, state)} = vec4(${color.associatedVariableName}, 1.0);\r\n`;
}
state.compilationString += `#ifdef IMAGEPROCESSINGPOSTPROCESS\r\n`;
if (this.convertInputToLinearSpace) {
state.compilationString += `${output.associatedVariableName}.rgb = toLinearSpace(${color.associatedVariableName}.rgb);\r\n`;
}
state.compilationString += `#else\r\n`;
state.compilationString += `#ifdef IMAGEPROCESSING\r\n`;
if (this.convertInputToLinearSpace) {
state.compilationString += `${output.associatedVariableName}.rgb = toLinearSpace(${color.associatedVariableName}.rgb);\r\n`;
if (color.connectedPoint?.isConnected) {
if (color.connectedPoint!.type === NodeMaterialBlockConnectionPointTypes.Color4 || color.connectedPoint!.type === NodeMaterialBlockConnectionPointTypes.Vector4) {
state.compilationString += `${this._declareOutput(output, state)} = ${color.associatedVariableName};\r\n`;
} else {
state.compilationString += `${this._declareOutput(output, state)} = vec4(${color.associatedVariableName}, 1.0);\r\n`;
}
state.compilationString += `#ifdef IMAGEPROCESSINGPOSTPROCESS\r\n`;
if (this.convertInputToLinearSpace) {
state.compilationString += `${output.associatedVariableName}.rgb = toLinearSpace(${color.associatedVariableName}.rgb);\r\n`;
}
state.compilationString += `#else\r\n`;
state.compilationString += `#ifdef IMAGEPROCESSING\r\n`;
if (this.convertInputToLinearSpace) {
state.compilationString += `${output.associatedVariableName}.rgb = toLinearSpace(${color.associatedVariableName}.rgb);\r\n`;
}
state.compilationString += `${output.associatedVariableName} = applyImageProcessing(${output.associatedVariableName});\r\n`;
state.compilationString += `#endif\r\n`;
state.compilationString += `#endif\r\n`;

if (this.rgb.hasEndpoints) {
state.compilationString += this._declareOutput(this.rgb, state) + ` = ${this.output.associatedVariableName}.xyz;\r\n`;
}
}
state.compilationString += `${output.associatedVariableName} = applyImageProcessing(${output.associatedVariableName});\r\n`;
state.compilationString += `#endif\r\n`;
state.compilationString += `#endif\r\n`;

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export class ScreenSpaceBlock extends NodeMaterialBlock {
public constructor(name: string) {
super(name, NodeMaterialBlockTargets.Fragment);

this.registerInput("vector", NodeMaterialBlockConnectionPointTypes.Vector3);
this.registerInput("vector", NodeMaterialBlockConnectionPointTypes.AutoDetect);
this.registerInput("worldViewProjection", NodeMaterialBlockConnectionPointTypes.Matrix);
this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Vector2);
this.registerOutput("x", NodeMaterialBlockConnectionPointTypes.Float);
this.registerOutput("y", NodeMaterialBlockConnectionPointTypes.Float);

this.inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector4);
this.inputs[0].addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class ShadowMapBlock extends NodeMaterialBlock {

this.registerInput("worldPosition", NodeMaterialBlockConnectionPointTypes.Vector4, false);
this.registerInput("viewProjection", NodeMaterialBlockConnectionPointTypes.Matrix, false);
this.registerInput("worldNormal", NodeMaterialBlockConnectionPointTypes.Vector3, true);
this.registerInput("worldNormal", NodeMaterialBlockConnectionPointTypes.AutoDetect, true);
this.registerOutput("depth", NodeMaterialBlockConnectionPointTypes.Vector3);

this.worldNormal.acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector4);
this.worldNormal.addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export class ClearCoatBlock extends NodeMaterialBlock {
this.registerInput("tintAtDistance", NodeMaterialBlockConnectionPointTypes.Float, true, NodeMaterialBlockTargets.Fragment);
this.registerInput("tintThickness", NodeMaterialBlockConnectionPointTypes.Float, true, NodeMaterialBlockTargets.Fragment);
this.registerInput("worldTangent", NodeMaterialBlockConnectionPointTypes.Vector4, true);
this.registerInput("worldNormal", NodeMaterialBlockConnectionPointTypes.Vector4, true);
this.worldNormal.acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector3);
this.registerInput("worldNormal", NodeMaterialBlockConnectionPointTypes.AutoDetect, true);
this.worldNormal.addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Vector4 | NodeMaterialBlockConnectionPointTypes.Vector3);
this.registerInput(
"TBN",
NodeMaterialBlockConnectionPointTypes.Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class ReflectionBlock extends ReflectionTextureBaseBlock {

this._isUnique = true;

this.registerInput("position", NodeMaterialBlockConnectionPointTypes.Vector3, false, NodeMaterialBlockTargets.Vertex);
this.registerInput("position", NodeMaterialBlockConnectionPointTypes.AutoDetect, false, NodeMaterialBlockTargets.Vertex);
this.registerInput("world", NodeMaterialBlockConnectionPointTypes.Matrix, false, NodeMaterialBlockTargets.Vertex);
this.registerInput("color", NodeMaterialBlockConnectionPointTypes.Color3, true, NodeMaterialBlockTargets.Fragment);

Expand All @@ -103,7 +103,7 @@ export class ReflectionBlock extends ReflectionTextureBaseBlock {
new NodeMaterialConnectionPointCustomObject("reflection", this, NodeMaterialConnectionPointDirection.Output, ReflectionBlock, "ReflectionBlock")
);

this.position.acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector4);
this.position.addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class ParticleTextureBlock extends NodeMaterialBlock {

this._isUnique = false;

this.registerInput("uv", NodeMaterialBlockConnectionPointTypes.Vector2, false, NodeMaterialBlockTargets.VertexAndFragment);
this.registerInput("uv", NodeMaterialBlockConnectionPointTypes.AutoDetect, false, NodeMaterialBlockTargets.VertexAndFragment);

this.registerOutput("rgba", NodeMaterialBlockConnectionPointTypes.Color4, NodeMaterialBlockTargets.Neutral);
this.registerOutput("rgb", NodeMaterialBlockConnectionPointTypes.Color3, NodeMaterialBlockTargets.Neutral);
Expand All @@ -56,8 +56,9 @@ export class ParticleTextureBlock extends NodeMaterialBlock {
this.registerOutput("b", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);
this.registerOutput("a", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);

this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector3);
this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector4);
this._inputs[0].addExcludedConnectionPointFromAllowedTypes(
NodeMaterialBlockConnectionPointTypes.Vector2 | NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export class MorphTargetsBlock extends NodeMaterialBlock {

this.registerInput("position", NodeMaterialBlockConnectionPointTypes.Vector3);
this.registerInput("normal", NodeMaterialBlockConnectionPointTypes.Vector3);
this.registerInput("tangent", NodeMaterialBlockConnectionPointTypes.Vector4);
this.tangent.acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector3);
this.registerInput("tangent", NodeMaterialBlockConnectionPointTypes.AutoDetect);
this.tangent.addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Vector4 | NodeMaterialBlockConnectionPointTypes.Vector3);
this.registerInput("uv", NodeMaterialBlockConnectionPointTypes.Vector2);
this.registerOutput("positionOutput", NodeMaterialBlockConnectionPointTypes.Vector3);
this.registerOutput("normalOutput", NodeMaterialBlockConnectionPointTypes.Vector3);
Expand Down
Loading

0 comments on commit 8bcce96

Please sign in to comment.