Merge /u/fgarlin/simgear/ branch next into next
https://sourceforge.net/p/flightgear/simgear/merge-requests/70/
This commit is contained in:
@@ -53,9 +53,6 @@ class Technique;
|
|||||||
class Effect;
|
class Effect;
|
||||||
class SGReaderWriterOptions;
|
class SGReaderWriterOptions;
|
||||||
|
|
||||||
using namespace osg;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object to be initialized at some point after an effect -- and its
|
* Object to be initialized at some point after an effect -- and its
|
||||||
* containing effect geode -- are hooked into the scene graph. Some
|
* containing effect geode -- are hooked into the scene graph. Some
|
||||||
@@ -179,9 +176,9 @@ void mergePropertyTrees(SGPropertyNode* resultNode,
|
|||||||
|
|
||||||
class UniformFactoryImpl {
|
class UniformFactoryImpl {
|
||||||
public:
|
public:
|
||||||
ref_ptr<Uniform> getUniform( Effect * effect,
|
osg::ref_ptr<osg::Uniform> getUniform( Effect * effect,
|
||||||
const string & name,
|
const string & name,
|
||||||
Uniform::Type uniformType,
|
osg::Uniform::Type uniformType,
|
||||||
SGConstPropertyNode_ptr valProp,
|
SGConstPropertyNode_ptr valProp,
|
||||||
const SGReaderWriterOptions* options );
|
const SGReaderWriterOptions* options );
|
||||||
void updateListeners( SGPropertyNode* propRoot );
|
void updateListeners( SGPropertyNode* propRoot );
|
||||||
@@ -194,9 +191,9 @@ private:
|
|||||||
|
|
||||||
SGMutex _mutex;
|
SGMutex _mutex;
|
||||||
|
|
||||||
typedef boost::tuple<std::string, Uniform::Type, std::string, std::string> UniformCacheKey;
|
typedef boost::tuple<std::string, osg::Uniform::Type, std::string, std::string> UniformCacheKey;
|
||||||
typedef boost::tuple<ref_ptr<Uniform>, SGPropertyChangeListener*> UniformCacheValue;
|
typedef boost::tuple<osg::ref_ptr<osg::Uniform>, SGPropertyChangeListener*> UniformCacheValue;
|
||||||
std::map<UniformCacheKey,ref_ptr<Uniform> > uniformCache;
|
std::map<UniformCacheKey,osg::ref_ptr<osg::Uniform> > uniformCache;
|
||||||
|
|
||||||
typedef std::queue<DeferredPropertyListener*> DeferredListenerList;
|
typedef std::queue<DeferredPropertyListener*> DeferredListenerList;
|
||||||
DeferredListenerList deferredListenerList;
|
DeferredListenerList deferredListenerList;
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ namespace
|
|||||||
{
|
{
|
||||||
TextureBuilder::Registrar install1D("1d", new TexBuilder<Texture1D>("1d"));
|
TextureBuilder::Registrar install1D("1d", new TexBuilder<Texture1D>("1d"));
|
||||||
TextureBuilder::Registrar install2D("2d", new TexBuilder<Texture2D>("2d"));
|
TextureBuilder::Registrar install2D("2d", new TexBuilder<Texture2D>("2d"));
|
||||||
TextureBuilder::Registrar install3D("3d", new TexBuilder<Texture3D>("3d"));
|
//TextureBuilder::Registrar install3D("3d", new TexBuilder<Texture3D>("3d"));
|
||||||
}
|
}
|
||||||
|
|
||||||
class WhiteTextureBuilder : public TextureBuilder
|
class WhiteTextureBuilder : public TextureBuilder
|
||||||
@@ -776,6 +776,96 @@ namespace {
|
|||||||
TextureBuilder::Registrar installCubeMap("cubemap", new CubeMapBuilder);
|
TextureBuilder::Registrar installCubeMap("cubemap", new CubeMapBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Texture3DBuilder : public TextureBuilder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Texture* build(Effect* effect, Pass* pass, const SGPropertyNode*,
|
||||||
|
const SGReaderWriterOptions* options);
|
||||||
|
protected:
|
||||||
|
typedef map<TexTuple, observer_ptr<Texture3D> > TexMap;
|
||||||
|
TexMap texMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
Texture* Texture3DBuilder::build(Effect* effect, Pass* pass,
|
||||||
|
const SGPropertyNode* props,
|
||||||
|
const SGReaderWriterOptions* options)
|
||||||
|
{
|
||||||
|
TexTuple attrs = makeTexTuple(effect, props, options, "3d");
|
||||||
|
typename TexMap::iterator itr = texMap.find(attrs);
|
||||||
|
|
||||||
|
ref_ptr<Texture3D> tex;
|
||||||
|
if ((itr != texMap.end())&&
|
||||||
|
(itr->second.lock(tex)))
|
||||||
|
{
|
||||||
|
return tex.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
tex = new Texture3D;
|
||||||
|
|
||||||
|
const string& imageName = attrs.get<0>();
|
||||||
|
if (imageName.empty())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
osgDB::ReaderWriter::ReadResult result;
|
||||||
|
|
||||||
|
// load texture for effect
|
||||||
|
SGReaderWriterOptions::LoadOriginHint origLOH = options->getLoadOriginHint();
|
||||||
|
if(attrs.get<8>() == ImageInternalFormat::Normalized)
|
||||||
|
options->setLoadOriginHint(SGReaderWriterOptions::LoadOriginHint::ORIGIN_EFFECTS_NORMALIZED);
|
||||||
|
else
|
||||||
|
options->setLoadOriginHint(SGReaderWriterOptions::LoadOriginHint::ORIGIN_EFFECTS);
|
||||||
|
#if OSG_VERSION_LESS_THAN(3,4,2)
|
||||||
|
result = osgDB::readImageFile(imageName, options);
|
||||||
|
#else
|
||||||
|
result = osgDB::readRefImageFile(imageName, options);
|
||||||
|
#endif
|
||||||
|
options->setLoadOriginHint(origLOH);
|
||||||
|
osg::ref_ptr<osg::Image> image;
|
||||||
|
if (result.success())
|
||||||
|
image = result.getImage();
|
||||||
|
if (image.valid())
|
||||||
|
{
|
||||||
|
osg::ref_ptr<osg::Image> image3d = new osg::Image;
|
||||||
|
int size = image->t();
|
||||||
|
int depth = image->s() / image->t();
|
||||||
|
image3d->allocateImage(size, size, depth,
|
||||||
|
image->getPixelFormat(), image->getDataType());
|
||||||
|
|
||||||
|
for (int i = 0; i < depth; ++i) {
|
||||||
|
osg::ref_ptr<osg::Image> subimage = new osg::Image;
|
||||||
|
subimage->allocateImage(size, size, 1,
|
||||||
|
image->getPixelFormat(), image->getDataType());
|
||||||
|
copySubImage(image, size * i, 0, size, size, subimage.get(), 0, 0);
|
||||||
|
image3d->copySubImage(0, 0, i, subimage.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
image3d->setInternalTextureFormat(image->getInternalTextureFormat());
|
||||||
|
image3d = computeMipmap(image3d.get(), attrs.get<7>());
|
||||||
|
tex->setImage(image3d.get());
|
||||||
|
} else {
|
||||||
|
SG_LOG(SG_INPUT, SG_ALERT, "failed to load effect texture file " << imageName);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
tex->setFilter(Texture::MIN_FILTER, attrs.get<1>());
|
||||||
|
tex->setFilter(Texture::MAG_FILTER, attrs.get<2>());
|
||||||
|
tex->setWrap(Texture::WRAP_S, attrs.get<3>());
|
||||||
|
tex->setWrap(Texture::WRAP_T, attrs.get<4>());
|
||||||
|
tex->setWrap(Texture::WRAP_R, attrs.get<5>());
|
||||||
|
|
||||||
|
if (itr == texMap.end())
|
||||||
|
texMap.insert(make_pair(attrs, tex));
|
||||||
|
else
|
||||||
|
itr->second = tex; // update existing, but empty observer
|
||||||
|
return tex.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
TextureBuilder::Registrar install3D("3d", new Texture3DBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
EffectNameValue<TexEnvCombine::CombineParam> combineParamInit[] =
|
EffectNameValue<TexEnvCombine::CombineParam> combineParamInit[] =
|
||||||
{
|
{
|
||||||
{"replace", TexEnvCombine::REPLACE},
|
{"replace", TexEnvCombine::REPLACE},
|
||||||
|
|||||||
@@ -123,7 +123,11 @@ SGLight::appendLight(const SGPropertyNode *configNode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
osg::ShapeDrawable *debug_drawable = new osg::ShapeDrawable(debug_shape);
|
osg::ShapeDrawable *debug_drawable = new osg::ShapeDrawable(debug_shape);
|
||||||
debug_drawable->setColor(osg::Vec4(1.0, 0.0, 0.0, 1.0));
|
debug_drawable->setColor(
|
||||||
|
osg::Vec4(configNode->getFloatValue("debug-color/r", 1.0f),
|
||||||
|
configNode->getFloatValue("debug-color/g", 0.0f),
|
||||||
|
configNode->getFloatValue("debug-color/b", 0.0f),
|
||||||
|
configNode->getFloatValue("debug-color/a", 1.0f)));
|
||||||
osg::Geode *debug_geode = new osg::Geode;
|
osg::Geode *debug_geode = new osg::Geode;
|
||||||
debug_geode->addDrawable(debug_drawable);
|
debug_geode->addDrawable(debug_drawable);
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,20 @@
|
|||||||
#include <simgear/scene/material/EffectCullVisitor.hxx>
|
#include <simgear/scene/material/EffectCullVisitor.hxx>
|
||||||
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
|
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
|
||||||
#include <simgear/scene/util/RenderConstants.hxx>
|
#include <simgear/scene/util/RenderConstants.hxx>
|
||||||
|
#include <simgear/scene/util/SGUpdateVisitor.hxx>
|
||||||
#include <simgear/structure/exception.hxx>
|
#include <simgear/structure/exception.hxx>
|
||||||
|
|
||||||
#include "CompositorUtil.hxx"
|
#include "CompositorUtil.hxx"
|
||||||
|
|
||||||
|
|
||||||
|
class LightDirectionCallback : public osg::Uniform::Callback {
|
||||||
|
public:
|
||||||
|
virtual void operator()(osg::Uniform *uniform, osg::NodeVisitor *nv) {
|
||||||
|
SGUpdateVisitor *uv = dynamic_cast<SGUpdateVisitor *>(nv);
|
||||||
|
uniform->set(toOsg(uv->getLightDirection()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
namespace simgear {
|
namespace simgear {
|
||||||
namespace compositor {
|
namespace compositor {
|
||||||
|
|
||||||
@@ -113,10 +123,16 @@ Compositor::Compositor(osg::View *view,
|
|||||||
new osg::Uniform("fg_ViewMatrixInverse", osg::Matrixf()),
|
new osg::Uniform("fg_ViewMatrixInverse", osg::Matrixf()),
|
||||||
new osg::Uniform("fg_ProjectionMatrix", osg::Matrixf()),
|
new osg::Uniform("fg_ProjectionMatrix", osg::Matrixf()),
|
||||||
new osg::Uniform("fg_ProjectionMatrixInverse", osg::Matrixf()),
|
new osg::Uniform("fg_ProjectionMatrixInverse", osg::Matrixf()),
|
||||||
|
new osg::Uniform("fg_PrevViewMatrix", osg::Matrixf()),
|
||||||
|
new osg::Uniform("fg_PrevViewMatrixInverse", osg::Matrixf()),
|
||||||
|
new osg::Uniform("fg_PrevProjectionMatrix", osg::Matrixf()),
|
||||||
|
new osg::Uniform("fg_PrevProjectionMatrixInverse", osg::Matrixf()),
|
||||||
new osg::Uniform("fg_CameraPositionCart", osg::Vec3f()),
|
new osg::Uniform("fg_CameraPositionCart", osg::Vec3f()),
|
||||||
new osg::Uniform("fg_CameraPositionGeod", osg::Vec3f())
|
new osg::Uniform("fg_CameraPositionGeod", osg::Vec3f()),
|
||||||
|
new osg::Uniform("fg_LightDirection", osg::Vec3f())
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
_uniforms[LIGHT_DIRECTION]->setUpdateCallback(new LightDirectionCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
Compositor::~Compositor()
|
Compositor::~Compositor()
|
||||||
@@ -149,6 +165,18 @@ Compositor::update(const osg::Matrix &view_matrix,
|
|||||||
SGGeod camera_pos_geod = SGGeod::fromCart(
|
SGGeod camera_pos_geod = SGGeod::fromCart(
|
||||||
SGVec3d(camera_pos.x(), camera_pos.y(), camera_pos.z()));
|
SGVec3d(camera_pos.x(), camera_pos.y(), camera_pos.z()));
|
||||||
|
|
||||||
|
osg::Matrixf prev_view_matrix, prev_view_matrix_inv;
|
||||||
|
_uniforms[VIEW_MATRIX]->get(prev_view_matrix);
|
||||||
|
_uniforms[VIEW_MATRIX_INV]->get(prev_view_matrix_inv);
|
||||||
|
osg::Matrixf prev_proj_matrix, prev_proj_matrix_inv;
|
||||||
|
_uniforms[PROJECTION_MATRIX]->get(prev_proj_matrix);
|
||||||
|
_uniforms[PROJECTION_MATRIX_INV]->get(prev_proj_matrix_inv);
|
||||||
|
|
||||||
|
_uniforms[PREV_VIEW_MATRIX]->set(prev_view_matrix);
|
||||||
|
_uniforms[PREV_VIEW_MATRIX_INV]->set(prev_view_matrix_inv);
|
||||||
|
_uniforms[PREV_PROJECTION_MATRIX]->set(prev_proj_matrix);
|
||||||
|
_uniforms[PREV_PROJECTION_MATRIX_INV]->set(prev_proj_matrix_inv);
|
||||||
|
|
||||||
for (int i = 0; i < TOTAL_BUILTIN_UNIFORMS; ++i) {
|
for (int i = 0; i < TOTAL_BUILTIN_UNIFORMS; ++i) {
|
||||||
osg::ref_ptr<osg::Uniform> u = _uniforms[i];
|
osg::ref_ptr<osg::Uniform> u = _uniforms[i];
|
||||||
switch (i) {
|
switch (i) {
|
||||||
|
|||||||
@@ -51,8 +51,13 @@ public:
|
|||||||
VIEW_MATRIX_INV,
|
VIEW_MATRIX_INV,
|
||||||
PROJECTION_MATRIX,
|
PROJECTION_MATRIX,
|
||||||
PROJECTION_MATRIX_INV,
|
PROJECTION_MATRIX_INV,
|
||||||
|
PREV_VIEW_MATRIX,
|
||||||
|
PREV_VIEW_MATRIX_INV,
|
||||||
|
PREV_PROJECTION_MATRIX,
|
||||||
|
PREV_PROJECTION_MATRIX_INV,
|
||||||
CAMERA_POSITION_CART,
|
CAMERA_POSITION_CART,
|
||||||
CAMERA_POSITION_GEOD,
|
CAMERA_POSITION_GEOD,
|
||||||
|
LIGHT_DIRECTION,
|
||||||
TOTAL_BUILTIN_UNIFORMS
|
TOTAL_BUILTIN_UNIFORMS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ PassBuilder::build(Compositor *compositor, const SGPropertyNode *root,
|
|||||||
pass->type = root->getStringValue("type");
|
pass->type = root->getStringValue("type");
|
||||||
pass->effect_scheme = root->getStringValue("effect-scheme");
|
pass->effect_scheme = root->getStringValue("effect-scheme");
|
||||||
|
|
||||||
osg::Camera *camera = new Camera;
|
osg::Camera *camera = new osg::Camera;
|
||||||
pass->camera = camera;
|
pass->camera = camera;
|
||||||
|
|
||||||
camera->setName(pass->name);
|
camera->setName(pass->name);
|
||||||
@@ -107,8 +107,8 @@ PassBuilder::build(Compositor *compositor, const SGPropertyNode *root,
|
|||||||
camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
||||||
|
|
||||||
// XXX: Should we make this configurable?
|
// XXX: Should we make this configurable?
|
||||||
camera->setCullingMode(CullSettings::SMALL_FEATURE_CULLING
|
camera->setCullingMode(osg::CullSettings::SMALL_FEATURE_CULLING
|
||||||
| CullSettings::VIEW_FRUSTUM_CULLING);
|
| osg::CullSettings::VIEW_FRUSTUM_CULLING);
|
||||||
|
|
||||||
osg::Node::NodeMask cull_mask =
|
osg::Node::NodeMask cull_mask =
|
||||||
std::stoul(root->getStringValue("cull-mask", "0xffffffff"), nullptr, 0);
|
std::stoul(root->getStringValue("cull-mask", "0xffffffff"), nullptr, 0);
|
||||||
@@ -639,8 +639,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
// Given a projection matrix, return a new one with the same frustum
|
// Given a projection matrix, return a new one with the same frustum
|
||||||
// sides and new near / far values.
|
// sides and new near / far values.
|
||||||
void makeNewProjMat(Matrixd& oldProj, double znear,
|
void makeNewProjMat(osg::Matrixd& oldProj, double znear,
|
||||||
double zfar, Matrixd& projection) {
|
double zfar, osg::Matrixd& projection) {
|
||||||
projection = oldProj;
|
projection = oldProj;
|
||||||
// Slightly inflate the near & far planes to avoid objects at the
|
// Slightly inflate the near & far planes to avoid objects at the
|
||||||
// extremes being clipped out.
|
// extremes being clipped out.
|
||||||
|
|||||||
Reference in New Issue
Block a user