Page 1 of 2

Trouble with screen space and alpha-masked shader

PostPosted: Fri Dec 08, 2017 11:06 pm
by JoNax97
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!

Re: Trouble with screen space and alpha-masked shader

PostPosted: Mon Dec 11, 2017 12:38 pm
by Amplify_Borba
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!

Re: Trouble with screen space and alpha-masked shader

PostPosted: Tue Dec 12, 2017 7:13 pm
by JoNax97
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!

Re: Trouble with screen space and alpha-masked shader

PostPosted: Wed Dec 13, 2017 12:13 pm
by Amplify_RnD_Rick
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 5053 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!

Re: Trouble with screen space and alpha-masked shader

PostPosted: Wed Dec 13, 2017 5:31 pm
by JoNax97
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!

Re: Trouble with screen space and alpha-masked shader

PostPosted: Wed Dec 13, 2017 5:49 pm
by Amplify_RnD_Rick
No problem at all, we're here to help!

Re: Trouble with screen space and alpha-masked shader

PostPosted: Thu May 10, 2018 7:37 pm
by AdultLink
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! :)

Re: Trouble with screen space and alpha-masked shader

PostPosted: Thu May 10, 2018 11:49 pm
by Ricardo Teixeira
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!

Re: Trouble with screen space and alpha-masked shader

PostPosted: Fri May 11, 2018 10:13 am
by AdultLink
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.

Re: Trouble with screen space and alpha-masked shader

PostPosted: Fri May 11, 2018 10:44 am
by Ricardo Teixeira
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.