diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7b77d97d0..13db4da54 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -937,7 +937,6 @@ set (PCH_SOURCES rendering/hwrenderer/hw_vertexbuilder.cpp rendering/hwrenderer/doom_aabbtree.cpp rendering/hwrenderer/hw_models.cpp - rendering/hwrenderer/hw_postprocessshader.cpp rendering/hwrenderer/hw_precache.cpp rendering/hwrenderer/scene/hw_lighting.cpp rendering/hwrenderer/scene/hw_drawlistadd.cpp @@ -1152,6 +1151,7 @@ set (PCH_SOURCES common/rendering/hwrenderer/data/hw_aabbtree.cpp common/rendering/hwrenderer/data/hw_shadowmap.cpp common/rendering/hwrenderer/data/hw_shaderpatcher.cpp + common/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp common/rendering/gl_load/gl_interface.cpp diff --git a/src/common/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp b/src/common/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp new file mode 100644 index 000000000..f23d4497f --- /dev/null +++ b/src/common/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp @@ -0,0 +1,139 @@ +/* +** Postprocessing framework +** Copyright (c) 2016-2020 Magnus Norddahl +** +** 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 "vm.h" +#include "hwrenderer/postprocessing/hw_postprocessshader.h" +#include "hwrenderer/postprocessing/hw_postprocess.h" + +static void ShaderSetEnabled(const FString &shaderName, bool value) +{ + for (unsigned int i = 0; i < PostProcessShaders.Size(); i++) + { + PostProcessShader &shader = PostProcessShaders[i]; + if (shader.Name == shaderName) + shader.Enabled = value; + } +} + +DEFINE_ACTION_FUNCTION_NATIVE(_PPShader, SetEnabled, ShaderSetEnabled) +{ + PARAM_PROLOGUE; + PARAM_STRING(shaderName); + PARAM_BOOL(value); + ShaderSetEnabled(shaderName, value); + + return 0; +} + +static void ShaderSetUniform1f(const FString &shaderName, const FString &uniformName, double value) +{ + for (unsigned int i = 0; i < PostProcessShaders.Size(); i++) + { + PostProcessShader &shader = PostProcessShaders[i]; + if (shader.Name == shaderName) + { + double *vec4 = shader.Uniforms[uniformName].Values; + vec4[0] = value; + vec4[1] = 0.0; + vec4[2] = 0.0; + vec4[3] = 1.0; + } + } +} + +DEFINE_ACTION_FUNCTION_NATIVE(_PPShader, SetUniform1f, ShaderSetUniform1f) +{ + PARAM_PROLOGUE; + PARAM_STRING(shaderName); + PARAM_STRING(uniformName); + PARAM_FLOAT(value); + ShaderSetUniform1f(shaderName, uniformName, value); + return 0; +} + +DEFINE_ACTION_FUNCTION(_PPShader, SetUniform2f) +{ + PARAM_PROLOGUE; + PARAM_STRING(shaderName); + PARAM_STRING(uniformName); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + + for (unsigned int i = 0; i < PostProcessShaders.Size(); i++) + { + PostProcessShader &shader = PostProcessShaders[i]; + if (shader.Name == shaderName) + { + double *vec4 = shader.Uniforms[uniformName].Values; + vec4[0] = x; + vec4[1] = y; + vec4[2] = 0.0; + vec4[3] = 1.0; + } + } + return 0; +} + +DEFINE_ACTION_FUNCTION(_PPShader, SetUniform3f) +{ + PARAM_PROLOGUE; + PARAM_STRING(shaderName); + PARAM_STRING(uniformName); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_FLOAT(z); + + for (unsigned int i = 0; i < PostProcessShaders.Size(); i++) + { + PostProcessShader &shader = PostProcessShaders[i]; + if (shader.Name == shaderName) + { + double *vec4 = shader.Uniforms[uniformName].Values; + vec4[0] = x; + vec4[1] = y; + vec4[2] = z; + vec4[3] = 1.0; + } + } + return 0; +} + +DEFINE_ACTION_FUNCTION(_PPShader, SetUniform1i) +{ + PARAM_PROLOGUE; + PARAM_STRING(shaderName); + PARAM_STRING(uniformName); + PARAM_INT(value); + + for (unsigned int i = 0; i < PostProcessShaders.Size(); i++) + { + PostProcessShader &shader = PostProcessShaders[i]; + if (shader.Name == shaderName) + { + double *vec4 = shader.Uniforms[uniformName].Values; + vec4[0] = (double)value; + vec4[1] = 0.0; + vec4[2] = 0.0; + vec4[3] = 1.0; + } + } + return 0; +} diff --git a/src/rendering/hwrenderer/hw_postprocessshader.cpp b/src/rendering/hwrenderer/hw_postprocessshader.cpp deleted file mode 100644 index f8e6e3e8b..000000000 --- a/src/rendering/hwrenderer/hw_postprocessshader.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* -** Postprocessing framework -** Copyright (c) 2016-2020 Magnus Norddahl -** -** 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 "vm.h" -#include "d_player.h" -#include "hwrenderer/postprocessing/hw_postprocessshader.h" -#include "g_levellocals.h" -#include "hwrenderer/postprocessing/hw_postprocess.h" - -static bool IsConsolePlayer(player_t *player) -{ - AActor *activator = player ? player->mo : nullptr; - if (activator == nullptr || activator->player == nullptr) - return false; - return activator->player == activator->Level->GetConsolePlayer(); -} - -static void ShaderSetEnabled(player_t *player, const FString &shaderName, bool value) -{ - if (IsConsolePlayer(player)) - { - for (unsigned int i = 0; i < PostProcessShaders.Size(); i++) - { - PostProcessShader &shader = PostProcessShaders[i]; - if (shader.Name == shaderName) - shader.Enabled = value; - } - } -} - -DEFINE_ACTION_FUNCTION_NATIVE(_Shader, SetEnabled, ShaderSetEnabled) -{ - PARAM_PROLOGUE; - PARAM_POINTER(player, player_t); - PARAM_STRING(shaderName); - PARAM_BOOL(value); - ShaderSetEnabled(player, shaderName, value); - - return 0; -} - -static void ShaderSetUniform1f(player_t *player, const FString &shaderName, const FString &uniformName, double value) -{ - if (IsConsolePlayer(player)) - { - for (unsigned int i = 0; i < PostProcessShaders.Size(); i++) - { - PostProcessShader &shader = PostProcessShaders[i]; - if (shader.Name == shaderName) - { - double *vec4 = shader.Uniforms[uniformName].Values; - vec4[0] = value; - vec4[1] = 0.0; - vec4[2] = 0.0; - vec4[3] = 1.0; - } - } - } -} - -DEFINE_ACTION_FUNCTION_NATIVE(_Shader, SetUniform1f, ShaderSetUniform1f) -{ - PARAM_PROLOGUE; - PARAM_POINTER(player, player_t); - PARAM_STRING(shaderName); - PARAM_STRING(uniformName); - PARAM_FLOAT(value); - ShaderSetUniform1f(player, shaderName, uniformName, value); - return 0; -} - -DEFINE_ACTION_FUNCTION(_Shader, SetUniform2f) -{ - PARAM_PROLOGUE; - PARAM_POINTER(player, player_t); - PARAM_STRING(shaderName); - PARAM_STRING(uniformName); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - - if (IsConsolePlayer(player)) - { - for (unsigned int i = 0; i < PostProcessShaders.Size(); i++) - { - PostProcessShader &shader = PostProcessShaders[i]; - if (shader.Name == shaderName) - { - double *vec4 = shader.Uniforms[uniformName].Values; - vec4[0] = x; - vec4[1] = y; - vec4[2] = 0.0; - vec4[3] = 1.0; - } - } - } - return 0; -} - -DEFINE_ACTION_FUNCTION(_Shader, SetUniform3f) -{ - PARAM_PROLOGUE; - PARAM_POINTER(player, player_t); - PARAM_STRING(shaderName); - PARAM_STRING(uniformName); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_FLOAT(z); - - if (IsConsolePlayer(player)) - { - for (unsigned int i = 0; i < PostProcessShaders.Size(); i++) - { - PostProcessShader &shader = PostProcessShaders[i]; - if (shader.Name == shaderName) - { - double *vec4 = shader.Uniforms[uniformName].Values; - vec4[0] = x; - vec4[1] = y; - vec4[2] = z; - vec4[3] = 1.0; - } - } - } - return 0; -} - -DEFINE_ACTION_FUNCTION(_Shader, SetUniform1i) -{ - PARAM_PROLOGUE; - PARAM_POINTER(player, player_t); - PARAM_STRING(shaderName); - PARAM_STRING(uniformName); - PARAM_INT(value); - - if (IsConsolePlayer(player)) - { - for (unsigned int i = 0; i < PostProcessShaders.Size(); i++) - { - PostProcessShader &shader = PostProcessShaders[i]; - if (shader.Name == shaderName) - { - double *vec4 = shader.Uniforms[uniformName].Values; - vec4[0] = (double)value; - vec4[1] = 0.0; - vec4[2] = 0.0; - vec4[3] = 1.0; - } - } - } - return 0; -} diff --git a/wadsrc/static/zscript.txt b/wadsrc/static/zscript.txt index a447a9b73..e6bd04830 100644 --- a/wadsrc/static/zscript.txt +++ b/wadsrc/static/zscript.txt @@ -6,6 +6,7 @@ version "4.6" #include "zscript/engine/dictionary.zs" #include "zscript/engine/inputevents.zs" #include "zscript/engine/service.zs" +#include "zscript/engine/ppshader.zs" #include "zscript/engine/ui/menu/colorpickermenu.zs" #include "zscript/engine/ui/menu/joystickmenu.zs" diff --git a/wadsrc/static/zscript/doombase.zs b/wadsrc/static/zscript/doombase.zs index f81596199..07245d3ac 100644 --- a/wadsrc/static/zscript/doombase.zs +++ b/wadsrc/static/zscript/doombase.zs @@ -701,11 +701,31 @@ class Lighting : SectorEffect native 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); + // This interface was deprecated for the pointless player dependency + private static bool IsConsolePlayer(PlayerInfo player) + { + return player && !player.mo && player == players[consoleplayer]; + } + deprecated("4.8", "Use PPShader.SetEnabled() instead") clearscope static void SetEnabled(PlayerInfo player, string shaderName, bool enable) + { + if (IsConsolePlayer(player)) PPShader.SetEnabled(shaderName, enable); + } + deprecated("4.8", "Use PPShader.SetUniform1f() instead") clearscope static void SetUniform1f(PlayerInfo player, string shaderName, string uniformName, float value) + { + if (IsConsolePlayer(player)) PPShader.SetUniform1f(shaderName, uniformName, value); + } + deprecated("4.8", "Use PPShader.SetUniform2f() instead") clearscope static void SetUniform2f(PlayerInfo player, string shaderName, string uniformName, vector2 value) + { + if (IsConsolePlayer(player)) PPShader.SetUniform2f(shaderName, uniformName, value); + } + deprecated("4.8", "Use PPShader.SetUniform3f() instead") clearscope static void SetUniform3f(PlayerInfo player, string shaderName, string uniformName, vector3 value) + { + if (IsConsolePlayer(player)) PPShader.SetUniform3f(shaderName, uniformName, value); + } + deprecated("4.8", "Use PPShader.SetUniform1i() instead") clearscope static void SetUniform1i(PlayerInfo player, string shaderName, string uniformName, int value) + { + if (IsConsolePlayer(player)) PPShader.SetUniform1i(shaderName, uniformName, value); + } } struct FRailParams diff --git a/wadsrc/static/zscript/engine/ppshader.zs b/wadsrc/static/zscript/engine/ppshader.zs new file mode 100644 index 000000000..5c94e7e23 --- /dev/null +++ b/wadsrc/static/zscript/engine/ppshader.zs @@ -0,0 +1,8 @@ +struct PPShader native +{ + native clearscope static void SetEnabled(string shaderName, bool enable); + native clearscope static void SetUniform1f(string shaderName, string uniformName, float value); + native clearscope static void SetUniform2f(string shaderName, string uniformName, vector2 value); + native clearscope static void SetUniform3f(string shaderName, string uniformName, vector3 value); + native clearscope static void SetUniform1i(string shaderName, string uniformName, int value); +}