Weird Z-Buffer issue

Node-based Shader Editor

Weird Z-Buffer issue

Postby danieleve » Mon Jan 15, 2018 11:05 am

Hello!
I'm new to Amplify Shader Editor, and with this tool I'm trying to make a transparent shader that write into the Z-Buffer (that is not possible with standard Unity shaders).
I did a test with a simple radial gradient texture, using "Alpha Test" for Render Queue (because with Render Queue set to Transparent the shader do not write to the Z-Buffer), with these settings:
Image

The result into the scene of this shader is this one (the colored circles):
Image
As you can see the transparency is not the best, but it's not a big problem.

The real problem is the Z-Buffer, that look like that (in this picture I've hided the box surrounding the circles):
Image
It seem to me that the shader create a very low resolution Z pass, or something like that...
I'm pretty sure that it's not an issue of my texture because it's 2048x2048.
Is it possible to get a reasonably "smooth" Z pass?

Many thanks!
danieleve
 
Posts: 4
Joined: Mon Jan 15, 2018 8:10 am

Re: Weird Z-Buffer issue

Postby Amplify_Borba » Mon Jan 15, 2018 12:01 pm

Hello danieleve, thank you for getting in touch and for your support!

Since you have the "Alpha to Coverage" parameter toggled on, you're converting an alpha to a dither pattern, which produces the visual noise on the circles instead of a smooth gradient.

Also, try setting the "ZTest Mode" to Always to see if this helps you achieve the desired effect.

Please let me know if this information is helpful and if you have any further questions, 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: Weird Z-Buffer issue

Postby danieleve » Mon Jan 15, 2018 1:24 pm

Thank-you Amplify_Borba,
if I don't use "Alpha to Coverage" the Z-Buffer don't change (it's ditered in the same way), furthermore there are problems with the transparency, as you can see in this picture (altough the gradient look much better):
(P.s. If the Z-depth seem to be better is just because the picture is smaller)
Image
So "Alpha to Coverage" seem to me to be the only option to have a (quite) correct picture and write into the Z-Buffer at the same time... isn't it?

I've tried to set the "ZTest Mode" to Always, both with "Alpha to Coverage" and not, but nothing change in the Z buffer, as in this picture (It just change the order in which are drawn the circles, that with "ZTest Mode" set to Always is wrong)
Image

Maybe do you have some other suggestions that I can try?
Thanks a lot again!
danieleve
 
Posts: 4
Joined: Mon Jan 15, 2018 8:10 am

Re: Weird Z-Buffer issue

Postby Amplify_Borba » Mon Jan 15, 2018 3:07 pm

Dithering is Unity's way of rendering shadows over transparency, we're going to perform some further testing on our side to see if there's anything we can do on our side regarding this situation, I'll get back in touch as soon as we have any developments on this!
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: Weird Z-Buffer issue

Postby danieleve » Mon Jan 15, 2018 4:40 pm

Thanks again Amplify_Borba,
I really hope you can find a workaround for this.
Just, talking about shadows, please note how the Z-Buffer change with "Cast Shadows / Receive Shadows" options of the shader are ON or OFF, despite the fact that the light in the scene has Shadows turned off.

Image

Image
danieleve
 
Posts: 4
Joined: Mon Jan 15, 2018 8:10 am

Re: Weird Z-Buffer issue

Postby danieleve » Tue Jan 16, 2018 12:47 pm

I've read a post on the Unity about transparent objects and Z-Buffer (that I should use to put them into the volume fog), that say:
For volume fog... objects do not need to write to the Z-Buffer, but rather the camera depth texture. Only objects that are in the opaque queues (0~2499) and have a shadowcaster pass write to the camera depth texture, but you can make a transparent shader with a queue of 2499 and a Fallback "VertexLit" (not "Transparent/VertexLit") and it'll show up in the camera depth texture. However this has serious implications elsewhere, such as transparency sorting and the directional shadow receiving

Indeed what I need is the camera deth texture, so I've tried in this way:
Image

but, again, the result is wrong: the transparency is not the right one (from 1 to 0), and there's no Depth texture..
Image

Do you have any tip to achieve what was written in the post?
Tkanks a lot!
danieleve
 
Posts: 4
Joined: Mon Jan 15, 2018 8:10 am

Re: Weird Z-Buffer issue

Postby Amplify_Borba » Tue Jan 16, 2018 4:56 pm

Thank you for your patience, our developer has performed some tests on our side and I'm getting back to you with some additional information regarding your situation.

Transparent surfaces have no concept of depth and even if you force them to render any kind of depth there'll be some disconnect between the what you render in final color and what depends on the depth. For instance, shadows are rendered according to the depth, so in order to make transparent objects render any shadows unity calculates a dithered pattern from the alpha channel. This dithered pattern is what you see in the z-buffer. Unity then blurs that pattern making it easier on the eyes.

There's no way of rendering two different depths and have it blend between the two, at least not in a single shader, and even then there would be no way to blend the resulting effects. In order for that to be possible it would need some kind of external management of opaque and transparent objects and render them separately to combine them later in some fashion. Unity already does this with transparent objects.

Transparent objects are a complex issue, you must accept the depth and order issues that they have or rewrite unity rendering system to support something more complex, and even then there's no guarante it'll work. Maybe with the new SRP in 2018 this might become a reality but not for now.

In short, there's no depth way of smoothing the depth.

Apologies for this situation, please let us know if you have any further questions.
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


Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 0 guests

cron