Jump to content

Multiple Materials


SpiderPig
 Share

Recommended Posts

Through brief trial and error I got this example to work.  I want to be able to get the materials index so I can retrieve multiple materials in the shader for my voxel terrain.  I can find a way to send the materials indexes I need to the shader, that shouldn't be a problem.  (I'll probably use a small texture to hold the index)  It's just actually getting the material index.  Something like this perhaps?

material->GetIndex()

My C++ Code:

auto material1 = CreateMaterial();
material1->SetColor(0, 1, 0);
auto material2 = CreateMaterial();
material2->SetColor(1, 0, 0);

...
  
terrain->SetMaterial("VoxelObject.mat");

My Shader Code:

Material m1 = materials[3];
Material m2 = materials[4];

float slope = getSlope(normal);
color = mix(m1.diffuseColor, m2.diffuseColor, slope);

The Result:

MultipleMaterials.thumb.png.a44b9e6e435d0829a9be277b25fc0665.png

Link to comment
Share on other sites

I have thought of the idea of using the terrain material painting system to apply multiple materials to a mesh. As long as they all use the same shader family it will work. Stay tuned on this...

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 2 weeks later...

I wonder if it's too much to ask for a temporary solution for this?  Just the ability to get the index the material is stored in the shader is enough, I can do the rest and send it to my shader.  I'd like to get a nice material up and running for the voxel terrain.  I'm just guessing at what the material index is in the shader.  It changes though as the game grows though. :)

Link to comment
Share on other sites

On 2/25/2023 at 6:26 PM, SpiderPig said:

Through brief trial and error I got this example to work.  I want to be able to get the materials index so I can retrieve multiple materials in the shader for my voxel terrain.  I can find a way to send the materials indexes I need to the shader, that shouldn't be a problem.  (I'll probably use a small texture to hold the index)  It's just actually getting the material index.  Something like this perhaps?

material->GetIndex()

My C++ Code:

Is this possible yet?

 

Link to comment
Share on other sites

Okay, I am adding a new method Material::GetHandle, which will return the index of the material in the material array.

This method must ONLY be called from a render hook. See World::AddHook.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...