forked from mirror/openmw-tes3mp
Merge branch 'master' into terraincollision
Conflicts: apps/openmw/mwworld/scene.cppactorid
commit
c0af3c7241
@ -0,0 +1,20 @@
|
||||
set(MWINIIMPORT
|
||||
main.cpp
|
||||
importer.cpp
|
||||
)
|
||||
|
||||
set(MWINIIMPORT_HEADER
|
||||
importer.hpp
|
||||
)
|
||||
|
||||
source_group(launcher FILES ${MWINIIMPORT} ${MWINIIMPORT_HEADER})
|
||||
|
||||
add_executable(mwiniimport
|
||||
${MWINIIMPORT}
|
||||
)
|
||||
|
||||
target_link_libraries(mwiniimport
|
||||
${Boost_LIBRARIES}
|
||||
components
|
||||
)
|
||||
|
@ -0,0 +1,184 @@
|
||||
#include "importer.hpp"
|
||||
#include <boost/iostreams/device/file.hpp>
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
MwIniImporter::MwIniImporter() {
|
||||
const char *map[][2] =
|
||||
{
|
||||
{ "fps", "General:Show FPS" },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
for(int i=0; map[i][0]; i++) {
|
||||
mMergeMap.insert(std::make_pair<std::string, std::string>(map[i][0], map[i][1]));
|
||||
}
|
||||
}
|
||||
|
||||
void MwIniImporter::setVerbose(bool verbose) {
|
||||
mVerbose = verbose;
|
||||
}
|
||||
|
||||
std::string MwIniImporter::numberToString(int n) {
|
||||
std::stringstream str;
|
||||
str << n;
|
||||
return str.str();
|
||||
}
|
||||
|
||||
MwIniImporter::multistrmap MwIniImporter::loadIniFile(std::string filename) {
|
||||
std::cout << "load ini file: " << filename << std::endl;
|
||||
|
||||
std::string section("");
|
||||
MwIniImporter::multistrmap map;
|
||||
boost::iostreams::stream<boost::iostreams::file_source>file(filename.c_str());
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
|
||||
if(line[0] == '[') {
|
||||
if(line.length() > 2) {
|
||||
section = line.substr(1, line.length()-3);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
int comment_pos = line.find(";");
|
||||
if(comment_pos > 0) {
|
||||
line = line.substr(0,comment_pos);
|
||||
}
|
||||
|
||||
if(line.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int pos = line.find("=");
|
||||
if(pos < 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string key(section + ":" + line.substr(0,pos));
|
||||
std::string value(line.substr(pos+1));
|
||||
|
||||
multistrmap::iterator it;
|
||||
if((it = map.find(key)) == map.end()) {
|
||||
map.insert( std::make_pair<std::string, std::vector<std::string> > (key, std::vector<std::string>() ) );
|
||||
}
|
||||
map[key].push_back(value);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
MwIniImporter::multistrmap MwIniImporter::loadCfgFile(std::string filename) {
|
||||
std::cout << "load cfg file: " << filename << std::endl;
|
||||
|
||||
MwIniImporter::multistrmap map;
|
||||
boost::iostreams::stream<boost::iostreams::file_source>file(filename.c_str());
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
|
||||
// we cant say comment by only looking at first char anymore
|
||||
int comment_pos = line.find("#");
|
||||
if(comment_pos > 0) {
|
||||
line = line.substr(0,comment_pos);
|
||||
}
|
||||
|
||||
if(line.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int pos = line.find("=");
|
||||
if(pos < 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string key(line.substr(0,pos));
|
||||
std::string value(line.substr(pos+1));
|
||||
|
||||
multistrmap::iterator it;
|
||||
if((it = map.find(key)) == map.end()) {
|
||||
map.insert( std::make_pair<std::string, std::vector<std::string> > (key, std::vector<std::string>() ) );
|
||||
}
|
||||
map[key].push_back(value);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
void MwIniImporter::merge(multistrmap &cfg, multistrmap &ini) {
|
||||
multistrmap::iterator cfgIt;
|
||||
multistrmap::iterator iniIt;
|
||||
for(strmap::iterator it=mMergeMap.begin(); it!=mMergeMap.end(); it++) {
|
||||
if((iniIt = ini.find(it->second)) != ini.end()) {
|
||||
cfg.erase(it->first);
|
||||
if(!this->specialMerge(it->first, it->second, cfg, ini)) {
|
||||
cfg.insert(std::make_pair<std::string, std::vector<std::string> >(it->first, iniIt->second));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MwIniImporter::specialMerge(std::string cfgKey, std::string iniKey, multistrmap &cfg, multistrmap &ini) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void MwIniImporter::importGameFiles(multistrmap &cfg, multistrmap &ini) {
|
||||
std::vector<std::string> esmFiles;
|
||||
std::vector<std::string> espFiles;
|
||||
std::string baseGameFile("Game Files:GameFile");
|
||||
std::string gameFile("");
|
||||
|
||||
multistrmap::iterator it = ini.begin();
|
||||
for(int i=0; it != ini.end(); i++) {
|
||||
gameFile = baseGameFile;
|
||||
gameFile.append(this->numberToString(i));
|
||||
|
||||
it = ini.find(gameFile);
|
||||
if(it == ini.end()) {
|
||||
break;
|
||||
}
|
||||
|
||||
for(std::vector<std::string>::iterator entry = it->second.begin(); entry!=it->second.end(); entry++) {
|
||||
std::string filetype(entry->substr(entry->length()-4, 3));
|
||||
std::transform(filetype.begin(), filetype.end(), filetype.begin(), ::tolower);
|
||||
|
||||
if(filetype.compare("esm") == 0) {
|
||||
esmFiles.push_back(*entry);
|
||||
}
|
||||
else if(filetype.compare("esp") == 0) {
|
||||
espFiles.push_back(*entry);
|
||||
}
|
||||
}
|
||||
|
||||
gameFile = "";
|
||||
}
|
||||
|
||||
cfg.erase("master");
|
||||
cfg.insert( std::make_pair<std::string, std::vector<std::string> > ("master", std::vector<std::string>() ) );
|
||||
|
||||
for(std::vector<std::string>::iterator it=esmFiles.begin(); it!=esmFiles.end(); it++) {
|
||||
cfg["master"].push_back(*it);
|
||||
}
|
||||
|
||||
cfg.erase("plugin");
|
||||
cfg.insert( std::make_pair<std::string, std::vector<std::string> > ("plugin", std::vector<std::string>() ) );
|
||||
|
||||
for(std::vector<std::string>::iterator it=espFiles.begin(); it!=espFiles.end(); it++) {
|
||||
cfg["plugin"].push_back(*it);
|
||||
}
|
||||
}
|
||||
|
||||
void MwIniImporter::writeToFile(boost::iostreams::stream<boost::iostreams::file_sink> &out, multistrmap &cfg) {
|
||||
|
||||
for(multistrmap::iterator it=cfg.begin(); it != cfg.end(); it++) {
|
||||
for(std::vector<std::string>::iterator entry=it->second.begin(); entry != it->second.end(); entry++) {
|
||||
out << (it->first) << "=" << (*entry) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
#ifndef MWINIIMPORTER_IMPORTER
|
||||
#define MWINIIMPORTER_IMPORTER 1
|
||||
|
||||
#include <boost/iostreams/device/file.hpp>
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <exception>
|
||||
|
||||
class MwIniImporter {
|
||||
public:
|
||||
typedef std::map<std::string, std::string> strmap;
|
||||
typedef std::map<std::string, std::vector<std::string> > multistrmap;
|
||||
|
||||
MwIniImporter();
|
||||
void setVerbose(bool verbose);
|
||||
multistrmap loadIniFile(std::string filename);
|
||||
multistrmap loadCfgFile(std::string filename);
|
||||
void merge(multistrmap &cfg, multistrmap &ini);
|
||||
void importGameFiles(multistrmap &cfg, multistrmap &ini);
|
||||
void writeToFile(boost::iostreams::stream<boost::iostreams::file_sink> &out, multistrmap &cfg);
|
||||
|
||||
private:
|
||||
bool specialMerge(std::string cfgKey, std::string iniKey, multistrmap &cfg, multistrmap &ini);
|
||||
std::string numberToString(int n);
|
||||
bool mVerbose;
|
||||
strmap mMergeMap;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,79 @@
|
||||
#include "importer.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
bpo::options_description desc("Syntax: mwiniimporter <options>\nAllowed options");
|
||||
desc.add_options()
|
||||
("help,h", "produce help message")
|
||||
("verbose,v", "verbose output")
|
||||
("ini,i", bpo::value<std::string>(), "morrowind.ini file")
|
||||
("cfg,c", bpo::value<std::string>(), "openmw.cfg file")
|
||||
("output,o", bpo::value<std::string>()->default_value(""), "openmw.cfg file")
|
||||
("game-files,g", "import esm and esp files")
|
||||
;
|
||||
|
||||
bpo::variables_map vm;
|
||||
try {
|
||||
bpo::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
|
||||
|
||||
// parse help before calling notify because we dont want it to throw an error if help is set
|
||||
if(vm.count("help")) {
|
||||
std::cout << desc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bpo::notify(vm);
|
||||
|
||||
}
|
||||
catch(std::exception& e) {
|
||||
std::cerr << "Error:" << e.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
catch(...) {
|
||||
std::cerr << "Error" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
|
||||
std::string iniFile = vm["ini"].as<std::string>();
|
||||
std::string cfgFile = vm["cfg"].as<std::string>();
|
||||
|
||||
// if no output is given, write back to cfg file
|
||||
std::string outputFile(vm["output"].as<std::string>());
|
||||
if(vm["output"].defaulted()) {
|
||||
outputFile = vm["cfg"].as<std::string>();
|
||||
}
|
||||
|
||||
if(!boost::filesystem::exists(iniFile)) {
|
||||
std::cerr << "ini file does not exist" << std::endl;
|
||||
return -3;
|
||||
}
|
||||
if(!boost::filesystem::exists(cfgFile)) {
|
||||
std::cerr << "cfg file does not exist" << std::endl;
|
||||
return -4;
|
||||
}
|
||||
|
||||
MwIniImporter importer;
|
||||
importer.setVerbose(vm.count("verbose"));
|
||||
boost::iostreams::stream<boost::iostreams::file_sink> file(outputFile);
|
||||
|
||||
MwIniImporter::multistrmap ini = importer.loadIniFile(iniFile);
|
||||
MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile);
|
||||
|
||||
importer.merge(cfg, ini);
|
||||
|
||||
if(vm.count("game-files")) {
|
||||
importer.importGameFiles(cfg, ini);
|
||||
}
|
||||
|
||||
std::cout << "write to: " << outputFile << std::endl;
|
||||
importer.writeToFile(file, cfg);
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,302 @@
|
||||
#include "occlusionquery.hpp"
|
||||
|
||||
#include <OgreRenderSystem.h>
|
||||
#include <OgreRoot.h>
|
||||
#include <OgreBillboardSet.h>
|
||||
#include <OgreHardwareOcclusionQuery.h>
|
||||
#include <OgreEntity.h>
|
||||
#include <OgreSubEntity.h>
|
||||
|
||||
using namespace MWRender;
|
||||
using namespace Ogre;
|
||||
|
||||
OcclusionQuery::OcclusionQuery(OEngine::Render::OgreRenderer* renderer, SceneNode* sunNode) :
|
||||
mSunTotalAreaQuery(0), mSunVisibleAreaQuery(0), mSingleObjectQuery(0), mActiveQuery(0),
|
||||
mDoQuery(0), mSunVisibility(0), mQuerySingleObjectStarted(false), mTestResult(false),
|
||||
mQuerySingleObjectRequested(false), mWasVisible(false), mObjectWasVisible(false), mDoQuery2(false),
|
||||
mBBNode(0)
|
||||
{
|
||||
mRendering = renderer;
|
||||
mSunNode = sunNode;
|
||||
|
||||
try {
|
||||
RenderSystem* renderSystem = Root::getSingleton().getRenderSystem();
|
||||
|
||||
mSunTotalAreaQuery = renderSystem->createHardwareOcclusionQuery();
|
||||
mSunVisibleAreaQuery = renderSystem->createHardwareOcclusionQuery();
|
||||
mSingleObjectQuery = renderSystem->createHardwareOcclusionQuery();
|
||||
|
||||
mSupported = (mSunTotalAreaQuery != 0) && (mSunVisibleAreaQuery != 0) && (mSingleObjectQuery != 0);
|
||||
}
|
||||
catch (Ogre::Exception e)
|
||||
{
|
||||
mSupported = false;
|
||||
}
|
||||
|
||||
if (!mSupported)
|
||||
{
|
||||
std::cout << "Hardware occlusion queries not supported." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// This means that everything up to RENDER_QUEUE_MAIN can occlude the objects that are tested
|
||||
const int queue = RENDER_QUEUE_MAIN+1;
|
||||
|
||||
MaterialPtr matBase = MaterialManager::getSingleton().getByName("BaseWhiteNoLighting");
|
||||
MaterialPtr matQueryArea = matBase->clone("QueryTotalPixels");
|
||||
matQueryArea->setDepthWriteEnabled(false);
|
||||
matQueryArea->setColourWriteEnabled(false);
|
||||
matQueryArea->setDepthCheckEnabled(false); // Not occluded by objects
|
||||
MaterialPtr matQueryVisible = matBase->clone("QueryVisiblePixels");
|
||||
matQueryVisible->setDepthWriteEnabled(false);
|
||||
matQueryVisible->setColourWriteEnabled(false); // Uncomment this to visualize the occlusion query
|
||||
matQueryVisible->setDepthCheckEnabled(true); // Occluded by objects
|
||||
matQueryVisible->setCullingMode(CULL_NONE);
|
||||
matQueryVisible->setManualCullingMode(MANUAL_CULL_NONE);
|
||||
|
||||
if (sunNode)
|
||||
mBBNode = mSunNode->getParentSceneNode()->createChildSceneNode();
|
||||
|
||||
mObjectNode = mRendering->getScene()->getRootSceneNode()->createChildSceneNode();
|
||||
mBBNodeReal = mRendering->getScene()->getRootSceneNode()->createChildSceneNode();
|
||||
|
||||
mBBQueryTotal = mRendering->getScene()->createBillboardSet(1);
|
||||
mBBQueryTotal->setDefaultDimensions(150, 150);
|
||||
mBBQueryTotal->createBillboard(Vector3::ZERO);
|
||||
mBBQueryTotal->setMaterialName("QueryTotalPixels");
|
||||
mBBQueryTotal->setRenderQueueGroup(queue+1);
|
||||
mBBNodeReal->attachObject(mBBQueryTotal);
|
||||
|
||||
mBBQueryVisible = mRendering->getScene()->createBillboardSet(1);
|
||||
mBBQueryVisible->setDefaultDimensions(150, 150);
|
||||
mBBQueryVisible->createBillboard(Vector3::ZERO);
|
||||
mBBQueryVisible->setMaterialName("QueryVisiblePixels");
|
||||
mBBQueryVisible->setRenderQueueGroup(queue+1);
|
||||
mBBNodeReal->attachObject(mBBQueryVisible);
|
||||
|
||||
mBBQuerySingleObject = mRendering->getScene()->createBillboardSet(1);
|
||||
/// \todo ideally this should occupy exactly 1 pixel on the screen
|
||||
mBBQuerySingleObject->setDefaultDimensions(0.003, 0.003);
|
||||
mBBQuerySingleObject->createBillboard(Vector3::ZERO);
|
||||
mBBQuerySingleObject->setMaterialName("QueryVisiblePixels");
|
||||
mBBQuerySingleObject->setRenderQueueGroup(queue);
|
||||
mObjectNode->attachObject(mBBQuerySingleObject);
|
||||
|
||||
mRendering->getScene()->addRenderObjectListener(this);
|
||||
mRendering->getScene()->addRenderQueueListener(this);
|
||||
mDoQuery = true;
|
||||
}
|
||||
|
||||
OcclusionQuery::~OcclusionQuery()
|
||||
{
|
||||
RenderSystem* renderSystem = Root::getSingleton().getRenderSystem();
|
||||
if (mSunTotalAreaQuery) renderSystem->destroyHardwareOcclusionQuery(mSunTotalAreaQuery);
|
||||
if (mSunVisibleAreaQuery) renderSystem->destroyHardwareOcclusionQuery(mSunVisibleAreaQuery);
|
||||
if (mSingleObjectQuery) renderSystem->destroyHardwareOcclusionQuery(mSingleObjectQuery);
|
||||
}
|
||||
|
||||
bool OcclusionQuery::supported()
|
||||
{
|
||||
return mSupported;
|
||||
}
|
||||
|
||||
void OcclusionQuery::notifyRenderSingleObject(Renderable* rend, const Pass* pass, const AutoParamDataSource* source,
|
||||
const LightList* pLightList, bool suppressRenderStateChanges)
|
||||
{
|
||||
// The following code activates and deactivates the occlusion queries
|
||||
// so that the queries only include the rendering of their intended targets
|
||||
|
||||
// Close the last occlusion query
|
||||
// Each occlusion query should only last a single rendering
|
||||
if (mActiveQuery != NULL)
|
||||
{
|
||||
mActiveQuery->endOcclusionQuery();
|
||||
mActiveQuery = NULL;
|
||||
}
|
||||
|
||||
// Open a new occlusion query
|
||||
if (mDoQuery == true)
|
||||
{
|
||||
if (rend == mBBQueryTotal)
|
||||
{
|
||||
mActiveQuery = mSunTotalAreaQuery;
|
||||
mWasVisible = true;
|
||||
}
|
||||
else if (rend == mBBQueryVisible)
|
||||
{
|
||||
mActiveQuery = mSunVisibleAreaQuery;
|
||||
}
|
||||
}
|
||||
if (mDoQuery == true && rend == mBBQuerySingleObject)
|
||||
{
|
||||
mQuerySingleObjectStarted = true;
|
||||
mQuerySingleObjectRequested = false;
|
||||
mActiveQuery = mSingleObjectQuery;
|
||||
mObjectWasVisible = true;
|
||||
}
|
||||
|
||||
if (mActiveQuery != NULL)
|
||||
mActiveQuery->beginOcclusionQuery();
|
||||
}
|
||||
|
||||
void OcclusionQuery::renderQueueEnded(uint8 queueGroupId, const String& invocation, bool& repeatThisInvocation)
|
||||
{
|
||||
if (mActiveQuery != NULL)
|
||||
{
|
||||
mActiveQuery->endOcclusionQuery();
|
||||
mActiveQuery = NULL;
|
||||
}
|
||||
/**
|
||||
* for every beginOcclusionQuery(), we want a respective pullOcclusionQuery() and vice versa
|
||||
* this also means that results can be wrong at other places if we pull, but beginOcclusionQuery() was never called
|
||||
* this can happen for example if the object that is tested is outside of the view frustum
|
||||
* to prevent this, check if the queries have been performed after everything has been rendered and if not, start them manually
|
||||
*/
|
||||
if (queueGroupId == RENDER_QUEUE_SKIES_LATE)
|
||||
{
|
||||
if (mWasVisible == false && mDoQuery)
|
||||
{
|
||||
mSunTotalAreaQuery->beginOcclusionQuery();
|
||||
mSunTotalAreaQuery->endOcclusionQuery();
|
||||
mSunVisibleAreaQuery->beginOcclusionQuery();
|
||||
mSunVisibleAreaQuery->endOcclusionQuery();
|
||||
}
|
||||
if (mObjectWasVisible == false && mDoQuery)
|
||||
{
|
||||
mSingleObjectQuery->beginOcclusionQuery();
|
||||
mSingleObjectQuery->endOcclusionQuery();
|
||||
mQuerySingleObjectStarted = true;
|
||||
mQuerySingleObjectRequested = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OcclusionQuery::update(float duration)
|
||||
{
|
||||
if (!mSupported) return;
|
||||
|
||||
mWasVisible = false;
|
||||
mObjectWasVisible = false;
|
||||
|
||||
// Adjust the position of the sun billboards according to camera viewing distance
|
||||
// we need to do this to make sure that _everything_ can occlude the sun
|
||||
float dist = mRendering->getCamera()->getFarClipDistance();
|
||||
if (dist==0) dist = 10000000;
|
||||
dist -= 1000; // bias
|
||||
dist /= 1000.f;
|
||||
if (mBBNode)
|
||||
{
|
||||
mBBNode->setPosition(mSunNode->getPosition() * dist);
|
||||
mBBNode->setScale(dist, dist, dist);
|
||||
mBBNodeReal->setPosition(mBBNode->_getDerivedPosition());
|
||||
mBBNodeReal->setScale(mBBNode->getScale());
|
||||
}
|
||||
|
||||
// Stop occlusion queries until we get their information
|
||||
// (may not happen on the same frame they are requested in)
|
||||
mDoQuery = false;
|
||||
|
||||
if (!mSunTotalAreaQuery->isStillOutstanding()
|
||||
&& !mSunVisibleAreaQuery->isStillOutstanding()
|
||||
&& !mSingleObjectQuery->isStillOutstanding())
|
||||
{
|
||||
unsigned int totalPixels;
|
||||
unsigned int visiblePixels;
|
||||
|
||||
mSunTotalAreaQuery->pullOcclusionQuery(&totalPixels);
|
||||
mSunVisibleAreaQuery->pullOcclusionQuery(&visiblePixels);
|
||||
|
||||
if (totalPixels == 0)
|
||||
{
|
||||
// probably outside of the view frustum
|
||||
mSunVisibility = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
mSunVisibility = float(visiblePixels) / float(totalPixels);
|
||||
if (mSunVisibility > 1) mSunVisibility = 1;
|
||||
}
|
||||
|
||||
unsigned int result;
|
||||
|
||||
mSingleObjectQuery->pullOcclusionQuery(&result);
|
||||
|
||||
mTestResult = (result != 0);
|
||||
|
||||
mQuerySingleObjectStarted = false;
|
||||
mQuerySingleObjectRequested = false;
|
||||
|
||||
mDoQuery = true;
|
||||
}
|
||||
}
|
||||
|
||||
void OcclusionQuery::occlusionTest(const Ogre::Vector3& position, Ogre::SceneNode* object)
|
||||
{
|
||||
assert( !occlusionTestPending()
|
||||
&& "Occlusion test still pending");
|
||||
|
||||
mBBQuerySingleObject->setVisible(true);
|
||||
|
||||
mObjectNode->setPosition(position);
|
||||
// scale proportional to camera distance, in order to always give the billboard the same size in screen-space
|
||||
mObjectNode->setScale( Vector3(1,1,1)*(position - mRendering->getCamera()->getRealPosition()).length() );
|
||||
|
||||
mQuerySingleObjectRequested = true;
|
||||
}
|
||||
|
||||
bool OcclusionQuery::occlusionTestPending()
|
||||
{
|
||||
return (mQuerySingleObjectRequested || mQuerySingleObjectStarted);
|
||||
}
|
||||
|
||||
void OcclusionQuery::setSunNode(Ogre::SceneNode* node)
|
||||
{
|
||||
mSunNode = node;
|
||||
if (!mBBNode)
|
||||
mBBNode = node->getParentSceneNode()->createChildSceneNode();
|
||||
}
|
||||
|
||||
bool OcclusionQuery::getTestResult()
|
||||
{
|
||||
assert( !occlusionTestPending()
|
||||
&& "Occlusion test still pending");
|
||||
|
||||
return mTestResult;
|
||||
}
|
||||
|
||||
bool OcclusionQuery::isPotentialOccluder(Ogre::SceneNode* node)
|
||||
{
|
||||
bool result = false;
|
||||
for (unsigned int i=0; i < node->numAttachedObjects(); ++i)
|
||||
{
|
||||
MovableObject* ob = node->getAttachedObject(i);
|
||||
std::string type = ob->getMovableType();
|
||||
if (type == "Entity")
|
||||
{
|
||||
Entity* ent = static_cast<Entity*>(ob);
|
||||
for (unsigned int j=0; j < ent->getNumSubEntities(); ++j)
|
||||
{
|
||||
// if any sub entity has a material with depth write off,
|
||||
// consider the object as not an occluder
|
||||
MaterialPtr mat = ent->getSubEntity(j)->getMaterial();
|
||||
|
||||
Material::TechniqueIterator techIt = mat->getTechniqueIterator();
|
||||
while (techIt.hasMoreElements())
|
||||
{
|
||||
Technique* tech = techIt.getNext();
|
||||
Technique::PassIterator passIt = tech->getPassIterator();
|
||||
while (passIt.hasMoreElements())
|
||||
{
|
||||
Pass* pass = passIt.getNext();
|
||||
|
||||
if (pass->getDepthWriteEnabled() == false)
|
||||
return false;
|
||||
else
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
#ifndef _GAME_OCCLUSION_QUERY_H
|
||||
#define _GAME_OCCLUSION_QUERY_H
|
||||
|
||||
#include <OgreRenderObjectListener.h>
|
||||
#include <OgreRenderQueueListener.h>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class HardwareOcclusionQuery;
|
||||
class Entity;
|
||||
class SceneNode;
|
||||
}
|
||||
|
||||
#include <openengine/ogre/renderer.hpp>
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
///
|
||||
/// \brief Implements hardware occlusion queries on the GPU
|
||||
///
|
||||
class OcclusionQuery : public Ogre::RenderObjectListener, public Ogre::RenderQueueListener
|
||||
{
|
||||
public:
|
||||
OcclusionQuery(OEngine::Render::OgreRenderer*, Ogre::SceneNode* sunNode);
|
||||
~OcclusionQuery();
|
||||
|
||||
/**
|
||||
* @return true if occlusion queries are supported on the user's hardware
|
||||
*/
|
||||
bool supported();
|
||||
|
||||
/**
|
||||
* per-frame update
|
||||
*/
|
||||
void update(float duration);
|
||||
|
||||
/**
|
||||
* request occlusion test for a billboard at the given position, omitting an entity
|
||||
* @param position of the billboard in ogre coordinates
|
||||
* @param object to exclude from the occluders
|
||||
*/
|
||||
void occlusionTest(const Ogre::Vector3& position, Ogre::SceneNode* object);
|
||||
|
||||
/**
|
||||
* @return true if a request is still outstanding
|
||||
*/
|
||||
bool occlusionTestPending();
|
||||
|
||||
/**
|
||||
* Checks if the objects held by this scenenode
|
||||
* can be considered as potential occluders
|
||||
* (which might not be the case when transparency is involved)
|
||||
* @param Scene node
|
||||
*/
|
||||
bool isPotentialOccluder(Ogre::SceneNode* node);
|
||||
|
||||
/**
|
||||
* @return true if the object tested in the last request was occluded
|
||||
*/
|
||||
bool getTestResult();
|
||||
|
||||
float getSunVisibility() const {return mSunVisibility;};
|
||||
|
||||
void setSunNode(Ogre::SceneNode* node);
|
||||
|
||||
private:
|
||||
Ogre::HardwareOcclusionQuery* mSunTotalAreaQuery;
|
||||
Ogre::HardwareOcclusionQuery* mSunVisibleAreaQuery;
|
||||
Ogre::HardwareOcclusionQuery* mSingleObjectQuery;
|
||||
Ogre::HardwareOcclusionQuery* mActiveQuery;
|
||||
|
||||
Ogre::BillboardSet* mBBQueryVisible;
|
||||
Ogre::BillboardSet* mBBQueryTotal;
|
||||
Ogre::BillboardSet* mBBQuerySingleObject;
|
||||
|
||||
Ogre::SceneNode* mSunNode;
|
||||
Ogre::SceneNode* mBBNode;
|
||||
Ogre::SceneNode* mBBNodeReal;
|
||||
float mSunVisibility;
|
||||
|
||||
Ogre::SceneNode* mObjectNode;
|
||||
|
||||
bool mWasVisible;
|
||||
bool mObjectWasVisible;
|
||||
|
||||
bool mTestResult;
|
||||
|
||||
bool mSupported;
|
||||
bool mDoQuery;
|
||||
bool mDoQuery2;
|
||||
|
||||
bool mQuerySingleObjectRequested;
|
||||
bool mQuerySingleObjectStarted;
|
||||
|
||||
OEngine::Render::OgreRenderer* mRendering;
|
||||
|
||||
protected:
|
||||
virtual void notifyRenderSingleObject(Ogre::Renderable* rend, const Ogre::Pass* pass, const Ogre::AutoParamDataSource* source,
|
||||
const Ogre::LightList* pLightList, bool suppressRenderStateChanges);
|
||||
|
||||
virtual void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,95 @@
|
||||
#include "water.hpp"
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
|
||||
Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
||||
mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()),
|
||||
mIsUnderwater(false)
|
||||
{
|
||||
try
|
||||
{
|
||||
Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Water", -1);
|
||||
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false);
|
||||
} catch(...) {}
|
||||
|
||||
mTop = cell->water;
|
||||
|
||||
mIsUnderwater = false;
|
||||
|
||||
mWaterPlane = Ogre::Plane(Ogre::Vector3::UNIT_Y, 0);
|
||||
|
||||
Ogre::MeshManager::getSingleton().createPlane("water", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, mWaterPlane, CELL_SIZE*5, CELL_SIZE * 5, 10, 10, true, 1, 3,5, Ogre::Vector3::UNIT_Z);
|
||||
|
||||
mWater = mSceneManager->createEntity("water");
|
||||
|
||||
mWater->setMaterialName("Examples/Water0");
|
||||
|
||||
mWaterNode = mSceneManager->getRootSceneNode()->createChildSceneNode();
|
||||
mWaterNode->setPosition(0, mTop, 0);
|
||||
|
||||
if(!(cell->data.flags & cell->Interior))
|
||||
{
|
||||
mWaterNode->setPosition(getSceneNodeCoordinates(cell->data.gridX, cell->data.gridY));
|
||||
}
|
||||
mWaterNode->attachObject(mWater);
|
||||
}
|
||||
|
||||
|
||||
Water::~Water()
|
||||
{
|
||||
Ogre::MeshManager::getSingleton().remove("water");
|
||||
|
||||
mWaterNode->detachObject(mWater);
|
||||
mSceneManager->destroyEntity(mWater);
|
||||
mSceneManager->destroySceneNode(mWaterNode);
|
||||
|
||||
Ogre::CompositorManager::getSingleton().removeCompositorChain(mViewport);
|
||||
}
|
||||
|
||||
void Water::changeCell(const ESM::Cell* cell)
|
||||
{
|
||||
mTop = cell->water;
|
||||
|
||||
if(!(cell->data.flags & cell->Interior))
|
||||
mWaterNode->setPosition(getSceneNodeCoordinates(cell->data.gridX, cell->data.gridY));
|
||||
else
|
||||
setHeight(mTop);
|
||||
}
|
||||
|
||||
void Water::setHeight(const float height)
|
||||
{
|
||||
mTop = height;
|
||||
mWaterNode->setPosition(0, height, 0);
|
||||
}
|
||||
|
||||
void Water::toggle()
|
||||
{
|
||||
mWater->setVisible(!mWater->getVisible());
|
||||
}
|
||||
|
||||
void Water::checkUnderwater(float y)
|
||||
{
|
||||
if ((mIsUnderwater && y > mTop) || !mWater->isVisible())
|
||||
{
|
||||
try {
|
||||
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false);
|
||||
} catch(...) {}
|
||||
mIsUnderwater = false;
|
||||
}
|
||||
|
||||
if (!mIsUnderwater && y < mTop && mWater->isVisible())
|
||||
{
|
||||
try {
|
||||
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", true);
|
||||
} catch(...) {}
|
||||
mIsUnderwater = true;
|
||||
}
|
||||
}
|
||||
|
||||
Ogre::Vector3 Water::getSceneNodeCoordinates(int gridX, int gridY)
|
||||
{
|
||||
return Ogre::Vector3(gridX * CELL_SIZE + (CELL_SIZE / 2), mTop, -gridY * CELL_SIZE - (CELL_SIZE / 2));
|
||||
}
|
||||
|
||||
} // namespace
|
@ -0,0 +1,40 @@
|
||||
#ifndef GAME_MWRENDER_WATER_H
|
||||
#define GAME_MWRENDER_WATER_H
|
||||
|
||||
#include <Ogre.h>
|
||||
#include <components/esm/loadcell.hpp>
|
||||
|
||||
namespace MWRender {
|
||||
|
||||
/// Water rendering
|
||||
class Water : Ogre::RenderTargetListener, Ogre::Camera::Listener
|
||||
{
|
||||
static const int CELL_SIZE = 8192;
|
||||
Ogre::Camera *mCamera;
|
||||
Ogre::SceneManager *mSceneManager;
|
||||
Ogre::Viewport *mViewport;
|
||||
|
||||
Ogre::Plane mWaterPlane;
|
||||
Ogre::SceneNode *mWaterNode;
|
||||
Ogre::Entity *mWater;
|
||||
|
||||
bool mIsUnderwater;
|
||||
int mTop;
|
||||
|
||||
Ogre::Vector3 getSceneNodeCoordinates(int gridX, int gridY);
|
||||
|
||||
public:
|
||||
Water (Ogre::Camera *camera, const ESM::Cell* cell);
|
||||
~Water();
|
||||
|
||||
void toggle();
|
||||
|
||||
void checkUnderwater(float y);
|
||||
void changeCell(const ESM::Cell* cell);
|
||||
void setHeight(const float height);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,122 @@
|
||||
#ifdef OPENMW_USE_AUDIERE
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#include "audiere_decoder.hpp"
|
||||
|
||||
|
||||
static void fail(const std::string &msg)
|
||||
{ throw std::runtime_error("Audiere exception: "+msg); }
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
|
||||
class OgreFile : public audiere::File
|
||||
{
|
||||
Ogre::DataStreamPtr mStream;
|
||||
|
||||
ADR_METHOD(int) read(void* buffer, int size)
|
||||
{
|
||||
return mStream->read(buffer, size);
|
||||
}
|
||||
|
||||
ADR_METHOD(bool) seek(int position, SeekMode mode)
|
||||
{
|
||||
if(mode == CURRENT)
|
||||
mStream->seek(mStream->tell()+position);
|
||||
else if(mode == BEGIN)
|
||||
mStream->seek(position);
|
||||
else if(mode == END)
|
||||
mStream->seek(mStream->size()+position);
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ADR_METHOD(int) tell()
|
||||
{
|
||||
return mStream->tell();
|
||||
}
|
||||
|
||||
size_t refs;
|
||||
virtual void ref() { ++refs; }
|
||||
virtual void unref()
|
||||
{
|
||||
if(--refs == 0)
|
||||
delete this;
|
||||
}
|
||||
|
||||
public:
|
||||
OgreFile(const Ogre::DataStreamPtr &stream)
|
||||
: mStream(stream), refs(1)
|
||||
{ }
|
||||
virtual ~OgreFile() { }
|
||||
};
|
||||
|
||||
|
||||
void Audiere_Decoder::open(const std::string &fname)
|
||||
{
|
||||
close();
|
||||
|
||||
audiere::FilePtr file(new OgreFile(mResourceMgr.openResource(fname)));
|
||||
mSoundSource = audiere::OpenSampleSource(file);
|
||||
|
||||
int channels, srate;
|
||||
audiere::SampleFormat format;
|
||||
|
||||
mSoundSource->getFormat(channels, srate, format);
|
||||
if(format == audiere::SF_S16)
|
||||
mSampleType = SampleType_Int16;
|
||||
else if(format == audiere::SF_U8)
|
||||
mSampleType = SampleType_UInt8;
|
||||
else
|
||||
fail("Unsupported sample type");
|
||||
|
||||
if(channels == 1)
|
||||
mChannelConfig = ChannelConfig_Mono;
|
||||
else if(channels == 2)
|
||||
mChannelConfig = ChannelConfig_Stereo;
|
||||
else
|
||||
fail("Unsupported channel count");
|
||||
|
||||
mSampleRate = srate;
|
||||
}
|
||||
|
||||
void Audiere_Decoder::close()
|
||||
{
|
||||
mSoundSource = NULL;
|
||||
}
|
||||
|
||||
void Audiere_Decoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType *type)
|
||||
{
|
||||
*samplerate = mSampleRate;
|
||||
*chans = mChannelConfig;
|
||||
*type = mSampleType;
|
||||
}
|
||||
|
||||
size_t Audiere_Decoder::read(char *buffer, size_t bytes)
|
||||
{
|
||||
int size = bytesToFrames(bytes, mChannelConfig, mSampleType);
|
||||
size = mSoundSource->read(size, buffer);
|
||||
return framesToBytes(size, mChannelConfig, mSampleType);
|
||||
}
|
||||
|
||||
void Audiere_Decoder::rewind()
|
||||
{
|
||||
mSoundSource->reset();
|
||||
}
|
||||
|
||||
Audiere_Decoder::Audiere_Decoder()
|
||||
{
|
||||
}
|
||||
|
||||
Audiere_Decoder::~Audiere_Decoder()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,42 @@
|
||||
#ifndef GAME_SOUND_AUDIERE_DECODER_H
|
||||
#define GAME_SOUND_AUDIERE_DECODER_H
|
||||
|
||||
#include <OgreDataStream.h>
|
||||
|
||||
#include "audiere.h"
|
||||
|
||||
#include "sound_decoder.hpp"
|
||||
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
class Audiere_Decoder : public Sound_Decoder
|
||||
{
|
||||
audiere::SampleSourcePtr mSoundSource;
|
||||
int mSampleRate;
|
||||
SampleType mSampleType;
|
||||
ChannelConfig mChannelConfig;
|
||||
|
||||
virtual void open(const std::string &fname);
|
||||
virtual void close();
|
||||
|
||||
virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type);
|
||||
|
||||
virtual size_t read(char *buffer, size_t bytes);
|
||||
virtual void rewind();
|
||||
|
||||
Audiere_Decoder& operator=(const Audiere_Decoder &rhs);
|
||||
Audiere_Decoder(const Audiere_Decoder &rhs);
|
||||
|
||||
Audiere_Decoder();
|
||||
public:
|
||||
virtual ~Audiere_Decoder();
|
||||
|
||||
friend class SoundManager;
|
||||
};
|
||||
#ifndef DEFAULT_DECODER
|
||||
#define DEFAULT_DECODER (::MWSound::Audiere_Decoder)
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
@ -0,0 +1,158 @@
|
||||
#include "settings.hpp"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <OgreResourceGroupManager.h>
|
||||
#include <OgreStringConverter.h>
|
||||
|
||||
using namespace Settings;
|
||||
|
||||
Ogre::ConfigFile Manager::mFile = Ogre::ConfigFile();
|
||||
Ogre::ConfigFile Manager::mDefaultFile = Ogre::ConfigFile();
|
||||
CategorySettingVector Manager::mChangedSettings = CategorySettingVector();
|
||||
CategorySettingValueMap Manager::mNewSettings = CategorySettingValueMap();
|
||||
|
||||
void Manager::loadUser (const std::string& file)
|
||||
{
|
||||
mFile.load(file);
|
||||
}
|
||||
|
||||
void Manager::loadDefault (const std::string& file)
|
||||
{
|
||||
mDefaultFile.load(file);
|
||||
}
|
||||
|
||||
void Manager::saveUser(const std::string& file)
|
||||
{
|
||||
std::fstream fout(file.c_str(), std::ios::out);
|
||||
|
||||
Ogre::ConfigFile::SectionIterator seci = mFile.getSectionIterator();
|
||||
|
||||
while (seci.hasMoreElements())
|
||||
{
|
||||
Ogre::String sectionName = seci.peekNextKey();
|
||||
|
||||
if (sectionName.length() > 0)
|
||||
fout << '\n' << '[' << seci.peekNextKey() << ']' << '\n';
|
||||
|
||||
Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
|
||||
Ogre::ConfigFile::SettingsMultiMap::iterator i;
|
||||
for (i = settings->begin(); i != settings->end(); ++i)
|
||||
{
|
||||
fout << i->first.c_str() << " = " << i->second.c_str() << '\n';
|
||||
}
|
||||
|
||||
CategorySettingValueMap::iterator it = mNewSettings.begin();
|
||||
while (it != mNewSettings.end())
|
||||
{
|
||||
if (it->first.first == sectionName)
|
||||
{
|
||||
fout << it->first.second << " = " << it->second << '\n';
|
||||
mNewSettings.erase(it++);
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
std::string category = "";
|
||||
for (CategorySettingValueMap::iterator it = mNewSettings.begin();
|
||||
it != mNewSettings.end(); ++it)
|
||||
{
|
||||
if (category != it->first.first)
|
||||
{
|
||||
category = it->first.first;
|
||||
fout << '\n' << '[' << category << ']' << '\n';
|
||||
}
|
||||
fout << it->first.second << " = " << it->second << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
const std::string Manager::getString (const std::string& setting, const std::string& category)
|
||||
{
|
||||
if (mNewSettings.find(std::make_pair(category, setting)) != mNewSettings.end())
|
||||
return mNewSettings[std::make_pair(category, setting)];
|
||||
|
||||
std::string defaultval = mDefaultFile.getSetting(setting, category);
|
||||
return mFile.getSetting(setting, category, defaultval);
|
||||
}
|
||||
|
||||
const float Manager::getFloat (const std::string& setting, const std::string& category)
|
||||
{
|
||||
return Ogre::StringConverter::parseReal( getString(setting, category) );
|
||||
}
|
||||
|
||||
const int Manager::getInt (const std::string& setting, const std::string& category)
|
||||
{
|
||||
return Ogre::StringConverter::parseInt( getString(setting, category) );
|
||||
}
|
||||
|
||||
const bool Manager::getBool (const std::string& setting, const std::string& category)
|
||||
{
|
||||
return Ogre::StringConverter::parseBool( getString(setting, category) );
|
||||
}
|
||||
|
||||
void Manager::setString (const std::string& setting, const std::string& category, const std::string& value)
|
||||
{
|
||||
CategorySetting s = std::make_pair(category, setting);
|
||||
|
||||
bool found=false;
|
||||
try
|
||||
{
|
||||
Ogre::ConfigFile::SettingsIterator it = mFile.getSettingsIterator(category);
|
||||
while (it.hasMoreElements())
|
||||
{
|
||||
Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current();
|
||||
|
||||
if ((*i).first == setting)
|
||||
{
|
||||
if ((*i).second != value)
|
||||
{
|
||||
mChangedSettings.push_back(std::make_pair(category, setting));
|
||||
(*i).second = value;
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
|
||||
it.getNext();
|
||||
}
|
||||
}
|
||||
catch (Ogre::Exception&)
|
||||
{}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
if (mNewSettings.find(s) != mNewSettings.end())
|
||||
{
|
||||
if (mNewSettings[s] != value)
|
||||
{
|
||||
mChangedSettings.push_back(std::make_pair(category, setting));
|
||||
mNewSettings[s] = value;
|
||||
}
|
||||
}
|
||||
else
|
||||
mNewSettings[s] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void Manager::setInt (const std::string& setting, const std::string& category, const int value)
|
||||
{
|
||||
setString(setting, category, Ogre::StringConverter::toString(value));
|
||||
}
|
||||
|
||||
void Manager::setFloat (const std::string& setting, const std::string& category, const float value)
|
||||
{
|
||||
setString(setting, category, Ogre::StringConverter::toString(value));
|
||||
}
|
||||
|
||||
void Manager::setBool (const std::string& setting, const std::string& category, const bool value)
|
||||
{
|
||||
setString(setting, category, Ogre::StringConverter::toString(value));
|
||||
}
|
||||
|
||||
const CategorySettingVector Manager::apply()
|
||||
{
|
||||
CategorySettingVector vec = mChangedSettings;
|
||||
mChangedSettings.clear();
|
||||
return vec;
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
#ifndef _COMPONENTS_SETTINGS_H
|
||||
#define _COMPONENTS_SETTINGS_H
|
||||
|
||||
#include <OgreConfigFile.h>
|
||||
|
||||
namespace Settings
|
||||
{
|
||||
typedef std::pair < std::string, std::string > CategorySetting;
|
||||
typedef std::vector< std::pair<std::string, std::string> > CategorySettingVector;
|
||||
typedef std::map < CategorySetting, std::string > CategorySettingValueMap;
|
||||
|
||||
///
|
||||
/// \brief Settings management (can change during runtime)
|
||||
///
|
||||
class Manager
|
||||
{
|
||||
public:
|
||||
static Ogre::ConfigFile mFile;
|
||||
static Ogre::ConfigFile mDefaultFile;
|
||||
|
||||
static CategorySettingVector mChangedSettings;
|
||||
///< tracks all the settings that were changed since the last apply() call
|
||||
|
||||
static CategorySettingValueMap mNewSettings;
|
||||
///< tracks all the settings that are in the default file, but not in user file yet
|
||||
|
||||
void loadDefault (const std::string& file);
|
||||
///< load file as the default settings (can be overridden by user settings)
|
||||
|
||||
void loadUser (const std::string& file);
|
||||
///< load file as user settings
|
||||
|
||||
void saveUser (const std::string& file);
|
||||
///< save user settings to file
|
||||
|
||||
static const CategorySettingVector apply();
|
||||
///< returns the list of changed settings and then clears it
|
||||
|
||||
static const int getInt (const std::string& setting, const std::string& category);
|
||||
static const float getFloat (const std::string& setting, const std::string& category);
|
||||
static const std::string getString (const std::string& setting, const std::string& category);
|
||||
static const bool getBool (const std::string& setting, const std::string& category);
|
||||
|
||||
static void setInt (const std::string& setting, const std::string& category, const int value);
|
||||
static void setFloat (const std::string& setting, const std::string& category, const float value);
|
||||
static void setString (const std::string& setting, const std::string& category, const std::string& value);
|
||||
static void setBool (const std::string& setting, const std::string& category, const bool value);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // _COMPONENTS_SETTINGS_H
|
@ -0,0 +1,13 @@
|
||||
project(resources)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/caustic_0.png "${OpenMW_BINARY_DIR}/resources/water/caustic_0.png" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/Example_Fresnel.cg "${OpenMW_BINARY_DIR}/resources/water/Example_Fresnel.cg" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/Example_FresnelPS.asm "${OpenMW_BINARY_DIR}/resources/water/Example_FresnelPS.asm" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/GlassFP.cg "${OpenMW_BINARY_DIR}/resources/water/GlassFP.cg" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/GlassVP.cg "${OpenMW_BINARY_DIR}/resources/water/GlassVP.cg" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/perlinvolume.dds "${OpenMW_BINARY_DIR}/resources/water/perlinvolume.dds" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/Water02.jpg "${OpenMW_BINARY_DIR}/resources/water/Water02.jpg" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/water.compositor "${OpenMW_BINARY_DIR}/resources/water/water.compositor" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/waves2.dds "${OpenMW_BINARY_DIR}/resources/water/waves2.dds" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/Examples-Water.material "${OpenMW_BINARY_DIR}/resources/water/Examples-Water.material" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/WaterNormal1.tga "${OpenMW_BINARY_DIR}/resources/water/WaterNormal1.tga" COPYONLY)
|
Binary file not shown.
@ -0,0 +1,43 @@
|
||||
[HUD]
|
||||
|
||||
# FPS counter
|
||||
# 0: not visible
|
||||
# 1: basic FPS display
|
||||
# 2: advanced FPS display (batches, triangles)
|
||||
fps = 0
|
||||
|
||||
[Objects]
|
||||
|
||||
shaders = true
|
||||
|
||||
# Max. number of lights that affect objects. Setting to 1 will only reflect sunlight
|
||||
# Note: has no effect when shaders are turned off
|
||||
num lights = 8
|
||||
|
||||
# Use static geometry for static objects. Improves rendering speed.
|
||||
use static geometry = true
|
||||
|
||||
[Viewing distance]
|
||||
|
||||
# Limit the rendering distance of small objects
|
||||
limit small object distance = false
|
||||
|
||||
# Size below which an object is considered as small
|
||||
small object size = 250
|
||||
|
||||
# Rendering distance for small objects
|
||||
small object distance = 3500
|
||||
|
||||
# Max viewing distance at clear weather conditions
|
||||
max viewing distance = 5600
|
||||
|
||||
# Distance at which fog starts (proportional to viewing distance)
|
||||
fog start factor = 0.5
|
||||
|
||||
# Distance at which fog ends (proportional to viewing distance)
|
||||
fog end factor = 1.0
|
||||
|
||||
[Terrain]
|
||||
|
||||
# Max. number of lights that affect the terrain. Setting to 1 will only reflect sunlight
|
||||
num lights = 8
|
@ -0,0 +1,116 @@
|
||||
// Vertex program for fresnel reflections / refractions
|
||||
void main_vp(
|
||||
float4 pos : POSITION,
|
||||
float4 normal : NORMAL,
|
||||
float2 tex : TEXCOORD0,
|
||||
|
||||
out float4 oPos : POSITION,
|
||||
out float3 noiseCoord : TEXCOORD0,
|
||||
out float4 projectionCoord : TEXCOORD1,
|
||||
out float3 oEyeDir : TEXCOORD2,
|
||||
out float3 oNormal : TEXCOORD3,
|
||||
|
||||
uniform float4x4 worldViewProjMatrix,
|
||||
uniform float3 eyePosition, // object space
|
||||
uniform float timeVal,
|
||||
uniform float scale, // the amount to scale the noise texture by
|
||||
uniform float scroll, // the amount by which to scroll the noise
|
||||
uniform float noise // the noise perturb as a factor of the time
|
||||
)
|
||||
{
|
||||
oPos = mul(worldViewProjMatrix, pos);
|
||||
// Projective texture coordinates, adjust for mapping
|
||||
float4x4 scalemat = float4x4(0.5, 0, 0, 0.5,
|
||||
0,-0.5, 0, 0.5,
|
||||
0, 0, 0.5, 0.5,
|
||||
0, 0, 0, 1);
|
||||
projectionCoord = mul(scalemat, oPos);
|
||||
// Noise map coords
|
||||
noiseCoord.xy = (tex + (timeVal * scroll)) * scale;
|
||||
noiseCoord.z = noise * timeVal;
|
||||
|
||||
oEyeDir = normalize(pos.xyz - eyePosition);
|
||||
oNormal = normal.rgb;
|
||||
|
||||
}
|
||||
|
||||
// Fragment program for distorting a texture using a 3D noise texture
|
||||
void main_fp(
|
||||
float3 noiseCoord : TEXCOORD0,
|
||||
float4 projectionCoord : TEXCOORD1,
|
||||
float3 eyeDir : TEXCOORD2,
|
||||
float3 normal : TEXCOORD3,
|
||||
|
||||
out float4 col : COLOR,
|
||||
|
||||
uniform float4 tintColour,
|
||||
uniform float noiseScale,
|
||||
uniform float fresnelBias,
|
||||
uniform float fresnelScale,
|
||||
uniform float fresnelPower,
|
||||
uniform sampler2D waterTex : register(s0),
|
||||
uniform sampler2D noiseMap : register(s1),
|
||||
uniform sampler2D reflectMap : register(s2),
|
||||
uniform sampler2D refractMap : register(s3)
|
||||
)
|
||||
{
|
||||
// Do the tex projection manually so we can distort _after_
|
||||
float2 final = projectionCoord.xy / projectionCoord.w;
|
||||
|
||||
// Noise
|
||||
float3 noiseNormal = (tex2D(noiseMap, (noiseCoord.xy / 5)).rgb - 0.5).rbg * noiseScale;
|
||||
final += noiseNormal.xz;
|
||||
|
||||
// Fresnel
|
||||
//normal = normalize(normal + noiseNormal.xz);
|
||||
float fresnel = fresnelBias + fresnelScale * pow(1 + dot(eyeDir, normal), fresnelPower);
|
||||
|
||||
// Reflection / refraction
|
||||
float4 reflectionColour = tex2D(reflectMap, final);
|
||||
float4 refractionColour = tex2D(refractMap, final) + tintColour;
|
||||
|
||||
// Final colour
|
||||
col = lerp(refractionColour, reflectionColour, fresnel) * tex2D(waterTex, noiseNormal) / 3 ;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Old version to match ATI PS 1.3 implementation
|
||||
void main_vp_old(
|
||||
float4 pos : POSITION,
|
||||
float4 normal : NORMAL,
|
||||
float2 tex : TEXCOORD0,
|
||||
|
||||
out float4 oPos : POSITION,
|
||||
out float fresnel : COLOR,
|
||||
out float3 noiseCoord : TEXCOORD0,
|
||||
out float4 projectionCoord : TEXCOORD1,
|
||||
|
||||
uniform float4x4 worldViewProjMatrix,
|
||||
uniform float3 eyePosition, // object space
|
||||
uniform float fresnelBias,
|
||||
uniform float fresnelScale,
|
||||
uniform float fresnelPower,
|
||||
uniform float timeVal,
|
||||
uniform float scale, // the amount to scale the noise texture by
|
||||
uniform float scroll, // the amount by which to scroll the noise
|
||||
uniform float noise // the noise perturb as a factor of the time
|
||||
)
|
||||
{
|
||||
oPos = mul(worldViewProjMatrix, pos);
|
||||
// Projective texture coordinates, adjust for mapping
|
||||
float4x4 scalemat = float4x4(0.5, 0, 0, 0.5,
|
||||
0,-0.5, 0, 0.5,
|
||||
0, 0, 0.5, 0.5,
|
||||
0, 0, 0, 1);
|
||||
projectionCoord = mul(scalemat, oPos);
|
||||
// Noise map coords
|
||||
noiseCoord.xy = (tex + (timeVal * scroll)) * scale;
|
||||
noiseCoord.z = noise * timeVal;
|
||||
|
||||
// calc fresnel factor (reflection coefficient)
|
||||
float3 eyeDir = normalize(pos.xyz - eyePosition);
|
||||
fresnel = fresnelBias + fresnelScale * pow(1 + dot(eyeDir, normal), fresnelPower);
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
ps.1.4
|
||||
// conversion from Cg generated ARB_fragment_program to ps.1.4 by NFZ
|
||||
// command line args: -profile arbfp1 -entry main_fp
|
||||
// program main_fp
|
||||
// c0 : distortionRange
|
||||
// c1 : tintColour
|
||||
// testure 0 : noiseMap
|
||||
// texture 1 : reflectMap
|
||||
// texture 2 : refractMap
|
||||
// v0.x : fresnel
|
||||
// t0.xyz : noiseCoord
|
||||
// t1.xyw : projectionCoord
|
||||
|
||||
def c2, 2, 1, 0, 0
|
||||
|
||||
// Cg: distort.x = tex3D(noiseMap, noiseCoord).x;
|
||||
// arbfp1: TEX R0.x, fragment.texcoord[0], texture[0], 3D;
|
||||
// sample noise map using noiseCoord in TEX unit 0
|
||||
|
||||
texld r0, t0.xyz
|
||||
|
||||
// get projected texture coordinates from TEX coord 1
|
||||
// will be used in phase 2
|
||||
|
||||
texcrd r1.xy, t1_dw.xyw
|
||||
mov r1.z, c2.y
|
||||
|
||||
// Cg: distort.y = tex3D(noiseMap, noiseCoord + yoffset).x;
|
||||
// arbfp1: ADD R1.xyz, fragment.texcoord[0], c1;
|
||||
// arbfp1: TEX R1.x, R1, texture[0], 3D;
|
||||
// arbfp1: MOV R0.y, R1.x;
|
||||
|
||||
// Cg: distort = (distort * 2 - 1) * distortionRange;
|
||||
// arbfp1: MAD R0.xy, R0, c0.x, -c0.y;
|
||||
// arbfp1: MUL R0.xy, R0, u0.x;
|
||||
// (distort * 2 - 1) same as 2*(distort -.5) so use _bx2
|
||||
|
||||
|
||||
// Cg: final = projectionCoord.xy / projectionCoord.w;
|
||||
// Cg: final += distort;
|
||||
// arbfp1: RCP R0.w, fragment.texcoord[1].w;
|
||||
// arbfp1: MAD R0.xy, fragment.texcoord[1], R0.w, R0;
|
||||
// final = (distort * projectionCoord.w) + projectionCoord.xy
|
||||
// for ps.1.4 have to re-arrange things a bit to perturb projected texture coordinates
|
||||
|
||||
mad r0.xyz, r0_bx2, c0.x, r1
|
||||
|
||||
phase
|
||||
|
||||
// do dependant texture reads
|
||||
// Cg: reflectionColour = tex2D(reflectMap, final);
|
||||
// arbfp1: TEX R0, R0, texture[1], 2D;
|
||||
// sampe reflectMap using dependant read : texunit 1
|
||||
|
||||
texld r1, r0.xyz
|
||||
|
||||
// Cg: refractionColour = tex2D(refractMap, final) + tintColour;
|
||||
// arbfp1: TEX R1, R0, texture[2], 2D;
|
||||
// sample refractMap : texunit 2
|
||||
|
||||
texld r2, r0.xyz
|
||||
|
||||
// adding tintColour that is in global c1
|
||||
// arbfp1: ADD R1, R1, u1;
|
||||
|
||||
add r2, r2, c1
|
||||
|
||||
// Cg: col = lerp(refractionColour, reflectionColour, fresnel);
|
||||
// arbfp1: ADD R0, R0, -R1;
|
||||
// arbfp1: MAD result.color, fragment.color.primary.x, R0, R1;
|
||||
|
||||
lrp r0, v0.x, r1, r2
|
@ -0,0 +1,149 @@
|
||||
|
||||
vertex_program Water/GlassVP cg
|
||||
{
|
||||
source GlassVP.cg
|
||||
entry_point glass_vp
|
||||
profiles vs_1_1 arbvp1
|
||||
|
||||
default_params
|
||||
{
|
||||
param_named_auto worldViewProj worldviewproj_matrix
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fragment_program Water/GlassFP cg
|
||||
{
|
||||
source GlassFP.cg
|
||||
entry_point main_ps
|
||||
profiles ps_2_0 arbfp1
|
||||
}
|
||||
|
||||
material Water/Compositor
|
||||
{
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
depth_check off
|
||||
vertex_program_ref Water/GlassVP
|
||||
{
|
||||
param_named_auto timeVal time 0.25
|
||||
param_named scale float 0.1
|
||||
}
|
||||
|
||||
fragment_program_ref Water/GlassFP
|
||||
{
|
||||
param_named tintColour float4 0 0.35 0.35 1
|
||||
}
|
||||
|
||||
texture_unit RT
|
||||
{
|
||||
tex_coord_set 0
|
||||
tex_address_mode clamp
|
||||
filtering linear linear linear
|
||||
}
|
||||
|
||||
texture_unit
|
||||
{
|
||||
texture WaterNormal1.tga 2d
|
||||
tex_coord_set 1
|
||||
//tex_address_mode clamp
|
||||
filtering linear linear linear
|
||||
}
|
||||
texture_unit
|
||||
{
|
||||
texture caustic_0.png 2d
|
||||
tex_coord_set 2
|
||||
//tex_address_mode clamp
|
||||
filtering linear linear linear
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
vertex_program Water/RefractReflectVP cg
|
||||
{
|
||||
source Example_Fresnel.cg
|
||||
entry_point main_vp
|
||||
profiles vs_1_1 arbvp1
|
||||
}
|
||||
vertex_program Water/RefractReflectVPold cg
|
||||
{
|
||||
source Example_Fresnel.cg
|
||||
entry_point main_vp_old
|
||||
profiles vs_1_1 arbvp1
|
||||
}
|
||||
|
||||
fragment_program Water/RefractReflectFP cg
|
||||
{
|
||||
source Example_Fresnel.cg
|
||||
entry_point main_fp
|
||||
// sorry, ps_1_1 and fp20 can't do this
|
||||
profiles ps_2_0 arbfp1
|
||||
}
|
||||
|
||||
fragment_program Water/RefractReflectPS asm
|
||||
{
|
||||
source Example_FresnelPS.asm
|
||||
// sorry, only for ps_1_4 :)
|
||||
syntax ps_1_4
|
||||
|
||||
}
|
||||
material Examples/Water0
|
||||
{
|
||||
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
//
|
||||
|
||||
depth_write off
|
||||
vertex_program_ref Water/RefractReflectVP
|
||||
{
|
||||
param_named_auto worldViewProjMatrix worldviewproj_matrix
|
||||
param_named_auto eyePosition camera_position_object_space
|
||||
param_named_auto timeVal time 0.15
|
||||
param_named scroll float 1
|
||||
param_named scale float 1
|
||||
param_named noise float 1
|
||||
// scroll and noisePos will need updating per frame
|
||||
}
|
||||
fragment_program_ref Water/RefractReflectFP
|
||||
{
|
||||
param_named fresnelBias float -0.1
|
||||
param_named fresnelScale float 0.8
|
||||
param_named fresnelPower float 20
|
||||
param_named tintColour float4 1 1 1 1
|
||||
param_named noiseScale float 0.05
|
||||
}
|
||||
// Water
|
||||
scene_blend alpha_blend
|
||||
texture_unit
|
||||
{
|
||||
|
||||
// Water texture
|
||||
texture Water02.jpg
|
||||
// min / mag filtering, no mip
|
||||
filtering linear linear none
|
||||
alpha_op_ex source1 src_manual src_current 0.9
|
||||
|
||||
}
|
||||
// Noise
|
||||
texture_unit
|
||||
{
|
||||
alpha_op_ex source1 src_manual src_current 0.9
|
||||
// Perlin noise volume
|
||||
texture waves2.dds
|
||||
// min / mag filtering, no mip
|
||||
filtering linear linear none
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
sampler RT : register(s0);
|
||||
sampler NormalMap : register(s1);
|
||||
sampler CausticMap : register(s2);
|
||||
|
||||
float4 main_ps(float2 iTexCoord : TEXCOORD0,
|
||||
float3 noiseCoord : TEXCOORD1,
|
||||
uniform float4 tintColour) : COLOR
|
||||
{
|
||||
float4 normal = tex2D(NormalMap, noiseCoord);
|
||||
|
||||
|
||||
return tex2D(RT, iTexCoord + normal.xy * 0.05) +
|
||||
(tex2D(CausticMap, noiseCoord) / 5) +
|
||||
tintColour ;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
void glass_vp
|
||||
(
|
||||
in float4 inPos : POSITION,
|
||||
|
||||
out float4 pos : POSITION,
|
||||
out float2 uv0 : TEXCOORD0,
|
||||
out float4 noiseCoord : TEXCOORD1,
|
||||
|
||||
uniform float4x4 worldViewProj,
|
||||
uniform float timeVal,
|
||||
uniform float scale
|
||||
)
|
||||
{
|
||||
// Use standardise transform, so work accord with render system specific (RS depth, requires texture flipping, etc)
|
||||
pos = mul(worldViewProj, inPos);
|
||||
|
||||
// The input positions adjusted by texel offsets, so clean up inaccuracies
|
||||
inPos.xy = sign(inPos.xy);
|
||||
|
||||
// Convert to image-space
|
||||
uv0 = (float2(inPos.x, -inPos.y) + 1.0f) * 0.5f;
|
||||
noiseCoord = (pos + timeVal) * scale;
|
||||
}
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 182 KiB |
Binary file not shown.
After Width: | Height: | Size: 192 KiB |
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
Binary file not shown.
@ -0,0 +1,21 @@
|
||||
compositor Water
|
||||
{
|
||||
technique
|
||||
{
|
||||
texture rt0 target_width target_height PF_R8G8B8
|
||||
|
||||
target rt0 { input previous }
|
||||
|
||||
target_output
|
||||
{
|
||||
// Start with clear output
|
||||
input none
|
||||
|
||||
pass render_quad
|
||||
{
|
||||
material Water/Compositor
|
||||
input 0 rt0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue