From 86660a3ff3c958500683300e5e5882d1239d6ca5 Mon Sep 17 00:00:00 2001 From: aap Date: Wed, 29 Apr 2020 21:31:29 +0200 Subject: [PATCH] fixed gl3 matfx --- src/gl/gl3matfx.cpp | 9 +++++++++ src/gl/shaders/matfx_env.frag | 6 +++++- src/gl/shaders/matfx_gl3.inc | 5 ++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/gl/gl3matfx.cpp b/src/gl/gl3matfx.cpp index f341fb8..23af3ac 100644 --- a/src/gl/gl3matfx.cpp +++ b/src/gl/gl3matfx.cpp @@ -31,12 +31,14 @@ namespace gl3 { static Shader *envShader; static int32 u_texMatrix; static int32 u_coefficient; +static int32 u_colorClamp; static void* matfxOpen(void *o, int32, int32) { u_texMatrix = registerUniform("u_texMatrix"); u_coefficient = registerUniform("u_coefficient"); + u_colorClamp = registerUniform("u_colorClamp"); matFXGlobals.pipelines[PLATFORM_GL3] = makeMatFXPipeline(); #include "shaders/matfx_gl3.inc" @@ -146,6 +148,13 @@ matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, MatFX::Env *env) glUniform4fv(U(u_surfProps), 1, surfProps); glUniform1fv(U(u_coefficient), 1, &env->coefficient); + static float zero[4]; + static float one[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + // This clamps the vertex color below. With it we can achieve both PC and PS2 style matfx + if(MatFX::modulateEnvMap) + glUniform4fv(U(u_colorClamp), 1, zero); + else + glUniform4fv(U(u_colorClamp), 1, one); rw::SetRenderState(VERTEXALPHA, 1); rw::SetRenderState(SRCBLEND, BLENDONE); diff --git a/src/gl/shaders/matfx_env.frag b/src/gl/shaders/matfx_env.frag index 87ec846..f77426c 100644 --- a/src/gl/shaders/matfx_env.frag +++ b/src/gl/shaders/matfx_env.frag @@ -16,6 +16,7 @@ uniform sampler2D tex0; uniform sampler2D tex1; uniform float u_coefficient; +uniform vec4 u_colorClamp; in vec4 v_color; in vec2 v_tex0; @@ -29,10 +30,13 @@ main(void) { vec4 pass1 = v_color; vec4 envColor = pass1; // TODO: colorClamp - pass1 *= texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y)); + vec4 pass2 = envColor*u_coefficient*texture(tex1, vec2(v_tex1.x, 1.0-v_tex1.y)); + pass1.rgb = mix(u_fogColor.rgb, pass1.rgb, v_fog); + pass2.rgb = mix(vec3(0.0, 0.0, 0.0), pass2.rgb, v_fog); + color.rgb = pass1.rgb*pass1.a + pass2.rgb; color.a = pass1.a; diff --git a/src/gl/shaders/matfx_gl3.inc b/src/gl/shaders/matfx_gl3.inc index ac351fa..9ffd868 100644 --- a/src/gl/shaders/matfx_gl3.inc +++ b/src/gl/shaders/matfx_gl3.inc @@ -84,10 +84,13 @@ const char *matfx_env_frag_src = "{\n" " vec4 pass1 = v_color;\n" " vec4 envColor = pass1; // TODO: colorClamp\n" - " pass1 *= texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n" + " vec4 pass2 = envColor*u_coefficient*texture(tex1, vec2(v_tex1.x, 1.0-v_tex1.y));\n" +" pass1.rgb = mix(u_fogColor.rgb, pass1.rgb, v_fog);\n" +" pass2.rgb = mix(vec3(0.0, 0.0, 0.0), pass2.rgb, v_fog);\n" + " color.rgb = pass1.rgb*pass1.a + pass2.rgb;\n" " color.a = pass1.a;\n"