Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Vanguard Game Support #237

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UmodelTool/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ BEGIN_CLASS_TABLE
#if UNREAL3
REGISTER_MATERIAL_CLASSES_U3 //!! needed for Bioshock 2 too
#endif
#if VANGUARD
REGISTER_MATERIAL_CLASSES_VANGUARD
#endif

#if DECLARE_VIEWER_PROPS
REGISTER_SKELMESH_VCLASSES
Expand Down
146 changes: 146 additions & 0 deletions Unreal/UnRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,15 @@ void UShader::GetParams(CMaterialParams &Params) const
NormalMap->GetParams(Params2);
Params.Normal = Params2.Diffuse;
}
#endif
#if VANGUARD
if (Normal)
{
//Some models look funky with this on, others look good. Disabling for now
//CMaterialParams Params2;
//Normal->GetParams(Params2);
//Params.Normal = Params2.Diffuse;
}
#endif
if (SpecularityMask)
{
Expand All @@ -1583,6 +1592,143 @@ bool UShader::IsTranslucent() const
return (OutputBlending != OB_Normal);
}

#if VANGUARD
void UNormalBitmapMaterial::GetParams(CMaterialParams &params) const
{
if (normalTex) params.Diffuse = normalTex;
else if (BumpMap) params.Diffuse = BumpMap;
}

void UNormalBitmapMaterial::PostLoad()
{
if (BumpMap)
{
UBits = BumpMap->UBits;
VBits = BumpMap->VBits;
USize = BumpMap->USize;
VSize = BumpMap->VSize;
UClamp = BumpMap->UClamp;
VClamp = BumpMap->VClamp;
UClampMode = BumpMap->UClampMode;
VClampMode = BumpMap->VClampMode;

if (BumpMap->Format == TEXF_DXT3) return;

assert(BumpMap->Format == TEXF_P8);

normalTex = new UTexture;
normalTex->UBits = UBits;
normalTex->VBits = VBits;
normalTex->USize = USize;
normalTex->VSize = VSize;
normalTex->UClamp = UClamp;
normalTex->VClamp = VClamp;
normalTex->UClampMode = UClampMode;
normalTex->VClampMode = VClampMode;

normalTex->Mips.SetNum(1);
//Norm mip
FMipmap &nMip = normalTex->Mips[0];
nMip.UBits = UBits;
nMip.VBits = VBits;
nMip.USize = USize;
nMip.VSize = VSize;

//Bump Mip
const FMipmap &bMip = BumpMap->Mips[0];

/* BGRA8 CODE - In client but image doesn't look like other normal maps ive seen
{
float scale = BumpScale / USize * 0.0039215689;

nMip.DataArray.AddUninitialized(USize * VSize * 4);

const byte *rawU = &bMip.DataArray[0];
const byte *rawV = &bMip.DataArray[USize];

//Decode into BGRA8 format
byte *dest = &nMip.DataArray[0];
for (int v = 0; v < VSize; v++)
{
const byte *rawU2 = rawU + 1;
for (int u = 0; u < USize; u++)
{
float fu1 = *rawU++ * scale;
float fv = *rawV++ * scale;
float fu2 = fu1 - *rawU2++ * scale;
fu1 -= fv;

float t = (fu1 * fu1) + (fu2 * fu2) + 1.0f;
float r, g, b;
if (t >= 0.00000001)
{
b = 1.0f / sqrtf(t);
g = fu1 * r;
r = fu2 * r;
}
else r = 0.0f, g = 0.0f, b = 0.0f;

b = (r + 1.0f) * 127.5f;
g = (g + 1.0f) * 127.5f;
r = (r + 1.0f) * 127.5f;

uint32 bb = (byte)b, gb = (byte)g, rb = (byte)r;
uint32 pack = bb | (gb << 8) | (rb << 16);
*reinterpret_cast<uint32*>(dest) = pack;
dest += 4;

//Safety check to stay in-bounds
if (u == USize - 2) rawU2 -= USize;
}
}

normalTex->Format = TEXF_RGBA8;
Format = TEXF_RGBA8;
}
else */
{
float scale = BumpScale / 0.00390625f;

nMip.DataArray.AddUninitialized(USize * VSize * 2);
byte *dest = &nMip.DataArray[0];

const byte *rawU = &bMip.DataArray[0];
const byte *rawV = &bMip.DataArray[USize];
for (int v = 0; v < VSize; v++)
{
const byte *rawU2 = rawU + 1;
for (int u = 0; u < USize; u++)
{
float fu1 = *rawU++ * scale;
float fv = *rawV++ * scale;
float fu2 = fu1 - *rawU2++ * scale;
fu1 -= fv;

float t = (fu1 * fu1) + (fu2 * fu2) + 1.0f;

float tv, tu;
if (t >= 0.00000001)
{
float n = 1.0f / sqrt(t);
tv = n * fu2;
tu = n * fu1;
}
else tv = tu = 0.0f;

*dest++ = appRound(tv * 128.0f);
*dest++ = appRound(tu * 128.0f);

//Safety check to stay in-bounds
if (u == USize - 2) rawU2 -= USize;
}
}

normalTex->Format = TEXF_V8U8;
Format = TEXF_V8U8;
}
}
}
#endif // VANGUARD


#if BIOSHOCK
Expand Down
73 changes: 73 additions & 0 deletions Unreal/UnrealMaterial/UnMaterial2.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ UE2 MATERIALS TREE:
ShadowBitmapMaterial
- Texture
Cubemap
#if VANGUARD
NormalBitmapMaterial
SpecularBitmapMaterial
#endif
- ConstantMaterial
- ConstantColor
FadeColor
Expand Down Expand Up @@ -296,6 +300,7 @@ enum ETextureFormat
TEXF_CxV8U8,
TEXF_DXT5N, // Note: in Bioshock this value has name 3DC, but really DXT5N is used
TEXF_3DC, // BC5 compression
TEXF_V8U8
};

_ENUM(ETextureFormat)
Expand All @@ -316,6 +321,7 @@ _ENUM(ETextureFormat)
_E(TEXF_CxV8U8),
_E(TEXF_DXT5N),
_E(TEXF_3DC),
_E(TEXF_V8U8)
};

enum ETexClampMode
Expand Down Expand Up @@ -363,6 +369,63 @@ class UBitmapMaterial : public URenderedMaterial // abstract
#endif // RENDERING
};

#if VANGUARD
class UNormalBitmapMaterial : public UBitmapMaterial
{
DECLARE_CLASS(UNormalBitmapMaterial, UBitmapMaterial);
public:

UNormalBitmapMaterial() : BumpScale(8.0f) {}

~UNormalBitmapMaterial()
{
if (normalTex) delete normalTex;
}
class UTexture* BumpMap;
float BumpScale;
//Looks wrong but correct casing
float BumpCulldistance;

BEGIN_PROP_TABLE
PROP_OBJ(BumpMap)
PROP_FLOAT(BumpScale)
PROP_FLOAT(BumpCulldistance)
END_PROP_TABLE

//CUSTOM
UTexture* normalTex;
void PostLoad() override;
void GetParams(CMaterialParams &Params) const override;
};

//No functionality yet
class USpecularBitmapMaterial : public UBitmapMaterial
{
DECLARE_CLASS(USpecularBitmapMaterial, UBitmapMaterial);
public:
class UMaterial* ExponentMap;
float DiffuseStrength, SpecularStrength, EnvStrength;
FColor SpecularColor;
float SpecularPower;
float DiffuseClarity, SpecularClarity, EnvClarity;
float DiffuseBumpiness, SpecularBumpiness, EnvBumpiness;

BEGIN_PROP_TABLE
PROP_OBJ(ExponentMap)
PROP_FLOAT(DiffuseStrength)
PROP_FLOAT(SpecularStrength)
PROP_FLOAT(EnvStrength)
PROP_COLOR(SpecularColor)
PROP_FLOAT(SpecularPower)
PROP_FLOAT(DiffuseClarity)
PROP_FLOAT(SpecularClarity)
PROP_FLOAT(EnvClarity)
PROP_FLOAT(DiffuseBumpiness)
PROP_FLOAT(SpecularBumpiness)
PROP_FLOAT(EnvBumpiness)
END_PROP_TABLE
};
#endif //VANGUARD

class UPalette : public UObject
{
Expand Down Expand Up @@ -597,6 +660,9 @@ class UShader : public URenderedMaterial
UMaterial *Diffuse;
#if BIOSHOCK
UMaterial *NormalMap;
#endif
#if VANGUARD
UMaterial *Normal;
#endif
UMaterial *Opacity;
UMaterial *Specular;
Expand Down Expand Up @@ -658,6 +724,9 @@ class UShader : public URenderedMaterial
PROP_BOOL(AlphaTest)
PROP_BYTE(AlphaRef)
#endif // LINEAGE2
#if VANGUARD
PROP_OBJ(Normal)
#endif//VANGUARD
#if BIOSHOCK
PROP_STRUC(Opacity_Bio, FMaskMaterial)
PROP_STRUC(HeightMap, FMaskMaterial)
Expand Down Expand Up @@ -1356,6 +1425,10 @@ class USCX_basic_material : public URenderedMaterial
REGISTER_CLASS(FMaskMaterial) \
REGISTER_CLASS(UFacingShader)

#define REGISTER_MATERIAL_CLASSES_VANGUARD \
REGISTER_CLASS(UNormalBitmapMaterial) \
REGISTER_CLASS(USpecularBitmapMaterial)

#define REGISTER_MATERIAL_CLASSES_SCELL \
REGISTER_CLASS(UUnreal3Material) \
REGISTER_CLASS(USCX_basic_material)
Expand Down
3 changes: 3 additions & 0 deletions Unreal/UnrealMaterial/UnTexture2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ ETexturePixelFormat UTexture::GetTexturePixelFormat() const
case TEXF_3DC:
intFormat = TPF_BC5;
break;
case TEXF_V8U8:
intFormat = TPF_V8U8;
break;
default:
appNotify("Unknown UE2 texture format: %s (%d)", EnumToName(Format), Format);
}
Expand Down
Loading