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 Roughness float values to MetalRoughMap.cs #407

Merged
merged 1 commit into from
Apr 22, 2019
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 @@ -86,6 +86,12 @@ public override int MetallicRoughnessXTexCoord
set { return; }
}

public override double RoughnessFactor
{
get { return _material.GetFloat("_Glossiness"); }
set { _material.SetFloat("_Glossiness", (float)value); }
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this render correctly? Glossiness is the inverse of roughness. I do see that MetallicRoughnessTexture in the cs files refers to MetallicGlossMap in the shaders. Is this an optimization to use the same variable to hold different values for the different shader variants? It seems odd to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is very odd. Im not sure exactly what the deal is. In the PbrMetallicRoughness.shader file, it has
_Glossiness("Roughness Factor", Range(0.0, 1.0)) = 1.0
as the shader parameter. I tested in babylonjs (see pictures) and it renders the same in the editor with the change.

Best I can tell, is that PbrMetallicRoughness.shader and PbrSpecularGlossiness.shader both use UnityStandardInput.cginc, which uses _Glossiness. These shaders also use a couple unity internal cginc files, which I assume require the _Glossiness parameter as well. Though without digging through it, I can only speculate.

But, like I said, it works.

babylonjs (left) vs Unity (right)
image


public override IUniformMap Clone()
{
var copy = new MetalRoughMap(new Material(_material));
Expand Down