From 1c5f1dbedbf0606f1e88e68a4b2e784b78eb56e1 Mon Sep 17 00:00:00 2001 From: aap Date: Fri, 12 Jan 2018 09:41:33 +0100 Subject: [PATCH] some fixes --- premake5.lua | 1 + shaders/vs/vcsVS.hlsl | 50 +++++++++++++++++++++++++++++++++++++ src/leeds.cpp | 1 + src/leedsCarpipe.cpp | 1 + src/main.cpp | 42 +++++++++++++++++++++++++++++-- src/pipeswitch.cpp | 6 ----- src/reversed/defaultFuncs.c | 2 +- src/reversed/xbpipe.c | 6 ++--- src/skygfx.h | 18 +++++++++++++ 9 files changed, 115 insertions(+), 12 deletions(-) create mode 100644 shaders/vs/vcsVS.hlsl diff --git a/premake5.lua b/premake5.lua index f3a7b47..0384a27 100644 --- a/premake5.lua +++ b/premake5.lua @@ -50,4 +50,5 @@ project "skygfx_vc" filter "configurations:Release" defines { "NDEBUG" } optimize "On" + symbols "On" flags { "StaticRuntime" } diff --git a/shaders/vs/vcsVS.hlsl b/shaders/vs/vcsVS.hlsl new file mode 100644 index 0000000..83fbc2b --- /dev/null +++ b/shaders/vs/vcsVS.hlsl @@ -0,0 +1,50 @@ +struct VS_INPUT +{ + float4 Position : POSITION; + float3 Normal : NORMAL; + float2 TexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 position : POSITION; + float2 texcoord0 : TEXCOORD0; + float2 texcoord1 : TEXCOORD1; + float4 color : COLOR0; +}; + +float4x4 combined : register(c0); +float4x4 world : register(c4); +float4x4 tex : register(c8); +float3 eye : register(c12); +float3 directDir : register(c13); +float3 ambient : register(c15); +float4 matCol : register(c16); +float3 directCol : register(c17); +float3 lightDir[4] : register(c18); +float3 lightCol[4] : register(c22); + +float4 directSpec : register(c26); + +VS_OUTPUT +main(in VS_INPUT In) +{ + VS_OUTPUT Out; + + Out.position = mul(In.Position, combined); + Out.texcoord0 = In.TexCoord; + float3 N = normalize(mul(In.Normal, (float3x3)world).xyz); + float3 V = normalize(eye - mul(In.Position, world).xyz); + + float3 c = directCol*saturate(dot(N, -directDir)); + c += ambient; + for(int i = 0; i < 4; i++) + c += lightCol[i]*saturate(dot(N, -lightDir[i])); + Out.color = float4(saturate(c), 1.0f)*matCol; + + N = mul(N, (float3x3)tex); // to view space + N = -N; + Out.texcoord1.xy = N.xy*0.5 + 0.5; + + return Out; +} diff --git a/src/leeds.cpp b/src/leeds.cpp index 0702475..e1cd31f 100644 --- a/src/leeds.cpp +++ b/src/leeds.cpp @@ -31,6 +31,7 @@ leedsSetSurfaceProps(RwRGBA *color, RwSurfaceProperties *surfProps, RwUInt32 fla static D3DCOLORVALUE black = { 0, 0, 0, 0 }; RwRGBA c = *color; + // REMOVE: we do this in InitialiseGame_hook now if(config.leedsWorldAmbTweak < 0) config.leedsWorldAmbTweak = 1.0f; if(config.leedsWorldEmissTweak < 0) config.leedsWorldEmissTweak = 0.0f; diff --git a/src/leedsCarpipe.cpp b/src/leedsCarpipe.cpp index 9be048f..26c3e9e 100644 --- a/src/leedsCarpipe.cpp +++ b/src/leedsCarpipe.cpp @@ -450,6 +450,7 @@ leedsCarRenderFFPEnvMesh(RxD3D8InstanceData *inst, RwUInt32 flags) { int fog, zwrite; + // REMOVE: we do this in InitialiseGame_hook now if(config.leedsEnvMult == -9999.0f) config.leedsEnvMult = isIII() ? 0.22 : 0.3; diff --git a/src/main.cpp b/src/main.cpp index 372c920..591dae1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,6 +72,8 @@ RwImVertexIndex *blurIndices = AddressByVersion(0x5FDD90, 0x5F static addr DefinedState_A = AddressByVersion(0x526330, 0x526570, 0x526500, 0x57F9C0, 0x57F9E0, 0x57F7F0); WRAPPER void DefinedState(void) { VARJMP(DefinedState_A); } +RsGlobalType &RsGlobal = *AddressByVersion(0x8F4360, 0, 0, 0, 0, 0); + SkyGFXConfig config; bool d3d9; @@ -808,10 +810,20 @@ footsplash_hook(void) } } +// BETA sliding in oddjob2 text for III, thanks Fire_Head for finding this +float &OddJob2XOffset = *(float*)0x8F1B5C; +WRAPPER void CFont__PrintString(float x, float y, short *str) { EAXJMP(0x500F50); } +void +CFont__PrintString__Oddjob2(float x, float y, short *str) +{ + CFont__PrintString(x - OddJob2XOffset * RsGlobal.width/640.0f, y, str); +} + void (*CMBlur__MotionBlurRenderIII_orig)(RwCamera*, RwUInt8, RwUInt8, RwUInt8, RwUInt8, int, int); void CMBlur__MotionBlurRenderIII(RwCamera *cam, RwUInt8 red, RwUInt8 green, RwUInt8 blue, RwUInt8 alpha, int type, int bluralpha) { + // REMOVE: we do this in InitialiseGame_hook now if(config.trailsSwitch < 0) config.trailsSwitch = 0; if(config.disableColourOverlay) return; @@ -825,6 +837,7 @@ void (*CMBlur__MotionBlurRenderVC_orig)(RwCamera*, RwUInt8, RwUInt8, RwUInt8, Rw void CMBlur__MotionBlurRenderVC(RwCamera *cam, RwUInt8 red, RwUInt8 green, RwUInt8 blue, RwUInt8 alpha, int type) { + // REMOVE: we do this in InitialiseGame_hook now if(config.trailsSwitch < 0) config.trailsSwitch = 0; if(config.disableColourOverlay) return; @@ -917,6 +930,14 @@ InitialiseGame_hook(void) if(!postrw_once){ d3d9 = RwD3D9Supported(); + // This is where we can sanitize some values: + if(config.trailsSwitch < 0) config.trailsSwitch = 0; + if(config.radiosity < 0) config.radiosity = 0; + if(config.leedsEnvMult < 0) config.leedsEnvMult = isIII() ? 0.22 : 0.3; + if(config.leedsWorldAmbTweak < 0) config.leedsWorldAmbTweak = 1.0f; + if(config.leedsWorldEmissTweak < 0) config.leedsWorldEmissTweak = 0.0f; + + if (isIII()) // fall back to generic.txd when reading from dff InjectHook(AddressByVersion(0x5AAE1B, 0x5AB0DB, 0x5AD708, 0, 0, 0), RwTextureRead_generic); CarPipe::Init(); @@ -924,10 +945,14 @@ InitialiseGame_hook(void) LeedsCarPipe::Get()->Init(); neoInit(); + + if(config.rimlight < 0) config.rimlight = 0; + if(config.neoGlossPipe < 0) config.neoGlossPipe = 0; + if(config.carPipeSwitch < 0) config.carPipeSwitch = 0; + if(config.worldPipeSwitch < 0) config.worldPipeSwitch = 0; + postrw_once = true; } - if(config.carPipeSwitch < 0) config.carPipeSwitch = 0; - if(config.worldPipeSwitch < 0) config.worldPipeSwitch = 0; InitialiseGame(); } @@ -970,6 +995,13 @@ delayedPatches(int a, int b) void leedsMenu(); leedsMenu(); + extern int seamOffX; + extern int seamOffY; + DebugMenuAddVarBool32("SkyGFX", "Seam fixer", &config.seamfix, nil); + DebugMenuAddVar("SkyGFX", "Seam Offset X", &seamOffX, nil, 1, -10, 10, nil); + DebugMenuAddVar("SkyGFX", "Seam Offset Y", &seamOffY, nil, 1, -10, 10, nil); + + DebugMenuAddVarBool8("SkyGFX|ScreenFX", "Enable YCbCr tweak", (int8_t*)&ScreenFX::m_bYCbCrFilter, nil); DebugMenuAddVar("SkyGFX|ScreenFX", "Y scale", &ScreenFX::m_lumaScale, nil, 0.004f, 0.0f, 10.0f); DebugMenuAddVar("SkyGFX|ScreenFX", "Y offset", &ScreenFX::m_lumaOffset, nil, 0.004f, -1.0f, 1.0f); @@ -995,6 +1027,7 @@ delayedPatches(int a, int b) #endif } + return RsEventHandler_orig(a, b); } @@ -1254,6 +1287,11 @@ patch(void) //MemoryVP::InjectHook(0x5219B3, CVehicleModelInfo__SetEnvironmentMapCB_hook); //MemoryVP::Patch(0x521986+1, CVehicleModelInfo__SetEnvironmentMapCB_hook); + // beta sliding in text + InjectHook(0x509DDE, CFont__PrintString__Oddjob2); + InjectHook(0x509E51, CFont__PrintString__Oddjob2); + + // clear framebuffer Patch(0x48CFC1+1, 3); Patch(0x48D0AD+1, 3); diff --git a/src/pipeswitch.cpp b/src/pipeswitch.cpp index 2cb12c8..a1389c4 100644 --- a/src/pipeswitch.cpp +++ b/src/pipeswitch.cpp @@ -153,12 +153,6 @@ WorldPipe::Init(void) WorldPipe::Get()->CreateRwPipeline(); WorldPipe::Get()->SetRenderCallback(RenderCallback); - if(DebugMenuLoad()){ - DebugMenuAddVarBool32("SkyGFX", "Seam fixer", &config.seamfix, nil); - DebugMenuAddVar("SkyGFX", "Seam Offset X", &seamOffX, nil, 1, -10, 10, nil); - DebugMenuAddVar("SkyGFX", "Seam Offset Y", &seamOffY, nil, 1, -10, 10, nil); - } - if(gtaversion == III_10){ InterceptCall(&CSimpleModelInfo__SetAtomic_A, &CSimpleModelInfo::SetAtomic_hook, 0x4768F1); InjectHook(0x476707, &CSimpleModelInfo::SetAtomic_hook); diff --git a/src/reversed/defaultFuncs.c b/src/reversed/defaultFuncs.c index 1b2d22e..487f211 100644 --- a/src/reversed/defaultFuncs.c +++ b/src/reversed/defaultFuncs.c @@ -112,7 +112,7 @@ rxD3D8DefaultRenderCallback_fixed(RwResEntry *repEntry, void *object, RwUInt8 ty if(curalpha != a) rwD3D8RenderStateVertexAlphaEnable(curalpha = a); if(lighting){ - RwD3D8SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, inst->vertexAlpha != 0); + RwD3D8SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, inst->vertexAlpha ? D3DMCS_COLOR1 : D3DMCS_MATERIAL); RwD3D8SetSurfaceProperties(&inst->material->color, &inst->material->surfaceProps, flags & rpGEOMETRYMODULATEMATERIALCOLOR); } diff --git a/src/reversed/xbpipe.c b/src/reversed/xbpipe.c index a03f72f..cf679e0 100644 --- a/src/reversed/xbpipe.c +++ b/src/reversed/xbpipe.c @@ -39,12 +39,12 @@ void _rxXbDefaultRenderFFPObjectSetUp(RxXboxResEntryHeader *res, void *object, c if(lightingEnabled){ if(flags & rpGEOMETRYPRELIT){ RwXboxSetCachedRenderState(D3DRS_COLORVERTEX, 1); - RwXboxSetCachedRenderState(D3DRS_EMISSIVEMATERIALSOURCE, 1); + RwXboxSetCachedRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1); }else{ RwXboxSetCachedRenderState(D3DRS_COLORVERTEX, 0); - RwXboxSetCachedRenderState(D3DRS_EMISSIVEMATERIALSOURCE, 0); + RwXboxSetCachedRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL); } - RwXboxSetCachedRenderState(D3DRS_DIFFUSEMATERIALSOURCE, res->vertexAlpha); + RwXboxSetCachedRenderState(D3DRS_DIFFUSEMATERIALSOURCE, res->vertexAlpha ? D3DMCS_COLOR1 : D3DMCS_MATERIAL); } normalizeNormals = 0; if(flags & rpGEOMETRYNORMALS && type == rpATOMIC && XbAtomicHasScaling(object)){ diff --git a/src/skygfx.h b/src/skygfx.h index 2ceba22..48e5849 100644 --- a/src/skygfx.h +++ b/src/skygfx.h @@ -65,6 +65,24 @@ class ScreenFX //#define RELEASE +struct RsGlobalType +{ + const char *appName; + int width; + int height; + int maximumWidth; + int maximumHeight; + int maxFPS; + int quit; + void *ps; +/* + RsInputDevice keyboard; + RsInputDevice mouse; + RsInputDevice pad; +*/ +}; +extern RsGlobalType &RsGlobal; + struct GlobalScene { RpWorld *world;