Neos-Metaverse / NeosPublic

A public issue/wiki only repository for the NeosVR project
195 stars 9 forks source link

Light Cookies cause visual artifacts with toon shader and mirrors. #2284

Open Aerizeon opened 3 years ago

Aerizeon commented 3 years ago

Describe the bug

When using a spot light with a light cookie, an unusual banding effect is seen on Toon materials, and the reflection of Toon and PBR materials in a mirror, even when they are outside of the cone of the spot light.

Additionally, when the light cookie is not set to Clamped mode, the effect will show a tiled version of the light cookie instead of the banding.

The appearance of both of these are affected by the current MipMapBias setting of the lightcookie texture.

Relevant issues

[Did you find any existing issues relevant to this one? If you found the same issue, please contribute to that one instead of making a duplicate.]

To Reproduce

  1. Create Empty Object
  2. Attach a Light component
  3. Change type to Spot
  4. Attach a light cookie image, preferably something circular.
  5. Adjust the MipMapBias and WrapModeU/V settings to observe various effects caused.

Expected behavior

Lighting should not show on items outside of the spot cone, and should not have visual artifacts.

Screenshots / Video

With WrapMode Repeat

Settings: Settings Effect: Example

With WrapMode Clamp

Settings: Settings Effect: Example

Bug information (please complete the following information):

Reporters:

Reddragon Epsilion

Frooxius commented 3 years ago

This is not a bug, just the way light cookies work. For them to work properly you need to always use the Clamp mode and have some clearance at the edges of the texture to prevent banding.

Aerizeon commented 3 years ago

Even though it only affects Toon and reflections, and not PBR materials?

Geenz commented 3 years ago

I'm re-opening this one. Largely so I can do a bit of quality of life investigation on it.

Frooxius commented 3 years ago

It affects PBR materials as well, though not always, you will sometimes get the effect randomly popping in and out. This is based on Unity's light cookie rendering, we're not doing anything special there.

Typically in Unity you'd set the texture to "Cookie" type, which sets the wrap mode to clamp and adds black edges around the texture to prevent banding. See their documentation here: https://docs.unity3d.com/Manual/TextureTypes.html#cookie

shiftyscales commented 3 years ago

I'm re-opening this one. Largely so I can do a bit of quality of life investigation on it.

Hmm- I'm almost wondering if a mechanism similar to how normal maps are treated could be beneficial?

E.g. normal maps when placed in the NormalMap field of a material will be marked IsNormalMap.

Perhaps a mechanism to mark a texture as a 'Cookie' type that forces the wrap mode to clamp/adds black edges around the texture as Frooxius noted, @Geenz?

Geenz commented 3 years ago

@shiftyscales @Frooxius Honestly, having done a bit of a refresher with Unity's rendering pipeline around pixel lights, cookies, and so on - I'm seriously considering a general light cookie pass to make them more flexible (such as supporting "color" light cookies - useful for things like caustics, projectors, and so on). It's probably not a bad idea to improve the light cookie authoring flow generally as a result. I'll go ahead and make an epic on the graphics board to track this.