Ejemplo n.º 1
0
SimpleShape::SimpleShape(vec3 position, vec3 aColour, vec3 dColour, vec3 sColour, float shine)
{
	setPosition(position);
	setAmbientColour(aColour);
	setDiffuseColour(dColour);
	setSpecularColour(sColour);
	setShininess(shine);
}
Ejemplo n.º 2
0
ccMaterial::ccMaterial(const QString& name)
	: m_name(name)
	, m_uniqueID(QUuid::createUuid().toString())
	, m_diffuseFront(ccColor::bright)
	, m_diffuseBack(ccColor::bright)
	, m_ambient(ccColor::night)
	, m_specular(ccColor::night)
	, m_emission(ccColor::night)
	, m_texMinificationFilter(QOpenGLTexture::Nearest)
	, m_texMagnificationFilter(QOpenGLTexture::Linear)
{
	setShininess(50.0);
};
Ejemplo n.º 3
0
 OSGMaterialStruct::OSGMaterialStruct(const mars::interfaces::MaterialData &mat)
 {
   setColorMode(osg::Material::OFF);
   setAmbient(osg::Material::FRONT, toOSGVec4(mat.ambientFront));
   setAmbient(osg::Material::BACK, toOSGVec4(mat.ambientBack));
   setSpecular(osg::Material::FRONT, toOSGVec4(mat.specularFront));
   setSpecular(osg::Material::BACK, toOSGVec4(mat.specularBack));
   setDiffuse(osg::Material::FRONT, toOSGVec4(mat.diffuseFront));
   setDiffuse(osg::Material::BACK, toOSGVec4(mat.diffuseBack));
   setEmission(osg::Material::FRONT, toOSGVec4(mat.emissionFront));
   setEmission(osg::Material::BACK, toOSGVec4(mat.emissionBack));
   setShininess(osg::Material::FRONT_AND_BACK, mat.shininess);
   setTransparency(osg::Material::FRONT_AND_BACK, mat.transparency);
 }
Ejemplo n.º 4
0
Phong::Phong(const Flags flags): transformationMatrixUniform(0), projectionMatrixUniform(1), normalMatrixUniform(2), lightUniform(3), diffuseColorUniform(4), ambientColorUniform(5), specularColorUniform(6), lightColorUniform(7), shininessUniform(8), _flags(flags) {
    #ifdef MAGNUM_BUILD_STATIC
    /* Import resources on static build, if not already */
    if(!Utility::Resource::hasGroup("MagnumShaders"))
        importShaderResources();
    #endif
    Utility::Resource rs("MagnumShaders");

    #ifndef MAGNUM_TARGET_GLES
    const Version version = Context::current().supportedVersion({Version::GL320, Version::GL310, Version::GL300, Version::GL210});
    #else
    const Version version = Context::current().supportedVersion({Version::GLES300, Version::GLES200});
    #endif

    Shader vert = Implementation::createCompatibilityShader(rs, version, Shader::Type::Vertex);
    Shader frag = Implementation::createCompatibilityShader(rs, version, Shader::Type::Fragment);

    vert.addSource(flags ? "#define TEXTURED\n" : "")
        .addSource(rs.get("generic.glsl"))
        .addSource(rs.get("Phong.vert"));
    frag.addSource(flags & Flag::AmbientTexture ? "#define AMBIENT_TEXTURE\n" : "")
        .addSource(flags & Flag::DiffuseTexture ? "#define DIFFUSE_TEXTURE\n" : "")
        .addSource(flags & Flag::SpecularTexture ? "#define SPECULAR_TEXTURE\n" : "")
        .addSource(rs.get("Phong.frag"));

    CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile({vert, frag}));

    attachShaders({vert, frag});

    #ifndef MAGNUM_TARGET_GLES
    if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>(version))
    #else
    if(!Context::current().isVersionSupported(Version::GLES300))
    #endif
    {
        bindAttributeLocation(Position::Location, "position");
        bindAttributeLocation(Normal::Location, "normal");
        if(flags) bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates");
    }

    CORRADE_INTERNAL_ASSERT_OUTPUT(link());

    #ifndef MAGNUM_TARGET_GLES
    if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version))
    #endif
    {
        transformationMatrixUniform = uniformLocation("transformationMatrix");
        projectionMatrixUniform = uniformLocation("projectionMatrix");
        normalMatrixUniform = uniformLocation("normalMatrix");
        lightUniform = uniformLocation("light");
        ambientColorUniform = uniformLocation("ambientColor");
        diffuseColorUniform = uniformLocation("diffuseColor");
        specularColorUniform = uniformLocation("specularColor");
        lightColorUniform = uniformLocation("lightColor");
        shininessUniform = uniformLocation("shininess");
    }

    #ifndef MAGNUM_TARGET_GLES
    if(flags && !Context::current().isExtensionSupported<Extensions::GL::ARB::shading_language_420pack>(version))
    #endif
    {
        if(flags & Flag::AmbientTexture) setUniform(uniformLocation("ambientTexture"), AmbientTextureLayer);
        if(flags & Flag::DiffuseTexture) setUniform(uniformLocation("diffuseTexture"), DiffuseTextureLayer);
        if(flags & Flag::SpecularTexture) setUniform(uniformLocation("specularTexture"), SpecularTextureLayer);
    }

    /* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */
    #ifdef MAGNUM_TARGET_GLES
    /* Default to fully opaque white so we can see the textures */
    if(flags & Flag::AmbientTexture) setAmbientColor(Color4{1.0f});
    else setAmbientColor(Color4{0.0f, 1.0f});

    if(flags & Flag::DiffuseTexture) setDiffuseColor(Color4{1.0f});

    setSpecularColor(Color4{1.0f});
    setLightColor(Color4{.0f});
    setShininess(80.0f);
    #endif
}
Ejemplo n.º 5
0
	Material::Material(const glm::vec3& ambientAndDiffuse) {
		setKa(ambientAndDiffuse);
		setKd(ambientAndDiffuse);
		setKs(glm::vec3(1.0f, 1.0f, 1.0f));
		setShininess(1.0f);
	}
Ejemplo n.º 6
0
void Material::setShininess(float f)
{
    auto ptr = lock();
    if ( ptr )
        ptr->setShininess(f);
}
Ejemplo n.º 7
0
	Material::Material() {
		setKa(glm::vec3(0.25f, 0.25f, 0.25f));
		setKd(glm::vec3(0.5f, 0.5f, 0.5f));
		setKs(glm::vec3(1.0f, 1.0f, 1.0f));
		setShininess(8.0f);
	}
Ejemplo n.º 8
0
	Material::Material(const glm::vec3& ambientAndDiffuse, const glm::vec3& Ks, const float& shininess) {
		setKa(ambientAndDiffuse);
		setKd(ambientAndDiffuse);
		setKs(Ks);
		setShininess(shininess);
	}
Ejemplo n.º 9
0
	Material::Material(const glm::vec3& Ka, const glm::vec3& Kd) {
		setKa(Ka);
		setKd(Kd);
		setKs(glm::vec3(1.0f, 1.0f, 1.0f));
		setShininess(1.0f);
	}
Ejemplo n.º 10
0
	Material::Material(const glm::vec3& Ka, const glm::vec3& Kd, const glm::vec3& Ks) {
		setKa(Ka);
		setKd(Kd);
		setKs(Ks);
		setShininess(1.0f);
	}
Ejemplo n.º 11
0
	Material::Material(const glm::vec3& Ka, const glm::vec3& Kd, const glm::vec3& Ks, const float& shininess) {
		setKa(Ka);
		setKd(Kd);
		setKs(Ks);
		setShininess(shininess);
	}
Ejemplo n.º 12
0
Material::Material()
{
    setReflection(Vector3(0));
    setRefraction(Vector3(0), 1);
    setShininess(infinity); //Default to a perfectly reflective surface if the specular component is non-zero
}
Ejemplo n.º 13
0
unsigned int MaterialMgr::load(FILE* f)
{
  char buffer[512];
  char* retval = NULL;
  unsigned int matId =  INVALID_MATERIAL;

  retval = fgets(buffer, sizeof(buffer), f);
  char* name;
  if ( (name = FindProperty(retval, "Name")) != NULL)
  {
    matId = addMaterial(name);

    retval = fgets(buffer, sizeof(buffer), f);
    char* coloreR;
    int ColoreR;
    if ( (coloreR = FindProperty(retval, "ColoreR")) == NULL)
    {
      remMaterial(matId);
      return INVALID_MATERIAL;
    }
    ColoreR = atoi(coloreR);

    retval = fgets(buffer, sizeof(buffer), f);
    char* coloreG;
    int ColoreG;
    if ( (coloreG = FindProperty(retval, "ColoreG")) == NULL)
    {
      remMaterial(matId);
      return INVALID_MATERIAL;
    }
    ColoreG = atoi(coloreG);

     
    retval = fgets(buffer, sizeof(buffer), f);
    char* coloreB;
    int ColoreB;
    if ( (coloreB = FindProperty(retval, "ColoreB")) == NULL)  
    {
      remMaterial(matId);
      return INVALID_MATERIAL;
    }
    ColoreB = atoi(coloreB);

    setColor(matId, ColoreR, ColoreG, ColoreB);

    //Specular
    retval = fgets(buffer, sizeof(buffer), f);
    char* szSpecular;
    int nSpecular;
    if ( (szSpecular = FindProperty(retval, "Specular")) == NULL)
    {
      remMaterial(matId);
      return INVALID_MATERIAL;
    }
    nSpecular = atoi(szSpecular);

    setSpecular(matId, nSpecular);
    //Specular


    //Shininess
    retval = fgets(buffer, sizeof(buffer), f);
    char* szShininess;
    int nShininess;
    if ( (szShininess = FindProperty(retval, "Shininess")) == NULL)
    {
      remMaterial(matId);
      return INVALID_MATERIAL;
    }
    nShininess = atoi(szShininess);

    setShininess(matId, nShininess);
    //Shininess


    //Luminosity
    retval = fgets(buffer, sizeof(buffer), f);
    char* szLuminosity;
    int nLuminosity;
    if ( (szLuminosity = FindProperty(retval, "Luminosity")) == NULL)
    {
      remMaterial(matId);
      return INVALID_MATERIAL;
    }
    nLuminosity = atoi(szLuminosity);

    setLuminosity(matId, nLuminosity);
    //Luminosity


    //Emission
    retval = fgets(buffer, sizeof(buffer), f);
    char* szEmission;
    int nEmission;
    if ( (szEmission = FindProperty(retval, "Emission")) == NULL)
    {
      remMaterial(matId);
      return INVALID_MATERIAL;
    }
    nEmission = atoi(szEmission);
    setEmission(matId, nEmission);
    //Emission


    //Trasparency
    retval = fgets(buffer, sizeof(buffer), f);
    char* szTrasparency;
    int nTrasparency;
    if ( (szTrasparency = FindProperty(retval, "Trasparency")) == NULL)
    {
      remMaterial(matId);
      return INVALID_MATERIAL;
    }
    nTrasparency = atoi(szTrasparency);

    setTrasparency(matId, nTrasparency);
    //Trasparency    
  }

  return matId;
}