Skip to content

Commit

Permalink
Merge pull request Revolutionary-Games#728 from ShimmyShaman/amdfix
Browse files Browse the repository at this point in the history
Fixes issue Revolutionary-Games#723 Invisible compound clouds (for AMD graphics).
  • Loading branch information
hhyyrylainen authored Feb 9, 2019
2 parents 6879a61 + 6c3e4cf commit 4b5c74d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
65 changes: 40 additions & 25 deletions src/microbe_stage/compound_cloud_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <OgrePlane.h>
#include <OgreRoot.h>
#include <OgreSceneManager.h>
#include <OgreSubMesh2.h>
#include <OgreTechnique.h>
#include <OgreTextureManager.h>
#include <Utility/Random.h>
Expand Down Expand Up @@ -324,34 +325,53 @@ void
if(!Ogre::Root::getSingletonPtr())
return;

// Create a background plane on which the fluid clouds will be drawn.
Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 1.0);
// Ogre::Plane plane(1, 1, 1, 1);

const auto meshName =
"CompoundCloudSystem_Plane_" + std::to_string(++CloudMeshNumberCounter);

const auto mesh =
Ogre::v1::MeshManager::getSingleton().createPlane(meshName + "_v1",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
CLOUD_X_EXTENT, CLOUD_Y_EXTENT, 1, 1,
// Normals. These are required for import to V2 to work
true, 1, 1.0f, 1.0f, Ogre::Vector3::UNIT_X,
Ogre::v1::HardwareBuffer::HBU_STATIC_WRITE_ONLY,
Ogre::v1::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false, false);

// Create a background plane on which the fluid clouds will be drawn.
m_planeMesh = Ogre::MeshManager::getSingleton().createManual(
meshName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

// Fourth true is qtangent encoding which is not needed if we don't do
// normal mapping
m_planeMesh->importV1(mesh.get(), true, true, true);
Ogre::SubMesh* planeSubMesh = m_planeMesh->createSubMesh();

Ogre::VaoManager* myVaoManager =
Ogre::Root::getSingleton().getRenderSystem()->getVaoManager();

Ogre::VertexElement2Vec myVertexElements;
myVertexElements.push_back(
Ogre::VertexElement2(Ogre::VET_FLOAT3, Ogre::VES_POSITION));
myVertexElements.push_back(
Ogre::VertexElement2(Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES));


Ogre::v1::MeshManager::getSingleton().remove(mesh);
// Simple square plane with 4 vertices & 2 primitive triangles.
CloudPlaneVertex meshVertices[] = {
{Ogre::Vector3(-CLOUD_WIDTH, 0, -CLOUD_HEIGHT), Ogre::Vector2(0, 0)},
{Ogre::Vector3(-CLOUD_WIDTH, 0, CLOUD_HEIGHT), Ogre::Vector2(0, 1)},
{Ogre::Vector3(CLOUD_WIDTH, 0, CLOUD_HEIGHT), Ogre::Vector2(1, 1)},
{Ogre::Vector3(CLOUD_WIDTH, 0, -CLOUD_HEIGHT), Ogre::Vector2(1, 0)}};

// This crashes when used with RenderDoc and doesn't render anything
// m_planeMesh = Leviathan::GeometryHelpers::CreateXZPlane(
// meshName, CLOUD_WIDTH, CLOUD_HEIGHT);
Ogre::VertexBufferPacked* myVertexBuffer = myVaoManager->createVertexBuffer(
myVertexElements, sizeof(meshVertices) / sizeof(CloudPlaneVertex),
Ogre::BT_IMMUTABLE, meshVertices, false);

Ogre::VertexBufferPackedVec myVertexBuffers;
myVertexBuffers.push_back(myVertexBuffer);

uint16_t myIndices[] = {2, 0, 1, 0, 2, 3};

Ogre::IndexBufferPacked* myIndexBuffer = myVaoManager->createIndexBuffer(
Ogre::IndexBufferPacked::IT_16BIT, sizeof(myIndices) / sizeof(uint16_t),
Ogre::BT_IMMUTABLE, myIndices, false);

Ogre::VertexArrayObject* myVao = myVaoManager->createVertexArrayObject(
myVertexBuffers, myIndexBuffer, Ogre::OT_TRIANGLE_LIST);

planeSubMesh->mVao[Ogre::VpNormal].push_back(myVao);

// Set the bounds to get frustum culling and LOD to work correctly.
m_planeMesh->_setBounds(Ogre::Aabb(Ogre::Vector3::ZERO,
Ogre::Vector3(CLOUD_WIDTH, CLOUD_Y_COORDINATE, CLOUD_HEIGHT)));

// Need to edit the render queue (for when the item is created)
world.GetScene()->getRenderQueue()->setRenderQueueMode(
Expand Down Expand Up @@ -911,11 +931,6 @@ void
cloud.m_sceneNode->setPosition(
cloud.m_position.X, CLOUD_Y_COORDINATE, cloud.m_position.Z);

// Because of the way Ogre generates the UVs for a plane we need to rotate
// the plane to match up with world coordinates
cloud.m_sceneNode->setOrientation(
Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3::UNIT_Y));

// Create a modified material that uses
cloud.m_planeMaterial = Ogre::MaterialManager::getSingleton().create(
cloud.m_textureName + "_material", "Generated");
Expand Down
6 changes: 6 additions & 0 deletions src/microbe_stage/compound_cloud_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <Entities/System.h>

#include <OgreMesh.h>
#include <OgreVector2.h>

#include <vector>

Expand Down Expand Up @@ -339,6 +340,11 @@ class CompoundCloudComponent : public Leviathan::Component {
class CompoundCloudSystem {
friend CompoundCloudComponent;

struct CloudPlaneVertex {
Ogre::Vector3 m_pos;
Ogre::Vector2 m_uv;
};

public:
/**
* @brief Constructor
Expand Down

0 comments on commit 4b5c74d

Please sign in to comment.