I'm creating a texture with code like this:
SWEP.DisplayRT = GetRenderTarget("TF_DisplayRT", 512, 512, false)
SWEP.DisplayMat = CreateMaterial( "TF_DisplayMat", "UnlitGeneric", { ["$basetexture"] = "TF_DisplayRT" } )
This works and I can draw it no problem. However, I can't make it transparent. I need it to start transparent and I need to be able to clear what's on it, so it's fully transparent and blank again. What texture/shader flags do I need, and how do I clear it? Bonus points if anyone knows how to clear just sections of it.
I think you cannot make a transparent texture with Lua, at least not without some stencil trickery and whatnot. Don't fully take my word for it, but I am pretty sure it is not possible. You can clear the render target to a certain color, not so sure about transparency. If there is a way and someone knows, please correct me.
Material Parameters
That Material Parameters link has neither examples nor the actual parameter used to create transparent effects.
The solution I came up with was this:
SWEP.DisplayRT = GetRenderTarget("TF_DisplayRT", 512, 512, false)
SWEP.DisplayMat = CreateMaterial( "TF_DisplayMat", "UnlitGeneric", { ["$basetexture"] = "TF_DisplayRT", ["$translucent"] = 1 } )
--Then, actually update it like this:
render.SetRenderTarget(self.DisplayRT)
render.OverrideAlphaWriteEnable( true, true )
render.ClearDepth()
render.Clear( 0, 0, 0, 0 )
surface.SetDrawColor(0,0,0,255)
--do more surface.Draw whatevs here
render.OverrideAlphaWriteEnable( false )
This has an interesting effect that, despite making the texture 512 by 512, it does not draw how you'd expect. Drawing a line from 0,0 to 256,256 does not go from the top left corner to the center, but drawing a line from 0,0 to ScrW()/2,ScrH()/2 does. It does something like rescaling the parameters from your screen size to the size of the rendered texture, as fractions of the whole display.
Sorry, you need to Log In to post a reply to this thread.