[Community Project] WIP Weather & Water Shader

**Welcome to the community created Simulation, Weather (WIP), and Dynamic TOD system! **

**The point of project is twofold. First, it aims to provide a realistic water simulation that is both highly customizable, and being as physically accurate as possible. The second aspect is in regards to the weather and time-of-day setup.

The reason the Weather/TOD is in the same project is due to how much of the itself is driven by the weather around it, to allow integration of real life simulation, both parts are necessary for such as wind, rain, and storms. The Beaufort Scale will be implemented to allow custom control of the sea state and weather in one place.**

project is currently being maintained by:

List of Contributors

    • Initial Shader + Code for Buoyancy
  • Nadrugal - Additions to the SkyDome
    • Fish flocking AI and a variety of fish
      and more to be added shortly, currently rewriting post.

Want your name on list? Feel free to make improvements to the OceanDemo project, and either PM me or Post in the thread below with your addition! Even if you don’t think you can help yet, that’s no problem! Any suggestions can be left by posting below as well.

Thanks!

----------------------------------------------------------------------------------------------------------------------------------------------------------

To download (or fork) the project, use the link below.

** Link** - https://.com/UE4-OceanProject/OceanProject

----------------------------------------------------------------------------------------------------------------------------------------------------------

system uses techniques from many tutorials, however it would not have been possible without the help of the following users (Especially , he deserves a lot of credit for !):
, JBaldwin, berna , ufna, , KhenaB, gregdumb and many others. Click on their names to see the corresponding threads!

For those wanting more info on how the waves are created mathematically, ARTICLE goes over everything. Specifically have a look at the section on “Gerstner Waves” for the actual equations that produce the waves.

----------------------------------------------------------------------------------------------------------------------------------------------------------

Newest Features

added in a bunch of new features during my absence, these are available for the 4.8 & 4.9 versions on .

Screens:

SSR

http://www.mediafire.com/convkey/ea7f/9ifotl4151ob4d2zg.jpg?size_id=6

(Click for original size)

Foam

http://www.mediafire.com/convkey/03a1/octvtnvf2kpam4gzg.jpg?size_id=6

(Click for original size)

Shore

http://www.mediafire.com/convkey/f095/70xpo3gp13mprlszg.jpg?size_id=6

(Click for original size)

New features:

-Screen Space Reflections (SSR)
-Planar Reflection support
-Infinite System
-Distance Blended Normals
-Configurable Sets of Panning Normals (Small, Medium, Far)
-Heightmap-based Seafoam & Foam Wave Caps (Thanks Le!)
-Cubmap-based Reflections (optional)
-Exposed many parameters to BP_Ocean. - You can now easily switch between shader versions, change textures, normals, foam, cubemap, heightmap etc.
-Underwater Distortion Effect
-Underwater Caustics

-Fixed buoyant destructible physics (too “jumpy”)
-Fixed a few other problems caused by 4.8 engine core changes

Current known issues:
SSR shader version uses 14 samplers (might not work in/… please let me know)

New Skydome Features

I’m releasing the latest code changes for the new Skydome I’m working on in stages. I want to make sure first part’s accuracy is rock solid before adding additional parts, as they will be dependent on sun/moon positions during the day & year. So is the first of a series of upcoming skydome changes.

update is the high accuracy sun & moon positioning, based on the input latitude, longitude, UTC offset, and local time. The calculations for are very complex, and boring, so I’m only going to go over the values shown in the Debug HUD.

First, what you will see when you open the project, and how to set it all up for your desired location:

When you open the project, you will be in a demo level named dcSkyTestMap, which is a copy of the Island Map level with the skydome added. (if you don’t want to use the new skydome, the Island Map still has the old one). These 2 arrows will show you the direction of the Sun/Moon (yellow/gray) and will update themselves appropriately, and the compass is set to North == +X axis (has not been rotated, default world placement).

To change the date & time, select the BP_Sky reference in the World Outliner, and expand the small arrow beside Local Time in the Default section. Here you will also find the controls for Latitude, Longitude, UTC Offset Hours, whether to allow Daylight Savings time (calculated automatically if enabled), and a Time Scale Multiplier which allows you to speed up (or slow down) time. By default is set to 10 which means 10 seconds of game time goes by every 1 second in real world time.

The values are automatically clamped in code to the maximum number of seconds in a minute (59), hours in a day (23), days in the current month (28 to 31), etc. I had clamped the sliders to not exceed these values, but for some reason it won’t allow you to change the value with it turned on, so just be aware that values greater than min/do not have any effect.

Finally we have the Debug HUD, will look very confusing to most people, but is as simple as I could make it while still providing the necessary information. Here’s what it looks like, the values are broken down below:

The best way to verify data is to use website and enter in the date/time, latitude & longitude info into these boxes (or use the map, but make sure the lat/long are correct):

With that entered, all of the other fields will populate themselves with data. The values in game vs the values on the website will vary slightly (0.1 to 2 degrees average) and are not meant to be exact, calculating the exact position is not feasible (or necessary) for a game / simulation. Using approximations allows high accuracy, without performance concerns.

Now, what these values mean:

SUN

  • Time Correction Factor (TCF): The number of minutes to add/subtract to account for the variation in Solar Time within a gives time zone.
  • Equation of Time](http://www.pveducation.org/pvcdrom/properties-of-sunlight/suns-position) (EOT): An equation that corrects for the eccentricity of the earth’s orbit and axial tilt for the given date/time.
  • Hour Angle (HRA): Converts Solar Time to the number of degrees the sun has moved. 0 == sun’s highest point, so the value will be negative in the east (morning) and positive in the west (evening)
  • Declination](Declination Angle | PVEducation): The earth’s axial tilt for the given date/time vs the sun. varies from -23.4397 (northern hemisphere winter) to +23.4397 (northern hemisphere summer).
  • Altitude Angle](Elevation Angle | PVEducation): The vertical angle of the sun in the sky measured from the horizontal, 0 = sunrise, 90 = highest point of the sun that day (time varies) **NOTE: For value to work in UE4 coordinates we need to subtract 180 from the result, is why the value differs in the actual rotator’ pitch value.
  • Azimuth Angle](Azimuth Angle | PVEducation): The horizontal compass direction of the sun. At solar noon angle will be exactly due south (-180) (local time varies)
  • Current Rotator Value: The current rotation of the Sun’s Directional Light.

References used for solar positioning:
http://www.pveducation.org/pvcdrom/p…/suns-position
http://www.stjarnhimlen.se/comp/tutorial.html#5
http://www.powerfromthesun.net/Book/…chapter03.html

MOON

  • Approximations L/M/F: These are approximations for the location of the moon in it’s orbit around the earth, including the inclination of the orbit, orbital eccentricity, arg of perigee, and longitude of ascending node
  • Ecliptic Longitude](Ecliptic coordinate system - Wikipedia): The longitude location of the moon on the celestial sphere.
  • Ecliptic Latitude](Ecliptic coordinate system - Wikipedia): The latitude location of the moon on the celestial sphere.
  • Mean Distance (km): The distance of the moon from earth, in kilometers.
  • Declination: Similar to the solar declination, is the angle of the earth’s axial tilt, but also takes the inclination of the moon’s orbit into account.
  • Right Ascension: Angular position of the moon measured eastward along the celestial equator. Both right ascension and lunar declination are found by converting from ecliptic to rectangular coordinates (x/y/z), rotating to account for earth’s axial tilt, then converting back into spherical coordinates.
  • Sidereal Time: A time scale (measured in degrees) based on the rate of earth’s rotation relative to fixed stars, rather than the sun. is a constant value that varies only by location (not time), which differs from the actual definition of Sidereal Time, we only use it as a reference.
  • Hour Angle (HRA): Similar to the sun HRA, however is measured against sidereal time instead of solar time. The number of degrees the moon has moved from time 0 (0 to 360 degrees).
  • Altitude Angle: Same as the sun, vertical height of the moon. Value is found by converting Ecliptic (celestial sphere) coordinates to geocentric (observer to sky) coordinates.
  • Azimuth Angle: Same as the sun, horizontal compass direction of the moon. Value is found by converting Ecliptic (celestial sphere) coordinates to geocentric (observer to sky) coordinates.
  • Current Rotator Value: The current rotation of the Moon’ Directional Light.

References used for lunar positioning:
http://aa.quae.nl/en/reken/hemelpositie.html

http://www.stjarnhimlen.se/comp/tutorial.html#7

There is an excellent video explaining the basics of how we calculate the time of day, calendar systems, and the earth’s rotation in the following video (which came out the day after I posted ). Highly recommend watching it to get a good idea how works:
watch?v=IJhgZBn-LHg

All of the above calculations are implemented in the plugin to ensure there are no performance issues. The blueprint BP_Sky is based off the TimeManager class (in the plugin) and uses it’s functions to calculate the sun/moon/moon phases in the base class. makes the blueprint much easier to read, and reduces it’s complexity considerably. These functions could be used by any actor, such as a custom skydome system, by either adding the actor as a child, or inheriting from the actor and calling the Calculate xxx functions.

Please try it out, let me know how it works for you, and whether you have any problems. I have been testing the system out and so far it seems to be working great, but feedback would be much appreciated! :slight_smile:

Version 4.12.2 has now been released.

You can download the new release (and all other versions) from here

4 Likes

Well, you don’t need good grammar with a shader like that, friend.

Looking great . Are you intending to release as a free tutorial, or as part of a marketplace submission? Either way, keep us updated!

Thanks ! The tutorial and any content released would be free, I don’t have any plans to market . It is just a project I am working on to learn some of the more advanced techniques, as well as something I may someday incorporate into a game.

Fantastic Work ! I would really like to see implemented into a project at some point. Be sure to keep us updated as you progress along with your Shader. Have a great day and be sure to keep up the great work!

Hi !!
Great job pal! The surface moves in a very good way! Keep up the good work!
How many waves do you mix? I use 4 :slight_smile:

Thanks ! Great to hear from you! I have been keeping notes while working through , so hopefully it will make a good tutorial in the end. :slight_smile:

Thanks! And thank you for all of your help with getting set up, much appreciated! :slight_smile:

In the video I was using 8 of them actually, I have tested with a range of waves from 2 up to 16 each with varying direction and amplitude. I added a bunch of switch statements so I can add more waves from a material instance, with all of the values hooked up with parameters as well for each wave. It took a while to set it all up, but being able to adjust properties in an instance has been a huge help. Eventually I will move them all back into a function to keep things organized, but having to compile shaders for every little change was driving me crazy, so until I find just the right mix of values I am going to leave them in the material.

What kind of a plane do you use? Mine is 2048x2048 subdivided 120x120 and then scaled in the editor with 1x tessellation. I am probably going to need to increase the size & subdivision to get the wave peaks to look better. I will be experimenting with in the coming days, the performance so far is really good so I am not too worried about increasing the detail a bit.

I am working on the foam and color at the moment, trying to get it to look more realistic like yours looks! Thanks again. :slight_smile:

That’s some nice work ! I think that those waves look really cool!

nice motion. feels very real.

Thanks in advance for sharing the tutorial and a sample, . It looks good. :slight_smile:

Thanks guys! :slight_smile:

Just wanted to note I have updated the original post with the video below showing some of the customization options, and a very early wip look at some foam! Hopefully longer version shows better details, but I left the link for the original video in the first post as well.

F3QAzlBK8iQ

A quick update on my shader, I haven’t been able to work on it as much as I’d like, but finally have a new video update. I have managed to switch over to a translucent material, due to the wave heights overlapping I was encountering an with translucent depth sorting causing issues, but have that under control now. I have also moved all of the material parameters into a blueprint so everything can be controlled in one place. Still need to add in many more features, but translucency with proper depth shading was not as simple as I expected.

AVYg9hJQxgM

, work man, I’ve been watching with keen interest.

Let me know if you need any help with that, I helped write that code (or whatever the original version of it was). All (or at least most of) the magic happens by creating a vertical skirt on the edge, and stretching it out to the horizon, and having it parented to the camera. I think there may be some trickery in the shader as well, can’t really recall.

Hey thanks man, good to hear from you! :slight_smile:

And yes, I will certainly be needing help with the infinite water plane, I have tested out some LOD’s with separate material instances and have had some success, however your system sounds so much better, and would love to get it working! I have not been able to do any work on yet, but I would like to be able to release as free content when it is complete for people to add into their game, so I want to try and keep the system as simple as possible, while allowing it to be extended by users. If I could get it working with good performance, a BP only system would be ideal for the example project (from the looks of the code it doesn’t look possible to do BP only, but maybe a simpler system). But I would also like to create a more advanced system in code to use in a project sometime in the future.

Any ideas or thoughts on how you would go about the simpler system are most welcome! But if code is necessary, I am not against using it at all, just less code the better so it is simple to understand for those who may download it in the future. Thanks again! :smiley:

So it should be doable without any code.

The thing is how the grid vertices are done.

How it works is first of all being parented to the camera position and z-axis rotation (other axis rotations don’t affect it). It has a central grid, a border grid surrounding the inner grid and which is stretched to the far view distance, and then a “wall” of horizon quad, forming a type of skirt that goes directly upwards from the border grid.

Here’s an ASCII diagram from the code (setupVBIB function here):



   //   x------------x
   //    \      6     \    <- horizon quad is really 'above' the front border
   //      x ---------  x     not in front of it
   //      | \    2   / |
   //      |   x---- x  |
   //      |   |     |  |
   //      |  5|  1  |3 |
   //      |   x --- x  |
   //      | /    4    \|
   //      x------------x


1 = Inner grid

2-5 = Border grid

6 = Horizon quad

So as long as you can create a mesh that looks like that and change the vert positions, it should be doable without any C++ code. Not sure what’s available in that respect, but I imagine it should be doable.

The setupVBIB function has a lot of comments on how the grid and stuff is set up, so going over it should help.

It’s been a while since I updated thread, translucency has been a major headache for the system. For that reason I will be releasing two versions of the shader, opaque & translucent, so you guys can get good results no matter what. The translucent material would be better for scenes closer to the shore and areas you want to see underwater, for the open though you can get away with an opaque material in some cases.

Today I was playing around with some weather , I have been building a custom atmosphere/sky/weather system as well (which may also get released) and decided to throw in some special to see how it looks, so here is that video:

mP9zCLP4s_k

was thrown together rather quickly, so the rain and lighting are not custom made but instead modified versions of assets from the example content, but I will be re-creating them soon. The sky is made up of a few layers, with a large sky sphere that controls the dynamic TOD sun/stars and atmosphere colors, a moon mesh, an inner sphere for additional atmosphere modification, a panning cloud layer on a dome shape with directional control, a wip particle cloud generating system, random lightning particle generator, and HeightFog all combined into a BP that is highly customizable. It needs some more work, but I am happy with the results so far.

I should have everything ready to distribute fairly soon (an ‘alpha’ version at least, it needs more work), hopefully either later week or early next week. I will update the thread with more details soon. :slight_smile:

@n00854180t - I have been trying to get a better mesh setup working, so far it has not worked out, changing the vert positions in a BP is creating a lot of artifacts when playing in editor. I abandoned that approach for the time being going back to a large sub-d plane as the tessellation does a pretty good job, but it’s still something I would like to try and implement at a later date, so thank you for all the info and I will keep you posted on how it goes!

Hmm, you shouldn’t need to change the vertex positions for that - just make it static with the layout mentioned before ( grid surrounded by planes, with a wall at the edge). T3D used the vertex shader to push the skirt’s top verts up (and maybe out too) to make it seemless. Moving with the player should be done by just transforming it, make it a BP or whatever with your statically laid out verts in the configuration above (you could even use a sub-d for the middle grid too) and then attach it to the character (which should be offset to the grid so that there are only a few grid squares behind them wasted) and lock the Z position.

The only vert changes that are really needed at run time are pushing the very end skirt up to the horizon so that it works when players move in the z direction.

You’ll have to account for the rotation and stuff in your wave simulation - you don’t want it to rotate with the player rotation, basically.


Regardless of the infinite idea, it looks , very nice work.

Ok guys, I could keep adjusting the system forever, instead I am releasing an initial version of the system today. Right now Buoyancy is not working correctly, the system is all there, but needs more troubleshooting, hopefully I have that ready by the weekend.

So without further delay, Here we go, for UE4 version 4.5.1

I was able to reduce the download size, so only the Demo Project can be downloaded (to cut back on internet traffic).

**For a demo project containing the System and More - DOWNLOAD **version 0.1.2 (bug fix) now on GitHub, download the version that matches your editor version
-Everything has been placed into a basic scene so you can just start playing with the waves and explore the systems involved.
-You get all of the files in the download above, plus I have included my WIP Skydome & weather system. It is far from complete, but I like it better than the default for now, and may be a good starting point creating your own system. :slight_smile:

system uses techniques from many tutorials, however it would not have been possible without the help of the following users:
JBaldwin, , berna , ufna, , KhenaB, gregdumb and many others. Click on their names to see the corresponding threads!

For those wanting more info on how the waves are created mathematically, ARTICLE goes over everything. Specifically have a look at the section on “Gerstner Waves” for the actual equations that produce the waves.

**However I have a request for those who download, since the community helped me create , I want to become a Community project, so if you have an idea to improve either the Sky/Weather or system (which both need more work), please make the changes on your end, and either send them to me and I will incorporate them into a project for all of , or post a link with your changes here, and I will update the project.

The have many requests for a working water/weather system, and I think that with project we could create an looking, highly functional product that will give other users a to learn how these are created. I have not included everything in the downloads above, but I will be continually updating them as new parts are added.

So to the Community: Please help me make a reality!! It would be such a great tool to have around for all of us, never mind just those who are new to game development.**

For now any improvements you can share, please either post them here, or PM me with the files, I will integrate them and add a new release for the community. :smiley:

I’m still working on the tutorials, but wanted to allow anyone who wants to download it give it a try now, as it is highly commented.

I love the UE4 community here and made it my mission to provide as much content for free as possible, it’s my way of saying thank you to Epic for the community they built here, you all feel like family to me!
project wasn’t supposed to take long, however I am going through a difficult time at the moment. For reason I could not work on project as much as I would have liked to, and is why I would appreciate anyone’s help to improve system for the community.

Enjoy ! Look forward to any suggestions, additional features, and help from the community to make even better. :slight_smile:

thanks a lot! great work indeed!

Very cool stuff! Unfortunately my Project ist still on 4.4, so I can’t fully play with for now until I can Update to 4.5 :slight_smile:

I will be adding a download for version 4.4 over the next couple of days as well. I don’t know how much demand there is for earlier versions, but I can add them as well if requested. :slight_smile: