From 64f4332b43527ddb642da486d487e28f4958e466 Mon Sep 17 00:00:00 2001
From: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date: Thu, 20 Jan 2022 13:30:23 -0500
Subject: [PATCH 1/3] - add cmath includes to fix the mac compile std::floor
 errors

---
 src/maploader/maploader.cpp                       | 1 +
 src/rendering/hwrenderer/scene/hw_spritelight.cpp | 1 +
 2 files changed, 2 insertions(+)

diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp
index 14174a8cd2..a0ef9991b5 100644
--- a/src/maploader/maploader.cpp
+++ b/src/maploader/maploader.cpp
@@ -59,6 +59,7 @@
 
 
 #include <math.h>
+#include <cmath>	// needed for std::floor on mac
 #include "maploader.h"
 #include "c_cvars.h"
 #include "actor.h"
diff --git a/src/rendering/hwrenderer/scene/hw_spritelight.cpp b/src/rendering/hwrenderer/scene/hw_spritelight.cpp
index 71b4868882..8f24499941 100644
--- a/src/rendering/hwrenderer/scene/hw_spritelight.cpp
+++ b/src/rendering/hwrenderer/scene/hw_spritelight.cpp
@@ -37,6 +37,7 @@
 #include "hwrenderer/scene/hw_drawinfo.h"
 #include "hwrenderer/scene/hw_drawstructs.h"
 #include "models.h"
+#include <cmath>	// needed for std::floor on mac
 
 template<class T>
 T smoothstep(const T edge0, const T edge1, const T x)

From 4c4fafc2c081dd1a9300424985772fdabf5cb1d1 Mon Sep 17 00:00:00 2001
From: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date: Thu, 20 Jan 2022 22:38:46 -0500
Subject: [PATCH 2/3] - add debug ccmds to manipulate custom postprocess
 shaders and their uniforms from the console

---
 src/CMakeLists.txt                            |   1 +
 .../hw_postprocessshader_ccmds.cpp            | 136 ++++++++++++++++++
 2 files changed, 137 insertions(+)
 create mode 100644 src/common/rendering/hwrenderer/postprocessing/hw_postprocessshader_ccmds.cpp

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 13db4da542..f5fe0a5aae 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1154,6 +1154,7 @@ set (PCH_SOURCES
 	common/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp
 	common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp
 	common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp
+	common/rendering/hwrenderer/postprocessing/hw_postprocessshader_ccmds.cpp
 	common/rendering/gl_load/gl_interface.cpp
 	common/rendering/gl/gl_renderer.cpp
 	common/rendering/gl/gl_stereo3d.cpp
diff --git a/src/common/rendering/hwrenderer/postprocessing/hw_postprocessshader_ccmds.cpp b/src/common/rendering/hwrenderer/postprocessing/hw_postprocessshader_ccmds.cpp
new file mode 100644
index 0000000000..4608b9ce96
--- /dev/null
+++ b/src/common/rendering/hwrenderer/postprocessing/hw_postprocessshader_ccmds.cpp
@@ -0,0 +1,136 @@
+/*
+**  Debug ccmds for post-process shaders
+**  Copyright (c) 2022 Rachael Alexanderson
+**
+**  This software is provided 'as-is', without any express or implied
+**  warranty.  In no event will the authors be held liable for any damages
+**  arising from the use of this software.
+**
+**  Permission is granted to anyone to use this software for any purpose,
+**  including commercial applications, and to alter it and redistribute it
+**  freely, subject to the following restrictions:
+**
+**  1. The origin of this software must not be misrepresented; you must not
+**     claim that you wrote the original software. If you use this software
+**     in a product, an acknowledgment in the product documentation would be
+**     appreciated but is not required.
+**  2. Altered source versions must be plainly marked as such, and must not be
+**     misrepresented as being the original software.
+**  3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "hwrenderer/postprocessing/hw_postprocessshader.h"
+#include "hwrenderer/postprocessing/hw_postprocess.h"
+#include "printf.h"
+#include "c_dispatch.h"
+
+CCMD (shaderenable)
+{
+	if (argv.argc() < 3)
+	{
+		Printf("Usage: shaderenable [name] [1/0/-1]\nState '-1' toggles the active shader state\n");
+		return;
+	}
+	auto shaderName = argv[1];
+
+	int value = atoi(argv[2]);
+
+	bool found = 0;
+	for (unsigned int i = 0; i < PostProcessShaders.Size(); i++)
+	{
+		PostProcessShader &shader = PostProcessShaders[i];
+		if (strcmp(shader.Name, shaderName) == 0)
+		{
+			if (value != -1)
+				shader.Enabled = value;
+			else
+				shader.Enabled = !shader.Enabled; //toggle
+			found = 1;
+		}
+	}
+	if (found && value != -1)
+		Printf("Changed active state of all instances of %s to %s\n", shaderName, value?"On":"Off");
+	else if (found)
+		Printf("Toggled active state of all instances of %s\n", shaderName);
+	else
+		Printf("No shader named '%s' found\n", shaderName);
+}
+
+CCMD (shaderuniform)
+{
+	if (argv.argc() < 3)
+	{
+		Printf("Usage: shaderuniform [shader name] [uniform name] [[value1 ..]]\n");
+		return;
+	}
+	auto shaderName = argv[1];
+	auto uniformName = argv[2];
+
+	bool found = 0;
+	for (unsigned int i = 0; i < PostProcessShaders.Size(); i++)
+	{
+		PostProcessShader &shader = PostProcessShaders[i];
+		if (strcmp(shader.Name, shaderName) == 0)
+		{
+			if (argv.argc() > 3)
+			{
+				double *vec4 = shader.Uniforms[uniformName].Values;
+				vec4[0] = argv.argc()>=4 ? atof(argv[3]) : 0.0;
+				vec4[1] = argv.argc()>=5 ? atof(argv[4]) : 0.0;
+				vec4[2] = argv.argc()>=6 ? atof(argv[5]) : 0.0;
+				vec4[3] = 1.0;
+			}
+			else
+			{
+				double *vec4 = shader.Uniforms[uniformName].Values;
+				Printf("Shader '%s' uniform '%s': %f %f %f\n", shaderName, uniformName, vec4[0], vec4[1], vec4[2]);
+			}
+			found = 1;
+		}
+	}
+	if (found && argv.argc() > 3)
+		Printf("Changed uniforms of %s named %s\n", shaderName, uniformName);
+	else if (!found)
+		Printf("No shader named '%s' found\n", shaderName);
+}
+
+CCMD(listshaders)
+{
+	for (unsigned int i = 0; i < PostProcessShaders.Size(); i++)
+	{
+		PostProcessShader &shader = PostProcessShaders[i];
+		Printf("Shader (%i): %s\n", i, shader.Name.GetChars());
+	}
+}
+
+CCMD(listuniforms)
+{
+	if (argv.argc() < 2)
+	{
+		Printf("Usage: listuniforms [name]\n");
+		return;
+	}
+	auto shaderName = argv[1];
+
+	bool found = 0;
+	for (unsigned int i = 0; i < PostProcessShaders.Size(); i++)
+	{
+		PostProcessShader &shader = PostProcessShaders[i];
+		if (strcmp(shader.Name, shaderName) == 0)
+		{
+			Printf("Shader '%s' uniforms:\n", shaderName);
+
+			decltype(shader.Uniforms)::Iterator it(shader.Uniforms);
+			decltype(shader.Uniforms)::Pair* pair;
+
+			while (it.NextPair(pair))
+			{
+				double *vec4 = shader.Uniforms[pair->Key].Values;
+				Printf("  %s : %f %f %f\n", pair->Key.GetChars(), vec4[0], vec4[1], vec4[2]);
+			}
+			found = 1;
+		}
+	}
+	if (!found)
+		Printf("No shader named '%s' found\n", shaderName);
+}

From 2ab4539d406a41abe6a6cdbdde6be7fffee26d78 Mon Sep 17 00:00:00 2001
From: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date: Fri, 21 Jan 2022 16:40:04 -0500
Subject: [PATCH 3/3] - fix logic error with shader compatibility layer

---
 wadsrc/static/zscript/doombase.zs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/wadsrc/static/zscript/doombase.zs b/wadsrc/static/zscript/doombase.zs
index 07245d3ac1..f1190cea86 100644
--- a/wadsrc/static/zscript/doombase.zs
+++ b/wadsrc/static/zscript/doombase.zs
@@ -704,7 +704,7 @@ struct Shader native
 	// This interface was deprecated for the pointless player dependency 
 	private static bool IsConsolePlayer(PlayerInfo player)
 	{
-		return player && !player.mo && player == players[consoleplayer];
+		return player && player.mo && player == players[consoleplayer];
 	}
 	deprecated("4.8", "Use PPShader.SetEnabled() instead") clearscope static void SetEnabled(PlayerInfo player, string shaderName, bool enable)
 	{