debashis.bhandari Posted July 25, 2019 Share Posted July 25, 2019 Hi there, I am working on Mesh object. I am creating mesh at runtime and trying to set opacity to it. I have tried setMaterialParameter("albedo_color", ...); but it does not work. Kindly guide. Thank you. Link to comment
silent Posted July 25, 2019 Share Posted July 25, 2019 Hi Debashis, Please correct me if I wrong, you want to get semi-transparent object? If so, I would recommend to use setTransparent() method for that. Otherwise, could you please give us more details about your use-case (some screenshots or video of what you are trying to achieve)? Thanks! 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
debashis.bhandari Posted July 26, 2019 Author Share Posted July 26, 2019 13 hours ago, silent said: Hi Debashis, Please correct me if I wrong, you want to get semi-transparent object? If so, I would recommend to use setTransparent() method for that. Otherwise, could you please give us more details about your use-case (some screenshots or video of what you are trying to achieve)? Thanks! Hello Silent, Yes! I want to create a semi transparent box. I have written following function that I am calling from AppWorldLogic::init() int AppWorldLogic::AddMeshToScene3() { // creating a box (ObjectMeshDynamic node) MeshPtr mesh = Mesh::create(); mesh->addBoxSurface("box_surface", Math::vec3(1.5f, 1.5f, 1.5f)); ObjectMeshDynamicPtr my_mesh = ObjectMeshDynamic::create(mesh); my_mesh->release(); editor_->addNode(my_mesh->getNode(), 1); mesh->clear(); // getting the interface to material libraries Materials *materials = Materials::get(); // creating a new material library materials->create("my_material_lib"); // creating a new child material of the mesh_base and putting it to the created library materials->inheritMaterial("mesh_base", "my_material_lib", "my_mesh_base0"); // getting a pointer to the new material named "my_mesh_base0" MaterialPtr my_mesh_base = materials->findMaterial("my_mesh_base0"); // setting the albedo color of the material to red my_mesh_base->setParameter(Material::PARAMETER_COLOR, Math::vec4(255, 0, 0, 255)); my_mesh_base->setTransparent(Material::TRANSPARENT_BLEND); // assigning a "my_mesh_base0" material to the surface 0 of the my_mesh ObjectMeshDynamic node my_mesh->setMaterial("my_mesh_base0", 0); // assigning a "my_mesh_base0" material to all surfaces of the my_mesh ObjectMeshDynamic node my_mesh->setMaterial("my_mesh_base0", "*"); return 1; } I have atached screenshot of how it shows. Also I tried these values too: TRANSPARENT_NONE, TRANSPARENT_ALPHA_TEST, TRANSPARENT_WATER, for my_mesh_base->setTransparent(...) But it does not show properly Kindly guide! Thank you Link to comment
silent Posted July 26, 2019 Share Posted July 26, 2019 Basically, for AlphaBlend you need to set blending function via setBlendFunc() method. You can check sample in SDK Browser -> Samples -> UnigineScript -> Materials -> transparent_00 for more information. 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
debashis.bhandari Posted July 26, 2019 Author Share Posted July 26, 2019 (edited) It worked as expected after I did following: int AppWorldLogic::AddMeshToScene3() { // creating a box (ObjectMeshDynamic node) MeshPtr mesh = Mesh::create(); mesh->addBoxSurface("box_surface", Math::vec3(1.5f, 1.5f, 1.5f)); ObjectMeshDynamicPtr my_mesh = ObjectMeshDynamic::create(mesh); my_mesh->release(); editor_->addNode(my_mesh->getNode(), 1); mesh->clear(); // getting the interface to material libraries Materials *materials = Materials::get(); // creating a new material library materials->create("my_material_lib"); // creating a new child material of the mesh_base and putting it to the created library materials->inheritMaterial("mesh_base", "my_material_lib", "my_mesh_base0"); // getting a pointer to the new material named "my_mesh_base0" MaterialPtr my_mesh_base = materials->findMaterial("my_mesh_base0"); my_mesh_base->setTransparent(2); my_mesh_base->setBlendFunc(Gui::BLEND_SRC_ALPHA, Gui::BLEND_ONE_MINUS_SRC_ALPHA); my_mesh_base->setParameter(Material::PARAMETER_COLOR, Math::vec4(1.0f, 0.0f, 0.0f , 0.5f)); // assigning a "my_mesh_base0" material to the surface 0 of the my_mesh ObjectMeshDynamic node my_mesh->setMaterial("my_mesh_base0", 0); return 1; } Thank you so much for guidance. Edited July 26, 2019 by debashis.bhandari Added screenshot Link to comment
silent Posted July 26, 2019 Share Posted July 26, 2019 These defines are located in UnigineRenderState.h file: https://developer.unigine.com/en/docs/2.5/api/library/rendering/class.renderstate#BLEND_ONE_MINUS_SRC_ALPHA 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
debashis.bhandari Posted July 26, 2019 Author Share Posted July 26, 2019 Thank you! :) Link to comment
Recommended Posts