Freelook aware shader

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom 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.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Freelook aware shader

Post by Pixel Eater »

I'm having a go at making scene reflections on water surfaces and the shader needs to know what the mouse is doing.

I've tried this in zscript.zc:

Code: Select all

version "2.5"

class mirrormireHandler : EventHandler
{
	PlayerInfo p;
	override void UiTick()
	{
		if (p)
			if (Cvar.GetCVar("gl_mirrormire", p).GetInt())
			{
				Shader.SetUniform1f(p, "MirrorMire", "pitch", GetActorPitch(0));
				Shader.SetEnabled(p, "MirrorMire", true);
			}
			else
			{
				Shader.SetEnabled(p, "MirrorMire", false);
			}
	}
	override void PlayerEntered(PlayerEvent e)
	{
		p = players[e.PlayerNumber];
	}
}
And get this error: Call to unknown function 'GetActorPitch'

Any ideas what else I need to do to get that to work?
User avatar
Nash
 
 
Posts: 17436
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Freelook aware shader

Post by Nash »

You'll need to get the player's Actor or Map Object - p.mo - and then read the "pitch" variable directly from it.

let mo = p.mo;
if (mo) { Shader.SetUniform1f(p, "MirrorMire", "pitch", mo.pitch); }
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: Freelook aware shader

Post by Gutawer »

That won't be accurate enough for a smooth shader (since mo.pitch will change per-tick, not per-frame). What you really wanna do is override RenderOverlay and use e.viewPitch. That's the pitch that GZDoom will use when rendering that frame, and so it takes into account mouse movements in-between ticks.
Also, by the way, the thing you're using to get the PlayerInfo won't be multiplayer-safe. You really wanna use players[consoleplayer] - in ui functions, consoleplayer refers to the player number that is being rendered from.
Kotti
Posts: 86
Joined: Tue Dec 27, 2016 4:08 am

Re: Freelook aware shader

Post by Kotti »

Do not use PlayerInfo.mo for rendering, but PlayerInfo.camera. This is the actual camera actor in use.
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: Freelook aware shader

Post by Pixel Eater »

Wow, I didn't realise there'd be so many ways to do it! I'll have a play later and see what I can come up with 8-)
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: Freelook aware shader

Post by Pixel Eater »

I've managed to get it working but it's pretty glitchy (still struggling with the mouse pitch stuff). This is how it looks so far:
grab.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
Nash
 
 
Posts: 17436
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Freelook aware shader

Post by Nash »

AWESOME!
User avatar
Dark Pulse
Posts: 66
Joined: Fri Nov 21, 2014 5:35 pm
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support

Re: Freelook aware shader

Post by Dark Pulse »

Wow, keep this up. This would add a lot of ambiance to water-heavy maps. :)
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: Freelook aware shader

Post by Pixel Eater »

Thanks Nash :)
Wow, keep this up. This would add a lot of ambiance to water-heavy maps. :)
I intend to! At the moment this idea is branching into two possibilities- one version (the previous screenshot) that is just for effect but is hardly accurate and a more three dimensional one that will be slower:
Grab2.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
Nash
 
 
Posts: 17436
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Freelook aware shader

Post by Nash »

When can we test this?! :D :D :D
User avatar
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm

Re: Freelook aware shader

Post by ibm5155 »

Uh no more need for workarouds for making this kind of effect with 3D floors \o/
Shame it'll take ages for zandronum to support it ¬¬
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: Freelook aware shader

Post by Pixel Eater »

Nash, if you like you can join GiveOneMoreChance as a co-developer. Actually it would be great to have another person take a stab at the alternate CPU intensive version. I was going to wait until the current one worked before looking at it again...

ibm5155, I'm guessing that doesn't work with vanilla levels though?
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: Freelook aware shader

Post by Pixel Eater »

Just a heads up- GiveOneMoreChance and I have managed to get a version of Mirror Mire that's fit for human/demon consumption! There's always room for improvement but it's at least functional now :mrgreen:

Return to “Scripting”