| | 37 | osg::StateSet* stateset = group->getOrCreateStateSet(); |
| | 38 | osg::ShaderAttribute* sa = new osg::ShaderAttribute; |
| | 39 | sa->setType(osg::StateAttribute::Type(10000)); |
| | 40 | sa1 = sa; |
| | 41 | stateset->setAttribute(sa); |
| | 42 | |
| | 43 | { |
| | 44 | osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX); |
| | 45 | vertex_shader->addCodeInjection(-1,"varying vec4 color;\n"); |
| | 46 | vertex_shader->addCodeInjection(-1,"varying vec4 texcoord;\n"); |
| | 47 | vertex_shader->addCodeInjection(0,"color = gl_Color;\n"); |
| | 48 | vertex_shader->addCodeInjection(0,"texcoord = gl_MultiTexCoord0;\n"); |
| | 49 | vertex_shader->addCodeInjection(0,"gl_Position = ftransform();\n"); |
| | 50 | sa->addShader(vertex_shader); |
| | 51 | } |
| | 52 | |
| | 53 | { |
| | 54 | osg::Shader* fragment_shader = new osg::Shader(osg::Shader::FRAGMENT); |
| | 55 | fragment_shader->addCodeInjection(-1,"varying vec4 color;\n"); |
| | 56 | fragment_shader->addCodeInjection(-1,"varying vec4 texcoord;\n"); |
| | 57 | fragment_shader->addCodeInjection(-1,"uniform sampler2D baseTexture; \n"); |
| | 58 | fragment_shader->addCodeInjection(0,"gl_FragColor = color * texture2DProj( baseTexture, texcoord );\n"); |
| | 59 | |
| | 60 | sa->addShader(fragment_shader); |
| | 61 | } |
| | 62 | |
| | 63 | sa->addUniform(new osg::Uniform("baseTexture",0)); |
| | 64 | |
| | 65 | #if 1 |
| | 66 | osg::ShaderAttribute* sa_dummy = new osg::ShaderAttribute; |
| | 67 | sa_dummy->setType(osg::StateAttribute::Type(10001)); |
| | 68 | stateset->setAttribute(sa_dummy); |
| | 69 | #endif |
| | 70 | |
| | 71 | } |
| | 72 | |
| | 73 | // inherit the ShaderComponents entirely from above |
| | 74 | { |
| | 75 | osg::PositionAttitudeTransform* pat = new osg::PositionAttitudeTransform; |
| | 76 | pat->setPosition(position); |
| | 77 | pat->addChild(node); |
| | 78 | |
| | 79 | position.x() += spacing; |
| | 80 | |
| | 81 | group->addChild(pat); |
| | 82 | |
| | 83 | } |
| | 84 | |
| | 85 | { |
| | 86 | osg::PositionAttitudeTransform* pat = new osg::PositionAttitudeTransform; |
| | 87 | pat->setPosition(position); |
| | 88 | pat->addChild(node); |
| | 89 | |
| | 90 | position.x() += spacing; |
| | 91 | |
| | 92 | osg::StateSet* stateset = pat->getOrCreateStateSet(); |
| | 93 | stateset->setMode(GL_BLEND, osg::StateAttribute::ON); |
| | 94 | |
| | 95 | #if 1 |
| | 96 | osg::ShaderAttribute* sa = new osg::ShaderAttribute; |
| | 97 | sa->setType(osg::StateAttribute::Type(10001)); |
| | 98 | stateset->setAttribute(sa); |
| | 99 | |
| | 100 | { |
| | 101 | osg::Shader* fragment_shader = new osg::Shader(osg::Shader::FRAGMENT); |
| | 102 | fragment_shader->addCodeInjection(0.9f,"gl_FragColor.a = gl_FragColor.a*0.5;\n"); |
| | 103 | |
| | 104 | sa->addShader(fragment_shader); |
| | 105 | } |
| | 106 | #endif |
| | 107 | |
| | 108 | group->addChild(pat); |
| | 109 | } |
| | 110 | |
| | 111 | // resuse the first ShaderAttribute's type and ShaderComponent, just use new uniform |
| | 112 | { |
| | 113 | osg::PositionAttitudeTransform* pat = new osg::PositionAttitudeTransform; |
| | 114 | pat->setPosition(position); |
| | 115 | pat->addChild(node); |
| | 116 | |
| | 117 | position.x() += spacing; |
| | 118 | |
| | 119 | osg::StateSet* stateset = pat->getOrCreateStateSet(); |
| | 120 | osg::ShaderAttribute* sa = new osg::ShaderAttribute(*sa1); |
| | 121 | stateset->setAttribute(sa); |
| | 122 | |
| | 123 | // reuse the same ShaderComponent as the first branch |
| | 124 | sa->addUniform(new osg::Uniform("myColour",osg::Vec4(1.0f,1.0f,0.0f,1.0f))); |
| | 125 | |
| | 126 | group->addChild(pat); |
| | 127 | |
| | 128 | } |
| | 129 | |
| | 130 | |
| | 131 | // resuse the first ShaderAttribute's type and ShaderComponent, just use new uniform |
| | 132 | { |
| 45 | | //sa->setType(osg::StateAttribute::Type(10000)); |
| 46 | | sa1 = sa; |
| 47 | | stateset->setAttribute(sa); |
| 48 | | |
| 49 | | { |
| 50 | | const char shader_str[] = |
| 51 | | "uniform vec4 myColour;\n" |
| 52 | | "vec4 colour()\n" |
| 53 | | "{\n" |
| 54 | | " return myColour;\n" |
| 55 | | "}\n"; |
| 56 | | |
| 57 | | osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX, shader_str); |
| 58 | | vertex_shader->addCodeInjection(-1,"varying vec4 c;\n"); |
| 59 | | vertex_shader->addCodeInjection(-1,"vec4 colour();\n"); |
| | 141 | sa->setType(osg::StateAttribute::Type(10000)); |
| | 142 | stateset->setAttribute(sa); |
| | 143 | stateset->setMode(GL_BLEND, osg::StateAttribute::ON); |
| | 144 | stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); |
| | 145 | |
| | 146 | { |
| | 147 | osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX); |
| 74 | | } |
| 75 | | |
| 76 | | group->addChild(pat); |
| 77 | | |
| 78 | | } |
| 79 | | #if 1 |
| 80 | | { |
| 81 | | osg::PositionAttitudeTransform* pat = new osg::PositionAttitudeTransform; |
| 82 | | pat->setPosition(position); |
| 83 | | pat->addChild(node); |
| 84 | | |
| 85 | | position.x() += spacing; |
| 86 | | |
| 87 | | osg::StateSet* stateset = pat->getOrCreateStateSet(); |
| 88 | | osg::ShaderAttribute* sa = new osg::ShaderAttribute; |
| 89 | | //sa->setType(osg::StateAttribute::Type(10000)); |
| 90 | | stateset->setAttribute(sa); |
| 91 | | |
| 92 | | // reuse the same ShaderComponent as the first branch |
| 93 | | sa->setShaderComponent(sa1->getShaderComponent()); |
| 94 | | sa->addUniform(new osg::Uniform("myColour",osg::Vec4(1.0f,1.0f,0.0f,1.0f))); |
| 95 | | |
| 96 | | group->addChild(pat); |
| 97 | | |
| 98 | | } |
| 99 | | #endif |
| | 160 | sa->addUniform(new osg::Uniform("newColour",osg::Vec4(1.0f,1.0f,1.0f,0.5f))); |
| | 161 | } |
| | 162 | |
| | 163 | group->addChild(pat); |
| | 164 | |
| | 165 | group->addChild(pat); |
| | 166 | |
| | 167 | } |
| | 168 | |