Call of Duty 4 :: Ocean Shader
realtime / dynamic ocean shader

GitHub Repository :: CoD4 Shader Tutorial :: IW3xo :: Discord Server

Overview

  • Shader based on: https://github.com/tuxalin/water-shader
  • Fully tweakable via in-game GUI or fastfile hotloading (requires IW3xo)
  • Vanilla CoD4 Support
  • Dynamic heightmap generation
  • Displacement
  • Cubemap usage for reflection and radiance
  • Waterdepth dependend refraction and color extiction
  • High wave and shore foam
  • Shore blending

General

  • Supports both xmodels and world geometry while the latter has some visual bugs
  • Supports fullbright and radiants fake-light mode by using a simpler second shader
  • Will only look decent on the first and second day after a dedicated server was started (cod4 gametime bug making it choppy and hella buggy)

Play

Usage:

  1. Clone the repo or download as zip
  2. Copy all files into the cod4 root directory
  3. Open the shader_ocean.gdt in Asset Manager, compile the material and the xmodel
  4. Compile shaders: worldfx_ocean and worldfx_ocean_unlit by either using ShaderGen, included within cod4-compileToolsXaml or shader_tool directly
  5. Place the ocean_plane xmodel into your map or apply the material to any other kind of xmodel/terrain patch
  6. Tweak in-game using IW3xo (The shader ships with in-game tweaking enabled, requiring IW3xo to be used, see below to disable this if needed)

Tweaking in-game using the GUI:

  1. Use IW3xo and the built in /devgui command -> ocean tab to tweak the shader however you like. Use the export button to export your settings.
    • settings will be exported to root/iw3xo/shader_settings/ocean_settings.txt
  2. Overwrite the static shader constants inside the #else block (if USE_CUSTOM_CONSTANTS is not defined) in both the vertex and pixelshader.
    • Note that both are sharing 3 of the exported constants.
  3. The shader ships with in-game tweaking enabled, requiring IW3xo to be used.
    • This can be disabled by commenting “//” #define USE_CUSTOM_CONSTANTS in both the vertex and pixelshader.
  4. Disabling USE_CUSTOM_CONSTANTS will enable vanilla cod4 usage. You have to do this before you ship your mod/map.
  5. General shader features such as reflection probe usage or debug ouput can be enabled by defining certain pre-defined preprocessors.
    • eg. #define USE_REFLECTION_PROBES; #define DEBUG_NORMALS etc

Tweaking in-game using an addon fastfile:

  • IW3xo supports loading/reloading of fastfiles and its assets in-game
  • Expecting that you already have the shader up and running in your map/mod, do the following:

​Include the following in your fastfile zone

material,dynamic_ocean
techset,mc_worldfx_ocean
techset,wc_worldfx_ocean
techset,worldfx_ocean
  • Modify the shader however you like and recompile it. Make sure you get no errors when doing so.
  • Build the fastfile. Again, watch for errors.
  • Load up your map/mod thats including the ocean shader
  • Use the following command to load your zone file: /loadzone your_zone_name
  • The ocean shader should now reflect your changes
  • Rinse and repeat

Asset Manager Material Settings:

  1. Template: the material template to be used for this material (deffiles/materials/)
  2. String: the techset that will be used for the material. If you created copies of the shader files, you’ll need to edit this to reflect your changes
  3. colorMap: cubeMap for reflections and sky radiance
    • use IW3xo to generate cubeMaps using the now fixed command /cubeMapShot 1024 filename (dvar r_smp_backend needs to be disabled)
  4. normalMap: water normal map
  5. specularMap: foam texture (both high wave and shore foam)
  6. cosineMap: no longer in use, but could be used within the shader by sampling the alpha channel of the specularMap