OSG : specular corrected and now have quite normal behavior

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

Former-commit-id: ec77ece221406d9ef168764ba3027723db7c07d2
Former-commit-id: 598326b80f677fab7050af3247af22eeb8fcdfb1
This commit is contained in:
rvlander 2013-05-22 17:07:00 +00:00
parent 724d79596a
commit dc0091b1f9
4 changed files with 15 additions and 28 deletions

View file

@ -156,7 +156,6 @@ void SDPerspCamera::setProjection(void)
void SDPerspCamera::setModelView(void) void SDPerspCamera::setModelView(void)
{ {
screen->getOsgCam()->setViewMatrixAsLookAt(eye,center,up); screen->getOsgCam()->setViewMatrixAsLookAt(eye,center,up);
screen->getOsgCam()->setUserValue("eye",eye);
} }
void SDPerspCamera::loadDefaults(char *attr) void SDPerspCamera::loadDefaults(char *attr)

View file

@ -48,8 +48,7 @@ private :
osg::Node *pCar; osg::Node *pCar;
osg::StateSet* stateset; osg::StateSet* stateset;
osg::Uniform * diffuseMap; osg::Uniform * diffuseMap;
osg::Uniform * normalMap; //osg::Uniform * normalMap;
osg::Uniform * viewPoint;
osg::Uniform * specularColor; osg::Uniform * specularColor;
osg::Uniform * lightVector; osg::Uniform * lightVector;
osg::Uniform * lightPower; osg::Uniform * lightPower;
@ -79,8 +78,6 @@ public :
stateset->addUniform(diffuseMap); stateset->addUniform(diffuseMap);
// normalMap = new osg::Uniform("normalmap", 1 ); // normalMap = new osg::Uniform("normalmap", 1 );
// stateset->addUniform(normalMap); // stateset->addUniform(normalMap);
viewPoint = new osg::Uniform("pv",osg::Vec3());
stateset->addUniform(viewPoint);
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()); lightVector = new osg::Uniform("lightvector",osg::Vec3());
@ -89,12 +86,11 @@ public :
stateset->addUniform(lightPower); stateset->addUniform(lightPower);
ambientColor =new osg::Uniform("ambientColor",osg::Vec4()); ambientColor =new osg::Uniform("ambientColor",osg::Vec4());
stateset->addUniform(ambientColor); stateset->addUniform(ambientColor);
shininess = new osg::Uniform("smoothness", 128.0f); shininess = new osg::Uniform("smoothness", 300.0f);
stateset->addUniform(shininess); stateset->addUniform(shininess);
} }
void update(osg::Vec3f c, osg::Matrixf view){ void update(osg::Matrixf view){
SDRender * ren = (SDRender *)getRender(); SDRender * ren = (SDRender *)getRender();
osg::Vec3f sun_pos= ren->getSky()->getSun()->getSunPosition(); osg::Vec3f sun_pos= ren->getSky()->getSun()->getSunPosition();
@ -111,9 +107,6 @@ public :
//Wil have to check space coordinates !
osg::Vec4f v = osg::Vec4f(c.x(),c.y(),c.z(),1.0f);
osg::Vec4f pv = v*view;
osg::Vec4f lv = osg::Vec4(sun_pos.x(),sun_pos.y(),sun_pos.z(),0.0f); osg::Vec4f lv = osg::Vec4(sun_pos.x(),sun_pos.y(),sun_pos.z(),0.0f);
lv = lv*view; lv = lv*view;
@ -121,11 +114,9 @@ public :
GfOut("View Point : %f %f %f\n",pv.x(),pv.y(),pv.z()); GfOut("View Point : %f %f %f\n",pv.x(),pv.y(),pv.z());
GfOut("Light Vector : %f %f %f\n",lv.x(),lv.y(),lv.z()); GfOut("Light Vector : %f %f %f\n",lv.x(),lv.y(),lv.z());
*/ */
//GfOut("View Point : %f %f %f\n",pv.x(),pv.y(),pv.z());
// GfOut("Scene Color : %f %f %f %f\n",scene_color._v[0],scene_color._v[1],scene_color._v[2],scene_color._v[3]); // GfOut("Scene Color : %f %f %f %f\n",scene_color._v[0],scene_color._v[1],scene_color._v[2],scene_color._v[3]);
this->viewPoint->set(osg::Vec3f(pv.x(),pv.y(),pv.z()));
this->lightVector->set(osg::Vec3f(lv.x(),lv.y(),lv.z())); this->lightVector->set(osg::Vec3f(lv.x(),lv.y(),lv.z()));
this->lightPower->set(sun_color); this->lightPower->set(sun_color);
this->ambientColor->set(scene_color); this->ambientColor->set(scene_color);
@ -329,7 +320,7 @@ osg::ref_ptr<osg::Node> SDCar::initOcclusionQuad(tCarElt *car){
std::string TmpPath = GetDataDir(); std::string TmpPath = GetDataDir();
GfOut("\n################## LOADING SHADOW ###############################\n"); // GfOut("\n################## LOADING SHADOW ###############################\n");
std::string shadowTextureName = GfParmGetStr(car->_carHandle, SECT_GROBJECTS, PRM_SHADOW_TEXTURE, ""); std::string shadowTextureName = GfParmGetStr(car->_carHandle, SECT_GROBJECTS, PRM_SHADOW_TEXTURE, "");
@ -340,7 +331,7 @@ osg::ref_ptr<osg::Node> SDCar::initOcclusionQuad(tCarElt *car){
std::string dir = buf; std::string dir = buf;
shadowTextureName = TmpPath +dir+shadowTextureName; shadowTextureName = TmpPath +dir+shadowTextureName;
GfOut("\n lepath = %s\n",shadowTextureName.c_str()); // GfOut("\n lepath = %s\n",shadowTextureName.c_str());
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
osg::ref_ptr<osg::Vec2Array> texcoords = new osg::Vec2Array; osg::ref_ptr<osg::Vec2Array> texcoords = new osg::Vec2Array;
@ -401,7 +392,7 @@ osg::ref_ptr<osg::Node> SDCar::initOcclusionQuad(tCarElt *car){
shadowVertices = vertices; shadowVertices = vertices;
GfOut("\n################## LOADED SHADOW ###############################\n"); // GfOut("\n################## LOADED SHADOW ###############################\n");
return root; return root;
@ -425,6 +416,7 @@ void SDCar::updateCar()
//ugly computation, order to chec //ugly computation, order to chec
osg::Vec3Array::iterator itr; osg::Vec3Array::iterator itr;
itr = shadowVertices->begin(); itr = shadowVertices->begin();
while (itr != shadowVertices->end()) while (itr != shadowVertices->end())
{ {
osg::Vec3 vtx = *itr; osg::Vec3 vtx = *itr;
@ -442,10 +434,10 @@ void SDCar::updateCar()
} }
void SDCar::updateShadingParameters(osg::Vec3f eye,osg::Matrixf modelview){ void SDCar::updateShadingParameters(osg::Matrixf modelview){
shader->update(eye,modelview); shader->update(modelview);
} }
SDCars::SDCars(void) SDCars::SDCars(void)
@ -490,11 +482,11 @@ void SDCars::updateCars()
} }
} }
void SDCars::updateShadingParameters(osg::Vec3f eye,osg::Matrixf modelview){ void SDCars::updateShadingParameters(osg::Matrixf modelview){
std::vector<SDCar *>::iterator it; std::vector<SDCar *>::iterator it;
for(it = the_cars.begin(); it!= the_cars.end(); it++) for(it = the_cars.begin(); it!= the_cars.end(); it++)
{ {
(*it)->updateShadingParameters(eye,modelview); (*it)->updateShadingParameters(modelview);
} }
} }

View file

@ -43,7 +43,7 @@ class SDCar
public : public :
osg::ref_ptr<osg::Node> loadCar(tCarElt *car); osg::ref_ptr<osg::Node> loadCar(tCarElt *car);
void updateCar(); void updateCar();
void updateShadingParameters(osg::Vec3f eye,osg::Matrixf modelview); void updateShadingParameters(osg::Matrixf modelview);
}; };
class SDCars class SDCars
@ -62,7 +62,7 @@ class SDCars
void loadCars(tSituation * pSituation); void loadCars(tSituation * pSituation);
void updateCars(); void updateCars();
void unLoad(); void unLoad();
void updateShadingParameters(osg::Vec3f eye,osg::Matrixf modelview); void updateShadingParameters(osg::Matrixf modelview);
osg::Node* getCarsNode(){ return cars_branch.get(); } osg::Node* getCarsNode(){ return cars_branch.get(); }
}; };

View file

@ -42,12 +42,8 @@ public:
virtual void operator()(const osg::Camera& cam) const virtual void operator()(const osg::Camera& cam) const
{ {
SDCars * cars = (SDCars*)getCars(); SDCars * cars = (SDCars*)getCars();
osg::Vec3 e;
cam.getUserValue("eye",e);
osg::Matrixf mat = cam.getViewMatrix(); osg::Matrixf mat = cam.getViewMatrix();
cars->updateShadingParameters(e,mat); cars->updateShadingParameters(mat);
// GfOut("Camera DrawnHHERERE %d %f %f %F\n",&cam,e.x(),e.y(),e.z());
// traverse(node, nv);
} }
}; };