1
0
mirror of https://github.com/XLabsProject/iw3x-port.git synced 2023-08-02 15:02:11 +02:00

Fix up water, model placement, lots of stuff. Frankly too much for a single commit

This commit is contained in:
Louvenarde 2022-08-14 00:44:30 +02:00
parent d73fc074dd
commit d323c4c6bc
8 changed files with 277 additions and 126 deletions

View File

@ -13,7 +13,7 @@ namespace Components
if (!image) return;
std::string name = image->name;
if (image->texture.loadDef)
if (image->category != Game::GfxImageCategory::IMG_CATEGORY_LOAD_FROM_FILE && image->texture.loadDef)
{
if (name[0] == '*') name.erase(name.begin());

View File

@ -429,7 +429,7 @@ namespace Components
map.skies = &sky;
sky.skyImage = world->skyImage;
sky.skySamplerState = world->skySamplerState & 0xFF;
sky.skySamplerState = world->skySamplerState/* & 0xFF*/;
sky.skyStartSurfs = world->skyStartSurfs;
sky.skySurfCount = world->skySurfCount;
@ -647,10 +647,6 @@ namespace Components
map.dpvs.surfaces[i].lightmapIndex = world->dpvs.surfaces[i].lightmapIndex;
map.dpvs.surfaces[i].reflectionProbeIndex = world->dpvs.surfaces[i].reflectionProbeIndex;
map.dpvs.surfaces[i].primaryLightIndex = world->dpvs.surfaces[i].primaryLightIndex;
// Static model flags in iw3 do not correspond to static model flags in iw4
// I think they're intentionally misaligned because iw3:STATIC_MODEL_FLAG_NO_SHADOW does NOT correspond to iw4:STATIC_MODEL_FLAG_NO_CAST_SHADOW
// If you make them match you'll get fucked up shadows. So let's put everything to zero instead!
map.dpvs.surfaces[i].flags = world->dpvs.surfaces[i].flags;
map.dpvs.surfacesBounds[i].bounds.compute(world->dpvs.surfaces[i].bounds[0], world->dpvs.surfaces[i].bounds[1]); // Verified
@ -670,14 +666,78 @@ namespace Components
map.dpvs.smodelDrawInsts[i].placement.scale = world->dpvs.smodelDrawInsts[i].placement.scale;
map.dpvs.smodelDrawInsts[i].model = world->dpvs.smodelDrawInsts[i].model;
// Double cull distance so it looks nicer in iw4
map.dpvs.smodelDrawInsts[i].cullDist = static_cast<unsigned short>(world->dpvs.smodelDrawInsts[i].cullDist * 2);
map.dpvs.smodelDrawInsts[i].reflectionProbeIndex = world->dpvs.smodelDrawInsts[i].reflectionProbeIndex;
map.dpvs.smodelDrawInsts[i].primaryLightIndex = world->dpvs.smodelDrawInsts[i].primaryLightIndex;
map.dpvs.smodelDrawInsts[i].lightingHandle = world->dpvs.smodelDrawInsts[i].lightingHandle;
map.dpvs.smodelDrawInsts[i].flags = world->dpvs.smodelDrawInsts[i].flags;
// This has been moved
if (world->dpvs.smodelInsts) map.dpvs.smodelDrawInsts[i].groundLighting = world->dpvs.smodelInsts[i].groundLighting;
if (world->dpvs.smodelInsts)
{
map.dpvs.smodelDrawInsts[i].groundLighting = world->dpvs.smodelInsts[i].groundLighting;
Game::IW3::GfxColor* color = &map.dpvs.smodelDrawInsts[i].groundLighting;
//// Grass needs 0x20 otherwise it doesn't read data from the lightmap and it's full bright !
//// Gameflags to 0x3 and model flags & 0x1 are both good indicators that this is foliage
//// and that it requires ground lighting. Leaves out the tree and most other bigger stuff.
auto surfBits = map.dpvs.smodelDrawInsts[i].model->materialHandles[0]->info.surfaceTypeBits;
if (
map.dpvs.smodelDrawInsts[i].model->flags & 0b00000001 &&
(surfBits == 512 || surfBits == 128)
)
{
// Color correction to take in account the stronger sun in iw4
/*
IW3 IW4
0 0
5 4
15 13
50 42
80 66
120 95
160 122
200 147
255 179
*/
unsigned char alpha = color->array[3];
color->array[3] = static_cast<unsigned char>(
std::ceil(
std::log2(alpha / ( 255 + 150 ) + 1)
* 255
)
);
map.dpvs.smodelDrawInsts[i].flags |= 0x20;
Logger::Print("Added STATIC_MODEL_FLAG_GROUND_LIGHTING on draw instance of %s\n", map.dpvs.smodelDrawInsts[i].model->name);
}
// Note: The following is not useful, but it might be one day
// It is not useful in preventing some objects from turning black. They turn blakc because
// they are placed under the ground, which makes the game forbide them from accessing
// ground_lighting which they need. Not sure how to detect & fix that !
#if 0
// Remap everybody above 15 because very dark smodels are actually completely black in iw4
// Except the alpha! don't touch the alpha!
for (size_t j = 0; j < 3; j++)
{
constexpr auto remapMin = 15;
auto b = color->array[j];
color->array[j] = static_cast<unsigned char>(
std::floor(
remapMin + (color->array[j] / (255.f + remapMin)) * 255.f
)
);
auto a = color->array[j];
assert(b <= a); // this cannot darken anyone!
}
#endif
}
}
}
@ -735,7 +795,7 @@ namespace Components
}
// Specify that it's a custom map
map.checksum = 0x0000C0D4;
map.checksum = 0xC0D40000;
IGfxWorld::SaveConvertedWorld(&map);
}

View File

@ -114,7 +114,7 @@ namespace Components
// Save_water_t
if (water->H0)
{
auto ptr = reinterpret_cast<uint8_t*>(&water->H0);
auto ptr = reinterpret_cast<uint8_t*>(water->H0);
auto buffer = std::vector<uint8_t>(ptr, ptr + water->M * water->N * sizeof(Game::IW3::complex_s));
waterJson.AddMember("H0", RAPIDJSON_STR(strDuplicator.duplicateString(Utils::Base64::Encode(buffer))), allocator);
@ -122,7 +122,7 @@ namespace Components
if (water->wTerm)
{
auto ptr = reinterpret_cast<uint8_t*>(&water->wTerm);
auto ptr = reinterpret_cast<uint8_t*>(water->wTerm);
auto buffer = std::vector<uint8_t>(ptr, ptr + water->M * water->N * sizeof(float));
waterJson.AddMember("wTerm", RAPIDJSON_STR(strDuplicator.duplicateString(Utils::Base64::Encode(buffer))), allocator);
@ -364,10 +364,11 @@ namespace Components
mat.gameFlags.packed = material->info.gameFlags.packed;
// ???
mat.gameFlags.fields.unk8 = material->info.gameFlags.fields.unk7;
mat.gameFlags.fields.unk7 = material->info.gameFlags.fields.unk8;
// Sort key
#if USE_IW3_SORTKEYS
mat.sortKey = material->info.sortKey; // Using iw3 value directly
#else
@ -412,6 +413,21 @@ namespace Components
mat.constantCount = material->constantCount;
mat.stateBitsCount = material->stateBitsCount;
mat.stateFlags = static_cast<Game::IW4::StateFlags>(material->stateFlags); // Correspondance is identical
// If you want something a bit more sane, uncomment this:
#if 0
if (mat.sortKey == 0)
{
mat.stateFlags = static_cast<Game::IW4::StateFlags>(mat.stateFlags | Game::IW4::STATE_FLAG_AMBIENT);
Logger::Print("Added STATE_FLAG_AMBIENT on %s (sortkey is opaque-ambient)\n", mat.name);
}
#else
// Give ambient to everyone. Why not?
// While this sounds evil, it actually fixes lighting issues on grass, rocks, everything
// And does not seem to have any drawback!
mat.stateFlags = static_cast<Game::IW4::StateFlags>(mat.stateFlags | Game::IW4::STATE_FLAG_AMBIENT);
#endif
mat.cameraRegion = material->cameraRegion;
if (mat.cameraRegion == 0x3) {
@ -465,6 +481,16 @@ namespace Components
Logger::Print("Material %s was given sortkey %i from %i (does not write to depth)\n", name.data(), 29, iw3Key);
return 29; // mtl_fx_rock01
}
// Why ? How!
// mtl_bm21_undercarriage what's wrong with you!
if (techsetName.contains("2d"))
{
//"opaque" => SORTKEY_BLEND_ADDITIVE
Logger::Print("Material %s was given sortkey %i from %i (2d)\n", name.data(), 47, iw3Key);
return 47;
}
}
if (iw3Key == 9)
@ -546,7 +572,6 @@ namespace Components
if (iw3Key == 43)
{
// Default 29
if (techsetName.contains("2d"))
{
//"blend / additive" => SORTKEY_BLEND_ADDITIVE
@ -554,8 +579,17 @@ namespace Components
return 47;
}
if (techsetName.contains("effect") && name.contains("gfx"))
{
//"blend / additive" => SORTKEY_BLEND_ADDITIVE
// gfx_flare_wtr is an example of this
Logger::Print("Material %s was given sortkey %i from %i (is a gfx/effect material)\n", name.data(), 47, iw3Key);
return 47;
}
#define IW3_CAMERA_REGION_DECAL 0x1
if (material->cameraRegion = IW3_CAMERA_REGION_DECAL)
if (material->cameraRegion == IW3_CAMERA_REGION_DECAL)
{
/*
- 25 (2 matches)

View File

@ -6,6 +6,112 @@ namespace Components
{
const std::string IMaterialTechniqueSet::techsetSuffix = ".3x";
std::unordered_map <std::int32_t, std::int32_t> IMaterialTechniqueSet::iw3CodeConstMap =
{
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_POSITION, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_POSITION },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_DIFFUSE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_DIFFUSE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPECULAR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPECULAR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPOTDIR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPOTDIR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPOTFACTORS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPOTFACTORS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_NEARPLANE_ORG, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_NEARPLANE_ORG },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_NEARPLANE_DX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_NEARPLANE_DX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_NEARPLANE_DY, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_NEARPLANE_DY },
// missing
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SHADOW_PARMS, Game::IW4::ShaderCodeConstants::CONST_SRC_NONE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SHADOWMAP_POLYGON_OFFSET, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_SHADOWMAP_POLYGON_OFFSET },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_RENDER_TARGET_SIZE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_RENDER_TARGET_SIZE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_FALLOFF_PLACEMENT, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_FALLOFF_PLACEMENT },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DOF_EQUATION_VIEWMODEL_AND_FAR_BLUR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DOF_EQUATION_VIEWMODEL_AND_FAR_BLUR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DOF_EQUATION_SCENE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DOF_EQUATION_SCENE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DOF_LERP_SCALE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DOF_LERP_SCALE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DOF_LERP_BIAS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DOF_LERP_BIAS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DOF_ROW_DELTA, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DOF_ROW_DELTA },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_PARTICLE_CLOUD_COLOR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_PARTICLE_CLOUD_COLOR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_GAMETIME, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_GAMETIME },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_PIXEL_COST_FRACS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_PIXEL_COST_FRACS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_PIXEL_COST_DECODE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_PIXEL_COST_DECODE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_0, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_1, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_1 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_2, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_2 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_3, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_3 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_4, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_4 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_5, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_5 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_6, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_6 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_7, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_7 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_COLOR_MATRIX_R, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_COLOR_MATRIX_R },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_COLOR_MATRIX_G, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_COLOR_MATRIX_G },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_COLOR_MATRIX_B, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_COLOR_MATRIX_B },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SHADOWMAP_SWITCH_PARTITION, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_SHADOWMAP_SWITCH_PARTITION },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SHADOWMAP_SCALE , Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_SHADOWMAP_SCALE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_ZNEAR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_ZNEAR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SUN_POSITION, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_POSITION },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SUN_DIFFUSE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_DIFFUSE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SUN_SPECULAR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPECULAR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHTING_LOOKUP_SCALE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHTING_LOOKUP_SCALE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DEBUG_BUMPMAP, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DEBUG_BUMPMAP },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_MATERIAL_COLOR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_MATERIAL_COLOR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FOG, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FOG },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FOG_COLOR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FOG_COLOR_GAMMA }, // this is CORRECT! Do not map me to LINEAR_COLOR ! GAMMA is in fact gamma COLOR which is what IW3 has !
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_GLOW_SETUP, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_GLOW_SETUP },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_GLOW_APPLY, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_GLOW_APPLY },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_COLOR_BIAS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_COLOR_BIAS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_COLOR_TINT_BASE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_COLOR_TINT_BASE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_COLOR_TINT_DELTA, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_COLOR_TINT_DELTA },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_OUTDOOR_FEATHER_PARMS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_OUTDOOR_FEATHER_PARMS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_ENVMAP_PARMS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_ENVMAP_PARMS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SPOT_SHADOWMAP_PIXEL_ADJUST, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_SPOT_SHADOWMAP_PIXEL_ADJUST },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_CLIP_SPACE_LOOKUP_SCALE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_CLIP_SPACE_LOOKUP_SCALE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_CLIP_SPACE_LOOKUP_OFFSET, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_CLIP_SPACE_LOOKUP_OFFSET },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_PARTICLE_CLOUD_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_PARTICLE_CLOUD_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DEPTH_FROM_CLIP, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DEPTH_FROM_CLIP },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_CODE_MESH_ARG_0, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_CODE_MESH_ARG_0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_CODE_MESH_ARG_1, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_CODE_MESH_ARG_1 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_CODE_MESH_ARG_LAST, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_CODE_MESH_ARG_LAST },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_BASE_LIGHTING_COORDS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_BASE_LIGHTING_COORDS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_VIEW_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_VIEW_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_VIEW_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_VIEW_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_VIEW_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_VIEW_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SHADOW_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_SHADOW_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_SHADOW_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_SHADOW_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_SHADOW_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_SHADOW_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_SHADOW_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_SHADOW_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_WORLD_OUTDOOR_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_WORLD_OUTDOOR_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_OUTDOOR_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_OUTDOOR_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX },
// Matrix => Matrix0
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_WORLD_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_WORLD_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_WORLD_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_WORLD_VIEW_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_VIEW_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_WORLD_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_WORLD_VIEW_PROJECTION_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_VIEW_PROJECTION_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_NONE, Game::IW4::ShaderCodeConstants::CONST_SRC_NONE },
};
const std::unordered_map<Game::IW4::MaterialTechniqueType, Game::IW3::MaterialTechniqueType> IMaterialTechniqueSet::techniqueTypeTableFromIW4 = {
{ Game::IW4::TECHNIQUE_DEPTH_PREPASS, Game::IW3::TECHNIQUE_DEPTH_PREPASS},
{ Game::IW4::TECHNIQUE_BUILD_FLOAT_Z, Game::IW3::TECHNIQUE_BUILD_FLOAT_Z},
@ -68,7 +174,7 @@ namespace Components
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_MODEL_LIGHTING , Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_MODEL_LIGHTING },
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_LIGHTMAP_PRIMARY,Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_LIGHTMAP_PRIMARY },
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_LIGHTMAP_SECONDARY,Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_LIGHTMAP_SECONDARY },
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_SHADOWCOOKIE, Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_SHADOWMAP_SUN }, // incorrect!
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_SHADOWCOOKIE, Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_WHITE }, // incorrect!
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_SHADOWMAP_SUN, Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_SHADOWMAP_SUN },
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_SHADOWMAP_SPOT , Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_SHADOWMAP_SPOT },
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_FEEDBACK , Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_FEEDBACK },
@ -76,9 +182,9 @@ namespace Components
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_RESOLVED_SCENE , Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_RESOLVED_SCENE},
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_POST_EFFECT_0 , Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_POST_EFFECT_0},
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_POST_EFFECT_1 , Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_POST_EFFECT_1},
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_SKY , Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_SHADOWMAP_SUN }, // incorrect!
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_SKY , Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_BLACK }, // incorrect!
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_LIGHT_ATTENUATION , Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_LIGHT_ATTENUATION},
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_DYNAMIC_SHADOWS , Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_BLACK }, // Incorrect!
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_DYNAMIC_SHADOWS , Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_SHADOWMAP_SPOT }, // Incorrect!
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_OUTDOOR , Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_OUTDOOR },
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_FLOATZ , Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_FLOATZ },
{ Game::IW3::MaterialTextureSource::TEXTURE_SRC_CODE_PROCESSED_FLOATZ, Game::IW4::MaterialTextureSource::TEXTURE_SRC_CODE_PROCESSED_FLOATZ },
@ -107,6 +213,7 @@ namespace Components
output.AddMember("version", IW4X_TECHSET_VERSION, allocator);
output.AddMember("name", rapidjson::Value(techniqueName.data(), allocator), allocator);
// What do I know
auto shiftedFlags = tech->flags << 2;
const auto flags = std::format("{:016b}", shiftedFlags);
@ -119,6 +226,23 @@ namespace Components
Game::IW3::MaterialPass* pass = &tech->passArray[i];
rapidjson::Value jsonPass(rapidjson::kObjectType);
bool isWaterPass = false;
constexpr auto hashToLookFor = Utils::HashString("waterColor");
// Detect if this is about water!
for (int k = 0; k < pass->perPrimArgCount + pass->perObjArgCount + pass->stableArgCount; ++k)
{
Game::IW3::MaterialShaderArgument* arg = &pass->args[k];
if (arg->type == Game::MaterialShaderArgumentType::MTL_ARG_MATERIAL_PIXEL_CONST)
{
if (arg->u.nameHash == hashToLookFor)
{
isWaterPass = true;
break;
}
}
}
if (pass->vertexDecl)
{
@ -177,6 +301,14 @@ namespace Components
}
unsigned short val = (unsigned short)newIndex->second;
if (isWaterPass && val == Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_POSITION)
{
// If IsWaterTechnique => fuck up the sun position
// Because it's not correct for iw3 anyway and so unexpected
Logger::Print("Routed the pass argument %i to the wrong constant %i instead of %i on purpose because it is a water material!\n", k, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FOG_COLOR_LINEAR, val);
val = Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FOG_COLOR_LINEAR; // Anything normalized & stable will do
}
rapidjson::Value codeConst(rapidjson::kObjectType);
codeConst.AddMember("index", val, allocator);
@ -226,7 +358,6 @@ namespace Components
Game::IW4::MaterialVertexDeclaration* iw4Decl = allocator.allocate<Game::IW4::MaterialVertexDeclaration>();
// TODO: figure out how to actually name these things
iw4Decl->name = allocator.duplicateString(Utils::VA("iw4xDecl%d", numDecls++));
iw4Decl->hasOptionalSource = decl->hasOptionalSource;
iw4Decl->streamCount = decl->streamCount;
@ -370,7 +501,6 @@ namespace Components
{
rapidjson::Value value = rapidjson::Value(rapidjson::kNullType);
if (techset->techniques[i])
{
std::string techniqueName = IMaterialTechniqueSet::DumpTechnique(techset->techniques[i]);
@ -458,107 +588,4 @@ namespace Components
{
}
std::unordered_map <std::int32_t, std::int32_t> IMaterialTechniqueSet::iw3CodeConstMap =
{
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_POSITION, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_POSITION },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_DIFFUSE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_DIFFUSE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPECULAR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPECULAR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPOTDIR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPOTDIR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPOTFACTORS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPOTFACTORS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_NEARPLANE_ORG, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_NEARPLANE_ORG },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_NEARPLANE_DX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_NEARPLANE_DX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_NEARPLANE_DY, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_NEARPLANE_DY },
// missing
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SHADOW_PARMS, Game::IW4::ShaderCodeConstants::CONST_SRC_NONE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SHADOWMAP_POLYGON_OFFSET, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_SHADOWMAP_POLYGON_OFFSET },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_RENDER_TARGET_SIZE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_RENDER_TARGET_SIZE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_FALLOFF_PLACEMENT, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_FALLOFF_PLACEMENT },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DOF_EQUATION_VIEWMODEL_AND_FAR_BLUR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DOF_EQUATION_VIEWMODEL_AND_FAR_BLUR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DOF_EQUATION_SCENE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DOF_EQUATION_SCENE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DOF_LERP_SCALE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DOF_LERP_SCALE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DOF_LERP_BIAS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DOF_LERP_BIAS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DOF_ROW_DELTA, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DOF_ROW_DELTA },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_PARTICLE_CLOUD_COLOR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_PARTICLE_CLOUD_COLOR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_GAMETIME, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_GAMETIME },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_PIXEL_COST_FRACS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_PIXEL_COST_FRACS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_PIXEL_COST_DECODE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_PIXEL_COST_DECODE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_0, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_1, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_1 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_2, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_2 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_3, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_3 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_4, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_4 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_5, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_5 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_6, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_6 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_7, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FILTER_TAP_7 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_COLOR_MATRIX_R, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_COLOR_MATRIX_R },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_COLOR_MATRIX_G, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_COLOR_MATRIX_G },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_COLOR_MATRIX_B, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_COLOR_MATRIX_B },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SHADOWMAP_SWITCH_PARTITION, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_SHADOWMAP_SWITCH_PARTITION },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SHADOWMAP_SCALE , Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_SHADOWMAP_SCALE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_ZNEAR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_ZNEAR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SUN_POSITION, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_POSITION },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SUN_DIFFUSE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_DIFFUSE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SUN_SPECULAR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHT_SPECULAR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_LIGHTING_LOOKUP_SCALE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_LIGHTING_LOOKUP_SCALE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DEBUG_BUMPMAP, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DEBUG_BUMPMAP },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_MATERIAL_COLOR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_MATERIAL_COLOR },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FOG, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FOG },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_FOG_COLOR, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_FOG_COLOR_LINEAR }, // ~not necessarily a great match.
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_GLOW_SETUP, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_GLOW_SETUP },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_GLOW_APPLY, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_GLOW_APPLY },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_COLOR_BIAS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_COLOR_BIAS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_COLOR_TINT_BASE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_COLOR_TINT_BASE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_COLOR_TINT_DELTA, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_COLOR_TINT_DELTA },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_OUTDOOR_FEATHER_PARMS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_OUTDOOR_FEATHER_PARMS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_ENVMAP_PARMS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_ENVMAP_PARMS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SPOT_SHADOWMAP_PIXEL_ADJUST, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_SPOT_SHADOWMAP_PIXEL_ADJUST },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_CLIP_SPACE_LOOKUP_SCALE, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_CLIP_SPACE_LOOKUP_SCALE },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_CLIP_SPACE_LOOKUP_OFFSET, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_CLIP_SPACE_LOOKUP_OFFSET },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_PARTICLE_CLOUD_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_PARTICLE_CLOUD_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_DEPTH_FROM_CLIP, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_DEPTH_FROM_CLIP },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_CODE_MESH_ARG_0, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_CODE_MESH_ARG_0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_CODE_MESH_ARG_1, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_CODE_MESH_ARG_1 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_CODE_MESH_ARG_LAST, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_CODE_MESH_ARG_LAST },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_BASE_LIGHTING_COORDS, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_BASE_LIGHTING_COORDS },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_COUNT_FLOAT4, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_COUNT_FLOAT4 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_FIRST_CODE_MATRIX , Game::IW4::ShaderCodeConstants::CONST_SRC_FIRST_CODE_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_WORLD_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_WORLD_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_VIEW_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_VIEW_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_VIEW_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_WORLD_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_WORLD_VIEW_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_VIEW_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_VIEW_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_VIEW_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_VIEW_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_PROJECTION_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_WORLD_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_WORLD_VIEW_PROJECTION_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_VIEW_PROJECTION_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX0 },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_SHADOW_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_SHADOW_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_SHADOW_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_SHADOW_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_SHADOW_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_SHADOW_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_SHADOW_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_SHADOW_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_WORLD_OUTDOOR_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_WORLD_OUTDOOR_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_OUTDOOR_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_WORLD_OUTDOOR_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX, Game::IW4::ShaderCodeConstants::CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_TOTAL_COUNT, Game::IW4::ShaderCodeConstants::CONST_SRC_TOTAL_COUNT },
{ Game::IW3::ShaderCodeConstants::CONST_SRC_NONE, Game::IW4::ShaderCodeConstants::CONST_SRC_NONE },
};
}

View File

@ -21,7 +21,7 @@ namespace Components
private:
static Game::IW4::MaterialTechniqueSet* Dump(Game::IW3::MaterialTechniqueSet* techset);
static std::string DumpTechnique(Game::IW3::MaterialTechnique* tech);
static std::string DumpTechnique(Game::IW3::MaterialTechnique* tech);
static std::string DumpDecl(Game::IW3::MaterialVertexDeclaration* decl);
static std::string DumpVS(Game::IW3::MaterialVertexShader* vs);
static std::string DumpPS(Game::IW3::MaterialPixelShader* ps);

View File

@ -72,6 +72,20 @@ namespace Game
TS_WATER_MAP = 0xB,
};
enum GfxImageCategory : char
{
IMG_CATEGORY_UNKNOWN = 0x0,
IMG_CATEGORY_AUTO_GENERATED = 0x1,
IMG_CATEGORY_LIGHTMAP = 0x2,
IMG_CATEGORY_LOAD_FROM_FILE = 0x3,
IMG_CATEGORY_RAW = 0x4,
IMG_CATEGORY_FIRST_UNMANAGED = 0x5,
IMG_CATEGORY_WATER = 0x5,
IMG_CATEGORY_RENDERTARGET = 0x6,
IMG_CATEGORY_TEMP = 0x7,
};
enum MaterialShaderArgumentType : unsigned __int16
{
MTL_ARG_MATERIAL_VERTEX_CONST = 0x0,
@ -119,7 +133,7 @@ namespace Game
{
unsigned char unk1 : 1;
unsigned char addShadowToPrimaryLight : 1;
unsigned char unk3 : 1;
unsigned char isFoliageRequiresGroundLighting : 1;
unsigned char unk4 : 1;
unsigned char unk5 : 1;
unsigned char unk6 : 1;
@ -315,7 +329,7 @@ namespace Game
unsigned __int16 width;
unsigned __int16 height;
unsigned __int16 depth;
char category;
GfxImageCategory category;
bool delayLoadPixels;
const char *name;
};
@ -1011,7 +1025,7 @@ namespace Game
union GfxColor
{
unsigned int packed;
char array[4];
unsigned char array[4];
};
union PackedTexCoords

View File

@ -4,6 +4,7 @@ namespace Utils
{
namespace Image
{
#pragma warning(push, 0)
std::vector<int> BoxesForGauss(int sigma, int n) // standard deviation, number of boxes
{
float wIdeal = sqrt((12 * sigma * sigma / n) + 2); // Ideal averaging filter w
@ -157,4 +158,5 @@ namespace Utils
BoxBlur_4(data, newData, width, height, channelCount, (bxs[2] - 1) / 2);
}
}
#pragma warning(pop)
}

View File

@ -21,6 +21,20 @@ namespace Utils
bool FileExists(std::string file);
void WriteFile(std::string file, std::string data);
std::string ReadFile(std::string file);
constexpr unsigned int HashString(const char* string)
{
const char* v2 = string;
char v3 = *string;
unsigned int result = 0;
for (; *v2; v3 = *v2)
{
++v2;
result = 33 * result ^ (v3 | 0x20);
}
return result;
}
template<class T>
rapidjson::Value MakeJsonArray(T* arr, size_t length, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>& allocator);