mob-sakai / SoftMaskForUGUI

Enhance Unity UI (uGUI) with advanced soft-masking features to create more visually appealing effects!
https://github.com/mob-sakai/SoftMaskForUGUI
MIT License
1.97k stars 261 forks source link

Incorrect behavior when a world space canvas and an overlay canvas are enabled together #107

Closed noam2000 closed 3 years ago

noam2000 commented 3 years ago

When there are two canvases enabled at the same time, where one's render mode is set to "World Space" and the other to "Screen Space - Overlay", and both have graphics that use Soft Mask, they tend to conflict with each other and produce undesired results, such as the mask not working.

To Reproduce

  1. Create two canvases, one set to World Space and the other to Screen Space - Overlay. Give each a Soft Mask and a graphic with Soft Maskable on. For reference:

image image image

  1. You should notice that one or the other breaks and doesn't produce the desired results. If you disable a canvas (or the Soft Mask on that canvas), then the other graphic will work properly.

image The red graphic is the one in World Space, and the green one is in Overlay. They have the same mask, but only one of them works.

Expected behavior Both masks should work together without conflict.

Environment

Additional context Ticking "Use Stencil" in the Soft Maskable kind of solves the issue, but produces some.. not very soft results as you'd expect from the component.

image

Hopefully it's something that can be fixed. Thank you for your time :)

mob-sakai commented 3 years ago

@noam2000 Thank you for reporting. Could you please attach a minimal project (included Assets, Packages and ProjectSettings directories) that reproduces the issue?

noam2000 commented 3 years ago

Here you go: SoftMaskIssueRepro.zip

mob-sakai commented 3 years ago

@noam2000 Thanks.

I found a problem with the shader for the scene view. I commented out the part and it works in the game view.

noam2000 commented 3 years ago

@mob-sakai

I commented out the lines you highlighted, but I'm getting some slightly.. different results. Although the canvases no longer conflict, the overlay canvas isn't working properly now.

This is from the game view, on the same repro project I've sent. image

mob-sakai commented 3 years ago

Sorry, I was a little wrong.

Comment out here: https://github.com/mob-sakai/SoftMaskForUGUI/blob/upm/Shaders/SoftMask.cginc#L28-L34

And change here to #if UNITY_UV_STARTS_AT_TOP https://github.com/mob-sakai/SoftMaskForUGUI/blob/upm/Shaders/SoftMask.cginc#L35

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 1.0.0-preview.14 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

mob-sakai commented 3 years ago

The issue seems to be fixed in v1.0.0-preview.14.

It works in the game view and the scene view. Please try it!