• Alter a HUD drawn texture's colour/saturation/etc.
    16 replies, posted
I give up. I've been quite some hours investigating the render library and I've been unable to understand all functions and achieve what I was looking for. I want to generate a texture that contains the icon from the weapon selector of a specific weapon. It has two main textures: A background, and on top, the texture resulting of WEAPON.WepSelectIcon (which returns an ID). Right now I've got something like this: https://files.facepunch.com/forum/upload/113353/34a97a6f-8152-440b-993e-894150643f98/scn1.png And I would like to alter the rendering of the weapon image so it looks something like this: https://files.facepunch.com/forum/upload/113353/d3956b82-4e0b-4ed4-a600-7f599bb8c986/scn2.png (inb4 shitty photoshopping) Only altering saturation would be enough, so the colouring could be more effective. Any ideas? Thanks in advance.
This would be possible through the use of stencils. I'm not good with stencils though, I still find them confusing although I've used them before. I'm sure somebody on this forum will know what to do in this case.
Thanks for the answer, at least I know something more that before!
Actually, I forgot Blue made a really great library that you could probably use for this: Blue's Masks and Shadows!
Or, you can just change the textures in a DModelPanel. This should work, I guess. local panel = vgui.Create("DModelPanel") panel:SetPos( 0, 0 ) -- Set this to the position of it or something panel:SetSize( 200, 200 ) panel:SetModel("blah/blah/model.mdl") -- set this to the model panel:RequestFocus() -- something along these lines, tbh cant remember function panel:PreDrawModel(ent) ent:SetMaterial("gui/someorangething") -- get an orange texture, or something end
I might aswell check out that tomorrow and see if I can make it work with it. It looks like what I might need but I have to take a deeper look at it.
I mean, if my idea works then using Blue's Masks would be a bit of a waste... (notice me)
I was assuming the model he was showing wasn't a DModelPanel, but a static image. If it's a model it's way easier.
OP says... I've invested quite some hours investigating the render library and I've been unable to understand all functions and achieve what I was looking for. ... so I can only presume either he has something that barely works or is using a png.
yes you are correct so we must wait for his response
As I said on the initial post, I'm using the icon of the swep SWEP.WepSelectIcon, so it's a texture (vtf). Using a DModelPanel would be a hassle because every weapon model has a size and origin and I'm trying to create a system as universal as possible (for the default weapons I'll have to write a text, and for those using a custom function I call it on the same place that I'd draw the image).
In that case, try using Blue's Masks and Shadows! I'll make an example maybe later
That looks sick. I'll see if I can use it (I don't have the absolute path, only the texture ID though, I don't know if I'll be able to use it with only that).
local gray = CreateMaterial("color_gray","UnlitGeneric",Material("color"):GetKeyValues()) gray:SetVector( "$color", Vector(0.5,0.5,0.5) ) function self.Icon:DrawModel( ent ) render.ClearStencil()  render.SetStencilEnable(true) render.SetStencilTestMask(255) render.SetStencilWriteMask(255) render.SetStencilReferenceValue(1)  render.SetStencilPassOperation( STENCILOPERATION_REPLACE )  render.SetStencilFailOperation( STENCILOPERATION_ZERO )  render.SetStencilZFailOperation( STENCILOPERATION_ZERO )  render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_ALWAYS ) render.SetBlend(0) self:GetEntity():DrawModel() render.SetBlend(1) render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_EQUAL) render.SetMaterial(gray) render.DrawScreenQuad() render.SetStencilEnable(false)  return  end I used this code to make the model in a DModel be gray. This code works but is most likely trash, be careful. https://files.facepunch.com/forum/upload/114817/03c6b641-aeb1-49f9-9b10-e30137b5a29b/image.png
https://files.facepunch.com/forum/upload/113353/6260e5c5-13c9-47ce-9044-dd0cc1322dae/scn4.png This is the result, and I kinda expected it. I don't know if by tweaking your code I could get a result, but I think this is happening because your method is only effective in a 3D context, where the shape is decided by the model itself, and you're just changing its material and color.
If it has a texture ID it should also have an absolute path. You usually need to use surface.GetTextureID to even get the ID for the texture, and that function requires a path. I'm not sure how you even create an ITexture on it's own but I'm sure there's a path somewhere
I don't have access to the absolute path since I get the texture from SWEP.WepSelectIcon, which is a property that most SWEPs are bound to have (unless they use their only 'draw slot' function, which I take in account too) and it's always a texture ID. Unless there's a function to retreive the texture path from a ID (which I currently don't know despite having searched) I don't really know if I'd be able to get the path directly.
Sorry, you need to Log In to post a reply to this thread.