III/VC: Fix rendering corona lines on non-nvidia GPU's

This commit is contained in:
Silent 2019-12-07 18:21:00 +01:00
parent df012b84cf
commit c9e34d5761
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
2 changed files with 45 additions and 0 deletions

View File

@ -4,6 +4,9 @@
#include "Utils/Patterns.h"
#include "StoredCar.h"
#include <rwcore.h>
RwCamera*& Camera = **hook::get_pattern<RwCamera**>( "A1 ? ? ? ? D8 88 ? ? ? ?", 1 );
// ============= handling.cfg name matching fix =============
namespace HandlingNameLoadFix
@ -19,6 +22,26 @@ namespace HandlingNameLoadFix
}
};
// ============= Corona lines rendering fix =============
namespace CoronaLinesFix
{
static RwBool RenderLine_SetRecipZ( RwIm2DVertex *vertices, RwInt32 numVertices, RwInt32 vert1, RwInt32 vert2 )
{
const RwReal nearScreenZ = RwIm2DGetNearScreenZ();
const RwReal nearZ = RwCameraGetNearClipPlane( Camera );
const RwReal recipZ = 1.0f / nearZ;
for ( RwInt32 i = 0; i < numVertices; i++ )
{
RwIm2DVertexSetScreenZ( &vertices[i], nearScreenZ );
RwIm2DVertexSetCameraZ( &vertices[i], nearZ );
RwIm2DVertexSetRecipCameraZ( &vertices[i], recipZ );
}
return RwIm2DRenderLine( vertices, numVertices, vert1, vert2 );
}
}
// ============= Delayed patches =============
namespace DelayedPatches
{
@ -92,6 +115,17 @@ namespace Common {
InjectHook( findExactWord.get<void>( -5 ), strncpy_Fix );
InjectHook( findExactWord.get<void>( 0xD ), strncmp_Fix );
}
// Fixed corona lines rendering on non-nvidia cards
{
using namespace CoronaLinesFix;
auto renderLine = get_pattern( "E8 ? ? ? ? 83 C4 10 FF 44 24 1C 43" );
InjectHook( renderLine, RenderLine_SetRecipZ );
}
}
void III_VC_SetDelayedPatchesFunc( void(*func)() )

View File

@ -34,3 +34,14 @@ void** GTARwEngineInstance = []() -> void** {
assert(!"Could not locate RwEngineInstance!");
return nullptr;
}();
RwBool RwIm2DRenderLine(RwIm2DVertex *vertices, RwInt32 numVertices, RwInt32 vert1, RwInt32 vert2)
{
return GTARWSRCGLOBAL(dOpenDevice).fpIm2DRenderLine( vertices, numVertices, vert1, vert2 );
}
RwReal RwIm2DGetNearScreenZ()
{
return GTARWSRCGLOBAL(dOpenDevice).zBufferNear;
}