ShaderEffect: port ShaderEffect, ShadowCache, manager and parser TUs
ShaderEffect.cpp (0x8728C0-0x873F50), ShadowCache.cpp (0x873F60-0x876370), ShaderEffectManager.cpp (0x876370-0x876E30) and ShaderEffectParser.cpp (0x876E30-0x8773F0). Shared additions: GxRenderTargetSet, CGxDevice::DeviceGetRenderTarget, C44Matrix::Identity, CWFrustum (m_sceneLink removed: 0xF4 stride), M2LIGHTTYPE and the CM2Lighting::SetupGxLights declaration. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
@@ -1897,3 +1897,9 @@ void CGxDevice::ITexWHDStartEnd(CGxTex* texId, uint32_t& width, uint32_t& height
|
||||
mipCount = baseMip + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: 4458969e manual
|
||||
// OFFSET: 0x00682D50
|
||||
void CGxDevice::DeviceGetRenderTarget(EGxBuffer buffer, CGxTex*& texture) {
|
||||
texture = this->m_textureTarget[buffer].m_texture;
|
||||
}
|
||||
|
||||
@@ -304,6 +304,7 @@ class CGxDevice {
|
||||
const CRect& DeviceCurWindow();
|
||||
const CRect& DeviceDefWindow();
|
||||
void DeviceGamma(CGxGammaRamp& ramp);
|
||||
void DeviceGetRenderTarget(EGxBuffer buffer, CGxTex*& texture);
|
||||
void DeviceScreenShot();
|
||||
void DeviceSetCurWindow(const CRect& rect);
|
||||
void DeviceSetDefWindow(const CRect& rect);
|
||||
|
||||
@@ -750,3 +750,10 @@ void GxFormatColor(CImVector& color) {
|
||||
color = formatted;
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: 25db0bac manual
|
||||
// OFFSET: 0x0057E4F0
|
||||
void GxRenderTargetSet(EGxBuffer buffer, CGxTex* texture, uint32_t plane) {
|
||||
GxRsSet(GxRs_ScissorTest, 0);
|
||||
g_theGxDevicePtr->DeviceSetRenderTarget(buffer, texture, plane);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ class CRect;
|
||||
char* GxBufLock(CGxBuf* buf);
|
||||
void GxBufUnlock(CGxBuf* buf, uint32_t size);
|
||||
void GxBufDestroy(CGxBuf* buf);
|
||||
void GxRenderTargetSet(EGxBuffer buffer, CGxTex* texture, uint32_t plane);
|
||||
void GxBufData(CGxBuf* buf, const void* data, uint32_t size, uint32_t offset);
|
||||
CGxBuf* GxBufStream(EGxPoolTarget target, uint32_t itemSize, uint32_t itemCount);
|
||||
void GxPrimIndexPtr(uint32_t indexCount, const uint16_t* indices);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <windows.h>
|
||||
#include "Engine/Source/Model2/Types.h"
|
||||
#include "Engine/Source/Tempest/C3Vector.h"
|
||||
#include "Engine/Source/Tempest/C4Plane.h"
|
||||
#include "Engine/Source/Tempest/CAaSphere.h"
|
||||
@@ -15,7 +16,7 @@ class CM2Light {
|
||||
public:
|
||||
/* 0000 */ CM2Scene* m_scene;
|
||||
/* 0004 */ uint32_t m_stamp;
|
||||
/* 0008 */ uint32_t m_type;
|
||||
/* 0008 */ M2LIGHTTYPE m_type;
|
||||
/* 000C */ C3Vector m_pos;
|
||||
/* 0018 */ C3Vector m_viewPos;
|
||||
/* 0024 */ C3Vector m_dir;
|
||||
@@ -53,6 +54,8 @@ class CM2Lighting {
|
||||
/* 00B4 */ float m_fogDensity;
|
||||
/* 00B8 */ C3Vector m_fogColor;
|
||||
/* 00C4 */ C4Plane m_liquidPlane;
|
||||
|
||||
void SetupGxLights(const C3Vector* origin);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
#include <cstdint>
|
||||
#include <windows.h>
|
||||
|
||||
enum M2LIGHTTYPE {
|
||||
M2LIGHT_DIRECT = 0,
|
||||
M2LIGHT_POINT = 1,
|
||||
};
|
||||
|
||||
class CM2ModelCall;
|
||||
|
||||
class CM2ModelCall {
|
||||
|
||||
@@ -1 +1,586 @@
|
||||
#include "ShaderEffect.h"
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include "Engine/Source/ShaderEffect/ShaderEffect.h"
|
||||
#include "Engine/Source/Gx/CGxDevice/CGxDevice.h"
|
||||
#include "Engine/Source/Gx/CGxDevice/CGxShader.h"
|
||||
#include "Engine/Source/Gx/CGxMatrixStack.h"
|
||||
#include "Engine/Source/Gx/Gx.h"
|
||||
#include "Engine/Source/Model2/M2Light.h"
|
||||
#include "Engine/Source/ShaderEffect/ShadowCache.h"
|
||||
#include "Engine/Source/Tempest/C44Matrix.h"
|
||||
#include "Engine/Source/Tempest/CImVector.h"
|
||||
|
||||
// STATIC: 0x00D43008
|
||||
int32_t CShaderEffect::s_useAlphaRef;
|
||||
|
||||
// STATIC: 0x00D4300C
|
||||
float CShaderEffect::s_fogMul;
|
||||
|
||||
// STATIC: 0x00D43010
|
||||
uint32_t CShaderEffect::s_shadowValue;
|
||||
|
||||
// STATIC: 0x00D43014
|
||||
uint32_t CShaderEffect::s_usePcfFiltering;
|
||||
|
||||
// STATIC: 0x00D43018
|
||||
uint32_t CShaderEffect::s_localLightCount;
|
||||
|
||||
// STATIC: 0x00D4301C
|
||||
int32_t CShaderEffect::s_lightEnabled;
|
||||
|
||||
// STATIC: 0x00D43020
|
||||
int32_t CShaderEffect::s_enableShaders;
|
||||
|
||||
// STATIC: 0x00D43024
|
||||
CShaderEffect* CShaderEffect::s_curEffect;
|
||||
|
||||
// STATIC: 0x00D43028
|
||||
C3Vector CShaderEffect::s_sunDiffuse;
|
||||
|
||||
// STATIC: 0x00D43034
|
||||
C3Vector CShaderEffect::s_sunAmbient;
|
||||
|
||||
// STATIC: 0x00D43040
|
||||
C3Vector CShaderEffect::s_sunDir;
|
||||
|
||||
// STATIC: 0x00D4304C
|
||||
C3Vector CShaderEffect::s_sunSpec;
|
||||
|
||||
// STATIC: 0x00D43058
|
||||
C4Vector CShaderEffect::s_fogColorAlphaRef;
|
||||
|
||||
// STATIC: 0x00D43068
|
||||
C4Vector CShaderEffect::s_fogParams;
|
||||
|
||||
// STATIC: 0x00D43098
|
||||
LocalLights CShaderEffect::s_localLights;
|
||||
|
||||
// VERIFY: 9049c785 manual
|
||||
// OFFSET: 0x008728C0
|
||||
void CShaderEffect::InitFixedFuncPass(const EGxTexOp* colorOps, const EGxTexOp* alphaOps, uint32_t count) {
|
||||
this->m_fixedFuncPassCount = count;
|
||||
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
this->m_colorOps[i] = colorOps[i];
|
||||
this->m_alphaOps[i] = alphaOps[i];
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: be9bb4f7 manual
|
||||
// OFFSET: 0x00872900
|
||||
void CShaderEffect::ComputeLocalLights(LocalLights* localLights, uint32_t lightCount, CM2Light** lights, const C3Vector* origin) {
|
||||
uint32_t i = 0;
|
||||
|
||||
if (lightCount) {
|
||||
C44Matrix view;
|
||||
|
||||
if (origin) {
|
||||
GxXformView(view);
|
||||
}
|
||||
|
||||
for (; i < lightCount; i++) {
|
||||
CM2Light* light = lights[i];
|
||||
|
||||
if (light->m_type == M2LIGHT_POINT) {
|
||||
localLights->m_color[i].x = light->m_dirColor.x;
|
||||
localLights->m_color[i].y = light->m_dirColor.y;
|
||||
localLights->m_color[i].z = light->m_dirColor.z;
|
||||
localLights->m_color[i].w = 1.0f;
|
||||
|
||||
C3Vector position;
|
||||
|
||||
if (origin) {
|
||||
position = (light->m_pos - *origin) * view;
|
||||
} else {
|
||||
position = light->m_viewPos;
|
||||
}
|
||||
|
||||
localLights->m_position[i].x = position.x;
|
||||
localLights->m_position[i].y = position.y;
|
||||
localLights->m_position[i].z = position.z;
|
||||
localLights->m_position[i].w = 1.0f;
|
||||
|
||||
localLights->m_constantAttenuation[i] = light->m_constantAttenuation;
|
||||
localLights->m_linearAttenuation[i] = light->m_linearAttenuation;
|
||||
localLights->m_quadraticAttenuation[i] = light->m_quadraticAttenuation;
|
||||
} else {
|
||||
localLights->m_color[i].x = 0.0f;
|
||||
localLights->m_color[i].y = 0.0f;
|
||||
localLights->m_color[i].z = 0.0f;
|
||||
localLights->m_color[i].w = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (; i < 4; i++) {
|
||||
localLights->m_color[i].x = 0.0f;
|
||||
localLights->m_color[i].y = 0.0f;
|
||||
localLights->m_color[i].z = 0.0f;
|
||||
localLights->m_color[i].w = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: 3d4e9331 auto
|
||||
// OFFSET: 0x00872AD0
|
||||
void CShaderEffect::SetUsePcfFiltering(uint32_t usePcfFiltering) {
|
||||
if (usePcfFiltering) {
|
||||
CShaderEffect::s_usePcfFiltering = 1;
|
||||
|
||||
if (CShaderEffect::s_enableShaders) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CShaderEffect::s_usePcfFiltering = 0;
|
||||
}
|
||||
|
||||
// VERIFY: b3663650 manual
|
||||
// OFFSET: 0x00872B00
|
||||
void CShaderEffect::UpdateWorldViewMatrix() {
|
||||
if (!CShaderEffect::s_enableShaders) {
|
||||
return;
|
||||
}
|
||||
|
||||
C44Matrix view;
|
||||
C44Matrix world;
|
||||
GxXformView(view);
|
||||
|
||||
CGxMatrixStack& worldStack = g_theGxDevicePtr->m_xforms[GxXform_World];
|
||||
world = worldStack.m_mtx[worldStack.m_level];
|
||||
|
||||
C44Matrix worldView = world * view;
|
||||
worldView = worldView.Transpose();
|
||||
|
||||
GxShaderConstantsSet(GxSh_Vertex, 31, reinterpret_cast<const float*>(&worldView), 4);
|
||||
}
|
||||
|
||||
// VERIFY: 3063e016 auto
|
||||
// OFFSET: 0x00872C10
|
||||
void CShaderEffect::UpdateProjMatrix() {
|
||||
if (!CShaderEffect::s_enableShaders) {
|
||||
return;
|
||||
}
|
||||
|
||||
C44Matrix projection;
|
||||
projection = g_theGxDevicePtr->m_projNative;
|
||||
|
||||
if (g_theGxDevicePtr->DeviceApi() == GxApi_OpenGl) {
|
||||
projection.c0 = projection.c0 * -1.0f;
|
||||
projection.c1 = projection.c1 * -1.0f;
|
||||
projection.c2 = projection.c2 * -1.0f;
|
||||
projection.c3 = -1.0f * projection.c3;
|
||||
}
|
||||
|
||||
projection = projection.Transpose();
|
||||
|
||||
GxShaderConstantsSet(GxSh_Vertex, 2, reinterpret_cast<const float*>(&projection), 4);
|
||||
}
|
||||
|
||||
// VERIFY: 326b299e auto
|
||||
// OFFSET: 0x00872CE0
|
||||
void CShaderEffect::InitShaderSystem(int32_t enableShaders, int32_t usePcfFiltering) {
|
||||
CShaderEffect::s_enableShaders = enableShaders;
|
||||
CShaderEffect::SetUsePcfFiltering(usePcfFiltering);
|
||||
CShaderEffect::s_fogMul = 1.0f;
|
||||
CShaderEffect::s_useAlphaRef = g_theGxDevicePtr->Caps().unk_0130;
|
||||
}
|
||||
|
||||
// VERIFY: fd7f8aba manual
|
||||
// OFFSET: 0x00872D30
|
||||
void CShaderEffect::InitEffect(const char* vertexShader, const char* pixelShader) {
|
||||
memset(this->m_vertexShaders, 0, sizeof(this->m_vertexShaders));
|
||||
memset(this->m_pixelShaders, 0, sizeof(this->m_pixelShaders));
|
||||
this->m_fixedFuncPassCount = 0;
|
||||
|
||||
if (!CShaderEffect::s_enableShaders || !vertexShader || !pixelShader) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_theGxDevicePtr->ShaderCreate(this->m_vertexShaders, GxSh_Vertex, "Shaders\\Vertex", vertexShader, sizeof(this->m_vertexShaders) / sizeof(this->m_vertexShaders[0]));
|
||||
g_theGxDevicePtr->ShaderCreate(this->m_pixelShaders, GxSh_Pixel, "Shaders\\Pixel", pixelShader, sizeof(this->m_pixelShaders) / sizeof(this->m_pixelShaders[0]));
|
||||
}
|
||||
|
||||
// VERIFY: 9b6a2325 manual
|
||||
// OFFSET: 0x00872DE0
|
||||
uint32_t CShaderEffect::SelectShadowShader() {
|
||||
if (!(CShaderEffect::s_fogColorAlphaRef.w > 0.0f) || (g_theGxDevicePtr->Caps().unk_0130 && !CShaderEffect::s_shadowValue)) {
|
||||
return CShaderEffect::s_shadowValue + 4 * CShaderEffect::s_usePcfFiltering;
|
||||
}
|
||||
|
||||
return CShaderEffect::s_shadowValue + 4 * (CShaderEffect::s_usePcfFiltering + 2);
|
||||
}
|
||||
|
||||
// VERIFY: ae00ba32 manual
|
||||
// OFFSET: 0x00872E40
|
||||
void CShaderEffect::SetGlobalLighting(CM2Light* light) {
|
||||
CShaderEffect::s_sunDir = light->m_dir;
|
||||
CShaderEffect::s_sunSpec = light->m_specColor;
|
||||
|
||||
C44Matrix view;
|
||||
GxXformView(view);
|
||||
|
||||
C3Vector sunDir;
|
||||
sunDir.x = view.c0 * CShaderEffect::s_sunDir.z + view.b0 * CShaderEffect::s_sunDir.y + view.a0 * CShaderEffect::s_sunDir.x;
|
||||
sunDir.y = CShaderEffect::s_sunDir.z * view.c1 + CShaderEffect::s_sunDir.y * view.b1 + CShaderEffect::s_sunDir.x * view.a1;
|
||||
sunDir.z = CShaderEffect::s_sunDir.z * view.c2 + CShaderEffect::s_sunDir.y * view.b2 + CShaderEffect::s_sunDir.x * view.a2;
|
||||
CShaderEffect::s_sunDir = sunDir;
|
||||
|
||||
if (CShaderEffect::s_enableShaders) {
|
||||
C4Vector sunSpec;
|
||||
sunSpec.x = CShaderEffect::s_sunSpec.x;
|
||||
sunSpec.y = CShaderEffect::s_sunSpec.y;
|
||||
sunSpec.z = CShaderEffect::s_sunSpec.z;
|
||||
sunSpec.w = 14.0f;
|
||||
|
||||
GxShaderConstantsSet(GxSh_Vertex, 12, &CShaderEffect::s_sunDir.x, 1);
|
||||
GxShaderConstantsSet(GxSh_Vertex, 13, &sunSpec.x, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: fd36fa66 manual
|
||||
// OFFSET: 0x00872F90
|
||||
void CShaderEffect::SetCurrent() {
|
||||
CShaderEffect::s_curEffect = this;
|
||||
|
||||
if (CShaderEffect::s_enableShaders || !this->m_fixedFuncPassCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < this->m_fixedFuncPassCount; i++) {
|
||||
GxRsSet(static_cast<EGxRenderState>(GxRs_ColorOp0 + i), this->m_colorOps[i]);
|
||||
GxRsSet(static_cast<EGxRenderState>(GxRs_AlphaOp0 + i), this->m_alphaOps[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: 0344992e manual
|
||||
// OFFSET: 0x00873060
|
||||
void CShaderEffect::SetShaders(uint32_t vertexPermute, uint32_t pixelPermute) {
|
||||
int32_t useAlphaRef = 1;
|
||||
|
||||
if (CShaderEffect::s_enableShaders) {
|
||||
g_theGxDevicePtr->RsSet(GxRs_VertexShader, CShaderEffect::s_curEffect->m_vertexShaders[vertexPermute]);
|
||||
g_theGxDevicePtr->RsSet(GxRs_PixelShader, CShaderEffect::s_curEffect->m_pixelShaders[pixelPermute]);
|
||||
useAlphaRef = (pixelPermute & 8) == 0;
|
||||
}
|
||||
|
||||
if (useAlphaRef == CShaderEffect::s_useAlphaRef) {
|
||||
return;
|
||||
}
|
||||
|
||||
CShaderEffect::s_useAlphaRef = useAlphaRef;
|
||||
|
||||
if (useAlphaRef) {
|
||||
float alphaRef = CShaderEffect::s_fogColorAlphaRef.w * 255.0f;
|
||||
GxRsSet(GxRs_AlphaRef, static_cast<int32_t>(alphaRef));
|
||||
} else {
|
||||
GxShaderConstantsSet(GxSh_Pixel, 2, &CShaderEffect::s_fogColorAlphaRef.x, 1);
|
||||
GxRsSet(GxRs_AlphaRef, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: f5c47bbc auto
|
||||
// OFFSET: 0x00873160
|
||||
void CShaderEffect::SetDefaultShaders(uint32_t lightCount) {
|
||||
if (!CShaderEffect::s_enableShaders) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t shadowValue = CShaderEffect::s_shadowValue > 2 ? 2 : CShaderEffect::s_shadowValue;
|
||||
uint32_t lights = lightCount > 2 ? 2 : lightCount;
|
||||
|
||||
uint32_t vertexPermute = CShaderEffect::s_lightEnabled + 2 * (CShaderEffect::s_localLightCount + 5 * (lights + 3 * shadowValue));
|
||||
|
||||
CShaderEffect::SetShaders(vertexPermute, CShaderEffect::SelectShadowShader());
|
||||
}
|
||||
|
||||
// VERIFY: 71c6c864 manual
|
||||
// OFFSET: 0x008731C0
|
||||
void CShaderEffect::SetLightingEnabled(int32_t enabled) {
|
||||
CShaderEffect::s_lightEnabled = enabled;
|
||||
|
||||
if (!CShaderEffect::s_enableShaders) {
|
||||
GxRsSet(GxRs_Lighting, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: 26a9b9a3 manual
|
||||
// OFFSET: 0x00873210
|
||||
void CShaderEffect::SetFogParams(float start, float end, float density, const CImVector& color) {
|
||||
if (CShaderEffect::s_enableShaders) {
|
||||
CShaderEffect::s_fogColorAlphaRef.x = color.r * (1.0f / 255.0f);
|
||||
CShaderEffect::s_fogColorAlphaRef.y = color.g * (1.0f / 255.0f);
|
||||
CShaderEffect::s_fogColorAlphaRef.z = (1.0f / 255.0f) * color.b;
|
||||
|
||||
double scale = 1.0 / (end - start);
|
||||
CShaderEffect::s_fogParams.x = -(CShaderEffect::s_fogMul * scale);
|
||||
CShaderEffect::s_fogParams.y = end * scale;
|
||||
CShaderEffect::s_fogParams.z = density;
|
||||
CShaderEffect::s_fogParams.w = 0.0f;
|
||||
|
||||
if (!g_theGxDevicePtr->Caps().unk_0134) {
|
||||
GxShaderConstantsSet(GxSh_Pixel, 2, &CShaderEffect::s_fogColorAlphaRef.x, 1);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
GxRsSet(GxRs_FogStart, start);
|
||||
GxRsSet(GxRs_FogEnd, end);
|
||||
}
|
||||
|
||||
GxRsSet(GxRs_FogColor, *reinterpret_cast<const int32_t*>(&color));
|
||||
}
|
||||
|
||||
// VERIFY: af8a3952 manual
|
||||
// OFFSET: 0x00873390
|
||||
void CShaderEffect::SetFogEnabled(int32_t enabled) {
|
||||
if (enabled && g_theGxDevicePtr->MasterEnable(GxMasterEnable_Fog)) {
|
||||
if (CShaderEffect::s_enableShaders) {
|
||||
GxShaderConstantsSet(GxSh_Vertex, 30, &CShaderEffect::s_fogParams.x, 1);
|
||||
|
||||
if (!g_theGxDevicePtr->Caps().unk_0138) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
GxRsSet(GxRs_Fog, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CShaderEffect::s_enableShaders || g_theGxDevicePtr->Caps().unk_0138) {
|
||||
GxRsSet(GxRs_Fog, 0);
|
||||
} else {
|
||||
float fogParams[4] = { 0.0f, 1.0f, 1.0f, 0.0f };
|
||||
GxShaderConstantsSet(GxSh_Vertex, 30, fogParams, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: c6b67cc5 manual
|
||||
// OFFSET: 0x00873480
|
||||
void CShaderEffect::SetTexMtx_Identity(uint32_t stage) {
|
||||
if (CShaderEffect::s_enableShaders) {
|
||||
float matrix[8] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f };
|
||||
GxShaderConstantsSet(GxSh_Vertex, 2 * stage + 6, matrix, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
GxRsSet(static_cast<EGxRenderState>(GxRs_TextureShader0 + stage), 0);
|
||||
g_theGxDevicePtr->m_xforms[stage].Identity();
|
||||
GxRsSet(static_cast<EGxRenderState>(GxRs_TexGen0 + stage), 0);
|
||||
}
|
||||
|
||||
// VERIFY: ce1f9620 manual
|
||||
// OFFSET: 0x00873550
|
||||
void CShaderEffect::SetTexMtx_SphereMap(uint32_t stage) {
|
||||
if (CShaderEffect::s_enableShaders) {
|
||||
float matrix[8] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f };
|
||||
GxShaderConstantsSet(GxSh_Vertex, 2 * stage + 6, matrix, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
GxRsSet(static_cast<EGxRenderState>(GxRs_TextureShader0 + stage), 0);
|
||||
g_theGxDevicePtr->m_xforms[stage].Identity();
|
||||
GxRsSet(static_cast<EGxRenderState>(GxRs_TexGen0 + stage), 6);
|
||||
}
|
||||
|
||||
// VERIFY: d55e347c manual
|
||||
// OFFSET: 0x00873620
|
||||
void CShaderEffect::SetTexMtx(const C44Matrix& matrix, uint32_t stage) {
|
||||
if (CShaderEffect::s_enableShaders) {
|
||||
float constants[8] = { matrix.a0, matrix.b0, matrix.c0, matrix.d0, matrix.a1, matrix.b1, matrix.c1, matrix.d1 };
|
||||
GxShaderConstantsSet(GxSh_Vertex, 2 * stage + 6, constants, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
GxRsSet(static_cast<EGxRenderState>(GxRs_TextureShader0 + stage), 1);
|
||||
|
||||
CGxMatrixStack& stack = g_theGxDevicePtr->m_xforms[stage];
|
||||
stack.m_dirty = 1;
|
||||
stack.m_flags[stack.m_level] &= ~CGxMatrixStack::F_Identity;
|
||||
stack.m_mtx[stack.m_level] = matrix;
|
||||
|
||||
GxRsSet(static_cast<EGxRenderState>(GxRs_TexGen0 + stage), 0);
|
||||
}
|
||||
|
||||
// VERIFY: 571cb58b manual
|
||||
// OFFSET: 0x00873730
|
||||
void CShaderEffect::SetTexMtx_TexGen(EGxTexGen texGen, const C44Matrix& matrix, uint32_t stage) {
|
||||
if (CShaderEffect::s_enableShaders) {
|
||||
C44Matrix view;
|
||||
GxXformView(view);
|
||||
|
||||
float swap = view.a1;
|
||||
view.a1 = view.b0;
|
||||
view.b0 = swap;
|
||||
swap = view.a2;
|
||||
view.a2 = view.c0;
|
||||
view.c0 = swap;
|
||||
swap = view.b2;
|
||||
view.b2 = view.c1;
|
||||
view.c1 = swap;
|
||||
view.d0 = view.d0 * -1.0f;
|
||||
view.d1 = view.d1 * -1.0f;
|
||||
view.d2 = -1.0f * view.d2;
|
||||
|
||||
C44Matrix texMatrix = view * matrix;
|
||||
float constants[8] = { texMatrix.a0, texMatrix.b0, texMatrix.c0, texMatrix.d0, texMatrix.a1, texMatrix.b1, texMatrix.c1, texMatrix.d1 };
|
||||
GxShaderConstantsSet(GxSh_Vertex, 2 * stage + 6, constants, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
GxRsSet(static_cast<EGxRenderState>(GxRs_TextureShader0 + stage), 1);
|
||||
|
||||
CGxMatrixStack& stack = g_theGxDevicePtr->m_xforms[stage];
|
||||
stack.m_dirty = 1;
|
||||
stack.m_flags[stack.m_level] &= ~CGxMatrixStack::F_Identity;
|
||||
stack.m_mtx[stack.m_level] = matrix;
|
||||
|
||||
GxRsSet(static_cast<EGxRenderState>(GxRs_TexGen0 + stage), 2);
|
||||
}
|
||||
|
||||
// VERIFY: f365063d manual
|
||||
// OFFSET: 0x00873900
|
||||
void CShaderEffect::SetDiffuse(const C4Vector& color) {
|
||||
if (CShaderEffect::s_enableShaders) {
|
||||
GxShaderConstantsSet(GxSh_Vertex, 28, &color.x, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
float r = color.x < 0.0f ? 0.0f : (color.x >= 1.0f ? 1.0f : color.x);
|
||||
float g = color.y < 0.0f ? 0.0f : (color.y >= 1.0f ? 1.0f : color.y);
|
||||
float b = color.z < 0.0f ? 0.0f : (color.z >= 1.0f ? 1.0f : color.z);
|
||||
float a = color.w < 0.0f ? 0.0f : (color.w >= 1.0f ? 1.0f : color.w);
|
||||
|
||||
CImVector diffuse;
|
||||
diffuse.r = static_cast<uint8_t>(r * 255.0f);
|
||||
diffuse.g = static_cast<uint8_t>(g * 255.0f);
|
||||
diffuse.b = static_cast<uint8_t>(b * 255.0f);
|
||||
diffuse.a = static_cast<uint8_t>(a * 255.0f);
|
||||
|
||||
GxRsSet(GxRs_MatDiffuse, *reinterpret_cast<int32_t*>(&diffuse));
|
||||
}
|
||||
|
||||
// VERIFY: d0cdacd9 manual
|
||||
// OFFSET: 0x00873A50
|
||||
void CShaderEffect::SetEmissive(const C4Vector& color) {
|
||||
if (CShaderEffect::s_enableShaders) {
|
||||
GxShaderConstantsSet(GxSh_Vertex, 29, &color.x, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
float r = color.x < 0.0f ? 0.0f : (color.x >= 1.0f ? 1.0f : color.x);
|
||||
float g = color.y < 0.0f ? 0.0f : (color.y >= 1.0f ? 1.0f : color.y);
|
||||
float b = color.z < 0.0f ? 0.0f : (color.z >= 1.0f ? 1.0f : color.z);
|
||||
float a = color.w < 0.0f ? 0.0f : (color.w >= 1.0f ? 1.0f : color.w);
|
||||
|
||||
CImVector emissive;
|
||||
emissive.r = static_cast<uint8_t>(r * 255.0f);
|
||||
emissive.g = static_cast<uint8_t>(g * 255.0f);
|
||||
emissive.b = static_cast<uint8_t>(b * 255.0f);
|
||||
emissive.a = static_cast<uint8_t>(a * 255.0f);
|
||||
|
||||
GxRsSet(GxRs_MatEmissive, *reinterpret_cast<int32_t*>(&emissive));
|
||||
}
|
||||
|
||||
// VERIFY: 7e25358b manual
|
||||
// OFFSET: 0x00873BA0
|
||||
void CShaderEffect::SetAlphaRef(float alphaRef) {
|
||||
CShaderEffect::s_fogColorAlphaRef.w = alphaRef;
|
||||
|
||||
if (!CShaderEffect::s_useAlphaRef) {
|
||||
GxShaderConstantsSet(GxSh_Pixel, 2, &CShaderEffect::s_fogColorAlphaRef.x, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
float value = alphaRef * 255.0f;
|
||||
GxRsSet(GxRs_AlphaRef, static_cast<int32_t>(value));
|
||||
}
|
||||
|
||||
// VERIFY: a90cae3f manual
|
||||
// OFFSET: 0x00873C20
|
||||
CShaderEffect::~CShaderEffect() {
|
||||
if (!CShaderEffect::s_enableShaders) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < sizeof(this->m_vertexShaders) / sizeof(this->m_vertexShaders[0]); i++) {
|
||||
if (this->m_vertexShaders[i]) {
|
||||
g_theGxDevicePtr->ShaderDestroy(this->m_vertexShaders[i]);
|
||||
}
|
||||
|
||||
this->m_vertexShaders[i] = nullptr;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < sizeof(this->m_pixelShaders) / sizeof(this->m_pixelShaders[0]); i++) {
|
||||
if (this->m_pixelShaders[i]) {
|
||||
g_theGxDevicePtr->ShaderDestroy(this->m_pixelShaders[i]);
|
||||
}
|
||||
|
||||
this->m_pixelShaders[i] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: 17775013 manual
|
||||
// OFFSET: 0x00873CA0
|
||||
void CShaderEffect::SetLocalLighting(CM2Lighting* lighting, int32_t enabled, const C3Vector* origin) {
|
||||
CShaderEffect::s_lightEnabled = enabled;
|
||||
|
||||
if (!CShaderEffect::s_enableShaders) {
|
||||
GxRsSet(GxRs_Lighting, enabled);
|
||||
}
|
||||
|
||||
CShaderEffect::s_localLightCount = lighting ? lighting->m_lightCount : 0;
|
||||
|
||||
if (!CShaderEffect::s_enableShaders) {
|
||||
if (enabled) {
|
||||
lighting->SetupGxLights(origin);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
CShaderEffect::s_sunDir = lighting->m_sunDir;
|
||||
|
||||
if (CShaderEffect::s_sunDir.x != 0.0f || CShaderEffect::s_sunDir.y != 0.0f || CShaderEffect::s_sunDir.z != 0.0f) {
|
||||
float scale = 1.0 / sqrt(CShaderEffect::s_sunDir.z * CShaderEffect::s_sunDir.z + CShaderEffect::s_sunDir.y * CShaderEffect::s_sunDir.y + CShaderEffect::s_sunDir.x * CShaderEffect::s_sunDir.x);
|
||||
CShaderEffect::s_sunDir.x = CShaderEffect::s_sunDir.x * scale;
|
||||
CShaderEffect::s_sunDir.y = CShaderEffect::s_sunDir.y * scale;
|
||||
CShaderEffect::s_sunDir.z = scale * CShaderEffect::s_sunDir.z;
|
||||
}
|
||||
|
||||
CShaderEffect::s_sunAmbient = lighting->m_sunAmbient;
|
||||
|
||||
float r = lighting->m_sunDiffuse.x;
|
||||
float g = lighting->m_sunDiffuse.y;
|
||||
float b = lighting->m_sunDiffuse.z;
|
||||
CShaderEffect::s_sunDiffuse.x = r >= 1.0f ? 1.0f : r;
|
||||
CShaderEffect::s_sunDiffuse.y = g >= 1.0f ? 1.0f : g;
|
||||
CShaderEffect::s_sunDiffuse.z = b < 1.0f ? b : 1.0f;
|
||||
|
||||
GxShaderConstantsSet(GxSh_Vertex, 10, &CShaderEffect::s_sunDiffuse.x, 1);
|
||||
GxShaderConstantsSet(GxSh_Vertex, 11, &CShaderEffect::s_sunAmbient.x, 1);
|
||||
GxShaderConstantsSet(GxSh_Vertex, 12, &CShaderEffect::s_sunDir.x, 1);
|
||||
|
||||
if (CShaderEffect::s_localLightCount) {
|
||||
CShaderEffect::ComputeLocalLights(&CShaderEffect::s_localLights, CShaderEffect::s_localLightCount, lighting->m_lights, origin);
|
||||
GxShaderConstantsSet(GxSh_Vertex, 17, reinterpret_cast<const float*>(&CShaderEffect::s_localLights), sizeof(LocalLights) / sizeof(C4Vector));
|
||||
}
|
||||
|
||||
CShadowCache::SetShadowMapGenericInterior(lighting->m_flags & 8);
|
||||
}
|
||||
|
||||
// VERIFY: fd00dfa0 manual
|
||||
// OFFSET: 0x00873EE0
|
||||
void CShaderEffect::SetAlphaRefDefault() {
|
||||
float alphaRef = CGxDevice::s_alphaRef[g_theGxDevicePtr->m_appRenderStates[GxRs_BlendingMode].m_value.m_data.i[0]] * (1.0f / 255.0f);
|
||||
CShaderEffect::SetAlphaRef(alphaRef);
|
||||
}
|
||||
|
||||
// VERIFY: 47270730 auto
|
||||
// OFFSET: 0x00873F30
|
||||
CShaderEffect::CShaderEffect() {
|
||||
}
|
||||
|
||||
@@ -3,22 +3,77 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "Engine/Source/Gx/Types.h"
|
||||
#include "Engine/Source/ShaderEffect/Types.h"
|
||||
#include "Engine/Source/Storm/H/stpl.h"
|
||||
#include "Engine/Source/Tempest/C3Vector.h"
|
||||
#include "Engine/Source/Tempest/C4Vector.h"
|
||||
|
||||
class C44Matrix;
|
||||
class CGxShader;
|
||||
class CShaderEffect;
|
||||
struct HASHKEY_STRI;
|
||||
class CImVector;
|
||||
class CM2Light;
|
||||
class CM2Lighting;
|
||||
|
||||
class CShaderEffect {
|
||||
struct LocalLights {
|
||||
/* 0000 */ C4Vector m_color[4];
|
||||
/* 0040 */ C4Vector m_position[4];
|
||||
/* 0080 */ float m_constantAttenuation[4];
|
||||
/* 0090 */ float m_linearAttenuation[4];
|
||||
/* 00A0 */ float m_quadraticAttenuation[4];
|
||||
};
|
||||
|
||||
class CShaderEffect : public TSHashObject<CShaderEffect, HASHKEY_STRI> {
|
||||
public:
|
||||
/* 0000 */ TSHashObject<CShaderEffect, HASHKEY_STRI> m_hashObj;
|
||||
/* 0018 */ uint32_t m_fixedFuncOpCount;
|
||||
/* 001C */ uint32_t m_colorOps;
|
||||
/* 0020 */ uint32_t unk_0020;
|
||||
/* 0024 */ uint32_t m_alphaOps;
|
||||
/* 0028 */ uint32_t m_vertexShaders;
|
||||
/* 002C */ CGxShader* m_vertexShaders2 [90];
|
||||
/* 0194 */ CGxShader* m_pixelShaders [16];
|
||||
static CShaderEffect* s_curEffect;
|
||||
static int32_t s_enableShaders;
|
||||
static C4Vector s_fogColorAlphaRef;
|
||||
static float s_fogMul;
|
||||
static C4Vector s_fogParams;
|
||||
static int32_t s_lightEnabled;
|
||||
static uint32_t s_localLightCount;
|
||||
static LocalLights s_localLights;
|
||||
static uint32_t s_shadowValue;
|
||||
static C3Vector s_sunAmbient;
|
||||
static C3Vector s_sunDiffuse;
|
||||
static C3Vector s_sunDir;
|
||||
static C3Vector s_sunSpec;
|
||||
static int32_t s_useAlphaRef;
|
||||
static uint32_t s_usePcfFiltering;
|
||||
|
||||
static void ComputeLocalLights(LocalLights* localLights, uint32_t lightCount, CM2Light** lights, const C3Vector* origin);
|
||||
static void InitShaderSystem(int32_t enableShaders, int32_t usePcfFiltering);
|
||||
static uint32_t SelectShadowShader();
|
||||
static void SetAlphaRef(float alphaRef);
|
||||
static void SetAlphaRefDefault();
|
||||
static void SetDefaultShaders(uint32_t lightCount);
|
||||
static void SetDiffuse(const C4Vector& color);
|
||||
static void SetEmissive(const C4Vector& color);
|
||||
static void SetFogEnabled(int32_t enabled);
|
||||
static void SetFogParams(float start, float end, float density, const CImVector& color);
|
||||
static void SetGlobalLighting(CM2Light* light);
|
||||
static void SetLightingEnabled(int32_t enabled);
|
||||
static void SetLocalLighting(CM2Lighting* lighting, int32_t enabled, const C3Vector* origin);
|
||||
static void SetShaders(uint32_t vertexPermute, uint32_t pixelPermute);
|
||||
static void SetTexMtx(const C44Matrix& matrix, uint32_t stage);
|
||||
static void SetTexMtx_Identity(uint32_t stage);
|
||||
static void SetTexMtx_SphereMap(uint32_t stage);
|
||||
static void SetTexMtx_TexGen(EGxTexGen texGen, const C44Matrix& matrix, uint32_t stage);
|
||||
static void SetUsePcfFiltering(uint32_t usePcfFiltering);
|
||||
static void UpdateProjMatrix();
|
||||
static void UpdateWorldViewMatrix();
|
||||
|
||||
/* 0018 */ uint32_t m_fixedFuncPassCount;
|
||||
/* 001C */ EGxTexOp m_colorOps[2];
|
||||
/* 0024 */ EGxTexOp m_alphaOps[2];
|
||||
/* 002C */ CGxShader* m_vertexShaders[90];
|
||||
/* 0194 */ CGxShader* m_pixelShaders[16];
|
||||
|
||||
CShaderEffect();
|
||||
~CShaderEffect();
|
||||
void InitEffect(const char* vertexShader, const char* pixelShader);
|
||||
void InitFixedFuncPass(const EGxTexOp* colorOps, const EGxTexOp* alphaOps, uint32_t count);
|
||||
void SetCurrent();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1 +1,69 @@
|
||||
#include "ShaderEffectManager.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include "Engine/Source/ShaderEffect/ShaderEffectManager.h"
|
||||
#include "Engine/Source/BlizzardCore/SFile2-Core.h"
|
||||
#include "Engine/Source/Storm/H/storm.h"
|
||||
|
||||
// STATIC: 0x00D43408
|
||||
TSHashTable<CShaderEffect, HASHKEY_STRI> CShaderEffectManager::m_ShaderList;
|
||||
|
||||
// VERIFY: 554f80ac manual
|
||||
// OFFSET: 0x008764D0
|
||||
void CShaderEffectManager::DestroyAllEffects() {
|
||||
CShaderEffect* effect = CShaderEffectManager::m_ShaderList.m_fulllist.Head();
|
||||
|
||||
while (effect) {
|
||||
effect = CShaderEffectManager::m_ShaderList.DeleteNode(effect);
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: e6522edb auto
|
||||
// OFFSET: 0x00876530
|
||||
CShaderEffect* CShaderEffectManager::GetEffect(const char* name) {
|
||||
return CShaderEffectManager::m_ShaderList.Ptr(name);
|
||||
}
|
||||
|
||||
// VERIFY: 82eb3c99 manual
|
||||
// OFFSET: 0x00876BE0
|
||||
CShaderEffect* CShaderEffectManager::CreateEffect(const char* name) {
|
||||
CShaderEffectManager::m_ShaderList.Ptr(name);
|
||||
|
||||
return CShaderEffectManager::m_ShaderList.New(name, 0, 0);
|
||||
}
|
||||
|
||||
// VERIFY: 156a1818 manual
|
||||
// OFFSET: 0x00876CA0
|
||||
void CShaderEffectManager::ParseEffectCallback(const CShaderEffectParser::ParsedEffect& effect, void* param) {
|
||||
CShaderEffect* shaderEffect = CShaderEffectManager::m_ShaderList.New(effect.m_name, 0, 0);
|
||||
|
||||
shaderEffect->InitEffect(effect.m_shaderPasses[0].m_vertexShader, effect.m_shaderPasses[0].m_pixelShader);
|
||||
|
||||
for (uint32_t i = 0; i < effect.m_fixedFuncPassCount; i++) {
|
||||
const CShaderEffectParser::ParsedEffect::FixedFuncPass& pass = effect.m_fixedFuncPasses[i];
|
||||
shaderEffect->InitFixedFuncPass(pass.m_colorOps, pass.m_alphaOps, pass.m_pass);
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: c6a3a3f5 manual
|
||||
// OFFSET: 0x00876D90
|
||||
void CShaderEffectManager::AddEffectFile(const char* fileName) {
|
||||
char path[256];
|
||||
sprintf(path, "Shaders\\Effects\\%s", fileName);
|
||||
|
||||
SFileImpl* file;
|
||||
SFileOpenFile(path, &file);
|
||||
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t size = SFileGetFileSize(file, nullptr);
|
||||
char* data = static_cast<char*>(SMemAlloc(size + 1, __FILE__, __LINE__, 0));
|
||||
SFileReadFile(file, data, size, nullptr, nullptr, 0);
|
||||
SFileCloseFile(file);
|
||||
|
||||
CShaderEffectParser::ParseEffectFile(data, size, CShaderEffectManager::ParseEffectCallback, nullptr);
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,21 @@
|
||||
#ifndef ENGINE_SOURCE_SHADEREFFECT_SHADEREFFECTMANAGER_H
|
||||
#define ENGINE_SOURCE_SHADEREFFECT_SHADEREFFECTMANAGER_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "Engine/Source/ShaderEffect/ShaderEffect.h"
|
||||
#include "Engine/Source/ShaderEffect/ShaderEffectParser.h"
|
||||
#include "Engine/Source/Storm/H/stpl.h"
|
||||
|
||||
class CShaderEffectManager {
|
||||
public:
|
||||
static TSHashTable<CShaderEffect, HASHKEY_STRI> m_ShaderList;
|
||||
|
||||
static void AddEffectFile(const char* fileName);
|
||||
static CShaderEffect* CreateEffect(const char* name);
|
||||
static void DestroyAllEffects();
|
||||
static CShaderEffect* GetEffect(const char* name);
|
||||
static void ParseEffectCallback(const CShaderEffectParser::ParsedEffect& effect, void* param);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1 +1,236 @@
|
||||
#include "ShaderEffectParser.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include "Engine/Source/ShaderEffect/ShaderEffectParser.h"
|
||||
#include "Engine/Source/Storm/H/storm.h"
|
||||
|
||||
// STATIC: 0x00A4D678
|
||||
const EGxTexOp CShaderEffectParser::s_gxTexOpValues[GxTexOps_Last] = {
|
||||
GxTexOp_Mod,
|
||||
GxTexOp_Mod2x,
|
||||
GxTexOp_Add,
|
||||
GxTexOp_PassThru,
|
||||
GxTexOp_Decal,
|
||||
GxTexOp_Fade,
|
||||
};
|
||||
|
||||
// STATIC: 0x00B1D5C8
|
||||
const char* CShaderEffectParser::s_gxTexOpNames[GxTexOps_Last] = {
|
||||
"Mod",
|
||||
"Mod2x",
|
||||
"Add",
|
||||
"PassThru",
|
||||
"Decal",
|
||||
"Fade",
|
||||
};
|
||||
|
||||
// VERIFY: 64b6e307 auto
|
||||
// OFFSET: 0x00876F10
|
||||
static int32_t FindScope(const char* data, uint32_t start, uint32_t end, uint32_t* open, uint32_t* close) {
|
||||
int32_t depth = 0;
|
||||
|
||||
for (uint32_t i = start; i < end; i++) {
|
||||
if (data[i] == '{') {
|
||||
if (!depth) {
|
||||
*open = i;
|
||||
}
|
||||
|
||||
depth++;
|
||||
} else if (data[i] == '}' && !--depth) {
|
||||
*close = i;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// VERIFY: 6bc79b07 auto
|
||||
// OFFSET: 0x00876F70
|
||||
static EGxTexOp LookupTexOp(const char* name) {
|
||||
for (uint32_t i = 0; i < GxTexOps_Last; i++) {
|
||||
if (!SStrCmpI(name, CShaderEffectParser::s_gxTexOpNames[i], STORM_MAX_STR)) {
|
||||
return CShaderEffectParser::s_gxTexOpValues[i];
|
||||
}
|
||||
}
|
||||
|
||||
return GxTexOp_Mod;
|
||||
}
|
||||
|
||||
// VERIFY: 361a6237 manual
|
||||
// OFFSET: 0x00876E30
|
||||
int32_t CShaderEffectParser::ExtractFuncKeyword(const char* text, const char* keyword, char (*args)[64], uint32_t& argCount, uint32_t& pos) {
|
||||
size_t length = strlen(keyword);
|
||||
|
||||
if (strncmp(text, keyword, length) || text[length] != '(') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (text[length + 1] == ')') {
|
||||
argCount = 0;
|
||||
pos += length + 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
argCount = 1;
|
||||
memset(args[0], 0, sizeof(args[0]));
|
||||
|
||||
uint32_t i = length + 1;
|
||||
uint32_t j = 0;
|
||||
char c = text[i];
|
||||
|
||||
while (c != ')') {
|
||||
if (c == ',') {
|
||||
argCount++;
|
||||
memset(args[argCount - 1], 0, sizeof(args[0]));
|
||||
j = 0;
|
||||
i++;
|
||||
} else {
|
||||
args[argCount - 1][j++] = c;
|
||||
}
|
||||
|
||||
c = text[i + 1];
|
||||
i++;
|
||||
}
|
||||
|
||||
pos += i + 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// VERIFY: 43a0acdb manual
|
||||
// OFFSET: 0x00876FB0
|
||||
void CShaderEffectParser::ParseFixedFunc(char* data, uint32_t size, uint32_t& pos, char (*args)[64], uint32_t argCount, ParsedEffect* effect) {
|
||||
uint32_t open;
|
||||
uint32_t close;
|
||||
|
||||
if (!FindScope(data, pos, size, &open, &close)) {
|
||||
return;
|
||||
}
|
||||
|
||||
pos = open + 1;
|
||||
|
||||
while (pos < close) {
|
||||
if (CShaderEffectParser::ExtractFuncKeyword(data + pos, "Pass", args, argCount, pos)) {
|
||||
ParsedEffect::FixedFuncPass* pass = &effect->m_fixedFuncPasses[effect->m_fixedFuncPassCount];
|
||||
|
||||
char* end;
|
||||
pass->m_pass = strtol(args[0], &end, 10);
|
||||
|
||||
uint32_t passOpen;
|
||||
uint32_t passClose;
|
||||
FindScope(data, pos, size, &passOpen, &passClose);
|
||||
|
||||
pass->m_colorOps[0] = GxTexOp_Mod;
|
||||
pass->m_colorOps[1] = GxTexOp_Mod;
|
||||
pass->m_colorOps[2] = GxTexOp_Mod;
|
||||
pass->m_alphaOps[0] = GxTexOp_Mod;
|
||||
pass->m_alphaOps[1] = GxTexOp_Mod;
|
||||
pass->m_alphaOps[2] = GxTexOp_Mod;
|
||||
|
||||
while (pos < passClose) {
|
||||
if (CShaderEffectParser::ExtractFuncKeyword(data + pos, "ColorOp0", args, argCount, pos)) {
|
||||
pass->m_colorOps[0] = LookupTexOp(args[0]);
|
||||
} else if (CShaderEffectParser::ExtractFuncKeyword(data + pos, "ColorOp1", args, argCount, pos)) {
|
||||
pass->m_colorOps[1] = LookupTexOp(args[0]);
|
||||
} else if (CShaderEffectParser::ExtractFuncKeyword(data + pos, "AlphaOp0", args, argCount, pos)) {
|
||||
pass->m_alphaOps[0] = LookupTexOp(args[0]);
|
||||
} else if (CShaderEffectParser::ExtractFuncKeyword(data + pos, "AlphaOp1", args, argCount, pos)) {
|
||||
pass->m_alphaOps[1] = LookupTexOp(args[0]);
|
||||
}
|
||||
|
||||
pos++;
|
||||
}
|
||||
|
||||
effect->m_fixedFuncPassCount++;
|
||||
pos = passClose + 1;
|
||||
}
|
||||
|
||||
pos++;
|
||||
}
|
||||
|
||||
pos = close + 1;
|
||||
}
|
||||
|
||||
// VERIFY: 6fc19477 manual
|
||||
// OFFSET: 0x00877150
|
||||
void CShaderEffectParser::ParseShader(char* data, uint32_t size, uint32_t& pos, char (*args)[64], uint32_t argCount, ParsedEffect* effect) {
|
||||
uint32_t open;
|
||||
uint32_t close;
|
||||
|
||||
if (!FindScope(data, pos, size, &open, &close)) {
|
||||
return;
|
||||
}
|
||||
|
||||
pos = open + 1;
|
||||
|
||||
while (pos < close) {
|
||||
if (CShaderEffectParser::ExtractFuncKeyword(data + pos, "Pass", args, argCount, pos)) {
|
||||
ParsedEffect::ShaderPass* pass = &effect->m_shaderPasses[effect->m_shaderPassCount];
|
||||
|
||||
uint32_t passOpen;
|
||||
uint32_t passClose;
|
||||
FindScope(data, pos, size, &passOpen, &passClose);
|
||||
|
||||
while (pos < passClose) {
|
||||
if (CShaderEffectParser::ExtractFuncKeyword(data + pos, "VertexShader", args, argCount, pos)) {
|
||||
strcpy(pass->m_vertexShader, args[0]);
|
||||
} else if (CShaderEffectParser::ExtractFuncKeyword(data + pos, "PixelShader", args, argCount, pos)) {
|
||||
strcpy(pass->m_pixelShader, args[0]);
|
||||
}
|
||||
|
||||
pos++;
|
||||
}
|
||||
|
||||
effect->m_shaderPassCount++;
|
||||
pos = passClose + 1;
|
||||
}
|
||||
|
||||
pos++;
|
||||
}
|
||||
|
||||
pos = close + 1;
|
||||
}
|
||||
|
||||
// VERIFY: 353721c3 auto
|
||||
// OFFSET: 0x00877290
|
||||
void CShaderEffectParser::ParseEffect(char* data, uint32_t size, uint32_t& pos, char (*args)[64], uint32_t argCount, ParsedEffect* effect) {
|
||||
SStrCopy(effect->m_name, args[0], sizeof(effect->m_name));
|
||||
effect->m_fixedFuncPassCount = 0;
|
||||
effect->m_shaderPassCount = 0;
|
||||
|
||||
uint32_t open;
|
||||
uint32_t close;
|
||||
|
||||
if (!FindScope(data, pos, size, &open, &close)) {
|
||||
return;
|
||||
}
|
||||
|
||||
pos = open + 1;
|
||||
|
||||
while (pos < close) {
|
||||
if (CShaderEffectParser::ExtractFuncKeyword(data + pos, "FixedFunc", args, argCount, pos)) {
|
||||
CShaderEffectParser::ParseFixedFunc(data, size, pos, args, argCount, effect);
|
||||
} else if (CShaderEffectParser::ExtractFuncKeyword(data + pos, "Shader", args, argCount, pos)) {
|
||||
CShaderEffectParser::ParseShader(data, size, pos, args, argCount, effect);
|
||||
}
|
||||
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: e3f85c73 auto
|
||||
// OFFSET: 0x00877360
|
||||
void CShaderEffectParser::ParseEffectFile(char* data, uint32_t size, void (*callback)(const ParsedEffect&, void*), void* param) {
|
||||
char args[16][64];
|
||||
ParsedEffect effect;
|
||||
uint32_t argCount;
|
||||
|
||||
for (uint32_t pos = 0; pos < size; pos++) {
|
||||
if (CShaderEffectParser::ExtractFuncKeyword(data + pos, "Effect", args, argCount, pos)) {
|
||||
CShaderEffectParser::ParseEffect(data, size, pos, args, argCount, &effect);
|
||||
callback(effect, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,39 @@
|
||||
#ifndef ENGINE_SOURCE_SHADEREFFECT_SHADEREFFECTPARSER_H
|
||||
#define ENGINE_SOURCE_SHADEREFFECT_SHADEREFFECTPARSER_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "Engine/Source/ShaderEffect/Types.h"
|
||||
|
||||
class CShaderEffectParser {
|
||||
public:
|
||||
struct ParsedEffect {
|
||||
struct FixedFuncPass {
|
||||
/* 0000 */ uint32_t m_pass;
|
||||
/* 0004 */ EGxTexOp m_colorOps[3];
|
||||
/* 0010 */ EGxTexOp m_alphaOps[3];
|
||||
};
|
||||
|
||||
struct ShaderPass {
|
||||
/* 0000 */ char m_vertexShader[64];
|
||||
/* 0040 */ char m_pixelShader[64];
|
||||
};
|
||||
|
||||
/* 0000 */ char m_name[64];
|
||||
/* 0040 */ uint32_t m_fixedFuncPassCount;
|
||||
/* 0044 */ FixedFuncPass m_fixedFuncPasses[1];
|
||||
/* 0060 */ uint32_t m_shaderPassCount;
|
||||
/* 0064 */ ShaderPass m_shaderPasses[1];
|
||||
};
|
||||
|
||||
static const char* s_gxTexOpNames[GxTexOps_Last];
|
||||
static const EGxTexOp s_gxTexOpValues[GxTexOps_Last];
|
||||
|
||||
static int32_t ExtractFuncKeyword(const char* text, const char* keyword, char (*args)[64], uint32_t& argCount, uint32_t& pos);
|
||||
static void ParseEffect(char* data, uint32_t size, uint32_t& pos, char (*args)[64], uint32_t argCount, ParsedEffect* effect);
|
||||
static void ParseEffectFile(char* data, uint32_t size, void (*callback)(const ParsedEffect&, void*), void* param);
|
||||
static void ParseFixedFunc(char* data, uint32_t size, uint32_t& pos, char (*args)[64], uint32_t argCount, ParsedEffect* effect);
|
||||
static void ParseShader(char* data, uint32_t size, uint32_t& pos, char (*args)[64], uint32_t argCount, ParsedEffect* effect);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,114 @@
|
||||
#ifndef ENGINE_SOURCE_SHADEREFFECT_SHADOWCACHE_H
|
||||
#define ENGINE_SOURCE_SHADEREFFECT_SHADOWCACHE_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "Engine/Source/ShaderEffect/Types.h"
|
||||
#include "Engine/Source/Tempest/C3Vector.h"
|
||||
#include "Engine/Source/Tempest/C44Matrix.h"
|
||||
#include "Engine/Source/Tempest/C4Vector.h"
|
||||
#include "Engine/Source/Tempest/CAaBox.h"
|
||||
#include "_Triage/CWFrustum.h"
|
||||
|
||||
class CFrustum;
|
||||
class CGxTex;
|
||||
class CTexture;
|
||||
struct CShadowCacheQueryData;
|
||||
|
||||
typedef void (*ShadowMatrixCallback)(C3Vector& center, float radius, C44Matrix& matrix, C3Vector& direction, int32_t band);
|
||||
typedef void (*ShadowFrustumCallback)(CFrustum& frustum, C44Matrix& matrix, const C3Vector& direction, CShadowCacheQueryData& data, int32_t band);
|
||||
typedef int32_t (*ShadowQueryCallback)(CShadowCacheQueryData& data, uint32_t frame);
|
||||
typedef int32_t (*ShadowRenderCallback)(CShadowCacheQueryData& data, int32_t band, CGxTex* target, CGxTex* colorTarget, C3Vector& direction);
|
||||
|
||||
struct CShadowBand {
|
||||
/* 0000 */ CTexture* m_textures[2];
|
||||
/* 0008 */ float m_radius;
|
||||
/* 000C */ float m_updateDistance;
|
||||
/* 0010 */ C3Vector m_lastPos;
|
||||
/* 001C */ C3Vector m_pos;
|
||||
/* 0028 */ C3Vector m_dir;
|
||||
/* 0034 */ uint32_t m_updateCount;
|
||||
/* 0038 */ uint32_t m_current;
|
||||
|
||||
CShadowBand();
|
||||
};
|
||||
|
||||
struct CShadowCacheQueryData {
|
||||
/* 0000 */ int32_t m_queryFlags[3];
|
||||
/* 000C */ int32_t m_active[3];
|
||||
/* 0018 */ int32_t m_useCullFrustum[3];
|
||||
/* 0024 */ CAaBox m_extents[3];
|
||||
/* 006C */ CWFrustum m_frustums[3];
|
||||
/* 0348 */ CWFrustum m_cullFrustums[3];
|
||||
/* 0624 */ CWFrustum unk_0624[3];
|
||||
/* 0900 */ float m_cullRects[3][4];
|
||||
/* 0930 */ C3Vector m_pos[3];
|
||||
/* 0954 */ uint8_t m_textureIndex[3];
|
||||
/* 0958 */ float m_radius[3];
|
||||
/* 0964 */ float m_bounds[3][4];
|
||||
/* 0994 */ float m_texBounds[3][4];
|
||||
/* 09C4 */ C44Matrix m_matrices[3];
|
||||
/* 0A84 */ int32_t m_lastBand;
|
||||
/* 0A88 */ int32_t m_useFrustum;
|
||||
|
||||
CShadowCacheQueryData();
|
||||
};
|
||||
|
||||
class CShadowCache {
|
||||
public:
|
||||
static const float s_bandRadius[3];
|
||||
static const float s_bandUpdateDistance[3];
|
||||
static C4Vector s_cutoffPlane;
|
||||
static C4Vector s_cutoffPlaneDefault;
|
||||
static float s_debugAspect;
|
||||
static int32_t s_debugLevel;
|
||||
static CShadowBand s_extDynShadow;
|
||||
static float s_extDynShadowCullRect[4];
|
||||
static CShadowBand s_extShadowBands[3];
|
||||
static uint8_t s_frameCounter;
|
||||
static ShadowFrustumCallback s_frustumCallback;
|
||||
static CTexture* s_intDynShadow;
|
||||
static ShadowMatrixCallback s_matrixCallback;
|
||||
static int32_t s_needsRebuild;
|
||||
static C4Vector s_pcfOffsets[8];
|
||||
static ShadowQueryCallback s_queryCallback;
|
||||
static int32_t s_recreateTextures;
|
||||
static ShadowRenderCallback s_renderCallback;
|
||||
static EShadowMode s_shadowMode;
|
||||
static C4Vector s_shadowMatrices[12];
|
||||
static float s_shadowScale;
|
||||
static uint32_t s_shadowSize;
|
||||
static const char* s_shadowModeDescs[NUM_SHADOW_MODES + 1];
|
||||
static const uint32_t s_shadowValues[NUM_SHADOW_MODES + 1];
|
||||
static C3Vector s_sunDir;
|
||||
static C4Vector s_sunDirViewSpace;
|
||||
static float s_textureSize[2];
|
||||
|
||||
static void ClearBandTextures();
|
||||
static void Destroy();
|
||||
static void GatherBands(CShadowCacheQueryData& data, const C3Vector& pos, CWFrustum& frustum, int32_t useCullFrustum);
|
||||
static EShadowMode GetShadowMode();
|
||||
static const char* GetShadowModeDesc(uint32_t mode);
|
||||
static uint32_t GetShadowValue();
|
||||
static void Init();
|
||||
static void InitPcfOffsets();
|
||||
static void __fastcall NotifyTexturesRecreate();
|
||||
static void PostUpdate();
|
||||
static void PreUpdate(const C3Vector& sunDir);
|
||||
static void RenderBands(CShadowCacheQueryData& data);
|
||||
static void SetDebugParams(float aspect, int32_t level);
|
||||
static void SetFrustumCallback(ShadowFrustumCallback callback);
|
||||
static void SetMatrixCallback(ShadowMatrixCallback callback);
|
||||
static void SetQueryCallback(ShadowQueryCallback callback);
|
||||
static void SetRenderCallback(ShadowRenderCallback callback);
|
||||
static void SetShadowMapDetailDoodad();
|
||||
static void SetShadowMapGenericGlobal();
|
||||
static void SetShadowMapGenericInterior(int32_t interior);
|
||||
static void SetShadowMapTerrain();
|
||||
static int32_t SetShadowMode(EShadowMode mode);
|
||||
static void SetShadowScale(float scale);
|
||||
static int32_t Update(const C3Vector& pos, int32_t useCullFrustum);
|
||||
static int32_t ValidateShadowMode(EShadowMode mode);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef ENGINE_SOURCE_SHADEREFFECT_TYPES_H
|
||||
#define ENGINE_SOURCE_SHADEREFFECT_TYPES_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
enum EGxTexOp {
|
||||
GxTexOp_Mod = 0,
|
||||
GxTexOp_Mod2x = 1,
|
||||
GxTexOp_Add = 2,
|
||||
GxTexOp_PassThru = 3,
|
||||
GxTexOp_Decal = 4,
|
||||
GxTexOp_Fade = 5,
|
||||
GxTexOps_Last = 6,
|
||||
};
|
||||
|
||||
enum EShadowMode {
|
||||
SHADOW_LOWEST = 0,
|
||||
SHADOW_LOW = 1,
|
||||
SHADOW_MEDIUM = 2,
|
||||
SHADOW_MEDIUM_HIGH = 3,
|
||||
SHADOW_HIGH = 4,
|
||||
SHADOW_VERY_HIGH = 5,
|
||||
NUM_SHADOW_MODES = 6,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,27 @@
|
||||
#include "Engine/Source/Tempest/C44Matrix.h"
|
||||
#include "Engine/Source/Tempest/C4Quaternion.h"
|
||||
|
||||
// VERIFY: bcc62f69 auto
|
||||
// OFFSET: 0x0057C2A0
|
||||
void C44Matrix::Identity() {
|
||||
this->d3 = 1.0f;
|
||||
this->c2 = 1.0f;
|
||||
this->b1 = 1.0f;
|
||||
this->a0 = 1.0f;
|
||||
this->d2 = 0.0f;
|
||||
this->d1 = 0.0f;
|
||||
this->d0 = 0.0f;
|
||||
this->c3 = 0.0f;
|
||||
this->c1 = 0.0f;
|
||||
this->c0 = 0.0f;
|
||||
this->b3 = 0.0f;
|
||||
this->b2 = 0.0f;
|
||||
this->b0 = 0.0f;
|
||||
this->a3 = 0.0f;
|
||||
this->a2 = 0.0f;
|
||||
this->a1 = 0.0f;
|
||||
}
|
||||
|
||||
// VERIFY: b9812d24 manual
|
||||
// OFFSET: 0x00407F40
|
||||
C44Matrix::C44Matrix() {
|
||||
|
||||
@@ -41,6 +41,7 @@ class C44Matrix {
|
||||
C44Matrix AffineInverse() const;
|
||||
C44Matrix AffineInverse(float scale) const;
|
||||
float Determinant() const;
|
||||
void Identity();
|
||||
C44Matrix Inverse() const;
|
||||
C44Matrix Inverse(float determinant) const;
|
||||
void Rotate(const C4Quaternion& q);
|
||||
|
||||
+4
-1
@@ -14,7 +14,10 @@ class CWFrustum : public CFrustum {
|
||||
/* 00E8 */ float m_aspect;
|
||||
/* 00EC */ float m_minz;
|
||||
/* 00F0 */ float m_maxz;
|
||||
/* 00F4 */ TSLink<CWFrustum> m_sceneLink;
|
||||
|
||||
CWFrustum();
|
||||
CWFrustum& operator=(const CWFrustum& source);
|
||||
void InvertPlanes();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user