Trouble with screen space and alpha-masked shader

Node-based Shader Editor

Trouble with screen space and alpha-masked shader

Postby JoNax97 » Fri Dec 08, 2017 11:06 pm

Hello,

I've recently started using Amplify Shader Editor to replicate a shader showcased here. The objective is to dissolve the objects in front of the player, and it consists in a 3D noise generator tied to the world position, blended with the distance from screen center, witch then gets used as the value for opacity masking.

Image
This is the result of just applying the noise. Shadows behave as expected.

However I've encountered a problem related with the use of screen position in the shader: Whenever the screen pos. value is involved in the final calulation, shadows stop working correctly. As you can see in the screenshot below, both the projected shadows and the self-shadowing keeps getting rendered for the pixels that are discarded by the opacity mask.

Image

Then after a certain value of the Mask Clip, they disappear altogether. Interestingly enough, this value is either zero, one, or sqrt(2)/2.

This is the composition of the shader:
Image
Image
Image

Does anyone know what am I doing wrong?

Thank you very much!
JoNax97
 
Posts: 3
Joined: Fri Dec 08, 2017 10:48 pm

Re: Trouble with screen space and alpha-masked shader

Postby Amplify_Borba » Mon Dec 11, 2017 12:38 pm

Hey there, thank you for getting in touch and for your support!

Would it be possible for you to send us the shader and, if you're using custom nodes, please be sure to send them as well so we can test this on our side as it will greatly speed things up, thanks!
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Trouble with screen space and alpha-masked shader

Postby JoNax97 » Tue Dec 12, 2017 7:13 pm

Here I send you a test scene that shows the error, including the .shader file (I don't think I need to add any file from ASE, if that's wrong let me know) and a demo material.

Thank you a lot for the support!
Attachments
dissolve_test.unitypackage
(60.05 KiB) Downloaded 150 times
JoNax97
 
Posts: 3
Joined: Fri Dec 08, 2017 10:48 pm

Re: Trouble with screen space and alpha-masked shader

Postby Amplify_RnD_Rick » Wed Dec 13, 2017 12:13 pm

Hey JoNax97,

We took a look at your shader. The issue on shadows appearing on clipped geometry is fairly simple, you just need to set your Render Queue to Transparent.

The fact of clipped fragments are still generating shadow, this is a bit more complicated and is in fact happening because you are using a screen position to determine the Clip operation. Unity renders shadow maps through a different camera/projection which is dependent on the scene light sources thus the screen position results are different.

You can even see this happening on the link you sent. When the cat character passes through the hallway, its fragments starts to get discarded but the shadow remains the same.

There's a small hack you can do to slightly overcome this, but it is far from perfect. By adding a Vertex To Fragment node between the Screen Position node and what comes next ( in your case the Component Mask ) we are forcing an ASE to not use Unity pre-calculated Screen Position but manually calculate our own and interpolate it into the surface body which provide different results from Unity default behavior.

VertexToFragHack.JPG
VertexToFragHack.JPG (34.77 KiB) Viewed 3898 times


But again, this is far from perfect and wont take into account all the discarded fragments on your main camera.


Please let us know if you require further help as we will gladly help you out!
Amplify_RnD_Rick
 
Posts: 40
Joined: Wed Mar 01, 2017 6:33 pm

Re: Trouble with screen space and alpha-masked shader

Postby JoNax97 » Wed Dec 13, 2017 5:31 pm

Thank you very much for your help and the explanation!

I will apply the fix you proposed and tinker around with the results a bit. Honestly, I didn't even notice the shadows in the example. Now I'm starting to think it even looks better, as it helps to reinforce the idea that the object is still present in the scene.

Again, thank you for all the help!
JoNax97
 
Posts: 3
Joined: Fri Dec 08, 2017 10:48 pm

Re: Trouble with screen space and alpha-masked shader

Postby Amplify_RnD_Rick » Wed Dec 13, 2017 5:49 pm

No problem at all, we're here to help!
Amplify_RnD_Rick
 
Posts: 40
Joined: Wed Mar 01, 2017 6:33 pm

Re: Trouble with screen space and alpha-masked shader

Postby AdultLink » Thu May 10, 2018 7:37 pm

Hi!

Piggybacking on this question, since I'm trying to achieve the exact same result, how would you go around creating the emissive border around the noise? I'm kind of a ASE noob and I pretty much am on the stage of "plugging stuff around and see what happens" but I managed to kinda get it working like this:

Image
https://imgur.com/3nGnyqR

I feel like there is a more proper way to do it than this, is that correct? Also, I'd like my fresnel color not to show up on the inner side of faces, is that even possible?

Image

Thank you very much for such an awesome product! :)
AdultLink
 
Posts: 4
Joined: Thu May 10, 2018 7:27 pm

Re: Trouble with screen space and alpha-masked shader

Postby Ricardo Teixeira » Thu May 10, 2018 11:49 pm

AdultLink wrote:Hi!

Piggybacking on this question, since I'm trying to achieve the exact same result, how would you go around creating the emissive border around the noise? I'm kind of a ASE noob and I pretty much am on the stage of "plugging stuff around and see what happens" but I managed to kinda get it working like this:

Image
https://imgur.com/3nGnyqR

I feel like there is a more proper way to do it than this, is that correct? Also, I'd like my fresnel color not to show up on the inner side of faces, is that even possible?

Image

Thank you very much for such an awesome product! :)


Hello,

Have you had a chance to examine the Dissolve sample included in the ASE package?

Be sure to check the Emission area, it's quite similar to the effect you're looking for.

Let us know if you have any followup questions.

Thanks!
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: Trouble with screen space and alpha-masked shader

Postby AdultLink » Fri May 11, 2018 10:13 am

I did check the included dissolve shader, however the dissolve source is a texture and not noise, which seems to change the issue completely. Following a node structure similar to the emission on this shader doesn't do anything.
AdultLink
 
Posts: 4
Joined: Thu May 10, 2018 7:27 pm

Re: Trouble with screen space and alpha-masked shader

Postby Ricardo Teixeira » Fri May 11, 2018 10:44 am

AdultLink wrote:I did check the included dissolve shader, however the dissolve source is a texture and not noise, which seems to change the issue completely. Following a node structure similar to the emission on this shader doesn't do anything.


Hey there,

Using the Step, SmoothStep, or the Remap node, is the best way to achieve the effect you are looking for. If you want to detail the emission area a bit more, I recommend checking the melt sample instead.

I don't see anything necessarily wrong with the way you did your effect except for the noise node, you should really consider using a texture instead of that node, it's quite costly.

Do you have a specific effect in mind, perhaps a reference screenshot?

Let us know, we would be happy to elaborate.
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Next

Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 0 guests

cron