Jump to content

changing state of post-process shader by code


Christian Clavet
 Share

Recommended Posts

Hi! Is there a method (preferably LUA if possible) to enable/disable some of the post-process shaders that are used in a map. I don't seem to find something that is related to that in documentation.

I would like to use that so that in the settings menu, I could offer a way to disable/enable "FX's" to keep game performance on lower end hardware...

Link to comment
Share on other sites

  • 2 years later...
On 7/9/2017 at 7:28 PM, Christian Clavet said:

Thanks. Exactly what I was looking for!

I'm new in LUA, im trying to do this. Any tip i can follow to code ENABLE/DISABLE Shaders. I'm trying enable/disable WOBBLE.SHADER when i go out of water or underwater.

I have readed gamecreator link about entity camera:

On 7/9/2017 at 7:25 PM, gamecreator said:

You can use the camera functions like AddPostEffect and ClearPostEffects.  I don't code Lua but it should work there too.
https://www.leadwerks.com/learn.php?page=API-Reference_Object_Entity_Camera

 

And i tried  encoding myself script with AddPostEffect command, but i don't know how use it.

Any tip or code example to see the sintax???

Thank you very much.

Link to comment
Share on other sites

1 hour ago, Josh said:

It would be like camera:AddPostEffect("Shaders/PostEffects/nameofshader.shader")

Thanks for your answer Josh. But my problem is how encode that line in a Script. If I write that command in my own script appears error of nil value.

My case using the flowgraph is this:

I've got a box (called Trigger_EnableDisableWobble) with texture Trigger, with Physics Trigger and Script collision trigger.lua.

How and where can I encode the line addposteffect when our character touches the trigger to add that shader?

Thanks for help.

Link to comment
Share on other sites

3 hours ago, Josh said:

Well, you need a variable where your camera is. What script is in this? Can you post some of your code?

I don't have any camera on the map. Only de FPSPlayer.prefab of our character.

This is my code for CollisionTrigger... Is the default of Leadwerks...

function Script:Start()
	self.enabled=true
end

function Script:Collision(entity, position, normal, speed)
	if self.enabled then
		self.component:CallOutputs("Collision")
	end
end

function Script:Enable()--in
	if self.enabled==false then
		self.enabled=true
		--self:CallOutputs("Enable")
	end
end

function Script:Disable()--in
	if self.enabled then
		self.enabled=false
		--self:CallOutputs("Disable")
	end
end

Any hint of how encode camera:AddPostEffect line???

I have tried this:

function Script:Collision(entity, position, normal, speed)
	if self.enabled then
		self.component:CallOutputs("Collision")
		self.camera:AddPostEffect("Shaders/PostEffects/wobble.shader")
	end
end

And in have tried this too in the same script:

function Script:Render(camera, context, buffer, depthtexture, diffusetexture, normaltexture)
	camera:AddPostEffect("Shaders/PostEffects/wobble.shader")
end

It doesn't work...

I don't know how encode this...

Link to comment
Share on other sites

Without having tried it, I think you need something like this:

function Script:Collision(entity, position, normal, speed)
	if self.enabled then
		if entity.script ~= nil then
			if entity.script.camera ~= nil then
				entity.script.camera:AddPostEffect("Shaders/PostEffects/wobble.shader")
		        self.enabled = false
			end
		end
	end
end

 

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

2 hours ago, Josh said:

Without having tried it, I think you need something like this:


function Script:Collision(entity, position, normal, speed)
	if self.enabled then
		if entity.script ~= nil then
			if entity.script.camera ~= nil then
				entity.script.camera:AddPostEffect("Shaders/PostEffects/wobble.shader")
		        self.enabled = false
			end
		end
	end
end

  

I will say something that many people will tell you in the forum:
"I love you Josh!! I love you buddy!!"

It works!! Thank you very much!!

You have saved my day

  • Haha 1
Link to comment
Share on other sites

3 hours ago, Josh said:

Without having tried it, I think you need something like this: 


function Script:Collision(entity, position, normal, speed)
	if self.enabled then
		if entity.script ~= nil then
			if entity.script.camera ~= nil then
				entity.script.camera:AddPostEffect("Shaders/PostEffects/wobble.shader")
		        self.enabled = false
			end
		end
	end
end

 

I have now 2 collisions scripts differents for the Water area. One for ENABLE (thanks @Josh) wobble.shader effect, and another one for DISABLE it with ClearPostEffects()

This is the result:

Many thanks team!!

Im very newbie with LUA, and sometimes one simple line of code takes me a long time to achieve my objetive.

  • Like 2
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...