- Specify shader uniforms from ZScript

This commit is contained in:
Magnus Norddahl 2017-07-03 22:30:49 +02:00
parent 1b5f3da9c5
commit e161bba146
4 changed files with 67 additions and 0 deletions

View file

@ -178,6 +178,40 @@ void FGLRenderer::PostProcessScene(int fixedcm)
RunCustomPostProcessShaders("screen");
}
#include "vm.h"
DEFINE_ACTION_FUNCTION(_Shader, SetUniform1f)
{
PARAM_PROLOGUE;
PARAM_STRING(shaderName);
PARAM_STRING(uniformName);
PARAM_FLOAT_DEF(value);
for (unsigned int i = 0; i < PostProcessShaders.Size(); i++)
{
PostProcessShader &shader = PostProcessShaders[i];
if (shader.Name == shaderName)
shader.Uniform1f[uniformName] = value;
}
return 0;
}
DEFINE_ACTION_FUNCTION(_Shader, SetUniform1i)
{
PARAM_PROLOGUE;
PARAM_STRING(shaderName);
PARAM_STRING(uniformName);
PARAM_INT_DEF(value);
for (unsigned int i = 0; i < PostProcessShaders.Size(); i++)
{
PostProcessShader &shader = PostProcessShaders[i];
if (shader.Name == shaderName)
shader.Uniform1i[uniformName] = value;
}
return 0;
}
void FGLRenderer::RunCustomPostProcessShaders(FString target)
{
for (unsigned int i = 0; i < PostProcessShaders.Size(); i++)
@ -222,6 +256,24 @@ void FGLRenderer::RunCustomPostProcessShaders(FString target)
shader.Instance->Program.Bind();
TMap<FString, float>::Iterator it1f(shader.Uniform1f);
TMap<FString, float>::Pair *pair1f;
while (it1f.NextPair(pair1f))
{
int location = glGetUniformLocation(shader.Instance->Program, pair1f->Key.GetChars());
if (location != -1)
glUniform1f(location, pair1f->Value);
}
TMap<FString, int>::Iterator it1i(shader.Uniform1i);
TMap<FString, int>::Pair *pair1i;
while (it1i.NextPair(pair1i))
{
int location = glGetUniformLocation(shader.Instance->Program, pair1i->Key.GetChars());
if (location != -1)
glUniform1i(location, pair1i->Value);
}
shader.Instance->InputTexture.Set(0);
if (shader.Instance->HWTexture)

View file

@ -92,6 +92,11 @@ struct PostProcessShader
FString ShaderLumpName;
int ShaderVersion = 0;
FTexture *Texture = nullptr;
FString Name;
TMap<FString, int> Uniform1i;
TMap<FString, float> Uniform1f;
std::shared_ptr<PostProcessShaderInstance> Instance;
};

View file

@ -693,6 +693,11 @@ void gl_ParseHardwareShader(FScanner &sc, int deflump)
sc.MustGetNumber();
shaderdesc.ShaderVersion = sc.Number;
}
else if (sc.Compare("name"))
{
sc.MustGetString();
shaderdesc.Name = sc.String;
}
else if (sc.Compare("texture"))
{
sc.MustGetString();

View file

@ -775,3 +775,8 @@ class Lighting : SectorEffect native
{
}
struct Shader native
{
native static void SetUniform1f(string shaderName, string uniformName, float value);
native static void SetUniform1i(string shaderName, string uniformName, int value);
}