Jump to content

how to remove an single post effect from the camera


Andy90
 Share

Go to solution Solved by Josh,

Recommended Posts

Here is my effect manager script. It's really simple to use. Just create a pivot in your map and add the script. Then assign your camera to the script.

Script.effects = {}
Script.camera = nil --Entity "Camera";

function Script:Start()
	self:AddEffect("bloom", "Shaders/PostEffects/bloom.lua", true)
	self:AddEffect("ssao", "Shaders/PostEffects/ssao.shader", true)
	self:AddEffect("godrays", "Shaders/PostEffects/godrays.lua", true)
	self:AddEffect("grayscale", "Shaders/PostEffects/grayscale.shader", false)
	self:BuildEffectChain()
end

--Adds a new effect to the effect chain
function Script:AddEffect(name, file, enabled)
	local effect = {
		name = name,
		file = file,
		enabled = enabled
	}
	table.insert(self.effects, effect)
	if enabled then
		self:BuildEffectChain()
	end
	return #self.effects + 1
end

--Disables the effect at position n
function Script:DisableEffect(index)
	if self.effects[index].enabled == true then
		self.effects[index].enabled = false
		self:BuildEffectChain()
	end
end

--Enables the effect at position n
function Script:EnableEffect(index)
	if self.effects[index].enabled == false then
		self.effects[index].enabled = true
		self:BuildEffectChain()
	end
end

--Returns the effect index with the given name
function Script:GetEffectIndex(name)
	for i, item in ipairs(self.effects) do
		if item.name == name then
			return i
		end
	end
end

--Returns the effect with the given name (untested)
function Script:GetEffect(name)
	local effectIndex = self:GetEffectIndex(name);
	return self.effects[effectIndex];
end

-- Rebuils the effect chain
function Script:BuildEffectChain()
	self.camera:ClearPostEffects()
	for i, item in ipairs(self.effects) do
		if item.enabled then
			self.camera:AddPostEffect(item.file)
		end
	end
end

You can call the functions from the script when you assign the pivot as the entity. For example:

image.png.12071d884b0c375e6d17565849deb312.png

and use

local effectIndex = self.effectManager.script:GetEffectIndex("grayscale");
self.effectManager.script:DisableEffect(effectIndex);
  • Like 3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...