| 1015 | | |
| 1016 | | |
| 1017 | | osg::StateSet* stateset = new osg::StateSet; |
| 1018 | | |
| 1019 | | stateset->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON ); |
| 1020 | | stateset->setRenderingHint( osg::StateSet::TRANSPARENT_BIN ); |
| | 1020 | |
| | 1021 | osg::StateSet* stateset = new osg::StateSet(*dstate, osg::CopyOp::DEEP_COPY_ALL); |
| | 1022 | |
| | 1023 | { |
| | 1024 | // vertex program |
| | 1025 | std::ostringstream vp_oss; |
| | 1026 | vp_oss << |
| | 1027 | "!!ARBvp1.0\n" |
| | 1028 | |
| | 1029 | "ATTRIB vpos = vertex.position;\n" |
| | 1030 | "ATTRIB vcol = vertex.color;\n" |
| | 1031 | "ATTRIB tc = vertex.texcoord[" << 0 << "];" |
| | 1032 | |
| | 1033 | "PARAM mvp[4] = { state.matrix.mvp };\n" |
| | 1034 | "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" |
| | 1035 | |
| | 1036 | "TEMP position;\n" |
| | 1037 | |
| | 1038 | // vec3 position = gl_Vertex.xyz * gl_Color.w + gl_Color.xyz; |
| | 1039 | "MAD position, vpos, vcol.w, vcol;\n" |
| | 1040 | |
| | 1041 | // gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0); |
| | 1042 | "MOV position.w, one;\n" |
| | 1043 | "DP4 result.position.x, mvp[0], position;\n" |
| | 1044 | "DP4 result.position.y, mvp[1], position;\n" |
| | 1045 | "DP4 result.position.z, mvp[2], position;\n" |
| | 1046 | "DP4 result.position.w, mvp[3], position;\n" |
| | 1047 | |
| | 1048 | // gl_FrontColor = vec4(1.0,1.0,1.0,1.0); |
| | 1049 | "MOV result.color.front.primary, one;\n" |
| | 1050 | |
| | 1051 | // texcoord = gl_MultiTexCoord0.st; |
| | 1052 | "MOV result.texcoord, tc;\n" |
| | 1053 | "END\n"; |
| | 1054 | |
| | 1055 | |
| | 1056 | // fragment program |
| | 1057 | std::ostringstream fp_oss; |
| | 1058 | fp_oss << |
| | 1059 | "!!ARBfp1.0\n" |
| | 1060 | "TEX result.color, fragment.texcoord[" << 0 << "], texture[" << 0 << "], 2D;" |
| | 1061 | "END\n"; |
| | 1062 | |
| | 1063 | osg::ref_ptr<osg::VertexProgram> vp = new osg::VertexProgram; |
| | 1064 | vp->setVertexProgram(vp_oss.str()); |
| | 1065 | stateset->setAttributeAndModes(vp.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
| | 1066 | |
| | 1067 | osg::ref_ptr<osg::FragmentProgram> fp = new osg::FragmentProgram; |
| | 1068 | fp->setFragmentProgram(fp_oss.str()); |
| | 1069 | stateset->setAttributeAndModes(fp.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
| | 1070 | } |
| | 1071 | |
| | 1072 | group->addChild(createShaderGraph(cell.get(),stateset)); |
| | 1073 | group->addChild(createHUDWithText("Using osg::Vertex/FragmentProgram to create a forest\n\nPress left cursor key to select osg::MatrixTransform's based forest\nPress right cursor key to select OpenGL shader based forest")); |
| | 1074 | _techniqueSwitch->addChild(group); |
| | 1075 | std::cout<<"done."<<std::endl; |
| | 1076 | } |
| | 1077 | |
| | 1078 | { |
| | 1079 | std::cout<<"Creating OpenGL shader based forest..."; |
| | 1080 | osg::Group* group = new osg::Group; |
| | 1081 | |
| | 1082 | osg::StateSet* stateset = new osg::StateSet(*dstate, osg::CopyOp::DEEP_COPY_ALL); |