Quick Links
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)
Usage:
- Clone the repo or download as zip
- Copy all files into the cod4 root directory
- Open the shader_ocean.gdt in Asset Manager, compile the material and the xmodel
- Compile shaders: worldfx_ocean and worldfx_ocean_unlit by either using ShaderGen, included within cod4-compileToolsXaml or shader_tool directly
- Place the ocean_plane xmodel into your map or apply the material to any other kind of xmodel/terrain patch
- 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:
- 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
- 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.
- 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.
- Disabling USE_CUSTOM_CONSTANTS will enable vanilla cod4 usage. You have to do this before you ship your mod/map.
- 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
- 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:
- Template: the material template to be used for this material (deffiles/materials/)
- 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
- 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)
- normalMap: water normal map
- specularMap: foam texture (both high wave and shore foam)
- cosineMap: no longer in use, but could be used within the shader by sampling the alpha channel of the specularMap