I'm Making a custom ocean shader and I'm having some issues with the depth.
My ocean looks like this at the moment
As you can see, the part of the character that is over the water, is showing in the refraction.
Now, with this nodes
I can get the depth, which looks like this
Then I can apply some refraction with this nodes
To have my depth look like this
Now the depth is refracted as the transparent effect, achieved through a grab screen color, with this nodes
Which again, looks like this
I need to get, somehow, a mask that looks like this
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.
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.
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.
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.
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?
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.
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.. 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!
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.
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
and these are the nodes I used
I still can't quite understand how or why it works, but I'm glad I got that to work... 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!
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!