Exemple #1
0
void setup_plastic(void)
{
    boost::shared_ptr<shade::GLSLTexture> texture(new shade::GLSLTexture(GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY_EXT));
    texture->bind();
    glTexParameterf(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameterf(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    Texture texture_data("examples/patterns.dds", 4);
    texture_data.upload();

    boost::shared_ptr<ArrayPlastic> specular(new ArrayPlastic(0.7, .3));
    specular->texture_unit.set(texture);
    boost::shared_ptr<shade::shaders::ObjectSpace> object_space(new shade::shaders::ObjectSpace);
    specular->coordinate_system = object_space;
    boost::shared_ptr<shade::shaders::UVCoord> uvcoord(new shade::shaders::UVCoord);
    specular->uv = uvcoord;
    shader->material = specular;
    {
        shaders::IlluminatedMaterial::LightList::Accessor accessor(specular->lights);

        boost::shared_ptr<shaders::PointLight> light(new shaders::PointLight);
        light->position.set_value(shade::vec3<>(30., 15., 10.));
        light->color.set_value(shade::vec3<>(1., 1., 1.));
        accessor->push_back(light);

        boost::shared_ptr<shaders::PointLight> light2(new shaders::PointLight);
        light2->position.set_value(shade::vec3<>(-15., -3, 0.));
        light2->color.set_value(shade::vec3<>(1., 1., 1.));
        accessor->push_back(light2);
    }
}
Exemple #2
0
void setup_plastic_with_texture(void)
{
  boost::shared_ptr<shade::shaders::Plastic> specular(new shade::shaders::Plastic(0.7, .3));
  boost::shared_ptr<shade::shaders::ObjectSpace> object_space(new shade::shaders::ObjectSpace);
  boost::shared_ptr<shade::shaders::Texture2D> tex(new shade::shaders::Texture2D);
  tex->texture_unit.set(example::make_texture("examples/pattern.dds"));
  boost::shared_ptr<shade::shaders::UVCoord> uvcoord(new shade::shaders::UVCoord);
  tex->uv = uvcoord;
  specular->color = tex;
  specular->coordinate_system = object_space;
  shader->material = specular;
  {
    shaders::IlluminatedMaterial::LightList::Accessor accessor(specular->lights);

    boost::shared_ptr<shaders::PointLight> light(new shaders::PointLight);
    light->position.set_value(shade::vec3<>(30., 15., 10.));
    light->color.set_value(shade::vec3<>(1., 1., 1.));
    accessor->push_back(light);

    boost::shared_ptr<shaders::PointLight> light2(new shaders::PointLight);
    light2->position.set_value(shade::vec3<>(-15., -3, 0.));
    light2->color.set_value(shade::vec3<>(1., 1., 1.));
    accessor->push_back(light2);
  }
}
Exemple #3
0
boost::shared_ptr<shade::Program> setup_shading(boost::shared_ptr<shade::GLSLWrapper> state, boost::shared_ptr<shade::Texture> texture)
{
  boost::shared_ptr<shade::shaders::Surface> shader(new shade::shaders::Surface);
  boost::shared_ptr<shade::Program> program(new shade::Program(shader, state));

  boost::shared_ptr<shade::shaders::Constant> constant(new shade::shaders::Constant);
  constant->color.set_value(shade::vec4<>(1., 0.4, 0.4, 1.));
  shader->material = constant;

  boost::shared_ptr<shade::shaders::Texture2D> tex(new shade::shaders::Texture2D);
  tex->texture_unit.set(texture);
  boost::shared_ptr<shade::shaders::UVCoord> uvcoord(new shade::shaders::UVCoord);
  tex->uv = uvcoord;
  constant->color = tex;

  return program;
}
Exemple #4
0
void init(void)
{
  shader = boost::shared_ptr<shaders::Surface>(new shaders::Surface);

  boost::shared_ptr<shade::shaders::Plastic> specular(new shade::shaders::Plastic(0.4, 0.6));
  boost::shared_ptr<shade::shaders::TangentSpace> coordinate_system(new shade::shaders::TangentSpace);
  boost::shared_ptr<shade::shaders::Texture2D> tex_access(new shade::shaders::Texture2D);
  boost::shared_ptr<shade::GLSLTexture> texture(example::make_texture("examples/heightbump.dds"));
  tex_access->texture_unit.set(texture);
  boost::shared_ptr<shade::shaders::UVCoord> uvcoord(new shade::shaders::UVCoord);
  tex_access->uv = uvcoord;
  specular->color.set_value(shade::vec4<>(1., 0.4, 0.4, 1.));
  specular->coordinate_system = coordinate_system;
  coordinate_system->normal_map = tex_access;
  shader->material = specular;
  {
    shaders::IlluminatedMaterial::LightList::Accessor accessor(specular->lights);

    boost::shared_ptr<shaders::PointLight> light(new shaders::PointLight);
    light->position.set_value(shade::vec3<>(30., 15., 10.));
    light->color.set_value(shade::vec3<>(1., 1., 1.));
    accessor->push_back(light);

    boost::shared_ptr<shaders::PointLight> light2(new shaders::PointLight);
    light2->position.set_value(shade::vec3<>(-15., -3, 0.));
    light2->color.set_value(shade::vec3<>(1., 1., 1.));
    accessor->push_back(light2);
  }

  boost::shared_ptr<Displacement> displacement = boost::shared_ptr<Displacement>(new Displacement);
  shader->geometry = displacement;
  displacement->coordinate_system = coordinate_system.get();
  displacement->texture_unit.set(texture);

  state = shade::create_GLSL_wrapper();
  state->init();
  state->set_geometry_paramters(GL_TRIANGLES, GL_TRIANGLE_STRIP, 64);
  program = boost::shared_ptr<shade::Program>(new shade::Program(shader, state));

  if (std::getenv("DISPLACE_WIREFRAME"))
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
Exemple #5
0
void setup_plane_shading(osg::ref_ptr<osg::StateSet> osg_state, boost::shared_ptr<shade::Texture> plane_map)
{
    boost::shared_ptr<shade::GLSLWrapper> state(new shade::osg::Wrapper(osg_state));

    boost::shared_ptr<shade::shaders::Surface> shader(new shade::shaders::Surface);
    boost::shared_ptr<shade::Program> program(new shade::Program(shader, state));

    boost::shared_ptr<shade::shaders::Constant> plane_material(new shade::shaders::Constant());
    plane_material->color.set_value(shade::vec4<>(1., 0.4, 0.4, 1.));
    shader->material = plane_material;

    boost::shared_ptr<shade::shaders::Texture2D> texture(new shade::shaders::Texture2D);
    texture->texture_unit.set(plane_map);
    boost::shared_ptr<ScreenCoord> uvcoord(new ScreenCoord);
    texture->uv = uvcoord;
    plane_material->color = texture;

    program->compile();
    state->make_current();
    program->upload();
}