improved shader stuff

This commit is contained in:
Silent 2014-06-04 23:09:13 +02:00
parent 93e5e13ce0
commit c706013ee8
4 changed files with 135 additions and 76 deletions

View file

@ -26,5 +26,6 @@
//#define HIDE_MATERIAL //#define HIDE_MATERIAL
//#define EXPAND_ALPHA_ENTITY_LISTS 800 //#define EXPAND_ALPHA_ENTITY_LISTS 800
//#define EXPAND_BOAT_ALPHA_ATOMIC_LISTS 400
//#define SA_STEAM_TEST //#define SA_STEAM_TEST

View file

@ -1528,7 +1528,7 @@ void __declspec(naked) DumpIPLStub()
#include "nvc.h" #include "nvc.h"
static IDirect3DVertexShader9* pNVCShader = nullptr; static IDirect3DVertexShader9* pNVCShader = nullptr;
static bool bRenderNVC; static bool bRenderNVC = false;
static RpAtomic* pRenderedAtomic; static RpAtomic* pRenderedAtomic;
WRAPPER void _rwD3D9SetVertexShader(void *shader) { EAXJMP(0x7F9FB0); } WRAPPER void _rwD3D9SetVertexShader(void *shader) { EAXJMP(0x7F9FB0); }
@ -1546,15 +1546,28 @@ WRAPPER RwBool _rpD3D9VertexDeclarationInstColor(RwUInt8 *mem,
RwInt32 numVerts, RwInt32 numVerts,
RwUInt32 stride) { EAXJMP(0x754AE0); } RwUInt32 stride) { EAXJMP(0x754AE0); }
void CompileShader() WRAPPER bool IsVisionFXActive() { EAXJMP(0x7034F0); }
{
static bool bCompiledYet = false;
if ( !bCompiledYet ) bool ShaderAttach()
{
// CGame::InitialiseRenderWare
// TODO: EXEs
if ( ((bool(*)())0x5BD600)() )
{ {
bCompiledYet = true;
RwD3D9CreateVertexShader(reinterpret_cast<const RwUInt32*>(g_vs20_NVC_vertex_shader), reinterpret_cast<void**>(&pNVCShader)); RwD3D9CreateVertexShader(reinterpret_cast<const RwUInt32*>(g_vs20_NVC_vertex_shader), reinterpret_cast<void**>(&pNVCShader));
return true;
} }
return false;
}
void ShaderDetach()
{
if ( pNVCShader )
RwD3D9DeleteVertexShader(pNVCShader);
// PluginDetach?
// TODO: EXEs
((void(*)())0x53BB80)();
} }
void SetShader(void* shader) void SetShader(void* shader)
@ -1564,6 +1577,9 @@ void SetShader(void* shader)
// TODO: Daynight balance var // TODO: Daynight balance var
D3DMATRIX outMat; D3DMATRIX outMat;
float fDayNightBalance = *(float*)0x8D12C0; float fDayNightBalance = *(float*)0x8D12C0;
RwRGBAReal* AmbientLight = RpLightGetColor(*(RpLight**)0xC886E8);
assert(!shader);
RwD3D9SetVertexShader(pNVCShader); RwD3D9SetVertexShader(pNVCShader);
@ -1572,6 +1588,7 @@ void SetShader(void* shader)
RwD3D9SetVertexShaderConstant(0, &outMat, 4); RwD3D9SetVertexShaderConstant(0, &outMat, 4);
RwD3D9SetVertexShaderConstant(4, &fDayNightBalance, 1); RwD3D9SetVertexShaderConstant(4, &fDayNightBalance, 1);
RwD3D9SetVertexShaderConstant(5, AmbientLight, 1);
} }
else else
RwD3D9SetVertexShader(shader); RwD3D9SetVertexShader(shader);
@ -1586,7 +1603,6 @@ void __declspec(naked) SetShader2()
push edx push edx
push edi push edi
push ebp push ebp
call CompileShader
mov eax, 5DA6A0h mov eax, 5DA6A0h
call eax call eax
add esp, 10h add esp, 10h
@ -1702,11 +1718,13 @@ __forceinline void Patch_SA_10()
using namespace MemoryVP; using namespace MemoryVP;
// TEMP - shaders! // TEMP - shaders!
/*InjectHook(0x5DA743, SetShader); InjectHook(0x5DA743, SetShader);
InjectHook(0x5D66F1, SetShader2); InjectHook(0x5D66F1, SetShader2);
InjectHook(0x5D6116, UsageIndex1, PATCH_JUMP); InjectHook(0x5D6116, UsageIndex1, PATCH_JUMP);
InjectHook(0x5D63B7, PassDayColoursToShader, PATCH_JUMP); InjectHook(0x5D63B7, PassDayColoursToShader, PATCH_JUMP);
InjectHook(0x5D637B, HijackEsi, PATCH_JUMP); InjectHook(0x5D637B, HijackEsi, PATCH_JUMP);
InjectHook(0x5BF3A1, ShaderAttach);
InjectHook(0x53D910, ShaderDetach);
Patch<const void*>(0x5D67F4, HijackAtomic); Patch<const void*>(0x5D67F4, HijackAtomic);
Patch<BYTE>(0x5D7200, 0xC3); Patch<BYTE>(0x5D7200, 0xC3);
Patch<WORD>(0x5D67BB, 0x6890); Patch<WORD>(0x5D67BB, 0x6890);
@ -1719,7 +1737,10 @@ __forceinline void Patch_SA_10()
Patch<BYTE>(0x5D60CF, sizeof(D3DCOLOR)); Patch<BYTE>(0x5D60CF, sizeof(D3DCOLOR));
Patch<BYTE>(0x5D60EA, sizeof(D3DCOLOR)); Patch<BYTE>(0x5D60EA, sizeof(D3DCOLOR));
Patch<BYTE>(0x5D60C2, 0x13); Patch<BYTE>(0x5D60C2, 0x13);
Patch<BYTE>(0x5D62F0, 0xEB);*/ Patch<BYTE>(0x5D62F0, 0xEB);
// PostFX fix
Patch<float>(*(float**)0x7034C0, 0.0);
//Patch<BYTE>(0x5D7265, 0xEB); //Patch<BYTE>(0x5D7265, 0xEB);
@ -1735,6 +1756,16 @@ __forceinline void Patch_SA_10()
Patch<const void*>(0x73445E, RenderBigVehicleActomic); Patch<const void*>(0x73445E, RenderBigVehicleActomic);
//Patch<const void*>(0x73406E, TwoPassAlphaRender); //Patch<const void*>(0x73406E, TwoPassAlphaRender);
// Boats
/*Patch<BYTE>(0x4C79DF, 0x19);
Patch<DWORD>(0x733A87, EXPAND_BOAT_ALPHA_ATOMIC_LISTS * sizeof(AlphaObjectInfo));
Patch<DWORD>(0x733AD7, EXPAND_BOAT_ALPHA_ATOMIC_LISTS * sizeof(AlphaObjectInfo));*/
// Fixed strafing? Hopefully
static const float fStrafeCheck = 0.1f;
Patch<const void*>(0x61E0C2, &fStrafeCheck);
Nop(0x61E0CA, 6);
// Plane rotors // Plane rotors
InjectHook(0x4C7981, PlaneAtomicRendererSetup, PATCH_JUMP); InjectHook(0x4C7981, PlaneAtomicRendererSetup, PATCH_JUMP);

View file

@ -15,6 +15,7 @@ struct VS_OUTPUT
float4x4 viewProjMatrix : register(c0); float4x4 viewProjMatrix : register(c0);
float fDayNightBalance : register(c4); float fDayNightBalance : register(c4);
float4 AmbientLight : register(c5);
VS_OUTPUT NVC_vertex_shader( in VS_INPUT In ) VS_OUTPUT NVC_vertex_shader( in VS_INPUT In )
{ {
@ -22,7 +23,10 @@ VS_OUTPUT NVC_vertex_shader( in VS_INPUT In )
Out.Position = mul(In.Position, viewProjMatrix); Out.Position = mul(In.Position, viewProjMatrix);
Out.Texture = In.Texture; Out.Texture = In.Texture;
Out.Color = In.DayColor * (1.0-fDayNightBalance) + In.NightColor * fDayNightBalance;
Out.Color = (In.DayColor * (1.0-fDayNightBalance) + In.NightColor * fDayNightBalance);
Out.Color.rgb += AmbientLight.rgb * AmbientLight.a;
Out.Color = saturate(Out.Color);
return Out; return Out;
} }

View file

@ -8,6 +8,7 @@
// //
// Parameters: // Parameters:
// //
// float4 AmbientLight;
// float fDayNightBalance; // float fDayNightBalance;
// float4x4 viewProjMatrix; // float4x4 viewProjMatrix;
// //
@ -18,10 +19,11 @@
// ---------------- ----- ---- // ---------------- ----- ----
// viewProjMatrix c0 4 // viewProjMatrix c0 4
// fDayNightBalance c4 1 // fDayNightBalance c4 1
// AmbientLight c5 1
// //
vs_2_0 vs_2_0
def c5, 1, 0, 0, 0 def c6, 1, 0, 0, 0
dcl_position v0 dcl_position v0
dcl_texcoord v1 dcl_texcoord v1
dcl_color v2 dcl_color v2
@ -30,85 +32,106 @@
dp4 oPos.y, v0, c1 dp4 oPos.y, v0, c1
dp4 oPos.z, v0, c2 dp4 oPos.z, v0, c2
dp4 oPos.w, v0, c3 dp4 oPos.w, v0, c3
mov r0.x, c4.x mov r0.x, c6.x
add r0.x, -r0.x, c5.x add r0.x, r0.x, -c4.x
mul r1, v2, c4.x mul r1, v2, c4.x
mad oD0, v3, r0.x, r1 mad r0, v3, r0.x, r1
mad r0.xyz, c5, c5.w, r0
max r0, r0, c6.y
min oD0, r0, c6.x
mov oT0.xy, v1 mov oT0.xy, v1
// approximately 9 instruction slots used // approximately 12 instruction slots used
#endif #endif
const BYTE g_vs20_NVC_vertex_shader[] = const BYTE g_vs20_NVC_vertex_shader[] =
{ {
0, 2, 254, 255, 254, 255, 0, 2, 254, 255, 254, 255,
49, 0, 67, 84, 65, 66, 62, 0, 67, 84, 65, 66,
28, 0, 0, 0, 143, 0, 28, 0, 0, 0, 195, 0,
0, 0, 0, 2, 254, 255, 0, 0, 0, 2, 254, 255,
2, 0, 0, 0, 28, 0, 3, 0, 0, 0, 28, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
136, 0, 0, 0, 68, 0, 188, 0, 0, 0, 88, 0,
0, 0, 2, 0, 4, 0, 0, 0, 2, 0, 5, 0,
1, 0, 18, 0, 88, 0, 1, 0, 22, 0, 104, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104, 0, 0, 0, 2, 0, 120, 0, 0, 0, 2, 0,
0, 0, 4, 0, 2, 0, 4, 0, 1, 0, 18, 0,
120, 0, 0, 0, 0, 0, 140, 0, 0, 0, 0, 0,
0, 0, 102, 68, 97, 121, 0, 0, 156, 0, 0, 0,
78, 105, 103, 104, 116, 66, 2, 0, 0, 0, 4, 0,
97, 108, 97, 110, 99, 101, 2, 0, 172, 0, 0, 0,
0, 171, 171, 171, 0, 0, 0, 0, 0, 0, 65, 109,
3, 0, 1, 0, 1, 0, 98, 105, 101, 110, 116, 76,
105, 103, 104, 116, 0, 171,
171, 171, 1, 0, 3, 0,
1, 0, 4, 0, 1, 0,
0, 0, 0, 0, 0, 0,
102, 68, 97, 121, 78, 105,
103, 104, 116, 66, 97, 108,
97, 110, 99, 101, 0, 171,
171, 171, 0, 0, 3, 0,
1, 0, 1, 0, 1, 0,
0, 0, 0, 0, 0, 0,
118, 105, 101, 119, 80, 114,
111, 106, 77, 97, 116, 114,
105, 120, 0, 171, 3, 0,
3, 0, 4, 0, 4, 0,
1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 118, 105, 101, 119, 0, 0, 118, 115, 95, 50,
80, 114, 111, 106, 77, 97, 95, 48, 0, 77, 105, 99,
116, 114, 105, 120, 0, 171, 114, 111, 115, 111, 102, 116,
3, 0, 3, 0, 4, 0, 32, 40, 82, 41, 32, 72,
4, 0, 1, 0, 0, 0, 76, 83, 76, 32, 83, 104,
0, 0, 0, 0, 118, 115, 97, 100, 101, 114, 32, 67,
95, 50, 95, 48, 0, 77, 111, 109, 112, 105, 108, 101,
105, 99, 114, 111, 115, 111, 114, 32, 57, 46, 50, 57,
102, 116, 32, 40, 82, 41, 46, 57, 53, 50, 46, 51,
32, 72, 76, 83, 76, 32, 49, 49, 49, 0, 81, 0,
83, 104, 97, 100, 101, 114, 0, 5, 6, 0, 15, 160,
32, 67, 111, 109, 112, 105, 0, 0, 128, 63, 0, 0,
108, 101, 114, 32, 57, 46,
50, 57, 46, 57, 53, 50,
46, 51, 49, 49, 49, 0,
81, 0, 0, 5, 5, 0,
15, 160, 0, 0, 128, 63,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 0,
31, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 128,
0, 128, 0, 0, 15, 144, 0, 0, 15, 144, 31, 0,
31, 0, 0, 2, 5, 0, 0, 2, 5, 0, 0, 128,
0, 128, 1, 0, 15, 144, 1, 0, 15, 144, 31, 0,
31, 0, 0, 2, 10, 0, 0, 2, 10, 0, 0, 128,
0, 128, 2, 0, 15, 144, 2, 0, 15, 144, 31, 0,
31, 0, 0, 2, 10, 0, 0, 2, 10, 0, 1, 128,
1, 128, 3, 0, 15, 144, 3, 0, 15, 144, 9, 0,
9, 0, 0, 3, 0, 0, 0, 3, 0, 0, 1, 192,
1, 192, 0, 0, 228, 144, 0, 0, 228, 144, 0, 0,
0, 0, 228, 160, 9, 0,
0, 3, 0, 0, 2, 192,
0, 0, 228, 144, 1, 0,
228, 160, 9, 0, 0, 3, 228, 160, 9, 0, 0, 3,
0, 0, 4, 192, 0, 0, 0, 0, 2, 192, 0, 0,
228, 144, 2, 0, 228, 160, 228, 144, 1, 0, 228, 160,
9, 0, 0, 3, 0, 0, 9, 0, 0, 3, 0, 0,
8, 192, 0, 0, 228, 144, 4, 192, 0, 0, 228, 144,
3, 0, 228, 160, 1, 0, 2, 0, 228, 160, 9, 0,
0, 2, 0, 0, 1, 128, 0, 3, 0, 0, 8, 192,
4, 0, 0, 160, 2, 0, 0, 0, 228, 144, 3, 0,
0, 3, 0, 0, 1, 128, 228, 160, 1, 0, 0, 2,
0, 0, 0, 129, 5, 0, 0, 0, 1, 128, 6, 0,
0, 160, 5, 0, 0, 3, 0, 160, 2, 0, 0, 3,
1, 0, 15, 128, 2, 0, 0, 0, 1, 128, 0, 0,
228, 144, 4, 0, 0, 160, 0, 128, 4, 0, 0, 161,
5, 0, 0, 3, 1, 0,
15, 128, 2, 0, 228, 144,
4, 0, 0, 160, 4, 0,
0, 4, 0, 0, 15, 128,
3, 0, 228, 144, 0, 0,
0, 128, 1, 0, 228, 128,
4, 0, 0, 4, 0, 0, 4, 0, 0, 4, 0, 0,
15, 208, 3, 0, 228, 144, 7, 128, 5, 0, 228, 160,
0, 0, 0, 128, 1, 0, 5, 0, 255, 160, 0, 0,
228, 128, 1, 0, 0, 2, 228, 128, 11, 0, 0, 3,
0, 0, 3, 224, 1, 0, 0, 0, 15, 128, 0, 0,
228, 144, 255, 255, 0, 0 228, 128, 6, 0, 85, 160,
10, 0, 0, 3, 0, 0,
15, 208, 0, 0, 228, 128,
6, 0, 0, 160, 1, 0,
0, 2, 0, 0, 3, 224,
1, 0, 228, 144, 255, 255,
0, 0
}; };