I have managed to get effect but as you can see all the water gets blocked behind the glass sphere and not just inside of it, also it wouldn’t have worked if my water plane wasn’t translucent
Another approach would be to handle inside the water material. If you transfer the center location and radius of the sub’s glass sphere you can easily calculate the area that needs to be masked.
Same method works for your particles and other stuff that should not show up inside
Cons:
You have to know the number of objects that can cause masking ahead of time and each one will adds a few instructions to the shader (so only use it if you have a small number of “hero” objects)
Only works with shapes that can be easily mathematically defined (spheres, capsules, boxes, etc.)
Thank you so much and Arnage for the suggestions is really appreciated
I have thought about masking the object through the water material directly, i was trying to find a way to calculate the bounds of the object and send that to the opacity but i couldn’t figure it out, if only there was a way to calculate the bounds and transform of the shape and sent that to the material
Arnage, interesting, while seems a bit limited with the shape i could give it a try and model the diving suit/submarine for to work well enough, you mention “transfer the center location and radius of the sub’s glass sphere”, i see that you use a constant4 for the location, would work only for a static mesh our could location be dynamic?
, i’d like to hear more about your suggestion, are you saying that i should calculate the scene depth in order to know the distance between the camera and the submarine mesh from the inside and mask that out?
will all take place from the interior only and the vehicle will be dynamic
Those aren’t constants, they’re parameters. Which you can easily update from a blueprint to make the hole follow the location of the sub.
You are indeed constraint a bit with the shape. However, you only need the transparent parts to line up, if you have opaque hull parts the edge just needs to end up somewhere inside the thickness of the hull, which should allow for some more freedom in shape. Additionally you can also use some extra instructions to create a more complex shape.
Ah, i’m familiar with parameters, i work with material instances, for some reason i had forgotten parameters can be accessed in blueprint
I want to give your method a try, what would be the easiest way to calculate the bounds of each parts of the object, the sphere shape seems quite simple but let’s say the helmet isn’t perfectly round, would have to be an equation done in the material editor with trial and error until the mask matches the mesh?
Math is quite predictable, so trial and error is not necessarily required But yeah, if you need another shape you would have to adjust the math to approximate that shape. Also keep in mind that for other shapes you have to consider the objects rotation in addition to the location.
One additional advantage of method is that you can easily add other such as foam or waves near the sub in a more exact way then the common depth based methods would allow.
Oh you are absolutely right, but in my case i’m sure there will be a lot of trial and error involved
Yes, i have so many ideas that technique will allow me to do, also i have noticed that viewed from the interior the mask doesn’t have to be extremely precise for the effect to look right so is even more reassuring
Are there any good resources out there where i could learn how to create mathematical shapes in the material editor?
Not that I know of unfortunately. A good place to start might be the various gradient and procedural material functions that ship with the editor. They’re mostly 2D and in UV space, but it should not be too hard to translate the concepts to 3D and world space.
Some more ideas to extend method:
Using a texture mask to define an extruded more complex shape around one axis and then using some additional math to define the behavior on the other axis. (might work well for the ship in your first post)
Using a 3D texture to define any shape you want.
Accessing the distance field data generated by the engine for DFAO. (Haven’t tried , so no idea how, but would save you from having to manually create a 3D texture)
These probably go beyond what you need, but might inspire others that read thread.