Dose Depth Fade node only work with light that has shadow on

Node-based Shader Editor
Post Reply
cyuxi
Posts: 3
Joined: Mon Apr 02, 2018 8:46 am

Dose Depth Fade node only work with light that has shadow on

Post by cyuxi »

Hi,
I was trying to make a depth fade effect to smooth out the intersection of clouds and scene objects, however getting stuck with few problems.

It seems the Depth Fade Node cannot work properly if I don't put a light(with shadow on) in the scene.

If shadow on the light is turned on and the scene is not baked, the Depth Fade Node would just worked well, and this is the result I wanted.
Light_ShadowOn_WithDepth.jpg
Light_ShadowOn_WithDepth.jpg (147.57 KiB) Viewed 4698 times

But the Depth Fade node turned invalid if the light or the shadow is turned off...
Light_ShadowOff_NoDepth.jpg
Light_ShadowOff_NoDepth.jpg (150.42 KiB) Viewed 4698 times
And if we baked the scene, the Depth Fade node just won't work at all nonetheless the Shadow option on light is turned on or not.

Here is how the Depth Fade node applied.
DepthFadeUnlitShader.jpg
DepthFadeUnlitShader.jpg (185.49 KiB) Viewed 4698 times
The materials of the three rocks are simply Standard(specular).

I wonder If there are solutions of making Depth Fade node to work with no lighting and baked scene ?
User avatar
Ricardo Teixeira
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: Dose Depth Fade node only work with light that has shado

Post by Ricardo Teixeira »

Greetings,

Is that a single cloud object?

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!
cyuxi
Posts: 3
Joined: Mon Apr 02, 2018 8:46 am

Re: Dose Depth Fade node only work with light that has shado

Post by cyuxi »

Ricardo Teixeira wrote:Greetings,

Is that a single cloud object?

Thanks!
Hi,
The cloud is a mesh.( I split a mesh into four in order to share the texture map which has four shapes of cloud.)
I'm currently using the Unity 2017.2.0f3.
I have attached the screenshot and the test scene. Please have a look.

I'm looking forward to your further advises.Thanks.
Attachments
TestCloud.unitypackage
(163.89 KiB) Downloaded 222 times
Cloud.jpg
Cloud.jpg (117.15 KiB) Viewed 4687 times
User avatar
Amplify_Borba
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Dose Depth Fade node only work with light that has shado

Post by Amplify_Borba »

Hello, this behavior is expected since the shadow casting pass is not being called due to the lack of light / shadows.

There is a workaround to this, which involves forcing the camera to generate a depth texture in order to access values from the depth buffer on an unlit scene.

You can add the following script to your MainCamera for this purpose:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExecuteInEditMode]

public class EnableDepthTexture : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Camera.main.depthTextureMode = DepthTextureMode.Depth;
    }
Please let me know if this helps, 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!
cyuxi
Posts: 3
Joined: Mon Apr 02, 2018 8:46 am

Re: Dose Depth Fade node only work with light that has shado

Post by cyuxi »

Amplify_Borba wrote:Hello, this behavior is expected since the shadow casting pass is not being called due to the lack of light / shadows.

There is a workaround to this, which involves forcing the camera to generate a depth texture in order to access values from the depth buffer on an unlit scene.

You can add the following script to your MainCamera for this purpose:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExecuteInEditMode]

public class EnableDepthTexture : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Camera.main.depthTextureMode = DepthTextureMode.Depth;
    }
Please let me know if this helps, thanks!
Great! Such a nice trick! It's working now. You also provided me an explicit direction to learn such mechanism of unity.
Thank you Sir! and Happy new year!
User avatar
Amplify_Borba
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Dose Depth Fade node only work with light that has shado

Post by Amplify_Borba »

No problem, we're glad we could help.

Have you had the chance to rate and review Amplify Shader Editor? It would be awesome if you could share your experience with the Unity community, every bit helps and your feedback is extremely valuable to us.

Feel free to get back in touch if you have further issues or questions, thank you and a happy new year to you as well!
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!
Post Reply