Made light maps a little less hacky

This commit is contained in:
MysterD 2023-04-28 00:22:30 -07:00
parent ba4ed58cfa
commit e9ecf7a8f4
5 changed files with 42 additions and 19 deletions

View file

@ -313,6 +313,9 @@ s64 DynOS_Gfx_ParseGfxConstants(const String& _Arg, bool* found) {
gfx_constant(CAP);
gfx_constant(METAL);
// Extended
gfx_constant(G_LIGHT_MAP_EXT);
// Common values
gfx_constant(CALC_DXT(4,G_IM_SIZ_4b_BYTES));
gfx_constant(CALC_DXT(8,G_IM_SIZ_4b_BYTES));

View file

@ -21,7 +21,7 @@
#define _GBI_H_
#include <PR/ultratypes.h>
#include "src/pc/djui/djui_gbi.h"
#include "gbi_extension.h"
/*
* To use the F3DEX ucodes, define F3DEX_GBI before include this file.

View file

@ -1,5 +1,15 @@
#pragma once
///////////////////////
// G_SETGEOMETRYMODE //
///////////////////////
#define G_LIGHT_MAP_EXT 0x00000800
//////////
// DJUI //
//////////
#define G_TEXCLIP_DJUI 0xe1
#define G_TEXOVERRIDE_DJUI 0xe0
#define G_DJUI_SIMPLE_VERT 0x11

View file

@ -241,6 +241,8 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(struct ColorC
bool opt_fog = cc->cm.use_fog;
bool opt_texture_edge = cc->cm.texture_edge;
bool opt_2cycle = cc->cm.use_2cycle;
bool opt_light_map = cc->cm.light_map;
#ifdef USE_GLES
bool opt_noise = false;
#else
@ -304,6 +306,11 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(struct ColorC
append_line(vs_buf, &vs_len, "varying vec4 vFog;");
num_floats += 4;
}
if (opt_light_map) {
append_line(vs_buf, &vs_len, "attribute vec2 aLightMap;");
append_line(vs_buf, &vs_len, "varying vec2 vLightMap;");
num_floats += 2;
}
for (int i = 0; i < num_inputs; i++) {
vs_len += sprintf(vs_buf + vs_len, "attribute vec%d aInput%d;\n", opt_alpha ? 4 : 3, i + 1);
vs_len += sprintf(vs_buf + vs_len, "varying vec%d vInput%d;\n", opt_alpha ? 4 : 3, i + 1);
@ -316,6 +323,9 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(struct ColorC
if (opt_fog) {
append_line(vs_buf, &vs_len, "vFog = aFog;");
}
if (opt_light_map) {
append_line(vs_buf, &vs_len, "vLightMap = aLightMap;");
}
for (int i = 0; i < num_inputs; i++) {
vs_len += sprintf(vs_buf + vs_len, "vInput%d = aInput%d;\n", i + 1, i + 1);
}
@ -336,6 +346,9 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(struct ColorC
if (opt_fog) {
append_line(fs_buf, &fs_len, "varying vec4 vFog;");
}
if (opt_light_map) {
append_line(fs_buf, &fs_len, "varying vec2 vLightMap;");
}
for (int i = 0; i < num_inputs; i++) {
fs_len += sprintf(fs_buf + fs_len, "varying vec%d vInput%d;\n", opt_alpha ? 4 : 3, i + 1);
}
@ -394,7 +407,7 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(struct ColorC
}
if (used_textures[1]) {
if (cc->cm.light_map) {
append_line(fs_buf, &fs_len, "vec4 texVal1 = sampleTex(uTex1, vInput1.rg, uTex1Size, uTex1Filter);");
append_line(fs_buf, &fs_len, "vec4 texVal1 = sampleTex(uTex1, vLightMap, uTex1Size, uTex1Filter);");
} else {
append_line(fs_buf, &fs_len, "vec4 texVal1 = sampleTex(uTex1, vTexCoord, uTex1Size, uTex1Filter);");
}
@ -508,6 +521,12 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(struct ColorC
++cnt;
}
if (opt_light_map) {
prg->attrib_locations[cnt] = glGetAttribLocation(shader_program, "aLightMap");
prg->attrib_sizes[cnt] = 2;
++cnt;
}
for (int i = 0; i < num_inputs; i++) {
char name[16];
sprintf(name, "aInput%d", i + 1);

View file

@ -1032,9 +1032,9 @@ static void OPTIMIZE_O3 gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t
cm->use_noise = (rdp.other_mode_l & G_AC_DITHER) == G_AC_DITHER;
cm->use_2cycle = (rdp.other_mode_h & (3U << G_MDSFT_CYCLETYPE)) == G_CYC_2CYCLE;
cm->use_fog = (rdp.other_mode_l >> 30) == G_BL_CLR_FOG;
cm->light_map = (cm->alpha1 == 0x08040000);
cm->light_map = (rsp.geometry_mode & G_LIGHT_MAP_EXT) == G_LIGHT_MAP_EXT;
if (cm->texture_edge || cm->light_map) {
if (cm->texture_edge) {
cm->use_alpha = true;
}
@ -1113,27 +1113,18 @@ static void OPTIMIZE_O3 gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t
buf_vbo[buf_vbo_len++] = v_arr[i]->color.a / 255.0f; // fog factor (not alpha)
}
if (cm->light_map) {
struct RGBA* col = &v_arr[i]->color;
buf_vbo[buf_vbo_len++] = ( (((uint16_t)col->g) << 8) | ((uint16_t)col->r) ) / 65535.0f;
buf_vbo[buf_vbo_len++] = 1.0f - (( (((uint16_t)col->a) << 8) | ((uint16_t)col->b) ) / 65535.0f);
}
for (int j = 0; j < num_inputs; j++) {
struct RGBA *color = NULL;
struct RGBA tmp = { 0 };
for (int a = 0; a < (cm->use_alpha ? 2 : 1 ); a++) {
u8 mapping = comb->shader_input_mapping[j];
if (cm->light_map && mapping == CC_SHADE) {
if (a == 0) {
struct RGBA* col = &v_arr[i]->color;
printf("light: ");
buf_vbo[buf_vbo_len++] = ( (((uint16_t)col->g) << 8) | ((uint16_t)col->r) ) / 65535.0f;
printf(" %f", buf_vbo[buf_vbo_len-1]);
buf_vbo[buf_vbo_len++] = 1.0f - (( (((uint16_t)col->a) << 8) | ((uint16_t)col->b) ) / 65535.0f);
printf(", %f\n", buf_vbo[buf_vbo_len-1]);
buf_vbo[buf_vbo_len++] = 0;
} else {
buf_vbo[buf_vbo_len++] = 1;
}
continue;
}
switch (mapping) {
case CC_PRIM:
color = &rdp.prim_color;