[RESOLVED] Apply shader when shooting weapon?

Ask about editing graphics, sounds, models, music, etc here!
Shaders (GLSL) and SNDINFO questions also go here!

Moderators: GZDoom Developers, Raze Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
User avatar
Numnzel
Posts: 161
Joined: Wed Jul 18, 2012 6:17 pm
Location: Empty space

[RESOLVED] Apply shader when shooting weapon?

Post by Numnzel »

Hello.
As the title says, I'm trying to apply a shader when I shoot a weapon, there is any way to do it?

EDIT: I should say that it's a screen shader.
I don't understand this subject so much, so it may be relevant.

This is the shader code:
Spoiler:
Thank you.
Last edited by Numnzel on Mon Apr 27, 2020 9:03 am, edited 1 time in total.
User avatar
Cherno
Posts: 1336
Joined: Tue Dec 06, 2016 11:25 am

Re: Apply shader when shooting weapon?

Post by Cherno »

The only way I could think of is to have seperate MODELDEF entries, so the shooting frames can have different skins, and only those skins have the shader aplied via GLDEFS.
User avatar
Numnzel
Posts: 161
Joined: Wed Jul 18, 2012 6:17 pm
Location: Empty space

Re: Apply shader when shooting weapon?

Post by Numnzel »

Sorry, I'm not sure if I explained it correctly.

I'm actually not using models, and it's not a shader for a weapon, it's a GLSL shader that it's applied on the entire screen. And I want to use it as an effect after shooting a weapon.
User avatar
MFG38
Posts: 414
Joined: Sun Apr 14, 2019 8:26 am
Graphics Processor: nVidia (Modern GZDoom)
Location: Finland

Re: Apply shader when shooting weapon?

Post by MFG38 »

If your weapon code is in ZScript, you'll need to write a custom function that enables the shader upon firing the weapon and attach it to the weapon's Fire state. The documentation regarding using shaders in ZScript is unfortunately rather lacking - you'll basically have to look at other people's shaders to learn how it works.

This snippet from GZDoom's base.zs should be of some help, though:

Code: Select all

struct Shader native
{
	native clearscope static void SetEnabled(PlayerInfo player, string shaderName, bool enable);
	native clearscope static void SetUniform1f(PlayerInfo player, string shaderName, string uniformName, float value);
	native clearscope static void SetUniform2f(PlayerInfo player, string shaderName, string uniformName, vector2 value);
	native clearscope static void SetUniform3f(PlayerInfo player, string shaderName, string uniformName, vector3 value);
	native clearscope static void SetUniform1i(PlayerInfo player, string shaderName, string uniformName, int value);
}
User avatar
Numnzel
Posts: 161
Joined: Wed Jul 18, 2012 6:17 pm
Location: Empty space

Re: Apply shader when shooting weapon?

Post by Numnzel »

Thanks, I actually did it!

This is the code I used to call the shader and animate it, and then reseting it, for it may help someone else:

Zscript:
Spoiler:
GLDefs:
Spoiler:
Shader:
Spoiler:
Although it is unfinished, if someone uses this code please don't forget to acknowledge me and my friend Bélsel, who helped me with the algorithm.
Thank you both for your time.

Return to “Assets (and other stuff)”