void Stimulus3DShaderDemo::post_init(bool slave) { osg::ref_ptr<osg::Node> drawn_geometry_node = load_osg_file("Stimulus3DShaderDemo.osg"); osg::StateSet* state = drawn_geometry_node->getOrCreateStateSet(); state->setMode(GL_LIGHTING,osg::StateAttribute::OFF); osg::Program* AltitudeProgram; osg::Shader* AltitudeVertObj; osg::Shader* AltitudeFragObj; AltitudeProgram = new osg::Program; AltitudeProgram->setName( "altitude" ); AltitudeVertObj = new osg::Shader( osg::Shader::VERTEX ); AltitudeFragObj = new osg::Shader( osg::Shader::FRAGMENT ); AltitudeProgram->addShader( AltitudeFragObj ); AltitudeProgram->addShader( AltitudeVertObj ); load_shader_source( AltitudeVertObj, "rainbow.vert" ); load_shader_source( AltitudeFragObj, "rainbow.frag" ); state->setAttributeAndModes(AltitudeProgram, osg::StateAttribute::ON); example_param_uniform = new osg::Uniform( osg::Uniform::FLOAT, "example_param" ); state->addUniform( example_param_uniform ); _group = new osg::Group; _group->addChild(drawn_geometry_node); _group->setName("Stimulus3DShaderDemo._group"); _slave = slave; { Poco::NamedMutex::ScopedLock lock(_memlock); *_mem.begin() = 'a'; } }
void ProjectCubemapToGeometryPass::set_shader(std::string vert_filename, std::string frag_filename) { osg::ref_ptr<osg::Shader> vshader = new osg::Shader( osg::Shader::VERTEX ); osg::ref_ptr<osg::Shader> fshader = new osg::Shader( osg::Shader::FRAGMENT ); load_shader_source( vshader, vert_filename ); load_shader_source( fshader, frag_filename ); _program = new osg::Program; _program->addShader(vshader.get()); _program->addShader(fshader.get()); _state_set->setAttributeAndModes(_program.get(), osg::StateAttribute::ON);// | osg::StateAttribute::OVERRIDE ); }
/** * Load and compile a GLSL shader file. * @param filename GLSL file name. * @param type GLSL shader type enum. * @return Shader handle in case of success, 0 otherwise. */ GLuint GL::ShaderObject::compile_shader_object(const string& shader, const string& material, GLenum type) { string file_extension; switch(type) { case GL_VERTEX_SHADER: file_extension = ".vert"; break; case GL_GEOMETRY_SHADER: file_extension = ".geom"; break; case GL_FRAGMENT_SHADER: file_extension = ".frag"; break; #ifdef GL_VERSION_4_0 case GL_TESS_CONTROL_SHADER: file_extension = ".tess_ctrl"; break; case GL_TESS_EVALUATION_SHADER: file_extension = ".tess_eval"; break; #endif #ifdef GL_VERSION_4_3 case GL_COMPUTE_SHADER: file_extension = ".compute"; break; #endif default: assert(0); } if (!load_shader_source(shader, material, file_extension)) { return 0; } if (config.verbosity_level() >= 2) { cout << boost::format("\t %1%/%2%%3%") % gl_config.shader_dir() % shader % file_extension << endl; } string source = ss.str(); shader_handle = glCreateShader(type); const char * csource = source.c_str(); GLint source_length = source.size(); glShaderSource(shader_handle, 1, &csource, &source_length); glCompileShader(shader_handle); GLint status; glGetShaderiv(shader_handle, GL_COMPILE_STATUS, &status); if (config.verbosity_level() > 0 || status == GL_FALSE) { print_shader_log(); } if (status == GL_FALSE) { glDeleteShader(shader_handle); return 0; } return shader_handle; }
void StimulusCylinderGrating_centered_bw::init_cyl(CylInfo& cyl) { osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints; hints->setDetailRatio(2.0f); hints->setCreateTop(false); hints->setCreateBottom(false); osg::Vec3 center = osg::Vec3(0.0f,0.0f,0.0f); float radius = 1.0f; float height = 3.0; cyl.cylinder = new osg::Cylinder(center,radius,height); cyl.shape = new osg::ShapeDrawable(cyl.cylinder, hints.get()); const char* phase_position_name; const char* wavelength_name; const char* contrast_name; const char* orientation_name; for (int i=0; i<NUM_GRATINGS; i++) { GratingParams new_values; new_values.phase_position = 0.0; new_values.phase_velocity = 360*D2R; new_values.wavelength = 20*D2R; new_values.contrast = 1.0; new_values.orientation = 0; if (i==0) { phase_position_name="phase_position0"; wavelength_name="wavelength0"; contrast_name="contrast0"; orientation_name="orientation0"; } else { flyvr_assert(false); } cyl.gratings[i].u_phase_position = new osg::Uniform( osg::Uniform::FLOAT, phase_position_name ); cyl.gratings[i].u_wavelength = new osg::Uniform( osg::Uniform::FLOAT, wavelength_name ); cyl.gratings[i].u_contrast = new osg::Uniform( osg::Uniform::FLOAT, contrast_name ); cyl.gratings[i].u_orientation = new osg::Uniform( osg::Uniform::FLOAT, orientation_name ); set_grating_info( i, new_values); } cyl.geode = new osg::Geode; cyl.geode->addDrawable(cyl.shape.get()); cyl.program = new osg::Program; cyl.program->setName( "cylinder_shader" ); cyl.vertex_shader = new osg::Shader( osg::Shader::VERTEX ); cyl.fragment_shader = new osg::Shader( osg::Shader::FRAGMENT ); cyl.program->addShader(cyl.vertex_shader); cyl.program->addShader(cyl.fragment_shader); load_shader_source( cyl.vertex_shader, "grating_blended_centered.vert" ); load_shader_source( cyl.fragment_shader, "grating_blended_centered.frag" ); cyl.state_set = cyl.shape->getOrCreateStateSet(); cyl.state_set->setMode(GL_LIGHTING, osg::StateAttribute::OFF); cyl.state_set->setMode(GL_BLEND, osg::StateAttribute::ON); cyl.state_set->setAttributeAndModes( cyl.program, osg::StateAttribute::ON); for (int i=0;i<NUM_GRATINGS;i++) { cyl.state_set->addUniform( cyl.gratings[i].u_phase_position ); cyl.state_set->addUniform( cyl.gratings[i].u_wavelength ); cyl.state_set->addUniform( cyl.gratings[i].u_contrast ); cyl.state_set->addUniform( cyl.gratings[i].u_orientation ); } }