CSP UV2 Emissive Textures - John5i4/Shutoko-Revival-Project GitHub Wiki

What is it and why do it in the first place?

Explaining it in technical terms: Having an emissive map on UV2 means you can have two UV maps for the same object. This allows you to use UV1 to map your object in such a way that all your tiled textures tile and remain crisp and then use UV2 to map the object in in another way, allocating more texels to faces that will have baked lighting on them.

Why bake lighting?

There's three reasons:

  • Performance. CSP is pretty cool and all but you cannot use CSP light sources for everything. You will quickly hit the limit of lights that CSP can render at one time or at the very least you will waste performance rendering lights that the player will never interact with. Baked lights are just an emissive texture so they are much easier to render.
  • Visibility. CSP has a distance limit for rendering CSP light sources. So, if you have a buildings or something that you want to light up and be visible from a long distance away, you need to use an emissive texture instead, which is visible the moment the model itself spawns. Basically infinite range.
  • Quality. Baked lights are calculated in the 3D/Rendering software of your choice. That means that you can do advanced lighting calculations that would be too expensive (for example shadows) or even impossible (caustics) for CSP and bake them on the texture. Granted, such fine details need a good amount of texels allocated to them but we'll get to that later.

If all of that made sense, read below for the tutorial.

Otherwise, expand this section for more info.

Baked lighting?

This is just a fancy way to refer to an emissive map. The only difference is that instead of simple areas of light or no light, the map is calculated in 3D space by the renderer. All those calculations are then painted on the texture. It will make sense in the visual example later on.

I will be using two terms to differentiate between the types of lighting:

  • CSP light sources - These are the lights that CSP spawns based on the track config, so any [LIGHT...] and [LIGHT_SERIES...] entries.
  • Baked lighting - This is the lights that are baked on the emissive texture.

Visual example

Lets say we have this simple wall.

Simple wall

The wall uses a single material, a single UV map and a simple tiled texture that you can see on the left side of the screenshot. It also has some things sticking out of it so we can better see how light interacts with it.

Here is another angle.

Angle 2

I have now switched to the rendered view, using Cycles in Blender and I added a point light in the place indicated by the 3D cursor. (This is a Blender light, it has nothing to do with CSP light sources)

The Cycles rendering engine did all the work and now we have some very realistic colors and lighting.

It was always possible to get this nice lighting painted on a texture and then used in Assetto Corsa, so lets skip over that process and instead explain what is new and improved when using UV2.

What is different now?

Traditionally, baking textures means that you need to unwrap your mesh in such a way that there is absolutely no overlap or stretching. This means that you can't use tiled textures. You need to bake everything into a new texture with a new UV map. Subsequently, the clarity of the texture depends on it's resolution. When you have a complex, large objects that you want to bake, the texture size increases dramatically. We're talking 4K textures just to get a reasonable amount of clarity on the texture. And this is for all textures that your material is made of: diffuse, normal, specular...

The difference with UV2 is simple: Since you only bake lighting (emissive), then why bother with the diffuse, the normal, the specular or whatever other map you're using? With UV2 you can ignore all those, use the simple tiled texture like you always did and still have the baked lighting just on the emissive. So, that's a massive saving on texture size and an increase in quality.

How do I do it?

Quick tutorial

The process is actually quite simple to set up.

Here are the steps. You can see them in more detail below.

  • Add a new UV map to your object.
  • Unwrap your object again in a way that there's no overlap or stretching.
  • Bake your lightning to this new UV map.
  • Export the object. Settings screenshot below. Very important.
  • Run the object through KSeditor as usual.
  • Use any MultiMapEmissive shader.
  • Assign all your textures as usual.
  • Export from ksEditor.
  • Now go to Content Manager > Content > Tools. There's a UV2 tool. Run it, click "Pack UV2" and it will ask you for an FBX file. Open the FBX you exported earlier. The tool will process it and will make you save a new KN5.
  • Overwrite the previous KN5. A .UV2 file will be saved at the same location by the tool, automatically. Now your KN5 "knows" that it has a UV2. You can use that KN5 on your track as usual.
Expand this for more info on those steps.

In more detail.

  • Add a new UV map to your object. I usually call it "UV2" but I think any name is valid.

  • Unwrap your object again in a way that there's no overlap or stretching. In blender, even "smart UV project will do. Ideally, allocate more texture space to faces that will receive the majority of the baked details. In our example, the front part of the wall and the small parts that stick out should get more texture space. The top and back of the wall is not hit by the light so it doesn't need much texture space.
  • Bake your lightning to this new UV map.

OPTIONAL: You can preview how the object will look in Assetto with the following shader node setup. It might wash your colors out but its the emissive that matters. In game it'll be fine.

  • Export the object with the following settings:

These are my standard recommended Blender to AC export settings with the only difference being the "Apply Transform" and "Triangulate Mesh" options are selected. You can also triangulate the mesh with a modifier or manually (or with whatever other method you wish).

  • Run the object through KSeditor as usual.
  • Use any MultiMapEmissive shader.
  • Assign all your textures as usual. The model is still using UV1 so don't be alarmed if it looks weird when you turn on the emissive.

in Editor

  • Export from ksEditor.
  • Now go to Content Manager > Content > Tools. There's a UV2 tool. Run it, click "Pack UV2" and it will ask you for an FBX file. Open the FBX you exported earlier. The tool will process it and will make you save a new KN5.
  • Overwrite the previous KN5. A .UV2 file will be saved at the same location by the tool, automatically. Now your KN5 "knows" that it has a UV2. You can use that KN5 on your track as usual.

This concludes the export process of a KN5 with UV2 in it. Next up, let's see how you can tell CSP to use that 2nd UV map.

Go in game and check your object. It should look like this: Still using UV1. Mine is lit up because I gave emissive values to the shader but you can control it via config instead.

Track Config

Now you gotta tell CSP to use UV2 with the object.

[SHADER_REPLACEMENT_...]
MATERIALS = XXXXXXXXX ;Your material's name goes here
MATERIAL_FLAG_1 = 1 ;This will tell CSP to use UV2

This is still a normal [SHADER_REPLACEMENT_...] by the way. You can do with it whatever you'd normally do. Control emissives with conditions, force different shaders, load external textures, etc.

Save the config and your object should look like this:

Its now using UV1 for everything except emissive, where UV2 is used.

Drawbacks

Right now I dont see a way to use this to light up objects that already have emissive maps. So, for example, a building with windows that use an emissive map to light up at night. You cannot use this method to make a spotlight light it up or something like that.

⚠️ **GitHub.com Fallback** ⚠️