[Community Project] WIP Weather & Water Shader

You should be doing the opacity masking in the material by the way :stuck_out_tongue: you will not be able to mask the out from the post process (unless there is a scene texture before translucency that I’m not aware of).

Btw, I did a few tests yesterday to see if I could do something on my end to allow for easy masking but unfortunately you cannot use the stencil buffer for opacity masking and underwater masking at the same time (they interfere with each other).
However, in the case of a submarine it should be easy to simply use a capsule mask in the material instead of the stencil buffer, you would need to drive the start and end point of the capsule via material parameter from the submarine blueprint (the material function for the capsule mask is called DistanceField_Capsule or something like that if you wanna give that a shot).

If you do not care about the underwater masking as much then you can use the stencil, I tried to mask the opacity when on the inside of a box and it works well.

No matter what I did to the material I could not get it opaque (the roof is still here, and interestingly renders ABOVE everyhthing) and the green is coming from no where as far as I can tell nothing green is hooked up ATM.

I never thought about applying these into the materials themselves.

Will do some more playing around! Thanks TK!


is what ahppens with an applied… it blends the original material (matte pink) with the blue. Very interesting learning alot.


Regarding the capsule masking, I never learned how to use that node, put it into a graph once and said, now what. Hence why Ineed to do the material courses for ue4.

Edit:

Although does mask the out thats right int he middle of the “room”, but only allows color shading cartoon style.

Learned what I’m sure will comein useful will play with tihs more than when I learn more about materials, theyre still pretty foreign to me. ThanKs TK


really excites me cause it feels so close to getting proper masking so that I can build my sub interior inside my sub exterior mesh so that I can start creating a scene instead of just driving a submarine around the blowing up other ships from the ship orperiscope point of view. will give a third or first person view. Very good feeling :slight_smile:

Any thoughts on how to reduce the jitter/artifacts in the reflections and distant ? I would love to pitch in and help but I’m still just starting to take a look at the project and not sure yet what is causing some of the visual issues.

Yeah the reflections is definitely the biggest that I have with the at the moment… screen space reflections are not gonna cut it here, you can improve them a bit by increasing the ray count in one of the .usf files but it comes with a cost and the result will be still far from accurate or clean.
Not really that much that we can do right now, it’s up to Epic to implement a better reflection system (it has to happen eventually but the question is when).

Anyways, I think I’m just about finished with the post process material:
http://www.mediafire.com/convkey/6c8a/96cwsflg676l4skzg.jpg?size_id=5
It looks better in motion with the distortion and all :stuck_out_tongue:
There are still many things I wanna add (like god rays and lens splashes) but will have to do for now.

I still need to fix a few things in the material and plugin code before the release but it shouldn’t take too long, maybe Friday.

Is for the PP -> waterplane -> horizon most water planes suffer from?

I noticed on the bug tracker on you said FFT based wave forms are in the works eventuallly. Arnt gerstner waves FFT based?

If not theres alot of code floating around working with FFT’s It looked similar when I glanced over it to the 8 sin sum gerstner setup though.

Getting the fog right seems to help clear up most of the distance scattering. I’m working on blending the fog with the sun position to get a smoother looking transition.
I still need to find the right values, it’s hard to blend with the skybox and not kill the color/brightness of the water in the process :slight_smile:

watch?v=-dKj3AZVX_E

Also do you know what might be causing FXAA to create the dark spots on the ? I would like to avoid using Temporal AA so it’s on my list of things to see if I can figure out and fix.

Also The new underwater PP looks great :smiley:

A Gerstner wave is basically a modified sine wave to be less round, more choppy :stuck_out_tongue: it’s a relatively simple algorithm.

FFT on the other hand is a really complicated algorithm (I doubt there are any people who can write the thing from scratch) which is far more physically correct.
It’s what they used in black flag, gta5 (etc.) and pretty much every movie where there is cgi .

Luckily for us we already have 2 FFT implementations in UE4, WaveWorks and VaOcean.
Both of them are incomplete atm but the base is there and it’s enough for me to build on, there is an updated VaOcean branch in my repo. but there are performance problems with the FFT readback that I haven’t solve yet but I’m close.

SSR is not supported with FXAA unfortunately… Anti-aliasing and reflections are the top things rendering-wise that I wish Epic improves upon (don’t we all?).

@ - that post process looks gorgeous, do want :smiley:

I knew how a gerstner wave looks but say code snipper from FFT based waves from unitys “ShaderExperiments” off theyre using FFT (from a library it looks like ive seen it a few times) surely we could do in c++?


void EvaluateWaves()
    {
        //Debug.Log("Evaluating Waves at " + Time.time * 1000);
		float kx, kz, len;// lambda = -1.0f;
        int index;
        for (int m_prime = 0; m_prime < TextureResolution; m_prime++)
        {
            kz = Mathf.PI * (2 * m_prime - TextureResolution) / OceanSize;
            for (int n_prime = 0; n_prime < TextureResolution; n_prime++)
            {
                kx = Mathf.PI * (2 * n_prime - TextureResolution) / OceanSize;
                len = Mathf.Sqrt(kx * kx + kz * kz);
                index = m_prime * TextureResolution + n_prime;

                ComplexDisplacementMap[index] = hTilde(n_prime, m_prime);

                SlopeX[index] = ComplexDisplacementMap[index] * new ComplexF(0, kx);
                SlopeZ[index] = ComplexDisplacementMap[index] * new ComplexF(0, kz);
                if (len < 0.000001f)
                {
                    DisplaceX[index] = new ComplexF(0, 0);
                    DisplaceZ[index] = new ComplexF(0, 0);
                }
                else
                {
                    DisplaceX[index] = ComplexDisplacementMap[index] * new ComplexF(0, -kx / len);
                    DisplaceZ[index] = ComplexDisplacementMap[index] * new ComplexF(0, -kz / len);
                }
            }
        }
        //Debug.Log("Beginning FFT at " + Time.time * 1000);
        Fourier.FFT2(ComplexDisplacementMap, TextureResolution, TextureResolution, FourierDirection.Backward);
        Fourier.FFT2(SlopeX, TextureResolution, TextureResolution, FourierDirection.Backward);
        Fourier.FFT2(SlopeZ, TextureResolution, TextureResolution, FourierDirection.Backward);
        Fourier.FFT2(DisplaceX, TextureResolution, TextureResolution, FourierDirection.Backward);
        Fourier.FFT2(DisplaceZ, TextureResolution, TextureResolution, FourierDirection.Backward);
        //Debug.Log("Finished FFT at " + Time.time * 1000);
        ApplyComplexMapToHeightMap();

I just implemented the landscape modulation part in the manager so that the buoyancy matches but the performance hit is huge :(… I’m currently using a single ray trace per point to detect the landscape height but for some reason it costs way more than I thought… it could be an with landscapes in general or tracing is simply that expensive(?) I don’t know.

There is one last thing that I can try… read the heightmap pixels rather than tracing, I could load the pixels into a float array on begin play which should hopefully be a lot faster to access but the downside is that I will have to replicate the same math as the heightmap modulation material function (I was hoping to completely avoid that by tracing).

That looks like the part where it reads the displacement, it doesn’t compute the FFT there.

Yup :wink: it looks even better now with animated wet lens effect:


I have also modified a couple .usf files so that GaussianDOF works with the plane properly.

Couldn’t you look into the terrain vertex structure instead?

Looks !

I wonder how games like Crysis do the “thick line” on the plane when the camera is half-submerged. Maybe altering the normals on the edge where it intersects the camera frustum?

So far it doesn’t look like the vertex data is easily accessible… I can’t find any information about either (the only relevant topics in answerhub are about traces).

I’m still searching for a way to do the water line but so far I have managed only a very ugly rough mask :stuck_out_tongue: I thought I could use the stencil buffer for as well but I can’t seem to be able to match a small water line mesh exactly where it needs to be.

How did you go about creating half-in-half-out water effect? That’s not implemented in the project files is it? I’ve been trying to do exact effect for my current Oculus Rift project but I can’t figure it out for the life of me. I’ve just been using a post-process effect, which obviously doesn’t give the desired effect when there’s relatively large waves. Some guidance on would be much appreciated.

I know there are other noobs like me following thread too embarrassed to speak up … community project would benefit from a more detailed Readme file or Version Description Document with the download, describing the differences in the various branches and example maps, and which BPs are mutually exclusive. The Trello board is great, but the “completed” actions does not tells us which BP, branch, or ExampleMap has the new .

For example, caustics is in the complete row, yet OceanExampleMap_01 is the only map with caustics. It is also the only example with translucent water for a coastal level, and buoyancy actors that work and don’t pop up into the air or sink below the surface. But of all the example maps, it is the only one that uses BP_Sky for accurate sun and moon positioning, but I can’t find an animated day/night check box. I would like to use the BP_Skydome from OceanExampleMap_02 but that then causes problems with the translucent water.

Why does the buoyancy work so much better in Map_01? In which BP is caustics implemented in 01 so I can make adjustments? Don’t know.

A lot of I can do myself, even as a noob…swimming, no problem:

One button switch between 1st and 3rd person with 2nd camera attached to root bone to avoid excessive bobbing, no problem:

Add a flashlight:

  1. Smooth inverse kenematics for character’s feet
  2. Where to find treading and swimming animations
  3. Landscape Height modulation to control waves encroaching up the shoreline
  4. Good looking Water line like that in Dying Light
  5. Character buoyancy only when treading or swimming at the surface so it bobs with waves and goes prone when swimming
  6. Swash, backwash, and wet
  7. Function changing water color based on z depth, like seen in Black Flag
  8. Working drivable sea-doo to enjoy the beautiful SSS enhanced waves!

These are my priorities, I would take them on if I could, but beyond my abilities.

Its impressive how far you people have come

That looks very sexy :D, nice work!

The project does have . Not the water on the camera, but the darkening of the screen and audio dampening when you are under water, and taking into account the waves. I don’t know how it’s done, but it’s there to analyze in the project.

Alright so I finally finished implementing and testing the heightmap pixel reading method and it has no performance impact, it might cause a tiny delay on begin play if the heightmap texture to load is large but it’s barely measurable.

The calculated landscape height from the heightmap is not as accurate as the trace since a single pixel corresponds to 4 vertices (at least that’s what I think), so if we need a more accurate result for some reason we could use bicubic interpolation or something like that but it’s really not needed for the heightmap modulation, it makes no difference.

I also added a small optimization to skip the gerstner calculations if a test point is too far below or above the base sea level, I might also add a bounds check to the buoyancy component to skip all buoyancy point iterations if the mesh is completely out of the water.
Not that any of that is important :stuck_out_tongue: the buoyancy stuff already have no performance hit really.

Also added a harpoon gun that I quickly prototyped a few months ago :stuck_out_tongue: it uses a physics constraint for the rope physics and cable component for the visuals and let me tell you it was so much fun making thing :stuck_out_tongue: ships glitching, objects flying to space and whatnot :D… love messing around with these kind of stuff.
http://www.mediafire.com/convkey/c899/95ewm3s35ohu6kgzg.jpg?size_id=5

There are a few more things I need to fix before the release so bear with me just a little longer :stuck_out_tongue:

Alright, i think i have to give plugin a go.

A few questions, is there a working 4.10.4 binary ready?
Is plugin viable for huge tiles, how much fps drop can i expect with reasonable medium settings? Basically i just want standard water, and waves …

I want the boat to move a little forward when the 2 front buoyancy test points are lower than the back 2. Like surfing on a wave. Testpoints don’t change in game so how to do alike?
Thanks