Help with detail ambient texture material plugin

Hi all, im trying to create something similar to detail maps

but basically a detail ambient texture that tiles separately from the ambient texture. with limited documentation on material plugins my thought was to just copy the detail map code and base my detail ambient texture plugin off of that.

however i don’t actually see where the detail map stuff is being calculated in the fragment shader in the above code?

for my use case the fragment shader would just multiply the ambient texture with the detail ambient texture eg:

ambientTexture = ambientTexture * detailAmbientTexture;

i looked at the texture samplers code in docs but its still not clear how to approach this. any help or links to resources would be appreciated.

cc @Evgeni_Popov

The shader code for detail maps is embedded directly into the standard and PBR shader code, so we don’t need to implement the getCustomCode function.

In your case, you will have to implement this function and do something like:

getCustomCode(shaderType) {
    return shaderType === "vertex" ? null : {
        "!reflectivityOutParams reflectivityOut;": `
            aoOut.ambientOcclusionColor.rgb *= vec3(0.5);
            reflectivityOutParams reflectivityOut;
        `,
    };
}

You will need to replace vec3(0.5) by your own code, of course.

We don’t have a predefined replacement point (like CUSTOM_FRAGMENT_BEGIN, CUSTOM_FRAGMENT_DEFINITIONS, CUSTOM_FRAGMENT_UPDATE_ALPHA, etc) for the ambient value, so I had to find a place in the sources where the code could be injected. It turns out that the ambient value is calculated before the reflectivityOutParams reflectivityOut; declaration, hence the regexp I used.

2 Likes