Merge branch 'blurshader_120_fix' of https://github.com/dpjudas/zdoom

This commit is contained in:
Christoph Oelckers 2016-07-31 09:17:28 +02:00
commit 20f4975e2b
2 changed files with 32 additions and 0 deletions

View file

@ -86,6 +86,20 @@ void FBlurShader::Blur(FFlatVertexBuffer *vbo, float blurAmount, int sampleCount
else else
setup->HorizontalShader->Bind(); setup->HorizontalShader->Bind();
if (gl.glslversion < 1.3)
{
if (vertical)
{
setup->VerticalScaleX.Set(1.0f / width);
setup->VerticalScaleY.Set(1.0f / height);
}
else
{
setup->HorizontalScaleX.Set(1.0f / width);
setup->HorizontalScaleY.Set(1.0f / height);
}
}
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, inputTexture); glBindTexture(GL_TEXTURE_2D, inputTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -146,6 +160,14 @@ FBlurShader::BlurSetup *FBlurShader::GetSetup(float blurAmount, int sampleCount)
blurSetup.HorizontalShader->Bind(); blurSetup.HorizontalShader->Bind();
glUniform1i(glGetUniformLocation(*blurSetup.HorizontalShader.get(), "SourceTexture"), 0); glUniform1i(glGetUniformLocation(*blurSetup.HorizontalShader.get(), "SourceTexture"), 0);
if (gl.glslversion < 1.3)
{
blurSetup.VerticalScaleX.Init(*blurSetup.VerticalShader.get(), "ScaleX");
blurSetup.VerticalScaleY.Init(*blurSetup.VerticalShader.get(), "ScaleY");
blurSetup.HorizontalScaleX.Init(*blurSetup.HorizontalShader.get(), "ScaleX");
blurSetup.HorizontalScaleY.Init(*blurSetup.HorizontalShader.get(), "ScaleY");
}
mBlurSetups.Push(blurSetup); mBlurSetups.Push(blurSetup);
return &mBlurSetups[mBlurSetups.Size() - 1]; return &mBlurSetups[mBlurSetups.Size() - 1];
@ -188,6 +210,14 @@ FString FBlurShader::FragmentShaderCode(float blurAmount, int sampleCount, bool
in vec2 TexCoord; in vec2 TexCoord;
uniform sampler2D SourceTexture; uniform sampler2D SourceTexture;
out vec4 FragColor; out vec4 FragColor;
#if __VERSION__ < 130
uniform float ScaleX;
uniform float ScaleY;
vec4 textureOffset(sampler2D s, vec2 texCoord, ivec2 offset)
{
return texture2D(s, texCoord + vec2(ScaleX * float(offset.x), ScaleY * float(offset.y)));
}
#endif
void main() void main()
{ {
FragColor = %s; FragColor = %s;

View file

@ -23,6 +23,8 @@ private:
int sampleCount; int sampleCount;
std::shared_ptr<FShaderProgram> VerticalShader; std::shared_ptr<FShaderProgram> VerticalShader;
std::shared_ptr<FShaderProgram> HorizontalShader; std::shared_ptr<FShaderProgram> HorizontalShader;
FBufferedUniform1f VerticalScaleX, VerticalScaleY;
FBufferedUniform1f HorizontalScaleX, HorizontalScaleY;
}; };
BlurSetup *GetSetup(float blurAmount, int sampleCount); BlurSetup *GetSetup(float blurAmount, int sampleCount);