OpenBarnyard
 
Loading...
Searching...
No Matches
ASkinShader_DX8.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "ASkinShader_DX8.h"
3#include "ASkinMesh_DX8.h"
4#include "ASkinMaterial_DX8.h"
5
14
15//-----------------------------------------------------------------------------
16// Enables memory debugging.
17// Note: Should be the last include!
18//-----------------------------------------------------------------------------
19#include <Core/TMemoryDebugOn.h>
20
22
24
25#define USE_ONE_TEXTURE_LIGHTING TFALSE
26#define VERTEX_SHADER_REGISTER_MVP 0
27#define VERTEX_SHADER_REGISTER_BONES 5
28
30 : m_hUnknownPixelShader( 0 ), m_hVertexShader( 0 ), m_hVertexShaderHD( 0 ), m_hPixelShader( 0 ), m_iAlphaRef( 128 ), m_bIsAlphaBlendMaterial( TFALSE ), m_fAMDPatch1( 0.0f ), m_bCPUSupportsFeature1( TFALSE ), m_bCPUSupportsFeature2( TFALSE ), m_bUnkFlag( TFALSE ), m_bHighEndSkinning( TTRUE ), m_bLightScattering( TTRUE ), m_fAMDPatch2( 1.0f )
31{
32}
33
37
39{
40 if ( IsValidated() )
41 {
42 auto pRenderInterface = TRenderD3DInterface::Interface();
43 auto pCurrentContext = TRenderContextD3D::Upcast( pRenderInterface->GetCurrentContext() );
44 auto pDevice = pRenderInterface->GetDirect3DDevice();
45
46 if ( IsHighEndSkinning() )
47 {
48 pDevice->SetRenderState( D3DRS_ALPHATESTENABLE, 1 );
49 pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 1 );
50 pDevice->SetRenderState( D3DRS_ALPHAFUNC, 5 );
51
52 DWORD bWasSpecularEnabled;
53 pDevice->GetRenderState( D3DRS_SPECULARENABLE, &bWasSpecularEnabled );
54 pDevice->SetRenderState( D3DRS_SPECULARENABLE, 0 );
55
56 pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, 4 );
57 pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, 2 );
58 pDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, 0 );
59 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, 4 );
60 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, 2 );
61 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, 0 );
62 pDevice->SetTextureStageState( 1, D3DTSS_COLOROP, 1 );
63 pDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, 1 );
64
65 pDevice->SetRenderState( D3DRS_CULLMODE, m_bRenderEnvMap ? 3 : 2 );
66 m_aOrderTables[ 0 ].Render();
67
68 pDevice->SetRenderState( D3DRS_SPECULARENABLE, bWasSpecularEnabled );
69 pDevice->SetRenderState( D3DRS_FOGENABLE, 0 );
70 pDevice->SetPixelShader( 0 );
71 }
72 else
73 {
74 SetupLowEndMode();
75 }
76 }
77
78 BaseClass::Flush();
79}
80
82{
83 auto pRenderInterface = TRenderD3DInterface::Interface();
84 auto pCurrentContext = TRenderContextD3D::Upcast( pRenderInterface->GetCurrentContext() );
85 auto pDevice = pRenderInterface->GetDirect3DDevice();
86
87 if ( IsValidated() )
88 {
89 pDevice->SetTextureStageState( 0, D3DTSS_ADDRESSU, 1 );
90 pDevice->SetTextureStageState( 0, D3DTSS_ADDRESSV, 1 );
91
92 if ( IsHighEndSkinning() )
93 {
94 pDevice->SetRenderState( D3DRS_ALPHATESTENABLE, 1 );
95 pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 1 );
96 pDevice->SetRenderState( D3DRS_ALPHAFUNC, 5 );
97
98 DWORD bWasSpecularEnabled;
99 pDevice->GetRenderState( D3DRS_SPECULARENABLE, &bWasSpecularEnabled );
100 pDevice->SetRenderState( D3DRS_SPECULARENABLE, 0 );
101
102 pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, 4 );
103 pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, 2 );
104 pDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, 0 );
105 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, 4 );
106 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, 2 );
107 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, 0 );
108 pDevice->SetTextureStageState( 1, D3DTSS_COLOROP, 1 );
109 pDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, 1 );
110 pDevice->SetRenderState( D3DRS_CULLMODE, m_bRenderEnvMap ? 3 : 2 );
111 }
112 else
113 {
114 SetupLowEndMode();
115 return;
116 }
117 }
118}
119
121{
122 auto pRenderInterface = TRenderD3DInterface::Interface();
123 auto pDevice = pRenderInterface->GetDirect3DDevice();
124
125 pDevice->SetRenderState( D3DRS_SPECULARENABLE, 0 );
126 pDevice->SetRenderState( D3DRS_FOGENABLE, 0 );
127 pDevice->SetPixelShader( 0 );
128}
129
131{
132 m_aOrderTables[ 0 ].Create( this, -390 );
133 m_aOrderTables[ 1 ].Create( this, 1000 );
134 m_aOrderTables[ 2 ].Create( this, -400 );
135 return BaseClass::Create();
136}
137
138static TBOOL CreateSkinVertexShader( const char* a_szFileName, const DWORD* a_pFunction, DWORD* a_pOutVertexShader )
139{
140 static constexpr DWORD s_ShaderDeclaration[] = {
141 0x20000000, 0x40020000, 0x40020001, 0x40040002,
142 0x40040003, 0x40010004, 0xFFFFFFFF
143 };
144
145 return TRenderD3DInterface::CreateVertexShader( s_ShaderDeclaration, a_pFunction, a_pOutVertexShader );
146}
147
149{
150 if ( IsValidated() )
151 return TTRUE;
152
154
155 if ( IsHighEndSkinning() )
156 {
157 // High end mode
158
159 constexpr static TUINT8 s_VertexShaderFunction[] = { 0x01, 0x01, 0xfe, 0xff, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x04, 0x00, 0xe4, 0xa0, 0x03, 0x00, 0xe4, 0x90, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xb0, 0x00, 0x00, 0x00, 0x80, 0x05, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0f, 0x80, 0x05, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0f, 0x80, 0x06, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0f, 0x80, 0x07, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xb0, 0x00, 0x00, 0x55, 0x80, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0f, 0x80, 0x05, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0x55, 0x90, 0x03, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0f, 0x80, 0x06, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0x55, 0x90, 0x04, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0f, 0x80, 0x07, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0x55, 0x90, 0x05, 0x00, 0xe4, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xb0, 0x00, 0x00, 0xaa, 0x80, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0f, 0x80, 0x05, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0xaa, 0x90, 0x03, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0f, 0x80, 0x06, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0xaa, 0x90, 0x04, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0f, 0x80, 0x07, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0xaa, 0x90, 0x05, 0x00, 0xe4, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xb0, 0x00, 0x00, 0xff, 0x80, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0f, 0x80, 0x05, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0xff, 0x90, 0x03, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0f, 0x80, 0x06, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0xff, 0x90, 0x04, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0f, 0x80, 0x07, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0xff, 0x90, 0x05, 0x00, 0xe4, 0x80, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x80, 0x03, 0x00, 0xe4, 0x80, 0x00, 0x00, 0xe4, 0x90, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01, 0x80, 0x03, 0x00, 0xe4, 0x80, 0x01, 0x00, 0xe4, 0x90, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x80, 0x04, 0x00, 0xe4, 0x80, 0x00, 0x00, 0xe4, 0x90, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x02, 0x80, 0x04, 0x00, 0xe4, 0x80, 0x01, 0x00, 0xe4, 0x90, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0x04, 0x80, 0x05, 0x00, 0xe4, 0x80, 0x00, 0x00, 0xe4, 0x90, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x04, 0x80, 0x05, 0x00, 0xe4, 0x80, 0x01, 0x00, 0xe4, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x02, 0x00, 0x08, 0x80, 0x02, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x80, 0x14, 0x00, 0x00, 0x00, 0x07, 0x00, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x07, 0x00, 0xe4, 0x80, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x80, 0x02, 0x00, 0x54, 0x80, 0x5f, 0x00, 0x54, 0xa0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x80, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x02, 0x00, 0x54, 0x80, 0x5f, 0x00, 0xfe, 0xa0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x55, 0x80, 0x00, 0x00, 0xaa, 0x80, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x06, 0x00, 0xe4, 0x80, 0x59, 0x00, 0xe4, 0xa1, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x80, 0x5d, 0x00, 0xaa, 0xa0, 0x0a, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x80, 0x02, 0x00, 0x00, 0x80, 0x5d, 0x00, 0xff, 0xa0, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x02, 0x00, 0x00, 0x80, 0x5b, 0x00, 0xa4, 0xa0, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x80, 0x02, 0x00, 0xff, 0x80, 0x02, 0x00, 0x00, 0x81, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x02, 0x00, 0x00, 0x80, 0x5a, 0x00, 0xe4, 0xa0, 0x00, 0x00, 0xe4, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xd0, 0x00, 0x00, 0xe4, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xd0, 0x5a, 0x00, 0xff, 0xa0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x04, 0x00, 0xe4, 0x90, 0xff, 0xff, 0x00, 0x00 };
160 constexpr static TUINT8 s_VertexHDShaderFunction[] = { 0x01, 0x01, 0xfe, 0xff, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x04, 0x00, 0xe4, 0xa0, 0x03, 0x00, 0xe4, 0x90, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xb0, 0x00, 0x00, 0x00, 0x80, 0x05, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0f, 0x80, 0x05, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0f, 0x80, 0x06, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0f, 0x80, 0x07, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xb0, 0x00, 0x00, 0x55, 0x80, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0f, 0x80, 0x05, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0x55, 0x90, 0x03, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0f, 0x80, 0x06, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0x55, 0x90, 0x04, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0f, 0x80, 0x07, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0x55, 0x90, 0x05, 0x00, 0xe4, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xb0, 0x00, 0x00, 0xaa, 0x80, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0f, 0x80, 0x05, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0xaa, 0x90, 0x03, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0f, 0x80, 0x06, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0xaa, 0x90, 0x04, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0f, 0x80, 0x07, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0xaa, 0x90, 0x05, 0x00, 0xe4, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xb0, 0x00, 0x00, 0xff, 0x80, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0f, 0x80, 0x05, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0xff, 0x90, 0x03, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0f, 0x80, 0x06, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0xff, 0x90, 0x04, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0f, 0x80, 0x07, 0x20, 0xe4, 0xa0, 0x02, 0x00, 0xff, 0x90, 0x05, 0x00, 0xe4, 0x80, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x80, 0x03, 0x00, 0xe4, 0x80, 0x00, 0x00, 0xe4, 0x90, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01, 0x80, 0x03, 0x00, 0xe4, 0x80, 0x01, 0x00, 0xe4, 0x90, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x80, 0x04, 0x00, 0xe4, 0x80, 0x00, 0x00, 0xe4, 0x90, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x02, 0x80, 0x04, 0x00, 0xe4, 0x80, 0x01, 0x00, 0xe4, 0x90, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0x04, 0x80, 0x05, 0x00, 0xe4, 0x80, 0x00, 0x00, 0xe4, 0x90, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x04, 0x80, 0x05, 0x00, 0xe4, 0x80, 0x01, 0x00, 0xe4, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x02, 0x00, 0x08, 0x80, 0x02, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x80, 0x14, 0x00, 0x00, 0x00, 0x07, 0x00, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x07, 0x00, 0xe4, 0x80, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x06, 0x00, 0xe4, 0x80, 0x59, 0x00, 0xe4, 0xa1, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x80, 0x06, 0x00, 0xe4, 0x80, 0x5e, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xd0, 0x5a, 0x00, 0xff, 0xa0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x04, 0x00, 0xe4, 0x90, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x54, 0x80, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x54, 0x80, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x54, 0x80, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x54, 0x80, 0xff, 0xff, 0x00, 0x00 };
161
162 if ( CreateSkinVertexShader( "ASkinShader_D3D8_Win.vsh", (DWORD*)s_VertexShaderFunction, &m_hVertexShader ) &&
163 CreateSkinVertexShader( "ASkinShader_D3D8_Win.vsh", (DWORD*)s_VertexHDShaderFunction, &m_hVertexShaderHD ) )
164 {
165 constexpr static TUINT8 s_PixelShaderFunction[] = { 0x04, 0x01, 0xff, 0xff, 0xfd, 0xff, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xb0, 0x42, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xb0, 0x42, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0xb0, 0x42, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0f, 0x80, 0x03, 0x00, 0xe4, 0xb0, 0x42, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0f, 0x80, 0x04, 0x00, 0xe4, 0xb0, 0x12, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0xe4, 0x80, 0x03, 0x00, 0xe4, 0x80, 0x12, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x02, 0x00, 0xe4, 0x80, 0x04, 0x00, 0xe4, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x80, 0x00, 0x00, 0xe4, 0x80, 0x01, 0x00, 0xe4, 0x80, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x80, 0x00, 0x00, 0xe4, 0x80, 0x02, 0x00, 0xe4, 0x80, 0x05, 0x00, 0x00, 0x40, 0x00, 0x00, 0x08, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x90, 0xff, 0xff, 0x00, 0x00 };
166 constexpr static TUINT8 s_PixelShaderFunctionLowEnd[] = { 0x01, 0x01, 0xff, 0xff, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xb0, 0x42, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0f, 0xb0, 0x42, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0f, 0xb0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x80, 0x01, 0x00, 0xe4, 0xb1, 0x00, 0x00, 0xe4, 0xa0, 0x00, 0x00, 0xe4, 0xb0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x02, 0x00, 0xe4, 0xb0, 0x00, 0x00, 0xe4, 0x80, 0x01, 0x00, 0x00, 0x40, 0x00, 0x00, 0x08, 0x80, 0x00, 0x00, 0xff, 0xb0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
167
168 auto pRenderInterface = TRenderD3DInterface::Interface();
169 auto pD3DDevice = pRenderInterface->GetDirect3DDevice();
170 auto pDevice = TSTATICCAST( TD3DAdapter::Mode::Device, pRenderInterface->GetCurrentDevice() );
171
172 if ( pDevice->GetD3DCaps().PixelShaderVersion < 0xffff0104 )
173 {
174 TRenderD3DInterface::CreatePixelShader( (DWORD*)s_PixelShaderFunctionLowEnd, &m_hPixelShader );
175 }
176 else
177 {
178 TRenderD3DInterface::CreatePixelShader( (DWORD*)s_PixelShaderFunction, &m_hPixelShader );
179 }
180
181 ApplyGPUSpecificPatches();
182 CheckCPUFeature1();
183 CheckCPUFeature2();
184
185 return BaseClass::Validate();
186 }
187 else
188 {
189 return TFALSE;
190 }
191 }
192 else
193 {
194 // Low end mode
195
196 ApplyGPUSpecificPatches();
197 CheckCPUFeature1();
198 CheckCPUFeature2();
199
200 return BaseClass::Validate();
201 }
202}
203
205{
206 if ( !IsValidated() ) return;
207
208 if ( !IsHighEndSkinning() )
209 {
210 m_SomeList.DeleteAll();
211 }
212 else
213 {
214 if ( m_hVertexShader != 0 )
215 {
217 m_hVertexShader = 0;
218 }
219
220 if ( m_hVertexShaderHD != 0 )
221 {
222 TRenderD3DInterface::DestroyVertexShader( m_hVertexShaderHD );
223 m_hVertexShaderHD = 0;
224 }
225
226 if ( m_hUnknownPixelShader != 0 )
227 {
228 TRenderD3DInterface::DestroyPixelShader( m_hUnknownPixelShader );
229 m_hUnknownPixelShader = 0;
230 }
231
232 if ( m_hPixelShader != 0 )
233 {
235 m_hPixelShader = 0;
236 }
237 }
238
239 BaseClass::Invalidate();
240}
241
247
249{
250 Validate();
251 return TTRUE;
252}
253
254void ASkinShaderHAL::Render( Toshi::TRenderPacket* a_pRenderPacket )
255{
256 if ( IsHighEndSkinning() )
257 {
258 if ( a_pRenderPacket && a_pRenderPacket->GetMesh() )
259 {
260 auto pMesh = TSTATICCAST( ASkinMeshHAL, a_pRenderPacket->GetMesh() );
261 auto pMaterial = TSTATICCAST( ASkinMaterialHAL, pMesh->GetMaterial() );
262
263 if ( pMesh->GetNumSubMeshes() == 0 ) return;
264
265 auto pSkeletonInstance = a_pRenderPacket->GetSkeletonInstance();
266 TVALIDPTR( pSkeletonInstance );
267
268 TVector4 vLightingLerp1 = TVector4( 1.0f, 1.0f, 1.0f, 1.0f );
269 TVector4 vLightingLerp2 = TVector4( 1.0f, 1.0f, 1.0f, 1.0f );
270
271 auto pRenderInterface = TRenderD3DInterface::Interface();
272 auto pCurrentContext = TRenderContextD3D::Upcast( pRenderInterface->GetCurrentContext() );
273 auto pD3DDevice = pRenderInterface->GetDirect3DDevice();
274
275 if ( pMaterial->IsHDLighting() && pMaterial->HasLighting1Tex() && pMaterial->HasLighting2Tex() )
276 {
277 // Apply lighting to the skin mesh that uses the HD shader
278 // HD shader uses 4 shading textures to character models look good
279
280 Validate();
281 pD3DDevice->SetVertexShader( m_hVertexShaderHD );
282 pD3DDevice->SetPixelShader( m_hPixelShader );
283
284 TMatrix44 oViewModel;
285 oViewModel.Invert( a_pRenderPacket->GetModelViewMatrix() );
286
287 TVector4 upVector;
288 upVector.Negate3( oViewModel.AsBasisVector4( 2 ) );
289
290 pD3DDevice->SetVertexShaderConstant( 94, &upVector, 1 );
291
292 TUINT ui8ShadeCoeff = a_pRenderPacket->GetShadeCoeff();
293 TFLOAT fShadeCoeff = a_pRenderPacket->GetShadeCoeff() * ( 1.0f / 255.0f );
294
295 auto pDevice = TSTATICCAST( TD3DAdapter::Mode::Device, pRenderInterface->GetCurrentDevice() );
296
297 if ( pDevice->GetD3DCaps().PixelShaderVersion < 0xffff0104 )
298 {
299 // Can't set all 4 textures at once
300
301 TTextureResourceHAL* pLightingTex1;
302 TTextureResourceHAL* pLightingTex2;
303
304 if ( ui8ShadeCoeff == 0 )
305 {
306 pLightingTex1 = pMaterial->GetLightingTexture( ASkinMaterial::LT_0 );
307 pLightingTex2 = pMaterial->GetLightingTexture( ASkinMaterial::LT_1 );
308 }
309 else if ( ui8ShadeCoeff == 255 )
310 {
311 pLightingTex1 = pMaterial->GetLightingTexture( ASkinMaterial::LT_2 );
312 pLightingTex2 = pMaterial->GetLightingTexture( ASkinMaterial::LT_3 );
313 }
314 else if ( ui8ShadeCoeff < 127 )
315 {
316 pLightingTex1 = pMaterial->GetLightingTexture( ASkinMaterial::LT_0 );
317 pLightingTex2 = pMaterial->GetLightingTexture( ASkinMaterial::LT_1 );
318
319 vLightingLerp2.x = ( 1.0f - ( fShadeCoeff + fShadeCoeff ) ) * 0.3f + 0.7f;
320 vLightingLerp2.y = vLightingLerp2.x;
321 vLightingLerp2.z = vLightingLerp2.x;
322 }
323 else
324 {
325 pLightingTex1 = pMaterial->GetLightingTexture( ASkinMaterial::LT_2 );
326 pLightingTex2 = pMaterial->GetLightingTexture( ASkinMaterial::LT_3 );
327
328 vLightingLerp1.x = ( ( fShadeCoeff - 0.5f ) + ( fShadeCoeff - 0.5f ) ) * 0.3f + 0.7f;
329 vLightingLerp1.y = vLightingLerp1.x;
330 vLightingLerp1.z = vLightingLerp1.x;
331 }
332
333 pD3DDevice->SetPixelShaderConstant( 0, &vLightingLerp1, 1 );
334 pD3DDevice->SetPixelShaderConstant( 1, &vLightingLerp2, 1 );
335 pD3DDevice->SetTexture( 1, pLightingTex1->GetD3DTexture() );
336 pD3DDevice->SetTextureStageState( 1, D3DTSS_MIPFILTER, 0 );
337 pD3DDevice->SetTexture( 2, pLightingTex2->GetD3DTexture() );
338 pD3DDevice->SetTextureStageState( 2, D3DTSS_MIPFILTER, 0 );
339 }
340 else
341 {
342 // Can set all 4 textures at once
343
344 if ( pMaterial->GetSomeTexture() && pRenderInterface->GetCurrentDevice() && !USE_ONE_TEXTURE_LIGHTING )
345 fShadeCoeff = fShadeCoeff - 0.3f;
346
347 vLightingLerp1.x = 1.0f - fShadeCoeff;
348 vLightingLerp1.y = vLightingLerp1.x;
349 vLightingLerp1.z = vLightingLerp1.x;
350 vLightingLerp1.w = 0.0f;
351
352 vLightingLerp2.x = fShadeCoeff;
353 vLightingLerp2.y = fShadeCoeff;
354 vLightingLerp2.z = fShadeCoeff;
355 vLightingLerp2.w = 0.0f;
356
357 pD3DDevice->SetTexture( 1, pMaterial->GetLightingTexture( ASkinMaterial::LT_0 )->GetD3DTexture() );
358 pD3DDevice->SetTextureStageState( 1, D3DTSS_MIPFILTER, 0 );
359
360 pD3DDevice->SetTexture( 2, pMaterial->GetLightingTexture( ASkinMaterial::LT_1 )->GetD3DTexture() );
361 pD3DDevice->SetTextureStageState( 2, D3DTSS_MIPFILTER, 0 );
362
363 pD3DDevice->SetTexture( 3, pMaterial->GetLightingTexture( ASkinMaterial::LT_2 )->GetD3DTexture() );
364 pD3DDevice->SetTextureStageState( 3, D3DTSS_MIPFILTER, 0 );
365
366 pD3DDevice->SetTexture( 4, pMaterial->GetLightingTexture( ASkinMaterial::LT_3 )->GetD3DTexture() );
367 pD3DDevice->SetTextureStageState( 4, D3DTSS_MIPFILTER, 0 );
368
369 pD3DDevice->SetPixelShaderConstant( 0, &vLightingLerp1, 1 );
370 pD3DDevice->SetPixelShaderConstant( 1, &vLightingLerp2, 1 );
371 }
372 }
373 else
374 {
375 // Apply lighting to the skin mesh that doesn't use the HD shader
376
377 TVector4 upVector = TVector4( 0.0f, 0.0f, 0.0f, 1.0f );
378 pD3DDevice->SetVertexShaderConstant( 94, &upVector, 1 );
379
380 Validate();
381 pD3DDevice->SetVertexShader( m_hVertexShader );
382 pD3DDevice->SetPixelShader( 0 );
383
384 auto pSomeTexture = pMaterial->GetSomeTexture();
385
386 if ( pSomeTexture && pRenderInterface->GetCurrentDevice() && USE_ONE_TEXTURE_LIGHTING )
387 {
388 constexpr TFLOAT kLightingLerp1 = 0.00f;
389 constexpr TFLOAT kLightingLerp2 = 0.25f;
390
391 pD3DDevice->SetTextureStageState( 3, D3DTSS_COLOROP, 1 );
392 pD3DDevice->SetTexture( 1, pSomeTexture->GetD3DTexture() );
393 pD3DDevice->SetTexture( 2, pSomeTexture->GetD3DTexture() );
394 pD3DDevice->SetTextureStageState( 1, D3DTSS_MIPFILTER, 2 );
395 pD3DDevice->SetTextureStageState( 2, D3DTSS_MIPFILTER, 2 );
396 vLightingLerp1.x = kLightingLerp1;
397 vLightingLerp1.y = kLightingLerp1;
398 vLightingLerp1.z = kLightingLerp1;
399 vLightingLerp1.w = 0.0f;
400
401 vLightingLerp2.x = kLightingLerp2;
402 vLightingLerp2.y = kLightingLerp2;
403 vLightingLerp2.z = kLightingLerp2;
404 vLightingLerp2.w = 0.0f;
405
406 pD3DDevice->SetPixelShaderConstant( 0, &vLightingLerp1, 1 );
407 pD3DDevice->SetPixelShaderConstant( 1, &vLightingLerp2, 1 );
408 pD3DDevice->SetPixelShader( m_hPixelShader );
409 }
410 }
411
412 TMatrix44 oModelViewProjection;
413 D3DXMatrixMultiply( oModelViewProjection, a_pRenderPacket->GetModelViewMatrix(), pCurrentContext->GetProjectionMatrix() );
414 D3DXMatrixTranspose( oModelViewProjection, oModelViewProjection );
415
416 static constexpr TVector4 s_vUnknown = TVector4( 256.0f, 256.0f, 256.0f, 256.0f );
417 pD3DDevice->SetVertexShaderConstant( VERTEX_SHADER_REGISTER_MVP, oModelViewProjection, 4 );
418 pD3DDevice->SetVertexShaderConstant( 4, &s_vUnknown, 1 );
419
420 TFLOAT fLightDirX = -a_pRenderPacket->GetLightDirection().x;
421 TFLOAT fLightDirY = -a_pRenderPacket->GetLightDirection().y;
422 TFLOAT fLightDirZ = -a_pRenderPacket->GetLightDirection().z;
423 TVector4 vLightColour = a_pRenderPacket->GetLightColour();
424
425 TVector4 vAmbientColour = a_pRenderPacket->GetAmbientColour();
426 vAmbientColour.w = a_pRenderPacket->GetAlpha();
427
428 TMatrix44 oModelView = a_pRenderPacket->GetModelViewMatrix();
429 TMatrix44 oWorldModelView;
430
431 for ( TINT i = 0; i < 4; i++ )
432 {
433 oWorldModelView.AsBasisVector4( i ).x = oModelView.m_f11 * sm_oWorldViewMatrix.AsBasisVector3( i ).x + oModelView.m_f12 * sm_oWorldViewMatrix.AsBasisVector3( i ).y + oModelView.m_f13 * sm_oWorldViewMatrix.AsBasisVector3( i ).z;
434 oWorldModelView.AsBasisVector4( i ).y = oModelView.m_f21 * sm_oWorldViewMatrix.AsBasisVector3( i ).x + oModelView.m_f22 * sm_oWorldViewMatrix.AsBasisVector3( i ).y + oModelView.m_f23 * sm_oWorldViewMatrix.AsBasisVector3( i ).z;
435 oWorldModelView.AsBasisVector4( i ).z = oModelView.m_f31 * sm_oWorldViewMatrix.AsBasisVector3( i ).x + oModelView.m_f32 * sm_oWorldViewMatrix.AsBasisVector3( i ).y + oModelView.m_f33 * sm_oWorldViewMatrix.AsBasisVector3( i ).z;
436 oWorldModelView.AsBasisVector4( i ).w = oModelView.m_f14 * sm_oWorldViewMatrix.AsBasisVector3( i ).x + oModelView.m_f24 * sm_oWorldViewMatrix.AsBasisVector3( i ).y + oModelView.m_f34 * sm_oWorldViewMatrix.AsBasisVector3( i ).z;
437 }
438
439 Toshi::TVector3 vLightDirWorld;
440 vLightDirWorld.x = oWorldModelView.m_f11 * fLightDirX + oWorldModelView.m_f21 * fLightDirY + oWorldModelView.m_f31 * fLightDirZ;
441 vLightDirWorld.y = oWorldModelView.m_f12 * fLightDirX + oWorldModelView.m_f22 * fLightDirY + oWorldModelView.m_f32 * fLightDirZ;
442 vLightDirWorld.z = oWorldModelView.m_f13 * fLightDirX + oWorldModelView.m_f23 * fLightDirY + oWorldModelView.m_f33 * fLightDirZ;
443 vLightDirWorld.Normalize();
444
445 TVector4 vUnkVector = TVector4( 1.0f, 0.0f, 0.0f, 1.0f );
446
447 pD3DDevice->SetVertexShaderConstant( 89, &vLightDirWorld, 1 );
448 pD3DDevice->SetVertexShaderConstant( 90, &vAmbientColour, 1 );
449 pD3DDevice->SetVertexShaderConstant( 91, &vLightColour, 1 );
450 pD3DDevice->SetVertexShaderConstant( 93, &vUnkVector, 1 );
451
452 TINT iAlpha = TINT( a_pRenderPacket->GetAlpha() * 128.0f );
453 if ( m_iAlphaRef < iAlpha ) iAlpha = m_iAlphaRef;
454 pD3DDevice->SetRenderState( D3DRS_ALPHAREF, iAlpha );
455
456 if ( pMaterial->GetBlendMode() != 0 || a_pRenderPacket->GetAlpha() < 1.0f )
457 {
458 if ( ISZERO( sm_eRenderStateFlags & 0x1b ) )
459 {
460 pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
461 sm_eRenderStateFlags |= 0x1b;
462 }
463 }
464 else if ( !ISZERO( sm_eRenderStateFlags & 0x1b ) )
465 {
466 pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
467 sm_eRenderStateFlags &= ~0x1b;
468 }
469
470 auto pVertexPool = TSTATICCAST( TVertexPoolResource, pMesh->GetVertexPool() );
471
472 TVertexBlockResource::HALBuffer vertexHALBuffer;
473 pVertexPool->GetHALBuffer( &vertexHALBuffer );
474 pD3DDevice->SetStreamSource( 0, vertexHALBuffer.apVertexBuffers[ 0 ], 0x28 );
475
476 for ( TINT i = 0; i < pMesh->GetNumSubMeshes(); i++ )
477 {
478 auto pSubMesh = pMesh->GetSubMesh( i );
479
480 TINT iCurrentRegister = VERTEX_SHADER_REGISTER_BONES;
481
482 for ( TUINT k = 0; k < pSubMesh->uiNumBones; k++ )
483 {
484 auto pBone = &pSkeletonInstance->GetBone( pSubMesh->aBones[ k ] );
485
486 TMatrix44 oBoneTransform;
487 D3DXMatrixTranspose( oBoneTransform, pBone->m_Transform );
488 pD3DDevice->SetVertexShaderConstant( iCurrentRegister, oBoneTransform, 3 );
489
490 iCurrentRegister += 3;
491 }
492
493 auto pIndexPool = TSTATICCAST( TIndexPoolResource, pSubMesh->pIndexPool );
494 TVALIDPTR( pIndexPool );
495
496 TIndexBlockResource::HALBuffer indexHALBuffer;
497 pIndexPool->GetHALBuffer( &indexHALBuffer );
498
499 pD3DDevice->SetIndices( indexHALBuffer.pIndexBuffer, vertexHALBuffer.uiVertexOffset );
500 pD3DDevice->DrawIndexedPrimitive(
501 D3DPT_TRIANGLESTRIP,
502 0,
503 pVertexPool->GetNumVertices(),
504 indexHALBuffer.uiIndexOffset,
505 pIndexPool->GetNumIndices()
506 );
507 }
508 }
509 }
510 else
511 {
512 RenderLowEnd( a_pRenderPacket );
513 }
514}
515
517{
518 m_bRenderEnvMap = a_bEnable;
519}
520
522{
523 return m_bHighEndSkinning;
524}
525
527{
528 m_bHighEndSkinning = a_bEnable && IsCapableHighEndSkinning();
529}
530
532{
533 D3DCAPS8 caps;
534
535 auto pRenderInterface = TRenderD3DInterface::Interface();
536 auto pDevice = pRenderInterface->GetDirect3DDevice();
537
538 if ( !pDevice )
539 {
540 auto pDirect3D = pRenderInterface->GetDirect3D();
541
542 TVALIDPTR( pDirect3D );
543 if ( !pDirect3D ) return TFALSE;
544
545 pDirect3D->GetDeviceCaps( 0, D3DDEVTYPE_HAL, &caps );
546 }
547 else
548 {
549 pDevice->GetDeviceCaps( &caps );
550 }
551
552 return ( ( caps.VertexShaderVersion & 0xFFFF ) > 256 ) && ( caps.DevCaps & 0x10000 );
553}
554
556{
557 return m_bLightScattering;
558}
559
561{
562}
563
565{
566 return m_bIsAlphaBlendMaterial;
567}
568
569void ASkinShaderHAL::SetAlphaBlendMaterial( TBOOL a_bIsAlphaBlendMaterial )
570{
571 m_bIsAlphaBlendMaterial = a_bIsAlphaBlendMaterial;
572}
573
575{
576 Validate();
577
578 auto pMaterial = new ASkinMaterialHAL();
579 pMaterial->SetShader( this );
580
581 if ( TNULL != a_szName )
582 pMaterial->SetName( a_szName );
583
585 {
586 auto pAlphaBlendMaterial = new ASkinMaterialHAL();
587 pAlphaBlendMaterial->SetShader( this );
588 pAlphaBlendMaterial->Create( 1 );
589
590 pMaterial->SetAlphaBlendMaterial( pAlphaBlendMaterial );
591 }
592
593 return pMaterial;
594}
595
597{
598 Validate();
599
600 auto pMesh = new ASkinMeshHAL();
601 pMesh->SetOwnerShader( this );
602
603 return pMesh;
604}
605
606TINT ASkinShaderHAL::AddLight( const Toshi::TVector3& a_rPosition, TFLOAT a_fIntensity )
607{
608 TASSERT( !"Not implemeted in the original game" );
609 return 0;
610}
611
612void ASkinShaderHAL::SetLight( TINT a_iIndex, const Toshi::TVector3& a_rPosition, TFLOAT a_fIntensity )
613{
614 TASSERT( !"Not implemeted in the original game" );
615}
616
618{
619 TASSERT( !"Not implemeted in the original game" );
620}
621
623{
624 return m_bRenderEnvMap;
625}
626
627void ASkinShaderHAL::SetSomeColour( TUINT a_uiR, TUINT a_uiG, TUINT a_uiB, TUINT a_uiA )
628{
629 m_SomeColour = ( ( a_uiA << 8 | a_uiB ) << 8 | a_uiG ) << 8 | a_uiR;
630}
631
633{
634 if ( m_SomeColourComponents[ 1 ] < 2 )
635 m_Unk3 = a_fAlpha * ( 1.0f / 128.0f );
636 else if ( m_SomeColourComponents[ 0 ] == 0 )
637 m_Unk3 = 1.0f;
638 else
639 m_Unk3 = 0.0f;
640
641 return m_Unk2;
642}
643
645{
646 m_Unk2 = a_Unknown;
647}
648
650{
651 auto pRender = TRenderD3DInterface::Interface();
652 auto pD3DDevice = pRender->GetDirect3DDevice();
653
654 pD3DDevice->SetRenderState( D3DRS_ALPHAREF, 1 );
655 m_iAlphaRef = a_iAlphaRef;
656}
657
658void ASkinShaderHAL::RenderLowEnd( Toshi::TRenderPacket* a_pRenderPacket )
659{
660 TASSERT( !"Hello there" );
661}
662
663void ASkinShaderHAL::SetupLowEndMode()
664{
665 auto pRenderInterface = TRenderD3DInterface::Interface();
666 auto pCurrentContext = TRenderContextD3D::Upcast( pRenderInterface->GetCurrentContext() );
667 auto pDevice = pRenderInterface->GetDirect3DDevice();
668
669 pDevice->SetVertexShader( 0x1d2 );
670 pDevice->SetPixelShader( 0 );
671 pDevice->SetRenderState( D3DRS_LIGHTING, 1 );
672 pDevice->SetRenderState( D3DRS_FOGENABLE, 0 );
673 pDevice->SetRenderState( D3DRS_ALPHATESTENABLE, 1 );
674 pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 1 );
675 pDevice->SetRenderState( D3DRS_SRCBLEND, 5 );
676 pDevice->SetRenderState( D3DRS_DESTBLEND, 6 );
677 pDevice->SetRenderState( D3DRS_ALPHAFUNC, 5 );
678
679 DWORD bWasSpecularEnabled;
680 pDevice->GetRenderState( D3DRS_SPECULARENABLE, &bWasSpecularEnabled );
681 pDevice->SetRenderState( D3DRS_SPECULARENABLE, 0 );
682
683 pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, 4 );
684 pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, 2 );
685 pDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, 0 );
686 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, 4 );
687 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, 2 );
688 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, 0 );
689 pDevice->SetTextureStageState( 1, D3DTSS_COLOROP, 1 );
690 pDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, 1 );
691
692 pDevice->SetRenderState( D3DRS_CULLMODE, m_bRenderEnvMap ? 3 : 2 );
693
694 static TMatrix44 s_IdentityMatrix = TMatrix44::IDENTITY;
695
696 pDevice->SetTransform( D3DTS_VIEW, s_IdentityMatrix );
697 pDevice->SetTransform( D3DTS_PROJECTION, pCurrentContext->GetProjectionMatrix() );
698 m_aOrderTables[ 0 ].Render();
699
700 pDevice->SetRenderState( D3DRS_SPECULARENABLE, bWasSpecularEnabled );
701 pDevice->SetRenderState( D3DRS_FOGENABLE, 0 );
702}
703
704void ASkinShaderHAL::ApplyGPUSpecificPatches()
705{
706 auto pRenderInterface = TRenderD3DInterface::Interface();
707 auto pDevice = pRenderInterface->GetCurrentDevice();
708 auto pMode = pDevice->GetMode();
709 auto pAdapter = pMode->GetAdapter();
710
711 if ( T2String8::CompareNoCase( pAdapter->GetDriverDescription(), "RADEON 8500 / RADEON 8500LE" ) == 0 )
712 {
713 m_fAMDPatch1 = 0.005f;
714 m_fAMDPatch2 = 0.99995f;
715 }
716}
717
718void ASkinShaderHAL::CheckCPUFeature1()
719{
720 TIMPLEMENT();
721 m_bCPUSupportsFeature1 = TTRUE;
722}
723
724void ASkinShaderHAL::CheckCPUFeature2()
725{
726 TIMPLEMENT();
727 m_bCPUSupportsFeature2 = TTRUE;
728}
#define TIMPLEMENT()
Definition Defines.h:136
#define TASSERT(X,...)
Definition Defines.h:138
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
#define TOSHI_NAMESPACE_USING
Definition Defines.h:46
#define ISZERO(X)
Definition Defines.h:3
#define TVALIDPTR(PTR)
Definition Defines.h:139
#define TDEFINE_CLASS(...)
Definition TObject.h:120
unsigned int TUINT
Definition Typedefs.h:8
char TCHAR
Definition Typedefs.h:20
uint8_t TUINT8
Definition Typedefs.h:17
float TFLOAT
Definition Typedefs.h:4
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
#define USE_ONE_TEXTURE_LIGHTING
#define VERTEX_SHADER_REGISTER_MVP
#define VERTEX_SHADER_REGISTER_BONES
TFLOAT m_f21
Definition TMatrix44.h:361
TFLOAT m_f12
Definition TMatrix44.h:360
TBOOL Invert(const TMatrix44 &a_rRight)
Definition TMatrix44.cpp:88
TFLOAT m_f32
Definition TMatrix44.h:362
TFLOAT m_f13
Definition TMatrix44.h:360
static constinit TMatrix44 IDENTITY
Definition TMatrix44.h:357
TFLOAT m_f14
Definition TMatrix44.h:360
TFLOAT m_f11
Definition TMatrix44.h:360
TFLOAT m_f23
Definition TMatrix44.h:361
TFLOAT m_f22
Definition TMatrix44.h:361
TFLOAT m_f31
Definition TMatrix44.h:362
TFLOAT m_f24
Definition TMatrix44.h:361
const TVector4 & AsBasisVector4(BASISVECTOR a_iIndex) const
Definition TMatrix44.h:131
TFLOAT m_f34
Definition TMatrix44.h:362
TFLOAT m_f33
Definition TMatrix44.h:362
TFLOAT w
Definition TVector4.h:367
TFLOAT x
Definition TVector4.h:367
TFLOAT y
Definition TVector4.h:367
constexpr void Negate3(const TVector4 &vec)
Definition TVector4.h:265
TFLOAT z
Definition TVector4.h:367
static TRenderContextD3D * Upcast(TRenderContext *a_pRenderContext)
static TBOOL CreateVertexShader(const DWORD *a_ShaderDeclaration, const DWORD *a_pFunction, DWORD *a_pOutVertexShader)
Creates a vertex shader.
static TFORCEINLINE TRenderD3DInterface * Interface()
Gets the render interface singleton.
static void DestroyPixelShader(DWORD a_hPixelShader)
Destroys a pixel shader.
static TBOOL CreatePixelShader(const DWORD *a_pFunction, DWORD *a_pOutPixelShader)
Creates a pixel shader.
static void DestroyVertexShader(DWORD a_hVertexShader)
Destroys a vertex shader.
IDirect3DTexture8 * GetD3DTexture()
IDirect3DVertexBuffer8 * apVertexBuffers[TVertexFactoryFormat::MAX_NUM_STREAMS]
static TINT CompareNoCase(const TCHAR *str1, const TCHAR *str2, TSIZE size=-1)
Definition T2String8.cpp:60
virtual void StartFlush() override
virtual void EnableHighEndSkinning(TBOOL a_bEnable) override
virtual void RemoveLight(TINT a_iIndex) override
virtual TBOOL TryValidate() override
virtual TBOOL IsAlphaBlendMaterial() override
virtual TBOOL IsCapableHighEndSkinning() override
virtual ASkinMaterial * CreateMaterial(const TCHAR *a_szName) override
virtual TBOOL Validate() override
virtual TBOOL IsHighEndSkinning() override
virtual void Render(Toshi::TRenderPacket *a_pRenderPacket) override
static Toshi::TMatrix44 sm_oWorldViewMatrix
virtual TBOOL IsLightScattering() override
virtual TINT AddLight(const Toshi::TVector3 &a_rPosition, TFLOAT a_fIntensity) override
virtual void SetUnknown2(TINT a_Unknown)
virtual TBOOL Create() override
virtual void SetLight(TINT a_iIndex, const Toshi::TVector3 &a_rPosition, TFLOAT a_fIntensity) override
virtual ASkinMesh * CreateMesh(const TCHAR *a_szName) override
virtual void SetAlphaBlendMaterial(TBOOL a_bIsAlphaBlendMaterial) override
static TUINT sm_eRenderStateFlags
virtual TBOOL IsEnableRenderEnvMap()
virtual void Flush() override
virtual TINT SetUnknown1(TINT a_Unknown, TUINT8 a_fAlpha)
virtual void EndFlush() override
void SetAlphaRef(TINT a_iAlphaRef)
virtual void SetLightScattering(TBOOL a_bEnable) override
virtual void Invalidate() override
virtual void EnableRenderEnvMap(TBOOL a_bEnable) override
virtual TBOOL TryInvalidate() override
virtual void SetSomeColour(TUINT a_uiR, TUINT a_uiG, TUINT a_uiB, TUINT a_uiA)
TUINT8 m_SomeColourComponents[8]
Definition ASkinShader.h:43
TFLOAT m_Unk3
Definition ASkinShader.h:47
TINT32 m_SomeColour
Definition ASkinShader.h:44