Hello,
I'm trying to get a Flamethrower to look its metal is getting hotter the longer it is used by blending two different textures together. I've attempted to make this effect by using the PreDrawViewModel hook and the RenderScreenspaceEffects without much luck, and with plenty of crashes as well (causing overflows by causing the draw function to recall the hook, resulting in an infinite loop). The best I've managed was this:
local Mat = Material("models/weapons/monstermash/flamethrower/flamethrower_hot")
function HotFlameThrower()
cam.Start3D( EyePos(), EyeAngles(), 68.5 )
cam.IgnoreZ( true )
for k, v in pairs( ents.GetAll() ) do
if IsValid(v) && v:GetClass() == "viewmodel" && v:GetClass() != "gmod_hands" then
render.SetBlend( 0.5 )
render.MaterialOverride( Mat )
v:DrawModel()
render.SetBlend( 1 )
render.MaterialOverride( 0 )
end
end
cam.IgnoreZ( false )
cam.End3D()
end
hook.Add("RenderScreenspaceEffects","HotFlameThrower",HotFlameThrower)
However, SetBlend seems to be usless, and for some reason the gmod hands also get affected bu the change in texture. What confuses me is that this following code works:
if IsValid(v) && v:GetClass() != "viewmodel" && v:GetClass() != "gmod_hands" then
render.SetBlend( 0.5 )
render.MaterialOverride( Mat )
v:DrawModel()
render.SetBlend( 1 )
render.MaterialOverride( 0 )
end
https://files.facepunch.com/forum/upload/113610/540ca3c4-d5e5-42d9-b18a-46d8adb83802/image.png
But as soon as I attempt to add it to the viewmodel, the texture is always completely opaque, even with Blend set to 0.
Any suggestions?
You could try to compile the model in a way that you stack 2 meshes ontop of each other, each with a different material (one acting as the base flamethrower mesh, the other one as the 'hot' overlay) and then just make the overlay effect stronger/weaker depending on the flamethrower usage.
Ehh, I was hoping I could stick to textures only so that I could have variations of this code working for other weapons if I wished to.
You could use WEAPON/PostDrawViewModel or whichever hook that this is supposed to be done in to draw a second entity over the default viewmodel (if they are misplaced, you need to use cam.Start3D with a proper fov argument to fix it) and do render magic on the second entity.
Sorry, you need to Log In to post a reply to this thread.