Skip to content

Commit

Permalink
Add sky multiplier and yaw offset support. Fixes JRB's skybox effect …
Browse files Browse the repository at this point in the history
…when the star is not collected.
  • Loading branch information
DarioSamo committed Jul 10, 2021
1 parent 526fa2a commit 583f1eb
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 26 deletions.
2 changes: 2 additions & 0 deletions include/rt64/rt64.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ typedef struct {
RT64_VECTOR3 ambientNoGIColor;
RT64_VECTOR3 eyeLightDiffuseColor;
RT64_VECTOR3 eyeLightSpecularColor;
RT64_VECTOR3 skyDiffuseMultiplier;
RT64_VECTOR3 skyHSLModifier;
float skyYawOffset;
float giDiffuseStrength;
float giSkyStrength;
} RT64_SCENE_DESC;
Expand Down
Binary file modified lib/rt64/rt64lib.dll
Binary file not shown.
11 changes: 9 additions & 2 deletions src/game/skybox.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,15 @@ Gfx *create_skybox_facing_camera(s8 player, s8 background, f32 fov,
f32 cameraFaceX = focX - posX;
f32 cameraFaceY = focY - posY;
f32 cameraFaceZ = focZ - posZ;
#endif
s8 colorIndex = 1;

// If the first star is collected in JRB, make the sky darker and slightly green
if (background == 8 && !(save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_JRB - 1) & 1)) {
colorIndex = 0;
}


#ifndef GFX_SEPARATE_SKYBOX
//! fov is always set to 90.0f. If this line is removed, then the game crashes because fov is 0 on
//! the first frame, which causes a floating point divide by 0
fov = 90.0f;
Expand All @@ -315,7 +317,12 @@ Gfx *create_skybox_facing_camera(s8 player, s8 background, f32 fov,

return init_skybox_display_list(player, background, colorIndex);
#else
gfx_set_skybox(background);
float skyboxColor[3];
u8 *chosenColor = sSkyboxColors[colorIndex];
skyboxColor[0] = chosenColor[0] / 255.0f;
skyboxColor[1] = chosenColor[1] / 255.0f;
skyboxColor[2] = chosenColor[2] / 255.0f;
gfx_set_skybox(background, skyboxColor);
return NULL;
#endif
}
4 changes: 2 additions & 2 deletions src/pc/gfx/gfx_pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ void gfx_init_skybox() {
}
}

void gfx_set_skybox(uint8_t skybox_id) {
gfx_rapi->set_skybox_texture(skybox.textures[skybox_id]);
void gfx_set_skybox(uint8_t skybox_id, float diffuse_color[3]) {
gfx_rapi->set_skybox(skybox.textures[skybox_id], diffuse_color);
}

#endif
Expand Down
2 changes: 1 addition & 1 deletion src/pc/gfx/gfx_pc.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void *gfx_build_graph_node_mod(void *graph_node, float modelview_matrix[4][4], u
#endif

#ifdef GFX_SEPARATE_SKYBOX
void gfx_set_skybox(uint8_t skybox_id);
void gfx_set_skybox(uint8_t skybox_id, float diffuse_color[3]);
#endif

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion src/pc/gfx/gfx_rendering_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct GfxRenderingAPI {
void (*set_graph_node_mod)(void *graph_node_mod);
#endif
#ifdef GFX_SEPARATE_SKYBOX
void (*set_skybox_texture)(uint32_t texture_id);
void (*set_skybox)(uint32_t texture_id, float diffuse_color[3]);
#endif
void (*init)(void);
void (*on_resize)(void);
Expand Down
14 changes: 11 additions & 3 deletions src/pc/gfx/gfx_rt64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ static void gfx_rt64_wapi_init(const char *window_title) {
RT64.fogColor.x = 0.0f;
RT64.fogColor.y = 0.0f;
RT64.fogColor.z = 0.0f;
RT64.skyboxDiffuseMultiplier = { 1.0f, 1.0f, 1.0f };
RT64.fogMul = RT64.fogOffset = 0;
RT64.pickTextureNextFrame = false;
RT64.pickTextureHighlight = false;
Expand Down Expand Up @@ -641,7 +642,9 @@ static void gfx_rt64_wapi_init(const char *window_title) {
sceneDesc.ambientNoGIColor = { 0.10f, 0.15f, 0.20f };
sceneDesc.eyeLightDiffuseColor = { 0.1f, 0.1f, 0.1f };
sceneDesc.eyeLightSpecularColor = { 0.1f, 0.1f, 0.1f };
sceneDesc.skyDiffuseMultiplier = { 1.0f, 1.0f, 1.0f };
sceneDesc.skyHSLModifier = { 0.0f, 0.0f, 0.0f };
sceneDesc.skyYawOffset = 0.0f;
sceneDesc.giDiffuseStrength = 0.7f;
sceneDesc.giSkyStrength = 0.35f;

Expand Down Expand Up @@ -1324,7 +1327,11 @@ static void gfx_rt64_rapi_end_frame(void) {

// Update the scene's description.
const auto &areaLighting = RT64.levelAreaLighting[levelIndex][areaIndex];
RT64.lib.SetSceneDescription(RT64.scene, areaLighting.sceneDesc);
RT64_SCENE_DESC sceneDescCopy = areaLighting.sceneDesc;
sceneDescCopy.skyDiffuseMultiplier.x *= RT64.skyboxDiffuseMultiplier.x;
sceneDescCopy.skyDiffuseMultiplier.y *= RT64.skyboxDiffuseMultiplier.y;
sceneDescCopy.skyDiffuseMultiplier.z *= RT64.skyboxDiffuseMultiplier.z;
RT64.lib.SetSceneDescription(RT64.scene, sceneDescCopy);

// Build lights array out of the static level lights and the dynamic lights.
int areaLightCount = areaLighting.lightCount;
Expand Down Expand Up @@ -1662,7 +1669,8 @@ static void gfx_rt64_rapi_set_graph_node_mod(void *graph_node_mod) {
RT64.graphNodeMod = (RecordedMod *)(graph_node_mod);
}

static void gfx_rt64_rapi_set_skybox_texture(uint32_t texture_id) {
static void gfx_rt64_rapi_set_skybox(uint32_t texture_id, float diffuse_color[3]) {
RT64.skyboxDiffuseMultiplier = { diffuse_color[0], diffuse_color[1], diffuse_color[2] };
RT64.lib.SetViewSkyPlane(RT64.view, RT64.textures[texture_id].texture);
}

Expand Down Expand Up @@ -1716,7 +1724,7 @@ struct GfxRenderingAPI gfx_rt64_rapi = {
gfx_rt64_rapi_draw_triangles_ortho,
gfx_rt64_rapi_draw_triangles_persp,
gfx_rt64_rapi_set_graph_node_mod,
gfx_rt64_rapi_set_skybox_texture,
gfx_rt64_rapi_set_skybox,
gfx_rt64_rapi_init,
gfx_rt64_rapi_on_resize,
gfx_rt64_rapi_start_frame,
Expand Down
1 change: 1 addition & 0 deletions src/pc/gfx/gfx_rt64_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ struct RT64Context {
ShaderProgram *shaderProgram;
bool background;
RT64_VECTOR3 fogColor;
RT64_VECTOR3 skyboxDiffuseMultiplier;
RT64_RECT scissorRect;
RT64_RECT viewportRect;
int16_t fogMul;
Expand Down
41 changes: 24 additions & 17 deletions src/pc/gfx/gfx_rt64_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ extern "C" {
#define GEO_LAYOUT_MODS_FILENAME FS_BASEDIR "/rt64/geo_layout_mods.json"
#define TEXTURE_MODS_FILENAME FS_BASEDIR "/rt64/texture_mods.json"

RT64_VECTOR3 gfx_rt64_load_vector3(const json &jvector) {
float x = jvector[0];
float y = jvector[1];
float z = jvector[2];
return { x, y, z };
RT64_VECTOR3 gfx_rt64_load_vector3(const json &jobject, const std::string &key, RT64_VECTOR3 def = { 0.0f, 0.0f, 0.0f }) {
auto it = jobject.find(key);
if (it != jobject.end()) {
const json &jvector = (*it);
if (jvector.size() == 3) {
return { jvector[0], jvector[1], jvector[2] };
}
}

return def;
}

json gfx_rt64_save_vector3(RT64_VECTOR3 v) {
Expand Down Expand Up @@ -67,10 +72,10 @@ json gfx_rt64_save_specular_map_mod(const std::string &specularTexName) {

void gfx_rt64_load_light(const json &jlight, RT64_LIGHT *light) {
// General parameters
light->position = gfx_rt64_load_vector3(jlight["position"]);
light->position = gfx_rt64_load_vector3(jlight, "position");
light->attenuationRadius = jlight["attenuationRadius"];
light->pointRadius = jlight["pointRadius"];
light->diffuseColor = gfx_rt64_load_vector3(jlight["diffuseColor"]);
light->diffuseColor = gfx_rt64_load_vector3(jlight, "diffuseColor");
light->shadowOffset = jlight["shadowOffset"];
light->attenuationExponent = jlight["attenuationExponent"];
light->flickerIntensity = jlight["flickerIntensity"];
Expand All @@ -85,9 +90,7 @@ void gfx_rt64_load_light(const json &jlight, RT64_LIGHT *light) {
}

// New parameters
if (jlight.find("specularColor") != jlight.end()) {
light->specularColor = gfx_rt64_load_vector3(jlight["specularColor"]);
}
light->specularColor = gfx_rt64_load_vector3(jlight, "specularColor", light->specularColor);
}

json gfx_rt64_save_light(RT64_LIGHT *light) {
Expand All @@ -105,13 +108,15 @@ json gfx_rt64_save_light(RT64_LIGHT *light) {
}

void gfx_rt64_load_scene_description(const json &jscene, RT64_SCENE_DESC *sceneDesc) {
sceneDesc->ambientBaseColor = gfx_rt64_load_vector3(jscene["ambientBaseColor"]);
sceneDesc->ambientNoGIColor = gfx_rt64_load_vector3(jscene["ambientNoGIColor"]);
sceneDesc->eyeLightDiffuseColor = gfx_rt64_load_vector3(jscene["eyeLightDiffuseColor"]);
sceneDesc->eyeLightSpecularColor = gfx_rt64_load_vector3(jscene["eyeLightSpecularColor"]);
sceneDesc->skyHSLModifier = gfx_rt64_load_vector3(jscene["skyHSLModifier"]);
sceneDesc->giDiffuseStrength = jscene["giDiffuseStrength"];
sceneDesc->giSkyStrength = jscene["giSkyStrength"];
sceneDesc->ambientBaseColor = gfx_rt64_load_vector3(jscene, "ambientBaseColor");
sceneDesc->ambientNoGIColor = gfx_rt64_load_vector3(jscene, "ambientNoGIColor");
sceneDesc->eyeLightDiffuseColor = gfx_rt64_load_vector3(jscene, "eyeLightDiffuseColor");
sceneDesc->eyeLightSpecularColor = gfx_rt64_load_vector3(jscene, "eyeLightSpecularColor");
sceneDesc->skyDiffuseMultiplier = gfx_rt64_load_vector3(jscene, "skyDiffuseMultiplier", { 1.0f, 1.0f, 1.0f });
sceneDesc->skyHSLModifier = gfx_rt64_load_vector3(jscene, "skyHSLModifier");
sceneDesc->skyYawOffset = jscene.value("skyYawOffset", 0.0f);
sceneDesc->giDiffuseStrength = jscene.value("giDiffuseStrength", 0.7f);
sceneDesc->giSkyStrength = jscene.value("giSkyStrength", 0.35f);
}

json gfx_rt64_save_scene_description(RT64_SCENE_DESC *sceneDesc) {
Expand All @@ -120,7 +125,9 @@ json gfx_rt64_save_scene_description(RT64_SCENE_DESC *sceneDesc) {
jscene["ambientNoGIColor"] = gfx_rt64_save_vector3(sceneDesc->ambientNoGIColor);
jscene["eyeLightDiffuseColor"] = gfx_rt64_save_vector3(sceneDesc->eyeLightDiffuseColor);
jscene["eyeLightSpecularColor"] = gfx_rt64_save_vector3(sceneDesc->eyeLightSpecularColor);
jscene["skyDiffuseMultiplier"] = gfx_rt64_save_vector3(sceneDesc->skyDiffuseMultiplier);
jscene["skyHSLModifier"] = gfx_rt64_save_vector3(sceneDesc->skyHSLModifier);
jscene["skyYawOffset"] = sceneDesc->skyYawOffset;
jscene["giDiffuseStrength"] = sceneDesc->giDiffuseStrength;
jscene["giSkyStrength"] = sceneDesc->giSkyStrength;
return jscene;
Expand Down

0 comments on commit 583f1eb

Please sign in to comment.