1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 10:23:56 +00:00
openmw/components/nif/property.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

439 lines
12 KiB
C++
Raw Normal View History

/*
OpenMW - The completely unofficial reimplementation of Morrowind
Copyright (C) 2008-2010 Nicolay Korslund
Email: < korslund@gmail.com >
WWW: https://openmw.org/
This file (property.h) is part of the OpenMW package.
OpenMW is distributed as free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License
version 3, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
version 3 along with this program. If not, see
https://www.gnu.org/licenses/ .
*/
#ifndef OPENMW_COMPONENTS_NIF_PROPERTY_HPP
#define OPENMW_COMPONENTS_NIF_PROPERTY_HPP
#include "base.hpp"
namespace Nif
{
2020-12-15 22:06:05 +00:00
struct Property : public Named
{
};
struct NiTexturingProperty : public Property
{
unsigned short flags{ 0u };
2022-09-22 18:26:05 +00:00
// A sub-texture
2020-12-15 22:06:05 +00:00
struct Texture
2022-09-22 18:26:05 +00:00
{
/* Clamp mode
0 - clampS clampT
1 - clampS wrapT
2 - wrapS clampT
3 - wrapS wrapT
2022-09-22 18:26:05 +00:00
*/
bool inUse;
NiSourceTexturePtr texture;
2022-09-22 18:26:05 +00:00
2019-10-05 12:02:42 +00:00
unsigned int clamp, uvSet;
2022-09-22 18:26:05 +00:00
void read(NIFStream* nif);
void post(NIFFile* nif);
2022-09-22 18:26:05 +00:00
2022-06-21 21:43:16 +00:00
bool wrapT() const { return clamp & 1; }
bool wrapS() const { return (clamp >> 1) & 1; }
2022-09-22 18:26:05 +00:00
};
/* Apply mode:
0 - replace
1 - decal
2 - modulate
3 - hilight // These two are for PS2 only?
4 - hilight2
*/
2021-01-09 10:21:57 +00:00
unsigned int apply{ 0 };
2022-09-22 18:26:05 +00:00
/*
* The textures in this list are as follows:
2022-09-22 18:26:05 +00:00
*
* 0 - Base texture
* 1 - Dark texture
* 2 - Detail texture
2019-10-05 12:02:42 +00:00
* 3 - Gloss texture
* 4 - Glow texture
* 5 - Bump map texture
* 6 - Decal texture
2022-09-22 18:26:05 +00:00
*/
2013-04-03 15:16:34 +00:00
enum TextureType
2022-09-22 18:26:05 +00:00
{
2013-04-03 15:16:34 +00:00
BaseTexture = 0,
DarkTexture = 1,
DetailTexture = 2,
GlossTexture = 3,
GlowTexture = 4,
BumpTexture = 5,
DecalTexture = 6,
2022-09-22 18:26:05 +00:00
};
2019-10-05 12:02:42 +00:00
std::vector<Texture> textures;
std::vector<Texture> shaderTextures;
2022-09-22 18:26:05 +00:00
2020-03-02 01:03:36 +00:00
osg::Vec2f envMapLumaBias;
osg::Vec4f bumpMapMatrix;
2022-09-22 18:26:05 +00:00
void read(NIFStream* nif) override;
void post(NIFFile* nif) override;
2022-09-22 18:26:05 +00:00
};
struct NiFogProperty : public Property
2022-09-22 18:26:05 +00:00
{
2019-10-05 12:02:42 +00:00
unsigned short mFlags;
float mFogDepth;
osg::Vec3f mColour;
2022-06-21 21:43:16 +00:00
void read(NIFStream* nif) override;
};
// These contain no other data than the 'flags' field
struct NiShadeProperty : public Property
2013-04-03 15:16:34 +00:00
{
unsigned short flags{ 0u };
void read(NIFStream* nif) override
2022-09-22 18:26:05 +00:00
{
Property::read(nif);
2013-04-03 15:16:34 +00:00
if (nif->getBethVersion() <= NIFFile::BethVersion::BETHVER_FO3)
flags = nif->getUShort();
2022-09-22 18:26:05 +00:00
}
2013-04-03 15:16:34 +00:00
};
enum class BSShaderType : unsigned int
2022-09-22 18:26:05 +00:00
{
ShaderType_TallGrass = 0,
ShaderType_Default = 1,
ShaderType_Sky = 10,
ShaderType_Skin = 14,
ShaderType_Water = 17,
2020-12-15 22:06:05 +00:00
ShaderType_Lighting30 = 29,
ShaderType_Tile = 32,
ShaderType_NoLighting = 33
2015-02-17 16:08:55 +00:00
};
struct BSShaderProperty : public NiShadeProperty
2022-09-22 18:26:05 +00:00
{
unsigned int type{ 0u }, flags1{ 0u }, flags2{ 0u };
float envMapIntensity{ 0.f };
void read(NIFStream* nif) override;
};
struct BSShaderLightingProperty : public BSShaderProperty
{
unsigned int clamp{ 0u };
void read(NIFStream* nif) override;
2022-06-21 21:43:16 +00:00
bool wrapT() const { return clamp & 1; }
bool wrapS() const { return (clamp >> 1) & 1; }
2022-09-22 18:26:05 +00:00
};
struct BSShaderPPLightingProperty : public BSShaderLightingProperty
{
BSShaderTextureSetPtr textureSet;
struct RefractionSettings
{
float strength{ 0.f };
int period{ 0 };
2022-09-22 18:26:05 +00:00
};
2020-12-16 21:46:09 +00:00
struct ParallaxSettings
2022-09-22 18:26:05 +00:00
{
2020-12-16 21:46:09 +00:00
float passes{ 0.f };
float scale{ 0.f };
2022-09-22 18:26:05 +00:00
};
RefractionSettings refraction;
2020-12-16 21:46:09 +00:00
ParallaxSettings parallax;
2022-09-22 18:26:05 +00:00
void read(NIFStream* nif) override;
2020-12-16 21:46:09 +00:00
void post(NIFFile* nif) override;
};
struct BSShaderNoLightingProperty : public BSShaderLightingProperty
{
std::string filename;
osg::Vec4f falloffParams;
2022-06-21 21:43:16 +00:00
void read(NIFStream* nif) override;
};
2020-12-16 21:46:09 +00:00
enum class BSLightingShaderType : unsigned int
{
ShaderType_Default = 0,
ShaderType_EnvMap = 1,
ShaderType_Glow = 2,
ShaderType_Parallax = 3,
2020-12-16 21:46:09 +00:00
ShaderType_FaceTint = 4,
ShaderType_SkinTint = 5,
ShaderType_HairTint = 6,
ShaderType_ParallaxOcc = 7,
ShaderType_MultitexLand = 8,
ShaderType_LODLand = 9,
ShaderType_Snow = 10,
ShaderType_MultiLayerParallax = 11,
ShaderType_TreeAnim = 12,
2020-12-16 21:46:09 +00:00
ShaderType_LODObjects = 13,
ShaderType_SparkleSnow = 14,
ShaderType_LODObjectsHD = 15,
ShaderType_EyeEnvmap = 16,
ShaderType_Cloud = 17,
ShaderType_LODNoise = 18,
ShaderType_MultitexLandLODBlend = 19,
ShaderType_Dismemberment = 20
2020-12-16 21:46:09 +00:00
};
2022-09-22 18:26:05 +00:00
2020-12-16 21:46:09 +00:00
struct BSLightingShaderProperty : public BSShaderProperty
{
BSShaderTextureSetPtr mTextureSet;
unsigned int mClamp{ 0u };
float mAlpha;
2020-12-16 21:46:09 +00:00
float mGlossiness;
osg::Vec3f mEmissive, mSpecular;
2020-12-16 21:46:09 +00:00
float mEmissiveMult, mSpecStrength;
2022-09-22 18:26:05 +00:00
void read(NIFStream* nif) override;
2020-12-16 21:46:09 +00:00
void post(NIFFile* nif) override;
};
struct NiDitherProperty : public Property
{
unsigned short flags;
void read(NIFStream* nif) override
2022-09-22 18:26:05 +00:00
{
Property::read(nif);
flags = nif->getUShort();
}
};
struct NiZBufferProperty : public Property
{
unsigned short flags;
unsigned int testFunction;
void read(NIFStream* nif) override
2022-09-22 18:26:05 +00:00
{
Property::read(nif);
flags = nif->getUShort();
testFunction = (flags >> 2) & 0x7;
if (nif->getVersion() >= NIFStream::generateVersion(4, 1, 0, 12)
&& nif->getVersion() <= NIFFile::NIFVersion::VER_OB)
testFunction = nif->getUInt();
}
2022-06-21 21:43:16 +00:00
bool depthTest() const { return flags & 1; }
bool depthWrite() const { return (flags >> 1) & 1; }
};
struct NiSpecularProperty : public Property
{
unsigned short flags;
void read(NIFStream* nif) override
2022-09-22 18:26:05 +00:00
{
Property::read(nif);
flags = nif->getUShort();
}
2022-06-21 21:43:16 +00:00
bool isEnabled() const { return flags & 1; }
};
struct NiWireframeProperty : public Property
{
unsigned short flags;
void read(NIFStream* nif) override
2022-09-22 18:26:05 +00:00
{
Property::read(nif);
flags = nif->getUShort();
2022-06-21 21:43:16 +00:00
}
bool isEnabled() const { return flags & 1; }
2022-09-22 18:26:05 +00:00
};
// The rest are all struct-based
template <typename T>
struct StructPropT : Property
{
T data;
unsigned short flags;
void read(NIFStream* nif) override
2022-09-22 18:26:05 +00:00
{
Property::read(nif);
flags = nif->getUShort();
data.read(nif);
2022-09-22 18:26:05 +00:00
}
2020-12-16 21:46:09 +00:00
};
2012-07-10 07:27:13 +00:00
struct S_MaterialProperty
2022-09-22 18:26:05 +00:00
{
// The vector components are R,G,B
osg::Vec3f ambient{ 1.f, 1.f, 1.f }, diffuse{ 1.f, 1.f, 1.f };
osg::Vec3f specular, emissive;
float glossiness{ 0.f }, alpha{ 0.f }, emissiveMult{ 1.f };
void read(NIFStream* nif);
2022-09-22 18:26:05 +00:00
};
2020-12-15 22:06:05 +00:00
struct S_VertexColorProperty
2022-09-22 18:26:05 +00:00
{
/* Vertex mode:
0 - source ignore
1 - source emmisive
2 - source amb diff
2022-09-22 18:26:05 +00:00
Lighting mode
0 - lighting emmisive
1 - lighting emmisive ambient/diffuse
*/
int vertmode, lightmode;
2012-07-10 07:27:13 +00:00
void read(NIFStream* nif);
};
struct S_AlphaProperty
{
/*
2022-06-21 21:43:16 +00:00
NiAlphaProperty blend modes (glBlendFunc):
0000 GL_ONE
0001 GL_ZERO
0010 GL_SRC_COLOR
0011 GL_ONE_MINUS_SRC_COLOR
0100 GL_DST_COLOR
0101 GL_ONE_MINUS_DST_COLOR
0110 GL_SRC_ALPHA
0111 GL_ONE_MINUS_SRC_ALPHA
1000 GL_DST_ALPHA
1001 GL_ONE_MINUS_DST_ALPHA
1010 GL_SRC_ALPHA_SATURATE
2022-09-22 18:26:05 +00:00
test modes (glAlphaFunc):
000 GL_ALWAYS
001 GL_LESS
010 GL_EQUAL
011 GL_LEQUAL
100 GL_GREATER
101 GL_NOTEQUAL
110 GL_GEQUAL
111 GL_NEVER
2022-09-22 18:26:05 +00:00
Taken from:
http://niftools.sourceforge.net/doc/nif/NiAlphaProperty.html
*/
// Tested against when certain flags are set (see above.)
unsigned char threshold;
2022-09-22 18:26:05 +00:00
void read(NIFStream* nif);
2022-09-22 18:26:05 +00:00
};
/*
Docs taken from:
http://niftools.sourceforge.net/doc/nif/NiStencilProperty.html
*/
struct S_StencilProperty
2022-09-22 18:26:05 +00:00
{
// Is stencil test enabled?
unsigned char enabled;
2022-09-22 18:26:05 +00:00
/*
0 TEST_NEVER
1 TEST_LESS
2 TEST_EQUAL
3 TEST_LESS_EQUAL
4 TEST_GREATER
5 TEST_NOT_EQUAL
6 TEST_GREATER_EQUAL
7 TEST_NEVER (though nifskope comment says TEST_ALWAYS, but ingame it is TEST_NEVER)
2022-09-22 18:26:05 +00:00
*/
int compareFunc;
unsigned stencilRef;
unsigned stencilMask;
2022-09-22 18:26:05 +00:00
/*
Stencil test fail action, depth test fail action and depth test pass action:
0 ACTION_KEEP
1 ACTION_ZERO
2 ACTION_REPLACE
3 ACTION_INCREMENT
4 ACTION_DECREMENT
5 ACTION_INVERT
2022-09-22 18:26:05 +00:00
*/
int failAction;
int zFailAction;
int zPassAction;
2022-09-22 18:26:05 +00:00
/*
Face draw mode:
0 DRAW_CCW_OR_BOTH
1 DRAW_CCW [default]
2 DRAW_CW
3 DRAW_BOTH
2022-09-22 18:26:05 +00:00
*/
int drawMode;
2022-09-22 18:26:05 +00:00
void read(NIFStream* nif);
};
2022-06-21 21:43:16 +00:00
struct NiAlphaProperty : public StructPropT<S_AlphaProperty>
2022-09-22 18:26:05 +00:00
{
2022-06-21 21:43:16 +00:00
bool useAlphaBlending() const { return flags & 1; }
int sourceBlendMode() const { return (flags >> 1) & 0xF; }
int destinationBlendMode() const { return (flags >> 5) & 0xF; }
bool noSorter() const { return (flags >> 13) & 1; }
2020-12-15 22:06:05 +00:00
bool useAlphaTesting() const { return (flags >> 9) & 1; }
int alphaTestMode() const { return (flags >> 10) & 0x7; }
};
struct NiVertexColorProperty : public StructPropT<S_VertexColorProperty>
{
2022-09-22 18:26:05 +00:00
};
struct NiStencilProperty : public Property
2022-09-22 18:26:05 +00:00
{
S_StencilProperty data;
unsigned short flags{ 0u };
2022-09-22 18:26:05 +00:00
void read(NIFStream* nif) override
2022-09-22 18:26:05 +00:00
{
Property::read(nif);
if (nif->getVersion() <= NIFFile::NIFVersion::VER_OB_OLD)
flags = nif->getUShort();
data.read(nif);
}
};
struct NiMaterialProperty : public Property
{
S_MaterialProperty data;
unsigned short flags{ 0u };
2022-09-22 18:26:05 +00:00
void read(NIFStream* nif) override
2022-09-22 18:26:05 +00:00
{
Property::read(nif);
if (nif->getVersion() >= NIFStream::generateVersion(3, 0, 0, 0)
&& nif->getVersion() <= NIFFile::NIFVersion::VER_OB_OLD)
flags = nif->getUShort();
data.read(nif);
}
};
} // Namespace
#endif