Port rt64alpha to nightly.

This commit is contained in:
Dario 2021-04-09 14:01:20 -03:00
parent fc5cb66f07
commit 04779ce252
20 changed files with 34557 additions and 20 deletions

View File

@ -428,6 +428,11 @@ DEP_FILES := $(O_FILES:.o=.d) $(ULTRA_O_FILES:.o=.d) $(GODDARD_O_FILES:.o=.d) $(
# Segment elf files
SEG_FILES := $(SEGMENT_ELF_FILES) $(ACTOR_ELF_FILES) $(LEVEL_ELF_FILES)
# RT64 configuration files
ifeq ($(RENDER_API),RT64)
include Makefile_rt64
endif
##################### Compiler Options #######################
INCLUDE_CFLAGS := -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I .
ENDIAN_BITWIDTH := $(BUILD_DIR)/endian-and-bitwidth
@ -713,6 +718,9 @@ $(BASEPACK_LST): $(EXE)
@find actors -name \*.png -exec echo "{} gfx/{}" >> $(BASEPACK_LST) \;
@find levels -name \*.png -exec echo "{} gfx/{}" >> $(BASEPACK_LST) \;
@find textures -name \*.png -exec echo "{} gfx/{}" >> $(BASEPACK_LST) \;
ifeq ($(RENDER_API),RT64)
@find rt64/textures -name \*.png -exec echo "{} gfx/{}" >> $(BASEPACK_LST) \;
endif
# prepares the resource ZIP with base data
$(BASEPACK_PATH): $(BASEPACK_LST)

19
Makefile_rt64 Normal file
View File

@ -0,0 +1,19 @@
# RT64
# Based off the Makefile for Dynamic Options System (dynos)
RT64_INPUT_DIR := ./rt64
RT64_OUTPUT_DIR := $(BUILD_DIR)/$(BASEDIR)/rt64
RT64_COPY_TO_RES := \
mkdir -p $(RT64_INPUT_DIR); \
mkdir -p $(RT64_OUTPUT_DIR); \
for f in $(RT64_INPUT_DIR)/config/*.json; do \
[ -f "$$f" ] || continue; \
cp -f $$f $(RT64_OUTPUT_DIR)/$$(basename -- $$f); \
done;
RT64 := $(shell $(call RT64_COPY_TO_RES))
# Render96 - Compilation macro
ifeq ($(findstring src/text/libs,$(SRC_DIRS)),src/text/libs)
INCLUDE_CFLAGS += -DRENDER_96_ALPHA
endif

25533
include/json/json.hpp Normal file

File diff suppressed because it is too large Load Diff

284
include/rt64/rt64.h Normal file
View File

@ -0,0 +1,284 @@
//
// RT64
//
#ifndef RT64_H_INCLUDED
#define RT64_H_INCLUDED
#include <Windows.h>
#include <stdio.h>
// Material constants.
#define RT64_MATERIAL_FILTER_POINT 0
#define RT64_MATERIAL_FILTER_LINEAR 1
#define RT64_MATERIAL_ADDR_WRAP 0
#define RT64_MATERIAL_ADDR_MIRROR 1
#define RT64_MATERIAL_ADDR_CLAMP 2
#define RT64_MATERIAL_CC_SHADER_0 0
#define RT64_MATERIAL_CC_SHADER_INPUT_1 1
#define RT64_MATERIAL_CC_SHADER_INPUT_2 2
#define RT64_MATERIAL_CC_SHADER_INPUT_3 3
#define RT64_MATERIAL_CC_SHADER_INPUT_4 4
#define RT64_MATERIAL_CC_SHADER_TEXEL0 5
#define RT64_MATERIAL_CC_SHADER_TEXEL0A 6
#define RT64_MATERIAL_CC_SHADER_TEXEL1 7
// Material attributes.
#define RT64_ATTRIBUTE_NONE 0x0
#define RT64_ATTRIBUTE_IGNORE_NORMAL_FACTOR 0x1
#define RT64_ATTRIBUTE_NORMAL_MAP_SCALE 0x2
#define RT64_ATTRIBUTE_REFLECTION_FACTOR 0x4
#define RT64_ATTRIBUTE_REFLECTION_SHINE_FACTOR 0x8
#define RT64_ATTRIBUTE_REFRACTION_FACTOR 0x10
#define RT64_ATTRIBUTE_SPECULAR_INTENSITY 0x20
#define RT64_ATTRIBUTE_SPECULAR_EXPONENT 0x40
#define RT64_ATTRIBUTE_SOLID_ALPHA_MULTIPLIER 0x80
#define RT64_ATTRIBUTE_SHADOW_ALPHA_MULTIPLIER 0x100
#define RT64_ATTRIBUTE_SELF_LIGHT 0x200
#define RT64_ATTRIBUTE_LIGHT_GROUP_MASK_BITS 0x400
#define RT64_ATTRIBUTE_DIFFUSE_COLOR_MIX 0x800
// Mesh flags.
#define RT64_MESH_RAYTRACE_ENABLED 0x1
#define RT64_MESH_RAYTRACE_UPDATABLE 0x2
// Light flags.
#define RT64_LIGHT_GROUP_MASK_ALL 0xFFFFFFFF
#define RT64_LIGHT_GROUP_DEFAULT 0x1
#define RT64_LIGHT_MAX_SAMPLES 128
typedef struct {
float x, y;
} RT64_VECTOR2;
typedef struct {
float x, y, z;
} RT64_VECTOR3;
typedef struct {
float x, y, z, w;
} RT64_VECTOR4;
typedef struct {
float m[4][4];
} RT64_MATRIX4;
typedef struct {
RT64_VECTOR3 position;
RT64_VECTOR3 normal;
RT64_VECTOR2 uv;
RT64_VECTOR4 inputs[4];
} RT64_VERTEX;
typedef struct {
int background;
int filterMode;
int diffuseTexIndex;
int normalTexIndex;
int hAddressMode;
int vAddressMode;
float ignoreNormalFactor;
float normalMapScale;
float reflectionFactor;
float reflectionShineFactor;
float refractionFactor;
float specularIntensity;
float specularExponent;
float solidAlphaMultiplier;
float shadowAlphaMultiplier;
RT64_VECTOR3 selfLight;
unsigned int lightGroupMaskBits;
RT64_VECTOR3 fogColor;
RT64_VECTOR4 diffuseColorMix;
float fogMul;
float fogOffset;
// N64 Color combiner parameters.
int c0[4];
int c1[4];
int do_single[2];
int do_multiply[2];
int do_mix[2];
int color_alpha_same;
int opt_alpha;
int opt_fog;
int opt_texture_edge;
// Flag containing all attributes that are actually used by this material.
int enabledAttributes;
// Add padding to line up with the HLSL structure.
int _pad;
} RT64_MATERIAL;
// Light
typedef struct {
RT64_VECTOR3 position;
RT64_VECTOR3 diffuseColor;
float attenuationRadius;
float pointRadius;
float specularIntensity;
float shadowOffset;
float attenuationExponent;
float flickerIntensity;
unsigned int groupBits;
unsigned int minSamples;
unsigned int maxSamples;
} RT64_LIGHT;
// Forward declaration of types.
typedef struct RT64_DEVICE RT64_DEVICE;
typedef struct RT64_VIEW RT64_VIEW;
typedef struct RT64_SCENE RT64_SCENE;
typedef struct RT64_INSTANCE RT64_INSTANCE;
typedef struct RT64_MESH RT64_MESH;
typedef struct RT64_TEXTURE RT64_TEXTURE;
typedef struct RT64_INSPECTOR RT64_INSPECTOR;
inline void RT64_ApplyMaterialAttributes(RT64_MATERIAL *dst, RT64_MATERIAL *src) {
if (src->enabledAttributes & RT64_ATTRIBUTE_IGNORE_NORMAL_FACTOR) {
dst->ignoreNormalFactor = src->ignoreNormalFactor;
}
if (src->enabledAttributes & RT64_ATTRIBUTE_NORMAL_MAP_SCALE) {
dst->normalMapScale = src->normalMapScale;
}
if (src->enabledAttributes & RT64_ATTRIBUTE_REFLECTION_FACTOR) {
dst->reflectionFactor = src->reflectionFactor;
}
if (src->enabledAttributes & RT64_ATTRIBUTE_REFLECTION_SHINE_FACTOR) {
dst->reflectionShineFactor = src->reflectionShineFactor;
}
if (src->enabledAttributes & RT64_ATTRIBUTE_REFRACTION_FACTOR) {
dst->refractionFactor = src->refractionFactor;
}
if (src->enabledAttributes & RT64_ATTRIBUTE_SPECULAR_INTENSITY) {
dst->specularIntensity = src->specularIntensity;
}
if (src->enabledAttributes & RT64_ATTRIBUTE_SPECULAR_EXPONENT) {
dst->specularExponent = src->specularExponent;
}
if (src->enabledAttributes & RT64_ATTRIBUTE_SOLID_ALPHA_MULTIPLIER) {
dst->solidAlphaMultiplier = src->solidAlphaMultiplier;
}
if (src->enabledAttributes & RT64_ATTRIBUTE_SHADOW_ALPHA_MULTIPLIER) {
dst->shadowAlphaMultiplier = src->shadowAlphaMultiplier;
}
if (src->enabledAttributes & RT64_ATTRIBUTE_SELF_LIGHT) {
dst->selfLight = src->selfLight;
}
if (src->enabledAttributes & RT64_ATTRIBUTE_LIGHT_GROUP_MASK_BITS) {
dst->lightGroupMaskBits = src->lightGroupMaskBits;
}
if (src->enabledAttributes & RT64_ATTRIBUTE_DIFFUSE_COLOR_MIX) {
dst->diffuseColorMix = src->diffuseColorMix;
}
}
// Internal function pointer types.
typedef RT64_DEVICE* (*CreateDevicePtr)(void *hwnd);
typedef void(*DrawDevicePtr)(RT64_DEVICE* device, int vsyncInterval);
typedef void(*DestroyDevicePtr)(RT64_DEVICE* device);
typedef RT64_VIEW* (*CreateViewPtr)(RT64_SCENE* scenePtr);
typedef void(*SetViewPerspectivePtr)(RT64_VIEW* viewPtr, RT64_VECTOR3 eyePosition, RT64_VECTOR3 eyeFocus, RT64_VECTOR3 eyeUpDirection, float fovRadians, float nearDist, float farDist);
typedef void(*DestroyViewPtr)(RT64_VIEW* viewPtr);
typedef RT64_SCENE* (*CreateScenePtr)(RT64_DEVICE* devicePtr);
typedef void (*SetSceneLightsPtr)(RT64_SCENE* scenePtr, RT64_LIGHT* lightArray, int lightCount);
typedef void(*DestroyScenePtr)(RT64_SCENE* scenePtr);
typedef RT64_MESH* (*CreateMeshPtr)(RT64_DEVICE* devicePtr, int flags);
typedef void (*SetMeshPtr)(RT64_MESH* meshPtr, RT64_VERTEX* vertexArray, int vertexCount, unsigned int* indexArray, int indexCount);
typedef void (*DestroyMeshPtr)(RT64_MESH* meshPtr);
typedef RT64_INSTANCE* (*CreateInstancePtr)(RT64_SCENE* scenePtr);
typedef void (*SetInstancePtr)(RT64_INSTANCE* instancePtr, RT64_MESH* meshPtr, RT64_MATRIX4 transform, RT64_TEXTURE* diffuseTexture, RT64_TEXTURE* normalTexture, RT64_MATERIAL material);
typedef void (*DestroyInstancePtr)(RT64_INSTANCE* instancePtr);
typedef RT64_TEXTURE* (*CreateTextureFromRGBA8Ptr)(RT64_DEVICE* devicePtr, void* bytes, int width, int height, int stride);
typedef void(*DestroyTexturePtr)(RT64_TEXTURE* texture);
typedef RT64_INSPECTOR* (*CreateInspectorPtr)(RT64_DEVICE* devicePtr);
typedef bool(*HandleMessageInspectorPtr)(RT64_INSPECTOR* inspectorPtr, UINT msg, WPARAM wParam, LPARAM lParam);
typedef void (*SetMaterialInspectorPtr)(RT64_INSPECTOR* inspectorPtr, RT64_MATERIAL* material);
typedef void(*SetLightsInspectorPtr)(RT64_INSPECTOR* inspectorPtr, RT64_LIGHT* lights, int *lightCount, int maxLightCount);
typedef void(*PrintToInspectorPtr)(RT64_INSPECTOR* inspectorPtr, const char* message);
typedef void(*DestroyInspectorPtr)(RT64_INSPECTOR* inspectorPtr);
// Stores all the function pointers used in the RT64 library.
typedef struct {
HMODULE handle;
CreateDevicePtr CreateDevice;
DrawDevicePtr DrawDevice;
DestroyDevicePtr DestroyDevice;
CreateViewPtr CreateView;
SetViewPerspectivePtr SetViewPerspective;
DestroyViewPtr DestroyView;
CreateScenePtr CreateScene;
SetSceneLightsPtr SetSceneLights;
DestroyScenePtr DestroyScene;
CreateMeshPtr CreateMesh;
SetMeshPtr SetMesh;
DestroyMeshPtr DestroyMesh;
CreateInstancePtr CreateInstance;
SetInstancePtr SetInstance;
DestroyInstancePtr DestroyInstance;
CreateTextureFromRGBA8Ptr CreateTextureFromRGBA8;
DestroyTexturePtr DestroyTexture;
CreateInspectorPtr CreateInspector;
HandleMessageInspectorPtr HandleMessageInspector;
PrintToInspectorPtr PrintToInspector;
SetMaterialInspectorPtr SetMaterialInspector;
SetLightsInspectorPtr SetLightsInspector;
DestroyInspectorPtr DestroyInspector;
} RT64_LIBRARY;
// Define RT64_DEBUG for loading the debug DLL.
inline RT64_LIBRARY RT64_LoadLibrary() {
RT64_LIBRARY lib;
#ifdef RT64_DEBUG
lib.handle = LoadLibrary(TEXT("rt64libd.dll"));
#else
lib.handle = LoadLibrary(TEXT("rt64lib.dll"));
#endif
if (lib.handle != 0) {
lib.CreateDevice = (CreateDevicePtr)(GetProcAddress(lib.handle, "RT64_CreateDevice"));
lib.DrawDevice = (DrawDevicePtr)(GetProcAddress(lib.handle, "RT64_DrawDevice"));
lib.DestroyDevice = (DestroyDevicePtr)(GetProcAddress(lib.handle, "RT64_DestroyDevice"));
lib.CreateView = (CreateViewPtr)(GetProcAddress(lib.handle, "RT64_CreateView"));
lib.SetViewPerspective = (SetViewPerspectivePtr)(GetProcAddress(lib.handle, "RT64_SetViewPerspective"));
lib.DestroyView = (DestroyViewPtr)(GetProcAddress(lib.handle, "RT64_DestroyView"));
lib.CreateScene = (CreateScenePtr)(GetProcAddress(lib.handle, "RT64_CreateScene"));
lib.SetSceneLights = (SetSceneLightsPtr)(GetProcAddress(lib.handle, "RT64_SetSceneLights"));
lib.DestroyScene = (DestroyScenePtr)(GetProcAddress(lib.handle, "RT64_DestroyScene"));
lib.CreateMesh = (CreateMeshPtr)(GetProcAddress(lib.handle, "RT64_CreateMesh"));
lib.SetMesh = (SetMeshPtr)(GetProcAddress(lib.handle, "RT64_SetMesh"));
lib.DestroyMesh = (DestroyMeshPtr)(GetProcAddress(lib.handle, "RT64_DestroyMesh"));
lib.CreateInstance = (CreateInstancePtr)(GetProcAddress(lib.handle, "RT64_CreateInstance"));
lib.SetInstance = (SetInstancePtr)(GetProcAddress(lib.handle, "RT64_SetInstance"));
lib.DestroyInstance = (DestroyInstancePtr)(GetProcAddress(lib.handle, "RT64_DestroyInstance"));
lib.CreateTextureFromRGBA8 = (CreateTextureFromRGBA8Ptr)(GetProcAddress(lib.handle, "RT64_CreateTextureFromRGBA8"));
lib.DestroyTexture = (DestroyTexturePtr)(GetProcAddress(lib.handle, "RT64_DestroyTexture"));
lib.CreateInspector = (CreateInspectorPtr)(GetProcAddress(lib.handle, "RT64_CreateInspector"));
lib.HandleMessageInspector = (HandleMessageInspectorPtr)(GetProcAddress(lib.handle, "RT64_HandleMessageInspector"));
lib.SetMaterialInspector = (SetMaterialInspectorPtr)(GetProcAddress(lib.handle, "RT64_SetMaterialInspector"));
lib.SetLightsInspector = (SetLightsInspectorPtr)(GetProcAddress(lib.handle, "RT64_SetLightsInspector"));
lib.PrintToInspector = (PrintToInspectorPtr)(GetProcAddress(lib.handle, "RT64_PrintToInspector"));
lib.DestroyInspector = (DestroyInspectorPtr)(GetProcAddress(lib.handle, "RT64_DestroyInspector"));
}
return lib;
}
inline void RT64_UnloadLibrary(RT64_LIBRARY lib) {
FreeLibrary(lib.handle);
}
#endif

202
include/xxhash/xxhash64.h Normal file
View File

@ -0,0 +1,202 @@
// //////////////////////////////////////////////////////////
// xxhash64.h
// Copyright (c) 2016 Stephan Brumme. All rights reserved.
// see http://create.stephan-brumme.com/disclaimer.html
//
#pragma once
#include <stdint.h> // for uint32_t and uint64_t
/// XXHash (64 bit), based on Yann Collet's descriptions, see http://cyan4973.github.io/xxHash/
/** How to use:
uint64_t myseed = 0;
XXHash64 myhash(myseed);
myhash.add(pointerToSomeBytes, numberOfBytes);
myhash.add(pointerToSomeMoreBytes, numberOfMoreBytes); // call add() as often as you like to ...
// and compute hash:
uint64_t result = myhash.hash();
// or all of the above in one single line:
uint64_t result2 = XXHash64::hash(mypointer, numBytes, myseed);
Note: my code is NOT endian-aware !
**/
class XXHash64
{
public:
/// create new XXHash (64 bit)
/** @param seed your seed value, even zero is a valid seed **/
explicit XXHash64(uint64_t seed)
{
state[0] = seed + Prime1 + Prime2;
state[1] = seed + Prime2;
state[2] = seed;
state[3] = seed - Prime1;
bufferSize = 0;
totalLength = 0;
}
/// add a chunk of bytes
/** @param input pointer to a continuous block of data
@param length number of bytes
@return false if parameters are invalid / zero **/
bool add(const void* input, uint64_t length)
{
// no data ?
if (!input || length == 0)
return false;
totalLength += length;
// byte-wise access
const unsigned char* data = (const unsigned char*)input;
// unprocessed old data plus new data still fit in temporary buffer ?
if (bufferSize + length < MaxBufferSize)
{
// just add new data
while (length-- > 0)
buffer[bufferSize++] = *data++;
return true;
}
// point beyond last byte
const unsigned char* stop = data + length;
const unsigned char* stopBlock = stop - MaxBufferSize;
// some data left from previous update ?
if (bufferSize > 0)
{
// make sure temporary buffer is full (16 bytes)
while (bufferSize < MaxBufferSize)
buffer[bufferSize++] = *data++;
// process these 32 bytes (4x8)
process(buffer, state[0], state[1], state[2], state[3]);
}
// copying state to local variables helps optimizer A LOT
uint64_t s0 = state[0], s1 = state[1], s2 = state[2], s3 = state[3];
// 32 bytes at once
while (data <= stopBlock)
{
// local variables s0..s3 instead of state[0]..state[3] are much faster
process(data, s0, s1, s2, s3);
data += 32;
}
// copy back
state[0] = s0; state[1] = s1; state[2] = s2; state[3] = s3;
// copy remainder to temporary buffer
bufferSize = stop - data;
for (unsigned int i = 0; i < bufferSize; i++)
buffer[i] = data[i];
// done
return true;
}
/// get current hash
/** @return 64 bit XXHash **/
uint64_t hash() const
{
// fold 256 bit state into one single 64 bit value
uint64_t result;
if (totalLength >= MaxBufferSize)
{
result = rotateLeft(state[0], 1) +
rotateLeft(state[1], 7) +
rotateLeft(state[2], 12) +
rotateLeft(state[3], 18);
result = (result ^ processSingle(0, state[0])) * Prime1 + Prime4;
result = (result ^ processSingle(0, state[1])) * Prime1 + Prime4;
result = (result ^ processSingle(0, state[2])) * Prime1 + Prime4;
result = (result ^ processSingle(0, state[3])) * Prime1 + Prime4;
}
else
{
// internal state wasn't set in add(), therefore original seed is still stored in state2
result = state[2] + Prime5;
}
result += totalLength;
// process remaining bytes in temporary buffer
const unsigned char* data = buffer;
// point beyond last byte
const unsigned char* stop = data + bufferSize;
// at least 8 bytes left ? => eat 8 bytes per step
for (; data + 8 <= stop; data += 8)
result = rotateLeft(result ^ processSingle(0, *(uint64_t*)data), 27) * Prime1 + Prime4;
// 4 bytes left ? => eat those
if (data + 4 <= stop)
{
result = rotateLeft(result ^ (*(uint32_t*)data) * Prime1, 23) * Prime2 + Prime3;
data += 4;
}
// take care of remaining 0..3 bytes, eat 1 byte per step
while (data != stop)
result = rotateLeft(result ^ (*data++) * Prime5, 11) * Prime1;
// mix bits
result ^= result >> 33;
result *= Prime2;
result ^= result >> 29;
result *= Prime3;
result ^= result >> 32;
return result;
}
/// combine constructor, add() and hash() in one static function (C style)
/** @param input pointer to a continuous block of data
@param length number of bytes
@param seed your seed value, e.g. zero is a valid seed
@return 64 bit XXHash **/
static uint64_t hash(const void* input, uint64_t length, uint64_t seed)
{
XXHash64 hasher(seed);
hasher.add(input, length);
return hasher.hash();
}
private:
/// magic constants :-)
static const uint64_t Prime1 = 11400714785074694791ULL;
static const uint64_t Prime2 = 14029467366897019727ULL;
static const uint64_t Prime3 = 1609587929392839161ULL;
static const uint64_t Prime4 = 9650029242287828579ULL;
static const uint64_t Prime5 = 2870177450012600261ULL;
/// temporarily store up to 31 bytes between multiple add() calls
static const uint64_t MaxBufferSize = 31+1;
uint64_t state[4];
unsigned char buffer[MaxBufferSize];
unsigned int bufferSize;
uint64_t totalLength;
/// rotate bits, should compile to a single CPU instruction (ROL)
static inline uint64_t rotateLeft(uint64_t x, unsigned char bits)
{
return (x << bits) | (x >> (64 - bits));
}
/// process a single 64 bit value
static inline uint64_t processSingle(uint64_t previous, uint64_t input)
{
return rotateLeft(previous + input * Prime2, 31) * Prime1;
}
/// process a block of 4x4 bytes, this is the main part of the XXHash32 algorithm
static inline void process(const void* data, uint64_t& state0, uint64_t& state1, uint64_t& state2, uint64_t& state3)
{
const uint64_t* block = (const uint64_t*) data;
state0 = processSingle(state0, block[0]);
state1 = processSingle(state1, block[1]);
state2 = processSingle(state2, block[2]);
state3 = processSingle(state3, block[3]);
}
};

View File

@ -0,0 +1,869 @@
{
"geoLayouts": [
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "amp_geo"
},
{
"materialMod": null,
"name": "birds_geo"
},
{
"materialMod": null,
"name": "black_bobomb_geo"
},
{
"materialMod": null,
"name": "blargg_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "blue_coin_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "blue_coin_no_shadow_geo"
},
{
"materialMod": null,
"name": "blue_coin_switch_geo"
},
{
"lightMod": {
"attenuationExponent": 2.0,
"attenuationRadius": 300.0,
"diffuseColor": [
0.0,
0.20000000298023224,
0.800000011920929
],
"flickerIntensity": 0.0,
"groupBits": 64,
"pointRadius": 25.0,
"position": [
0.0,
0.0,
0.0
],
"shadowOffset": 25.0,
"specularIntensity": 1.0
},
"materialMod": {
"ignoreNormalFactor": 1.0,
"lightGroupMaskBits": 0,
"selfLight": [
0.699999988079071,
0.699999988079071,
0.699999988079071
]
},
"name": "blue_flame_geo"
},
{
"materialMod": null,
"name": "bobomb_buddy_geo"
},
{
"materialMod": null,
"name": "boo_castle_geo"
},
{
"materialMod": null,
"name": "boo_geo"
},
{
"materialMod": null,
"name": "bookend_geo"
},
{
"materialMod": null,
"name": "bookend_part_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "bowling_ball_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "bowling_ball_track_geo"
},
{
"materialMod": null,
"name": "bowser2_geo"
},
{
"materialMod": null,
"name": "bowser_1_yellow_sphere_geo"
},
{
"materialMod": null,
"name": "bowser_bomb_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "bowser_flames_geo"
},
{
"materialMod": null,
"name": "bowser_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "bowser_impact_smoke_geo"
},
{
"materialMod": null,
"name": "bowser_key_cutscene_geo"
},
{
"materialMod": null,
"name": "bowser_key_geo"
},
{
"materialMod": null,
"name": "breakable_box_geo"
},
{
"materialMod": null,
"name": "breakable_box_small_geo"
},
{
"materialMod": null,
"name": "bub_geo"
},
{
"materialMod": null,
"name": "bubba_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "bubble_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "bubbly_tree_geo"
},
{
"materialMod": null,
"name": "bullet_bill_geo"
},
{
"materialMod": null,
"name": "bully_boss_geo"
},
{
"materialMod": null,
"name": "bully_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "burn_smoke_geo"
},
{
"materialMod": null,
"name": "butterfly_geo"
},
{
"materialMod": null,
"name": "cabin_door_geo"
},
{
"materialMod": null,
"name": "cannon_barrel_geo"
},
{
"materialMod": null,
"name": "cannon_base_geo"
},
{
"materialMod": null,
"name": "cap_switch_geo"
},
{
"materialMod": null,
"name": "cartoon_star_geo"
},
{
"materialMod": null,
"name": "castle_door_0_star_geo"
},
{
"materialMod": null,
"name": "castle_door_1_star_geo"
},
{
"materialMod": null,
"name": "castle_door_3_stars_geo"
},
{
"materialMod": null,
"name": "castle_door_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "chain_chomp_geo"
},
{
"materialMod": null,
"name": "checkerboard_platform_geo"
},
{
"materialMod": null,
"name": "chilly_chief_big_geo"
},
{
"materialMod": null,
"name": "chilly_chief_geo"
},
{
"materialMod": null,
"name": "chuckya_geo"
},
{
"materialMod": null,
"name": "clam_shell_geo"
},
{
"materialMod": null,
"name": "cyan_fish_geo"
},
{
"materialMod": null,
"name": "dirt_animation_geo"
},
{
"materialMod": null,
"name": "dorrie_geo"
},
{
"materialMod": null,
"name": "enemy_lakitu_geo"
},
{
"materialMod": null,
"name": "exclamation_box_geo"
},
{
"materialMod": null,
"name": "exclamation_box_outline_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "explosion_geo"
},
{
"materialMod": null,
"name": "eyerok_left_hand_geo"
},
{
"materialMod": null,
"name": "eyerok_right_hand_geo"
},
{
"materialMod": null,
"name": "fish_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "fish_shadow_geo"
},
{
"materialMod": null,
"name": "flyguy_geo"
},
{
"materialMod": null,
"name": "fwoosh_geo"
},
{
"materialMod": null,
"name": "goomba_geo"
},
{
"materialMod": null,
"name": "haunted_cage_geo"
},
{
"materialMod": null,
"name": "haunted_chair_geo"
},
{
"materialMod": null,
"name": "haunted_door_geo"
},
{
"materialMod": null,
"name": "hazy_maze_door_geo"
},
{
"materialMod": null,
"name": "heart_geo"
},
{
"materialMod": null,
"name": "heave_ho_geo"
},
{
"materialMod": null,
"name": "hoot_geo"
},
{
"materialMod": null,
"name": "idle_water_wave_geo"
},
{
"materialMod": null,
"name": "invisible_bowser_accessory_geo"
},
{
"materialMod": null,
"name": "key_door_geo"
},
{
"materialMod": null,
"name": "king_bobomb_geo"
},
{
"materialMod": null,
"name": "klepto_geo"
},
{
"materialMod": null,
"name": "koopa_flag_geo"
},
{
"materialMod": null,
"name": "koopa_shell2_geo"
},
{
"materialMod": null,
"name": "koopa_shell3_geo"
},
{
"materialMod": null,
"name": "koopa_shell_geo"
},
{
"materialMod": null,
"name": "koopa_with_shell_geo"
},
{
"materialMod": null,
"name": "koopa_without_shell_geo"
},
{
"materialMod": null,
"name": "lakitu_geo"
},
{
"materialMod": null,
"name": "leaves_geo"
},
{
"materialMod": null,
"name": "mad_piano_geo"
},
{
"materialMod": null,
"name": "manta_seg5_geo_05008D14"
},
{
"materialMod": null,
"name": "mario_TODO_geo_0000E0"
},
{
"materialMod": null,
"name": "mario_geo"
},
{
"materialMod": null,
"name": "marios_cap_geo"
},
{
"materialMod": null,
"name": "marios_metal_cap_geo"
},
{
"materialMod": null,
"name": "marios_wing_cap_geo"
},
{
"materialMod": null,
"name": "marios_winged_metal_cap_geo"
},
{
"materialMod": null,
"name": "metal_box_geo"
},
{
"materialMod": null,
"name": "metal_door_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "metallic_ball_geo"
},
{
"materialMod": null,
"name": "mips_geo"
},
{
"materialMod": null,
"name": "mist_geo"
},
{
"materialMod": null,
"name": "moneybag_geo"
},
{
"materialMod": null,
"name": "monty_mole_geo"
},
{
"materialMod": null,
"name": "mr_blizzard_geo"
},
{
"materialMod": null,
"name": "mr_blizzard_hidden_geo"
},
{
"materialMod": null,
"name": "mr_i_geo"
},
{
"materialMod": null,
"name": "mr_i_iris_geo"
},
{
"lightMod": {
"attenuationExponent": 2.0,
"attenuationRadius": 500.0,
"diffuseColor": [
0.20000000298023224,
0.800000011920929,
0.0
],
"flickerIntensity": 0.0,
"groupBits": 16,
"pointRadius": 25.0,
"position": [
0.0,
0.0,
0.0
],
"shadowOffset": 25.0,
"specularIntensity": 1.0
},
"materialMod": {
"ignoreNormalFactor": 1.0,
"lightGroupMaskBits": 0,
"selfLight": [
0.699999988079071,
0.699999988079071,
0.699999988079071
]
},
"name": "mushroom_1up_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "number_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "palm_tree_geo"
},
{
"materialMod": null,
"name": "peach_geo"
},
{
"materialMod": null,
"name": "penguin_geo"
},
{
"materialMod": null,
"name": "piranha_plant_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "pokey_body_part_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "pokey_head_geo"
},
{
"materialMod": null,
"name": "purple_marble_geo"
},
{
"materialMod": null,
"name": "purple_switch_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "red_coin_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "red_coin_no_shadow_geo"
},
{
"lightMod": {
"attenuationExponent": 2.0,
"attenuationRadius": 300.0,
"diffuseColor": [
0.800000011920929,
0.20000000298023224,
0.0
],
"flickerIntensity": 0.0,
"groupBits": 64,
"pointRadius": 25.0,
"position": [
0.0,
0.0,
0.0
],
"shadowOffset": 25.0,
"specularIntensity": 1.0
},
"materialMod": {
"ignoreNormalFactor": 1.0,
"lightGroupMaskBits": 0,
"selfLight": [
0.699999988079071,
0.699999988079071,
0.699999988079071
]
},
"name": "red_flame_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "red_flame_shadow_geo"
},
{
"materialMod": null,
"name": "scuttlebug_geo"
},
{
"materialMod": null,
"name": "seaweed_geo"
},
{
"materialMod": null,
"name": "skeeter_geo"
},
{
"materialMod": null,
"name": "small_key_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "small_water_splash_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "smoke_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "snow_tree_geo"
},
{
"materialMod": null,
"name": "snufit_geo"
},
{
"lightMod": {
"attenuationExponent": 2.0,
"attenuationRadius": 100.0,
"diffuseColor": [
0.80000000298023224,
0.800000011920929,
0.0
],
"flickerIntensity": 0.0,
"groupBits": 128,
"pointRadius": 25.0,
"position": [
0.0,
0.0,
0.0
],
"shadowOffset": 25.0,
"specularIntensity": 1.0
},
"materialMod": {
"ignoreNormalFactor": 1.0,
"lightGroupMaskBits": 0,
"selfLight": [
0.699999988079071,
0.699999988079071,
0.699999988079071
]
},
"name": "sparkles_animation_geo"
},
{
"lightMod": {
"attenuationExponent": 2.0,
"attenuationRadius": 100.0,
"diffuseColor": [
0.80000000298023224,
0.800000011920929,
0.0
],
"flickerIntensity": 0.0,
"groupBits": 128,
"pointRadius": 25.0,
"position": [
0.0,
0.0,
0.0
],
"shadowOffset": 25.0,
"specularIntensity": 1.0
},
"materialMod": {
"ignoreNormalFactor": 1.0,
"lightGroupMaskBits": 0,
"selfLight": [
0.699999988079071,
0.699999988079071,
0.699999988079071
]
},
"name": "sparkles_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "spiky_tree1_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "spiky_tree_geo"
},
{
"materialMod": null,
"name": "spindrift_geo"
},
{
"materialMod": null,
"name": "spiny_ball_geo"
},
{
"materialMod": null,
"name": "spiny_geo"
},
{
"materialMod": null,
"name": "springboard_bottom_geo"
},
{
"materialMod": null,
"name": "springboard_spring_geo"
},
{
"materialMod": null,
"name": "springboard_top_geo"
},
{
"materialMod": null,
"name": "star_geo"
},
{
"materialMod": null,
"name": "sushi_geo"
},
{
"materialMod": null,
"name": "swoop_geo"
},
{
"materialMod": null,
"name": "thwomp_geo"
},
{
"materialMod": null,
"name": "toad_geo"
},
{
"materialMod": null,
"name": "transparent_star_geo"
},
{
"materialMod": null,
"name": "treasure_chest_base_geo"
},
{
"materialMod": null,
"name": "treasure_chest_lid_geo"
},
{
"materialMod": null,
"name": "tweester_geo"
},
{
"materialMod": null,
"name": "ukiki_geo"
},
{
"materialMod": null,
"name": "unagi_geo"
},
{
"materialMod": null,
"name": "warp_pipe_geo"
},
{
"materialMod": null,
"name": "water_bomb_geo"
},
{
"materialMod": null,
"name": "water_bomb_shadow_geo"
},
{
"materialMod": null,
"name": "water_mine_geo"
},
{
"materialMod": null,
"name": "water_ring_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "water_splash_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "wave_trail_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "white_particle_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "white_puff_geo"
},
{
"materialMod": null,
"name": "whomp_geo"
},
{
"materialMod": null,
"name": "wiggler_body_geo"
},
{
"materialMod": null,
"name": "wiggler_head_geo"
},
{
"materialMod": null,
"name": "wooden_door2_geo"
},
{
"materialMod": null,
"name": "wooden_door_geo"
},
{
"materialMod": null,
"name": "wooden_post_geo"
},
{
"materialMod": null,
"name": "wooden_signpost_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "yellow_coin_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "yellow_coin_no_shadow_geo"
},
{
"materialMod": {
"ignoreNormalFactor": 1.0
},
"name": "yellow_sphere_geo"
},
{
"materialMod": null,
"name": "yoshi_egg_geo"
},
{
"materialMod": null,
"name": "yoshi_geo"
}
]
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
{
"presets" : [
{
"name": "Default",
"lightSampleSettings": [
{
"groupBits": 1,
"minSamples": 8,
"maxSamples": 32
},
{
"groupBits": 2,
"minSamples": 8,
"maxSamples": 16
},
{
"groupBits": 16,
"minSamples": 8,
"maxSamples": 8
}
]
}
]
}

View File

@ -0,0 +1,139 @@
{
"textures": [
{
"lightMod": {
"attenuationExponent": 2.0,
"attenuationRadius": 2000.0,
"diffuseColor": [
1.2999999523162842,
1.2999999523162842,
0.20000000298023224
],
"flickerIntensity": 0.125,
"groupBits": 16,
"pointRadius": 25.0,
"position": [
0.0,
0.0,
0.0
],
"shadowOffset": 80.0,
"specularIntensity": 1.0
},
"materialMod": {
"lightGroupMaskBits": 0,
"selfLight": [
0.699999988079071,
0.699999988079071,
0.699999988079071
]
},
"name": "actors/amp/amp_body.rgba16"
},
{
"materialMod": {
"diffuseColorMix": [
0.0,
0.0,
0.0,
1.0
],
"reflectionFactor": 0.800000011920929,
"reflectionShineFactor": 1.0
},
"name": "actors/mario/mario_metal.rgba16"
},
{
"materialMod": {
"diffuseColorMix": [
0.0,
0.0,
0.0,
1.0
],
"reflectionFactor": 0.800000011920929,
"reflectionShineFactor": 1.0
},
"name": "actors/mario/mario_metal_new.rgba32"
},
{
"lightMod": {
"attenuationExponent": 2.0,
"attenuationRadius": 6000.0,
"diffuseColor": [
1.2999999523162842,
1.2999999523162842,
0.20000000298023224
],
"flickerIntensity": 0.0,
"groupBits": 16,
"pointRadius": 200.0,
"position": [
0.0,
0.0,
0.0
],
"shadowOffset": 600.0,
"specularIntensity": 1.0
},
"materialMod": {
"lightGroupMaskBits": 0,
"selfLight": [
0.699999988079071,
0.699999988079071,
0.699999988079071
]
},
"name": "actors/star/star_surface.rgba16"
},
{
"materialMod": {
"reflectionFactor": 0.10000000149011612
},
"name": "levels/bitdw/1.rgba16"
},
{
"materialMod": {
"reflectionFactor": 0.20000000298023224,
"refractionFactor": 0.8999999761581421
},
"name": "levels/bitdw/3.rgba16"
},
{
"materialMod": {
"diffuseColorMix": [
0.0,
0.0,
0.0,
0.699999988079071
],
"normalMapScale": 0.20000000298023224,
"reflectionFactor": 0.375,
"refractionFactor": 0.949999988079071,
"solidAlphaMultiplier": 0.75
},
"name": "textures/segment2/segment2.11C58.rgba16",
"normalMapMod": {
"name": "rt64/textures/normal_maps/water_nrm.rgba32"
}
},
{
"materialMod": {
"diffuseColorMix": [
0.0,
0.0,
0.0,
0.699999988079071
],
"normalMapScale": 0.20000000298023224,
"reflectionFactor": 0.375,
"refractionFactor": 0.949999988079071,
"solidAlphaMultiplier": 0.75
},
"name": "textures/segment2/segment2.12458.rgba16",
"normalMapMod": {
"name": "rt64/textures/normal_maps/water_nrm.rgba32"
}
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 MiB

View File

@ -6,6 +6,8 @@
#include "game/memory.h"
#include "graph_node.h"
#include "pc/gfx/gfx_pc.h"
typedef void (*GeoLayoutCommandProc)(void);
GeoLayoutCommandProc GeoLayoutJumpTable[] = {
@ -111,10 +113,22 @@ void geo_layout_cmd_branch_and_link(void) {
gGeoLayoutStack[gGeoLayoutStackIndex++] = (gCurGraphNodeIndex << 16) + gGeoLayoutReturnIndex;
gGeoLayoutReturnIndex = gGeoLayoutStackIndex;
gGeoLayoutCommand = segmented_to_virtual(cur_geo_cmd_ptr(0x04));
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
gfx_push_geo_layout(gGeoLayoutCommand);
#endif
}
// 0x01: Terminate geo layout
void geo_layout_cmd_end(void) {
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
s16 pop_count = (gGeoLayoutStackIndex - gGeoLayoutReturnIndex) + 1;
while (pop_count > 0) {
gfx_pop_geo_layout();
pop_count--;
}
#endif
gGeoLayoutStackIndex = gGeoLayoutReturnIndex;
gGeoLayoutReturnIndex = gGeoLayoutStack[--gGeoLayoutStackIndex] & 0xFFFF;
gCurGraphNodeIndex = gGeoLayoutStack[gGeoLayoutStackIndex] >> 16;
@ -129,13 +143,26 @@ void geo_layout_cmd_branch(void) {
if (cur_geo_cmd_u8(0x01) == 1) {
gGeoLayoutStack[gGeoLayoutStackIndex++] = (uintptr_t) (gGeoLayoutCommand + CMD_PROCESS_OFFSET(8));
}
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
else {
gfx_pop_geo_layout();
}
#endif
gGeoLayoutCommand = segmented_to_virtual(cur_geo_cmd_ptr(0x04));
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
gfx_push_geo_layout(gGeoLayoutCommand);
#endif
}
// 0x03: Return from branch
void geo_layout_cmd_return(void) {
gGeoLayoutCommand = (u8 *) gGeoLayoutStack[--gGeoLayoutStackIndex];
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
gfx_pop_geo_layout();
#endif
}
// 0x04: Open node
@ -450,6 +477,11 @@ void geo_layout_cmd_node_translation_rotation(void) {
graphNode = init_graph_node_translation_rotation(gGraphNodePool, NULL, drawingLayer, displayList,
translation, rotation);
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
gfx_register_graph_node_layout(graphNode);
#endif
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand = (u8 *) cmdPos;
@ -485,7 +517,11 @@ void geo_layout_cmd_node_translation(void) {
graphNode =
init_graph_node_translation(gGraphNodePool, NULL, drawingLayer, displayList, translation);
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
gfx_register_graph_node_layout(graphNode);
#endif
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand = (u8 *) cmdPos;
@ -520,7 +556,11 @@ void geo_layout_cmd_node_rotation(void) {
}
graphNode = init_graph_node_rotation(gGraphNodePool, NULL, drawingLayer, displayList, sp2c);
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
gfx_register_graph_node_layout(graphNode);
#endif
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand = (u8 *) cmdPos;
@ -549,7 +589,11 @@ void geo_layout_cmd_node_scale(void) {
}
graphNode = init_graph_node_scale(gGraphNodePool, NULL, drawingLayer, displayList, scale);
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
gfx_register_graph_node_layout(graphNode);
#endif
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
@ -579,7 +623,11 @@ void geo_layout_cmd_node_animated_part(void) {
graphNode =
init_graph_node_animated_part(gGraphNodePool, NULL, drawingLayer, displayList, translation);
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
gfx_register_graph_node_layout(graphNode);
#endif
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x0C << CMD_SIZE_SHIFT;
@ -612,7 +660,11 @@ void geo_layout_cmd_node_billboard(void) {
}
graphNode = init_graph_node_billboard(gGraphNodePool, NULL, drawingLayer, displayList, translation);
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
gfx_register_graph_node_layout(graphNode);
#endif
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand = (u8 *) cmdPos;
@ -629,7 +681,11 @@ void geo_layout_cmd_node_display_list(void) {
void *displayList = cur_geo_cmd_ptr(0x04);
graphNode = init_graph_node_display_list(gGraphNodePool, NULL, drawingLayer, displayList);
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
gfx_register_graph_node_layout(graphNode);
#endif
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
@ -782,6 +838,10 @@ struct GraphNode *process_geo_layout(struct AllocOnlyPool *pool, void *segptr) {
gGeoLayoutCommand = segmented_to_virtual(segptr);
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
gfx_register_graph_node_layout(graphNode);
#endif
gGraphNodePool = pool;
gGeoLayoutStack[0] = 0;

View File

@ -7,6 +7,8 @@
#include "types.h"
#include "game/memory.h"
#include "pc/gfx/gfx_pc.h"
#define GRAPH_RENDER_ACTIVE (1 << 0)
#define GRAPH_RENDER_CHILDREN_FIRST (1 << 1)
#define GRAPH_RENDER_BILLBOARD (1 << 2)
@ -117,6 +119,9 @@ struct GraphNodePerspective
*/
struct DisplayListNode
{
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
void *graph_node_mod;
#endif
Mtx *transform;
void *displayList;
struct DisplayListNode *next;

View File

@ -156,11 +156,20 @@ static void geo_process_master_list_sub(struct GraphNodeMasterList *node) {
if ((currList = node->listHeads[i]) != NULL) {
gDPSetRenderMode(gDisplayListHead++, modeList->modes[i], mode2List->modes[i]);
while (currList != NULL) {
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
// The NoOp Tag method is used to indicate the current material mod being used for
// the next display lists that will be rendered.
gDPNoOpTag(gDisplayListHead++, currList->graph_node_mod);
#endif
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(currList->transform),
G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH);
gSPDisplayList(gDisplayListHead++, currList->displayList);
currList = currList->next;
}
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
// Make sure the material mod is no longer used after all display lists are drawn.
gDPNoOpTag(gDisplayListHead++, NULL);
#endif
}
}
if (enableZBuffer != 0) {
@ -174,7 +183,12 @@ static void geo_process_master_list_sub(struct GraphNodeMasterList *node) {
* parameter. Look at the RenderModeContainer struct to see the corresponding
* render modes of layers.
*/
#ifndef GFX_ENABLE_GRAPH_NODE_MODS
static void geo_append_display_list(void *displayList, s16 layer) {
#else
static void geo_append_display_list(void *displayList, s16 layer, void *graph_node_mod) {
#endif
#ifdef F3DEX_GBI_2
gSPLookAt(gDisplayListHead++, &lookAt);
@ -183,6 +197,9 @@ static void geo_append_display_list(void *displayList, s16 layer) {
struct DisplayListNode *listNode =
alloc_only_pool_alloc(gDisplayListHeap, sizeof(struct DisplayListNode));
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
listNode->graph_node_mod = graph_node_mod;
#endif
listNode->transform = gMatStackFixed[gMatStackIndex];
listNode->displayList = displayList;
listNode->next = 0;
@ -249,6 +266,10 @@ static void geo_process_perspective(struct GraphNodePerspective *node) {
f32 aspect = (f32) gCurGraphNodeRoot->width / (f32) gCurGraphNodeRoot->height;
#endif
#ifdef GFX_SEPARATE_PROJECTIONS
gfx_set_camera_config(node->fov, node->near, node->far);
#endif
guPerspective(mtx, &perspNorm, node->fov, aspect, node->near, node->far, 1.0f);
gSPPerspNormalize(gDisplayListHead++, perspNorm);
@ -317,6 +338,12 @@ static void geo_process_camera(struct GraphNodeCamera *node) {
gMatStackIndex++;
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
#ifdef GFX_SEPARATE_PROJECTIONS
gfx_set_camera_vectors(node->pos[0], node->pos[1], node->pos[2], node->focus[0], node->focus[1], node->focus[2], 0, 1.0f, 0);
gfx_set_view_matrix(mtx->m);
#endif
if (node->fnNode.node.children != 0) {
gCurGraphNodeCamera = node;
node->matrixPtr = &gMatStack[gMatStackIndex];
@ -344,7 +371,11 @@ static void geo_process_translation_rotation(struct GraphNodeTranslationRotation
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
if (node->displayList != NULL) {
#ifndef GFX_ENABLE_GRAPH_NODE_MODS
geo_append_display_list(node->displayList, node->node.flags >> 8);
#else
geo_append_display_list(node->displayList, node->node.flags >> 8, gfx_get_graph_node_mod(node));
#endif
}
if (node->node.children != NULL) {
geo_process_node_and_siblings(node->node.children);
@ -369,7 +400,11 @@ static void geo_process_translation(struct GraphNodeTranslation *node) {
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
if (node->displayList != NULL) {
#ifndef GFX_ENABLE_GRAPH_NODE_MODS
geo_append_display_list(node->displayList, node->node.flags >> 8);
#else
geo_append_display_list(node->displayList, node->node.flags >> 8, gfx_get_graph_node_mod(node));
#endif
}
if (node->node.children != NULL) {
geo_process_node_and_siblings(node->node.children);
@ -392,7 +427,11 @@ static void geo_process_rotation(struct GraphNodeRotation *node) {
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
if (node->displayList != NULL) {
#ifndef GFX_ENABLE_GRAPH_NODE_MODS
geo_append_display_list(node->displayList, node->node.flags >> 8);
#else
geo_append_display_list(node->displayList, node->node.flags >> 8, gfx_get_graph_node_mod(node));
#endif
}
if (node->node.children != NULL) {
geo_process_node_and_siblings(node->node.children);
@ -416,7 +455,11 @@ static void geo_process_scale(struct GraphNodeScale *node) {
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
if (node->displayList != NULL) {
#ifndef GFX_ENABLE_GRAPH_NODE_MODS
geo_append_display_list(node->displayList, node->node.flags >> 8);
#else
geo_append_display_list(node->displayList, node->node.flags >> 8, gfx_get_graph_node_mod(node));
#endif
}
if (node->node.children != NULL) {
geo_process_node_and_siblings(node->node.children);
@ -449,7 +492,11 @@ static void geo_process_billboard(struct GraphNodeBillboard *node) {
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
if (node->displayList != NULL) {
#ifndef GFX_ENABLE_GRAPH_NODE_MODS
geo_append_display_list(node->displayList, node->node.flags >> 8);
#else
geo_append_display_list(node->displayList, node->node.flags >> 8, gfx_get_graph_node_mod(node));
#endif
}
if (node->node.children != NULL) {
geo_process_node_and_siblings(node->node.children);
@ -464,7 +511,11 @@ static void geo_process_billboard(struct GraphNodeBillboard *node) {
*/
static void geo_process_display_list(struct GraphNodeDisplayList *node) {
if (node->displayList != NULL) {
#ifndef GFX_ENABLE_GRAPH_NODE_MODS
geo_append_display_list(node->displayList, node->node.flags >> 8);
#else
geo_append_display_list(node->displayList, node->node.flags >> 8, gfx_get_graph_node_mod(node));
#endif
}
if (node->node.children != NULL) {
geo_process_node_and_siblings(node->node.children);
@ -481,7 +532,11 @@ static void geo_process_generated_list(struct GraphNodeGenerated *node) {
(struct AllocOnlyPool *) gMatStack[gMatStackIndex]);
if (list != 0) {
#ifndef GFX_ENABLE_GRAPH_NODE_MODS
geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(list), node->fnNode.node.flags >> 8);
#else
geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(list), node->fnNode.node.flags >> 8, gfx_get_graph_node_mod(node));
#endif
}
}
if (node->fnNode.node.children != NULL) {
@ -502,7 +557,11 @@ static void geo_process_background(struct GraphNodeBackground *node) {
(struct AllocOnlyPool *) gMatStack[gMatStackIndex]);
}
if (list != 0) {
#ifndef GFX_ENABLE_GRAPH_NODE_MODS
geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(list), node->fnNode.node.flags >> 8);
#else
geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(list), node->fnNode.node.flags >> 8, gfx_get_graph_node_mod(node));
#endif
} else if (gCurGraphNodeMasterList != NULL) {
#ifndef F3DEX_GBI_2E
Gfx *gfxStart = alloc_display_list(sizeof(Gfx) * 7);
@ -520,7 +579,11 @@ static void geo_process_background(struct GraphNodeBackground *node) {
gDPSetCycleType(gfx++, G_CYC_1CYCLE);
gSPEndDisplayList(gfx++);
#ifndef GFX_ENABLE_GRAPH_NODE_MODS
geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(gfxStart), 0);
#else
geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(gfxStart), 0, gfx_get_graph_node_mod(node));
#endif
}
if (node->fnNode.node.children != NULL) {
geo_process_node_and_siblings(node->fnNode.node.children);
@ -583,7 +646,11 @@ static void geo_process_animated_part(struct GraphNodeAnimatedPart *node) {
mtxf_to_mtx(matrixPtr, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = matrixPtr;
if (node->displayList != NULL) {
#ifndef GFX_ENABLE_GRAPH_NODE_MODS
geo_append_display_list(node->displayList, node->node.flags >> 8);
#else
geo_append_display_list(node->displayList, node->node.flags >> 8, gfx_get_graph_node_mod(node));
#endif
}
if (node->node.children != NULL) {
geo_process_node_and_siblings(node->node.children);
@ -630,6 +697,7 @@ void geo_set_animation_globals(struct GraphNodeObject_sub *node, s32 hasAnimatio
* the floor below it.
*/
static void geo_process_shadow(struct GraphNodeShadow *node) {
#ifndef GFX_DISABLE_SHADOWS
Gfx *shadowList;
Mat4 mtxf;
Vec3f shadowPos;
@ -687,6 +755,7 @@ static void geo_process_shadow(struct GraphNodeShadow *node) {
mtxf_mul(gMatStack[gMatStackIndex], mtxf, *gCurGraphNodeCamera->matrixPtr);
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
#ifndef GFX_ENABLE_GRAPH_NODE_MODS
if (gShadowAboveWaterOrLava == 1) {
geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(shadowList), 4);
} else if (gMarioOnIceOrCarpet == 1) {
@ -694,9 +763,20 @@ static void geo_process_shadow(struct GraphNodeShadow *node) {
} else {
geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(shadowList), 6);
}
#else
if (gShadowAboveWaterOrLava == 1) {
geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(shadowList), 4, gfx_get_graph_node_mod(node));
} else if (gMarioOnIceOrCarpet == 1) {
geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(shadowList), 5, gfx_get_graph_node_mod(node));
} else {
geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(shadowList), 6, gfx_get_graph_node_mod(node));
}
#endif
gMatStackIndex--;
}
}
#endif
if (node->node.children != NULL) {
geo_process_node_and_siblings(node->node.children);
}
@ -742,7 +822,7 @@ static int obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) {
if (node->node.flags & GRAPH_RENDER_INVISIBLE) {
return FALSE;
}
#ifndef GFX_DISABLE_FRUSTUM_CULLING
geo = node->sharedChild;
// ! @bug The aspect ratio is not accounted for. When the fov value is 45,
@ -786,6 +866,7 @@ static int obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) {
if (matrix[3][0] < -hScreenEdge - cullingRadius) {
return FALSE;
}
#endif
return TRUE;
}

View File

@ -46,7 +46,12 @@
#define RATIO_X (gfx_current_dimensions.width / (2.0f * HALF_SCREEN_WIDTH))
#define RATIO_Y (gfx_current_dimensions.height / (2.0f * HALF_SCREEN_HEIGHT))
#ifdef GFX_MAX_BUFFERED
#define MAX_BUFFERED GFX_MAX_BUFFERED
#else
#define MAX_BUFFERED 256
#endif
#define MAX_LIGHTS 2
#define MAX_VERTICES 64
@ -71,9 +76,14 @@ struct XYWidthHeight {
struct LoadedVertex {
float x, y, z, w;
#ifdef GFX_OUTPUT_NORMALS_TO_VBO
float nx, ny, nz;
#endif
float u, v;
struct RGBA color;
#ifndef GFX_DISABLE_CLIP_REJECT
uint8_t clip_rej;
#endif
};
struct TextureHashmapNode {
@ -199,11 +209,129 @@ static unsigned long get_time(void) {
return 0;
}
#ifdef GFX_SEPARATE_PROJECTIONS
#include "goddard/gd_math.h"
static struct Matrices {
float model_matrix[4][4];
float inv_model_matrix[4][4];
float view_matrix[4][4];
float inv_view_matrix[4][4];
float prev_model_matrix[4][4];
float offset_matrix[4][4];
bool model_matrix_used;
bool is_ortho;
} matrices;
void gfx_set_camera_config(float fov_degrees, float near_dist, float far_dist) {
gfx_rapi->set_camera_config(fov_degrees, near_dist, far_dist);
}
void gfx_set_camera_vectors(float pos_x, float pos_y, float pos_z, float focus_x, float focus_y, float focus_z, float up_x, float up_y, float up_z) {
gfx_rapi->set_camera_vectors(pos_x, pos_y, pos_z, focus_x, focus_y, focus_z, up_x, up_y, up_z);
}
void gfx_set_view_matrix(float mat[4][4]) {
memcpy(matrices.view_matrix, mat, sizeof(float) * 4 * 4);
gd_inverse_mat4f(&matrices.view_matrix, &matrices.inv_view_matrix);
}
void inverse_affine(Mat4f *src, Mat4f *dst) {
float m10 = (*src)[0][1], m11 = (*src)[1][1], m12 = (*src)[2][1];
float m20 = (*src)[0][2], m21 = (*src)[1][2], m22 = (*src)[2][2];
float t00 = m22 * m11 - m21 * m12;
float t10 = m20 * m12 - m22 * m10;
float t20 = m21 * m10 - m20 * m11;
float m00 = (*src)[0][0], m01 = (*src)[1][0], m02 = (*src)[2][0];
float invDet = 1.0f / (m00 * t00 + m01 * t10 + m02 * t20);
t00 *= invDet; t10 *= invDet; t20 *= invDet;
m00 *= invDet; m01 *= invDet; m02 *= invDet;
float r00 = t00;
float r01 = m02 * m21 - m01 * m22;
float r02 = m01 * m12 - m02 * m11;
float r10 = t10;
float r11 = m00 * m22 - m02 * m20;
float r12 = m02 * m10 - m00 * m12;
float r20 = t20;
float r21 = m01 * m20 - m00 * m21;
float r22 = m00 * m11 - m01 * m10;
float m03 = (*src)[3][0], m13 = (*src)[3][1], m23 = (*src)[3][2];
float r03 = -(r00 * m03 + r01 * m13 + r02 * m23);
float r13 = -(r10 * m03 + r11 * m13 + r12 * m23);
float r23 = -(r20 * m03 + r21 * m13 + r22 * m23);
(*dst)[0][0] = r00; (*dst)[1][0] = r01; (*dst)[2][0] = r02; (*dst)[3][0] = r03;
(*dst)[0][1] = r10; (*dst)[1][1] = r11; (*dst)[2][1] = r12; (*dst)[3][1] = r13;
(*dst)[0][2] = r20; (*dst)[1][2] = r21; (*dst)[2][2] = r22; (*dst)[3][2] = r23;
(*dst)[0][3] = 0.0f; (*dst)[1][3] = 0.0f; (*dst)[2][3] = 0.0f; (*dst)[3][3] = 1.0f;
}
void transform_loaded_vertex(size_t i, Mat4f *src) {
struct LoadedVertex *d = &rsp.loaded_vertices[i];
float x = d->x * (*src)[0][0] + d->y * (*src)[1][0] + d->z * (*src)[2][0] + (*src)[3][0];
float y = d->x * (*src)[0][1] + d->y * (*src)[1][1] + d->z * (*src)[2][1] + (*src)[3][1];
float z = d->x * (*src)[0][2] + d->y * (*src)[1][2] + d->z * (*src)[2][2] + (*src)[3][2];
d->x = x;
d->y = y;
d->z = z;
#ifdef GFX_OUTPUT_NORMALS_TO_VBO
float nx = d->nx * (*src)[0][0] + d->ny * (*src)[1][0] + d->nz * (*src)[2][0];
float ny = d->nx * (*src)[0][1] + d->ny * (*src)[1][1] + d->nz * (*src)[2][1];
float nz = d->nx * (*src)[0][2] + d->ny * (*src)[1][2] + d->nz * (*src)[2][2];
d->nx = nx;
d->ny = ny;
d->nz = nz;
#endif
}
#endif
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
void gfx_push_geo_layout(void *geo_layout) {
gfx_rapi->push_geo_layout(geo_layout);
}
void gfx_register_graph_node_layout(void *graph_node) {
gfx_rapi->register_graph_node_layout(graph_node);
}
void gfx_pop_geo_layout(void) {
gfx_rapi->pop_geo_layout();
}
void *gfx_get_graph_node_mod(void *graph_node) {
return gfx_rapi->get_graph_node_mod(graph_node);
}
#endif
static void gfx_flush(void) {
if (buf_vbo_len > 0) {
int num = buf_vbo_num_tris;
unsigned long t0 = get_time();
#ifndef GFX_SEPARATE_PROJECTIONS
gfx_rapi->draw_triangles(buf_vbo, buf_vbo_len, buf_vbo_num_tris);
#else
if (matrices.is_ortho) {
gfx_rapi->draw_triangles_ortho(buf_vbo, buf_vbo_len, buf_vbo_num_tris);
}
else {
gfx_rapi->draw_triangles_persp(buf_vbo, buf_vbo_len, buf_vbo_num_tris, matrices.model_matrix);
}
#endif
buf_vbo_len = 0;
buf_vbo_num_tris = 0;
unsigned long t1 = get_time();
@ -315,7 +443,11 @@ static bool gfx_texture_cache_lookup(int tile, struct TextureHashmapNode **n, co
}
*node = &gfx_texture_cache.pool[gfx_texture_cache.pool_pos++];
if ((*node)->texture_addr == NULL) {
#ifndef GFX_REQUIRE_TEXTURE_HASH
(*node)->texture_id = gfx_rapi->new_texture();
#else
(*node)->texture_id = gfx_rapi->new_texture(string_hash(orig_addr));
#endif
}
gfx_rapi->select_texture(tile, (*node)->texture_id);
gfx_rapi->set_sampler_parameters(tile, false, 0, 0);
@ -734,6 +866,11 @@ static void gfx_sp_matrix(uint8_t parameters, const int32_t *addr) {
rsp.lights_changed = 1;
}
gfx_matrix_mul(rsp.MP_matrix, rsp.modelview_matrix_stack[rsp.modelview_matrix_stack_size - 1], rsp.P_matrix);
#ifdef GFX_SEPARATE_PROJECTIONS
gfx_matrix_mul(matrices.model_matrix, rsp.modelview_matrix_stack[rsp.modelview_matrix_stack_size - 1], matrices.inv_view_matrix);
matrices.is_ortho = (rsp.P_matrix[3][3] != 0.0f);
#endif
}
static void gfx_sp_pop_matrix(uint32_t count) {
@ -742,6 +879,11 @@ static void gfx_sp_pop_matrix(uint32_t count) {
--rsp.modelview_matrix_stack_size;
if (rsp.modelview_matrix_stack_size > 0) {
gfx_matrix_mul(rsp.MP_matrix, rsp.modelview_matrix_stack[rsp.modelview_matrix_stack_size - 1], rsp.P_matrix);
#ifdef GFX_SEPARATE_PROJECTIONS
gfx_matrix_mul(matrices.model_matrix, rsp.modelview_matrix_stack[rsp.modelview_matrix_stack_size - 1], matrices.inv_view_matrix);
matrices.is_ortho = (rsp.P_matrix[3][3] != 0.0f);
#endif
}
}
}
@ -752,22 +894,62 @@ static float gfx_adjust_x_for_aspect_ratio(float x) {
}
static void gfx_sp_vertex(size_t n_vertices, size_t dest_index, const Vtx *vertices) {
#ifdef GFX_SEPARATE_PROJECTIONS
if (!matrices.model_matrix_used) {
if (dest_index > 0) {
inverse_affine(&matrices.model_matrix, &matrices.inv_model_matrix);
gfx_matrix_mul(matrices.offset_matrix, matrices.prev_model_matrix, matrices.inv_model_matrix);
for (size_t i = 0; i < dest_index; i++) {
transform_loaded_vertex(i, &matrices.offset_matrix);
}
for (size_t i = dest_index + n_vertices; i < MAX_VERTICES; i++) {
transform_loaded_vertex(i, &matrices.offset_matrix);
}
}
memcpy(matrices.prev_model_matrix, matrices.model_matrix, sizeof(float) * 16);
matrices.model_matrix_used = true;
}
#endif
for (size_t i = 0; i < n_vertices; i++, dest_index++) {
const Vtx_t *v = &vertices[i].v;
const Vtx_tn *vn = &vertices[i].n;
struct LoadedVertex *d = &rsp.loaded_vertices[dest_index];
#ifndef GFX_SEPARATE_PROJECTIONS
float x = v->ob[0] * rsp.MP_matrix[0][0] + v->ob[1] * rsp.MP_matrix[1][0] + v->ob[2] * rsp.MP_matrix[2][0] + rsp.MP_matrix[3][0];
float y = v->ob[0] * rsp.MP_matrix[0][1] + v->ob[1] * rsp.MP_matrix[1][1] + v->ob[2] * rsp.MP_matrix[2][1] + rsp.MP_matrix[3][1];
float z = v->ob[0] * rsp.MP_matrix[0][2] + v->ob[1] * rsp.MP_matrix[1][2] + v->ob[2] * rsp.MP_matrix[2][2] + rsp.MP_matrix[3][2];
float w = v->ob[0] * rsp.MP_matrix[0][3] + v->ob[1] * rsp.MP_matrix[1][3] + v->ob[2] * rsp.MP_matrix[2][3] + rsp.MP_matrix[3][3];
x = gfx_adjust_x_for_aspect_ratio(x);
#else
float x, y, z, w;
if (matrices.is_ortho) {
x = v->ob[0] * rsp.MP_matrix[0][0] + v->ob[1] * rsp.MP_matrix[1][0] + v->ob[2] * rsp.MP_matrix[2][0] + rsp.MP_matrix[3][0];
y = v->ob[0] * rsp.MP_matrix[0][1] + v->ob[1] * rsp.MP_matrix[1][1] + v->ob[2] * rsp.MP_matrix[2][1] + rsp.MP_matrix[3][1];
z = v->ob[0] * rsp.MP_matrix[0][2] + v->ob[1] * rsp.MP_matrix[1][2] + v->ob[2] * rsp.MP_matrix[2][2] + rsp.MP_matrix[3][2];
w = v->ob[0] * rsp.MP_matrix[0][3] + v->ob[1] * rsp.MP_matrix[1][3] + v->ob[2] * rsp.MP_matrix[2][3] + rsp.MP_matrix[3][3];
x = gfx_adjust_x_for_aspect_ratio(x);
}
else {
x = v->ob[0];
y = v->ob[1];
z = v->ob[2];
w = 1.0f;
}
#endif
short U = v->tc[0] * rsp.texture_scaling_factor.s >> 16;
short V = v->tc[1] * rsp.texture_scaling_factor.t >> 16;
if (rsp.geometry_mode & G_LIGHTING) {
#ifdef GFX_OUTPUT_NORMALS_TO_VBO
d->nx = vn->n[0] / 127.0f;
d->ny = vn->n[1] / 127.0f;
d->nz = vn->n[2] / 127.0f;
#endif
if (rsp.lights_changed) {
for (int i = 0; i < rsp.current_num_lights - 1; i++) {
calculate_normal_dir(&rsp.current_lights[i], rsp.current_lights_coeffs[i]);
@ -782,7 +964,7 @@ static void gfx_sp_vertex(size_t n_vertices, size_t dest_index, const Vtx *verti
int r = rsp.current_lights[rsp.current_num_lights - 1].col[0];
int g = rsp.current_lights[rsp.current_num_lights - 1].col[1];
int b = rsp.current_lights[rsp.current_num_lights - 1].col[2];
#ifndef GFX_DISABLE_LIGHTING
for (int i = 0; i < rsp.current_num_lights - 1; i++) {
float intensity = 0;
intensity += vn->n[0] * rsp.current_lights_coeffs[i][0];
@ -795,7 +977,15 @@ static void gfx_sp_vertex(size_t n_vertices, size_t dest_index, const Vtx *verti
b += intensity * rsp.current_lights[i].col[2];
}
}
#else
// Simulated flat lighting with arbitrary value of the first light.
// This can probably be estimated in a more accurate way to get a
// better color value.
float intensity = 0.6f;
r += intensity * rsp.current_lights[0].col[0];
g += intensity * rsp.current_lights[0].col[1];
b += intensity * rsp.current_lights[0].col[2];
#endif
d->color.r = r > 255 ? 255 : r;
d->color.g = g > 255 ? 255 : g;
d->color.b = b > 255 ? 255 : b;
@ -813,6 +1003,11 @@ static void gfx_sp_vertex(size_t n_vertices, size_t dest_index, const Vtx *verti
V = (int32_t)((doty / 127.0f + 1.0f) / 4.0f * rsp.texture_scaling_factor.t);
}
} else {
#ifdef GFX_OUTPUT_NORMALS_TO_VBO
d->nx = 0.0f;
d->ny = 0.0f;
d->nz = 0.0f;
#endif
d->color.r = v->cn[0];
d->color.g = v->cn[1];
d->color.b = v->cn[2];
@ -820,7 +1015,7 @@ static void gfx_sp_vertex(size_t n_vertices, size_t dest_index, const Vtx *verti
d->u = U;
d->v = V;
#ifndef GFX_DISABLE_CLIP_REJECT
// trivial clip rejection
d->clip_rej = 0;
if (x < -w) d->clip_rej |= 1;
@ -829,13 +1024,14 @@ static void gfx_sp_vertex(size_t n_vertices, size_t dest_index, const Vtx *verti
if (y > w) d->clip_rej |= 8;
if (z < -w) d->clip_rej |= 16;
if (z > w) d->clip_rej |= 32;
#endif
d->x = x;
d->y = y;
d->z = z;
d->w = w;
if (rsp.geometry_mode & G_FOG) {
#ifndef GFX_SEPARATE_FOG
if (fabsf(w) < 0.001f) {
// To avoid division by zero
w = 0.001f;
@ -850,6 +1046,9 @@ static void gfx_sp_vertex(size_t n_vertices, size_t dest_index, const Vtx *verti
if (fog_z < 0) fog_z = 0;
if (fog_z > 255) fog_z = 255;
d->color.a = fog_z; // Use alpha variable to store fog factor
#else
d->color.a = 1.0f;
#endif
} else {
d->color.a = v->cn[3];
}
@ -863,12 +1062,12 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx) {
struct LoadedVertex *v_arr[3] = {v1, v2, v3};
//if (rand()%2) return;
#ifndef GFX_DISABLE_CLIP_REJECT
if (v1->clip_rej & v2->clip_rej & v3->clip_rej) {
// The whole triangle lies outside the visible area
return;
}
#endif
if ((rsp.geometry_mode & G_CULL_BOTH) != 0) {
float dx1 = v1->x / (v1->w) - v2->x / (v2->w);
float dy1 = v1->y / (v1->w) - v2->y / (v2->w);
@ -984,12 +1183,22 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx) {
}
}
}
#ifdef GFX_SEPARATE_FOG
if (use_fog) {
gfx_rapi->set_fog(rdp.fog_color.r, rdp.fog_color.g, rdp.fog_color.b, rsp.fog_mul, rsp.fog_offset);
}
#endif
bool use_texture = used_textures[0] || used_textures[1];
uint32_t tex_width = (rdp.texture_tile.lrs - rdp.texture_tile.uls + 4) / 4;
uint32_t tex_height = (rdp.texture_tile.lrt - rdp.texture_tile.ult + 4) / 4;
bool z_is_from_0_to_1 = gfx_rapi->z_is_from_0_to_1();
#ifndef GFX_SEPARATE_PROJECTIONS
bool z_is_from_0_to_1 = gfx_rapi->z_is_from_0_to_1();
#else
bool z_is_from_0_to_1 = matrices.is_ortho && gfx_rapi->z_is_from_0_to_1();
#endif
for (int i = 0; i < 3; i++) {
float z = v_arr[i]->z, w = v_arr[i]->w;
@ -1000,7 +1209,11 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx) {
buf_vbo[buf_vbo_len++] = v_arr[i]->y;
buf_vbo[buf_vbo_len++] = z;
buf_vbo[buf_vbo_len++] = w;
#ifdef GFX_OUTPUT_NORMALS_TO_VBO
buf_vbo[buf_vbo_len++] = v_arr[i]->nx;
buf_vbo[buf_vbo_len++] = v_arr[i]->ny;
buf_vbo[buf_vbo_len++] = v_arr[i]->nz;
#endif
if (use_texture) {
float u = (v_arr[i]->u - rdp.texture_tile.uls * 8) / 32.0f;
float v = (v_arr[i]->v - rdp.texture_tile.ult * 8) / 32.0f;
@ -1012,14 +1225,14 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx) {
buf_vbo[buf_vbo_len++] = u / tex_width;
buf_vbo[buf_vbo_len++] = v / tex_height;
}
#ifndef GFX_SEPARATE_FOG
if (use_fog) {
buf_vbo[buf_vbo_len++] = rdp.fog_color.r / 255.0f;
buf_vbo[buf_vbo_len++] = rdp.fog_color.g / 255.0f;
buf_vbo[buf_vbo_len++] = rdp.fog_color.b / 255.0f;
buf_vbo[buf_vbo_len++] = v_arr[i]->color.a / 255.0f; // fog factor (not alpha)
}
#endif
for (int j = 0; j < num_inputs; j++) {
struct RGBA *color;
struct RGBA tmp;
@ -1564,6 +1777,12 @@ static void gfx_run_dl(Gfx* cmd) {
}
break;
case (uint8_t)G_ENDDL:
#ifdef GFX_FLUSH_ON_ENDDL
gfx_flush();
#endif
#ifdef GFX_SEPARATE_PROJECTIONS
matrices.model_matrix_used = false;
#endif
return;
#ifdef F3DEX_GBI_2
case G_GEOMETRYMODE:
@ -1704,6 +1923,11 @@ static void gfx_run_dl(Gfx* cmd) {
case G_SETCIMG:
gfx_dp_set_color_image(C0(21, 3), C0(19, 2), C0(0, 11), seg_addr(cmd->words.w1));
break;
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
case G_NOOP:
gfx_rapi->set_graph_node_mod((void *)(cmd->words.w1));
break;
#endif
}
++cmd;
}

View File

@ -1,7 +1,8 @@
#ifndef GFX_PC_H
#define GFX_PC_H
struct GfxRenderingAPI;
#include "gfx_rendering_api.h"
struct GfxWindowManagerAPI;
struct GfxDimensions {
@ -23,6 +24,19 @@ void gfx_end_frame(void);
void gfx_precache_textures(void);
void gfx_shutdown(void);
#ifdef GFX_SEPARATE_PROJECTIONS
void gfx_set_camera_config(float fov_degrees, float near_dist, float far_dist);
void gfx_set_camera_vectors(float pos_x, float pos_y, float pos_z, float focus_x, float focus_y, float focus_z, float up_x, float up_y, float up_z);
void gfx_set_view_matrix(float mat[4][4]);
#endif
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
void gfx_push_geo_layout(void *geo_layout);
void gfx_register_graph_node_layout(void *graph_node);
void gfx_pop_geo_layout(void);
void *gfx_get_graph_node_mod(void *graph_node);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -5,6 +5,20 @@
#include <stdint.h>
#include <stdbool.h>
#ifdef RAPI_RT64
# define GFX_MAX_BUFFERED 16384
# define GFX_DISABLE_SHADOWS
# define GFX_DISABLE_FRUSTUM_CULLING
# define GFX_DISABLE_LIGHTING
# define GFX_DISABLE_CLIP_REJECT
# define GFX_FLUSH_ON_ENDDL
# define GFX_OUTPUT_NORMALS_TO_VBO
# define GFX_SEPARATE_PROJECTIONS
# define GFX_SEPARATE_FOG
# define GFX_REQUIRE_TEXTURE_HASH
# define GFX_ENABLE_GRAPH_NODE_MODS
#endif
struct ShaderProgram;
struct GfxRenderingAPI {
@ -14,7 +28,11 @@ struct GfxRenderingAPI {
struct ShaderProgram *(*create_and_load_new_shader)(uint32_t shader_id);
struct ShaderProgram *(*lookup_shader)(uint32_t shader_id);
void (*shader_get_info)(struct ShaderProgram *prg, uint8_t *num_inputs, bool used_textures[2]);
#ifndef GFX_REQUIRE_TEXTURE_HASH
uint32_t (*new_texture)(void);
#else
uint32_t (*new_texture)(uint64_t hash);
#endif
void (*select_texture)(int tile, uint32_t texture_id);
void (*upload_texture)(const uint8_t *rgba32_buf, int width, int height);
void (*set_sampler_parameters)(int sampler, bool linear_filter, uint32_t cms, uint32_t cmt);
@ -24,7 +42,24 @@ struct GfxRenderingAPI {
void (*set_viewport)(int x, int y, int width, int height);
void (*set_scissor)(int x, int y, int width, int height);
void (*set_use_alpha)(bool use_alpha);
#ifdef GFX_SEPARATE_FOG
void (*set_fog)(uint8_t fog_r, uint8_t fog_g, uint8_t fog_b, int16_t fog_mul, int16_t fog_offset);
#endif
#ifndef GFX_SEPARATE_PROJECTIONS
void (*draw_triangles)(float buf_vbo[], size_t buf_vbo_len, size_t buf_vbo_num_tris);
#else
void (*set_camera_config)(float fov_degrees, float near_dist, float far_dist);
void (*set_camera_vectors)(float pos_x, float pos_y, float pos_z, float focus_x, float focus_y, float focus_z, float up_x, float up_y, float up_z);
void (*draw_triangles_ortho)(float buf_vbo[], size_t buf_vbo_len, size_t buf_vbo_num_tris);
void (*draw_triangles_persp)(float buf_vbo[], size_t buf_vbo_len, size_t buf_vbo_num_tris, float transform_affine[4][4]);
#endif
#ifdef GFX_ENABLE_GRAPH_NODE_MODS
void (*push_geo_layout)(void *geo_layout);
void (*register_graph_node_layout)(void *graph_node);
void (*pop_geo_layout)(void);
void *(*get_graph_node_mod)(void *graph_node);
void (*set_graph_node_mod)(void *graph_node_mod);
#endif
void (*init)(void);
void (*on_resize)(void);
void (*start_frame)(void);

1633
src/pc/gfx/gfx_rt64.cpp Normal file

File diff suppressed because it is too large Load Diff

10
src/pc/gfx/gfx_rt64.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef GFX_RT64_H
#define GFX_RT64_H
#include "gfx_window_manager_api.h"
#include "gfx_rendering_api.h"
extern struct GfxWindowManagerAPI gfx_rt64_wapi;
extern struct GfxRenderingAPI gfx_rt64_rapi;
#endif

View File

@ -0,0 +1,200 @@
#ifndef GFX_RT64_GEO_MAP_H
#define GFX_RT64_GEO_MAP_H
#include <map>
#include <string>
#include "actors/group0.h"
#include "actors/group1.h"
#include "actors/group2.h"
#include "actors/group3.h"
#include "actors/group4.h"
#include "actors/group5.h"
#include "actors/group6.h"
#include "actors/group7.h"
#include "actors/group8.h"
#include "actors/group9.h"
#include "actors/group10.h"
#include "actors/group11.h"
#include "actors/group12.h"
#include "actors/group13.h"
#include "actors/group14.h"
#include "actors/group15.h"
#include "actors/group16.h"
#include "actors/group17.h"
#include "actors/common0.h"
#include "actors/common1.h"
#define FILL_GEO_MAPS(x) geoNameMap[(void *)(x)] = #x; nameGeoMap[#x] = (void *)(x)
inline void gfx_rt64_init_geo_layout_maps(std::unordered_map<void *, std::string> &geoNameMap, std::map<std::string, void *> &nameGeoMap) {
FILL_GEO_MAPS(mario_geo);
FILL_GEO_MAPS(amp_geo);
FILL_GEO_MAPS(birds_geo);
FILL_GEO_MAPS(blargg_geo);
FILL_GEO_MAPS(blue_coin_switch_geo);
FILL_GEO_MAPS(fish_shadow_geo);
FILL_GEO_MAPS(fish_geo);
FILL_GEO_MAPS(black_bobomb_geo);
FILL_GEO_MAPS(bobomb_buddy_geo);
FILL_GEO_MAPS(bowser_bomb_geo);
FILL_GEO_MAPS(boo_geo);
FILL_GEO_MAPS(boo_castle_geo);
FILL_GEO_MAPS(bookend_geo);
FILL_GEO_MAPS(bookend_part_geo);
FILL_GEO_MAPS(bowling_ball_geo);
FILL_GEO_MAPS(bowling_ball_track_geo);
FILL_GEO_MAPS(bowser_geo);
FILL_GEO_MAPS(bowser2_geo);
FILL_GEO_MAPS(bowser_flames_geo);
FILL_GEO_MAPS(bowser_key_geo);
FILL_GEO_MAPS(bowser_key_cutscene_geo);
FILL_GEO_MAPS(breakable_box_geo);
FILL_GEO_MAPS(breakable_box_small_geo);
FILL_GEO_MAPS(bub_geo);
FILL_GEO_MAPS(bubba_geo);
FILL_GEO_MAPS(bubble_geo);
FILL_GEO_MAPS(purple_marble_geo);
FILL_GEO_MAPS(bullet_bill_geo);
FILL_GEO_MAPS(bully_geo);
FILL_GEO_MAPS(bully_boss_geo);
FILL_GEO_MAPS(burn_smoke_geo);
FILL_GEO_MAPS(butterfly_geo);
FILL_GEO_MAPS(cannon_barrel_geo);
FILL_GEO_MAPS(cannon_base_geo);
FILL_GEO_MAPS(cap_switch_geo);
FILL_GEO_MAPS(metallic_ball_geo);
FILL_GEO_MAPS(chain_chomp_geo);
FILL_GEO_MAPS(haunted_chair_geo);
FILL_GEO_MAPS(checkerboard_platform_geo);
FILL_GEO_MAPS(chilly_chief_geo);
FILL_GEO_MAPS(chilly_chief_big_geo);
FILL_GEO_MAPS(chuckya_geo);
FILL_GEO_MAPS(clam_shell_geo);
FILL_GEO_MAPS(yellow_coin_geo);
FILL_GEO_MAPS(yellow_coin_no_shadow_geo);
FILL_GEO_MAPS(blue_coin_geo);
FILL_GEO_MAPS(blue_coin_no_shadow_geo);
FILL_GEO_MAPS(red_coin_geo);
FILL_GEO_MAPS(red_coin_no_shadow_geo);
FILL_GEO_MAPS(cyan_fish_geo);
FILL_GEO_MAPS(dirt_animation_geo);
FILL_GEO_MAPS(cartoon_star_geo);
FILL_GEO_MAPS(castle_door_geo);
FILL_GEO_MAPS(cabin_door_geo);
FILL_GEO_MAPS(wooden_door_geo);
FILL_GEO_MAPS(wooden_door2_geo);
FILL_GEO_MAPS(metal_door_geo);
FILL_GEO_MAPS(hazy_maze_door_geo);
FILL_GEO_MAPS(haunted_door_geo);
FILL_GEO_MAPS(castle_door_0_star_geo);
FILL_GEO_MAPS(castle_door_1_star_geo);
FILL_GEO_MAPS(castle_door_3_stars_geo);
FILL_GEO_MAPS(key_door_geo);
FILL_GEO_MAPS(dorrie_geo);
FILL_GEO_MAPS(exclamation_box_geo);
FILL_GEO_MAPS(exclamation_box_outline_geo);
FILL_GEO_MAPS(explosion_geo);
FILL_GEO_MAPS(eyerok_left_hand_geo);
FILL_GEO_MAPS(eyerok_right_hand_geo);
FILL_GEO_MAPS(red_flame_shadow_geo);
FILL_GEO_MAPS(red_flame_geo);
FILL_GEO_MAPS(blue_flame_geo);
FILL_GEO_MAPS(flyguy_geo);
FILL_GEO_MAPS(fwoosh_geo);
FILL_GEO_MAPS(goomba_geo);
FILL_GEO_MAPS(haunted_cage_geo);
FILL_GEO_MAPS(heart_geo);
FILL_GEO_MAPS(heave_ho_geo);
FILL_GEO_MAPS(hoot_geo);
FILL_GEO_MAPS(invisible_bowser_accessory_geo);
FILL_GEO_MAPS(bowser_impact_smoke_geo);
FILL_GEO_MAPS(king_bobomb_geo);
FILL_GEO_MAPS(klepto_geo);
FILL_GEO_MAPS(koopa_without_shell_geo);
FILL_GEO_MAPS(koopa_with_shell_geo);
FILL_GEO_MAPS(koopa_flag_geo);
FILL_GEO_MAPS(koopa_shell_geo);
FILL_GEO_MAPS(koopa_shell2_geo);
FILL_GEO_MAPS(koopa_shell3_geo);
FILL_GEO_MAPS(lakitu_geo);
FILL_GEO_MAPS(enemy_lakitu_geo);
FILL_GEO_MAPS(leaves_geo);
FILL_GEO_MAPS(mad_piano_geo);
FILL_GEO_MAPS(manta_seg5_geo_05008D14);
FILL_GEO_MAPS(mario_geo);
FILL_GEO_MAPS(marios_cap_geo);
FILL_GEO_MAPS(marios_metal_cap_geo);
FILL_GEO_MAPS(marios_wing_cap_geo);
FILL_GEO_MAPS(marios_winged_metal_cap_geo);
FILL_GEO_MAPS(metal_box_geo);
FILL_GEO_MAPS(mips_geo);
FILL_GEO_MAPS(mist_geo);
FILL_GEO_MAPS(white_puff_geo);
FILL_GEO_MAPS(moneybag_geo);
FILL_GEO_MAPS(monty_mole_geo);
FILL_GEO_MAPS(mr_i_geo);
FILL_GEO_MAPS(mr_i_iris_geo);
FILL_GEO_MAPS(mushroom_1up_geo);
FILL_GEO_MAPS(number_geo);
FILL_GEO_MAPS(peach_geo);
FILL_GEO_MAPS(penguin_geo);
FILL_GEO_MAPS(piranha_plant_geo);
FILL_GEO_MAPS(pokey_head_geo);
FILL_GEO_MAPS(pokey_body_part_geo);
FILL_GEO_MAPS(wooden_post_geo);
FILL_GEO_MAPS(purple_switch_geo);
FILL_GEO_MAPS(scuttlebug_geo);
FILL_GEO_MAPS(seaweed_geo);
FILL_GEO_MAPS(skeeter_geo);
FILL_GEO_MAPS(small_key_geo);
FILL_GEO_MAPS(mr_blizzard_hidden_geo);
FILL_GEO_MAPS(mr_blizzard_geo);
FILL_GEO_MAPS(snufit_geo);
FILL_GEO_MAPS(sparkles_geo);
FILL_GEO_MAPS(sparkles_animation_geo);
FILL_GEO_MAPS(spindrift_geo);
FILL_GEO_MAPS(spiny_geo);
FILL_GEO_MAPS(spiny_ball_geo);
FILL_GEO_MAPS(springboard_top_geo);
FILL_GEO_MAPS(springboard_spring_geo);
FILL_GEO_MAPS(springboard_bottom_geo);
FILL_GEO_MAPS(star_geo);
FILL_GEO_MAPS(small_water_splash_geo);
FILL_GEO_MAPS(mario_TODO_geo_0000E0);
FILL_GEO_MAPS(sushi_geo);
FILL_GEO_MAPS(swoop_geo);
FILL_GEO_MAPS(thwomp_geo);
FILL_GEO_MAPS(toad_geo);
FILL_GEO_MAPS(tweester_geo);
FILL_GEO_MAPS(transparent_star_geo);
FILL_GEO_MAPS(treasure_chest_base_geo);
FILL_GEO_MAPS(treasure_chest_lid_geo);
FILL_GEO_MAPS(bubbly_tree_geo);
FILL_GEO_MAPS(spiky_tree_geo);
FILL_GEO_MAPS(snow_tree_geo);
FILL_GEO_MAPS(spiky_tree1_geo);
FILL_GEO_MAPS(palm_tree_geo);
FILL_GEO_MAPS(ukiki_geo);
FILL_GEO_MAPS(unagi_geo);
FILL_GEO_MAPS(smoke_geo);
FILL_GEO_MAPS(warp_pipe_geo);
FILL_GEO_MAPS(water_bomb_geo);
FILL_GEO_MAPS(water_bomb_shadow_geo);
FILL_GEO_MAPS(water_mine_geo);
FILL_GEO_MAPS(water_ring_geo);
FILL_GEO_MAPS(water_splash_geo);
FILL_GEO_MAPS(idle_water_wave_geo);
FILL_GEO_MAPS(wave_trail_geo);
FILL_GEO_MAPS(white_particle_geo);
FILL_GEO_MAPS(whomp_geo);
FILL_GEO_MAPS(wiggler_body_geo);
FILL_GEO_MAPS(wiggler_head_geo);
FILL_GEO_MAPS(wooden_signpost_geo);
FILL_GEO_MAPS(bowser_1_yellow_sphere_geo);
FILL_GEO_MAPS(yellow_sphere_geo);
FILL_GEO_MAPS(yoshi_geo);
FILL_GEO_MAPS(yoshi_egg_geo);
}
#endif

View File

@ -16,6 +16,7 @@
#include "gfx/gfx_opengl.h"
#include "gfx/gfx_direct3d11.h"
#include "gfx/gfx_direct3d12.h"
#include "gfx/gfx_rt64.h"
#include "gfx/gfx_dxgi.h"
#include "gfx/gfx_sdl.h"
@ -210,6 +211,10 @@ void main_func(void) {
# else
# define RAPI_NAME "OpenGL"
# endif
#elif defined(RAPI_RT64)
# define RAPI_NAME "RT64"
wm_api = &gfx_rt64_wapi;
rendering_api = &gfx_rt64_rapi;
#else
#error No rendering API!
#endif