vmaurer
Topic Author
Posts: 17
Joined: 21 Jul 2022, 17:44

Passing vector and texture parameters to UE materials

17 Mar 2023, 16:52

Hey guys,

I'm working with UE5.1 and Noesis 3.2 and I want to implement a health bar using an UE material. In my material, I want to process three parameters:
- A health ratio value passed as a scalar parameter
- A texture atlas containing the health bar image as a texture2D parameter
- The uv coords for the texture within the atlas as a vector parameter

In my xaml resource dictionary, the texture is defined as a bitmap and the uv coords are defined as a color.
The health value is taken from a data context binding.

Here's the relevant snippet:
<noesis:Brush.Shader>
	<mat:M_TexturedProgressBar Ratio="{Binding HealthRatio}" RectForeground="{StaticResource R_HealthBar}" Texture="{StaticResource T_SpriteSheet_HUD}" />
</noesis:Brush.Shader>
And the resources used:
<BitmapImage x:Key="T_SpriteSheet_HUD" UriSource="T_SpriteSheet_HUD.png"/>
<Color x:Key="R_HealthBar" ScA="0" ScR="0.1123046875" ScG="0.9765625" ScB="0.1123046875" />
When importing all of this, I get the following warnings:
Cannot assign property to abstract class 'Color'
Cannot set value for 'Materials.UI.M_TexturedProgressBar.RectForeground', invalid value 'null' for property type 'Color'
Unknown property 'Materials.UI.M_TexturedProgressBar.Texture', or object to assign is incompatible
The warnings for the color parameter will go away, if I use the RGBA properties instead of ScA, ScR and so on, but I need floats of course.
Needless to say, the texture won't show up in the game and the vector parameter values are also incorrect. The health ratio value is the only thing that works.

I searched the forums and the web but couldn't find any related solution. The documentation doesn't seem to mention anything about parameters (correct me if I'm wrong) and I couldn't find anything in the samples either.

I'm aware there are other ways to implement a progress bar, but this is really not about progress bars. We are going to make plenty of use of materials so this is a general issue we would need to solve.

Thanks in advance.
 
User avatar
sfernandez
Site Admin
Posts: 3027
Joined: 22 Dec 2011, 19:20

Re: Passing vector and texture parameters to UE materials

20 Mar 2023, 21:59

Hi, if you need to define a vector (x,y,z,w) as a resource in xaml you can use the following:
<Point4D x:Key="R_HealthBar">0.0, 0.1123046875, 0.9765625, 0.1123046875</Point4D>
The problem with the Color is a known issue (#1752) that happens when defining a Color resource with properties, instead you can use the string conversion:
<Color x:Key="R_HealthBar">sc#0.0, 0.1123046875, 0.9765625, 0.1123046875</Color>
Could you please try any of these approaches?
 
User avatar
hcpizzi
Site Admin
Posts: 331
Joined: 09 Feb 2012, 12:40

Re: Passing vector and texture parameters to UE materials

21 Mar 2023, 11:29

As for material parameters in Unreal, currently we only expose scalar parameters as float properties, and vector parameters as color properties.

I can look into adding support for texture parameters, but on a first look it looks like the UMaterialInstanceDynamic interface for setting textures uses high level UTexture objects, which currently we don't keep.

For the time being you could have the texture set in a MaterialInstance in Unreal, and use that instead of the base Material.
 
vmaurer
Topic Author
Posts: 17
Joined: 21 Jul 2022, 17:44

Re: Passing vector and texture parameters to UE materials

21 Mar 2023, 13:50

Thanks a lot for the Replies.

@sfernandez:
I tried both approaches.
Defining the color as you suggested works, but the values passed to the material are incorrect, as they get converted to sRGB. To fix that, I would need to convert them back to linear in my material, which is not ideal. Is there a way to force the conversion off?

Using Point4D still produces a warning in UE and no values get passed to the material
Cannot set value for 'Materials.UI.M_TexturedProgressBar.RectForeground', invalid value '0,0.112305,0.976563,0.112305' for property type 'Color'

@hcpizzi: Yeah that's ok too, as we can set the texture atlas directly in UE and use vectors (once we know how) to "crop" the atlas
 
User avatar
hcpizzi
Site Admin
Posts: 331
Joined: 09 Feb 2012, 12:40

Re: Passing vector and texture parameters to UE materials

21 Mar 2023, 17:57

Hi,

I could expose two different properties for each vector parameter: The current one, and another one with the "_Linear" suffix that does the sRGB->linear conversion before passing the values to the Unreal material. So all you would need to do would be to set the RectForeground_Linear property instead of RectForeground.

Could this work for you?
 
vmaurer
Topic Author
Posts: 17
Joined: 21 Jul 2022, 17:44

Re: Passing vector and texture parameters to UE materials

22 Mar 2023, 10:53

Hi hcpizzi, while I totally agree that doing the conversion in code once would be better than in the material, it still sounds more like a workaround. LinearToSRGB and SRGBToLinear are a bit expensive, and there's also unnecessary loss of precision involved. There shouldn't be a conversion in the first place, if we intend to use the values as they are. I think there should be proper support for Point4D. I saw a definition of Point4D in the Noesis SDK code, but it seems there is no implementation in the core library. Apart from that, the function NoesisCreateTypeClassForUMaterial(UMaterialInterface* Material), where material parameters are actually set, doesn't handle the case if the type is a Point4D.
 
User avatar
hcpizzi
Site Admin
Posts: 331
Joined: 09 Feb 2012, 12:40

Re: Passing vector and texture parameters to UE materials

22 Mar 2023, 11:02

We could make that second property be of type Point4D instead of Color to avoid converting back and forth.

If you like the idea in principle I can send you a patch once I have it working.
 
vmaurer
Topic Author
Posts: 17
Joined: 21 Jul 2022, 17:44

Re: Passing vector and texture parameters to UE materials

22 Mar 2023, 11:10

Hey, sounds good to me. I'd be happy to give it a try! Thanks.
 
User avatar
hcpizzi
Site Admin
Posts: 331
Joined: 09 Feb 2012, 12:40

Re: Passing vector and texture parameters to UE materials

22 Mar 2023, 12:59

Here it is. Let us know if this works for you.
Attachments
LinearColorMaterialParams.zip
(750 Bytes) Downloaded 66 times
 
vmaurer
Topic Author
Posts: 17
Joined: 21 Jul 2022, 17:44

Re: Passing vector and texture parameters to UE materials

22 Mar 2023, 14:29

Hi hcpizzi, it works perfectly. Thanks for your help!

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 14 guests