x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Translucent shader distance

I'd like to preface this question by stating that I'm new to shader development in general. It's entirely possible I'm asking a really dumb question, or a really simple one that I don't have the vocabulary to Google yet.

Alright, so here's what I want to do. I want to make a semi-passable water shader with a depth-based opacity. In the PBR model, my understanding that the engine should handle opacity and reflection via the refraction property. However, it doesn't work properly in UE4, as is documented here (I'm seeing the same weird cutoff at shallow angles).

So, I decided I'd just try and do it myself using the method posted by Roel the previous link. The basic premise of the shader is that the opacity decreases as the depth of the water decreases. In doing some research on this, I came to understand that "depth" is probably a bad term to use. The provided Depth functions only measure distance to the camera, so the opacity looks really bad in deep water if the camera is close to the surface. The texture will look completely transparent despite the land underneath being very far away.

What I want (and here I may use some bad terminology) is distance between the world position of the texture pixel and the world position of the pixel that it is blending with. In short, if I have a translucent texture on object A, I want access to the position of object B:

  camera------>A------>B

Is this possible to get access to in the shader? Through the SceneColor function, I can get the color of the pixel in object B (albeit in screen space, not worldspace), so I'm hoping that the position is available in the rendering pipeline at some point. Again, I'm new so I might be going about this all wrong. If so, please let me know of a better way!

Product Version: Not Selected
Tags:
more ▼

asked Jan 03 '15 at 08:34 AM in Rendering

avatar image

Thundermooseman
6 1 1 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Download this material I threw together quickly. Give it a try!

The result looks like this: alt text

-The opacity based on depth is in there, look at the staircase.

-It has texture planar mapped in world space, so it is consistent throughout your game.

-Custom refraction like in my other post.

-Custom panner so there is control in material instances over the x and y speed.

-It has a little edge fade to make the border not as hard.

cheapwater.jpg (679.3 kB)
watercontent.zip (2.2 MB)
more ▼

answered Jan 04 '15 at 02:48 PM

avatar image

Roel
2.4k 70 43 142

avatar image Thundermooseman Jan 04 '15 at 05:27 PM

Ah, I see now! The DepthFade function is more or less doing what I was going to try to do manually. Thanks for sharing this!

avatar image TorQueMoD Feb 05 '15 at 09:55 PM

Hey Roel. Again thanks for sharing! Just wanted to mention to anyone else who finds this, if you add a Sphere Reflection Capture and a Skylight actor to the world (Found under the Visual tab and Lights tab respectively) it makes everything look fantastic!

avatar image Rxbxgamer555 Sep 17 '16 at 03:37 AM

Can you upload this map so we can see the whole thing or are you working on a game

avatar image Roel Sep 17 '16 at 12:53 PM

This map is from the free Shooter Game example at the bottom of the learning tab in the epic games launcher.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question