Skip to content

Commit

Permalink
fixed gl3 matfx
Browse files Browse the repository at this point in the history
  • Loading branch information
aap committed Apr 29, 2020
1 parent c39759f commit 86660a3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/gl/gl3matfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/gl/shaders/matfx_env.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion src/gl/shaders/matfx_gl3.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 86660a3

Please sign in to comment.