shading, proto-lighting

This commit is contained in:
floralrainfall 2023-07-10 19:33:38 -04:00
parent 54cbea9244
commit c37a4fbfcf
9 changed files with 65 additions and 24 deletions

View File

@ -46,7 +46,7 @@ namespace RNR
ogreSceneManager = ogreRoot->createSceneManager(); ogreSceneManager = ogreRoot->createSceneManager();
ogreSceneManager->setSkyBox(true, "sky/null_plainsky512", 5.f); ogreSceneManager->setSkyBox(true, "sky/null_plainsky512", 5.f);
ogreSceneManager->setAmbientLight(Ogre::ColourValue::White); ogreSceneManager->setAmbientLight(Ogre::ColourValue(0.5f,0.5f,0.5f));
if(Ogre::RTShader::ShaderGenerator::initialize()) if(Ogre::RTShader::ShaderGenerator::initialize())
{ {
@ -58,11 +58,16 @@ namespace RNR
else else
printf("OgreWidget::initializeOgre: unable to initialize ShaderGenerator\n"); printf("OgreWidget::initializeOgre: unable to initialize ShaderGenerator\n");
Ogre::Light* light = ogreSceneManager->createLight("MainLight"); Ogre::Light* light = ogreSceneManager->createLight("SunLight");
Ogre::SceneNode* lightNode = ogreSceneManager->getRootSceneNode()->createChildSceneNode(); Ogre::SceneNode* lightNode = ogreSceneManager->getRootSceneNode()->createChildSceneNode();
lightNode->setPosition(0, 10, 15); lightNode->setPosition(0, 10, 15);
lightNode->setDirection(-0.25, -0.5, -0.5);
lightNode->attachObject(light); lightNode->attachObject(light);
light->setDiffuseColour(0.9, 0.9, 1.0);
light->setSpecularColour(1.0, 1.0, 1.0);
light->setType(Ogre::Light::LT_DIRECTIONAL);
Ogre::SceneNode* camNode = ogreSceneManager->getRootSceneNode()->createChildSceneNode(); Ogre::SceneNode* camNode = ogreSceneManager->getRootSceneNode()->createChildSceneNode();
camNode->setPosition(0, 0, 5); camNode->setPosition(0, 0, 5);
camNode->lookAt(Ogre::Vector3(0, sinf(render_time), cosf(render_time)), Ogre::Node::TS_PARENT); camNode->lookAt(Ogre::Vector3(0, sinf(render_time), cosf(render_time)), Ogre::Node::TS_PARENT);
@ -83,7 +88,8 @@ namespace RNR
this->render_time += ogreRoot->getTimer()->getMilliseconds() / 1000.0; this->render_time += ogreRoot->getTimer()->getMilliseconds() / 1000.0;
ogreRoot->getTimer()->reset(); ogreRoot->getTimer()->reset();
ogreCamera->getParentSceneNode()->lookAt(Ogre::Vector3(sinf(this->render_time)*10.f,0,cosf(this->render_time)*10.f), Ogre::Node::TS_PARENT); ogreCamera->getParentSceneNode()->setPosition(Ogre::Vector3(sinf(this->render_time)*10,5.f,cosf(this->render_time)*10));
ogreCamera->getParentSceneNode()->lookAt(Ogre::Vector3(0,0,0), Ogre::Node::TS_PARENT);
ogreRoot->renderOneFrame(this->delta); ogreRoot->renderOneFrame(this->delta);
} }

View File

@ -20,8 +20,8 @@ int main(int argc, char** argv)
window.show(); window.show();
window.ogreWidget->initializeOgre(); window.ogreWidget->initializeOgre();
RNR::World* world = new RNR::World(); RNR::World* world = new RNR::World(window.ogreWidget->ogreRoot, window.ogreWidget->ogreSceneManager);
Ogre::SceneNode* workspace_node = window.ogreWidget->ogreSceneManager->createSceneNode("Workspace"); Ogre::SceneNode* workspace_node = window.ogreWidget->ogreSceneManager->getRootSceneNode()->createChildSceneNode();
workspace_node->attachObject(world->getWorkspace()); workspace_node->attachObject(world->getWorkspace());
workspace_node->setVisible(true); workspace_node->setVisible(true);
printf("main: workspace = %p (%p)\n",workspace_node, world->getWorkspace()); printf("main: workspace = %p (%p)\n",workspace_node, world->getWorkspace());

View File

@ -9,9 +9,15 @@
namespace RNR namespace RNR
{ {
class World;
class Instance class Instance
{ {
protected:
static World* world;
private: private:
std::string m_name; std::string m_name;
RNR::Instance* m_parent; RNR::Instance* m_parent;
std::vector<RNR::Instance*> m_children; std::vector<RNR::Instance*> m_children;
@ -24,6 +30,8 @@ namespace RNR
bool contains(RNR::Instance* child); bool contains(RNR::Instance* child);
bool isAncestorOf(RNR::Instance* instance); bool isAncestorOf(RNR::Instance* instance);
static void setWorld(World* world) { Instance::world = world; }
virtual bool askSetParent(RNR::Instance* instance); // derive this virtual bool askSetParent(RNR::Instance* instance); // derive this
bool canSetParent(RNR::Instance* instance); bool canSetParent(RNR::Instance* instance);
virtual bool askAddChild(RNR::Instance* instance); // derive this virtual bool askAddChild(RNR::Instance* instance); // derive this

View File

@ -18,6 +18,9 @@ namespace RNR
virtual Ogre::Real getBoundingRadius(void) const; virtual Ogre::Real getBoundingRadius(void) const;
virtual void visitRenderables(Ogre::Renderable::Visitor* visitor, bool debugRenderables); virtual void visitRenderables(Ogre::Renderable::Visitor* visitor, bool debugRenderables);
private: private:
Ogre::AxisAlignedBox m_bbox;
Ogre::String m_type;
void renderQueueAddInstance(Ogre::RenderQueue* queue, Instance* instance); void renderQueueAddInstance(Ogre::RenderQueue* queue, Instance* instance);
}; };
} }

View File

@ -2,6 +2,7 @@
#include <App/V8/Tree/Instance.hpp> #include <App/V8/Tree/Instance.hpp>
#include <App/V8/World/Workspace.hpp> #include <App/V8/World/Workspace.hpp>
#include <OGRE/Ogre.h>
namespace RNR namespace RNR
{ {
@ -10,9 +11,11 @@ namespace RNR
private: private:
Instance* m_datamodel; Instance* m_datamodel;
Workspace* m_workspace; Workspace* m_workspace;
Ogre::Root* m_ogreRoot;
Ogre::SceneManager* m_ogreSceneManager;
public: public:
World(); World(Ogre::Root* ogre, Ogre::SceneManager* ogreScene);
~World(); ~World();
void preStep(); void preStep();
@ -23,5 +26,7 @@ namespace RNR
void setDatamodel(Instance* instance) { m_datamodel = instance; } void setDatamodel(Instance* instance) { m_datamodel = instance; }
Workspace* getWorkspace() { return m_workspace; } Workspace* getWorkspace() { return m_workspace; }
void setWorkspace(Workspace* workspace) { m_workspace = workspace; } void setWorkspace(Workspace* workspace) { m_workspace = workspace; }
Ogre::Root* getOgreRoot() { return m_ogreRoot; }
Ogre::SceneManager* getOgreSceneManager() { return m_ogreSceneManager; }
}; };
} }

View File

@ -1,14 +1,17 @@
#include <App/V8/DataModel/BasePart.hpp> #include <App/V8/DataModel/BasePart.hpp>
#include <App/V8/World/World.hpp>
namespace RNR namespace RNR
{ {
Ogre::MeshPtr BasePart::m_partMesh = 0; Ogre::MeshPtr BasePart::m_partMesh = 0;
BasePart::BasePart() : m_matrix(), PVInstance() BasePart::BasePart() : m_matrix(), PVInstance(), Ogre::Renderable()
{ {
setName("Part"); setName("Part");
updateMatrix(); updateMatrix();
m_nearbyLights = Ogre::LightList();
m_nearbyLights.insert(m_nearbyLights.begin(), world->getOgreSceneManager()->getLight("SunLight"));
m_material = Ogre::MaterialManager::getSingletonPtr()->create("part", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); m_material = Ogre::MaterialManager::getSingletonPtr()->create("part", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
@ -20,24 +23,31 @@ namespace RNR
{ {
m_matrix = m_cframe.getMatrix(); m_matrix = m_cframe.getMatrix();
m_position = m_cframe.getPosition(); m_position = m_cframe.getPosition();
m_nearbyLights = Ogre::LightList();
} }
const Ogre::MaterialPtr& BasePart::getMaterial() const const Ogre::MaterialPtr& BasePart::getMaterial() const
{ {
return m_material; Ogre::SubMesh* submesh = m_partMesh->getSubMesh(0);
return submesh->getMaterial();
} }
void BasePart::getRenderOperation(Ogre::RenderOperation& op) void BasePart::getRenderOperation(Ogre::RenderOperation& op)
{ {
Ogre::SubMesh* submesh = m_partMesh->getSubMesh(0); Ogre::SubMesh* submesh = m_partMesh->getSubMesh(0);
op.operationType = op.OT_TRIANGLE_LIST; if(submesh)
op.vertexData = submesh->vertexData; {
op.indexData = submesh->indexData; op.operationType = op.OT_TRIANGLE_LIST;
op.numberOfInstances = 1; if(submesh->useSharedVertices == false)
op.srcRenderable = this; op.vertexData = submesh->vertexData;
op.useIndexes = true; else
op.vertexData = m_partMesh->sharedVertexData;
op.indexData = submesh->indexData;
op.numberOfInstances = 1;
op.srcRenderable = this;
op.useIndexes = true;
}
else
printf("BasePart::getRenderOperation: couldnt get submesh\n");
} }
Ogre::Real BasePart::getSquaredViewDepth(const Ogre::Camera* cam) const Ogre::Real BasePart::getSquaredViewDepth(const Ogre::Camera* cam) const
@ -53,6 +63,6 @@ namespace RNR
void BasePart::getWorldTransforms(Ogre::Matrix4* xform) const void BasePart::getWorldTransforms(Ogre::Matrix4* xform) const
{ {
xform[0] = m_matrix; *xform = m_matrix;
} }
} }

View File

@ -2,6 +2,8 @@
namespace RNR namespace RNR
{ {
World* Instance::world = 0;
Instance::Instance() Instance::Instance()
{ {
m_parent = 0; m_parent = 0;

View File

@ -6,11 +6,12 @@ namespace RNR
Workspace::Workspace() : Instance(), Ogre::MovableObject() Workspace::Workspace() : Instance(), Ogre::MovableObject()
{ {
setName("Workspace"); setName("Workspace");
m_type = Ogre::String("Entity");
m_bbox = Ogre::AxisAlignedBox(-1000,-1000,-1000, 1000,1000,1000);
} }
void Workspace::_updateRenderQueue(Ogre::RenderQueue* queue) void Workspace::_updateRenderQueue(Ogre::RenderQueue* queue)
{ {
printf("!!!!!!!!!!!!!!!!!!!!1 _updateRenderQueue\n");
std::vector<Instance*>* children = getChildren(); std::vector<Instance*>* children = getChildren();
for(auto& child : *children) for(auto& child : *children)
{ {
@ -21,22 +22,24 @@ namespace RNR
void Workspace::renderQueueAddInstance(Ogre::RenderQueue* queue, Instance* instance) void Workspace::renderQueueAddInstance(Ogre::RenderQueue* queue, Instance* instance)
{ {
std::vector<Instance*>* children = instance->getChildren(); std::vector<Instance*>* children = instance->getChildren();
BasePart* rend = dynamic_cast<BasePart*>(instance);
queue->addRenderable(rend);
for(auto& child : *children) for(auto& child : *children)
{ {
renderQueueAddInstance(queue, child); renderQueueAddInstance(queue, child);
} }
BasePart* rend = dynamic_cast<BasePart*>(instance);
queue->addRenderable(rend);
} }
const Ogre::String& Workspace::getMovableType(void) const const Ogre::String& Workspace::getMovableType(void) const
{ {
return Ogre::String("Entity"); printf("Workspace::getMovableType\n");
return m_type;
} }
const Ogre::AxisAlignedBox& Workspace::getBoundingBox(void) const const Ogre::AxisAlignedBox& Workspace::getBoundingBox(void) const
{ {
return Ogre::AxisAlignedBox(Ogre::Vector3(-1000,-1000,-1000),Ogre::Vector3(1000,1000,1000)); return m_bbox;
} }
Ogre::Real Workspace::getBoundingRadius(void) const Ogre::Real Workspace::getBoundingRadius(void) const

View File

@ -3,8 +3,12 @@
namespace RNR namespace RNR
{ {
World::World() World::World(Ogre::Root* ogre, Ogre::SceneManager* ogreSceneManager)
{ {
Instance::setWorld(this);
m_ogreRoot = ogre;
m_ogreSceneManager = ogreSceneManager;
m_datamodel = new Instance(); m_datamodel = new Instance();
m_datamodel->setName("DataModel"); m_datamodel->setName("DataModel");
m_workspace = new Workspace(); m_workspace = new Workspace();