Skip to content

Commit

Permalink
vsgopenmw-rebase-me
Browse files Browse the repository at this point in the history
  • Loading branch information
vsgopenmw-bot authored and Your Name committed Nov 2, 2023
1 parent 9548973 commit bc23ceb
Show file tree
Hide file tree
Showing 85 changed files with 982 additions and 389 deletions.
2 changes: 1 addition & 1 deletion apps/openmw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ source_group(game FILES ${GAME} ${GAME_HEADER})

add_openmw_dir (mwrender
mask bin rendermode renderinginterface renderpass intersect rendermanager terrainstorage landmanager
animcontext bodyparts wieldingcreature npc player face scene camera itemlight effect effects projectiles spellcastglow
animcontext bodyparts wieldingcreature npc player face scene camera itemlight effect effects projectiles spellcastglow transparency
env weather weatherdata
map worldmap preview shadow
#bulletdebugdraw ripplesimulation
Expand Down
7 changes: 4 additions & 3 deletions apps/openmw/mwmechanics/actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,14 +1248,15 @@ namespace MWMechanics

// Fade away actors on large distance (>90% of actor's processing distance)
float visibilityRatio = 1.0;
/*
const float fadeStartDistance = mActorsProcessingRange * 0.9f;
const float fadeEndDistance = mActorsProcessingRange;
const float fadeRatio = (dist - fadeStartDistance) / (fadeEndDistance - fadeStartDistance);
if (fadeRatio > 0)
visibilityRatio -= std::max(0.f, fadeRatio);
visibilityRatio = std::min(1.f, visibilityRatio);

*/
ctrl.setVisibility(visibilityRatio);
}

Expand Down Expand Up @@ -1738,14 +1739,14 @@ namespace MWMechanics
}

charactersToUpdate.push_back(&ctrl);
//updateVisibility(actor.getPtr(), ctrl);
updateVisibility(actor.getPtr(), ctrl);
}

if (playerCharacter)
{
charactersToUpdate.push_back(playerCharacter);
MWBase::Environment::get().getWorld()->applyDeferredPreviewRotationToPlayer(duration);
//playerCharacter->setVisibility(1.f);
playerCharacter->setVisibility(1.f);
MWBase::LuaManager::ActorControls* luaControls
= MWBase::Environment::get().getLuaManager()->getActorControls(player);
if (luaControls && player.getClass().getMovementSettings(player).mPosition[2] < 1)
Expand Down
10 changes: 4 additions & 6 deletions apps/openmw/mwmechanics/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "../mwrender/effect.hpp"
#include "../mwrender/itemlight.hpp"
#include "../mwrender/player.hpp"
#include "../mwrender/transparency.hpp"

#include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp"
Expand Down Expand Up @@ -914,7 +915,7 @@ namespace MWMechanics
* handle knockout and death which moves the character down. */
mAnimation->setAccumulation({ 1.0f, 1.0f, 0.0f });

MWRender::addItemLightsAndListener(*mActor->transform(), cls.getContainerStore(mPtr));
MWRender::addItemLightsAndListener(*mObject, cls.getContainerStore(mPtr));

if (cls.hasInventoryStore(mPtr))
{
Expand Down Expand Up @@ -1866,7 +1867,7 @@ namespace MWMechanics
speed = 0.f;

updateMagicEffects();
MWAnim::updateEffects(*mObject->transform(), duration);
MWAnim::updateEffects(*mObject->node(), duration);

bool isPlayer = mPtr == MWMechanics::getPlayer();
bool isFirstPersonPlayer = isPlayer && MWBase::Environment::get().getWorld()->isFirstPerson();
Expand Down Expand Up @@ -2423,7 +2424,6 @@ namespace MWMechanics
if (mActor)
{
mActor->manualAnimation(mPtr.getRefData().getPosition().rot[0], duration);
MWRender::updateItemLights(*mActor->transform(), duration);
if (mWielding)
{
if (mWeaponType != 0 && !mCurrentWeapon.empty())
Expand Down Expand Up @@ -2765,9 +2765,7 @@ namespace MWMechanics
visibility = std::min(visibility, alpha);
}

// TODO: implement a dithering shader rather than just change object transparency.
// createBin(ChameleonPostFxBin)
// mAnimation->setAlpha(visibility);
MWRender::setTransparency(*mObject, visibility);
}

std::string_view CharacterController::getMovementBasedAttackType() const
Expand Down
9 changes: 3 additions & 6 deletions apps/openmw/mwmechanics/summoning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ namespace MWMechanics

for (const auto& it : summonMapToGameSetting)
{
summonMap[it.first] = ESM::RefId::stringRefId(MWBase::Environment::get()
.getWorld()
->getStore()
.get<ESM::GameSetting>()
.find(it.second)
->mValue.getString());
auto creature = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search(it.second);
if (creature)
summonMap[it.first] = ESM::RefId::stringRefId(creature->mValue.getString());
}
return summonMap;
}
Expand Down
19 changes: 11 additions & 8 deletions apps/openmw/mwrender/effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,30 @@ namespace MWRender
const std::string& bone, const std::string& overrideTexture)
{
auto world = MWBase::Environment::get().getWorld();
auto anim = world->getAnimation(ptr);
if (!anim || !anim->animation) // if (!hasCharacterController)
auto object = world->getAnimation(ptr);
if (!object || !object->animation) // if (!hasCharacterController)
return;

auto static_ = world->getStore().get<ESM::Static>().search(effect);
if (!static_ || static_->mModel.empty())
return;

auto ctx = anim->context();
auto ctx = object->context();
ctx.compileContext = ctx.compileContext->clone(Mask_Effect);

auto node = ctx.readEffect(static_->mModel);
auto meta = Anim::Meta::get(*node);

vsg::Group* attachTo = anim->transform();
vsg::Group* attachBone{};
std::vector<Anim::Transform*> worldAttachmentPath = { object->transform() };
if (!bone.empty())
{
auto b = anim->searchBone(bone);
auto b = object->searchBone(bone);
if (!b)
return;
attachTo = Anim::getOrAttachBone(attachTo, b->path);
attachBone = Anim::getOrAttachBone(object->nodeToAddChildrenTo(), b->path);
for (auto& n : b->path)
worldAttachmentPath.emplace_back(n);
}
else if (!ptr.getClass().isNpc())
{
Expand All @@ -72,11 +75,11 @@ namespace MWRender
if (meta)
meta->attachTo(*node);

MWAnim::addEffect(ctx, *anim->transform(), *attachTo, node, magicEffectId, loop, overrideTexture);
MWAnim::addEffect(*object, attachBone, node, worldAttachmentPath, magicEffectId, loop, overrideTexture);
}
void removeEffect(const MWWorld::Ptr& ptr, std::optional<int> effectId)
{
if (auto anim = MWBase::Environment::get().getWorld()->getAnimation(ptr))
MWAnim::removeEffect(*anim->transform(), effectId);
MWAnim::removeEffect(*anim->node(), effectId);
}
}
19 changes: 8 additions & 11 deletions apps/openmw/mwrender/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,18 @@ namespace MWRender
void Effects::add(const std::string& model, const std::string& textureOverride, const vsg::vec3& worldPosition,
float scale, bool isMagicVFX)
{
MWAnim::Effect effect{.mwctx=mContext};
effect.overrideTexture = textureOverride;
effect.overrideAllTextures = !isMagicVFX;
effect.node = mContext.readNode(model);
effect.compile();

auto transform = vsg::ref_ptr{ new Anim::Transform };
transform->children = { effect.node };
effect.node = transform;

effect.attachTo(mNode.get());

transform->translation = worldPosition;
transform->setScale(scale);

MWAnim::Effect effect;
effect.mwctx = mContext;

auto [anim, node] = MWAnim::Effect::load(mContext, mContext.readNode(model), textureOverride, !isMagicVFX);
transform->children = { node };
effect.compile(anim, transform, { transform }, { node.get() } );

effect.attachTo(mNode.get());
mEffects->effects.push_back(effect);
}

Expand Down
15 changes: 8 additions & 7 deletions apps/openmw/mwrender/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ namespace MWRender
return View::dummyEnvMap();
}

vsg::ref_ptr<vsg::StateGroup> createEnv(const vsg::vec4& color)
vsg::ref_ptr<vsg::StateGroup> createEnv(const vsg::vec4& color, float alpha)
{
auto sg = vsg::StateGroup::create();
auto object = Pipeline::Object(0);
Pipeline::Object object;
object.value().envColor = color;
object.value().alpha = alpha;
auto layout = Pipeline::getCompatiblePipelineLayout();
sg->stateCommands = { vsg::BindDescriptorSet::create(
VK_PIPELINE_BIND_POINT_GRAPHICS, layout, Pipeline::OBJECT_SET, vsg::Descriptors{ object.descriptor() }) };
Expand All @@ -69,18 +70,18 @@ namespace MWRender
return {};
}

void addEnv(vsg::ref_ptr<vsg::Node>& node, std::optional<vsg::vec4> color)
void addEnv(vsg::ref_ptr<vsg::Node>& node, std::optional<vsg::vec4> color, float alpha)
{
if (color)
if (color || alpha != 1.f)
{
auto sg = createEnv(*color);
auto sg = createEnv(*color, alpha);
vsgUtil::addChildren(*sg, *node);
node = sg;
}
}

void addEnv(vsg::ref_ptr<vsg::Node>& node, const MWWorld::ConstPtr& item)
void addEnv(vsg::ref_ptr<vsg::Node>& node, const MWWorld::ConstPtr& item, float alpha)
{
addEnv(node, getGlowColor(item));
addEnv(node, getGlowColor(item), alpha);
}
}
6 changes: 3 additions & 3 deletions apps/openmw/mwrender/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace MWRender
* Adds reflective glow.
*/
vsg::ref_ptr<vsg::Descriptor> readEnv(vsg::ref_ptr<const vsg::Options> options);
vsg::ref_ptr<vsg::StateGroup> createEnv(const vsg::vec4& color);
void addEnv(vsg::ref_ptr<vsg::Node>& node, std::optional<vsg::vec4> color);
void addEnv(vsg::ref_ptr<vsg::Node>& node, const MWWorld::ConstPtr& item);
vsg::ref_ptr<vsg::StateGroup> createEnv(const vsg::vec4& color, float alpha = 1.f);
void addEnv(vsg::ref_ptr<vsg::Node>& node, std::optional<vsg::vec4> color, float alpha = 1.f);
void addEnv(vsg::ref_ptr<vsg::Node>& node, const MWWorld::ConstPtr& item, float alpha = 1.f);
std::optional<vsg::vec4> getGlowColor(const MWWorld::ConstPtr& item);
}

Expand Down
58 changes: 32 additions & 26 deletions apps/openmw/mwrender/itemlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <components/animation/update.hpp>
#include <components/mwanimation/light.hpp>
#include <components/mwanimation/object.hpp>
#include <components/vsgutil/removechild.hpp>

#include "../mwworld/containerstore.hpp"
Expand All @@ -25,58 +26,63 @@ namespace MWRender
class UpdateItemLights : public MWWorld::ContainerStoreListener
{
public:
UpdateItemLights(vsg::Group& n)
: node(n)
UpdateItemLights(MWAnim::Object& obj)
: object(obj)
{
}
vsg::Group& node;
void itemAdded(const MWWorld::ConstPtr& item, int count) override { addItemLightIfRequired(node, item); }
void itemRemoved(const MWWorld::ConstPtr& item, int count) override { removeItemLight(node, item); }
MWAnim::Object& object;
void itemAdded(const MWWorld::ConstPtr& item, int count) override { addItemLightIfRequired(object, item); }
void itemRemoved(const MWWorld::ConstPtr& item, int count) override { removeItemLight(object, item); }
};

void addItemLight(vsg::Group& node, const MWWorld::ConstPtr& item, const ESM::Light& light)
void addItemLight(MWAnim::Object& obj, const MWWorld::ConstPtr& item, const ESM::Light& light)
{
ItemLights lights;
node.getValue(sItemLights, lights);
obj.node()->getValue(sItemLights, lights);
if (lights.find(item) != lights.end())
return;
// osg::Vec4f ambient(1,1,1,1);
ItemLight l;
l.node = MWAnim::addLight(&node, &node, light, l.update.controllers);
l.node = MWAnim::addLight(obj.nodeToAddChildrenTo(), obj.nodeToAddChildrenTo(), light, obj.autoPlay.getOrCreateGroup().controllers);
lights[item] = l;
node.setValue(sItemLights, lights);
obj.node()->setValue(sItemLights, lights);
}

void removeItemLight(vsg::Group& node, const MWWorld::ConstPtr& item)
void removeItemLight(MWAnim::Object& obj, const MWWorld::ConstPtr& item)
{
if (item.getType() != ESM::Light::sRecordId)
return;
if (!obj.node()->getAuxiliary())
return;
ItemLights lights;
node.getValue(sItemLights, lights);
obj.node()->getValue(sItemLights, lights);
auto l = lights.find(item);
if (l == lights.end())
return;
vsgUtil::removeChild(&node, l->second.node);
node.setValue(sItemLights, lights);
vsgUtil::removeChild(obj.nodeToAddChildrenTo(), l->second.node);

auto& ctrls = obj.autoPlay.getOrCreateGroup().controllers;
auto citr = ctrls.begin();
while (citr != ctrls.end())
{
if (citr->second == l->second.node)
citr = ctrls.erase(citr);
else
++citr;
}

obj.node()->setValue(sItemLights, lights);
}

void addItemLightsAndListener(vsg::Group& node, MWWorld::ContainerStore& store)
void addItemLightsAndListener(MWAnim::Object& obj, MWWorld::ContainerStore& store)
{
for (auto iter = store.cbegin(MWWorld::ContainerStore::Type_Light); iter != store.cend(); ++iter)
{
auto light = iter->get<ESM::Light>()->mBase;
if (!(light->mData.mFlags & ESM::Light::Carry))
addItemLight(node, *iter, *light);
addItemLight(obj, *iter, *light);
}
store.setContListener(new UpdateItemLights(node));
}

void updateItemLights(vsg::Group& node, float dt)
{
ItemLights lights;
node.getValue(sItemLights, lights);
for (auto& [key, l] : lights)
l.update.update(dt);
store.setContListener(new UpdateItemLights(obj));
}

void removeListener(MWWorld::ContainerStore& store)
Expand All @@ -88,12 +94,12 @@ namespace MWRender
}
}

void addItemLightIfRequired(vsg::Group& node, const MWWorld::ConstPtr& item)
void addItemLightIfRequired(MWAnim::Object& obj, const MWWorld::ConstPtr& item)
{
if (item.getType() != ESM::Light::sRecordId)
return;
auto light = item.get<ESM::Light>()->mBase;
if (!(light->mData.mFlags & ESM::Light::Carry))
addItemLight(node, item, *light);
addItemLight(obj, item, *light);
}
}
17 changes: 8 additions & 9 deletions apps/openmw/mwrender/itemlight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@

#include "../mwworld/ptr.hpp"

#include <vsg/nodes/Group.h>

#include <components/animation/controllers.hpp>

namespace ESM
{
class Light;
}
namespace MWAnim
{
class Object;
}
namespace MWRender
{
void addItemLightsAndListener(vsg::Group& node, MWWorld::ContainerStore& store);
void addItemLightsAndListener(MWAnim::Object& obj, MWWorld::ContainerStore& store);
void removeListener(MWWorld::ContainerStore& store);
void addItemLightIfRequired(vsg::Group& node, const MWWorld::ConstPtr& item);
void addItemLight(vsg::Group& node, const MWWorld::ConstPtr& item, const ESM::Light& esmLight);
void removeItemLight(vsg::Group& node, const MWWorld::ConstPtr& item);
void updateItemLights(vsg::Group& node, float dt);
void addItemLightIfRequired(MWAnim::Object& obj, const MWWorld::ConstPtr& item);
void addItemLight(MWAnim::Object& obj, const MWWorld::ConstPtr& item, const ESM::Light& esmLight);
void removeItemLight(MWAnim::Object& obj, const MWWorld::ConstPtr& item);
}

#endif
2 changes: 1 addition & 1 deletion apps/openmw/mwrender/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ namespace MWRender
auto view = vsgUtil::createSharedView(camera, root);
// auto lightGrid = std::make_unique<View::LightGrid>(shaderOptions);
// setResolution()
view->mask = ~Mask_Particle;
view->mask = ~(Mask_Particle|Mask_GUI);
view->viewDependentState = collectLights;
view->bins = {
vsg::Bin::create(Bin_DepthSorted, vsg::Bin::DESCENDING),
Expand Down
Loading

0 comments on commit bc23ceb

Please sign in to comment.