Skip to content

Commit

Permalink
Add environmental shadow rescaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Jan 13, 2017
1 parent df71de3 commit 4cf5abd
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 56 deletions.
2 changes: 1 addition & 1 deletion include/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define TBF_MAJOR 0
#define TBF_MINOR 1
#define TBF_BUILD 2
#define TBF_BUILD 3
#define TBF_REV 0


Expand Down
2 changes: 1 addition & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct tbf_config_t
int32_t shadow_rescale = -2;
float postproc_ratio = 0.0f;
bool clear_blackbars = false;
int32_t env_shadow_rescale = 0;
int32_t env_shadow_rescale = 1;
} render;

struct {
Expand Down
16 changes: 8 additions & 8 deletions include/textures.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ interface ISKTextureD3D9 : public IDirect3DTexture9
pTex->PreLoad ();
}
STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS) {
tex_log->Log ( L"[ Tex. Mgr ] ISKTextureD3D9::GetType ()" );
//tex_log->Log ( L"[ Tex. Mgr ] ISKTextureD3D9::GetType ()" );

return pTex->GetType ();
}
Expand All @@ -272,7 +272,7 @@ interface ISKTextureD3D9 : public IDirect3DTexture9
return pTex->GetLOD ();
}
STDMETHOD_(DWORD, GetLevelCount)(THIS) {
tex_log->Log ( L"[ Tex. Mgr ] ISKTextureD3D9::GetLevelCount ()" );
//tex_log->Log ( L"[ Tex. Mgr ] ISKTextureD3D9::GetLevelCount ()" );

return pTex->GetLevelCount ();
}
Expand All @@ -293,15 +293,15 @@ interface ISKTextureD3D9 : public IDirect3DTexture9
pTex->GenerateMipSubLevels ();
}
STDMETHOD(GetLevelDesc)(THIS_ UINT Level,D3DSURFACE_DESC *pDesc) {
tex_log->Log ( L"[ Tex. Mgr ] ISKTextureD3D9::GetLevelDesc (%lu, %ph)",
Level,
pDesc );
//tex_log->Log ( L"[ Tex. Mgr ] ISKTextureD3D9::GetLevelDesc (%lu, %ph)",
//Level,
//pDesc );
return pTex->GetLevelDesc (Level, pDesc);
}
STDMETHOD(GetSurfaceLevel)(THIS_ UINT Level,IDirect3DSurface9** ppSurfaceLevel) {
tex_log->Log ( L"[ Tex. Mgr ] ISKTextureD3D9::GetSurfaceLevel (%lu, %ph)",
Level,
ppSurfaceLevel );
//tex_log->Log ( L"[ Tex. Mgr ] ISKTextureD3D9::GetSurfaceLevel (%lu, %ph)",
//Level,
//ppSurfaceLevel );

return pTex->GetSurfaceLevel (Level, ppSurfaceLevel);
}
Expand Down
56 changes: 45 additions & 11 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ std::wstring TBF_VER_STR = TBF_VERSION_STR_W;
std::wstring DEFAULT_BK2 = L"RAW\\MOVIE\\AM_TOZ_OP_001.BK2";

static
iSK_INI* dll_ini = nullptr;
iSK_INI* dll_ini = nullptr;
static
iSK_INI* gamepad_ini = nullptr;
iSK_INI* gamepad_ini = nullptr;
static
iSK_INI* render_ini = nullptr;

tbf_config_t config;

tbf::ParameterFactory g_ParameterFactory;
Expand Down Expand Up @@ -125,8 +128,9 @@ TBF_LoadConfig (std::wstring name)
);

// Load INI File
wchar_t wszFullName [ MAX_PATH + 2 ] = { L'\0' };
wchar_t wszPadName [ MAX_PATH + 2 ] = { L'\0' };
wchar_t wszFullName [ MAX_PATH + 2 ] = { L'\0' };
wchar_t wszPadName [ MAX_PATH + 2 ] = { L'\0' };
wchar_t wszRenderName [ MAX_PATH + 2 ] = { L'\0' };

lstrcatW (wszFullName, SK_GetConfigPath ());
lstrcatW (wszFullName, name.c_str ());
Expand All @@ -137,6 +141,10 @@ TBF_LoadConfig (std::wstring name)
lstrcatW (wszPadName, L"TBFix_Gamepad.ini");
gamepad_ini = TBF_CreateINI (wszPadName);

lstrcatW (wszRenderName, SK_GetConfigPath ());
lstrcatW (wszRenderName, L"TBFix_Render.ini");
render_ini = TBF_CreateINI (wszRenderName);

bool empty = dll_ini->get_sections ().empty ();

//
Expand Down Expand Up @@ -241,10 +249,20 @@ TBF_LoadConfig (std::wstring name)
L"Shadow Rescale Factor")
);
render.rescale_shadows->register_to_ini (
dll_ini,
L"TBFIX.Render",
render_ini,
L"Shadow.Quality",
L"RescaleShadows" );

render.rescale_env_shadows =
static_cast <tbf::ParameterInt *>
(g_ParameterFactory.create_parameter <int> (
L"Environmental Shadow Rescale Factor")
);
render.rescale_env_shadows->register_to_ini (
render_ini,
L"Shadow.Quality",
L"RescaleEnvShadows" );


input.gamepad.texture_set =
static_cast <tbf::ParameterStringW *>
Expand Down Expand Up @@ -295,8 +313,6 @@ TBF_LoadConfig (std::wstring name)
audio.compatibility->load ( config.audio.compatibility );
audio.enable_fix->load ( config.audio.enable_fix );

render.rescale_shadows->load (config.render.shadow_rescale);

textures.remaster->load (config.textures.remaster);
textures.cache->load (config.textures.cache);
textures.dump->load (config.textures.dump);
Expand All @@ -307,14 +323,18 @@ TBF_LoadConfig (std::wstring name)
//sys.intro_video->load (config.system.intro_video);
sys.injector->load (config.system.injector);

if (gamepad_ini->get_sections ().empty ()) {
if (gamepad_ini->get_sections ().empty () || render_ini->get_sections ().empty ()) {
TBF_SaveConfig (name, false);

gamepad_ini->parse ();
render_ini->parse ();
}

input.gamepad.texture_set->load (config.input.gamepad.texture_set);

render.rescale_shadows->load (config.render.shadow_rescale);
render.rescale_env_shadows->load (config.render.env_shadow_rescale);

if (empty)
return false;

Expand All @@ -330,6 +350,7 @@ TBF_SaveConfig (std::wstring name, bool close_config)
audio.enable_fix->store (config.audio.enable_fix);

render.rescale_shadows->store (config.render.shadow_rescale);
render.rescale_env_shadows->store (config.render.env_shadow_rescale);

textures.remaster->store (config.textures.remaster);
textures.cache->store (config.textures.cache);
Expand All @@ -343,8 +364,9 @@ TBF_SaveConfig (std::wstring name, bool close_config)
//sys.intro_video->store (config.system.intro_video);
sys.injector->store (config.system.injector);

wchar_t wszFullName [ MAX_PATH + 2 ] = { L'\0' };
wchar_t wszPadName [ MAX_PATH + 2 ] = { L'\0' };
wchar_t wszFullName [ MAX_PATH + 2 ] = { L'\0' };
wchar_t wszPadName [ MAX_PATH + 2 ] = { L'\0' };
wchar_t wszRenderName [ MAX_PATH + 2 ] = { L'\0' };

lstrcatW ( wszFullName,
SK_GetConfigPath () );
Expand All @@ -362,6 +384,13 @@ TBF_SaveConfig (std::wstring name, bool close_config)

gamepad_ini->write (wszPadName);

lstrcatW ( wszRenderName,
SK_GetConfigPath () );
lstrcatW ( wszRenderName,
L"TBFix_Render.ini" );

render_ini->write (wszRenderName);

if (close_config) {
if (dll_ini != nullptr) {
delete dll_ini;
Expand All @@ -372,5 +401,10 @@ TBF_SaveConfig (std::wstring name, bool close_config)
delete gamepad_ini;
gamepad_ini = nullptr;
}

if (render_ini != nullptr) {
delete render_ini;
render_ini = nullptr;
}
}
}
40 changes: 21 additions & 19 deletions src/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,12 @@ D3D9EndScene_Detour (IDirect3DDevice9* This)
}
#endif

extern bool pending_loads (void);
if (pending_loads ()) {
extern void TBFix_LoadQueuedTextures (void);
TBFix_LoadQueuedTextures ();
}

typedef BOOL (__stdcall *SKX_DrawExternalOSD_pfn)(const char* szAppName, const char* szText);

static HMODULE hMod =
Expand Down Expand Up @@ -562,12 +568,6 @@ D3D9EndScene_Detour (IDirect3DDevice9* This)

HRESULT hr = D3D9EndScene_Original (This);

extern bool pending_loads (void);
if (pending_loads ()) {
extern void TBFix_LoadQueuedTextures (void);
TBFix_LoadQueuedTextures ();
}

game_state.in_skit = false;

needs_aspect = false;
Expand Down Expand Up @@ -616,12 +616,6 @@ D3D9EndFrame_Post (HRESULT hr, IUnknown* device)

hr = SK_EndBufferSwap (hr, device);

extern bool pending_loads (void);
if (pending_loads ()) {
extern void TBFix_LoadQueuedTextures (void);
TBFix_LoadQueuedTextures ();
}

//if (config.framerate.minimize_latency)
//tbf::FrameRateFix::RenderTick ();

Expand Down Expand Up @@ -812,22 +806,22 @@ D3D9SetViewport_Detour (IDirect3DDevice9* This,
return D3D9SetViewport_Original (This, &rescaled_shadow);
}

#if 0
//
// Environmental Shadows
//
if (pViewport->Width == pViewport->Height &&
(pViewport->Width == 512 ||
pViewport->Width == 1024 ||
pViewport->Width == 2048)) {
pViewport->Width == 2048 ||
pViewport->Width == 4096)) {
//tex_log->Log (L"[Shadow Mgr] (Env. Resolution: (%lu x %lu)", pViewport->Width, pViewport->Height);
D3DVIEWPORT9 rescaled_shadow = *pViewport;

rescaled_shadow.Width <<= config.render.env_shadow_rescale;
rescaled_shadow.Height <<= config.render.env_shadow_rescale;

return D3D9SetViewport_Original (This, &rescaled_shadow);
}
#endif

//
// Adjust Post-Processing
Expand Down Expand Up @@ -1120,11 +1114,10 @@ D3D9SetVertexShaderConstantF_Detour (IDirect3DDevice9* This,
return D3D9SetVertexShaderConstantF_Original (This, 240, newData, 1);
}

#if 0
//
// Env Shadow
//
if (StartRegister == 240 && Vector4fCount == 1) {
if (StartRegister == 240 && Vector4fCount == 1 && (pConstantData [0] == -pConstantData [1])) {
uint32_t shift;
uint32_t dim = 0;

Expand All @@ -1143,9 +1136,19 @@ D3D9SetVertexShaderConstantF_Detour (IDirect3DDevice9* This,
//dll_log->Log (L" 2048x2048 Shadow: VS CRC: %lu, PS CRC: %lu", vs_checksum, ps_checksum);
}

if (pConstantData [0] == -1.0f / 4096.0f) {
dim = 4096UL;
//dll_log->Log (L" 2048x2048 Shadow: VS CRC: %lu, PS CRC: %lu", vs_checksum, ps_checksum);
}

if (pConstantData [0] == -1.0f / 8192.0f) {
dim = 8192UL;
//dll_log->Log (L" 2048x2048 Shadow: VS CRC: %lu, PS CRC: %lu", vs_checksum, ps_checksum);
}

shift = config.render.env_shadow_rescale;

float newData [4] = { 0.0f, 0.0f, 0.0f, 0.0f };
float newData [4] = { 0.0f, 0.0f, pConstantData [2], pConstantData [3] };

newData [0] = -1.0f / (dim << shift);
newData [1] = 1.0f / (dim << shift);
Expand All @@ -1159,7 +1162,6 @@ D3D9SetVertexShaderConstantF_Detour (IDirect3DDevice9* This,
return D3D9SetVertexShaderConstantF_Original (This, 240, newData, 1);
}
}
#endif


//
Expand Down
Loading

0 comments on commit 4cf5abd

Please sign in to comment.