Refracted Depth Issue

Node-based Shader Editor

Refracted Depth Issue

Postby Frenk.1999.98K » Mon Jan 14, 2019 5:56 pm

I'm Making a custom ocean shader and I'm having some issues with the depth.

My ocean looks like this at the moment
Image
As you can see, the part of the character that is over the water, is showing in the refraction.

Now, with this nodes
Image
I can get the depth, which looks like this
Image
Then I can apply some refraction with this nodes
Image
To have my depth look like this
Image
Now the depth is refracted as the transparent effect, achieved through a grab screen color, with this nodes
Image
Which again, looks like this
Image



I need to get, somehow, a mask that looks like this
Image
so that in that area, I could replace the refracted character with the real background.



To achieve the mask I thought I could get the difference from the refracted camera depth (which has the whole character, over and under water) and the refracted depth fade node (which has only the part of the character that is underwater).
the problem is that the following node doesn't have an UV input.
Image

Being still fairly new to ASE, After a lot of failed attempts and researches, I still have no Idea how I can refract the depth fade output value...

I hope someone will be able to either help me to refract the depth fade output value, or help me find another way to find the mask I need to hide the above-water character.
Frenk.1999.98K
 
Posts: 11
Joined: Mon Jan 14, 2019 4:55 pm

Re: Refracted Depth Issue

Postby Amplify_Borba » Tue Jan 15, 2019 12:14 pm

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

This is a complicated situation to tackle, ideally you would have to either render your character twice, once for the underwater part and another for what's outside of the water, or alternatively you would do this for everything, not just the character, but both solutions would require handling different buffers and also external scripting outside of the scope of our editor.

There is a more practical approach that can be achieved through the shader, but it might have a couple of issues / artifacts. It is based on this article.

Image

Here's the example shader:
WaterRefraction.zip
(2.17 KiB) Downloaded 211 times


Regarding your feedback, we're going to update the 'Depth Fade' fade node and add an additional input port, which will also allow for simplifying the shader we've shared as it will accept the screen position data. The '_CameraDepthTexture_TexelSize' global variable will also be automatically registered the node.

Lastly, I noticed that you're using an outdated build, please download the latest ASE build through our website, we update weekly and the latest builds usually take a while before landing on the Asset Store.

Please let us know if this helps!
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: Refracted Depth Issue

Postby Frenk.1999.98K » Tue Jan 15, 2019 8:59 pm

Thank you so much for fast reply and for the help!
The material you shared with me helped me a lot, but sadly it didn't solve my issue entirely.
I think that if you'll be able to add an input port to the 'Depth Fade' node that will accept the screen position data (I hope very soon), I'll be able to make it work!
Thank you for letting me know that I can download the latest ASE build through your website, as it's very very handy!

Another thing.
While I was working, today, I had to use two identical 'Custom Expression' nodes, so I tried to see if I could reuse one node, so that I wouldn't end up with the same function getting copied twice in the shader code.
I tried to use the call mode, but I couldn't figure out the right way to do an inline function call, passing the input and returning the output (without the return). I also tried to add a dependency to the original 'Custom Expression' node but It just created a variable with the input of the node in call mode.
Any help with this one, too?

Thanks in advance
Frenk.1999.98K
 
Posts: 11
Joined: Mon Jan 14, 2019 4:55 pm

Re: Refracted Depth Issue

Postby Amplify_Borba » Wed Jan 16, 2019 11:18 am

No problem, hopefully it should be available in the next build!

Regarding your other question, if you have a node that you need to reuse you can use the Register and Get Local Var nodes to pass the data from its output ports and better organize your graph.

Image

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!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Refracted Depth Issue

Postby Frenk.1999.98K » Wed Jan 16, 2019 12:11 pm

Hmm.. not quite.

What I meant was that If I do this
Image
The code will end up like this
Image

I though I could use the call mode to recycle them and end up with only one function, but I couldn't figure out how the call mode node actually works, and how to make it work...
I tried to look through the documentation but the example of use of the node is only for the create mode.

Hope this gives you a better idea of what I meant
Frenk.1999.98K
 
Posts: 11
Joined: Mon Jan 14, 2019 4:55 pm

Re: Refracted Depth Issue

Postby Amplify_Borba » Wed Jan 16, 2019 2:58 pm

Oh, apologies for misunderstanding your question!

You'll have to set the original Custom Expression's Mode to Create, and toggle the Auto-Register parameter On, so that it won't be necessary to connect it to the flow.

Image

After this, you can create any number of Custom Expressions to reference the aforementioned one, just be sure to set it in their Dependencies parameter as to ensure that the original one runs first.

Image

Here's the result in code:

Image

Please let me know if this helps!
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: Refracted Depth Issue

Postby Frenk.1999.98K » Wed Jan 16, 2019 11:02 pm

Yes, that helped me out perfectly, thank you very much!

Quick feedback:
Today I found out that each time I want to download ,i.e. the ASE, I have to reenter the Unity order number. I think it would be nice if the website would memorise it after the first time.
Although, this remain one of the best costumer support I've seen in a while, and also all of the Assets I purchased are amazing. So I'm not complaining too much, I'm just letting you know.. :D
Sadly I also have an'other question that popped up... I'm really sorry but I only recently got into shader making (thanks to ASE) and I happen to bump in things I don't quite know how to solve... :/

I'm trying to make the foam as a kind of intersection effect (as you would normally) but from what I gathered it's done with the depth texture.
How can I achieve those intersection highlights that have a constant looking thickness (mine looks all over the place and has everything but not a consistent thickness, due to the background)?

Also, do you think I could achieve a depth texture, as if the camera was always pointing down?
To clarify, I might describe it as having projected on the surface the height map of what's below the surface.
Now, I know this is probably going over the limit of what shaders can do, but given my current ignorance in the matter, I try to ask anyway.
If this isn't possible, I think I'll be able to render it separately and then pass it as an input texture, even though I'm not yet entirely sure on how I'll be able to position it in the right place..

Again, sorry for all of this trouble, and thank you immensely for the help you've given me so far!
Frenk.1999.98K
 
Posts: 11
Joined: Mon Jan 14, 2019 4:55 pm

Re: Refracted Depth Issue

Postby Amplify_Borba » Thu Jan 17, 2019 10:50 am

Thank you for your feedback, I'll pass this along to the team for further consideration!

Regarding the foam, there are several ways to approach this effect, we have a few samples that make use of the depth buffer, such as the ones you can find in the LowPolyWater, SimpleTerrain ( SimpleTerrainWater ) and Water folders.

Although simple to implement, the caveat with this technique is that by using the depth buffer you won't be able to get the real intersection distance, you'd have to resort to scripting outside of the shader's context in order to get accurate depth data to work with, since the depth fade will be dependent on the camera position.

Please let me know if this helps!
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: Refracted Depth Issue

Postby Frenk.1999.98K » Thu Jan 17, 2019 12:19 pm

Thank you again for the help!

Weirdly enough, I kind of accidentally bumped in the solution I was looking for (regarding having a more consistent depth, almost as if the camera was always pointing down), by simply playing around with nodes and by following some of my instinct..

this is the effect
Image

and these are the nodes I used
Image

I still can't quite understand how or why it works, but I'm glad I got that to work...:D
I also gave a closer look to the suggested sample shaders and it helped me wrap my head more around the foam concept!

Thank you again for all the help, and have a nice rest of the day/week!
Frenk.1999.98K
 
Posts: 11
Joined: Mon Jan 14, 2019 4:55 pm

Re: Refracted Depth Issue

Postby Amplify_Borba » Thu Jan 17, 2019 4:04 pm

That's an interesting solution you've come up with, thank you for sharing it!

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, the Unity Asset Store thrives on user interaction and direct feedback.
Every bit helps, your feedback is extremely valuable to us.

Please don't hesitate to get back in touch if you have any further questions, have a good one!
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