Open ZH-Hristov opened 9 months ago
I think the drawHud hook clips rendering within the screen resolution. Maybe just need to put a DisableClipping call in it.
If disabling the clipping won't work, maybe using RT_SIZE_LITERAL
could.
SF render.enableClipping doesn't change it.
that function is for 3d clip planes. it won't do it
I tried this
-- TEXTUREFLAGS_PROCEDURAL + TEXTUREFLAGS_EIGHTBITALPHA + TEXTUREFLAGS_RENDERTARGET + TEXTUREFLAGS_DEPTHRENDERTARGET
return GetRenderTargetEx("Starfall_CustomRT_" .. i, 1024, 1024, RT_SIZE_LITERAL, MATERIAL_RT_DEPTH_SEPARATE, bit.bor(2048, 8192, 32768, 65536), 0, 0 )
I'm pretty sure I tried it before too and it didn't work. Not sure it can be fixed
@thegrb93 Got a reply from rubat. Apparently drawing on it in 2D mode when it's bigger than the screen requires it to be wrapped in cam.start2D
Will give it a try when I can later.
The selectRenderTarget function does use cam.start2d
The selectRenderTarget function does use cam.start2d
This has to be a issue in Starfall somewhere. I recreated the exact same thing in normal GLua and it works fine there.
local exampleRT = GetRenderTarget( "example_rt", 1024, 1024 )
render.PushRenderTarget( exampleRT )
cam.Start2D()
render.Clear(0, 0, 0, 0)
surface.SetDrawColor( 255, 0, 0, 255 )
surface.DrawRect( 1024 * 0.5 - 25, 0, 50, 1024 )
cam.End2D()
render.PopRenderTarget()
local customMaterial = CreateMaterial( "example_rt_mat", "UnlitGeneric", {
["$basetexture"] = exampleRT:GetName(), -- You can use "example_rt" as well
["$translucent"] = 1,
["$vertexcolor"] = 1
} )
hook.Add( "HUDPaint", "ExampleDraw", function()
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( customMaterial )
surface.DrawTexturedRect( ScrW() * 0.5 - (ScrH() * 0.5), 0, ScrH(), ScrH() )
end )
Tested at 720p. SF one is still cut off.
@thegrb93 Got any clues? I tried DisableClipping in the render library but that didn't change anything.
The GLua snippet I sent works fine at low height resolutions, despite seemingly not doing anything different functionally?
I'll try in a bit
@ZH-Hristov It's because of the HUDPaint hook. If you do this code, then you see the same clipping starfall has.
local exampleRT = GetRenderTarget( "example_rt", 1024, 1024 )
local customMaterial = CreateMaterial( "example_rt_mat", "UnlitGeneric", {
["$basetexture"] = exampleRT:GetName(), -- You can use "example_rt" as well
["$translucent"] = 1,
["$vertexcolor"] = 1
} )
hook.Add( "HUDPaint", "ExampleDraw", function()
render.PushRenderTarget( exampleRT )
cam.Start2D()
render.Clear(0, 0, 0, 0)
surface.SetDrawColor( 255, 0, 0, 255 )
surface.DrawRect( 1024 * 0.5 - 25, 0, 50, 1024 )
cam.End2D()
render.PopRenderTarget()
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( customMaterial )
surface.DrawTexturedRect( ScrW() * 0.5 - (ScrH() * 0.5), 0, ScrH(), ScrH() )
end )
Seems most gmod render hooks suffer from this. I tried a few of them in starfall
--@name Untitled
--@author Sparky
--@client
enableHud(nil, true)
render.createRenderTarget("hi")
hook.add("predrawtranslucentrenderables","",function()
render.selectRenderTarget("hi")
render.clear()
render.setColor(Color(255,0,0))
render.drawRect(0,0,1024,1024)
render.selectRenderTarget()
render.pushViewMatrix({type="2D"})
render.setColor(Color(255,255,255))
render.setRenderTargetTexture("hi")
render.drawTexturedRect(100,200,200,200)
render.popViewMatrix()
end)
@ZH-Hristov It's because of the HUDPaint hook. If you do this code, then you see the same clipping starfall has.
local exampleRT = GetRenderTarget( "example_rt", 1024, 1024 ) local customMaterial = CreateMaterial( "example_rt_mat", "UnlitGeneric", { ["$basetexture"] = exampleRT:GetName(), -- You can use "example_rt" as well ["$translucent"] = 1, ["$vertexcolor"] = 1 } ) hook.Add( "HUDPaint", "ExampleDraw", function() render.PushRenderTarget( exampleRT ) cam.Start2D() render.Clear(0, 0, 0, 0) surface.SetDrawColor( 255, 0, 0, 255 ) surface.DrawRect( 1024 * 0.5 - 25, 0, 50, 1024 ) cam.End2D() render.PopRenderTarget() surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( customMaterial ) surface.DrawTexturedRect( ScrW() * 0.5 - (ScrH() * 0.5), 0, ScrH(), ScrH() ) end )
Adding DisableClipping in the RT context here works:
local exampleRT = GetRenderTarget( "example_rt", 1024, 1024 )
local customMaterial = CreateMaterial( "example_rt_mat", "UnlitGeneric", {
["$basetexture"] = exampleRT:GetName(), -- You can use "example_rt" as well
["$translucent"] = 1,
["$vertexcolor"] = 1
} )
hook.Add( "HUDPaint", "ExampleDraw", function()
render.PushRenderTarget( exampleRT )
DisableClipping(true)
cam.Start2D()
render.Clear(0, 0, 0, 0)
surface.SetDrawColor( 255, 0, 0, 255 )
surface.DrawRect( 1024 * 0.5 - 25, 0, 50, 1024 )
cam.End2D()
DisableClipping(false)
render.PopRenderTarget()
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( customMaterial )
surface.DrawTexturedRect( ScrW() * 0.5 - (ScrH() * 0.5), 0, ScrH(), ScrH() )
end )
So I suppose we need that in the render lib
Weird though, since the prepare render hook in SF has a surface.DisableClipping(true) call. It's apparently deprecated but it's an alias so it shouldn't matter. Maybe pushing an RT or a cam enables clipping? Idk.
Idk if its an alias. You should try adding it
I have no damn clue why this refuses to work in SF. I tried adding it in PrepareRender, I tried adding it as a render library function and I tried adding it right before cam.Start2D in the selectRenderTarget function.
It still gets cut off.
kill me
I'll check it out again
@ZH-Hristov Ok I got it working with render.drawRectFast
--@name Untitled
--@author Sparky
--@client
enableHud(nil, true)
render.createRenderTarget("hi")
hook.add("drawhud","",function()
render.selectRenderTarget("hi")
render.clear()
render.setColor(Color(255,0,0))
render.drawRectFast(0,0,1024,1024)
render.selectRenderTarget()
render.pushViewMatrix({type="2D"})
render.setColor(Color(255,255,255))
render.setRenderTargetTexture("hi")
render.drawTexturedRect(100,200,200,200)
render.popViewMatrix()
end)
It looks like the 3D rendering functions in the 2D context, such as render.DrawQuad suffers from clipping still, but surface render functions don't.
I didn't know the SF rect functions used DrawQuad instead. I guess I'll just use the "fast" ones.
Tested with this code:
Creates a centered RT and tries to draw a red rectangle from the top to the bottom of the screen.
For example: The rectangle will be properly fully drawn at 1080p, but will be cut off about 3/4 of the way down at 720p.
This could be a GMod issue for all I know, so its place might not be here.