Fixed flickering and alpha bugs in nvc shader.

This commit is contained in:
aap 2014-11-28 15:26:59 +01:00
parent b2c1a775e0
commit c8f8be75f3
3 changed files with 201 additions and 142 deletions

View file

@ -1,4 +1,5 @@
#include "StdAfxSA.h"
#include <limits>
#include "ScriptSA.h"
#include "GeneralSA.h"
@ -50,6 +51,8 @@ WRAPPER RwBool _rpD3D9VertexDeclarationInstColor(RwUInt8 *mem,
RwInt32 numVerts,
RwUInt32 stride) { VARJMP(var_rpD3D9VertexDeclarationInstColor); }
static void* varRwD3D9GetTransform = AddressByVersion<void*>(0x007FA4F0, 0x007FA4F0, 0x007FA4F0);
WRAPPER void _RwD3D9GetTransform(RwUInt32 state, void* matrix) { VARJMP(varRwD3D9GetTransform); }
RwCamera* RwCameraBeginUpdate(RwCamera* camera)
{
@ -718,7 +721,8 @@ BOOL Initialise3D(void* pParam)
void SetShader(RxD3D9InstanceData* pInstData)
{
if ( bRenderNVC )
//GetAsyncKeyState(VK_F5) &&
if (bRenderNVC )
{
D3DMATRIX outMat;
float fEnvVars[2] = { m_fDNBalanceParam, RpMaterialGetColor(pInstData->material)->alpha * (1.0f/255.0f) };
@ -735,7 +739,15 @@ void SetShader(RxD3D9InstanceData* pInstData)
_rwD3D9VSSetActiveWorldMatrix(RwFrameGetLTM(RpAtomicGetFrame(pRenderedAtomic)));
//_rwD3D9VSSetActiveWorldMatrix(RwFrameGetMatrix(RpAtomicGetFrame(pRenderedAtomic)));
_rwD3D9VSGetComposedTransformMatrix(&outMat);
D3DMATRIX worldMat, viewMat, projMat;
_RwD3D9GetTransform(D3DTS_WORLD, &worldMat);
_RwD3D9GetTransform(D3DTS_VIEW, &viewMat);
_RwD3D9GetTransform(D3DTS_PROJECTION, &projMat);
RwD3D9SetVertexShaderConstant(6, &worldMat, 4);
RwD3D9SetVertexShaderConstant(10, &viewMat, 4);
RwD3D9SetVertexShaderConstant(14, &projMat, 4);
RwD3D9SetVertexShaderConstant(0, &outMat, 4);
RwD3D9SetVertexShaderConstant(4, fEnvVars, 1);
RwD3D9SetVertexShaderConstant(5, AmbientLight, 1);

View file

@ -16,16 +16,20 @@ struct VS_OUTPUT
float4x4 viewProjMatrix : register(c0);
float2 fEnvVars : register(c4);
float4 AmbientLight : register(c5);
float4x4 world : register(c6);
float4x4 view : register(c10);
float4x4 proj : register(c14);
VS_OUTPUT NVC_vertex_shader( in VS_INPUT In )
{
VS_OUTPUT Out;
Out.Position = mul(In.Position, viewProjMatrix);
// Out.Position = mul(In.Position, viewProjMatrix);
Out.Position = mul(proj, mul(view, mul(world, In.Position)));
Out.Texture = In.Texture;
Out.Color.rgb = (In.DayColor.rgb * (1.0-fEnvVars[0]) + In.NightColor.rgb * fEnvVars[0]) + AmbientLight.rgb;
Out.Color.a = In.DayColor.a * fEnvVars[1];
Out.Color.a = In.DayColor.a * (256.0/128.0) * fEnvVars[1];
//Out.Color.rgb = In.DayColor.rgb + AmbientLight.rgb;
Out.Color = saturate(Out.Color);

View file

@ -1,138 +1,181 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
// fxc /T vs_2_0 /E NVC_vertex_shader /Fh ..\SilentPatch\nvc.h
// ..\SilentPatch\nvc.fx
//
//
// Parameters:
//
// float4 AmbientLight;
// float2 fEnvVars;
// float4x4 viewProjMatrix;
//
//
// Registers:
//
// Name Reg Size
// -------------- ----- ----
// viewProjMatrix c0 4
// fEnvVars c4 1
// AmbientLight c5 1
//
vs_2_0
def c6, 1, 0, 0, 0
dcl_position v0
dcl_texcoord v1
dcl_color v2
dcl_color1 v3
dp4 oPos.x, v0, c0
dp4 oPos.y, v0, c1
dp4 oPos.z, v0, c2
dp4 oPos.w, v0, c3
mov r0.x, c6.x
add r0.x, r0.x, -c4.x
mul r0.yzw, v2.xxyz, c4.x
mad r0.xyz, v3, r0.x, r0.yzww
add r0.xyz, r0, c5
mul r0.w, v3.w, c4.y
max r0, r0, c6.y
min oD0, r0, c6.x
mov oT0.xy, v1
// approximately 13 instruction slots used
#endif
const BYTE g_vs20_NVC_vertex_shader[] =
{
0, 2, 254, 255, 254, 255,
60, 0, 67, 84, 65, 66,
28, 0, 0, 0, 187, 0,
0, 0, 0, 2, 254, 255,
3, 0, 0, 0, 28, 0,
0, 0, 0, 1, 0, 0,
180, 0, 0, 0, 88, 0,
0, 0, 2, 0, 5, 0,
1, 0, 22, 0, 104, 0,
0, 0, 0, 0, 0, 0,
120, 0, 0, 0, 2, 0,
4, 0, 1, 0, 18, 0,
132, 0, 0, 0, 0, 0,
0, 0, 148, 0, 0, 0,
2, 0, 0, 0, 4, 0,
2, 0, 164, 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, 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, 0, 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,
57, 46, 50, 57, 46, 57,
53, 50, 46, 51, 49, 49,
49, 0, 81, 0, 0, 5,
6, 0, 15, 160, 0, 0,
128, 63, 0, 0, 0, 0,
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, 9, 0, 0, 3,
0, 0, 1, 192, 0, 0,
228, 144, 0, 0, 228, 160,
9, 0, 0, 3, 0, 0,
2, 192, 0, 0, 228, 144,
1, 0, 228, 160, 9, 0,
0, 3, 0, 0, 4, 192,
0, 0, 228, 144, 2, 0,
228, 160, 9, 0, 0, 3,
0, 0, 8, 192, 0, 0,
228, 144, 3, 0, 228, 160,
1, 0, 0, 2, 0, 0,
1, 128, 6, 0, 0, 160,
2, 0, 0, 3, 0, 0,
1, 128, 0, 0, 0, 128,
4, 0, 0, 161, 5, 0,
0, 3, 0, 0, 14, 128,
2, 0, 144, 144, 4, 0,
0, 160, 4, 0, 0, 4,
0, 0, 7, 128, 3, 0,
228, 144, 0, 0, 0, 128,
0, 0, 249, 128, 2, 0,
0, 3, 0, 0, 7, 128,
0, 0, 228, 128, 5, 0,
228, 160, 5, 0, 0, 3,
0, 0, 8, 128, 3, 0,
255, 144, 4, 0, 85, 160,
11, 0, 0, 3, 0, 0,
15, 128, 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
};
#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 c4 1
// AmbientLight c5 1
// world c6 4
// view c10 4
// proj c14 4
//
vs_2_0
def c0, 1, 0, 0, 0
dcl_position v0
dcl_texcoord v1
dcl_color v2
dcl_color1 v3
mul r0, v0.y, c7
mad r0, c6, v0.x, r0
mad r0, c8, v0.z, r0
mad r0, c9, v0.w, r0
mul r1, r0.y, c11
mad r1, c10, r0.x, r1
mad r1, c12, r0.z, r1
mad r0, c13, r0.w, r1
mul r1, r0.y, c15
mad r1, c14, r0.x, r1
mad r1, c16, r0.z, r1
mad oPos, c17, r0.w, r1
mov r0.x, c0.x
add r0.x, r0.x, -c4.x
mul r0.yzw, v2.xxyz, c4.x
mad r0.xyz, v3, r0.x, r0.yzww
add r0.xyz, r0, c5
mul r0.w, v3.w, c4.y
max r0, r0, c0.y
min oD0, r0, c0.x
mov oT0.xy, v1
// approximately 21 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, 5, 0,
1, 0, 22, 0, 144, 0,
0, 0, 0, 0, 0, 0,
160, 0, 0, 0, 2, 0,
4, 0, 1, 0, 18, 0,
172, 0, 0, 0, 0, 0,
0, 0, 188, 0, 0, 0,
2, 0, 14, 0, 4, 0,
58, 0, 196, 0, 0, 0,
0, 0, 0, 0, 212, 0,
0, 0, 2, 0, 10, 0,
4, 0, 42, 0, 196, 0,
0, 0, 0, 0, 0, 0,
217, 0, 0, 0, 2, 0,
6, 0, 4, 0, 26, 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, 0, 0, 15, 160,
0, 0, 128, 63, 0, 0,
0, 0, 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, 7, 0,
228, 160, 4, 0, 0, 4,
0, 0, 15, 128, 6, 0,
228, 160, 0, 0, 0, 144,
0, 0, 228, 128, 4, 0,
0, 4, 0, 0, 15, 128,
8, 0, 228, 160, 0, 0,
170, 144, 0, 0, 228, 128,
4, 0, 0, 4, 0, 0,
15, 128, 9, 0, 228, 160,
0, 0, 255, 144, 0, 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, 128,
13, 0, 228, 160, 0, 0,
255, 128, 1, 0, 228, 128,
5, 0, 0, 3, 1, 0,
15, 128, 0, 0, 85, 128,
15, 0, 228, 160, 4, 0,
0, 4, 1, 0, 15, 128,
14, 0, 228, 160, 0, 0,
0, 128, 1, 0, 228, 128,
4, 0, 0, 4, 1, 0,
15, 128, 16, 0, 228, 160,
0, 0, 170, 128, 1, 0,
228, 128, 4, 0, 0, 4,
0, 0, 15, 192, 17, 0,
228, 160, 0, 0, 255, 128,
1, 0, 228, 128, 1, 0,
0, 2, 0, 0, 1, 128,
0, 0, 0, 160, 2, 0,
0, 3, 0, 0, 1, 128,
0, 0, 0, 128, 4, 0,
0, 161, 5, 0, 0, 3,
0, 0, 14, 128, 2, 0,
144, 144, 4, 0, 0, 160,
4, 0, 0, 4, 0, 0,
7, 128, 3, 0, 228, 144,
0, 0, 0, 128, 0, 0,
249, 128, 2, 0, 0, 3,
0, 0, 7, 128, 0, 0,
228, 128, 5, 0, 228, 160,
5, 0, 0, 3, 0, 0,
8, 128, 3, 0, 255, 144,
4, 0, 85, 160, 11, 0,
0, 3, 0, 0, 15, 128,
0, 0, 228, 128, 0, 0,
85, 160, 10, 0, 0, 3,
0, 0, 15, 208, 0, 0,
228, 128, 0, 0, 0, 160,
1, 0, 0, 2, 0, 0,
3, 224, 1, 0, 228, 144,
255, 255, 0, 0
};