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

Bake smoothness and roughnessFactor into textures. #222

Merged

Conversation

yutopp
Copy link
Contributor

@yutopp yutopp commented Mar 14, 2019

Resolve #212.

Now some conversion logic are introduced when converting MetallicRoughness maps.

  • Unity world to glTF world

    • Now smoothness value is baked into exported textures when exporting
    • Thus roughnessFactor is hard-coded as 1.0f in glTF (because this values are already baked into textures)
  • glTF world to Unity world

    • (vice versa)
    • Now roughnessFactor value is baked into imported textures when importing
    • Thus smoothness is hard-coded as 1.0f in Unity (because this values are already baked into textures)

…nd roughnessFactor as hardcoded-value 1.0 in Unity world (Resolve #212)
@yutopp yutopp added this to the v0.52.0 milestone Mar 14, 2019
@yutopp yutopp requested a review from hiroj March 14, 2019 13:35
@yutopp
Copy link
Contributor Author

yutopp commented Mar 14, 2019

This is a screenshot when import glTF models with blender. Exported parameters by Unity are smoothness=1.0(left) and smoothness=0.0 (right). Now both of them have roughnessFactor=1.0 as glTF parameters.
1_0and0_0

@0b5vr
Copy link
Contributor

0b5vr commented Mar 15, 2019

対応はっや!試してみます!

@0b5vr
Copy link
Contributor

0b5vr commented Mar 15, 2019

ウオオーーーーいけたー!ありがとうございます!

a = (byte)(255 - src.g),
// Bake roughness values into a texture.
// See: https://github.com/dwango/UniVRM/issues/212.
a = (byte)(255 - Math.Min(src.g * (1.0f - _smoothness), 255)),
Copy link
Contributor

Choose a reason for hiding this comment

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

こちら、 roughness = 1.0 - smoothness でなく、
roughness = (1.0 - smoothness)^2 とのことですので、修正をお願いします。

以下のような要因で即時の変更が難しい場合、次のPRにまわしていただいても構わないです。

  • UniGLTF全編に対する変更が必要なこと
  • エクスポート結果が変化すること(正しくはなります)

こちらの記事を参考にどうぞ。
Roughnessは学術的に確立されたパラメータではあるものの、視覚的変化が線形でないため、
SmoothnessというRoughnessを一段覆うパラメータが生まれたようです。
https://blogs.unity3d.com/jp/2016/01/25/ggx-in-unity-5-3/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

おお、ありがとうございます!変更いたします。記事も参考になります 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

c8489af で対応しました。Import/Exportの段階ですべて変換してしまう方針です。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

計算間違えているので修正します...

@yutopp
Copy link
Contributor Author

yutopp commented Mar 15, 2019

Reimport glTF models with Unity.
(smoothness = 1.0, 0.5, 0.0 when exporting them)

image


var pixelSmoothness = src.a * _smoothnessOrRoughness; // smoothness
// https://blogs.unity3d.com/jp/2016/01/25/ggx-in-unity-5-3/
var pixelRoughnessFactor = (1.0f - pixelSmoothness) * (1.0f - pixelSmoothness);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var pixelRoughnessFactor = (1.0f - pixelSmoothness) * (1.0f - pixelSmoothness);
var pixelRoughnessFactorSqrt = (1.0f - pixelSmoothness);
var pixelRoughnessFactor = pixelRoughnessFactorSqrt * pixelRoughnessFactorSqrt;

めちゃ細かいですが……w

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@0b5vr 0b5vr Mar 15, 2019

Choose a reason for hiding this comment

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

対応ありがとうございます 🙏

@yutopp
Copy link
Contributor Author

yutopp commented Mar 15, 2019

式の修正、レビュー対応済みです。

@hiroj hiroj merged commit 3bc57e9 into master Mar 15, 2019
@yutopp yutopp deleted the feature/bake_smoothness_and_roughness_factor_into_textures branch March 15, 2019 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants