[SOLVED] Need help with material properties


Recommended Posts


I'm trying to change material parameters of "object water global". Problem is that some parameters are not saved or not applied at all. Here's what I do:

1) Create new material and apply it to water object

MaterialPtr core = materials->findMaterial("water_global_base");
MaterialPtr newMat = core->inherit();



2) Change material parameters

MaterialPtr mat = materials->findMaterial("my_water_material_0");
MaterialPtr core = materials->findMaterial("water_global_beaufort_4");

float fog = mat->getParameter("underwater_fog_transparency");

for (int i = 0; i < core->getNumParameters(); i++)
    mat->setParameter(i, core->getParameter(i));

mat->setParameter("underwater_fog_transparency", fog);

3) Restart the app OR reload materials (via 'materials_reload' console command)

I expect: All material's parameters are correctly applied and saved.

What i got: Some properties are saved and some are not, this makes water look ugly.

After a small research i found that some properties (such as 'wave0_uv_transform') are always saved with default value in material's XML file, ignoring what i passed in setParameter(). Properties are applied correctly before you reload the material.


Link to post

Hello Oleg,

Parameters have their types which can be obtained by getParameterType. And they should be set with methods according to these types. wave0_uv_transform has type PARAMETER_EXPRESSION. That's the snippet for setting it:

const auto parameter_id = mat->findParameter("wave0_uv_transform");
assert(mat->getParameterType(parameter_id) == Material::PARAMETER_EXPRESSION);
const auto value = Math::vec4(1.0, 2.0, 3.0, 4.0);
mat->setParameterExpression(parameter_id, String::format("vec4(%f,%f,%f,%f)", value.x, value.y, value.z, value.w));

We're currently working on improvement of that API.

Link to post

Hello Andrey.

Using setParameterExpression() solved my problem. Thanks.

Link to post
  • morbid changed the title to [SOLVED] Need help with material properties