Skip to content

Commit

Permalink
Manually Set Hologram Render Groups (#1873)
Browse files Browse the repository at this point in the history
* rendergroup setting

* typo

* nevermind i get it now

* ensure group is an integer

* getRenderGroup

* Tweak

* and the rest
  • Loading branch information
Advers authored Oct 21, 2024
1 parent 07a9665 commit 426483f
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 12 deletions.
13 changes: 7 additions & 6 deletions lua/entities/starfall_hologram/cl_init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include("shared.lua")
ENT.RenderGroup = RENDERGROUP_OPAQUE

ENT.DefaultMaterial = Material( "hunter/myplastic" )
ENT.Material = ENT.DefaultMaterial
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions lua/entities/starfall_hologram/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lua/entities/starfall_hologram/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions lua/entities/starfall_hud/cl_init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
include("shared.lua")

ENT.RenderGroup = RENDERGROUP_BOTH

function ENT:Initialize()
self.BaseClass.Initialize(self)

Expand Down
2 changes: 0 additions & 2 deletions lua/entities/starfall_processor/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions lua/entities/starfall_screen/cl_init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
include("shared.lua")

ENT.RenderGroup = RENDERGROUP_BOTH

This comment has been minimized.

Copy link
@NullLikesNothing

NullLikesNothing Oct 24, 2024

The RenderGroup for screens should still be RENDERGROUP_BOTH

Left is RENDERGROUP_BOTH and the right is after this change.
Image


local render = render
local IsValid = FindMetaTable("Entity").IsValid

Expand Down
7 changes: 7 additions & 0 deletions lua/starfall/libs_sh/entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions lua/starfall/libs_sh/enum.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions lua/starfall/libs_sh/hologram.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 426483f

Please sign in to comment.