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.

Freelook aware shader

Postby Pixel Eater » Tue Dec 19, 2017 8:47 pm

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 allExpand view
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
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Freelook aware shader

Postby Nash » Wed Dec 20, 2017 1:40 am

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
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: Freelook aware shader

Postby Gutawer » Wed Dec 20, 2017 4:21 am

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.
User avatar
Gutawer
User Accounts Assistant
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

Re: Freelook aware shader

Postby Kotti » Wed Dec 20, 2017 9:28 am

Do not use PlayerInfo.mo for rendering, but PlayerInfo.camera. This is the actual camera actor in use.
Kotti
 
Joined: 27 Dec 2016

Re: Freelook aware shader

Postby Pixel Eater » Wed Dec 20, 2017 4:18 pm

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
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Freelook aware shader

Postby Pixel Eater » Thu Dec 21, 2017 6:07 pm

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
User avatar
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Freelook aware shader

Postby Nash » Fri Dec 22, 2017 3:02 pm

AWESOME!
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: Freelook aware shader

Postby Dark Pulse » Mon Dec 25, 2017 11:14 pm

Wow, keep this up. This would add a lot of ambiance to water-heavy maps. :)
User avatar
Dark Pulse
Should I be happy or miserable that I enjoyed SNES Doom? What about PS1 Hexen?
 
Joined: 21 Nov 2014

Re: Freelook aware shader

Postby Pixel Eater » Tue Dec 26, 2017 2:12 am

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
User avatar
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Freelook aware shader

Postby Nash » Thu Dec 28, 2017 8:20 am

When can we test this?! :D :D :D
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: Freelook aware shader

Postby ibm5155 » Thu Dec 28, 2017 10:32 am

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
ibm5155
Just Spooky
 
Joined: 20 Jul 2011

Re: Freelook aware shader

Postby Pixel Eater » Thu Dec 28, 2017 6:05 pm

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
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Freelook aware shader

Postby Pixel Eater » Wed Jan 03, 2018 5:26 pm

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:
User avatar
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.


Return to Scripting

Who is online

Users browsing this forum: SanyaWaffles and 2 guests