This repository has been archived by the owner on Jan 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
CCarFXRenderer.cpp
118 lines (103 loc) · 3.31 KB
/
CCarFXRenderer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "StdInc.h"
bool CCarFXRenderer::Initialise()
{
return CCustomCarEnvMapPipeline::CreatePipe();
}
void CCarFXRenderer::Shutdown()
{
for(size_t i = 0; i < ELEMS_COUNT(ms_aDirtTextures); i++)
{
RwTextureDestroy(ms_aDirtTextures[i]);
}
CCustomCarEnvMapPipeline::DestroyPipe();
}
bool CCarFXRenderer::RegisterPlugins()
{
return CCustomCarEnvMapPipeline::RegisterPlugin();
}
void CCarFXRenderer::PreRenderUpdate()
{
return CCustomCarEnvMapPipeline::PreRenderUpdate();
}
bool CCarFXRenderer::IsCCPCPipelineAttached(RpAtomic* atomic)
{
return GetPipelineID(atomic) == 0x53F2009A;
}
static RpAtomic* CustomCarPipeAtomicSetupCB(RpAtomic* atomic, void*)
{
CCarFXRenderer::CustomCarPipeAtomicSetup(atomic);
return atomic;
}
void CCarFXRenderer::CustomCarPipeAtomicSetup(RpAtomic* atomic)
{
CCustomCarEnvMapPipeline::CustomPipeAtomicSetup(atomic);
}
void CCarFXRenderer::CustomCarPipeClumpSetup(RpClump* clump)
{
RpClumpForAllAtomics(clump, CustomCarPipeAtomicSetupCB, NULL);
}
void CCarFXRenderer::SetFxEnvMapLightMult(float mult)
{
CCustomCarEnvMapPipeline::m_EnvMapLightingMult = mult;
}
float CCarFXRenderer::GetFxEnvMapLightMult()
{
return CCustomCarEnvMapPipeline::m_EnvMapLightingMult;
}
void CCarFXRenderer::RemapDirt(CVehicleModelInfo* info, uint32_t id)
{
for(size_t i = 0; i < ELEMS_COUNT(info->DirtMaterialArray); i++)
{
RpMaterial* dirtMaterial = info->DirtMaterialArray[i];
if(dirtMaterial)
{
RpMaterialSetTexture(dirtMaterial, ms_aDirtTextures[id]);
}
}
}
void CCarFXRenderer::SetCustomFXAtomicRenderPipelinesVMICB(RpAtomic* atomic, void*)
{
CCarFXRenderer::CustomCarPipeAtomicSetup(atomic);
}
RpAtomic* CCarFXRenderer::AtomicRemapDirtCB(RpAtomic* atomic, void* data)
{
RpGeometryForAllMaterials(atomic->geometry, MaterialRemapDirtCB, data);
}
RpMaterial* CCarFXRenderer::MaterialRemapDirtCB(RpMaterial* material, void* data)
{
if(material->texture)
{
if(!strcmp(material->texture->name, "vehiclegrunge256"))
{
RpMaterialSetTexture(material, ms_aDirtTextures[*(int*)data]);
}
}
return material;
}
void CCarFXRenderer::InitialiseDirtTexture()
{
int16_t id = CTxdStore::FindTxdSlot("vehicle");
CTxdStore::PushCurrentTxd();
CTxdStore::SetCurrentTxd(id);
RwTexture* texture = RwTextureRead("vehiclegrunge256", 0);
RwRaster* raster = texture->raster;
texture->filterAddressing = 2;
for (size_t texId = 0; texId < ELEMS_COUNT(ms_aDirtTextures); texId++)
{
ms_aDirtTextures[texId] = CClothesBuilder::CopyTexture(texture);
RwTextureSetName(ms_aDirtTextures[texId], "vehiclegrunge256");
RwRaster* dirtRaster = ms_aDirtTextures[texId]->raster;
RwUInt8** dirtArray = (RwUInt8**)RwRasterLock(dirtRaster, 0, 3);
for (size_t i = 0; i != raster->height; i++)
{
for (size_t j = 0; j != raster->width; j++)
{
dirtArray[i][j] = ((texId * 255) / 16) + ((texId * dirtArray[i][j]) / 16);
dirtArray[i][j+1] = ((texId * 255) / 16) + ((texId * dirtArray[i][j+1]) / 16);
dirtArray[i][j+2] = ((texId * 255) / 16) + ((texId * dirtArray[i][j+2]) / 16);
}
}
RwRasterUnlock(dirtRaster);
}
CTxdStore::PopCurrentTxd();
}