Shader as a resource

This commit is contained in:
Silent 2015-02-08 19:52:41 +01:00
parent babe3c6f71
commit 3fd04e395a
7 changed files with 30 additions and 186 deletions

View file

@ -114,12 +114,12 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio
<ItemGroup> <ItemGroup>
<CustomBuild Include="..\SilentPatch\nvc.fx"> <CustomBuild Include="..\SilentPatch\nvc.fx">
<FileType>Document</FileType> <FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">fxc /T vs_2_0 /E NVC_vertex_shader /Fh ..\SilentPatch\nvc.h ..\SilentPatch\nvc.fx</Command> <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">fxc /T vs_2_0 /E NVC_vertex_shader /Fo ..\SilentPatch\nvc.cso ..\SilentPatch\nvc.fx</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\SilentPatch\nvc.h</Outputs> <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\SilentPatch\nvc.cso</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compiling shaders...</Message> <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compiling shaders...</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">fxc /T vs_2_0 /E NVC_vertex_shader /Fh ..\SilentPatch\nvc.h ..\SilentPatch\nvc.fx</Command> <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">fxc /T vs_2_0 /E NVC_vertex_shader /Fo ..\SilentPatch\nvc.cso ..\SilentPatch\nvc.fx</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compiling shaders...</Message> <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compiling shaders...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\SilentPatch\nvc.h</Outputs> <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\SilentPatch\nvc.cso</Outputs>
</CustomBuild> </CustomBuild>
<MASM Include="..\SilentPatch\win2000.asm"> <MASM Include="..\SilentPatch\win2000.asm">
<FileType>Document</FileType> <FileType>Document</FileType>
@ -141,11 +141,15 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio
<ClInclude Include="ModelInfoSA.h" /> <ClInclude Include="ModelInfoSA.h" />
<ClInclude Include="PedSA.h" /> <ClInclude Include="PedSA.h" />
<ClInclude Include="PNGFile.h" /> <ClInclude Include="PNGFile.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="ScriptSA.h" /> <ClInclude Include="ScriptSA.h" />
<ClInclude Include="StdAfxSA.h" /> <ClInclude Include="StdAfxSA.h" />
<ClInclude Include="TimerSA.h" /> <ClInclude Include="TimerSA.h" />
<ClInclude Include="VehicleSA.h" /> <ClInclude Include="VehicleSA.h" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ResourceCompile Include="Shaders.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" /> <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />

View file

@ -110,6 +110,9 @@
<ClInclude Include="PedSA.h"> <ClInclude Include="PedSA.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="..\SilentPatch\nvc.fx"> <CustomBuild Include="..\SilentPatch\nvc.fx">
@ -121,4 +124,9 @@
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</MASM> </MASM>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ResourceCompile Include="Shaders.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project> </Project>

BIN
SAFix/Shaders.rc Normal file

Binary file not shown.

View file

@ -728,8 +728,6 @@ void DrawRect_HalfPixel_Steam(CRect& rect, const CRGBA& rgba)
((void(*)(const CRect&, const CRGBA&))0x75CDA0)(rect, rgba); ((void(*)(const CRect&, const CRGBA&))0x75CDA0)(rect, rgba);
} }
#include "nvc.h"
static IDirect3DVertexShader9* pNVCShader = nullptr; static IDirect3DVertexShader9* pNVCShader = nullptr;
static bool bRenderNVC = false; static bool bRenderNVC = false;
static RpAtomic* pRenderedAtomic; static RpAtomic* pRenderedAtomic;
@ -739,7 +737,15 @@ bool ShaderAttach()
// CGame::InitialiseRenderWare // CGame::InitialiseRenderWare
if ( InitialiseRenderWare() ) if ( InitialiseRenderWare() )
{ {
RwD3D9CreateVertexShader(reinterpret_cast<const RwUInt32*>(g_vs20_NVC_vertex_shader), reinterpret_cast<void**>(&pNVCShader)); HMODULE thisModule;
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR)ShaderAttach, &thisModule);
HRSRC resource = FindResource(thisModule, MAKEINTRESOURCE(IDR_NVCSHADER), RT_RCDATA);
RwUInt32* shader = static_cast<RwUInt32*>(LoadResource(thisModule, resource));
RwD3D9CreateVertexShader(shader, reinterpret_cast<void**>(&pNVCShader));
FreeResource(shader);
return true; return true;
} }
return false; return false;

View file

@ -8,8 +8,8 @@
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#define WINVER 0x0500 #define WINVER 0x0501
#define _WIN32_WINNT 0x0500 #define _WIN32_WINNT 0x0501
#include <windows.h> #include <windows.h>
#include <utility> #include <utility>
@ -33,6 +33,8 @@
#include <d3d9.h> #include <d3d9.h>
#include "resource.h"
#include "MemoryMgr.h" #include "MemoryMgr.h"
#include "Maths.h" #include "Maths.h"

1
SAFix/resource.h Normal file
View file

@ -0,0 +1 @@
#define IDR_NVCSHADER 101

View file

@ -1,177 +0,0 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
// Parameters:
//
// float4 AmbientLight;
// float2 fEnvVars;
// float4x4 proj;
// float4x4 view;
// float4x4 world;
//
//
// Registers:
//
// Name Reg Size
// ------------ ----- ----
// fEnvVars c0 1
// AmbientLight c1 1
// world c2 4
// view c6 4
// proj c10 4
//
vs_2_0
def c14, 0, 1, 0, 0
dcl_position v0
dcl_texcoord v1
dcl_color v2
dcl_color1 v3
mul r0, v0.y, c3
mad r0, c2, v0.x, r0
mad r0, c4, v0.z, r0
mad r0, c5, v0.w, r0
mul r1, r0.y, c7
mad r1, c6, r0.x, r1
mad r1, c8, r0.z, r1
mad r0, c9, r0.w, r1
mul r1, r0.y, c11
mad r1, c10, r0.x, r1
mad r1, c12, r0.z, r1
mad oPos, c13, r0.w, r1
mov r0.xyz, v3
add r0.xyz, -r0, v2
mad r0.xyz, c0.x, r0, v3
add r0.xyz, r0, c1
mul r0.w, v2.w, c0.y
max r0, r0, c14.x
min oD0, r0, c14.y
mov oT0.xy, v1
// approximately 20 instruction slots used
#endif
const BYTE g_vs20_NVC_vertex_shader[] =
{
0, 2, 254, 255, 254, 255,
71, 0, 67, 84, 65, 66,
28, 0, 0, 0, 230, 0,
0, 0, 0, 2, 254, 255,
5, 0, 0, 0, 28, 0,
0, 0, 0, 1, 0, 0,
223, 0, 0, 0, 128, 0,
0, 0, 2, 0, 1, 0,
1, 0, 6, 0, 144, 0,
0, 0, 0, 0, 0, 0,
160, 0, 0, 0, 2, 0,
0, 0, 1, 0, 2, 0,
172, 0, 0, 0, 0, 0,
0, 0, 188, 0, 0, 0,
2, 0, 10, 0, 4, 0,
42, 0, 196, 0, 0, 0,
0, 0, 0, 0, 212, 0,
0, 0, 2, 0, 6, 0,
4, 0, 26, 0, 196, 0,
0, 0, 0, 0, 0, 0,
217, 0, 0, 0, 2, 0,
2, 0, 4, 0, 10, 0,
196, 0, 0, 0, 0, 0,
0, 0, 65, 109, 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, 69,
110, 118, 86, 97, 114, 115,
0, 171, 171, 171, 1, 0,
3, 0, 1, 0, 2, 0,
1, 0, 0, 0, 0, 0,
0, 0, 112, 114, 111, 106,
0, 171, 171, 171, 3, 0,
3, 0, 4, 0, 4, 0,
1, 0, 0, 0, 0, 0,
0, 0, 118, 105, 101, 119,
0, 119, 111, 114, 108, 100,
0, 118, 115, 95, 50, 95,
48, 0, 77, 105, 99, 114,
111, 115, 111, 102, 116, 32,
40, 82, 41, 32, 72, 76,
83, 76, 32, 83, 104, 97,
100, 101, 114, 32, 67, 111,
109, 112, 105, 108, 101, 114,
32, 54, 46, 51, 46, 57,
54, 48, 48, 46, 49, 54,
51, 56, 52, 0, 81, 0,
0, 5, 14, 0, 15, 160,
0, 0, 0, 0, 0, 0,
128, 63, 0, 0, 0, 0,
0, 0, 0, 0, 31, 0,
0, 2, 0, 0, 0, 128,
0, 0, 15, 144, 31, 0,
0, 2, 5, 0, 0, 128,
1, 0, 15, 144, 31, 0,
0, 2, 10, 0, 0, 128,
2, 0, 15, 144, 31, 0,
0, 2, 10, 0, 1, 128,
3, 0, 15, 144, 5, 0,
0, 3, 0, 0, 15, 128,
0, 0, 85, 144, 3, 0,
228, 160, 4, 0, 0, 4,
0, 0, 15, 128, 2, 0,
228, 160, 0, 0, 0, 144,
0, 0, 228, 128, 4, 0,
0, 4, 0, 0, 15, 128,
4, 0, 228, 160, 0, 0,
170, 144, 0, 0, 228, 128,
4, 0, 0, 4, 0, 0,
15, 128, 5, 0, 228, 160,
0, 0, 255, 144, 0, 0,
228, 128, 5, 0, 0, 3,
1, 0, 15, 128, 0, 0,
85, 128, 7, 0, 228, 160,
4, 0, 0, 4, 1, 0,
15, 128, 6, 0, 228, 160,
0, 0, 0, 128, 1, 0,
228, 128, 4, 0, 0, 4,
1, 0, 15, 128, 8, 0,
228, 160, 0, 0, 170, 128,
1, 0, 228, 128, 4, 0,
0, 4, 0, 0, 15, 128,
9, 0, 228, 160, 0, 0,
255, 128, 1, 0, 228, 128,
5, 0, 0, 3, 1, 0,
15, 128, 0, 0, 85, 128,
11, 0, 228, 160, 4, 0,
0, 4, 1, 0, 15, 128,
10, 0, 228, 160, 0, 0,
0, 128, 1, 0, 228, 128,
4, 0, 0, 4, 1, 0,
15, 128, 12, 0, 228, 160,
0, 0, 170, 128, 1, 0,
228, 128, 4, 0, 0, 4,
0, 0, 15, 192, 13, 0,
228, 160, 0, 0, 255, 128,
1, 0, 228, 128, 1, 0,
0, 2, 0, 0, 7, 128,
3, 0, 228, 144, 2, 0,
0, 3, 0, 0, 7, 128,
0, 0, 228, 129, 2, 0,
228, 144, 4, 0, 0, 4,
0, 0, 7, 128, 0, 0,
0, 160, 0, 0, 228, 128,
3, 0, 228, 144, 2, 0,
0, 3, 0, 0, 7, 128,
0, 0, 228, 128, 1, 0,
228, 160, 5, 0, 0, 3,
0, 0, 8, 128, 2, 0,
255, 144, 0, 0, 85, 160,
11, 0, 0, 3, 0, 0,
15, 128, 0, 0, 228, 128,
14, 0, 0, 160, 10, 0,
0, 3, 0, 0, 15, 208,
0, 0, 228, 128, 14, 0,
85, 160, 1, 0, 0, 2,
0, 0, 3, 224, 1, 0,
228, 144, 255, 255, 0, 0
};