Amplifying your potential.

Trouble with screen space and alpha-masked shader

Node-based Shader Editor
6 posts • Page 1 of 1

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: 180
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 5 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 65 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: 30
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: 30
Joined: Wed Mar 01, 2017 6:33 pm


6 posts • Page 1 of 1

Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 1 guest