Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add normal input to clear coat Block #12388

Merged
merged 4 commits into from
Apr 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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.registerOutput(
"clearcoat",
Expand All @@ -68,6 +70,7 @@ export class ClearCoatBlock extends NodeMaterialBlock {
state._excludeVariableName("vClearCoatTintParams");
state._excludeVariableName("vClearCoatRefractionParams");
state._excludeVariableName("vClearCoatTangentSpaceParams");
state._excludeVariableName("vGeometricNormaClearCoatW");
}

/**
Expand Down Expand Up @@ -141,6 +144,13 @@ export class ClearCoatBlock extends NodeMaterialBlock {
return this._inputs[8];
}

/**
* Gets the world normal input component
*/
public get worldNormal(): NodeMaterialConnectionPoint {
return this._inputs[9];
}

/**
* Gets the clear coat object output component
*/
Expand Down Expand Up @@ -255,6 +265,11 @@ export class ClearCoatBlock extends NodeMaterialBlock {
if (ccBlock) {
state._emitUniformFromString("vClearCoatRefractionParams", "vec4");
state._emitUniformFromString("vClearCoatTangentSpaceParams", "vec2");

const normalShading = ccBlock.worldNormal;
code += `vec3 vGeometricNormaClearCoatW = ${normalShading.isConnected ? "normalize(" + normalShading.associatedVariableName + ".xyz)" : "geometricNormalW"};\r\n`;
sebavan marked this conversation as resolved.
Show resolved Hide resolved
} else {
code += `vec3 vGeometricNormaClearCoatW = geometricNormalW;\r\n`;
}

if (generateTBNSpace && ccBlock) {
Expand All @@ -270,7 +285,7 @@ export class ClearCoatBlock extends NodeMaterialBlock {

clearcoatBlock(
${worldPosVarName}.xyz,
geometricNormalW,
vGeometricNormaClearCoatW,
viewDirectionW,
vClearCoatParams,
specularEnvironmentR0,
Expand Down