Author Topic: Changing Substance parameters with Blueprints at runtime - a couple questions  (Read 172 times)

I've been prototyping a character customisation system for the last couple days. The basic idea was to feed a bunch of different masks into a Substance graph, which blends them together and outputs a base color, roughness/metallic and normal map. Those textures are then blended with the base skin in the character material.

The graph that generates the texture set looks like this:

The DecalLayer node looks more complicated than it is, it's more or less just a couple blends and switches:

Changing parameters directly in the graph instance in editor works like a charm, but i ran into my first issue when I tried to change parameters at runtime.
In editor, the base color renders as DXT5 with alpha channel.

However, when changing values at runtime via blueprint, the output renders as DXT1 without alpha channel.

If I then save the texture asset in the content browser, the alpha channel suddenly appears and the format changes to DXT5. Changing values in editor on the instance renders directly to DXT5 with alpha, without the need to save the asset first.

To work around this issue, I packed the transparency channel into the roughness/metallic map.

So my first question would be, is there a way to force the alpha channel to be rendered at runtime? Because ideally, I'd like to use the third channel in the roughness/metallic for something else, like emissive.

The next issue I had, was when I started linking the parameters to a UI. In my first test, I just used keyboard inputs to set texture input parameters on the graph instance, and had the graph instance render async. That worked pretty well, but now I have the texture switching bound to onClicked events on aUI, and I added some sliders that change float parameters on the instance via their onValueChanged events.

Suddenly the three output maps seem to render different masks, and if the texture parameter changes are set to render async, at some point my message log keeps getting flooded with this error message, at which point only restarting the editor helps.

LogTexture: Error: DDC key missing.

Rendering synced instead works, but becomes painfully slow, especially when using the CPU engine. On the GPU it's bearable.

This is with sync rendering:

This is with async rendering:

My assumption was that the parameter change events get called too often for the render buffer to keep up with, and indeed, using the onMouseCaptureEnd event instead on the sliders seems to have fixed that particular issue.

But then I ran into my main problem. To see if the whole idea would be even feasible, I made a simple test build when I started the project.

This one uses just a simple graph that colors each mask texture and blends them together, but it's working in the build.

However, if I build my current setup with the UI, the output maps seem to be missing, and when I change values, they briefly appear at a very low resolution while the value is being changed, then they disappear again.

The outputs in the factory are set to 2k, while the default outputs sizes in the substance graph are set to 64x64 on the DecalLayer node and 512x512 on the DecalCombiner node that generates the final output.
When the maps show up, they seem to be rendered at 64x64.

Aside from being a different graph, the general setup is the same as before, just a material that samples output textures from a graph instance, and a user input that changes parameters on the graph instance.
I'm not creating a MID from the graph factory, it's a normal material instance that just samples the graph outputs.

Creating new MIDs from the factory isn't an option for the project I'm currently working on, ideally I just want a menu where I can change parameters, the graph instance would update the textures, and then back in the game, the updated textures are sampled in the character material.

After the initial attempts looked at least somewhat promising, I'm now wondering if it is at all possible to use the Substance UE4 plugin that way.

I would be grateful for any input on these issues.

Edit: I forgot to mention, UE 4.24.3, Substance Plugin
Last Edit: July 09, 2020, 02:10:06 am