Team Spartan Cookies & Milk Forums
Emitter's drawing priority - Printable Version

+- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk)
+-- Forum: Feedback (https://teamscm.co.uk/forum-9.html)
+--- Forum: Suggestions and improvements (https://teamscm.co.uk/forum-11.html)
+--- Thread: Emitter's drawing priority (/thread-3201.html)



Emitter's drawing priority - The17thDoctor - 04-04-2020

I noticed using starfall emitters that if 2 2D3D cameras were created, the one that is last in the rendering hook is drawing over the original one, is there a possibility to add something in order to avoid this issue ?


RE: Emitter's drawing priority - Person8880 - 05-04-2020

This happens because 3D2D rendering disables writing to the depth buffer (though still tests against it).

I've added a new function, render.overrideDepthEnable() which will allow you to force depth writing to be enabled. Use this before starting a 3D2D camera with opaque drawing operations to have it properly respect depth.

For example (taken from the docs):
-- Force depth writing to be enabled (must be done outside the 3D2D block). 
render.overrideDepthEnable( true, true )

-- First render a red rectangle.
render.start3D2D( Pos, Ang, 0.1 )
render.setColor( 255, 0, 0 )
render.drawRect( 0, 0, 256, 256 )
render.end3D2D()

-- Then render a yellow rectange behind it, note how this rectangle is occluded.
-- If you comment out the overrideDepthEnable above, this will draw over the top of the red rectangle.
render.start3D2D( Pos - Dir * 5, Ang, 0.1 )
render.setColor( 255, 255, 0 )
render.drawRect( 0, 0, 256, 256 )
render.end3D2D()

-- Stop overriding depth writing.
render.overrideDepthEnable( false )

Note that for translucent elements, this won't help. Translucent elements have to be drawn in the right order as it doesn't make sense for them to write to the depth buffer (and if you try it you'll get very strange results).


RE: Emitter's drawing priority - The17thDoctor - 05-04-2020

Thank you, that will really help for what I wanted to do Smile

After trying the function, my starfall returned me :
SF:.txt:11: attempt to call field 'overrideDepthEnable' (a nil value)

If you have any idea on why it does that, here is my code by the way :

--@name Test
--@author
--@shared

if SERVER then

else
eself = ents.self()

hook("render","render",function()
render.overrideDepthEnable(true,true)

render.start3D2D(eself:toWorld(Vector(0,0,-35)),eself:toWorld(Angle(0,0,0)),0.1)
render.setColor(255,255,255)
render.drawRect(-50,-35,100,70)
render.end3D2D()

render.overrideDepthEnable(false)
end)
end



RE: Emitter's drawing priority - mariofludd - 05-04-2020

(05-04-2020, 03:13 PM)The17thDoctor Wrote: Thank you, that will really help for what I wanted to do Smile

After trying the function, my starfall returned me :
SF:.txt:11: attempt to call field 'overrideDepthEnable' (a nil value)

If you have any idea on why it does that, here is my code by the way :

Line 11:  render.overrideDepthEnable(true,true)

maybe its the 2 true values?
(yes the docs have 2, try 1, see if it works)


RE: Emitter's drawing priority - Person8880 - 05-04-2020

The server needs to restart for the function to be available. I've restarted server 2 which was empty so it should be available there.


RE: Emitter's drawing priority - The17thDoctor - 05-04-2020

Thank you