The water is as shown in the screenshot

Hi. How do I add water like in the screenshot below? I didn’t find it in the documentation about water.

  1. The water in this screenshot is rendered using a setup (model in X3D format + shaders) in our demo models.

    • To see it in action, get the demo models (simplest: just git clone https://github.com/castle-engine/demo-models) and open using our Castle Model Viewer the file demo-models/water/caustics/Barna29.x3dv .

    • Walk around in Castle Model Viewer and dive into the water freely. AWSD for movement, hold right mouse button for “mouse look”, “C” to crouch (and get under the water surface).

    • Take a look at the Barna29.x3dv sources, it’s an X3D file (you can open it in any text editor) to see how it’s done. There are water and caustic shaders present in the same directory.

    As you will see above, the way it works is rather involved, and not really something you can easily reuse in your own project, without understanding various pieces of it. I’m giving this information so that you can explore it :), but admittedly I recommend you not to try to reuse this particular water, instead see point 2 below:

  2. The “water setup” that is simpler, and uses our mirrors on flat surface support, and is thus more easy to “reuse” in your own projects, is inside the examples/terrain/ demo.

    • Copy stuff from there, if you want to have “easy water in 3D game/application” in your project.

    • In particular, copy the water subdirectory, examples/terrain/data/water. It contains some shaders plus water.x3dv. In your own application, you can create TCastleScene and load the water.x3dv there (setting TCastleScene.Url to point to water.x3dv in your data).

    • And water.x3dv has a bunch of parameters that are easy to adjust in a text editor.

      Like the shape/size of the water surface:

      geometry IndexedFaceSet {
      coord Coordinate {
        point [ -1 0 -1, -1 0 1, 1 0 1, 1 0 -1, ]
      }
      

    Like water color / transparency:

        material PhysicalMaterial {
          transparency 0.3
          baseColor 0.5 0.5 1
    

    Shaders contain parameters to control waves:

    #define wave_speed 1.0
    #define wave_size 20.0
    #define wave_calmness 10.0
    #define wave_perturb_reflection 0.01
    

    Tweak all parameters above to your liking :slight_smile:

  3. Future: We want to develop “material components” (see roadmap item: Roadmap | Manual | Castle Game Engine ) that would allow to “wrap” such water in a nice component, reusable both in CGE editor and from Pascal code. This will avoid “copying around” and tweaking the X3D file and shaders for such tasks in the future.

2 Likes