OSG_GRAPH: ongoing process to support several EM methods

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5663 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: eb87263e15842bf04a6ad6737e3e5a5b13119002
Former-commit-id: a33966c6f090115fd54a4b65a3d725034f556f76
This commit is contained in:
rvlander 2013-08-08 10:24:26 +00:00
parent e5bc378ad5
commit 3734c903cd
8 changed files with 89 additions and 45 deletions

View file

@ -41,6 +41,8 @@
#include "OsgSky/OsgSky.h" #include "OsgSky/OsgSky.h"
#include "OsgFX/OsgShader.h"
#include "OsgFX/OsgReflectionMapping.h"
@ -220,17 +222,33 @@ osg::Node *SDCar::loadCar(tCarElt *car)
// car_root->setNodeMask(1); // car_root->setNodeMask(1);
this->shader = new SDCarShader(pCar.get()); this->shader = new SDCarShader(pCar.get(),this);
this->reflectionMappingMethod = REFLECTIONMAPPING_STATIC;
this->reflectionMapping = new SDReflectionMapping(car); this->reflectionMapping = new SDReflectionMapping(this);
// this->setReflectionMap(reflectionMapping->getReflectionMap()); // this->setReflectionMap(reflectionMapping->getReflectionMap());
return this->car_root; return this->car_root;
} }
bool SDCar::isCar(tCarElt*c){
return c==car;
}
SDReflectionMapping * SDCar::getReflectionMap(){
return reflectionMapping;
}
int SDCar::getReflectionMappingMethod(){
return reflectionMappingMethod;
}
tCarElt * SDCar::getCar(){
return car;
}
#define GR_SHADOW_POINTS 6 #define GR_SHADOW_POINTS 6
#define MULT 1.1 #define MULT 1.1
osg::ref_ptr<osg::Node> SDCar::initOcclusionQuad(tCarElt *car){ osg::ref_ptr<osg::Node> SDCar::initOcclusionQuad(tCarElt *car){
@ -371,7 +389,7 @@ void SDCar::updateShadingParameters(osg::Matrixf modelview){
shader->update(modelview); shader->update(modelview);
} }
void SDCar::setReflectionMap(osg::ref_ptr<osg::TextureCubeMap> map){ void SDCar::setReflectionMap(osg::ref_ptr<osg::Texture> map){
car_branch->getOrCreateStateSet()->setTextureAttributeAndModes(2,map,osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); car_branch->getOrCreateStateSet()->setTextureAttributeAndModes(2,map,osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
} }

View file

@ -27,8 +27,9 @@
#include <osg/TextureCubeMap> #include <osg/TextureCubeMap>
#include "OsgWheel.h" #include "OsgWheel.h"
#include "OsgFX/OsgShader.h"
#include "OsgFX/OsgReflectionMapping.h" class SDCarShader;
class SDReflectionMapping;
class SDCar class SDCar
{ {
@ -41,22 +42,24 @@ class SDCar
SDReflectionMapping * reflectionMapping; SDReflectionMapping * reflectionMapping;
osg::ref_ptr<osg::Vec3Array> shadowVertices; osg::ref_ptr<osg::Vec3Array> shadowVertices;
osg::ref_ptr<osg::Geometry> quad; osg::ref_ptr<osg::Geometry> quad;
int reflectionMappingMethod;
//osg::ref_ptr<osg::MatrixTransform> wheels[4]; //osg::ref_ptr<osg::MatrixTransform> wheels[4];
//osg::ref_ptr<osg::MatrixTransform> initWheel(int wheelIndec, const char *wheel_mod_name); //osg::ref_ptr<osg::MatrixTransform> initWheel(int wheelIndec, const char *wheel_mod_name);
osg::ref_ptr<osg::Node> initOcclusionQuad(tCarElt *car); osg::ref_ptr<osg::Node> initOcclusionQuad(tCarElt *car);
void setReflectionMap(osg::ref_ptr<osg::TextureCubeMap> map); void setReflectionMap(osg::ref_ptr<osg::Texture> map);
public : public :
osg::Node *loadCar(tCarElt *car); osg::Node *loadCar(tCarElt *car);
void deactivateCar(tCarElt*car); void deactivateCar(tCarElt*car);
inline bool isCar(tCarElt*c){ bool isCar(tCarElt*c);
return c==car; SDReflectionMapping * getReflectionMap();
}
inline SDReflectionMapping * getReflectionMap(){ int getReflectionMappingMethod();
return reflectionMapping;
} tCarElt * getCar();
void activateCar(tCarElt*car); void activateCar(tCarElt*car);
void updateCar(); void updateCar();

View file

@ -23,12 +23,15 @@
#include "OsgView/OsgScreens.h" #include "OsgView/OsgScreens.h"
#include "OsgReflectionMapping.h"
#include "OsgCar/OsgCar.h" #include "OsgCar/OsgCar.h"
#include "OsgRender.h" #include "OsgRender.h"
#include "OsgMain.h" #include "OsgMain.h"
#include "OsgReflectionMapping.h"
#include <car.h> #include <car.h>
@ -77,13 +80,16 @@ CameraPreCallback * pre_cam = new CameraPreCallback;
CameraPostCallback * post_cam = new CameraPostCallback; CameraPostCallback * post_cam = new CameraPostCallback;
SDReflectionMapping::SDReflectionMapping(tCarElt *c):car(c){ SDReflectionMapping::SDReflectionMapping(SDCar *c):car(c){
SDRender * render = (SDRender *)getRender(); SDRender * render = (SDRender *)getRender();
osg::ref_ptr<osg::Node> m_sceneroot = render->getRoot(); osg::ref_ptr<osg::Node> m_sceneroot = render->getRoot();
osg::ref_ptr<osg::TextureCubeMap> reflectionMap;
reflectionMap = new osg::TextureCubeMap; reflectionMap = new osg::TextureCubeMap;
this->reflectionMap =reflectionMap;
reflectionMap->setTextureSize( 256, 256 ); reflectionMap->setTextureSize( 256, 256 );
reflectionMap->setInternalFormat( GL_RGB); reflectionMap->setInternalFormat( GL_RGB);
reflectionMap->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); reflectionMap->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
@ -135,17 +141,19 @@ SDReflectionMapping::SDReflectionMapping(tCarElt *c):car(c){
void SDReflectionMapping::update(){ void SDReflectionMapping::update(){
//TODO support for multi screen
SDScreens * screens = (SDScreens*)getScreens(); SDScreens * screens = (SDScreens*)getScreens();
osg::Camera * viewCam = screens->getActiveView()->getOsgCam(); osg::Camera * viewCam = screens->getActiveView()->getOsgCam();
tCarElt * car = this->car->getCar();
pre_cam->setCar(car); pre_cam->setCar(car);
post_cam->setCar(car); post_cam->setCar(car);
sgVec3 P, p; sgVec3 p;
osg::Vec3 eye,center,up; osg::Vec3 eye,center,up;
float offset = 0;
p[0] = car->_drvPos_x; p[0] = car->_drvPos_x;
p[1] = car->_bonnetPos_y; p[1] = car->_bonnetPos_y;
p[2] = car->_drvPos_z; p[2] = car->_drvPos_z;

View file

@ -24,22 +24,29 @@
#include <car.h> #include <car.h>
#define REFLECTIONMAPPING_OFF 0
#define REFLECTIONMAPPING_STATIC 1
#define REFLECTIONMAPPING_HYBRID 2
#define REFLECTIONMAPPING_DYNAMIC 3
class SDCar;
class SDReflectionMapping class SDReflectionMapping
{ {
private: private:
osg::ref_ptr<osg::Group> camerasRoot; osg::ref_ptr<osg::Group> camerasRoot;
std::vector< osg::ref_ptr<osg::Camera> > cameras; std::vector< osg::ref_ptr<osg::Camera> > cameras;
osg::ref_ptr<osg::TextureCubeMap> reflectionMap; osg::ref_ptr<osg::Texture> reflectionMap;
tCarElt * car; SDCar *car;
inline osg::ref_ptr<osg::Group> getCamerasRoot(){ inline osg::ref_ptr<osg::Group> getCamerasRoot(){
return camerasRoot; return camerasRoot;
} }
public: public:
SDReflectionMapping(tCarElt *c); SDReflectionMapping(SDCar *c);
~SDReflectionMapping(); ~SDReflectionMapping();
inline osg::ref_ptr<osg::TextureCubeMap> getReflectionMap(){ inline osg::ref_ptr<osg::Texture> getReflectionMap(){
return reflectionMap; return reflectionMap;
} }

View file

@ -25,9 +25,10 @@
#include "OsgMain.h" #include "OsgMain.h"
#include "OsgShader.h" #include "OsgShader.h"
#include "OsgCar/OsgCar.h"
#include "OsgSky/OsgSky.h" #include "OsgSky/OsgSky.h"
SDCarShader::SDCarShader(osg::Node *car){ SDCarShader::SDCarShader(osg::Node *car, SDCar *c){
std::string TmpPath = GetDataDir(); std::string TmpPath = GetDataDir();
osg::ref_ptr<osg::Shader> vertShader = osg::ref_ptr<osg::Shader> vertShader =
@ -41,26 +42,30 @@ SDCarShader::SDCarShader(osg::Node *car){
program->addShader( fragShader.get() ); program->addShader( fragShader.get() );
pCar= car; pCar= car;
this->pSdCar = c;
stateset = pCar->getOrCreateStateSet(); stateset = pCar->getOrCreateStateSet();
stateset->setAttributeAndModes(program); stateset->setAttributeAndModes(program);
diffuseMap = new osg::Uniform("diffusemap", 0 ); diffuseMap = new osg::Uniform("diffusemap", 0 );
stateset->addUniform(diffuseMap); stateset->addUniform(diffuseMap);
reflectionMap = new osg::Uniform("reflectionmap", 2 );
stateset->addUniform(reflectionMap);
specularColor = new osg::Uniform("specularColor", osg::Vec4(0.8f,0.8f,0.8f,1.0f)); specularColor = new osg::Uniform("specularColor", osg::Vec4(0.8f,0.8f,0.8f,1.0f));
stateset->addUniform(specularColor); stateset->addUniform(specularColor);
/*lightVector = new osg::Uniform("lightvector",osg::Vec3());
stateset->addUniform(lightVector);
lightPower = new osg::Uniform("lightpower",osg::Vec4());
stateset->addUniform(lightPower);
ambientColor =new osg::Uniform("ambientColor",osg::Vec4());
stateset->addUniform(ambientColor);*/
lightVector = stateset->getOrCreateUniform("lightvector",osg::Uniform::FLOAT_VEC3); lightVector = stateset->getOrCreateUniform("lightvector",osg::Uniform::FLOAT_VEC3);
lightPower = stateset->getOrCreateUniform("lightpower",osg::Uniform::FLOAT_VEC4); lightPower = stateset->getOrCreateUniform("lightpower",osg::Uniform::FLOAT_VEC4);
ambientColor = stateset->getOrCreateUniform("ambientColor",osg::Uniform::FLOAT_VEC4); ambientColor = stateset->getOrCreateUniform("ambientColor",osg::Uniform::FLOAT_VEC4);
shininess = new osg::Uniform("smoothness", 300.0f); shininess = new osg::Uniform("smoothness", 300.0f);
stateset->addUniform(shininess); stateset->addUniform(shininess);
reflectionMappingMethod = new osg::Uniform("reflectionMappingMethod",pSdCar->getReflectionMappingMethod());
reflectionMapCube = new osg::Uniform("reflectionMapCube", 2 );
reflectionMap2DSampler = new osg::Uniform("reflectionMap2DSampler", 2 );
reflectionMapStaticOffsetCoords = stateset->getOrCreateUniform("reflectionMapStaticOffsetCoords",osg::Uniform::FLOAT_VEC3);
stateset->addUniform(reflectionMappingMethod);
stateset->addUniform(reflectionMap2DSampler);
stateset->addUniform(reflectionMapCube);
} }
void SDCarShader::update(osg::Matrixf view){ void SDCarShader::update(osg::Matrixf view){

View file

@ -16,23 +16,37 @@
* * * *
***************************************************************************/ ***************************************************************************/
#ifndef _OSGSHADERS_H_
#define _OSGSHADERS_H_
class SDCar;
class SDCarShader{ class SDCarShader{
private : private :
SDCar * pSdCar;
osg::ref_ptr<osg::Program> program ; osg::ref_ptr<osg::Program> program ;
osg::ref_ptr<osg::Node> pCar; osg::ref_ptr<osg::Node> pCar;
osg::ref_ptr<osg::StateSet> stateset; osg::ref_ptr<osg::StateSet> stateset;
osg::ref_ptr<osg::Uniform> diffuseMap; osg::ref_ptr<osg::Uniform> diffuseMap;
osg::ref_ptr<osg::Uniform> reflectionMap;
osg::ref_ptr<osg::Uniform> specularColor; osg::ref_ptr<osg::Uniform> specularColor;
osg::ref_ptr<osg::Uniform> lightVector; osg::ref_ptr<osg::Uniform> lightVector;
osg::ref_ptr<osg::Uniform> lightPower; osg::ref_ptr<osg::Uniform> lightPower;
osg::ref_ptr<osg::Uniform> ambientColor; osg::ref_ptr<osg::Uniform> ambientColor;
osg::ref_ptr<osg::Uniform> shininess; osg::ref_ptr<osg::Uniform> shininess;
osg::ref_ptr<osg::Uniform> reflectionMappingMethod;
osg::ref_ptr<osg::Uniform> reflectionMapCube;
osg::ref_ptr<osg::Uniform> reflectionMap2DSampler;
osg::ref_ptr<osg::Uniform> reflectionMapStaticOffsetCoords;
public : public :
SDCarShader(osg::Node *car); SDCarShader(osg::Node *car, SDCar *c);
void update(osg::Matrixf view); void update(osg::Matrixf view);
}; };
#endif //_OSGSHADERS_H_

View file

@ -49,21 +49,11 @@ SDDebugHUD::SDDebugHUD(){
HUD_camera->setNodeMask(0); HUD_camera->setNodeMask(0);
} }
void SDDebugHUD::setTexture(osg::ref_ptr<osg::Texture2D> map){ void SDDebugHUD::setTexture(osg::ref_ptr<osg::Texture> map){
osg::StateSet* stateset = HUD_camera->getOrCreateStateSet(); osg::StateSet* stateset = HUD_camera->getOrCreateStateSet();
stateset->setTextureAttributeAndModes( 0,map); stateset->setTextureAttributeAndModes( 0,map);
} }
void SDDebugHUD::setTexture(osg::ref_ptr<osg::TextureCubeMap> map){
osg::StateSet* stateset = HUD_camera->getOrCreateStateSet();
/* osg::ref_ptr<osg::Texture2D> lm = new osg::Texture2D;
lm->setTextureSize( 256, 256 );
lm->setInternalFormat( GL_RGB );
lm->setDataVariance(osg::Object::DYNAMIC);
lm->setImage(map->getImage(3));*/
stateset->setTextureAttributeAndModes( 0,map);
}
void SDDebugHUD::toggleHUD(){ void SDDebugHUD::toggleHUD(){
HUD_camera->setNodeMask(1-HUD_camera->getNodeMask()); HUD_camera->setNodeMask(1-HUD_camera->getNodeMask());
} }

View file

@ -27,8 +27,7 @@ class SDDebugHUD
public: public:
void toggleHUD(); void toggleHUD();
void setTexture(osg::ref_ptr<osg::TextureCubeMap> map); void setTexture(osg::ref_ptr<osg::Texture> map);
void setTexture(osg::ref_ptr<osg::Texture2D> map);
SDDebugHUD(); SDDebugHUD();
~SDDebugHUD(); ~SDDebugHUD();