[Community Project] WIP Weather & Ocean Water Shader
Welcome to the community created Ocean Simulation, Weather, and Dynamic TOD system. The point of this project is twofold. First, it aims to provide a realistic ocean 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 ocean itself is driven by the weather around it, to allow integration of real life ocean simulation, both parts are necessary for effects 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.
- Handkor - Initial Shader + Code for Buoyancy
- Nadrugal - Additions to the SkyDome
- Komodoman - Fish flocking AI and a variety of fish
and more to be added shortly, currently rewriting this post.
Want your name on this 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.
This system uses techniques from many tutorials, however it would not have been possible without the help of the following users (Especially Handkor, he deserves a lot of credit for this!): Handkor, JBaldwin, berna , ufna, Ehamloptiran, 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, THIS ARTICLE goes over everything. Specifically have a look at the section on "Gerstner Waves" for the actual equations that produce the waves.
TK-Master added in a bunch of new features during my absence, these are available for the 4.8 & 4.9 versions on GitHub.
(Click for original size)
(Click for original size)
(Click for original size)
-Screen Space Reflections (SSR)
-Planar Reflection support
-Infinite Ocean System
-Distance Blended Normals
-Configurable Sets of Panning Normals (Small, Medium, Far)
-Heightmap-based Seafoam & Foam Wave Caps (Thanks Tin 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
-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 linux/mac.. 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 this 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 this is the first of a series of upcoming skydome changes.
This update is the high accuracy sun & moon positioning, based on the input latitude, longitude, UTC offset, and local time. The calculations for this 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 this 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), max hours in a day (23), max 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/max do not have any effect.
Finally we have the Debug HUD, this 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 this data is to use this 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:
- 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 (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: The earth's axial tilt for the given date/time vs the sun. This varies from -23.4397 (northern hemisphere winter) to +23.4397 (northern hemisphere summer).
- Altitude Angle: 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 this value to work in UE4 coordinates we need to subtract 180 from the result, this is why the value differs in the actual rotator' pitch value.
- Azimuth Angle: The horizontal compass direction of the sun. At solar noon this angle will be exactly due south (-180) (local time varies)
- Current Rotator Value: The current rotation of the Sun's Directional Light.
- 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: The longitude location of the moon on the celestial sphere.
- Ecliptic Latitude: 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, this 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. This 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.
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 this). Highly recommend watching it to get a good idea how this works: https://www.youtube.com/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. This 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!