OpenSceneGraph/examples/osgdeferred/osgdeferred.h
Christian Buchner 2ef6909d9b I am hereby submitting a deferred rendering code sample, originally written by Michael Kapelko in 2013. I am submitting this code with his approval.
Deferred rendering is now the de-facto standard rendering technique in many modern game engines, hence I think it is important to have this technique demonstrated in an osg code example.

This particular sample adds soft shadows as well as bump mapping into the rendering pipeline. The image files whitemetal_diffuse.jpg and whitemetal_normal.jpg from OpenSceneGraph-Data images folder are required (The OSG_FILE_PATH environment variable must be set correctly)

Two additional osgt models are included with the demo (best to also put them into OpenSceneGraph-Data, I think.

The shaders are currently defined in separate .frag and .vert files.
2016-05-19 17:20:29 +01:00

67 lines
2.2 KiB
C++

#include <osg/Camera>
#include <osg/Group>
#include <osg/MatrixTransform>
#include <osg/Texture2D>
#include <osg/TextureRectangle>
#include <osgShadow/ShadowedScene>
struct Pipeline
{
int textureSize;
osg::ref_ptr<osg::Group> graph;
osg::Texture *pass1Shadows;
osg::Texture *pass2Colors;
osg::Texture *pass2Normals;
osg::Texture *pass2Positions;
osg::Texture *pass3Final;
};
osg::TextureRectangle *createFloatTextureRectangle();
osg::Camera *createHUDCamera(double left = 0,
double right = 1,
double bottom = 0,
double top = 1);
osg::ref_ptr<osg::LightSource> createLight(const osg::Vec3 &pos);
Pipeline createPipelineEffectCompositor(
osg::ref_ptr<osg::Group> scene,
osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene,
const osg::Vec3 lightPos);
Pipeline createPipelinePlainOSG(
osg::ref_ptr<osg::Group> scene,
osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene,
const osg::Vec3 lightPos);
osg::Camera *createRTTCamera(osg::Camera::BufferComponent buffer,
osg::Texture *tex,
bool isAbsolute = false);
osg::ref_ptr<osg::Group> createSceneRoom();
osg::Geode *createScreenQuad(float width,
float height,
float scale = 1,
osg::Vec3 corner = osg::Vec3());
osg::Texture2D *createTexture(const std::string &fileName);
osg::ref_ptr<osg::Camera> createTextureDisplayQuad(const osg::Vec3 &pos,
osg::StateAttribute *tex,
float scale,
float width = 0.3,
float height = 0.2);
void setAnimationPath(osg::ref_ptr<osg::MatrixTransform> node,
const osg::Vec3 &center,
float time,
float radius);
osg::ref_ptr<osg::StateSet> setShaderProgram(osg::ref_ptr<osg::Camera> pass,
const std::string& vert,
const std::string& frag);