I am trying to get the roughness value from a material. I know that UMaterial has a Roughness property but its only available within the editor. Plus it doesn’t seem to actually be the value of applied to the material. Is there a way to do this?
UMaterial* mat = static_cast(iMat);
mat->Roughness.Constant ← not sure what this really represents.
Here is what I can contribute based on my still-developing understanding of how these systems work:
I don’t think you can get what you want through the approach you are taking: the “roughness” of a material can be a constant (which is implied by your question) but the system is designed such that it doesn’t have to be. For example, the Material Editor permits you to generate expressions (which I think is essentially a “pixel shader”) that is applied in a constant or varying degrees over the “uv” space of the material.
The pixel shader is a compiled piece of code that interacts with other 3D-graphics systems in UE4 (other shaders) that are written in a shader scripting language.
As I understand how the Material Editor works, what you are really asking in your question is “how do I capture the result of the pixel shader for roughness”. Because this answer is mapped on to the uv space for the material, in practice, this answer is only meaningful on a pixel by pixel basis (one pixel in a material can have one roughness setting and, depending on the design of the shader, adjacent pixels may have different roughness settings).
I think the answer is found in the debugging section of that page: The primary method of debugging shaders is to modify a shader to output an intermediate, then visualize that with the appropriate VisualizeTexture command.
Unfortunately, I think that means that even if you wanted to find the roughness of a particular pixel in a material, you would have to edit the applicable shader to capture that output for you.
It might be possible by inserting a custom expression into your Material Editor script for roughness for that material (see Custom Expressions | Unreal Engine Documentation) but I haven’t considered how you might do that.