Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aap committed Jan 12, 2018
1 parent e823024 commit 1c5f1db
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 12 deletions.
1 change: 1 addition & 0 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ project "skygfx_vc"
filter "configurations:Release"
defines { "NDEBUG" }
optimize "On"
symbols "On"
flags { "StaticRuntime" }
50 changes: 50 additions & 0 deletions shaders/vs/vcsVS.hlsl
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions src/leeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/leedsCarpipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
42 changes: 40 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ RwImVertexIndex *blurIndices = AddressByVersion<RwImVertexIndex*>(0x5FDD90, 0x5F
static addr DefinedState_A = AddressByVersion<addr>(0x526330, 0x526570, 0x526500, 0x57F9C0, 0x57F9E0, 0x57F7F0);
WRAPPER void DefinedState(void) { VARJMP(DefinedState_A); }

RsGlobalType &RsGlobal = *AddressByVersion<RsGlobalType*>(0x8F4360, 0, 0, 0, 0, 0);

SkyGFXConfig config;
bool d3d9;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -917,17 +930,29 @@ 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<addr>(0x5AAE1B, 0x5AB0DB, 0x5AD708, 0, 0, 0), RwTextureRead_generic);
CarPipe::Init();
WorldPipe::Init();
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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -995,6 +1027,7 @@ delayedPatches(int a, int b)

#endif
}

return RsEventHandler_orig(a, b);
}

Expand Down Expand Up @@ -1254,6 +1287,11 @@ patch(void)
//MemoryVP::InjectHook(0x5219B3, CVehicleModelInfo__SetEnvironmentMapCB_hook);
//MemoryVP::Patch<void*>(0x521986+1, CVehicleModelInfo__SetEnvironmentMapCB_hook);

// beta sliding in text
InjectHook(0x509DDE, CFont__PrintString__Oddjob2);
InjectHook(0x509E51, CFont__PrintString__Oddjob2);


// clear framebuffer
Patch<uchar>(0x48CFC1+1, 3);
Patch<uchar>(0x48D0AD+1, 3);
Expand Down
6 changes: 0 additions & 6 deletions src/pipeswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/reversed/defaultFuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/reversed/xbpipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down
18 changes: 18 additions & 0 deletions src/skygfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1c5f1db

Please sign in to comment.