Announcement

Collapse
No announcement yet.

[Community Project] WIP Weather & Ocean Water Shader

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • [ASSETS] [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.


    This project is maintained by:
    - DotCam
    - TK-Master


    List of Contributors

    - 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.

    Thanks!

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

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

    GitHub Link - https://github.com/UE4-OceanProject/OceanProject

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

    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.

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


    Newest Features

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

    Screens:

    SSR

    (Click for original size)

    Foam

    (Click for original size)

    Shore

    (Click for original size)

    New features:

    -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
    -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 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).
    Click image for larger version

Name:	Arrows.JPG
Views:	1
Size:	41.1 KB
ID:	1108144

    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.
    Click image for larger version

Name:	DebugTime.JPG
Views:	1
Size:	71.1 KB
ID:	1108145

    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:
    Click image for larger version

Name:	DebugHud.JPG
Views:	1
Size:	140.1 KB
ID:	1108146

    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):
    Click image for larger version

Name:	Position Website.JPG
Views:	1
Size:	31.5 KB
ID:	1108147

    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 (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.

    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: 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.

    References used for lunar positioning:
    http://aa.quae.nl/en/reken/hemelpositie.html
    http://www.braeunig.us/space/plntpos.htm
    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 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!


    Version 4.12.2 has now been released.

    You can download the new release (and all other versions) from GitHub here
    Last edited by DotCam; 06-15-2016, 10:09 AM. Reason: grammar + notes + Updated video
    [Free Community Project/Plugin] WIP Dynamic Ocean & Calendar Based Sky
    New Features:: Highly accurate sun/moon position, and lunar phase calculations built into the plugin (base class for the SkyDome blueprint)
    In Progress: Weather simulation w/ volumetric clouds

  • #2
    Well, you don't need good grammar with a shader like that, friend.

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

    Comment


    • #3
      Originally posted by Havoc View Post
      Are you intending to release this as a free tutorial, or as part of a marketplace submission? Either way, keep us updated!
      Thanks Havoc! The tutorial and any content released would be free, I don't have any plans to market this. 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.
      [Free Community Project/Plugin] WIP Dynamic Ocean & Calendar Based Sky
      New Features:: Highly accurate sun/moon position, and lunar phase calculations built into the plugin (base class for the SkyDome blueprint)
      In Progress: Weather simulation w/ volumetric clouds

      Comment


      • #4
        Fantastic Work DotCam! I would really like to see this implemented into a project at some point. Be sure to keep us updated as you progress along with your Ocean Shader. Have a great day and be sure to keep up the great work!
        Last edited by [Epic] Gribbs; 09-19-2014, 01:14 PM. Reason: edit

        Comment


        • #5
          Hi DotCam!!
          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

          Comment


          • #6
            Originally posted by Sean Gribbin View Post
            Fantastic Work DotCam! I would really like to see this implemented into a project at some point. Be sure to keep us updated as you progress along with your Ocean Shader. Have a great day and be sure to keep up the great work!
            Thanks Sean! Great to hear from you! I have been keeping notes while working through this, so hopefully it will make a good tutorial in the end.

            Originally posted by berna View Post
            Hi DotCam!!
            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
            Thanks berna! And thank you for all of your help with getting this set up, much appreciated!

            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 this 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.
            [Free Community Project/Plugin] WIP Dynamic Ocean & Calendar Based Sky
            New Features:: Highly accurate sun/moon position, and lunar phase calculations built into the plugin (base class for the SkyDome blueprint)
            In Progress: Weather simulation w/ volumetric clouds

            Comment


            • #7
              That's some nice work DotCam! I think that those waves look really cool!

              Comment


              • #8
                nice motion. feels very real.

                Comment


                • #9
                  Thanks in advance for sharing the tutorial and a sample, DotCam. It looks good.
                  FREE Color LUT Collection
                  FREE Physics Driven Spacecraft Project
                  GTA Style Vehicle Interaction
                  Dynamic DoF(Depth of Field)
                  Camera Crossfade
                  Portfolio

                  Comment


                  • #10
                    Thanks guys!

                    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 this longer version shows better details, but I left the link for the original video in the first post as well.

                    [Free Community Project/Plugin] WIP Dynamic Ocean & Calendar Based Sky
                    New Features:: Highly accurate sun/moon position, and lunar phase calculations built into the plugin (base class for the SkyDome blueprint)
                    In Progress: Weather simulation w/ volumetric clouds

                    Comment


                    • #11
                      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 issue 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.

                      [Free Community Project/Plugin] WIP Dynamic Ocean & Calendar Based Sky
                      New Features:: Highly accurate sun/moon position, and lunar phase calculations built into the plugin (base class for the SkyDome blueprint)
                      In Progress: Weather simulation w/ volumetric clouds

                      Comment


                      • #12
                        @DotCam, awesome work man, I've been watching this with keen interest.

                        Originally posted by DotCam View Post
                        A post by n00854180t HERE about a T3D WaterPlane system is what I will be attempting soon.
                        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.
                        Storyteller - An immersive VR audiobook player

                        Dungeon Survival - WIP First person dungeon crawler with a focus on survival and environmental gameplay ala roguelikes

                        Comment


                        • #13
                          Originally posted by n00854180t View Post
                          @DotCam, awesome work man, I've been watching this 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!

                          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 this yet, but I would like to be able to release this 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!
                          [Free Community Project/Plugin] WIP Dynamic Ocean & Calendar Based Sky
                          New Features:: Highly accurate sun/moon position, and lunar phase calculations built into the plugin (base class for the SkyDome blueprint)
                          In Progress: Weather simulation w/ volumetric clouds

                          Comment


                          • #14
                            Originally posted by DotCam View Post
                            Hey thanks man, good to hear from you!

                            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 this yet, but I would like to be able to release this 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!
                            So it should be doable without any code.

                            The main 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):

                            Code:
                               //   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.
                            Storyteller - An immersive VR audiobook player

                            Dungeon Survival - WIP First person dungeon crawler with a focus on survival and environmental gameplay ala roguelikes

                            Comment


                            • #15
                              It's been a while since I updated this thread, translucency has been a major headache for the ocean 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 ocean though you can get away with an opaque material in some cases.

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



                              This was thrown together rather quickly, so the rain and lighting effects 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 this week or early next week. I will update the thread with more details soon.

                              @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!
                              [Free Community Project/Plugin] WIP Dynamic Ocean & Calendar Based Sky
                              New Features:: Highly accurate sun/moon position, and lunar phase calculations built into the plugin (base class for the SkyDome blueprint)
                              In Progress: Weather simulation w/ volumetric clouds

                              Comment

                              Working...
                              X