Optimized NVC shader

This commit is contained in:
Silent 2015-04-23 18:41:20 +02:00
parent 403df49335
commit c50c0a2c1d
3 changed files with 49 additions and 24 deletions

View file

@ -15,15 +15,17 @@ struct VS_OUTPUT
float2 fEnvVars : register(c0); float2 fEnvVars : register(c0);
float4 AmbientLight : register(c1); float4 AmbientLight : register(c1);
float4x4 world : register(c2); float4x4 worldViewProj : register(c2);
float4x4 view : register(c6); //float4x4 world : register(c2);
float4x4 proj : register(c10); //float4x4 view : register(c6);
//float4x4 proj : register(c10);
VS_OUTPUT NVC_vertex_shader( in VS_INPUT In ) VS_OUTPUT NVC_vertex_shader( in VS_INPUT In )
{ {
VS_OUTPUT Out; VS_OUTPUT Out;
Out.Position = mul(proj, mul(view, mul(world, In.Position))); //Out.Position = mul(proj, mul(view, mul(world, In.Position)));
Out.Position = mul(worldViewProj, In.Position);
Out.Texture = In.Texture; Out.Texture = In.Texture;
Out.Color.rgb = lerp(In.DayColor, In.NightColor, fEnvVars[0]).rgb + AmbientLight.rgb; Out.Color.rgb = lerp(In.DayColor, In.NightColor, fEnvVars[0]).rgb + AmbientLight.rgb;

View file

@ -686,9 +686,11 @@ char* GetMyDocumentsPath()
return cUserFilesPath; return cUserFilesPath;
} }
#include <xnamath.h>
static void* pNVCShader = nullptr; static void* pNVCShader = nullptr;
static bool bRenderNVC = false; static bool bRenderNVC = false;
static RpAtomic* pRenderedAtomic; static bool bXMSupported;
bool ShaderAttach() bool ShaderAttach()
{ {
@ -704,6 +706,8 @@ bool ShaderAttach()
RwD3D9CreateVertexShader(shader, reinterpret_cast<void**>(&pNVCShader)); RwD3D9CreateVertexShader(shader, reinterpret_cast<void**>(&pNVCShader));
FreeResource(shader); FreeResource(shader);
bXMSupported = XMVerifyCPUSupport();
return true; return true;
} }
return false; return false;
@ -746,13 +750,46 @@ void SetShader(RxD3D9InstanceData* pInstData)
//_rwD3D9VSSetActiveWorldMatrix(RwFrameGetMatrix(RpAtomicGetFrame(pRenderedAtomic))); //_rwD3D9VSSetActiveWorldMatrix(RwFrameGetMatrix(RpAtomicGetFrame(pRenderedAtomic)));
//_rwD3D9VSGetComposedTransformMatrix(&outMat); //_rwD3D9VSGetComposedTransformMatrix(&outMat);
D3DMATRIX worldMat, viewMat, projMat; XMMATRIX worldMat, viewMat, projMat;
XMMATRIX worldViewProjMat;
_RwD3D9GetTransform(D3DTS_WORLD, &worldMat); _RwD3D9GetTransform(D3DTS_WORLD, &worldMat);
_RwD3D9GetTransform(D3DTS_VIEW, &viewMat); _RwD3D9GetTransform(D3DTS_VIEW, &viewMat);
_RwD3D9GetTransform(D3DTS_PROJECTION, &projMat); _RwD3D9GetTransform(D3DTS_PROJECTION, &projMat);
RwD3D9SetVertexShaderConstant(2, &worldMat, 4);
RwD3D9SetVertexShaderConstant(6, &viewMat, 4); if ( bXMSupported )
RwD3D9SetVertexShaderConstant(10, &projMat, 4); {
worldViewProjMat = XMMatrixMultiply(XMMatrixMultiply(worldMat, viewMat), projMat);
}
else
{
XMMATRIX tempMat;
ZeroMemory(&worldViewProjMat, sizeof(worldViewProjMat));
ZeroMemory(&tempMat, sizeof(tempMat));
for( int i = 0; i < 4; i++ )
{
for( int j = 0; j < 4; j++ )
{
for(int x = 0; x < 4; x++)
tempMat.m[i][j] += worldMat.m[i][x] * viewMat.m[x][j];
}
}
for( int i = 0; i < 4; i++ )
{
for( int j = 0; j < 4; j++ )
{
for(int x = 0; x < 4; x++)
worldViewProjMat.m[i][j] += tempMat.m[i][x] * projMat.m[x][j];
}
}
}
//RwD3D9SetVertexShaderConstant(2, &worldMat, 4);
//RwD3D9SetVertexShaderConstant(6, &viewMat, 4);
//RwD3D9SetVertexShaderConstant(10, &projMat, 4);
RwD3D9SetVertexShaderConstant(2, &worldViewProjMat, 4);
RwD3D9SetVertexShaderConstant(0, fEnvVars, 1); RwD3D9SetVertexShaderConstant(0, fEnvVars, 1);
RwD3D9SetVertexShaderConstant(1, AmbientLight, 1); RwD3D9SetVertexShaderConstant(1, AmbientLight, 1);
@ -761,17 +798,6 @@ void SetShader(RxD3D9InstanceData* pInstData)
RwD3D9SetVertexShader(pInstData->vertexShader); RwD3D9SetVertexShader(pInstData->vertexShader);
} }
static void* HijackAtomic_JumpBack = AddressByVersion<void*>(0x5D6480, 0x5D6C60, 0x5F2C80);
void __declspec(naked) HijackAtomic()
{
_asm
{
mov eax, [esp+8]
mov pRenderedAtomic, eax
jmp HijackAtomic_JumpBack
}
}
void __declspec(naked) SetShader2() void __declspec(naked) SetShader2()
{ {
_asm _asm
@ -1726,7 +1752,6 @@ BOOL InjectDelayedPatches_10()
InjectHook(0x5D637B, HijackEsi, PATCH_JUMP); InjectHook(0x5D637B, HijackEsi, PATCH_JUMP);
InjectHook(0x5BF3A1, ShaderAttach); InjectHook(0x5BF3A1, ShaderAttach);
InjectHook(0x53D910, ShaderDetach); InjectHook(0x53D910, ShaderDetach);
Patch<const void*>(0x5D67F4, HijackAtomic);
Patch<BYTE>(0x5D7200, 0xC3); Patch<BYTE>(0x5D7200, 0xC3);
Patch<WORD>(0x5D67BB, 0x6890); Patch<WORD>(0x5D67BB, 0x6890);
Patch<WORD>(0x5D67D7, 0x6890); Patch<WORD>(0x5D67D7, 0x6890);
@ -1935,7 +1960,6 @@ BOOL InjectDelayedPatches_11()
InjectHook(0x5D6B5B, HijackEsi, PATCH_JUMP); InjectHook(0x5D6B5B, HijackEsi, PATCH_JUMP);
//InjectHook(0x5BF3A1, ShaderAttach); //InjectHook(0x5BF3A1, ShaderAttach);
InjectHook(0x53DDB0, ShaderDetach); InjectHook(0x53DDB0, ShaderDetach);
Patch<const void*>(0x5D6FD4, HijackAtomic);
Patch<BYTE>(0x5D79E0, 0xC3); Patch<BYTE>(0x5D79E0, 0xC3);
Patch<WORD>(0x5D6F9B, 0x6890); Patch<WORD>(0x5D6F9B, 0x6890);
Patch<WORD>(0x5D6FB7, 0x6890); Patch<WORD>(0x5D6FB7, 0x6890);
@ -2150,7 +2174,6 @@ BOOL InjectDelayedPatches_Steam()
InjectHook(0x5F2B7A, HijackEsi, PATCH_JUMP); InjectHook(0x5F2B7A, HijackEsi, PATCH_JUMP);
InjectHook(0x5DE5A1, ShaderAttach); InjectHook(0x5DE5A1, ShaderAttach);
InjectHook(0x550070, ShaderDetach); InjectHook(0x550070, ShaderDetach);
Patch<const void*>(0x5F3004, HijackAtomic);
Patch<BYTE>(0x5F3760, 0xC3); Patch<BYTE>(0x5F3760, 0xC3);
Patch<WORD>(0x5F2FCB, 0x6890); Patch<WORD>(0x5F2FCB, 0x6890);
Patch<WORD>(0x5F2FE7, 0x6890); Patch<WORD>(0x5F2FE7, 0x6890);

View file

@ -81,7 +81,7 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio
<PreprocessorDefinitions>SILENTPATCH_SA_VER;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>SILENTPATCH_SA_VER;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling> <StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>D:\RWSDK\Graphics\rwsdk\include\d3d9;..\SilentPatch</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>D:\RWSDK\Graphics\rwsdk\include\d3d9;$(DXSDK_DIR)\Include;..\SilentPatch</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>StdAfxSA.h</PrecompiledHeaderFile> <PrecompiledHeaderFile>StdAfxSA.h</PrecompiledHeaderFile>
</ClCompile> </ClCompile>