SpiderPig Posted February 25, 2023 Share Posted February 25, 2023 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: Quote Link to comment Share on other sites More sharing options...
Josh Posted February 27, 2023 Share Posted February 27, 2023 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... 1 Quote 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 More sharing options...
SpiderPig Posted February 27, 2023 Author Share Posted February 27, 2023 Yeah that'd be great. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted March 10, 2023 Author Share Posted March 10, 2023 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. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted January 9 Author Share Posted January 9 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? Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted January 9 Author Share Posted January 9 I may not be correct but it might be this I need - material->render_material->id; Quote Link to comment Share on other sites More sharing options...
Josh Posted January 9 Share Posted January 9 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. 1 Quote 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 More sharing options...
SpiderPig Posted January 11 Author Share Posted January 11 On 1/10/2024 at 3:06 AM, Josh said: This method must ONLY be called from a render hook. See World::AddHook. I can't find this in the documentation. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 11 Share Posted January 11 And you won't. This is a special thing I added for @klepto2 The Hook ID can be HOOK_TRANSFER or HOOK_RENDER. 1 Quote 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 More sharing options...
SpiderPig Posted January 12 Author Share Posted January 12 Works perfectly thankyou! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.