mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-28 23:13:02 +00:00
Made light maps a little less hacky
This commit is contained in:
parent
ba4ed58cfa
commit
e9ecf7a8f4
5 changed files with 42 additions and 19 deletions
|
@ -313,6 +313,9 @@ s64 DynOS_Gfx_ParseGfxConstants(const String& _Arg, bool* found) {
|
||||||
gfx_constant(CAP);
|
gfx_constant(CAP);
|
||||||
gfx_constant(METAL);
|
gfx_constant(METAL);
|
||||||
|
|
||||||
|
// Extended
|
||||||
|
gfx_constant(G_LIGHT_MAP_EXT);
|
||||||
|
|
||||||
// Common values
|
// Common values
|
||||||
gfx_constant(CALC_DXT(4,G_IM_SIZ_4b_BYTES));
|
gfx_constant(CALC_DXT(4,G_IM_SIZ_4b_BYTES));
|
||||||
gfx_constant(CALC_DXT(8,G_IM_SIZ_4b_BYTES));
|
gfx_constant(CALC_DXT(8,G_IM_SIZ_4b_BYTES));
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#define _GBI_H_
|
#define _GBI_H_
|
||||||
|
|
||||||
#include <PR/ultratypes.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.
|
* To use the F3DEX ucodes, define F3DEX_GBI before include this file.
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// G_SETGEOMETRYMODE //
|
||||||
|
///////////////////////
|
||||||
|
|
||||||
|
#define G_LIGHT_MAP_EXT 0x00000800
|
||||||
|
|
||||||
|
//////////
|
||||||
|
// DJUI //
|
||||||
|
//////////
|
||||||
|
|
||||||
#define G_TEXCLIP_DJUI 0xe1
|
#define G_TEXCLIP_DJUI 0xe1
|
||||||
#define G_TEXOVERRIDE_DJUI 0xe0
|
#define G_TEXOVERRIDE_DJUI 0xe0
|
||||||
#define G_DJUI_SIMPLE_VERT 0x11
|
#define G_DJUI_SIMPLE_VERT 0x11
|
|
@ -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_fog = cc->cm.use_fog;
|
||||||
bool opt_texture_edge = cc->cm.texture_edge;
|
bool opt_texture_edge = cc->cm.texture_edge;
|
||||||
bool opt_2cycle = cc->cm.use_2cycle;
|
bool opt_2cycle = cc->cm.use_2cycle;
|
||||||
|
bool opt_light_map = cc->cm.light_map;
|
||||||
|
|
||||||
#ifdef USE_GLES
|
#ifdef USE_GLES
|
||||||
bool opt_noise = false;
|
bool opt_noise = false;
|
||||||
#else
|
#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;");
|
append_line(vs_buf, &vs_len, "varying vec4 vFog;");
|
||||||
num_floats += 4;
|
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++) {
|
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, "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);
|
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) {
|
if (opt_fog) {
|
||||||
append_line(vs_buf, &vs_len, "vFog = aFog;");
|
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++) {
|
for (int i = 0; i < num_inputs; i++) {
|
||||||
vs_len += sprintf(vs_buf + vs_len, "vInput%d = aInput%d;\n", i + 1, i + 1);
|
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) {
|
if (opt_fog) {
|
||||||
append_line(fs_buf, &fs_len, "varying vec4 vFog;");
|
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++) {
|
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);
|
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 (used_textures[1]) {
|
||||||
if (cc->cm.light_map) {
|
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 {
|
} else {
|
||||||
append_line(fs_buf, &fs_len, "vec4 texVal1 = sampleTex(uTex1, vTexCoord, uTex1Size, uTex1Filter);");
|
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;
|
++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++) {
|
for (int i = 0; i < num_inputs; i++) {
|
||||||
char name[16];
|
char name[16];
|
||||||
sprintf(name, "aInput%d", i + 1);
|
sprintf(name, "aInput%d", i + 1);
|
||||||
|
|
|
@ -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_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_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->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;
|
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)
|
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++) {
|
for (int j = 0; j < num_inputs; j++) {
|
||||||
struct RGBA *color = NULL;
|
struct RGBA *color = NULL;
|
||||||
struct RGBA tmp = { 0 };
|
struct RGBA tmp = { 0 };
|
||||||
for (int a = 0; a < (cm->use_alpha ? 2 : 1 ); a++) {
|
for (int a = 0; a < (cm->use_alpha ? 2 : 1 ); a++) {
|
||||||
u8 mapping = comb->shader_input_mapping[j];
|
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) {
|
switch (mapping) {
|
||||||
case CC_PRIM:
|
case CC_PRIM:
|
||||||
color = &rdp.prim_color;
|
color = &rdp.prim_color;
|
||||||
|
|
Loading…
Reference in a new issue