Jump to content

[SOLVED] new Material();


photo

Recommended Posts

Hi how do i create an new material where i'm able to set the albedo color true code?

I am able to clone a material (NOT base_mesh) and set its metalness.

V2.12.0.1
Material mat = Materials.FindMaterial("Cone_material").Clone("mesh_base_0");
mat.SetParameterFloat("metalness", 1.0f);

//	mesh.SetMaterialParameterFloat4("Albedo_color_multiplier",vec4.BLACK,0);
//	mesh.SetMaterialParameterFloat4("diffuse_color",vec4.BLACK,0);
//	mesh.SetMaterialParameterFloat4("albedo",vec4.RED,0);

 

Link to comment

Hello David,

you need to use "albedo_color".
If you need to know more parameter names, maybe look into the corresponding .basemat-files.
You can find the mesh_base material in: /"your_current_sdk"/data/core/materials/default/mesh/mesh_base.basemat.
In line 160 the "albedo_color" parameter is defined.

Best regards

Link to comment
  • silent changed the title to [SOLVED] new Material();

Sorry to follow up on a SOLVED issue.

When i clone the mesh_base i get a "System.NullReferenceException: Object reference not set to an instance of an object." 
When i set it to new Material(); i get "Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Is it not possible to create a new new material?
Or do all materials inherit from mesh_base?

Example of a transparent green mesh for how wants a full example.

    public Material placeable_mat;

            placeable_mat = Materials.FindMaterial("mesh_base").Inherit("mesh_base_0");// Clone("mesh_base_0");
            placeable_mat.Transparent = 2;
            placeable_mat.SetBlendFunc(5,4);
            placeable_mat.SetParameterFloat("roughness", 0.1f);
            int param_ID = placeable_mat.FindParameter("albedo_color");
            float transparent = 0.1f;
            vec4 albedo_color = vec4.GREEN -  - new vec4(0f,0f,0f,transparent);
            placeable_mat.SetParameterFloat4(param_ID, albedo_color);

 

Link to comment

Hi David,

When i clone the mesh_base i get a "System.NullReferenceException: Object reference not set to an instance of an object." 
Is it not possible to create a new new material?
Or do all materials inherit from mesh_base?

There is a mistake in the documentation (thanks for finding it). You can't clone a base material. When you try to do it the Clone() method returns "null" and prints an error message to the console: "Material::clone(): base material is not supported" (use "~" key to see console during runtime). You got NullRefereneceException in the next line when you tried to use null object:

placeable_mat.Transparent = 2;

If you don't want to create new parameters / shaders / states / etc. in your material and just want to change parameter's values then use "Inherit" method. Otherwise create a new copy of the "mesh_base.basemat" (in explorer) and modify it in any text editor.
 

Best regards,
Alexander

Link to comment
×
×
  • Create New...