Hi

great submission, but since gl_Light* stuff are also deprecated, this is not as 
useful as it could be
but at least you can calc headlight with this uniforms

Cheers

07.02.2013, 15:46, "Aurelien Albert" <[email protected]>:
> Hi,
>
> In "advanced" OpenGL (glsl > 320 I think) gl_material is deprecated.
>
> This is really annoying if you want to render "normal" files such as 
> 3ds/ive/osgb... which contains osg::Material.
>
> This submission works like the "setUseModelViewAndProjectionUniforms" method 
> on osg::State, by introducing the "setUseGLMaterialUniforms" method :
>
> This method add some uniforms, synced with the current osg::Material :
>
> osg_FrontMaterial.ambient
> osg_FrontMaterial.diffuse
> osg_FrontMaterial.specular
> osg_FrontMaterial.emission
> osg_FrontMaterial.shininess
>
> and
>
> osg_BackMaterial.ambient
> osg_BackMaterial.diffuse
> osg_BackMaterial.specular
> osg_BackMaterial.emission
> osg_BackMaterial.shininess
>
> To use it in a shader, you can :
>
> 1/ Declare only uniforms you want to use :
>
> Code:
> uniform vec4 osg_FrontMaterial.ambient;
> uniform vec4 osg_FrontMaterial.diffuse;
>
> If you use only these two values
>
> 2/ Declare complete structure :
>
> Code:
> // Define the  structure
> struct osg_Material
> {
>    vec4   ambient;
>    vec4   diffuse;
>    vec4   specular;
>    vec4   emission;
>    float   shininess;
> };
>
> // Declare the unfiroms :
> uniform osg_Material osg_FrontMaterial;
> uniform osg_Material osg_BackMaterial;
>
> and then use osg_FrontMaterial.ambient, osg_FrontMaterial.diffuse, etc... in 
> your shader code.
>
> Thank you!
>
> Cheers,
> Aurelien
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=52462#52462
>
> ,
> /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
>  *
>  * This library is open source and may be redistributed and/or modified under
>  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
>  * (at your option) any later version.  The full license is in LICENSE file
>  * included with this distribution, and on the openscenegraph.org website.
>  *
>  * This library is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * OpenSceneGraph Public License for more details.
> */
> #include <osgUtil/RenderLeaf>
> #include <osgUtil/StateGraph>
> #include <osg/Notify>
>
> using namespace osg;
> using namespace osgUtil;
>
> void RenderLeaf::render(osg::RenderInfo& renderInfo,RenderLeaf* previous)
> {
>     osg::State& state = *renderInfo.getState();
>
>     // don't draw this leaf if the abort rendering flag has been set.
>     if (state.getAbortRendering())
>     {
>         //cout << "early abort"<<endl;
>         return;
>     }
>
>     if (previous)
>     {
>
>         // apply matrices if required.
>         state.applyProjectionMatrix(_projection.get());
>         state.applyModelViewMatrix(_modelview.get());
>
>         // apply state if required.
>         StateGraph* prev_rg = previous->_parent;
>         StateGraph* prev_rg_parent = prev_rg->_parent;
>         StateGraph* rg = _parent;
>         if (prev_rg_parent!=rg->_parent)
>         {
>             StateGraph::moveStateGraph(state,prev_rg_parent,rg->_parent);
>
>             // send state changes and matrix changes to OpenGL.
>             state.apply(rg->getStateSet());
>
>         }
>         else if (rg!=prev_rg)
>         {
>
>             // send state changes and matrix changes to OpenGL.
>             state.apply(rg->getStateSet());
>
>         }
>
>         // if we are using osg::Program which requires OSG's generated 
> uniforms to track
>         // modelview and projection matrices then apply them now.
>         if (state.getUseModelViewAndProjectionUniforms()) 
> state.applyModelViewAndProjectionUniformsIfRequired();
>         if (state.getUseGLMaterialUniforms()) 
> state.applyGLMaterialUniformsIfRequired();
>
>         // draw the drawable
>         _drawable->draw(renderInfo);
>     }
>     else
>     {
>         // apply matrices if required.
>         state.applyProjectionMatrix(_projection.get());
>         state.applyModelViewMatrix(_modelview.get());
>
>         // apply state if required.
>         StateGraph::moveStateGraph(state,NULL,_parent->_parent);
>
>         state.apply(_parent->getStateSet());
>
>         // if we are using osg::Program which requires OSG's generated 
> uniforms to track
>         // modelview and projection matrices then apply them now.
>         if (state.getUseModelViewAndProjectionUniforms()) 
> state.applyModelViewAndProjectionUniformsIfRequired();
>         if (state.getUseGLMaterialUniforms()) 
> state.applyGLMaterialUniformsIfRequired();
>
>         // draw the drawable
>         _drawable->draw(renderInfo);
>     }
>
>     if (_dynamic)
>     {
>         state.decrementDynamicObjectCount();
>     }
>
>     // OSG_NOTICE<<"RenderLeaf "<<_drawable->getName()<<" 
> "<<_depth<<std::endl;
> }
>
> ,
> _______________________________________________
> osg-submissions mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to