Page 1 of 1

Freelook aware shader

PostPosted: Tue Dec 19, 2017 8:47 pm
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 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?

Re: Freelook aware shader

PostPosted: Wed Dec 20, 2017 1:40 am
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); }

Re: Freelook aware shader

PostPosted: Wed Dec 20, 2017 4:21 am
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.

Re: Freelook aware shader

PostPosted: Wed Dec 20, 2017 9:28 am
by Kotti
Do not use PlayerInfo.mo for rendering, but PlayerInfo.camera. This is the actual camera actor in use.

Re: Freelook aware shader

PostPosted: Wed Dec 20, 2017 4:18 pm
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-)

Re: Freelook aware shader

PostPosted: Thu Dec 21, 2017 6:07 pm
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

Re: Freelook aware shader

PostPosted: Fri Dec 22, 2017 3:02 pm
by Nash
AWESOME!

Re: Freelook aware shader

PostPosted: Mon Dec 25, 2017 11:14 pm
by Dark Pulse
Wow, keep this up. This would add a lot of ambiance to water-heavy maps. :)

Re: Freelook aware shader

PostPosted: Tue Dec 26, 2017 2:12 am
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

Re: Freelook aware shader

PostPosted: Thu Dec 28, 2017 8:20 am
by Nash
When can we test this?! :D :D :D

Re: Freelook aware shader

PostPosted: Thu Dec 28, 2017 10:32 am
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 ¬¬

Re: Freelook aware shader

PostPosted: Thu Dec 28, 2017 6:05 pm
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?

Re: Freelook aware shader

PostPosted: Wed Jan 03, 2018 5:26 pm
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: