Jump to content

ClearPostEffects() making graphics go crazy.


lxFirebal69xl
 Share

Recommended Posts

So, when the player gets below a certain amount of health this happens:

 

if self.health < 50 then
  self.camera:AddPostEffect("Shaders/PostEffects/radiation.shader")
 end

 

Calls a simple shader to the camera, and this works without issues. Now the thing is, I made this function.

 

function Script:CameraFix()
if self.health > 50 then
self.camera:ClearPostEffects()
end
end

 

Which gets called every time the player picks up a health item in the game.

 

Here's a video demonstrating what happens when I grab a health item and the CameraFix() is called.

Link to comment
Share on other sites

Is that radiation post effect only being added once or is it being added multiple times when the player health is below 50? Just curious because the code above implies you are constantly adding the same effect to the camera effect stack.

 

Not quite sure why CleatPostEffects() is causing the scene to bleed but you could try to use the RemovePostEffect() command. Assuming you are only adding this one post effect to the stack then you could remove it via its number in the stack.

self.camera:RemovePostEffect(0)

 

Looking at this now - it would be helpful if Josh gave us a way to count the number of post effects in the stack. Something like 'camera:CountPostEffects()'?

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Is that radiation post effect only being added once or is it being added multiple times when the player health is below 50? Just curious because the code above implies you are constantly adding the same effect to the camera effect stack.

 

Not quite sure why CleatPostEffects() is causing the scene to bleed but you could try to use the RemovePostEffect() command. Assuming you are only adding this one post effect to the stack then you could remove it via its number in the stack.

self.camera:RemovePostEffect(0)

 

Looking at this now - it would be helpful if Josh gave us a way to count the number of post effects in the stack. Something like 'camera:CountPostEffects()'?

 

Using the

self.camera:RemovePostEffect(0)

 

Does indeed fix the issue, but doesn't remove the radiation post effect, so I guess I'm calling it multiple times, don't know how though since this

 

if self.health < 50 then
  self.camera:AddPostEffect("Shaders/PostEffects/radiation.shader")
 end

 

 

Only gets called when the player is hurt, aka in the Hurt() function.

Link to comment
Share on other sites

Medkit script:

 

Script.health = 50.0 --float "Health"
Script.useOnce = true --bool "Use once"
Script.ObjectDescription = "I'm not hurt." --string "Object Description"
Script.enabled = true --bool "Enabled"
Script.soundfile=""--path "Sound" "Wav Files (*.wav):wav"
local font1 = Font:Load("Fonts/MODERN SERIF ERODED.ttf", 20)
function Script:Start()
if self.soundfile then
 self.sound = Sound:Load(self.soundfile)
end
if  self.health < 0 then

 error ("Health can't be a negative value.")
end
end
function Script:Use(player)
if player.health < player.maxHealth then
self.enabled = false
if self.sound then self.sound:Play() end
player.health = self.health + player.health
player:CameraFix()
 if self.useOnce then
  self.entity:Release()
 end
elseif self.enabled == true then
self.component:CallOutputs("Use")
self.ObjectDescription = "Much better now."
self:GetText()
end
end

function Script:GetText()
if self.enabled == true then
return self.ObjectDescription
end
end
function Script:Enable()--in
self.DisplayEnabled=true
end
function Script:Disable()--in
self.DisplayEnabled=false
end

 

Hurt script:

 

function Script:Hurt(damage,distributorOfPain)
    if self.health>0 then
		    self.sound.damage[math.random(#self.sound.damage)]:Play()
		    self.health = self.health - damage
		    self.hurtoffset = Vec3(math.random(-1,1),math.random(-1,1),0):Normalize()*30
		    local blood = {}
		    local n=1
		    blood.texture=self.image.blood[math.random(1,4)]
		    blood.intensity=1
		    table.insert(self.bloodoverlay,blood)		 
		    if self.bloodindex>4 then self.bloodindex=1 end
		    if self.health<=0 then
				    self:Kill()
		    end
    end

 if self.health < 50 then
  self.camera:AddPostEffect("Shaders/PostEffects/radiation.shader")
 end
end

 

Code that is called when medkit is used:

 

function Script:CameraFix()
if self.health > 50 then
self.camera:RemovePostEffect(0)
end
end

Link to comment
Share on other sites

If the hurt function is being driven by a collision then it probably is being added multiple times. A system print would determine this. But the code you are showing will mean the same effect would be added each time the Hurt function is called and the player health is below 50. You need to add a boolean check to see if the post effect has already been added and to prevent it from being added multiple times.

 

if self.health<50 and self.postadded=="false" then

self.camera:AddPostEffect("Shaders/PostEffects/radiation.shader")

self.postadded = true

end

 

function Script:CameraFix()

if self.health>50 and self.postadded=="true" then

self.camera:RemovePostEffect(0)

self.postadded = "false"

end

end

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

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...