forked from speed-dreams/speed-dreams-code
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:
parent
e5bc378ad5
commit
3734c903cd
8 changed files with 89 additions and 45 deletions
|
@ -41,6 +41,8 @@
|
|||
#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);
|
||||
|
||||
|
||||
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());
|
||||
|
||||
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 MULT 1.1
|
||||
osg::ref_ptr<osg::Node> SDCar::initOcclusionQuad(tCarElt *car){
|
||||
|
@ -371,7 +389,7 @@ void SDCar::updateShadingParameters(osg::Matrixf 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,9 @@
|
|||
#include <osg/TextureCubeMap>
|
||||
|
||||
#include "OsgWheel.h"
|
||||
#include "OsgFX/OsgShader.h"
|
||||
#include "OsgFX/OsgReflectionMapping.h"
|
||||
|
||||
class SDCarShader;
|
||||
class SDReflectionMapping;
|
||||
|
||||
class SDCar
|
||||
{
|
||||
|
@ -41,22 +42,24 @@ class SDCar
|
|||
SDReflectionMapping * reflectionMapping;
|
||||
osg::ref_ptr<osg::Vec3Array> shadowVertices;
|
||||
osg::ref_ptr<osg::Geometry> quad;
|
||||
int reflectionMappingMethod;
|
||||
//osg::ref_ptr<osg::MatrixTransform> wheels[4];
|
||||
//osg::ref_ptr<osg::MatrixTransform> initWheel(int wheelIndec, const char *wheel_mod_name);
|
||||
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 :
|
||||
osg::Node *loadCar(tCarElt *car);
|
||||
void deactivateCar(tCarElt*car);
|
||||
inline bool isCar(tCarElt*c){
|
||||
return c==car;
|
||||
}
|
||||
inline SDReflectionMapping * getReflectionMap(){
|
||||
return reflectionMapping;
|
||||
}
|
||||
bool isCar(tCarElt*c);
|
||||
SDReflectionMapping * getReflectionMap();
|
||||
|
||||
int getReflectionMappingMethod();
|
||||
|
||||
tCarElt * getCar();
|
||||
|
||||
|
||||
void activateCar(tCarElt*car);
|
||||
void updateCar();
|
||||
|
|
|
@ -23,12 +23,15 @@
|
|||
|
||||
#include "OsgView/OsgScreens.h"
|
||||
|
||||
#include "OsgReflectionMapping.h"
|
||||
|
||||
|
||||
#include "OsgCar/OsgCar.h"
|
||||
#include "OsgRender.h"
|
||||
#include "OsgMain.h"
|
||||
|
||||
|
||||
#include "OsgReflectionMapping.h"
|
||||
|
||||
#include <car.h>
|
||||
|
||||
|
||||
|
@ -77,13 +80,16 @@ CameraPreCallback * pre_cam = new CameraPreCallback;
|
|||
CameraPostCallback * post_cam = new CameraPostCallback;
|
||||
|
||||
|
||||
SDReflectionMapping::SDReflectionMapping(tCarElt *c):car(c){
|
||||
SDReflectionMapping::SDReflectionMapping(SDCar *c):car(c){
|
||||
|
||||
SDRender * render = (SDRender *)getRender();
|
||||
osg::ref_ptr<osg::Node> m_sceneroot = render->getRoot();
|
||||
|
||||
|
||||
osg::ref_ptr<osg::TextureCubeMap> reflectionMap;
|
||||
|
||||
reflectionMap = new osg::TextureCubeMap;
|
||||
this->reflectionMap =reflectionMap;
|
||||
reflectionMap->setTextureSize( 256, 256 );
|
||||
reflectionMap->setInternalFormat( GL_RGB);
|
||||
reflectionMap->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
||||
|
@ -135,17 +141,19 @@ SDReflectionMapping::SDReflectionMapping(tCarElt *c):car(c){
|
|||
|
||||
void SDReflectionMapping::update(){
|
||||
|
||||
//TODO support for multi screen
|
||||
|
||||
SDScreens * screens = (SDScreens*)getScreens();
|
||||
osg::Camera * viewCam = screens->getActiveView()->getOsgCam();
|
||||
|
||||
tCarElt * car = this->car->getCar();
|
||||
|
||||
pre_cam->setCar(car);
|
||||
post_cam->setCar(car);
|
||||
|
||||
sgVec3 P, p;
|
||||
sgVec3 p;
|
||||
osg::Vec3 eye,center,up;
|
||||
|
||||
float offset = 0;
|
||||
|
||||
p[0] = car->_drvPos_x;
|
||||
p[1] = car->_bonnetPos_y;
|
||||
p[2] = car->_drvPos_z;
|
||||
|
|
|
@ -24,22 +24,29 @@
|
|||
|
||||
#include <car.h>
|
||||
|
||||
#define REFLECTIONMAPPING_OFF 0
|
||||
#define REFLECTIONMAPPING_STATIC 1
|
||||
#define REFLECTIONMAPPING_HYBRID 2
|
||||
#define REFLECTIONMAPPING_DYNAMIC 3
|
||||
|
||||
class SDCar;
|
||||
|
||||
class SDReflectionMapping
|
||||
{
|
||||
private:
|
||||
osg::ref_ptr<osg::Group> camerasRoot;
|
||||
std::vector< osg::ref_ptr<osg::Camera> > cameras;
|
||||
osg::ref_ptr<osg::TextureCubeMap> reflectionMap;
|
||||
tCarElt * car;
|
||||
osg::ref_ptr<osg::Texture> reflectionMap;
|
||||
SDCar *car;
|
||||
inline osg::ref_ptr<osg::Group> getCamerasRoot(){
|
||||
return camerasRoot;
|
||||
}
|
||||
|
||||
public:
|
||||
SDReflectionMapping(tCarElt *c);
|
||||
SDReflectionMapping(SDCar *c);
|
||||
~SDReflectionMapping();
|
||||
|
||||
inline osg::ref_ptr<osg::TextureCubeMap> getReflectionMap(){
|
||||
inline osg::ref_ptr<osg::Texture> getReflectionMap(){
|
||||
return reflectionMap;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,10 @@
|
|||
|
||||
#include "OsgMain.h"
|
||||
#include "OsgShader.h"
|
||||
#include "OsgCar/OsgCar.h"
|
||||
#include "OsgSky/OsgSky.h"
|
||||
|
||||
SDCarShader::SDCarShader(osg::Node *car){
|
||||
SDCarShader::SDCarShader(osg::Node *car, SDCar *c){
|
||||
|
||||
std::string TmpPath = GetDataDir();
|
||||
osg::ref_ptr<osg::Shader> vertShader =
|
||||
|
@ -41,26 +42,30 @@ SDCarShader::SDCarShader(osg::Node *car){
|
|||
program->addShader( fragShader.get() );
|
||||
|
||||
pCar= car;
|
||||
this->pSdCar = c;
|
||||
stateset = pCar->getOrCreateStateSet();
|
||||
stateset->setAttributeAndModes(program);
|
||||
|
||||
diffuseMap = new osg::Uniform("diffusemap", 0 );
|
||||
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));
|
||||
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);
|
||||
lightPower = stateset->getOrCreateUniform("lightpower",osg::Uniform::FLOAT_VEC4);
|
||||
ambientColor = stateset->getOrCreateUniform("ambientColor",osg::Uniform::FLOAT_VEC4);
|
||||
shininess = new osg::Uniform("smoothness", 300.0f);
|
||||
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){
|
||||
|
|
|
@ -16,23 +16,37 @@
|
|||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _OSGSHADERS_H_
|
||||
#define _OSGSHADERS_H_
|
||||
|
||||
class SDCar;
|
||||
|
||||
class SDCarShader{
|
||||
private :
|
||||
|
||||
SDCar * pSdCar;
|
||||
|
||||
osg::ref_ptr<osg::Program> program ;
|
||||
|
||||
osg::ref_ptr<osg::Node> pCar;
|
||||
|
||||
osg::ref_ptr<osg::StateSet> stateset;
|
||||
osg::ref_ptr<osg::Uniform> diffuseMap;
|
||||
osg::ref_ptr<osg::Uniform> reflectionMap;
|
||||
osg::ref_ptr<osg::Uniform> specularColor;
|
||||
osg::ref_ptr<osg::Uniform> lightVector;
|
||||
osg::ref_ptr<osg::Uniform> lightPower;
|
||||
osg::ref_ptr<osg::Uniform> ambientColor;
|
||||
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 :
|
||||
SDCarShader(osg::Node *car);
|
||||
SDCarShader(osg::Node *car, SDCar *c);
|
||||
void update(osg::Matrixf view);
|
||||
};
|
||||
|
||||
#endif //_OSGSHADERS_H_
|
||||
|
|
|
@ -49,21 +49,11 @@ SDDebugHUD::SDDebugHUD(){
|
|||
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();
|
||||
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(){
|
||||
HUD_camera->setNodeMask(1-HUD_camera->getNodeMask());
|
||||
}
|
||||
|
|
|
@ -27,8 +27,7 @@ class SDDebugHUD
|
|||
|
||||
public:
|
||||
void toggleHUD();
|
||||
void setTexture(osg::ref_ptr<osg::TextureCubeMap> map);
|
||||
void setTexture(osg::ref_ptr<osg::Texture2D> map);
|
||||
void setTexture(osg::ref_ptr<osg::Texture> map);
|
||||
SDDebugHUD();
|
||||
~SDDebugHUD();
|
||||
|
||||
|
|
Loading…
Reference in a new issue