Make OpenGL renderer able to vertex color lightmaps

This commit is contained in:
Agent X 2024-04-03 20:10:10 -04:00
parent c6437101c6
commit 817c8a1aff
1 changed files with 22 additions and 8 deletions

View File

@ -39,6 +39,7 @@
#include "../configfile.h"
#include "gfx_cc.h"
#include "gfx_rendering_api.h"
#include "gfx_pc.h"
#define TEX_CACHE_STEP 512
@ -49,10 +50,11 @@ struct ShaderProgram {
bool used_textures[2];
uint8_t num_floats;
GLint attrib_locations[7];
GLint uniform_locations[5];
GLint uniform_locations[6];
uint8_t attrib_sizes[7];
uint8_t num_attribs;
bool used_noise;
bool used_lightmap;
};
struct GLTexture {
@ -92,8 +94,8 @@ static void gfx_opengl_vertex_array_set_attribs(struct ShaderProgram *prg) {
}
static inline void gfx_opengl_set_shader_uniforms(struct ShaderProgram *prg) {
if (prg->used_noise)
glUniform1f(prg->uniform_locations[4], (float)frame_count);
if (prg->used_noise) { glUniform1f(prg->uniform_locations[4], (float)frame_count); }
if (prg->used_lightmap) { glUniform3f(prg->uniform_locations[5], gVertexColor[0] / 255.0f, gVertexColor[1] / 255.0f, gVertexColor[2] / 255.0f); }
}
static inline void gfx_opengl_set_texture_uniforms(struct ShaderProgram *prg, const int tile) {
@ -366,7 +368,7 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(struct ColorC
}
if ((opt_alpha && opt_dither) || ccf.do_noise) {
append_line(fs_buf, &fs_len, "uniform float frame_count;");
append_line(fs_buf, &fs_len, "uniform float uFrameCount;");
append_line(fs_buf, &fs_len, "float random(in vec3 value) {");
append_line(fs_buf, &fs_len, " float random = dot(sin(value), vec3(12.9898, 78.233, 37.719));");
@ -374,19 +376,24 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(struct ColorC
append_line(fs_buf, &fs_len, "}");
}
if (opt_light_map) {
append_line(fs_buf, &fs_len, "uniform vec3 uLightmapColor;");
}
append_line(fs_buf, &fs_len, "void main() {");
if ((opt_alpha && opt_dither) || ccf.do_noise) {
append_line(fs_buf, &fs_len, "float noise = floor(random(floor(vec3(gl_FragCoord.xy, frame_count))) + 0.5);");
append_line(fs_buf, &fs_len, "float noise = floor(random(floor(vec3(gl_FragCoord.xy, uFrameCount))) + 0.5);");
}
if (ccf.used_textures[0]) {
append_line(fs_buf, &fs_len, "vec4 texVal0 = sampleTex(uTex0, vTexCoord, uTex0Size, uTex0Filter);");
}
if (ccf.used_textures[1]) {
if (cc->cm.light_map) {
if (opt_light_map) {
append_line(fs_buf, &fs_len, "vec4 texVal1 = sampleTex(uTex1, vLightMap, uTex1Size, uTex1Filter);");
append_line(fs_buf, &fs_len, "texVal1.rgb = texVal1.rgb * texVal1.rgb + texVal1.rgb;");
append_line(fs_buf, &fs_len, "texVal0.rgb *= uLightmapColor.rgb;");
append_line(fs_buf, &fs_len, "texVal1.rgb = texVal1.rgb * texVal1.rgb + texVal1.rgb;");
} else {
append_line(fs_buf, &fs_len, "vec4 texVal1 = sampleTex(uTex1, vTexCoord, uTex1Size, uTex1Filter);");
}
@ -542,12 +549,19 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(struct ColorC
}
if ((opt_alpha && opt_dither) || ccf.do_noise) {
prg->uniform_locations[4] = glGetUniformLocation(shader_program, "frame_count");
prg->uniform_locations[4] = glGetUniformLocation(shader_program, "uFrameCount");
prg->used_noise = true;
} else {
prg->used_noise = false;
}
if (opt_light_map) {
prg->uniform_locations[5] = glGetUniformLocation(shader_program, "uLightmapColor");
prg->used_lightmap = true;
} else {
prg->used_lightmap = false;
}
return prg;
}