Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13ca744
commit 85aee83
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
source/common/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters