implemented extra model flags for backface culling and alpha test from mobile

This commit is contained in:
aap 2020-10-29 19:11:47 +01:00
parent 81e462b677
commit e97366c023
8 changed files with 418 additions and 3 deletions

View File

@ -1,6 +1,7 @@
#include "common.h" #include "common.h"
#include "main.h" #include "main.h"
#include "General.h"
#include "Quaternion.h" #include "Quaternion.h"
#include "ModelInfo.h" #include "ModelInfo.h"
#include "ModelIndices.h" #include "ModelIndices.h"
@ -449,6 +450,334 @@ CFileLoader::LoadAtomicFile(RwStream *stream, uint32 id)
return true; return true;
} }
#ifdef HARDCODED_MODEL_FLAGS
char *DoubleSidedNames[] = {
"chnabankdoor",
"Security_Hut",
"Hospital_Sub",
"phonebooth1",
"trafficlight1",
"sub_roadbarrier",
"redlightbuild09",
"doublestreetlght1",
"doc_shedbig31",
"com_land_128",
"garage7",
"proj_garage01",
"buildingground2",
"buildingground3",
"ch_roof_kb",
"overpassind",
"casino",
"ind_land100",
"fuckedup_skewlbus",
"Police_Station_ind",
"flagsitaly",
"sidebarrier_gaz1",
"bar_barrier12",
"bar_barrier10b",
"sidebarrier_gaz2",
"doc_shedbig3",
"doc_shedbig4",
"verticalift_bridge",
"verticalift_bridg2",
"usdcrdlrbuild01",
"apairporthanger",
"apairporthangerA",
"porthangerclosed",
"redlightbuild13",
"doc_rave",
"const_woodfence",
"const_woodfence2",
"const_woodfence3",
"subfraightback01",
"subfraightback02",
"subfraightback03",
"subfraightback04",
"subind_build03",
"chinabanner1",
"chinabanner2",
"chinabanner3",
"chinabanner4",
"Pumpfirescape",
"Pumphouse",
"amcounder",
"barrel1",
"barrel2",
"barrel3",
"barrel4",
"com_1way50",
"com_1way20",
"overpasscom01",
"overpasscom02",
"overpasscom03",
"overpasscom04",
"overpass_comse",
"newdockbuilding",
"newdockbuilding2",
"newdockbuilding",
"policeballhall",
"fuzballdoor",
"ind_land106",
"PoliceBallSigns",
"amcoudet",
"rustship_structure",
"impexpgrgesub",
"ind_land128",
"fshfctry_dstryd",
"railtrax_bentl",
"railtrax_lo4b",
"railtrax_straight",
"railtrax_bentrb",
"railtrax_skew",
"newtrackaaa",
"railtrax_skew5",
// these they forgot:
"railtrax_skewp",
"railtrax_ske2b",
"railtrax_strtshort",
"railtrax_2b",
"railtrax_straightss",
"railtrax_bentr",
""
};
char *TreeNames[] = {
"coast_treepatch",
"comparknewtrees",
"comtreepatchprk",
"condotree01",
"condotree1",
"indatree03",
"indtreepatch5",
"indtreepatch06f",
"new_carprktrees",
"new_carprktrees4",
"newcoasttrees1",
"newcoasttrees2",
"newcoasttrees3",
"newtreepatch_sub",
"newtrees1_sub",
"newunitrepatch",
"pinetree_narrow",
"pinetree_wide",
"treencom2",
"treepatch",
"treepatch01_sub",
"treepatch02_sub",
"treepatch2",
"treepatch2b",
"treepatch03",
"treepatch03_sub",
"treepatch04_sub",
"treepatch05_sub",
"treepatch06_sub",
"treepatch07_sub",
"treepatch08_sub",
"treepatch09_sub",
"treepatch10_sub",
"treepatch11_sub",
"treepatch12_sub",
"treepatch13_sub",
"treepatch14_sub",
"treepatch15_sub",
"treepatch16_sub",
"treepatch17_sub",
"treepatch18_sub",
"treepatch19_sub",
"treepatch20_sub",
"treepatch21_sub",
"treepatch22_sub",
"treepatch23_sub",
"treepatch24_sub",
"treepatch25_sub",
"treepatch26_sub",
"treepatch27_sub",
"treepatch28_sub",
"treepatch29_sub",
"treepatch30_sub",
"treepatch31_sub",
"treepatch32_sub",
"treepatch33_sub",
"treepatch34_sub",
"treepatch35_sub",
"treepatch69",
"treepatch152_sub",
"treepatch153_sub",
"treepatch171_sub",
"treepatch172_sub",
"treepatch173_sub",
"treepatch212_sub",
"treepatch213_sub",
"treepatch214_sub",
"treepatcha",
"treepatchb",
"treepatchcomtop1",
"treepatchd",
"treepatche",
"treepatchh",
"treepatchindaa2",
"treepatchindnew",
"treepatchindnew2",
"treepatchk",
"treepatchkb4",
"treepatchkb5",
"treepatchkb6",
"treepatchkb7",
"treepatchkb9",
"treepatchl",
"treepatchm",
"treepatchnew_sub",
"treepatchttwrs",
"treesuni1",
"trepatchindaa1",
"veg_bush2",
"veg_bush14",
"veg_tree1",
"veg_tree3",
"veg_treea1",
"veg_treea3",
"veg_treeb1",
"veg_treenew01",
"veg_treenew03",
"veg_treenew05",
"veg_treenew06",
"veg_treenew08",
"veg_treenew09",
"veg_treenew10",
"veg_treenew16",
"veg_treenew17",
"vegclubtree01",
"vegclubtree02",
"vegclubtree03",
"vegpathtree",
""
};
char *OptimizedNames[] = {
"coast_treepatch",
"comparknewtrees",
"comtreepatchprk",
"indtreepatch5",
"indtreepatch06f",
"new_carprktrees",
"new_carprktrees4",
"newcoasttrees1",
"newcoasttrees2",
"newcoasttrees3",
"newtreepatch_sub",
"newtrees1_sub",
"newunitrepatch",
"treepatch",
"treepatch01_sub",
"treepatch02_sub",
"treepatch2",
"treepatch2b",
"treepatch03",
"treepatch03_sub",
"treepatch04_sub",
"treepatch05_sub",
"treepatch06_sub",
"treepatch07_sub",
"treepatch08_sub",
"treepatch09_sub",
"treepatch10_sub",
"treepatch11_sub",
"treepatch12_sub",
"treepatch13_sub",
"treepatch14_sub",
"treepatch15_sub",
"treepatch16_sub",
"treepatch17_sub",
"treepatch18_sub",
"treepatch19_sub",
"treepatch20_sub",
"treepatch21_sub",
"treepatch22_sub",
"treepatch23_sub",
"treepatch24_sub",
"treepatch25_sub",
"treepatch26_sub",
"treepatch27_sub",
"treepatch28_sub",
"treepatch29_sub",
"treepatch30_sub",
"treepatch31_sub",
"treepatch32_sub",
"treepatch33_sub",
"treepatch34_sub",
"treepatch35_sub",
"treepatch69",
"treepatch152_sub",
"treepatch153_sub",
"treepatch171_sub",
"treepatch172_sub",
"treepatch173_sub",
"treepatch212_sub",
"treepatch213_sub",
"treepatch214_sub",
"treepatcha",
"treepatchb",
"treepatchcomtop1",
"treepatchd",
"treepatche",
"treepatchh",
"treepatchindaa2",
"treepatchindnew",
"treepatchindnew2",
"treepatchk",
"treepatchkb4",
"treepatchkb5",
"treepatchkb6",
"treepatchkb7",
"treepatchkb9",
"treepatchl",
"treepatchm",
"treepatchnew_sub",
"treepatchttwrs",
"treesuni1",
"trepatchindaa1",
"combtm_treeshad01",
"combtm_treeshad02",
"combtm_treeshad03",
"combtm_treeshad04",
"combtm_treeshad05",
"combtm_treeshad06",
"comtop_tshad",
"comtop_tshad2",
"comtop_tshad3",
"comtop_tshad4",
"comtop_tshad5",
"comtop_tshad6",
"se_treeshad01",
"se_treeshad02",
"se_treeshad03",
"se_treeshad04",
"se_treeshad05",
"se_treeshad06",
"treeshads01",
"treeshads02",
"treeshads03",
"treeshads04",
"treeshads05",
""
};
// not from mobile
static bool
MatchModelName(char *name, char **list)
{
int i;
char *s;
for(i = 0; *list[i] != '\0'; i++)
if(strncmp(name, "LOD", 3) == 0){
if(!CGeneral::faststricmp(name+3, list[i]+3))
return true;
}else{
if(!CGeneral::faststricmp(name, list[i]))
return true;
}
return false;
}
#endif
RpAtomic* RpAtomic*
CFileLoader::SetRelatedModelInfoCB(RpAtomic *atomic, void *data) CFileLoader::SetRelatedModelInfoCB(RpAtomic *atomic, void *data)
{ {
@ -600,6 +929,21 @@ SetModelInfoFlags(CSimpleModelInfo *mi, uint32 flags)
mi->m_isSubway = !!(flags & 0x10); mi->m_isSubway = !!(flags & 0x10);
mi->m_ignoreLight = !!(flags & 0x20); mi->m_ignoreLight = !!(flags & 0x20);
mi->m_noZwrite = !!(flags & 0x40); mi->m_noZwrite = !!(flags & 0x40);
#ifdef EXTRA_MODEL_FLAGS
// same flag values as SA
mi->m_bIsTree = !!(flags & 0x2000);
mi->m_bIsDoubleSided = !!(flags & 0x200000);
// new value otherwise unused
mi->m_bCanBeIgnored = !!(flags & 0x10000);
#ifdef HARDCODED_MODEL_FLAGS
// mobile sets these flags in CFileLoader::SetRelatedModelInfoCB, but that's stupid
if(MatchModelName(mi->GetName(), DoubleSidedNames)) mi->m_bIsDoubleSided = true;
if(MatchModelName(mi->GetName(), TreeNames)) mi->m_bIsTree = true;
if(MatchModelName(mi->GetName(), OptimizedNames)) mi->m_bCanBeIgnored = true;
#endif
#endif
} }
void void

View File

@ -201,6 +201,9 @@ enum Config {
#define LOAD_INI_SETTINGS #define LOAD_INI_SETTINGS
// Rendering/display // Rendering/display
#define EXTRA_MODEL_FLAGS // from mobile to optimize rendering
# define HARDCODED_MODEL_FLAGS // sets the flags enabled above from hardcoded model names.
// NB: keep this enabled unless your map IDEs have these flags baked in
#define ASPECT_RATIO_SCALE // Not just makes everything scale with aspect ratio, also adds support for all aspect ratios #define ASPECT_RATIO_SCALE // Not just makes everything scale with aspect ratio, also adds support for all aspect ratios
#define DEFAULT_NATIVE_RESOLUTION // Set default video mode to your native resolution (fixes Windows 10 launch) #define DEFAULT_NATIVE_RESOLUTION // Set default video mode to your native resolution (fixes Windows 10 launch)
#define USE_TXD_CDIMAGE // generate and load textures from txd.img #define USE_TXD_CDIMAGE // generate and load textures from txd.img

View File

@ -337,7 +337,7 @@ ReadTweakValueTable(char *fp, InterpolatedValue &interp)
* Neo Vehicle pipe * Neo Vehicle pipe
*/ */
int32 VehiclePipeSwitch = VEHICLEPIPE_NEO; int32 VehiclePipeSwitch = VEHICLEPIPE_MATFX;
float VehicleShininess = 0.7f; // the default is a bit extreme float VehicleShininess = 0.7f; // the default is a bit extreme
float VehicleSpecularity = 1.0f; float VehicleSpecularity = 1.0f;
InterpolatedFloat Fresnel(0.4f); InterpolatedFloat Fresnel(0.4f);

View File

@ -31,6 +31,14 @@ protected:
ModelInfoType m_type; ModelInfoType m_type;
uint8 m_num2dEffects; uint8 m_num2dEffects;
bool m_bOwnsColModel; bool m_bOwnsColModel;
#ifdef EXTRA_MODEL_FLAGS
public:
// from mobile
bool m_bIsDoubleSided;
bool m_bIsTree;
bool m_bCanBeIgnored; // for low-end devices
bool RenderDoubleSided(void) { return m_bIsDoubleSided || m_bIsTree; }
#endif
public: public:
CBaseModelInfo(ModelInfoType type); CBaseModelInfo(ModelInfoType type);

View File

@ -53,6 +53,14 @@ CVehicle *CRenderer::m_pFirstPersonVehicle;
bool CRenderer::m_loadingPriority; bool CRenderer::m_loadingPriority;
float CRenderer::ms_lodDistScale = 1.2f; float CRenderer::ms_lodDistScale = 1.2f;
#ifdef EXTRA_MODEL_FLAGS
#define BACKFACE_CULLING_ON SetCullMode(rwCULLMODECULLBACK)
#define BACKFACE_CULLING_OFF SetCullMode(rwCULLMODECULLNONE)
#else
#define BACKFACE_CULLING_ON
#define BACKFACE_CULLING_OFF
#endif
void void
CRenderer::Init(void) CRenderer::Init(void)
{ {
@ -101,6 +109,13 @@ CRenderer::RenderOneRoad(CEntity *e)
else{ else{
#ifdef EXTENDED_PIPELINES #ifdef EXTENDED_PIPELINES
CustomPipes::AttachGlossPipe(e->GetAtomic()); CustomPipes::AttachGlossPipe(e->GetAtomic());
#endif
#ifdef EXTRA_MODEL_FLAGS
if(CModelInfo::GetModelInfo(e->GetModelIndex())->RenderDoubleSided()){
BACKFACE_CULLING_OFF;
e->Render();
BACKFACE_CULLING_ON;
}else
#endif #endif
e->Render(); e->Render();
} }
@ -163,13 +178,22 @@ CRenderer::RenderOneNonRoad(CEntity *e)
for(i = 0; i < 8; i++) for(i = 0; i < 8; i++)
if(veh->pPassengers[i] && veh->pPassengers[i]->m_nPedState == PED_DRIVING) if(veh->pPassengers[i] && veh->pPassengers[i]->m_nPedState == PED_DRIVING)
veh->pPassengers[i]->Render(); veh->pPassengers[i]->Render();
BACKFACE_CULLING_OFF;
} }
#ifdef EXTRA_MODEL_FLAGS
if(CModelInfo::GetModelInfo(e->GetModelIndex())->RenderDoubleSided()){
BACKFACE_CULLING_OFF;
e->Render();
BACKFACE_CULLING_ON;
}else
#endif
e->Render(); e->Render();
if(e->IsVehicle()){ if(e->IsVehicle()){
e->bImBeingRendered = true; e->bImBeingRendered = true;
CVisibilityPlugins::RenderAlphaAtomics(); CVisibilityPlugins::RenderAlphaAtomics();
e->bImBeingRendered = false; e->bImBeingRendered = false;
BACKFACE_CULLING_ON;
} }
e->RemoveLighting(resetLights); e->RemoveLighting(resetLights);
@ -197,6 +221,7 @@ CRenderer::RenderRoads(void)
CTreadable *t; CTreadable *t;
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
BACKFACE_CULLING_ON;
DeActivateDirectional(); DeActivateDirectional();
SetAmbientColours(); SetAmbientColours();
@ -230,6 +255,7 @@ CRenderer::RenderEverythingBarRoads(void)
CVector dist; CVector dist;
EntityInfo ei; EntityInfo ei;
BACKFACE_CULLING_ON;
gSortedVehiclesAndPeds.Clear(); gSortedVehiclesAndPeds.Clear();
for(i = 0; i < ms_nNoOfVisibleEntities; i++){ for(i = 0; i < ms_nNoOfVisibleEntities; i++){
@ -284,6 +310,8 @@ CRenderer::RenderBoats(void)
{ {
CLink<EntityInfo> *node; CLink<EntityInfo> *node;
BACKFACE_CULLING_ON;
for(node = gSortedVehiclesAndPeds.tail.prev; for(node = gSortedVehiclesAndPeds.tail.prev;
node != &gSortedVehiclesAndPeds.head; node != &gSortedVehiclesAndPeds.head;
node = node->prev){ node = node->prev){
@ -298,6 +326,7 @@ void
CRenderer::RenderFadingInEntities(void) CRenderer::RenderFadingInEntities(void)
{ {
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
BACKFACE_CULLING_ON;
DeActivateDirectional(); DeActivateDirectional();
SetAmbientColours(); SetAmbientColours();
CVisibilityPlugins::RenderFadingEntities(); CVisibilityPlugins::RenderFadingEntities();

View File

@ -3,6 +3,7 @@
#endif #endif
#include "common.h" #include "common.h"
#include "RwHelper.h"
#include "Timecycle.h" #include "Timecycle.h"
#include "skeleton.h" #include "skeleton.h"
#include "Debug.h" #include "Debug.h"
@ -16,6 +17,7 @@ bool gPS2alphaTest = true;
#else #else
bool gPS2alphaTest = false; bool gPS2alphaTest = false;
#endif #endif
bool gBackfaceCulling = true;
#ifndef FINAL #ifndef FINAL
static bool charsetOpen; static bool charsetOpen;
@ -121,14 +123,32 @@ DefinedState(void)
#ifdef LIBRW #ifdef LIBRW
rw::SetRenderState(rw::ALPHATESTFUNC, rw::ALPHAGREATEREQUAL); rw::SetRenderState(rw::ALPHATESTFUNC, rw::ALPHAGREATEREQUAL);
rw::SetRenderState(rw::ALPHATESTREF, 3);
rw::SetRenderState(rw::GSALPHATEST, gPS2alphaTest); rw::SetRenderState(rw::GSALPHATEST, gPS2alphaTest);
#else #else
// D3D stuff // D3D stuff
RwD3D8SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER); RwD3D8SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
RwD3D8SetRenderState(D3DRS_ALPHAREF, 2);
#endif #endif
SetAlphaRef(2);
}
void
SetAlphaRef(int ref)
{
#ifdef LIBRW
rw::SetRenderState(rw::ALPHATESTREF, ref+1);
#else
RwD3D8SetRenderState(D3DRS_ALPHAREF, ref);
#endif
}
void
SetCullMode(uint32 mode)
{
if(gBackfaceCulling)
RwRenderStateSet(rwRENDERSTATECULLMODE, (void*)mode);
else
RwRenderStateSet(rwRENDERSTATECULLMODE, (void*)rwCULLMODECULLNONE);
} }
RwFrame* RwFrame*

View File

@ -11,6 +11,8 @@ void DestroyDebugFont();
void ObrsPrintfString(const char *str, short x, short y); void ObrsPrintfString(const char *str, short x, short y);
void FlushObrsPrintfs(); void FlushObrsPrintfs();
void DefinedState(void); void DefinedState(void);
void SetAlphaRef(int ref);
void SetCullMode(uint32 mode);
RwFrame *GetFirstChild(RwFrame *frame); RwFrame *GetFirstChild(RwFrame *frame);
RwObject *GetFirstObject(RwFrame *frame); RwObject *GetFirstObject(RwFrame *frame);
RpAtomic *GetFirstAtomic(RpClump *clump); RpAtomic *GetFirstAtomic(RpClump *clump);

View File

@ -1,5 +1,6 @@
#include "common.h" #include "common.h"
#include "RwHelper.h"
#include "templates.h" #include "templates.h"
#include "Entity.h" #include "Entity.h"
#include "ModelInfo.h" #include "ModelInfo.h"
@ -158,6 +159,10 @@ CVisibilityPlugins::RenderFadingEntities(void)
if(mi->m_noZwrite) if(mi->m_noZwrite)
#endif #endif
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);
#ifdef EXTRA_MODEL_FLAGS
if(mi->m_bIsTree)
SetAlphaRef(128);
#endif
if(e->bDistanceFade){ if(e->bDistanceFade){
DeActivateDirectional(); DeActivateDirectional();
@ -168,6 +173,10 @@ CVisibilityPlugins::RenderFadingEntities(void)
}else }else
CRenderer::RenderOneNonRoad(e); CRenderer::RenderOneNonRoad(e);
#ifdef EXTRA_MODEL_FLAGS
if(mi->m_bIsTree)
SetAlphaRef(2);
#endif
#ifdef FIX_BUGS #ifdef FIX_BUGS
if(mi->GetModelType() == MITYPE_SIMPLE && mi->m_noZwrite) if(mi->GetModelType() == MITYPE_SIMPLE && mi->m_noZwrite)
#else #else