Yellow-Dog-Man / Resonite-Issues

Issue repository for Resonite.
https://resonite.com
140 stars 2 forks source link

Add shadow for alpha blend material #170

Open lill-la opened 1 year ago

lill-la commented 1 year ago

Is your feature request related to a problem? Please describe.

現在、BlendModeをAlphaにしたマテリアルに対して、他の物体からの影が描画されません。(ここで言う影はLightコンポーネントのShadowTypeをNone以外にしたときに物体が発生させる影のことです)

これはアバターの表現において大きな障害となっており、例えば半透明の前髪・頬を赤く染めるエフェクト・単に半透明の衣服などを着せたとき、BlendModeがAlphaのマテリアルとOpaqueが混在すると、アバターが物体の影にいるときAlphaのマテリアルだけが光っているように見えてしまいます。

[Machine Translation] Currently, shadows from other objects are not rendered for materials with BlendMode set to Alpha. (The shadows here are those generated by objects when the Light component's ShadowType is set to a value other than None.)

This is a major obstacle to avatar expression. For example, if an avatar wears translucent bangs, a red cheek effect, or simply translucent clothing, and the BlendMode is mixed between Alpha and Opaque materials, when the avatar is in the shadow of an object, only the Alpha material will appear to glow. When the avatar is in the shadow of an object, only the Alpha material appears to glow.

image

Describe the solution you'd like

BlendModeがAlphaのマテリアルに対して影が影響を及ぼすようにする。

[Machine Translation] Allow shadows to affect materials with a BlendMode of Alpha.

Describe alternatives you've considered

  1. アバターの他の全てのマテリアルをAlphaあるいはRenderQueueを2501以上にする BlendModeがAlphaでないマテリアルも全て影の影響を受けないようにすればアバター全体が影の影響を受けなくなるため、アバターの中で不整合は無くなります。 しかし、他の影の影響を受けるオブジェクトやアバターと並んだときに発光しているかのように見える謎のオブジェクトになってしまいます。 また、DepthMaterialに無視されるようになってしまうため、これを利用したユーザー製のツール(OrangeによるDepthCamなど)が使えなくなってしまいます。

  2. RenderQueueを1~2500にする これは半透明かつ影の影響を受けますが、描画順の関係で別のオブジェクトが貫通して描画されてしまいます(スカイボックス・ライト・AO影など)。

[Machine Translation]

  1. Set Alpha or RenderQueue to 2501 or higher for all other materials in the avatar. If all materials whose BlendMode is not Alpha are also rendered unaffected by shadows, the entire avatar will be unaffected by shadows, and there will be no inconsistencies within the avatar. However, it would result in an enigmatic object that would appear to glow when aligned with other shadow-affected objects and the avatar. It will also be ignored by DepthMaterial, making it impossible to use user-made tools that take advantage of it (such as DepthCam by Orange).

  2. Set RenderQueue from 1 to 2500. This is semi-transparent and shadow sensitive, but due to the drawing order, another object will be drawn through it (skybox, light, AO shadow, etc.).

Additional Context

No response

ModernBalloonie commented 1 year ago

I wonder if this is a unity thing because it seems like unity's default materials do this as well.

amplified1 commented 1 year ago

This is a general rendering thing as both shadows and alpha are famously hard to render. The solution is probably something similar to how blender handles transparency settings in its Eevee renderer, where you can set the alpha handling for shadows and surface separately. In blender's case it doesn't support alpha blending on shadows but it does allow the user to select an alpha clip option for shadows or a dithering mode, one having clean shadows but no partially darkened shadows, and the other supplying gradual shadows, at the cost of being noisy. Alpha clip shadows are probably the best thing to implement, and would be best for your specific use case, as it would let your bangs cast an accurate enough shadow.