Open meepen opened 9 years ago
AFAIK @UnderscoreKilburn said that there will always be problems with transparency and render targets.
is there any work arounds? i kind of want to use transparency
I believe this is what you want? http://wiki.garrysmod.com/page/render/OverrideAlphaWriteEnable
There's an example in http://wiki.garrysmod.com/page/render/PushRenderTarget
Although if I remember correctly you also need to create the render target with some other flags, but give it a try anyway.
I figured that out after a while, but yes.
Did you eventually figure out which flags to use, @meepdarknessmeep?
Also running into issues with this. All my testing has proved fruitless.
I tried everything I could think of... I tried both GetRenderTarget and GetRenderTargetEx, and neither worked. When using GetRenderTargetEx, I tried all sorts of flags and settings without success. I even followed the example shown at the bottom of the documentation for the render.PushRenderTarget function or method or whatever the heck it's called in Lua.
I'm not sure if it has to do with render context or not, but the few tests I tried weren't successful.
Here's my code for making the texture:
-- https://wiki.facepunch.com/gmod/Global.GetRenderTargetEx
local b_texture = GetRenderTargetEx(
"cb_dof_b", -- texture name for internal use
ScrW(), -- texture width. should be power of 2.
ScrH(), -- texture height. should be power of 2.
RT_SIZE_DEFAULT, -- size mode.
MATERIAL_RT_DEPTH_SHARED, -- depth mode.
64+256+512+8192, -- texture flags. enums are not defined. currently has SRGB, no mipmap, no lod, and uses eight bit alpha.
CREATERENDERTARGETFLAGS_UNFILTERABLE_OK, -- render target flags. Used for HDR.
IMAGE_FORMAT_RGBA8888 -- Image format.
)
I used the PreDrawEffect hook to execute the following every frame:
cam.Start2D()
render.OverrideAlphaWriteEnable( true, true )
render.PushRenderTarget( b_texture )
render.Clear( 0, 0, 0, 0, true )
render.SetColorMaterial()
render.DrawScreenQuadEx( 100, 100, ScrW()-200, ScrH()-200 )
local r, g, b, a = render.ReadPixel( 10, 10 )
render.PopRenderTarget()
print( r, g, b, a )
local color = b_texture:GetColor( 10, 10 )
PrintTable( color )
render.ClearRenderTarget( b_texture, Color(0,0,0,0) )
color = b_texture:GetColor( 10, 10 )
PrintTable( color )
render.OverrideAlphaWriteEnable( false )
cam.End2D()
No matter what I do, I still get the same result. It's like there isn't an alpha channel at all or it's not being set right:
0 0 0 nil
a = 255 b = 0 g = 0 r = 0
a = 255 b = 0 g = 0 r = 0
All I want to do is blit one render target to another using the standard alpha compositing operation, but nothing I do seems to work.
for example,
this will draw the rectangle with color 255,255,255,(200/255)*100
i am assuming that it should however set the color of the whole rendertarget at black with 100 alpha then let the surface calls that are upcoming do whatever color they want