fixed gl3 matfx

This commit is contained in:
aap 2020-04-29 21:31:29 +02:00
parent c39759f83c
commit 86660a3ff3
3 changed files with 18 additions and 2 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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"