This is a custom material for Armory 3D for drawing underwater caustics inside of a mesh (preferably a rectangular solid) as if it was a volume. You can even move the camera into the volume mesh. The material is more or less based on this neat tutorial by Alexander Ameye, the caustics texture was generated with this tool.
This material requires Armory SDK 22.05 or newer, earlier versions will not work correctly.
The included example file CausticsVolume.blend is not required for using this shader. You can delete it locally after downloading this repository.
- Clone this repository
- Copy the
Assets
,Bundled
andShaders
folders to your project's directory - Make sure that the scene has a sun light since the shader uses that to project the caustics onto the meshes inside the volume.
- Load
Assets/Caustics_1.png
or a different caustics texture into your blend file and make sure its used and saved (with fake user or use it in a material node). Depending on the texture you might want to change some of the shader's parameters. - Make sure your project uses the deferred render path (
Render Properties > Armory Render Path > Renderer > Deferred Clustered
)
- In your project, add a cube and give it a new material.
You might want to display the mesh as wireframe in the viewport by setting
Object Properties > Viewport Display > Display As
toWire
. - In the material properties, enable
Armory Props > Read Depth
and setCustom Material
toCausticsVolume
. - In the
Bind Textures
panel below (only visible if aCustom Material
is set), select the caustics texture and setUniform Name
totex_caustics
In Shaders/CausticsVolume.frag.glsl
there are some parameters to change the look of the caustics:
const float CAUSTICS_SPEED = 0.04; // How fast the caustics move
const float CAUSTICS_SCALE = 0.2; // The size of the caustics
const float CAUSTICS_STRENGTH = 2.4; // The brightness of the caustics
const float EDGE_FADE_RADIUS = 0.3; // Size of the fraction of the mesh that is used to fade in the caustics
const float EDGE_FADE_OFFSET = 0.2; // Offset the fade for finer control
There's also a DEBUG
define in the shader, which when enabled will draw debug information instead of the final output. The drawn debug data is chosen by the DEBUG_DRAW_MODE
define.
To get the best visual debug output, remove the blending settings from the CausticsVolume.json
first.
There are a few things that may (or may not) be improved in the future:
- Chromatic aberration for the caustics
- Support for the forward render path
- Tweak the parameters from within the Blender UI. This will require changes to Armory first.
This work is licensed under the Zlib license which is a very permissive license also used by Armory and Kha at the time of writing this. You can find the license text here.