-
Notifications
You must be signed in to change notification settings - Fork 421
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
MToon10マテリアルをForward+レンダラーでの複数ライトに対応 #2421
MToon10マテリアルをForward+レンダラーでの複数ライトに対応 #2421
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forward+ 対応ありがとうございます!!
1点だけ返答の方お願いできますでしょうか?
InputData inputData = (InputData)0; | ||
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.pos); | ||
inputData.positionWS = input.positionWS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inputData
が未使用変数に思えるのですが、どうでしょう?
おそらく RealtimeLights.hlsl
の GetAdditionalLight()
に渡す予定の変数だったのかと思いますが
vrmc_materials_mtoon_lighting_unity.hlsl
の GetAdditionalLight()
内での呼び出しでは positionWS
は既に渡されているので、不要そうには思えます
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ご確認ありがとうございます。
この部分はまず最初にinputDataの定義なしで実装したのですが、シェーダのコンパイルエラーとなったのでinputDataを定義しました。
LIGHT_LOOP_BEGINマクロのドキュメントが見つからなかったので正しい使い方なのか良く分かっていないのですが、RealtimeLights.hlsl
のLIGHT_LOOP_BEGIN
マクロの定義でForward+レンダリングの場合にinputData.normalizedScreenSpaceUVとinputData.positionWSを参照しているため、inputData変数の定義が必要なようです。
#if USE_FORWARD_PLUS
#define LIGHT_LOOP_BEGIN(lightCount) { \
uint lightIndex; \
ClusterIterator _urp_internal_clusterIterator = ClusterInit(inputData.normalizedScreenSpaceUV, inputData.positionWS, 0); \
[loop] while (ClusterNext(_urp_internal_clusterIterator, lightIndex)) { \
lightIndex += URP_FP_DIRECTIONAL_LIGHTS_COUNT; \
FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
#define LIGHT_LOOP_END } }
#elif !_USE_WEBGL1_LIGHTS
またLIGHT_LOOP_BEGINでネット情報を探したところ、Cyanilux/URP_ShaderGraphCustomLightingではInputData inputDataを定義する実装をされていたので同じようにしたところシェーダのコンパイルエラーが解消されて複数ライトでのライティングができるようになったという経緯になります。
(参考: https://github.com/Cyanilux/URP_ShaderGraphCustomLighting/blob/main/CustomLighting.hlsl#L236-L253)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとうございます!
Unity の Graphics ライブラリを確認しましたが、たしかに使用されていますね……必要な定義そうです。
https://github.com/Unity-Technologies/Graphics/blob/fc267ad41df7e0cf39300c4c4d57dd1dc890c054/Packages/com.unity.render-pipelines.universal/ShaderLibrary/RealtimeLights.hlsl#L28-L34
@@ -112,6 +112,7 @@ Shader "VRM10/Universal Render Pipeline/MToon10" | |||
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS | |||
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE | |||
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS | |||
#pragma multi_compile _ _FORWARD_PLUS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
PullReq とは直接的には関係ない、元からの問題に気づいたメモ: Outline パスのライティング処理が variant が無いなど不完全になっている? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
URPでMToon10マテリアルに対してForward+レンダラーを使用したときにメインライト1つしか適用されていなかったようですので、Forward+での複数ライトに対応する変更を行いました。
動作確認のためライトを300個設置してForward+レンダラーで描画したものが以下のスクリーンショットです。(各球体からキャラに向けてスポットライトを当てています。Unity 2022.3.14f1にて動作確認。)
変更内容