diff --git a/lua/entities/starfall_hologram/cl_init.lua b/lua/entities/starfall_hologram/cl_init.lua index 379e0e61b..593d2e6b1 100644 --- a/lua/entities/starfall_hologram/cl_init.lua +++ b/lua/entities/starfall_hologram/cl_init.lua @@ -1,5 +1,4 @@ include("shared.lua") -ENT.RenderGroup = RENDERGROUP_OPAQUE ENT.DefaultMaterial = Material( "hunter/myplastic" ) ENT.Material = ENT.DefaultMaterial @@ -66,6 +65,7 @@ function ENT:Initialize() self.sf_userrenderbounds = false self:SetupBones() self:OnScaleChanged(nil, nil, self:GetScale()) + self:OnRenderGroupChanged(nil, nil, self:GetRenderGroupInternal()) if self:EntIndex() == -1 then self:SetPlayerColorInternal(VECTOR_PLAYER_COLOR_DISABLED) @@ -130,14 +130,15 @@ function ENT:OnCullModeChanged() self.renderstack:makeDirty() end -function ENT:Draw(flags) - local selfTbl = self:GetTable() - if self:GetColor().a ~= 255 then - selfTbl.RenderGroup = RENDERGROUP_BOTH +function ENT:OnRenderGroupChanged(name, old, group) + if group == -1 then + self.RenderGroup = nil else - selfTbl.RenderGroup = RENDERGROUP_OPAQUE + self.RenderGroup = group end +end +function ENT:Draw(flags) self.renderstack:run(flags) end diff --git a/lua/entities/starfall_hologram/init.lua b/lua/entities/starfall_hologram/init.lua index 3b182ab8a..b90390c75 100644 --- a/lua/entities/starfall_hologram/init.lua +++ b/lua/entities/starfall_hologram/init.lua @@ -19,6 +19,7 @@ function ENT:Initialize() self:SetPlayerColorInternal(VECTOR_PLAYER_COLOR_DISABLED) self:SetSuppressEngineLighting(false) self:SetCullMode(false) + self:SetRenderGroupInternal(-1) self.updateClip = false self.AutomaticFrameAdvance = false diff --git a/lua/entities/starfall_hologram/shared.lua b/lua/entities/starfall_hologram/shared.lua index c0b4036c5..ea3aaeb8d 100644 --- a/lua/entities/starfall_hologram/shared.lua +++ b/lua/entities/starfall_hologram/shared.lua @@ -14,11 +14,13 @@ function ENT:SetupDataTables() self:NetworkVar( "Vector", 1, "PlayerColorInternal" ) self:NetworkVar( "Bool", 0, "SuppressEngineLighting" ) self:NetworkVar( "Bool", 1, "CullMode" ) + self:NetworkVar( "Int", 0, "RenderGroupInternal" ) if CLIENT then self:NetworkVarNotify( "Scale", self.OnScaleChanged ) self:NetworkVarNotify( "PlayerColorInternal", self.OnPlayerColorChanged ) self:NetworkVarNotify( "SuppressEngineLighting", self.OnSuppressEngineLightingChanged ) self:NetworkVarNotify( "CullMode", self.OnCullModeChanged ) + self:NetworkVarNotify( "RenderGroupInternal", self.OnRenderGroupChanged ) end end diff --git a/lua/entities/starfall_hud/cl_init.lua b/lua/entities/starfall_hud/cl_init.lua index 341248263..cce7e215d 100644 --- a/lua/entities/starfall_hud/cl_init.lua +++ b/lua/entities/starfall_hud/cl_init.lua @@ -1,7 +1,5 @@ include("shared.lua") -ENT.RenderGroup = RENDERGROUP_BOTH - function ENT:Initialize() self.BaseClass.Initialize(self) diff --git a/lua/entities/starfall_processor/cl_init.lua b/lua/entities/starfall_processor/cl_init.lua index 70361787d..42abe44f4 100644 --- a/lua/entities/starfall_processor/cl_init.lua +++ b/lua/entities/starfall_processor/cl_init.lua @@ -2,8 +2,6 @@ include("shared.lua") DEFINE_BASECLASS("base_gmodentity") -ENT.RenderGroup = RENDERGROUP_BOTH - local IsValid = FindMetaTable("Entity").IsValid local IsWorld = FindMetaTable("Entity").IsWorld diff --git a/lua/entities/starfall_screen/cl_init.lua b/lua/entities/starfall_screen/cl_init.lua index 986a386ad..013264a0f 100644 --- a/lua/entities/starfall_screen/cl_init.lua +++ b/lua/entities/starfall_screen/cl_init.lua @@ -1,7 +1,5 @@ include("shared.lua") -ENT.RenderGroup = RENDERGROUP_BOTH - local render = render local IsValid = FindMetaTable("Entity").IsValid diff --git a/lua/starfall/libs_sh/entities.lua b/lua/starfall/libs_sh/entities.lua index d56eccfc0..26182bdc6 100644 --- a/lua/starfall/libs_sh/entities.lua +++ b/lua/starfall/libs_sh/entities.lua @@ -289,6 +289,13 @@ if CLIENT then ent:SetupBones() ent:DrawModel() end + + --- Returns the render group of the entity. + -- @client + -- @return number Render group + function ents_methods:getRenderGroup() + return getent(self):GetRenderGroup() + end end local soundsByEntity = SF.EntityTable("emitSoundsByEntity", function(e, t) diff --git a/lua/starfall/libs_sh/enum.lua b/lua/starfall/libs_sh/enum.lua index c9f168da0..84c43f1a7 100644 --- a/lua/starfall/libs_sh/enum.lua +++ b/lua/starfall/libs_sh/enum.lua @@ -1025,6 +1025,32 @@ env.RENDERFX = { PULSEFASTWIDER = kRenderFxPulseFastWider } +--- ENUMs of entity rendergroups +-- @name builtins_library.RENDERGROUP +-- @class table +-- @field STATIC_HUGE +-- @field OPAQUE_HUGE +-- @field STATIC +-- @field OPAQUE +-- @field TRANSLUCENT +-- @field BOTH +-- @field VIEWMODEL +-- @field VIEWMODEL_TRANSLUCENT +-- @field OPAQUE_BRUSH +-- @field OTHER +env.RENDERGROUP = { + STATIC_HUGE = RENDERGROUP_STATIC_HUGE, + OPAQUE_HUGE = RENDERGROUP_OPAQUE_HUGE, + STATIC = RENDERGROUP_STATIC, + OPAQUE = RENDERGROUP_OPAQUE, + TRANSLUCENT = RENDERGROUP_TRANSLUCENT, + BOTH = RENDERGROUP_BOTH, + VIEWMODEL = RENDERGROUP_VIEWMODEL, + VIEWMODEL_TRANSLUCENT = RENDERGROUP_VIEWMODEL_TRANSLUCENT, + OPAQUE_BRUSH = RENDERGROUP_OPAQUE_BRUSH, + OTHER = RENDERGROUP_OTHER +} + --- VRmod library enums -- @name vr_library.VR -- @class table diff --git a/lua/starfall/libs_sh/hologram.lua b/lua/starfall/libs_sh/hologram.lua index bc73d4110..99676596d 100644 --- a/lua/starfall/libs_sh/hologram.lua +++ b/lua/starfall/libs_sh/hologram.lua @@ -500,6 +500,22 @@ function hologram_methods:setCullMode(mode) holo:SetCullMode(mode==1) end +--- Set the render group for a hologram. +-- @shared +-- @param number|nil group Render group. If unset, the engine will decide the render group based on the entity's materials. +function hologram_methods:setRenderGroup(group) + local holo = getholo(self) + checkpermission(instance, holo, "entities.setRenderProperty") + + if group then + checkluatype(group, TYPE_NUMBER) + + holo:SetRenderGroupInternal(math.Truncate(group)) + else + holo:SetRenderGroupInternal(-1) + end +end + --- Applies engine effects to the hologram -- @shared -- @param number effect The effects to add. See EF Enums