I am trying to create materials with CreateMaterial.
Here is my code: https://pastebin.com/cC38kPQ2
For some reason, it just returns a material that is completely white.
https://files.facepunch.com/forum/upload/353627/2f749233-636a-454d-ab52-7a1dd0e78c2c/image.png
Can anyone tell me what I'm doing wrong?
I can create the materials with the passed path completely fine with Material(). Just not CreateMaterial for some reason.
local function createKitMaterial(path, name)
local mat = Material(path)
return CreateMaterial(name, "UnlitGeneric", {
["$basetexture"] = mat:GetTexture("$basetexture"),
})
end
This should work. If you try to make a material from a .png you need to call it with Material first.
The Material is already called first, that's the only reason that :GetTexture() is able to be attached to it in the first place.
But just in case, I tried it your way, didn't work.
It probably is a problem with transparency or whatever, basically you might need to set additional .vmt parameters based on what image your are loading.
It doesn't seem to be. I had another image that worked normal for Sneaky, but not for me. It was also a white square. But I did have another PNG which did work.
It seems random.
Nothing I can do or tell without the image files (one that works, one that doesn't) and the code, including both loading and drawing the image on screen.
Here are the images. I put them in a zip file because I'm not sure if image hosts change the file when it's uploaded.
https://anonfile.com/q6i1ddr0b2/images_zip
Layer1 works, assaultkit doesn't.
This is the code.
[Lua] local proxy = { local _mat = Material("assaultkit.png") ..
That code would just error, can you post what you actually used?
Oh lol, I messed it up. The code I had was actually correct, I just had to retype it in pastebin to show what I had.
https://pastebin.com/Jxb5GFEc
There you go :-)
Please read my post in its entirety. Also your file doesn't work.
https://files.facepunch.com/forum/upload/1804/328da3ed-ed39-4610-a2d6-c5fbe10556db/image.png
shouldn't it be something like this:
local function createKitMaterial(path, name)
local mat = Material(path)
return CreateMaterial(name, "UnlitGeneric", {
["$basetexture"] = "!" .. mat:GetName(),
})
end
since the wiki says "To retrieve a Lua material created with CreateMaterial, just prepend a "!" to the material name."
Material
That's not how it works....
fair, i just saw that in the wiki but wasnt sure if you actually needed it
First of all, what is wrong with using Material() function itself? Why do you need to use CreateMaterial()?
Secondly, as I have said, you will need extra parameters just to get transparency and equal functionality to Material()
local function createKitMaterial(path, name)
local params = {
["$basetexture"] = Material( path ):GetTexture( "$basetexture" ):GetName(),
["$vertexalpha"] = 1,
["$vertexcolor"] = 1,
}
local mat = CreateMaterial( name, "UnlitGeneric", params )
return mat
end
local mat = createKitMaterial( "assaultkit.png", "pointless_shit" )
local mat2 = Material( "assaultkit.png" )
hook.Add( "HUDPaint", "HUDPaint_DrawABox", function()
surface.SetMaterial( mat )
surface.SetDrawColor( 255, 255, 255, 255 )
surface.DrawTexturedRect( 50, 50, 128, 128 )
end )
Thirdly, you need to set $basetexture to a string as shown on the example for CreateMaterial() on the wiki.
Using GetName just makes it go purple and black, you think I haven't tried that?
I need to make the image glow, and I need VertexLitGeneric to do that.
The code I posted works just by copy pasting. You cannot use vertexlitgeneric for HUD elements, its for models.
Sorry, you need to Log In to post a reply to this thread.