Shader and Lighting Pipeline - KillzXGaming/MK8-MK8D-Research.- GitHub Wiki

Game pipeline

Lighting System

Diffuse Env Maps

The game uses diffuse environment maps which is created at runtime. These consists of multiple light sources like ambient, directional and hemisphere lighting. They make up the primary source of lighting for a course and can determine the overall color and brightness of the scene.

These maps are generated with aamp parameters found in .bgenv using the bagllmap and course_area.baglenv files.

The giant spherical light that is on top is the directional light. This light source is adjusted to produce the amount of light you see in a map. Night time maps will use lower values (0.5 - 1.1) and day time maps will use higher values (2.0+).

Hemisphere lighting is the base color under directional lighting. This one is usually the ground and sky color of the map you are doing.

The hemi lighting can also influence things like shadow color.

  • Diffuse env maps maps are generated at load using aamp file parameters in .bgenv.
  • Cubemaps are generated at load using aamp files (.baglcube)
  • Color correction is generated with a 3D LUT texture using aamp files (.baglccr)

During per frame drawing

  • Shadow projection for dynamic shadows are drawn for objects using dynamic casting.
  • Shadow projection for course is drawn to use for casting onto objects.
  • Models are drawn into a gbuffer render pass which stores normals and depth information.
  • Using the gbuffer rendered texture, the normalized depth is calculated into a texture.
  • Caustics are drawn using gbuffer linear depth and caustic textures.
  • All shadow maps are combined and unprojected onto one screen texture per texture channel.
  • Tire marks are created during kart movement using a tire marking texture and normalized linear depth. The tire mark outputs onto the same texture as the shadows using the alpha channel.
  • Using the gbuffer and normalized depth, light pre pass is calculated using spot, point and kart lightings. The light pre pass stores multiple array levels for different brightness.
  • Probe Light cubemaps are generated for any moving objects using the original diffuse env map they have and are stored per object.
  • The material pass is drawn rendering the bfres models. The shader uses the light pre pass, shader texture, diffuse env maps/probe env maps, reflection cube maps, and outputs it.
  • Particle effects are drawn onto screen.
  • Bloom is prepared extracting brightness from the screen output with various parameters.
  • The bright bloom texture is then blurred in multiple passes and stored in multiple mip maps.
  • Final post effect with srgb/hdr, bloom, and color correction combined.

How they are assigned

The game will load common/genv/Turbo_cmn.bgenv aamp parameters by default if a track does not have them. Then it uses the bagllmap to load a list of light maps. Each light map has a light source which can be found in course_area.baglenv which gets assigned by name and type.

MK8 divides these into 3 types. diffuse##, diffuse_course##, and diffuse_effect##.

  • diffuse_course used by the course model.
  • diffuse_effect for particle effects.
  • diffuse used for everything else. These are assigned through collect area checks.

The game uses the gsys_light_diffuse render info parameter to determine which one to assign to what material. If the object moves around, it uses gsys_areaenv_lightmap from collect.genvres.

Probe Lighting

Spot/Point Lighting

Baked Lighting

Shadows

Baked Shadows

Areas (for moving objects)

The game uses a file in .bgenv called collect.genvres which is a model of various boxes. These store material data for area information which gets set when an object's position is inside a box. This can be things like cubemaps, diffuse env maps, bloom settings, etc.

The mesh box's material user data setting determine what area settings to use.

  • gsys_areaenv_lightmap (what light map to use in bagllmap)
  • gsys_areaenv_envmap (what cubemap to use in baglcube)
  • gsys_areaenv_bloom (what bloom setting to use in baglenv)
  • gsys_areaenv_envobjset (what fog setting to use in baglenv)

Areas for course model

Course models use the material to determine the area settings.

In render info:

  • gsys_light_diffuse (determines the lightmap in bagllmap to use)

In material parameters:

If shader option parameter **enable_area_env_direct **= 1.

  • gsys_area_env_index_diffuse (determines what area index to use) Else it uses this parameter.
  • gsys_area_env_data0

Reflection Cubemaps

These are made at runtime when the game loads.

Models render into the cubemap based on the render info settings.

  • gsys_cube_map (if set to 1 it displays in cubemap)
  • gsys_cube_map_only (if set to 1 it does not appear in game and only in cubemap)

Render Info

  • gsys_pass (if set to seal or xlu_water, draws over object)
  • gsys_cube_map (draw into cubemap or not)
  • gsys_cube_map_only (only display in cubemaps)
  • gsys_dynamic_reflection (draw into dynamic reflections using screen space reflections)
  • gsys_priority_hint (priority possibly for drawing order)
  • gsys_priority (priority order index)
  • gsys_light_diffuse (light map to display on material)

Unused bake parameters probably set automatically by dev tools.

  • gsys_bake_group (the group the bake map was baked onto.
  • gsys_bake_texel_param (the texel param for baking.
  • gsys_bake_uv_unite (the uv set to bake onto.
  • gsys_bake_normal_map (to bake normal map lighting onto light map)
  • gsys_bake_emission_map (to bake emission map lighting onto light map)

Shader Options

Shader Parameters