Jump to content

[SOLVED] How to set diffuse color to material in C++ codes


photo

Recommended Posts

Posted (edited)

Is there a way to set diffuse color in RGB color format to a material in C++ object ? 

Something like below codes: 

Material* a;

a->setParameter("diffuse",vec3(1.0f,0.5f,0.5f));

 

BTW , where I can check the full like of parameter in string type of material object ? 

Thanks for any advice.

 

Edited by leon.dong
Posted

Hi Leon,

 

I propose to use Material::findParameter() to search for parameters in first place, which returns the parameter number in your material. For diffuse you need to look for "diffuse_color" (at least for any mesh_base.mat), which is an float4 variable. So Material::setParameterFloat4() is the best way to go, either with the parameter name or the parameter number.

Unfortunately there isn't any convenient documentation about this, but you can look in the .basemat file, while open them with a text editor. Usually you can find them at "<SDK_INSTALL_FOLDER>/data/core/materials/base/objects/mesh/mesh_base.basemat) for meshes. The other ones are in the dedicated material folder.

Hope that helps!

  • Thanks 1
Posted (edited)
1 hour ago, christian.wolf2 said:

Hi Leon,

 

I propose to use Material::findParameter() to search for parameters in first place, which returns the parameter number in your material. For diffuse you need to look for "diffuse_color" (at least for any mesh_base.mat), which is an float4 variable. So Material::setParameterFloat4() is the best way to go, either with the parameter name or the parameter number.

Unfortunately there isn't any convenient documentation about this, but you can look in the .basemat file, while open them with a text editor. Usually you can find them at "<SDK_INSTALL_FOLDER>/data/core/materials/base/objects/mesh/mesh_base.basemat) for meshes. The other ones are in the dedicated material folder.

Hope that helps!

Really helpful . Thanks.

 

Confirm one thing . The color in vec4 is RGBA or ARGB /? 

Edited by leon.dong
Posted
12 minutes ago, silent said:

You can also check the texture or parameter name in it's tooltip inside Editor:
image.png

Another way , Thanks.

Posted (edited)

@christian.wolf2 Your solution is clear. I found many useful parameters

Next question is  , In the below screen-shot , what's the difference between two diffuse color settings ? 

@silent  ThankThansk

image-2023-12-19_22-2-46.thumb.png.ae4cd6ab94979de0bcc2d87de26a3bae.png

Edited by leon.dong
Posted

Regarding your vector question, it is always RGBA. Please be aware that color parameters are always from 0 to 1, so maybe you need to divide the RGB color by 255.

The detail tab is used for detail textures. You can have a look here.

 

Best

Christian

Posted
13 hours ago, christian.wolf2 said:

Regarding your vector question, it is always RGBA. Please be aware that color parameters are always from 0 to 1, so maybe you need to divide the RGB color by 255.

The detail tab is used for detail textures. You can have a look here.

 

Best

Christian

Thanks. 

I tried below codes with no effect

		MaterialPtr myTempMat = baseMat->inherit(myTempMatName.c_str());
		int paraID=myTempMat->findParameter("diffuse_color");
		myTempMat->setParameter(paraID, Math::vec4(diffuse.x, diffuse.y, diffuse.z, 1.0));

Instead, if I call this , it has effect .

The problem is this code is for albedo . Since I only have diffuse and specular color info not albedo , How can I use it correcly? 

myTempMat->setParameter(Unigine::Material::PARAMETER_COLOR, Math::vec4(diffuse.x, diffuse.y, diffuse.z, 255));

 

Posted

May I ask what engine version you are using? Because Material::setParameter() isn't defined for my version (2.18) and I can't even find the member function, started from 2.13+.

Also, what workflow is your baseMat using? You first need to change the state to specular workflow if already doing. You can also do this easily via code (Material::setState("workflow",1)).

 

Posted

love you , Christian . 

Your answer is what I need. Material::setState("workflow",1) is very useful. 

My engine version is very old . 2.7.1 . 

so might be some API is different.

 

  • silent changed the title to [SOLVED] How to set diffuse color to material in C++ codes
×
×
  • Create New...