Changeset 13041 for OpenSceneGraph/trunk/src/osgUtil/ShaderGen.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgUtil/ShaderGen.cpp (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgUtil/ShaderGen.cpp
r12292 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 60 60 { 61 61 UniformMap::const_iterator it = _uniformMap.find(name); 62 return it != _uniformMap.end() ? 62 return it != _uniformMap.end() ? 63 63 const_cast<osg::Uniform *>(it->second.uniformVec.back().first) : 0; 64 64 } … … 67 67 68 68 osg::StateAttribute::GLModeValue getMode(const ModeMap &modeMap, 69 osg::StateAttribute::GLMode mode, 69 osg::StateAttribute::GLMode mode, 70 70 osg::StateAttribute::GLModeValue def = osg::StateAttribute::INHERIT) const 71 71 { … … 78 78 { 79 79 AttributeMap::const_iterator it = attributeMap.find(std::make_pair(type, member)); 80 return (it != attributeMap.end() && it->second.attributeVec.size()) ? 80 return (it != attributeMap.end() && it->second.attributeVec.size()) ? 81 81 const_cast<osg::StateAttribute*>(it->second.attributeVec.back().first) : 0; 82 82 } … … 135 135 vert << "varying vec3 viewDir;\n"; 136 136 } 137 137 138 138 // copy varying to fragment shader 139 139 frag << vert.str(); … … 169 169 if (stateMask & NORMAL_MAP) 170 170 { 171 vert << 171 vert << 172 172 " vec3 n = gl_NormalMatrix * gl_Normal;\n"\ 173 173 " vec3 t = gl_NormalMatrix * tangent;\n"\ … … 188 188 else if (stateMask & LIGHTING) 189 189 { 190 vert << 190 vert << 191 191 " normalDir = gl_NormalMatrix * gl_Normal;\n"\ 192 192 " vec3 dir = -vec3(gl_ModelViewMatrix * gl_Vertex);\n"\ … … 200 200 else if (stateMask & FOG) 201 201 { 202 vert << 202 vert << 203 203 " viewDir = -vec3(gl_ModelViewMatrix * gl_Vertex);\n"\ 204 204 " gl_FrontColor = gl_Color;\n"; … … 208 208 vert << " gl_FrontColor = gl_Color;\n"; 209 209 } 210 210 211 211 vert << "}\n"; 212 212 … … 231 231 if (stateMask & (LIGHTING | NORMAL_MAP)) 232 232 { 233 frag << 233 frag << 234 234 " vec3 nd = normalize(normalDir);\n"\ 235 235 " vec3 ld = normalize(lightDir);\n"\ … … 259 259 if (stateMask & FOG) 260 260 { 261 frag << 261 frag << 262 262 " float d2 = dot(viewDir, viewDir);//gl_FragCoord.z/gl_FragCoord.w;\n"\ 263 263 " float f = exp2(-1.442695*gl_Fog.density*gl_Fog.density*d2);\n"\ 264 264 " color.rgb = mix(gl_Fog.color.rgb, color.rgb, clamp(f, 0.0, 1.0));\n"; 265 265 } 266 266 267 267 frag << " gl_FragColor = color;\n"; 268 268 frag << "}\n"; … … 280 280 } 281 281 282 ShaderGenVisitor::ShaderGenVisitor() : 282 ShaderGenVisitor::ShaderGenVisitor() : 283 283 NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), 284 284 _stateCache(new ShaderGenCache), … … 287 287 } 288 288 289 ShaderGenVisitor::ShaderGenVisitor(ShaderGenCache *stateCache) : 289 ShaderGenVisitor::ShaderGenVisitor(ShaderGenCache *stateCache) : 290 290 NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), 291 291 _stateCache(stateCache), … … 384 384 ss->setAttribute(progss->getAttribute(osg::StateAttribute::PROGRAM)); 385 385 ss->setUniformList(progss->getUniformList()); 386 386 387 387 // remove any modes that won't be appropriate when using shaders 388 388 if ((stateMask&ShaderGenCache::LIGHTING)!=0)
