Jump to content

Recommended Posts

Posted

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

Posted

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

Let's build cool stuff and have fun. :)

  • 2 weeks later...
Posted

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. :)

Posted
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?

 

Posted

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

Let's build cool stuff and have fun. :)

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.

×
×
  • Create New...