local mat_Copy = Material( "pp/copy" )
local mat_Add = Material( "pp/add" )
local mat_Sub = Material( "pp/sub" )
local rt_Store = render.GetScreenEffectTexture( 0 )
local rt_Blur = render.GetScreenEffectTexture( 1 )
local List = {}
local RenderEnt = NULL
function Add( entities, color, blurx, blury, passes, add, ignorez )
if ( table.IsEmpty( entities ) ) then return end
if ( add == nil ) then add = true end
if ( ignorez == nil ) then ignorez = false end
local t =
{
Ents = entities,
Color = color,
Hidden = when_hidden,
BlurX = blurx or 2,
BlurY = blury or 2,
DrawPasses = passes or 1,
Additive = add,
IgnoreZ = ignorez
}
table.insert( List, t )
end
function RenderedEntity()
return RenderEnt
end
function Render( entry )
local rt_Scene = render.GetRenderTarget()
-- Store a copy of the original scene
render.CopyRenderTargetToTexture( rt_Store )
-- Clear our scene so that additive/subtractive rendering with it will work later
if ( entry.Additive ) then
render.Clear( 0, 0, 0, 255, false, true )
else
render.Clear( 255, 255, 255, 255, false, true )
end
-- Render colored props to the scene and set their pixels high
cam.Start3D()
render.SetStencilEnable( true )
render.SuppressEngineLighting(true)
cam.IgnoreZ( entry.IgnoreZ )
render.SetStencilWriteMask( 1 )
render.SetStencilTestMask( 1 )
render.SetStencilReferenceValue( 1 )
render.SetStencilCompareFunction( STENCIL_ALWAYS )
render.SetStencilPassOperation( STENCIL_REPLACE )
render.SetStencilFailOperation( STENCIL_KEEP )
render.SetStencilZFailOperation( STENCIL_KEEP )
for k, v in pairs( entry.Ents ) do
if ( !IsValid( v ) || v:GetNoDraw() ) then continue end
RenderEnt = v
v:DrawModel()
end
RenderEnt = NULL
render.SetStencilCompareFunction( STENCIL_EQUAL )
render.SetStencilPassOperation( STENCIL_KEEP )
-- render.SetStencilFailOperation( STENCIL_KEEP )
-- render.SetStencilZFailOperation( STENCIL_KEEP )
cam.Start2D()
surface.SetDrawColor( entry.Color )
surface.DrawRect( 0, 0, ScrW(), ScrH() )
cam.End2D()
cam.IgnoreZ( false )
render.SuppressEngineLighting(false)
render.SetStencilEnable( false )
cam.End3D()
-- Store a blurred version of the colored props in an RT
render.CopyRenderTargetToTexture( rt_Blur )
render.BlurRenderTarget( rt_Blur, entry.BlurX, entry.BlurY, 1 )
-- Restore the original scene
render.SetRenderTarget( rt_Scene )
mat_Copy:SetTexture( "$basetexture", rt_Store )
mat_Copy:SetString( "$color", "1 1 1" )
render.SetMaterial( mat_Copy )
render.DrawScreenQuad()
-- Draw back our blured colored props additively/subtractively, ignoring the high bits
render.SetStencilEnable( true )
render.SetStencilCompareFunction( STENCIL_NOTEQUAL )
-- render.SetStencilPassOperation( STENCIL_KEEP )
-- render.SetStencilFailOperation( STENCIL_KEEP )
-- render.SetStencilZFailOperation( STENCIL_KEEP )
if ( entry.Additive ) then
mat_Add:SetTexture( "$basetexture", rt_Blur )
render.SetMaterial( mat_Add )
else
mat_Sub:SetTexture( "$basetexture", rt_Blur )
render.SetMaterial( mat_Sub )
end
for i = 0, entry.DrawPasses do
render.DrawScreenQuad()
end
render.SetStencilEnable( false )
-- Return original values
render.SetStencilTestMask( 0 )
render.SetStencilWriteMask( 0 )
render.SetStencilReferenceValue( 0 )
Assistant
It is possible that code 1 and code 2 could conflict since they both use stencil buffers and globally affect rendering settings. To fix the conflict, you should encapsulate the rendering logic into render scene functions for better modularity and avoid global changes to rendering settings.
User
Assistant
Here is a modified version of Code 2 that adapts to Code 1's logic and avoids any conflicts with the stencil buffer:
User
you code 1 as a base
Assistant
Here is the modified version of Code 1 as a base, with the XRayMat function from Code 2 integrated. Now the code should avoid conflicts with the stencil buffer.
render.SetStencilFailOperation(STENCILOPERATION_KEEP)
render.SetStencilZFailOperation(STENCILOPERATION_KEEP)
render.SetStencilPassOperation(STENCILOPERATION_REPLACE)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_ALWAYS)
render.SetStencilReferenceValue(1)
render.SuppressEngineLighting(true)
FT = FrameTime()
for _, ent in pairs(ents.GetAll()) do
if ent:IsNPC() or ent:IsPlayer() then
if not ent:IsEffectActive(EF_NODRAW) then -- since there is no proper way to check if the NPC is dead, we just check if the NPC has a nodraw effect on him
render.SuppressEngineLighting(true)
ent:DrawModel()
render.SuppressEngineLighting(false)
end
elseif ent:GetClass() == "class C_ClientRagdoll" then
if not ent.Int then
ent.Int = 1
else
ent.Int = math.Clamp(ent.Int - FT * 0.015, 0, 1)
end
render.SetColorModulation(ent.Int, ent.Int, ent.Int)
render.SuppressEngineLighting(true)
ent:DrawModel()
render.SuppressEngineLighting(false)
render.SetColorModulation(1, 1, 1)
end
end
render.SuppressEngineLighting(false)
render.SetStencilReferenceValue(2)
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
render.SetStencilReferenceValue(1)
DrawColorModify(Clr_FLIR_Ents)
render.SetStencilEnable( false )
Assistant
To suppress the lighting when a physgun halo appears, you can modify the XRayMat function that I previously provided. You'll update the rendering function to suppress the lighting and set the color modulation even when the physgun halo is active.
Here's the XRayMat function with the lighting suppression:
function XRayMatScene(entry)
cam.Start3D()
cam.IgnoreZ(entry.IgnoreZ)
render.SuppressEngineLighting(true) -- Add this line
render.SetColorModulation(1, 1, 1) -- Add this line
for _, ent in pairs(ents.GetAll()) do
if not ent:IsEffectActive(EF_NODRAW) and (ent:IsNPC() or ent:IsPlayer() or ent:GetClass() == "class C_ClientRagdoll") then
ent:DrawModel()
end
end
render.SuppressEngineLighting(false) -- Add this line
render.SetColorModulation(1, 1, 1) -- Add this line
cam.IgnoreZ(false)
cam.End3D()
end
With these changes, the lighting should be suppressed and the scene should render properly even when the physgun halo is active.
User
change this:
local function FLIR_FX()
if NV_Status == false then return end
if NV_Type == 2 then
render.ClearStencil()
render.SetStencilEnable(true)
render.SetStencilFailOperation(STENCILOPERATION_KEEP)
render.SetStencilZFailOperation(STENCILOPERATION_KEEP)
render.SetStencilPassOperation(STENCILOPERATION_REPLACE)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_ALWAYS)
render.SetStencilReferenceValue(1)
render.SuppressEngineLighting(true)
FT = FrameTime()
for _, ent in pairs(ents.GetAll()) do
if ent:IsNPC() or ent:IsPlayer() then
if not ent:IsEffectActive(EF_NODRAW) then -- since there is no proper way to check if the NPC is dead, we just check if the NPC has a nodraw effect on him
render.SuppressEngineLighting(true)
ent:DrawModel()
render.SuppressEngineLighting(false)
end
elseif ent:GetClass() == "class C_ClientRagdoll" then
if not ent.Int then
ent.Int = 1
else
ent.Int = math.Clamp(ent.Int - FT * 0.015, 0, 1)
end
render.SetColorModulation(ent.Int, ent.Int, ent.Int)
render.SuppressEngineLighting(true)
ent:DrawModel()
render.SuppressEngineLighting(false)
render.SetColorModulation(1, 1, 1)
end
end
render.SuppressEngineLighting(false)
render.SetStencilReferenceValue(2)
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
render.SetStencilReferenceValue(1)
DrawColorModify(Clr_FLIR_Ents)
render.SetStencilEnable( false )
end
Assistant
To ensure the lighting doesn't get too bright when the physgun halo appears, we need to use the previously provided RenderScene function to manage the rendering properly. Here's the updated FLIR_FX code:
local function FLIR_FX()
if NV_Status == false then return end
if NV_Type == 2 then
local entry = {
IgnoreZ = false,
}
local FT = FrameTime()
for _, ent in pairs(ents.GetAll()) do
if ent:IsNPC() or ent:IsPlayer() then
if not ent:IsEffectActive(EF_NODRAW) then
render.SuppressEngineLighting(true)
ent:DrawModel()
render.SuppressEngineLighting(false)
end
elseif ent:GetClass() == "class C_ClientRagdoll" then
if not ent.Int then
ent.Int = 1
else
ent.Int = math.Clamp(ent.Int - FT * 0.015, 0, 1)
end
render.SetColorModulation(ent.Int, ent.Int, ent.Int)
render.SuppressEngineLighting(true)
ent:DrawModel()
render.SuppressEngineLighting(false)
render.SetColorModulation(1, 1, 1)
end
end
-- Call RenderScene to avoid conflicts
RenderScene(entry, function()
render.ClearStencil()
render.SetStencilEnable(true)
render.SetStencilFailOperation(STENCILOPERATION_KEEP)
render.SetStencilZFailOperation(STENCILOPERATION_KEEP)
render.SetStencilPassOperation(STENCILOPERATION_REPLACE)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_ALWAYS)
render.SetStencilReferenceValue(1)
cam.Start3D()
for _, ent in pairs(ents.GetAll()) do
if ent:IsNPC() or ent:IsPlayer() or ent:GetClass() == "class C_ClientRagdoll" then
ent:DrawModel()
end
end
cam.End3D()
render.SetStencilReferenceValue(2)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_EQUAL)
render.SetStencilPassOperation(STENCILOPERATION_REPLACE)
render.SetStencilReferenceValue(1)
DrawColorModify(Clr_FLIR_Ents)
render.SetStencilEnable(false)
end)
end
end
hook.Remove("PostDrawOpaqueRenderables", "SF_NV_FLIRFX")
hook.Add("PostDrawOpaqueRenderables", "SF_NV_FLIRFX", FLIR_FX)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
hook.Run( "PreDrawHalos" )
if ( #List == 0 ) then return end
for k, v in ipairs( List ) do
Render( v )
end
List = {}
end )
Code 2:
local function FLIR_FX()
if NV_Status == false then return end
if NV_Type == 2 then
render.ClearStencil()
render.SetStencilEnable(true)
render.SetStencilFailOperation(STENCILOPERATION_KEEP)
render.SetStencilZFailOperation(STENCILOPERATION_KEEP)
render.SetStencilPassOperation(STENCILOPERATION_REPLACE)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_ALWAYS)
render.SetStencilReferenceValue(1)
render.SuppressEngineLighting(true)
FT = FrameTime()
for _, ent in pairs(ents.GetAll()) do
if ent:IsNPC() or ent:IsPlayer() then
if not ent:IsEffectActive(EF_NODRAW) then -- since there is no proper way to check if the NPC is dead, we just check if the NPC has a nodraw effect on him
render.SuppressEngineLighting(true)
ent:DrawModel()
render.SuppressEngineLighting(false)
end
elseif ent:GetClass() == "class C_ClientRagdoll" then
if not ent.Int then
ent.Int = 1
else
ent.Int = math.Clamp(ent.Int - FT * 0.015, 0, 1)
end
render.SetColorModulation(ent.Int, ent.Int, ent.Int)
render.SuppressEngineLighting(true)
ent:DrawModel()
render.SuppressEngineLighting(false)
render.SetColorModulation(1, 1, 1)
end
end
render.SuppressEngineLighting(false)
render.SetStencilReferenceValue(2)
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
render.SetStencilReferenceValue(1)
DrawColorModify(Clr_FLIR_Ents)
render.SetStencilEnable( false )
end
does code 1 conflict with code 2? how? how can i fix it? write me the fixed code.
Here is the modified code:
Code 1:
-- Replace the "Render" function with this version
function RenderScene( entry, func )
local oldStencilEnable = render.GetStencilEnable()
-- Store old stencil values
local oldStencilTestMask = render.GetStencilTestMask()
local oldStencilWriteMask = render.GetStencilWriteMask()
local oldStencilReferenceValue = render.GetStencilReferenceValue()
local oldStencilCompareFunction = render.GetStencilCompareFunction()
local oldStencilPassOperation = render.GetStencilPassOperation()
local oldStencilFailOperation = render.GetStencilFailOperation()
local oldStencilZFailOperation = render.GetStencilZFailOperation()
func( entry )
-- Restore old stencil values
render.SetStencilTestMask( oldStencilTestMask )
render.SetStencilWriteMask( oldStencilWriteMask )
render.SetStencilReferenceValue( oldStencilReferenceValue )
render.SetStencilCompareFunction( oldStencilCompareFunction )
render.SetStencilPassOperation( oldStencilPassOperation )
render.SetStencilFailOperation( oldStencilFailOperation )
render.SetStencilZFailOperation( oldStencilZFailOperation )
render.SetStencilEnable( oldStencilEnable )
end
-- Update "RenderHalos" hook to use "RenderScene"
hook.Add( "PostDrawEffects", "RenderHalos", function()
hook.Run( "PreDrawHalos" )
if ( #List == 0 ) then return end
for k, v in ipairs( List ) do
RenderScene( v, Render )
end
List = {}
end )
Code 2:
-- Update "SF_NV_FLIRFX" hook to use "RenderScene"
local function FLIR_FX()
if NV_Status == false then return end
if NV_Type == 2 then
RenderScene( {}, function()
-- Place original contents of FLIR_FX function here
end )
end
end
hook.Remove("PostDrawOpaqueRenderables", "SF_NV_FLIRFX")
hook.Add("PostDrawOpaqueRenderables", "SF_NV_FLIRFX", FLIR_FX)
By wrapping the rendering logic in the "RenderScene" function, the code encapsulates and separates the stencil settings of the two separate parts, preventing conflicts in their rendering behavior.
code 1:
local function FLIR_FX()
if NV_Status == false then return end
if NV_Type == 2 then
render.ClearStencil()
render.SetStencilEnable(true)
render.SetStencilFailOperation(STENCILOPERATION_KEEP)
render.SetStencilZFailOperation(STENCILOPERATION_KEEP)
render.SetStencilPassOperation(STENCILOPERATION_REPLACE)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_ALWAYS)
render.SetStencilReferenceValue(1)
render.SuppressEngineLighting(true)
FT = FrameTime()
for _, ent in pairs(ents.GetAll()) do
if ent:IsNPC() or ent:IsPlayer() then
if not ent:IsEffectActive(EF_NODRAW) then -- since there is no proper way to check if the NPC is dead, we just check if the NPC has a nodraw effect on him
render.SuppressEngineLighting(true)
ent:DrawModel()
render.SuppressEngineLighting(false)
end
elseif ent:GetClass() == "class C_ClientRagdoll" then
if not ent.Int then
ent.Int = 1
else
ent.Int = math.Clamp(ent.Int - FT * 0.015, 0, 1)
end
render.SetColorModulation(ent.Int, ent.Int, ent.Int)
render.SuppressEngineLighting(true)
ent:DrawModel()
render.SuppressEngineLighting(false)
render.SetColorModulation(1, 1, 1)
end
end
render.SuppressEngineLighting(false)
render.SetStencilReferenceValue(2)
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
render.SetStencilReferenceValue(1)
DrawColorModify(Clr_FLIR_Ents)
render.SetStencilEnable( false )
end
local function XRayMat()
if LocalPlayer().thermalflir then
for k,v in pairs( ents.GetAll() ) do
if string.sub( (v:GetModel() or "" ), -3) == "mdl" then -- only affect models
-- Inefficient, but not TOO laggy I hope
local r = v:GetColor().r
local g = v:GetColor().g
local b = v:GetColor().b
local a = v:GetColor().a
if (a > 0) then
local entmat = v:GetMaterial()
if v:IsNPC() or v:IsPlayer() then -- It's alive!
if not (r == 255 and g == 255 and b == 255 and a == 255) then -- Has our color been changed?
DefClrs[ v ] = Color( r, g, b, a ) -- Store it so we can change it back later
v:SetColor( 255, 255, 255, 255 ) -- Set it back to what it should be now
end
if entmat ~= "xray/living" then -- Has our material been changed?
DefMats[ v ] = entmat -- Store it so we can change it back later
v:SetMaterial( "xray/living" ) -- The xray matierals are designed to show through walls
end
else -- It's a prop or something
/*if not (r == 255 and g == 255 and b == 255 and a == 255) then
DefClrs[ v ] = Color( r, g, b, a )
v:SetColor( 255, 255, 255, 255 )
end */
if entmat ~= "xray/prop" then
DefMats[ v ] = entmat
v:SetMaterial( "xray/living" )
end
end
end
end
end
end
end
adapt code 2 to code 1 so it does not using the buffer stuff, because buffer confilict with the physgun halo.
like use code's 1 logic and code's 2 technicque of applying materials and using render scene
Code 2:
local function XRayMat()
if not LocalPlayer().thermalflir then return end
local entry = {
IgnoreZ = true,
}
for _, ent in pairs(ents.GetAll()) do
if string.sub((ent:GetModel() or ""), -3) == "mdl" then -- only affect models
local r, g, b, a = ent:GetColor().r, ent:GetColor().g, ent:GetColor().b, ent:GetColor().a
if (a > 0) then
local entmat = ent:GetMaterial()
if ent:IsNPC() or ent:IsPlayer() then -- It's alive!
if not (r == 255 and g == 255 and b == 255 and a == 255) then -- Has our color been changed?
DefClrs[ent] = Color(r, g, b, a)
ent:SetColor(255, 255, 255, 255)
end
if entmat ~= "xray/living" then -- Has our material been changed?
DefMats[ent] = entmat
ent:SetMaterial("xray/living")
end
else -- It's a prop or something
if entmat ~= "xray/prop" then
DefMats[ent] = entmat
ent:SetMaterial("xray/living")
end
end
end
end
end
-- Call RenderScene from Code 1 to avoid conflicts
RenderScene(entry, function()
cam.Start3D()
cam.IgnoreZ(entry.IgnoreZ)
for _, ent in pairs(ents.GetAll()) do
if not ent:IsEffectActive(EF_NODRAW) and (ent:IsNPC() or ent:IsPlayer() or ent:GetClass() == "class C_ClientRagdoll") then
ent:DrawModel()
end
end
cam.IgnoreZ(false)
cam.End3D()
end)
-- Reset materials
for ent, mat in pairs(DefMats) do
ent:SetMaterial(mat)
end
for ent, clr in pairs(DefClrs) do
ent:SetColor(clr)
end
end
hook.Remove("PostDrawOpaqueRenderables", "SF_NV_XRayMat")
hook.Add("PostDrawOpaqueRenderables", "SF_NV_XRayMat", XRayMat)
In the modified code, we use Code 1's RenderScene function to draw the entities with the materials applied. The materials and colors are restored after the rendering is done to avoid global changes.
Now, Code 2 should work without conflicts with the physgun halo as it does not use the stencil buffer directly.
Code 1:
function XRayMatScene(entry)
cam.Start3D()
cam.IgnoreZ(entry.IgnoreZ)
for _, ent in pairs(ents.GetAll()) do
if not ent:IsEffectActive(EF_NODRAW) and (ent:IsNPC() or ent:IsPlayer() or ent:GetClass() == "class C_ClientRagdoll") then
ent:DrawModel()
end
end
cam.IgnoreZ(false)
cam.End3D()
end
local function XRayMat()
if not LocalPlayer().thermalflir then return end
local entry = {
IgnoreZ = true,
}
for _, ent in pairs(ents.GetAll()) do
if string.sub((ent:GetModel() or ""), -3) == "mdl" then -- only affect models
local r, g, b, a = ent:GetColor().r, ent:GetColor().g, ent:GetColor().b, ent:GetColor().a
if (a > 0) then
local entmat = ent:GetMaterial()
if ent:IsNPC() or ent:IsPlayer() then -- It's alive!
if not (r == 255 and g == 255 and b == 255 and a == 255) then -- Has our color been changed?
DefClrs[ent] = Color(r, g, b, a)
ent:SetColor(255, 255, 255, 255)
end
if entmat ~= "xray/living" then -- Has our material been changed?
DefMats[ent] = entmat
ent:SetMaterial("xray/living")
end
else -- It's a prop or something
if entmat ~= "xray/prop" then
DefMats[ent] = entmat
ent:SetMaterial("xray/living")
end
end
end
end
end
-- Call RenderScene to avoid conflicts
RenderScene(entry, XRayMatScene)
-- Reset materials
for ent, mat in pairs(DefMats) do
ent:SetMaterial(mat)
end
for ent, clr in pairs(DefClrs) do
ent:SetColor(clr)
end
end
hook.Remove("PostDrawOpaqueRenderables", "SF_NV_XRayMat")
hook.Add("PostDrawOpaqueRenderables", "SF_NV_XRayMat", XRayMat)
This code uses the RenderScene function from the original Code 1 and the XRayMat function from Code 2. The materials are applied to the entities within the XRayMat function and the rendering is performed using Code 1's RenderScene to avoid conflicts with the physgun halo. The materials and colors are reset after the rendering is completed.
i want to supress the lighting but when a physgun halo apears the lighting doesn't get supressed and it get's all bright