Page 1 of 1

Calculate distance between front and back faces?

PostPosted: Tue Oct 02, 2018 5:40 pm
by naitoookami
So I have put together a shader for some magic glowing crystals. I wanted some specific things from it. I wanted it to have transmission and translucency, it had to be transparent with distortions on what's behind it, and finally I wanted it to be more transparent at the edges as well as a lighter color and allowing more light to pass through depending on the depth of the model.

I've gotten everything here working EXCEPT the depth-based transparency. In the meantime I slapped a fresnel effect onto it for almost the effect I wanted but I wanted true depth. So, is there a way to calculate the distance between the back face and the next front face behind it in Amplify?

Image

Re: Calculate distance between front and back faces?

PostPosted: Wed Oct 03, 2018 10:33 am
by Ricardo Teixeira
naitoookami wrote:So I have put together a shader for some magic glowing crystals. I wanted some specific things from it. I wanted it to have transmission and translucency, it had to be transparent with distortions on what's behind it, and finally I wanted it to be more transparent at the edges as well as a lighter color and allowing more light to pass through depending on the depth of the model.

I've gotten everything here working EXCEPT the depth-based transparency. In the meantime I slapped a fresnel effect onto it for almost the effect I wanted but I wanted true depth. So, is there a way to calculate the distance between the back face and the next front face behind it in Amplify?

Image


Greetings,

Thank you for getting in touch, we would be happy to help!

It really depends on how you have it set up; you could build it based on our Translucency sample using a specific texture to control the effect, the Transmission sample, or using your own setup using with a custom implementation aided by the Surface Depth node, the Depth Fade, Screen Depth, or Camera Depth Fade node.

Thanks!

Re: Calculate distance between front and back faces?

PostPosted: Wed Oct 03, 2018 3:15 pm
by naitoookami
Pulling my hair out over this one. I knew I could use a texture for depth as this shader from the translucency example but this shader is for VRchat so I'd rather not have to create depth maps for each of the models I want to put this on. A method of finding the true depth of the model and using that is preferred. So I tried to follow your advice and tried to use any of those depth nodes. Experimenting with it I was able to kinda sorta get the effect I wanted but that made the crystal get more or less transparent with camera distance. So I thought of trying this...
Image

Attempted to multiply out front faces and back faces then find the distance between them but that solution here just resulted in the same camera distance fading that I didn't want. I'm pretty noob when it comes to shader stuff tbh I just can't wrap my head around how to get the numbers I need.

Re: Calculate distance between front and back faces?

PostPosted: Wed Oct 03, 2018 3:37 pm
by Ricardo Teixeira
naitoookami wrote:Pulling my hair out over this one. I knew I could use a texture for depth as this shader from the translucency example but this shader is for VRchat so I'd rather not have to create depth maps for each of the models I want to put this on. A method of finding the true depth of the model and using that is preferred. So I tried to follow your advice and tried to use any of those depth nodes. Experimenting with it I was able to kinda sorta get the effect I wanted but that made the crystal get more or less transparent with camera distance. So I thought of trying this...
Image

Attempted to multiply out front faces and back faces then find the distance between them but that solution here just resulted in the same camera distance fading that I didn't want. I'm pretty noob when it comes to shader stuff tbh I just can't wrap my head around how to get the numbers I need.


Why not simply use the Depth Fade node?

Can you elaborate on the effect you're looking to create?

Thanks!

Re: Calculate distance between front and back faces?

PostPosted: Wed Oct 03, 2018 4:26 pm
by naitoookami
So I added in just the depth fade node like you suggested but now it's just fully transparent with a light pink outline.

This is what I want it to look like, roughly done in photoshop.
Image

And this is what the depth fade node did to it
Image

I just want a nice transition between thick and thin parts of the mesh, essentially.

Re: Calculate distance between front and back faces?

PostPosted: Wed Oct 03, 2018 4:38 pm
by Ricardo Teixeira
naitoookami wrote:So I added in just the depth fade node like you suggested but now it's just fully transparent with a light pink outline.

This is what I want it to look like, roughly done in photoshop.


And this is what the depth fade node did to it


I just want a nice transition between thick and thin parts of the mesh, essentially.


Sorry but without an actual shader sample we can't examine the issue.

If you're looking to create that type of transition, I'm afraid it does involve some additional work.

Here is an existing discussion regarding the Thickness effect you're looking for:Unity Forum

Re: Calculate distance between front and back faces?

PostPosted: Wed Oct 03, 2018 6:11 pm
by naitoookami
That seems to be out of my skill range for now, sadly. In fact found the same post before coming here hoping that perhaps there was a shader function for it or another similar solution. Thank you so much for the quick responses and all of the help, you guys are the best.

Re: Calculate distance between front and back faces?

PostPosted: Thu Oct 04, 2018 10:18 am
by Ricardo Teixeira
naitoookami wrote:That seems to be out of my skill range for now, sadly. In fact found the same post before coming here hoping that perhaps there was a shader function for it or another similar solution. Thank you so much for the quick responses and all of the help, you guys are the best.


It's a bit tricky. I'm afraid that since it requires additional scripts beyond the scope of our editor, it's not something that we can add. I would still recommend looking into the other depth nodes, you might be able to build a similar effect.

Hope it helps!