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

Feature/uber lit shader #32

Merged
merged 21 commits into from
Aug 16, 2022
Merged

Conversation

CyTakayukiKiyohara
Copy link
Contributor

@CyTakayukiKiyohara CyTakayukiKiyohara commented Aug 3, 2022

NovaShaderのLit版の仕様が全入りしました。
かなり変更点が多くなっているので、いったんPRを出させていただきます。
各種端末での詳細なテストは別ブランチで行います。

1. 実装概要

Lit版の実装方針としては、Unlit版のフラグメントシェーダーで計算されるカラーをアルベドカラーとして考えて、そのカラーをUniversalFragmentPBRの入力値としています。そのため、Unlit版のカラーの計算処理を共通で使えるような実装に変更しています。
法線、スペキュラ、メタリックなどの入力値はLit専用のGUIからの設定に基づいて入力しています。
それ以外のパラメータはURPのLit版の実装を参考にして、同じ値を入れるようにしています。
Unlit版に影響を与えないように実装していきましたが、共通化する際に多少コードを変更しています。

2.URPのLit版とのクォリティ面での差異

URPのLit版と下記の差異があります。
(どの差異もクォリティ面ではポジティブな違いです)

  1. SSAOが適用されている
  2. 法線マップが貼られていないときのライティング
  3. バンプスケール
  • SSAOが適用されている
    Lit版の実装による影響ではないのですが、URPのパーティクルのシェーダーは法線を書き込んでいないため、SSAOによる陰影が生まれていません。ですが、Novaシェーダーが版ではSSAOを有効にすると陰影が生まれます。
    分かりにくいですが、地面とティーポットが設置している箇所にうっすらと影が生まれています。
    SSAOあり(Nova)
    SSAO_あり
    SSAOなし(URP)
    SSAO_なし
    URP版で法線を書き込んでいないのはパフォーマンス的なことを考慮しているのかと思いますが、SSAOを有効にすると地面との設置感が生まれることと、今後SSRなどを有効にした際に、エフェクトの反射なども起こせるようになるので、法線は書き込むままにしております。

  • 法線マップが貼られていないときのライティング
    法線マップが貼られていない場合、URPでは頂点シェーダーでの法線の正規化が高速化のためにスキップされており、ライティングの結果のクオリティが下がっています。ただ、NovaShaderのUnlit版の処理でそもそも法線が正規化されている点と、クオリティ面がかなり違っていたため、そのままにしています。
    法線マップなしライティング(NOVA)
    法線マップなしライティング(NOVA)
    法線マップなしライティング(URP)
    法線マップなしライティング(URP)

  • バンプスケール
    バンプスケールは法線マップの起伏を大きくするためのパラメータで、URPのLit版にも存在しています。
    バンプスケール 1.0倍
    バンプスケール_1
    バンプスケール 3.0倍
    バンプスケール_3
    URPのLit版にも存在しているのですが、URP版はモバイルに持っていくと高速化のためにバンプスケールが無効になっています。ですが、URP版のコードを読んでみると、法線のxy要素に乗算しているだけの処理なので、パフォーマンスに大きな影響はなさそうでした。
    バンプスケールにカスタムコードを使うように改造すれば、ひび割れが生まれてきたり、壁がへこむような演出も作れそうなのでNOVA版では有効のままにしています。
    これが不要なようでしたら削除します。

3. テスト用のシーンの追加

Lit版の実装にあたり、テスト用のシーンを下記の二つ追加しています。

  1. TestUberLit_00( URP版とNova版の差異を調べるテスト )
  2. TestUberLit_01( Nova版のLitに各種機能テスト。Flowmap、Tintmap、Emissionmapなど)

これらのテストを行って、正しく動作していることを確認しています。
テストは手持ちのPixel 6 Proで行いました。
下記のテスト動画では、3本のディレクショナルライトとカメラを回しています。
エフェクトにライトの影響と視線の移動よる鏡面反射が起きていることを確認できます。

Assets/Test/TestUberLit_00( URP版とNova版の差異を調べるテスト )
https://user-images.githubusercontent.com/106138524/182510421-5259dcef-282b-469d-a577-ef062d96c4bc.mp4

Assets/Test/TestUberLit_01( Nova版のLitに各種機能テスト。Flowmap、Tintmap、Emissionmapなど)
https://user-images.githubusercontent.com/106138524/182508779-d8c2da05-38ba-4f2a-985d-5093bb079c9f.mp4

# Conflicts:
#	Assets/Nova/Editor/Core/Scripts/MaterialEditorUtility.cs
#	Assets/Nova/Editor/Core/Scripts/MaterialPropertyNames.cs
#	Assets/Nova/Editor/Core/Scripts/ParticlesUberLitGUI.cs
#	Assets/Nova/Editor/Core/Scripts/Shaders/Particles.hlsl
#	Assets/Nova/Editor/Core/Scripts/Shaders/ParticlesUber.hlsl
#	Assets/Nova/Editor/Core/Scripts/Shaders/ParticlesUberLit.shader
#	Assets/Nova/Editor/Core/Scripts/Shaders/ParticlesUberLit.shader.meta
#	Assets/Nova/Editor/Core/Scripts/Shaders/ParticlesUberLitEditor.hlsl
#	Assets/Nova/Editor/Core/Scripts/Shaders/ParticlesUberLitEditor.hlsl.meta
#	Assets/Nova/Editor/Core/Scripts/Shaders/ParticlesUberLitForward.hlsl
#	Assets/Nova/Editor/Core/Scripts/Shaders/ParticlesUberLitForward.hlsl.meta
To use the writing process for depth values and normals in the Lit version as well.
@Haruma-K Haruma-K changed the base branch from main to develop_lit August 4, 2022 03:12
@Haruma-K
Copy link
Member

Haruma-K commented Aug 5, 2022

プロジェクトの問題な気がしていますが、環境反射が効いていないので調査していただきたいです。
通常のURPマテリアルで、スムースな金属マテリアルを作ってもうまく反映されていないので、今回のシェーダの問題ではない気はしています。

image

ビルトインパイプラインでも環境反射は反映されていなさそうですが、ビルトインパイプラインでリフレクションプローブだけはうまく反映されるという謎・・

image

*/
struct AttributesLit
{
Attributes attributesUnlit;
Copy link
Member

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.

できるんです!

Comment on lines 37 to 38
#include "ParticlesUberUnLit.hlsl"
#include "ParticlesUberLit.hlsl"
Copy link
Member

Choose a reason for hiding this comment

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

あっても困らないですが、 ParticlesUberLit.hlsl の中で ParticlesUberUnLit.hlsl をインクルードしているので、ここで ParticlesUberUnLit.hlsl は不要そうです。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

96eab88 で削除しました。

@Haruma-K
Copy link
Member

Haruma-K commented Aug 5, 2022

Testフォルダは、Demoフォルダを整理してそちらにまとめてしまっていいと思います!(特に分けている理由がなければ

@CyTakayukiKiyohara
Copy link
Contributor Author

79fad49 
Testフォルダの中身をDemoフォルダに移動しています。
これに伴って、Demoフォルダを整理しています。

fca73df
リフレクションプローブに関してはUnityの不具合ですが、
回避方法が分かったので、リフレクションプローブを再作成しています。
これに伴って、Unityのバージョンを2020.3.23f1に上げています。
関連issueは下記です。
https://issuetracker.unity3d.com/issues/the-scenes-lighting-settings-are-not-updated-and-saved-when-auto-generate-option-is-disabled
https://issuetracker.unity3d.com/issues/urp-reflection-probe-is-black-after-baking-when-using-the-blit-renderer-feature

@Haruma-K
Copy link
Member

@CyTakayukiKiyohara

Unityのバージョンを2020.3.23f1に上げています。

これ上がってないかも?です。(ProjectVersion.txtが上がってない)
手元の環境でバージョン上げたら反射が反映されたので、バージョンあげれば問題はなさそうです!

Copy link
Member

@Haruma-K Haruma-K left a comment

Choose a reason for hiding this comment

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

バージョンの件以外は問題ないのでApproveします :shipit:

Copy link

@qua-iy qua-iy left a comment

Choose a reason for hiding this comment

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

1つだけ些細なところが気になりましたが、基本approveです

@@ -5,7 +5,13 @@ EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes:
- enabled: 1
- enabled: 0
path: Assets/Demo/Demo.unity
Copy link

Choose a reason for hiding this comment

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

このファイルが無くなっているので、disabledとはいえ移動先に書き換えた方が良さそうな気がしています

Copy link
Contributor Author

Choose a reason for hiding this comment

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

この修正は次に出す予定の最適化のPRに含まれているため、次回の対応とさせてください。

@CyTakayukiKiyohara CyTakayukiKiyohara merged commit 2095e5f into develop_lit Aug 16, 2022
@CyTakayukiKiyohara CyTakayukiKiyohara deleted the feature/uber_lit_shader branch August 16, 2022 09:03
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.

3 participants