BrickColor; doesnt work on non FFP drivers

This commit is contained in:
floralrainfall 2023-07-16 03:47:53 -04:00
parent b8a489a6ec
commit 1c7d6e2de2
8 changed files with 153 additions and 36 deletions

View File

@ -1,41 +1,23 @@
//---------------------------------------------------------------------------
//These materials/shaders are part of the NEW InstanceManager implementation
//Written by Matias N. Goldberg ("dark_sylinc")
//---------------------------------------------------------------------------
material materials/part_shadow_caster
{
technique
{
pass
{
rtshader_system
{
lighting_stage gbuffer depth
transform_stage instanced
}
}
}
}
material materials/partinstanced
{
receive_shadows on
receive_shadows on
technique
{
shadow_caster_material materials/part_shadow_caster
technique
{
pass
{
specular 1 1 1 1 12.5
lighting on
pass
{
specular 1 1 1 1 12.5
lighting on
rtshader_system
texture_unit
{
colour_op_ex source1 src_manual src_current 1.0 0.5 0.5
}
rtshader_system
{
transform_stage instanced
lighting_stage per_pixel
}
}
}
}
}
}
}

View File

@ -41,7 +41,7 @@ namespace RNR
//Ogre::ResourceGroupManager::getSingletonPtr()->initialiseAllResourceGroups();
ogreSceneManager = ogreRoot->createSceneManager();
ogreSceneManager->setAmbientLight(Ogre::ColourValue(0.f,0.f,0.f));
ogreSceneManager->setAmbientLight(Ogre::ColourValue(0.2f,0.2f,0.2f));
Ogre::SceneNode* camNode = ogreSceneManager->getRootSceneNode()->createChildSceneNode();
camNode->setPosition(0, 0, 5);

View File

@ -15,6 +15,7 @@ add_library(Engine STATIC
Header/App/V8/Tree/ModelInstance.hpp
Header/App/V8/World/World.hpp
Header/App/CoordinateFrame.hpp
Header/App/BrickColor.hpp
Header/Network/GUID.hpp
Header/Rendering/Adorn.hpp
@ -33,6 +34,7 @@ add_library(Engine STATIC
Source/App/V8/Tree/PVInstance.cpp
Source/App/V8/Tree/ModelInstance.cpp
Source/App/CoordinateFrame.cpp
Source/App/BrickColor.cpp
Source/App/V8/World/World.cpp
Source/Network/GUID.cpp
Source/Rendering/Adorn.cpp

View File

@ -0,0 +1,21 @@
#pragma once
#include <OGRE/Ogre.h>
namespace RNR
{
class BrickColor
{
private:
int color_id;
std::string color_name;
Ogre::Vector3 color_val;
Ogre::MaterialPtr color_material;
public:
BrickColor(int color_id, std::string name, Ogre::Vector3 color);
static Ogre::Vector3 color(int brickcolor);
static bool valid(int brickcolor);
static Ogre::MaterialPtr material(int brickcolor);
};
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <App/V8/Tree/PVInstance.hpp>
#include <App/BrickColor.hpp>
#include <OGRE/Ogre.h>
#define STUD_HEIGHT 1.18
@ -9,6 +10,7 @@ namespace RNR
class PartInstance : public PVInstance, public Ogre::Renderable
{
protected:
int m_brickColor;
Ogre::MaterialPtr m_material;
Ogre::Matrix4 m_matrix;
Ogre::Vector3 m_position;
@ -27,6 +29,8 @@ namespace RNR
Ogre::Vector3 getSize() { return m_size; }
Ogre::Vector4 getColor() { return m_color; }
void setBrickColor(int brickcolor) { m_brickColor = brickcolor; }
int getBrickColor() { return m_brickColor; }
virtual const Ogre::MaterialPtr& getMaterial() const;
virtual void getRenderOperation(Ogre::RenderOperation& op);
virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const;

View File

@ -0,0 +1,94 @@
#include <App/BrickColor.hpp>
#include <OGRE/RTShaderSystem/OgreShaderGenerator.h>
namespace RNR
{
static BrickColor brickcolors[] = {
{ -1, std::string("Placeholder"), Ogre::Vector3(255.0/255.0,0.0/255.0,255.0/255.0) },
{ 1, std::string("White"), Ogre::Vector3(242.0/255.0,243.0/255.0,243.0/255.0) },
{ 2, std::string("Grey"), Ogre::Vector3(161.0/255.0,165.0/255.0,162.0/255.0) },
{ 3, std::string("Light yellow"), Ogre::Vector3(249.0/255.0,233.0/255.0,153.0/255.0) },
{ 5, std::string("Brick yellow"), Ogre::Vector3(215.0/255.0,197.0/255.0,154.0/255.0) },
{ 6, std::string("Light green"), Ogre::Vector3(194.0/255.0,218.0/255.0,184.0/255.0) },
{ 9, std::string("Light reddish violet"), Ogre::Vector3(232.0/255.0,186.0/255.0,200.0/255.0) },
{ 11, std::string("Pastel Blue"), Ogre::Vector3(128.0/255.0,187.0/255.0,219.0/255.0) },
{ 12, std::string("Light orange brown"), Ogre::Vector3(203.0/255.0,132.0/255.0,66.0/255.0) },
{ 18, std::string("Nougat"), Ogre::Vector3(204.0/255.0,142.0/255.0,105.0/255.0) },
{ 21, std::string("Bright red"), Ogre::Vector3(196.0/255.0,40.0/255.0,28.0/255.0) },
{ 22, std::string("Med. reddish violet"), Ogre::Vector3(196.0/255.0,112.0/255.0,160.0/255.0) },
{ 23, std::string("Bright blue"), Ogre::Vector3(13.0/255.0,105.0/255.0,172.0/255.0) },
{ 24, std::string("Bright yellow"), Ogre::Vector3(245.0/255.0,205.0/255.0,48.0/255.0) },
{ 25, std::string("Earth orange"), Ogre::Vector3(98.0/255.0,71.0/255.0,50.0/255.0) },
{ 26, std::string("Black"), Ogre::Vector3(27.0/255.0,42.0/255.0,52.0/255.0) },
{ 27, std::string("Dark grey"), Ogre::Vector3(109.0/255.0,110.0/255.0,108.0/255.0) },
{ 28, std::string("Dark green"), Ogre::Vector3(40.0/255.0,127.0/255.0,71.0/255.0) },
{ 29, std::string("Medium green"), Ogre::Vector3(161.0/255.0,196.0/255.0,140.0/255.0) },
};
BrickColor::BrickColor(int color_id, std::string color_name, Ogre::Vector3 color)
{
this->color_id = color_id;
this->color_name = color_name;
this->color_val = color;
}
Ogre::Vector3 BrickColor::color(int brickcolor)
{
for(int i = 0; i < sizeof(brickcolors) / sizeof(BrickColor); i++)
{
if(brickcolors[i].color_id == brickcolor)
{
return brickcolors[i].color_val;
}
}
return brickcolors[0].color_val;
}
Ogre::MaterialPtr BrickColor::material(int brickcolor)
{
for(int i = 0; i < sizeof(brickcolors) / sizeof(BrickColor); i++)
{
if(brickcolors[i].color_id == brickcolor)
{
if(!brickcolors[i].color_material)
{
brickcolors[i].color_material = Ogre::MaterialManager::getSingletonPtr()->getByName("materials/partinstanced");
brickcolors[i].color_material = brickcolors[i].color_material->clone(Ogre::String("tmp_part/") + Ogre::StringConverter::toString(brickcolor));
Ogre::Technique* mat_tech = brickcolors[i].color_material->getTechnique(0);
Ogre::Pass* mat_pass = mat_tech->getPass(0);
Ogre::TextureUnitState* part_texunit = mat_pass->getTextureUnitState(0);
part_texunit->setColourOperationEx(Ogre::LayerBlendOperationEx::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(brickcolors[i].color_val.x, brickcolors[i].color_val.y, brickcolors[i].color_val.z));
}
return brickcolors[i].color_material;
}
}
if(!brickcolors[0].color_material)
{
brickcolors[0].color_material = Ogre::MaterialManager::getSingletonPtr()->getByName("materials/partinstanced");
brickcolors[0].color_material = brickcolors[0].color_material->clone(Ogre::String("tmp_part/") + Ogre::StringConverter::toString(brickcolor));
Ogre::Technique* mat_tech = brickcolors[0].color_material->getTechnique(0);
Ogre::Pass* mat_pass = mat_tech->getPass(0);
Ogre::TextureUnitState* part_texunit = mat_pass->getTextureUnitState(0);
part_texunit->setColourOperationEx(Ogre::LayerBlendOperationEx::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(brickcolors[0].color_val.x, brickcolors[0].color_val.y, brickcolors[0].color_val.z));
}
return brickcolors[0].color_material;
}
bool BrickColor::valid(int brickcolor)
{
for(int i = 0; i < sizeof(brickcolors) / sizeof(BrickColor); i++)
{
if(brickcolors[i].color_id == brickcolor)
{
return true;
}
}
return false;
}
}

View File

@ -72,6 +72,14 @@ namespace RNR
{
setSize(XML::getVector3(node));
}
else if(prop_name == std::string("BrickColor"))
{
setBrickColor(node.text().as_int());
if(!BrickColor::valid(getBrickColor()))
{
printf("PartInstance::deserializeProperty: BrickColor not valid number (%i)\n", getBrickColor());
}
}
else
PVInstance::deserializeProperty(prop_name, node);
}

View File

@ -10,7 +10,9 @@ namespace RNR
setName("Workspace");
m_worldspawn = world->getOgreSceneManager()->getRootSceneNode()->createChildSceneNode();
m_geom = world->getOgreSceneManager()->createStaticGeometry("workspaceGeom");
m_geom->setCastShadows(true);
m_partEntity = world->getOgreSceneManager()->createEntity("fonts/Cube.mesh");
m_partEntity->setCastShadows(true);
}
void Workspace::onChildAdded(Instance* childAdded)
@ -22,10 +24,14 @@ namespace RNR
{
PartInstance* child_part = dynamic_cast<PartInstance*>(instance);
if(child_part)
m_geom->addEntity(m_partEntity,
{
m_partEntity->setMaterial(BrickColor::material(child_part->getBrickColor()));
m_geom->addEntity(m_partEntity,
child_part->getCFrame().getPosition(),
Ogre::Quaternion(child_part->getCFrame().getRotation()),
child_part->getSize());
}
for(auto& child : *instance->getChildren())
buildGeomInstance(child);
}