mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-20 14:11:32 +00:00
Modernize dynamic effects
This commit is contained in:
parent
2e847a12c4
commit
bb6e008801
3 changed files with 93 additions and 92 deletions
|
@ -9,55 +9,61 @@ namespace Nif
|
||||||
void NiDynamicEffect::read(NIFStream* nif)
|
void NiDynamicEffect::read(NIFStream* nif)
|
||||||
{
|
{
|
||||||
Node::read(nif);
|
Node::read(nif);
|
||||||
if (nif->getVersion() >= nif->generateVersion(10, 1, 0, 106)
|
|
||||||
&& nif->getBethVersion() < NIFFile::BethVersion::BETHVER_FO4)
|
if (nif->getVersion() > NIFFile::VER_MW && nif->getVersion() < nif->generateVersion(10, 1, 0, 0))
|
||||||
nif->getBoolean(); // Switch state
|
return;
|
||||||
if (nif->getVersion() <= NIFFile::VER_MW
|
|
||||||
|| (nif->getVersion() >= nif->generateVersion(10, 1, 0, 0)
|
if (nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_FO4)
|
||||||
&& nif->getBethVersion() < NIFFile::BethVersion::BETHVER_FO4))
|
return;
|
||||||
{
|
|
||||||
|
if (nif->getVersion() >= nif->generateVersion(10, 1, 0, 106))
|
||||||
|
nif->read(mSwitchState);
|
||||||
size_t numAffectedNodes = nif->get<uint32_t>();
|
size_t numAffectedNodes = nif->get<uint32_t>();
|
||||||
nif->skip(numAffectedNodes * 4);
|
nif->skip(numAffectedNodes * 4);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void NiLight::read(NIFStream* nif)
|
void NiLight::read(NIFStream* nif)
|
||||||
{
|
{
|
||||||
NiDynamicEffect::read(nif);
|
NiDynamicEffect::read(nif);
|
||||||
|
|
||||||
dimmer = nif->getFloat();
|
mDimmer = nif->getFloat();
|
||||||
ambient = nif->getVector3();
|
mAmbient = nif->getVector3();
|
||||||
diffuse = nif->getVector3();
|
mDiffuse = nif->getVector3();
|
||||||
specular = nif->getVector3();
|
mSpecular = nif->getVector3();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NiPointLight::read(NIFStream* nif)
|
||||||
|
{
|
||||||
|
NiLight::read(nif);
|
||||||
|
|
||||||
|
mConstantAttenuation = nif->getFloat();
|
||||||
|
mLinearAttenuation = nif->getFloat();
|
||||||
|
mQuadraticAttenuation = nif->getFloat();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NiSpotLight::read(NIFStream* nif)
|
||||||
|
{
|
||||||
|
NiPointLight::read(nif);
|
||||||
|
|
||||||
|
mCutoff = nif->getFloat();
|
||||||
|
mExponent = nif->getFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NiTextureEffect::read(NIFStream* nif)
|
void NiTextureEffect::read(NIFStream* nif)
|
||||||
{
|
{
|
||||||
NiDynamicEffect::read(nif);
|
NiDynamicEffect::read(nif);
|
||||||
|
|
||||||
// Model Projection Matrix
|
nif->read(mProjectionRotation);
|
||||||
nif->skip(3 * 3 * sizeof(float));
|
nif->read(mProjectionPosition);
|
||||||
|
nif->read(mFilterMode);
|
||||||
// Model Projection Transform
|
|
||||||
nif->skip(3 * sizeof(float));
|
|
||||||
|
|
||||||
// Texture Filtering
|
|
||||||
nif->skip(4);
|
|
||||||
|
|
||||||
// Max anisotropy samples
|
|
||||||
if (nif->getVersion() >= NIFStream::generateVersion(20, 5, 0, 4))
|
if (nif->getVersion() >= NIFStream::generateVersion(20, 5, 0, 4))
|
||||||
nif->skip(2);
|
nif->read(mMaxAnisotropy);
|
||||||
|
nif->read(mClampMode);
|
||||||
clamp = nif->getUInt();
|
mTextureType = static_cast<TextureType>(nif->get<uint32_t>());
|
||||||
|
mCoordGenType = static_cast<CoordGenType>(nif->get<uint32_t>());
|
||||||
textureType = (TextureType)nif->getUInt();
|
mTexture.read(nif);
|
||||||
|
nif->read(mEnableClipPlane);
|
||||||
coordGenType = (CoordGenType)nif->getUInt();
|
mClipPlane = osg::Plane(nif->get<osg::Vec4f>());
|
||||||
|
|
||||||
texture.read(nif);
|
|
||||||
|
|
||||||
nif->skip(1); // Use clipping plane
|
|
||||||
nif->skip(16); // Clipping plane dimensions vector
|
|
||||||
if (nif->getVersion() <= NIFStream::generateVersion(10, 2, 0, 0))
|
if (nif->getVersion() <= NIFStream::generateVersion(10, 2, 0, 0))
|
||||||
nif->skip(4); // PS2-specific shorts
|
nif->skip(4); // PS2-specific shorts
|
||||||
if (nif->getVersion() <= NIFStream::generateVersion(4, 1, 0, 12))
|
if (nif->getVersion() <= NIFStream::generateVersion(4, 1, 0, 12))
|
||||||
|
@ -67,24 +73,8 @@ namespace Nif
|
||||||
void NiTextureEffect::post(Reader& nif)
|
void NiTextureEffect::post(Reader& nif)
|
||||||
{
|
{
|
||||||
NiDynamicEffect::post(nif);
|
NiDynamicEffect::post(nif);
|
||||||
texture.post(nif);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NiPointLight::read(NIFStream* nif)
|
mTexture.post(nif);
|
||||||
{
|
|
||||||
NiLight::read(nif);
|
|
||||||
|
|
||||||
constantAttenuation = nif->getFloat();
|
|
||||||
linearAttenuation = nif->getFloat();
|
|
||||||
quadraticAttenuation = nif->getFloat();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NiSpotLight::read(NIFStream* nif)
|
|
||||||
{
|
|
||||||
NiPointLight::read(nif);
|
|
||||||
|
|
||||||
cutoff = nif->getFloat();
|
|
||||||
exponent = nif->getFloat();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,67 +29,75 @@
|
||||||
namespace Nif
|
namespace Nif
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Abstract
|
||||||
struct NiDynamicEffect : public Node
|
struct NiDynamicEffect : public Node
|
||||||
{
|
{
|
||||||
|
bool mSwitchState{ true };
|
||||||
void read(NIFStream* nif) override;
|
void read(NIFStream* nif) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used as base for NiAmbientLight, NiDirectionalLight, NiPointLight and NiSpotLight.
|
// Abstract light source
|
||||||
struct NiLight : NiDynamicEffect
|
struct NiLight : NiDynamicEffect
|
||||||
{
|
{
|
||||||
float dimmer;
|
float mDimmer;
|
||||||
osg::Vec3f ambient;
|
osg::Vec3f mAmbient;
|
||||||
osg::Vec3f diffuse;
|
osg::Vec3f mDiffuse;
|
||||||
osg::Vec3f specular;
|
osg::Vec3f mSpecular;
|
||||||
|
|
||||||
void read(NIFStream* nif) override;
|
void read(NIFStream* nif) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NiPointLight : public NiLight
|
struct NiPointLight : public NiLight
|
||||||
{
|
{
|
||||||
float constantAttenuation;
|
float mConstantAttenuation;
|
||||||
float linearAttenuation;
|
float mLinearAttenuation;
|
||||||
float quadraticAttenuation;
|
float mQuadraticAttenuation;
|
||||||
|
|
||||||
void read(NIFStream* nif) override;
|
void read(NIFStream* nif) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NiSpotLight : public NiPointLight
|
struct NiSpotLight : public NiPointLight
|
||||||
{
|
{
|
||||||
float cutoff;
|
float mCutoff;
|
||||||
float exponent;
|
float mExponent;
|
||||||
void read(NIFStream* nif) override;
|
void read(NIFStream* nif) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NiTextureEffect : NiDynamicEffect
|
struct NiTextureEffect : NiDynamicEffect
|
||||||
{
|
{
|
||||||
NiSourceTexturePtr texture;
|
enum class TextureType : uint32_t
|
||||||
unsigned int clamp;
|
|
||||||
|
|
||||||
enum TextureType
|
|
||||||
{
|
{
|
||||||
Projected_Light = 0,
|
ProjectedLight = 0,
|
||||||
Projected_Shadow = 1,
|
ProjectedShadow = 1,
|
||||||
Environment_Map = 2,
|
EnvironmentMap = 2,
|
||||||
Fog_Map = 3
|
FogMap = 3,
|
||||||
};
|
};
|
||||||
TextureType textureType;
|
|
||||||
|
|
||||||
enum CoordGenType
|
enum class CoordGenType : uint32_t
|
||||||
{
|
{
|
||||||
World_Parallel = 0,
|
WorldParallel = 0,
|
||||||
World_Perspective,
|
WorldPerspective = 1,
|
||||||
Sphere_Map,
|
SphereMap = 2,
|
||||||
Specular_Cube_Map,
|
SpecularCubeMap = 3,
|
||||||
Diffuse_Cube_Map
|
DiffuseCubeMap = 4,
|
||||||
};
|
};
|
||||||
CoordGenType coordGenType;
|
|
||||||
|
Matrix3 mProjectionRotation;
|
||||||
|
osg::Vec3f mProjectionPosition;
|
||||||
|
uint32_t mFilterMode;
|
||||||
|
NiSourceTexturePtr mTexture;
|
||||||
|
uint16_t mMaxAnisotropy{ 0 };
|
||||||
|
uint32_t mClampMode;
|
||||||
|
TextureType mTextureType;
|
||||||
|
CoordGenType mCoordGenType;
|
||||||
|
uint8_t mEnableClipPlane;
|
||||||
|
osg::Plane mClipPlane;
|
||||||
|
|
||||||
void read(NIFStream* nif) override;
|
void read(NIFStream* nif) override;
|
||||||
void post(Reader& nif) override;
|
void post(Reader& nif) override;
|
||||||
|
|
||||||
bool wrapT() const { return clamp & 1; }
|
bool wrapT() const { return mClampMode & 1; }
|
||||||
bool wrapS() const { return (clamp >> 1) & 1; }
|
bool wrapS() const { return mClampMode & 2; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Namespace
|
} // Namespace
|
||||||
|
|
|
@ -537,38 +537,41 @@ namespace NifOsg
|
||||||
}
|
}
|
||||||
|
|
||||||
const Nif::NiTextureEffect* textureEffect = static_cast<const Nif::NiTextureEffect*>(nifNode);
|
const Nif::NiTextureEffect* textureEffect = static_cast<const Nif::NiTextureEffect*>(nifNode);
|
||||||
if (textureEffect->textureType != Nif::NiTextureEffect::Environment_Map)
|
if (!textureEffect->mSwitchState)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (textureEffect->mTextureType != Nif::NiTextureEffect::TextureType::EnvironmentMap)
|
||||||
{
|
{
|
||||||
Log(Debug::Info) << "Unhandled NiTextureEffect type " << textureEffect->textureType << " in "
|
Log(Debug::Info) << "Unhandled NiTextureEffect type "
|
||||||
<< mFilename;
|
<< static_cast<uint32_t>(textureEffect->mTextureType) << " in " << mFilename;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textureEffect->texture.empty())
|
if (textureEffect->mTexture.empty())
|
||||||
{
|
{
|
||||||
Log(Debug::Info) << "NiTextureEffect missing source texture in " << mFilename;
|
Log(Debug::Info) << "NiTextureEffect missing source texture in " << mFilename;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::ref_ptr<osg::TexGen> texGen(new osg::TexGen);
|
osg::ref_ptr<osg::TexGen> texGen(new osg::TexGen);
|
||||||
switch (textureEffect->coordGenType)
|
switch (textureEffect->mCoordGenType)
|
||||||
{
|
{
|
||||||
case Nif::NiTextureEffect::World_Parallel:
|
case Nif::NiTextureEffect::CoordGenType::WorldParallel:
|
||||||
texGen->setMode(osg::TexGen::OBJECT_LINEAR);
|
texGen->setMode(osg::TexGen::OBJECT_LINEAR);
|
||||||
break;
|
break;
|
||||||
case Nif::NiTextureEffect::World_Perspective:
|
case Nif::NiTextureEffect::CoordGenType::WorldPerspective:
|
||||||
texGen->setMode(osg::TexGen::EYE_LINEAR);
|
texGen->setMode(osg::TexGen::EYE_LINEAR);
|
||||||
break;
|
break;
|
||||||
case Nif::NiTextureEffect::Sphere_Map:
|
case Nif::NiTextureEffect::CoordGenType::SphereMap:
|
||||||
texGen->setMode(osg::TexGen::SPHERE_MAP);
|
texGen->setMode(osg::TexGen::SPHERE_MAP);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log(Debug::Info) << "Unhandled NiTextureEffect coordGenType " << textureEffect->coordGenType
|
Log(Debug::Info) << "Unhandled NiTextureEffect CoordGenType "
|
||||||
<< " in " << mFilename;
|
<< static_cast<uint32_t>(textureEffect->mCoordGenType) << " in " << mFilename;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::ref_ptr<osg::Image> image(handleSourceTexture(textureEffect->texture.getPtr(), imageManager));
|
osg::ref_ptr<osg::Image> image(handleSourceTexture(textureEffect->mTexture.getPtr(), imageManager));
|
||||||
osg::ref_ptr<osg::Texture2D> texture2d(new osg::Texture2D(image));
|
osg::ref_ptr<osg::Texture2D> texture2d(new osg::Texture2D(image));
|
||||||
if (image)
|
if (image)
|
||||||
texture2d->setTextureSize(image->s(), image->t());
|
texture2d->setTextureSize(image->s(), image->t());
|
||||||
|
|
Loading…
Reference in a new issue