• Render a view in 3D2D
    5 replies, posted
I want to render a few views in 3D2D in an ENT:Draw() function to make a security camera system. I have tried a few things, but none of them work. If someone could give me a script to render this: [lua]local CamData = {} CamData.angles = Angle(0, 90, 0) CamData.origin = Vector(-6538.981, -9398.4609, 898.976) CamData.x = 0 CamData.y = 0 CamData.w = 200 CamData.h = 200[/lua] I can easily deal with the rest myself. My current attempt: [lua] cam.Start3D2D(self.Entity:GetPos() + self.Entity:GetUp() * -39 + self.Entity:GetForward() * 1.3 + self.Entity:GetRight()*4, ang ,0.2) --[[ surface.SetDrawColor(074, 125, 182, 255) surface.DrawRect(-w/2,-h/2,w,h) surface.SetDrawColor(225, 225, 225, 255) surface.DrawOutlinedRect(-w/2,-h/2,w,h) --]] local OldRT = render.GetRenderTarget() local NewRT = f // Set the material of the screen to our render target mot:SetMaterialTexture( "$basetexture", NewRT ) --print(OldRT) render.SetRenderTarget(f) surface.SetDrawColor(255,255,255,255) surface.SetTexture(mot) surface.DrawTexturedRect(-w/2,-h/2,w,h) render.SetViewPort(0,0,320,320) render.RenderView( CamData ) render.SetViewPort(0,0,ScrW(),ScrH()) -- -- render.SetViewPort(0,0,ScrW(),ScrH()) render.SetRenderTarget( OldRT ) -- surface.SetDrawColor(255,255,255,40) surface.SetTexture(mat) surface.DrawTexturedRect(-w/2,-h/2,w,h) --]] cam.End3D2D()[/lua] This simply makes all visual effects render in a 320,320 box in the top-left of my screen, without the view specified. Variable definitions: [lua]local mat = surface.GetTextureID"effects/tvscreen_noise003a" local f = GetRenderTarget("Testies",512,512) local mot = Material"paperboy"[/lua] Testies is defined as [code]"Testies" { "Name" "Testies" "Width" "512" "Height" "512" }[/code] and paperboy is a vmt defined as [code]"UnlitGeneric" { "$baseTexture" "models/props_debris/building_template010a" //"models/props_c17/metalladder003" "$nocull" "1" } [/code] thanks [editline]12:51PM[/editline] UPDATE: This draws a view, but it has black areas (like where props and occasional walls are) that slowly fill the screen every time I reload the entity, and the only way to get rid of them is to restart gmod. [lua]function ENT:Draw() self.Entity:DrawModel() local lightdata = render.GetLightColor(self.Entity:GetPos()) local ang = self.Entity:GetAngles() ang:RotateAroundAxis(ang:Right(), rot.x) ang:RotateAroundAxis(ang:Up(), rot.y) ang:RotateAroundAxis(ang:Forward(), rot.z) local OldRT = render.GetRenderTarget() local mot = mot local NewRT = f mot:SetMaterialTexture( "$basetexture", NewRT ) render.SetRenderTarget(NewRT) render.SuppressEngineLighting(true) render.RenderView( CamData ) render.SuppressEngineLighting(false) render.SetRenderTarget( OldRT ) cam.Start3D2D(self.Entity:GetPos() + self.Entity:GetUp() * -39 + self.Entity:GetForward() * 1.3 + self.Entity:GetRight()*4, ang ,0.2) surface.SetDrawColor(074, 125, 182, 255) surface.DrawRect(-w/2,-h/2,w,h) surface.SetDrawColor(225, 225, 225, 255) surface.DrawOutlinedRect(-w/2,-h/2,w,h) self:DrawLines(w,h) surface.SetDrawColor(255,255,255,100) -- surface.SetTexture(mof) surface.SetMaterial(mot) surface.DrawTexturedRect(-w/2,-h/2,w,h) cam.End3D2D() end[/lua] How do I make it draw properly? [editline]12:58PM[/editline] Further update, the player model doesn't draw, and the player's weapon leaves the black trails on the screen, which don't fade and eventually fill the entire screen. [media]http://i39.tinypic.com/28vskzt.jpg[/media] [editline]01:01PM[/editline] render.ClearDepth() fixes it. Whoo-hoo :) [editline]01:02PM[/editline] Any way to get the local player to draw? [media]http://i44.tinypic.com/fm56ir.jpg[/media]
Right, it's all nice now, apart from one problem: If the client can't see the camera's view, no entities in that view gets rendered. How'd I make it so they get rendered? [media]http://i43.tinypic.com/k00qhj.jpg[/media]
This is looking sexy
FireFox's Address Bar Of Doomâ„¢ just pulled this thread up when I was typing something else. I'd still quite like to get this to work if anyone knows how to solve the PVS issues.
Have you tried [url=http://wiki.garrysmod.com/?title=Gamemode.SetupPlayerVisibility]this[/url]? [lua] local function SetupPlayerVisibility( pl ) for i, entity in pairs( ents.GetAll( ) ) do AddOriginToPVS( entity:GetPos( ) ); end end hook.Add( "SetupPlayerVisibility", "AddEntsToPVS", SetupPlayerVisibility ); [/lua] That's probably not the right way to use it, though.
Nope, but looking at the wiki all I probably need to do is add each cam point to the PVS. I will experiment. :3: [editline]11:39AM[/editline] Well after throwing up a few rather odd engine errors [code] blocking issue in occlusion queries! Grab brian! blocking issue in occlusion queries! Grab brian! blocking issue in occlusion queries! Grab brian! blocking issue in occlusion queries! Grab brian! blocking issue in occlusion queries! Grab brian! [/code] it works! Thanks a lot Nevec! :D [img]http://i32.tinypic.com/erah4p.jpg[/img] [editline]Holy shit I used to type like a fucking mong[/editline] [url=https://github.com/Lexicality/AncientGLuaCrap/blob/master/lua/entities/sent_secstation/shared.lua]code released on github[/url]
Sorry, you need to Log In to post a reply to this thread.