From 886fd5efc94e92290cd1967082882fbb71e12d99 Mon Sep 17 00:00:00 2001 From: Julien Valentin Date: Thu, 16 Apr 2020 02:55:47 +0200 Subject: [PATCH] enable particle shading and force particle normal to (0.3,0.3,0.3) and update changelog --- CHANGELOG.md | 2 ++ components/nifosg/nifloader.cpp | 2 ++ components/nifosg/particle.cpp | 27 +++++++++++++++++++++++++++ components/nifosg/particle.hpp | 3 +++ 4 files changed, 34 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eff7dee0..d975eb4cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ 0.47.0 ------ + Bug #3676: NiParticleColorModifier isn't applied properly + Bug #4949: Incorrect particle lighting when force shaders = true Bug #5358: ForceGreeting always resets the dialogue window completely Bug #5363: Enchantment autocalc not always 0/1 Bug #5364: Script fails/stops if trying to startscript an unknown script diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 07cbaee37..801427b92 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -1078,6 +1078,8 @@ namespace NifOsg trans->addChild(toAttach); parentNode->addChild(trans); } + // create partsys stateset in order to pass in ShaderVisitor like all other Drawables + partsys->getOrCreateStateSet(); } void triCommonToGeometry(osg::Geometry *geometry, const std::vector& vertices, const std::vector& normals, const std::vector>& uvlist, const std::vector& colors, const std::vector& boundTextures, const std::string& name) diff --git a/components/nifosg/particle.cpp b/components/nifosg/particle.cpp index 2a79af1c8..1b1e469bc 100644 --- a/components/nifosg/particle.cpp +++ b/components/nifosg/particle.cpp @@ -2,6 +2,7 @@ #include +#include #include #include @@ -19,12 +20,19 @@ ParticleSystem::ParticleSystem() : osgParticle::ParticleSystem() , mQuota(std::numeric_limits::max()) { + mNormalArray = new osg::Vec3Array(1); + mNormalArray->setBinding(osg::Array::BIND_OVERALL); + (*mNormalArray.get())[0] = osg::Vec3(0.3, 0.3, 0.3); } ParticleSystem::ParticleSystem(const ParticleSystem ©, const osg::CopyOp ©op) : osgParticle::ParticleSystem(copy, copyop) , mQuota(copy.mQuota) { + mNormalArray = new osg::Vec3Array(1); + mNormalArray->setBinding(osg::Array::BIND_OVERALL); + (*mNormalArray.get())[0] = osg::Vec3(0.3, 0.3, 0.3); + // For some reason the osgParticle constructor doesn't copy the particles for (int i=0;iassignNormalArrayDispatcher(); + state.getCurrentVertexArrayState()->setNormalArray(state, mNormalArray); + } + else + { + state.getAttributeDispatchers().activateNormalArray(mNormalArray); + } +#else + state.Normal(0.3, 0.3, 0.3); +#endif + osgParticle::ParticleSystem::drawImplementation(renderInfo); +} + void InverseWorldMatrix::operator()(osg::Node *node, osg::NodeVisitor *nv) { if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR) diff --git a/components/nifosg/particle.hpp b/components/nifosg/particle.hpp index e159914c7..d71cbb9f5 100644 --- a/components/nifosg/particle.hpp +++ b/components/nifosg/particle.hpp @@ -36,8 +36,11 @@ namespace NifOsg void setQuota(int quota); + virtual void drawImplementation(osg::RenderInfo& renderInfo) const; + private: int mQuota; + osg::ref_ptr mNormalArray; }; // HACK: Particle doesn't allow setting the initial age, but we need this for loading the particle system state