| | 58 | ////////////////////////////////////////////////////////////////// |
| | 59 | // fragment shader |
| | 60 | // |
| | 61 | static const char fragmentShaderSource_debugHUD_texcoord[] = |
| | 62 | "uniform sampler2D osgShadow_shadowTexture; \n" |
| | 63 | " \n" |
| | 64 | "void main(void) \n" |
| | 65 | "{ \n" |
| | 66 | " vec4 texCoord = gl_TexCoord[1].xyzw; \n" |
| | 67 | " float value = texCoord.z / texCoord.w; \n" |
| | 68 | " gl_FragColor = vec4( value, value, value, 1.0 ); \n" |
| | 69 | "} \n"; |
| | 70 | |
| | 71 | static const char fragmentShaderSource_debugHUD[] = |
| | 72 | "uniform sampler2D osgShadow_shadowTexture; \n" |
| | 73 | " \n" |
| | 74 | "void main(void) \n" |
| | 75 | "{ \n" |
| | 76 | " vec4 texResult = texture2D(osgShadow_shadowTexture, gl_TexCoord[0].st ); \n" |
| | 77 | " float value = texResult.g - 0.5; \n" |
| | 78 | " gl_FragColor = vec4( value, value, value, 0.8 ); \n" |
| | 79 | "} \n"; |
| | 80 | |
| 148 | | _texture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_EDGE); |
| 149 | | _texture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_EDGE); |
| | 171 | |
| | 172 | // the shadow comparison should fail if object is outside the texture |
| | 173 | _texture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_BORDER); |
| | 174 | _texture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_BORDER); |
| | 175 | _texture->setBorderColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
| 465 | | stateset->setTextureAttributeAndModes(_baseTextureUnit,_texture.get(),osg::StateAttribute::ON); |
| 466 | | |
| 467 | | //TODO might need to have a shader for correct display |
| | 492 | |
| | 493 | stateset->setTextureAttributeAndModes(_shadowTextureUnit,_texture.get(),osg::StateAttribute::ON); |
| | 494 | |
| | 495 | //test to check the texture coordinates generated during shadow pass |
| | 496 | #if 0 |
| | 497 | stateset->setTextureMode(_shadowTextureUnit,GL_TEXTURE_GEN_S,osg::StateAttribute::ON); |
| | 498 | stateset->setTextureMode(_shadowTextureUnit,GL_TEXTURE_GEN_T,osg::StateAttribute::ON); |
| | 499 | stateset->setTextureMode(_shadowTextureUnit,GL_TEXTURE_GEN_R,osg::StateAttribute::ON); |
| | 500 | stateset->setTextureMode(_shadowTextureUnit,GL_TEXTURE_GEN_Q,osg::StateAttribute::ON); |
| | 501 | |
| | 502 | // create TexGen node |
| | 503 | osg::ref_ptr<osg::TexGenNode> texGenNode = new osg::TexGenNode; |
| | 504 | texGenNode->setTextureUnit(_shadowTextureUnit); |
| | 505 | texGenNode->setTexGen(_texgen.get()); |
| | 506 | camera->addChild(texGenNode.get()); |
| | 507 | #endif |
| | 508 | //shader for correct display |
| | 509 | |
| | 510 | osg::ref_ptr<osg::Program> program = new osg::Program; |
| | 511 | stateset->setAttribute(program.get()); |
| | 512 | |
| | 513 | osg::Shader* fragment_shader = new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource_debugHUD); |
| | 514 | program->addShader(fragment_shader); |