Garry's Mod Wiki

render.DepthRange

render.DepthRange( number depthmin, number depthmax )

Description

Set's the depth range of the upcoming render.

Arguments

1 number depthmin
The minimum depth of the upcoming render. 0.0 = render normally; 1.0 = render nothing
2 number depthmax
The maximum depth of the upcoming render. 0.0 = render everything (through walls); 1.0 = render normally

Example

Perform a downward screen wipe effect on all opaque objects once the client connects.

local depthmin = 1.0 function GM:PreDrawOpaqueRenderables(bDrawingDepth, bDrawingSkybox) render.DepthRange(depthmin, 1.0) if(depthmin > 0.0) then depthmin = depthmin - 0.001 end end

Example

Same effect as above but with a dark shadow skin present where the model is being drawn.

local depthmin = 1.0 local spawn_copies = {} -- The shadow copies function GM:PreDrawOpaqueRenderables(bDrawingDepth, bDrawingSkybox) render.DepthRange(depthmin, 1.0) if(!spawn_copies) then return false end if(depthmin > 0.0) then depthmin = depthmin - 0.001 else local alpha = 0 local valid_copies = 0 -- Fade out the shadow copies and remove them for _, spawncopy in pairs(spawn_copies) do if(IsValid(spawncopy)) then alpha = spawncopy:GetColor().a if(alpha > 0) then spawncopy:SetColor(Color(255, 255, 255, alpha-1)) else spawncopy:Remove() end valid_copies = valid_copies + 1 end end -- Nullify table since we aren't using it any more if(valid_copies == 0) then spawn_copies = nil end end end function GM:OnEntityCreated(ent) if(!spawn_copies) then return end -- Prevents infinite loop and other errors if(ent:GetClass() != "class C_BaseFlex" && ent:GetRenderGroup() == RENDERGROUP_OPAQUE && ent:GetClass() != "gmod_hands") then local mdl = ent:GetModel() -- Check that the entity is a model and not a brush if(mdl && string.find(mdl, ".mdl")) then local spawncopy = ClientsideModel(mdl) -- A material with $ignorez set to 1 works best here spawncopy:SetMaterial("models/overlay_rendertarget") spawncopy:AddEffects(EF_BONEMERGE) spawncopy:SetParent(ent) spawncopy:SetRenderMode(RENDERMODE_TRANSALPHA) spawncopy:SetColor(Color(255, 255, 255, 92)) table.insert(spawn_copies, spawncopy) end end end
Output:

Page Links


Special Pages


Wikis

?

Render Time: 34ms

DB GetPage 4
Generate Html 7
SaveChanges (1) 8
Render Body 0
Render Sidebar 12