leon.dong Posted December 19, 2023 Share Posted December 19, 2023 (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 December 19, 2023 by leon.dong Link to comment
christian.wolf2 Posted December 19, 2023 Share Posted December 19, 2023 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! 1 Link to comment
silent Posted December 19, 2023 Share Posted December 19, 2023 You can also check the texture or parameter name in it's tooltip inside Editor: 1 1 How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
leon.dong Posted December 19, 2023 Author Share Posted December 19, 2023 (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 December 19, 2023 by leon.dong Link to comment
leon.dong Posted December 19, 2023 Author Share Posted December 19, 2023 12 minutes ago, silent said: You can also check the texture or parameter name in it's tooltip inside Editor: Another way , Thanks. Link to comment
leon.dong Posted December 19, 2023 Author Share Posted December 19, 2023 (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 Edited December 19, 2023 by leon.dong Link to comment
christian.wolf2 Posted December 19, 2023 Share Posted December 19, 2023 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 Link to comment
leon.dong Posted December 20, 2023 Author Share Posted December 20, 2023 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)); Link to comment
christian.wolf2 Posted December 20, 2023 Share Posted December 20, 2023 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)). Link to comment
leon.dong Posted December 21, 2023 Author Share Posted December 21, 2023 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. Link to comment
Recommended Posts