bool DSLightChunk::operator == (const StateChunk &other) const { const DSLightChunk *tother = dynamic_cast<const DSLightChunk *>(&other); if(!tother) return false; if(tother == this) return true; if(!getAmbient ().equals(tother->getAmbient (), TypeTraits<Real32>::getDefaultEps()) || !getDiffuse ().equals(tother->getDiffuse (), TypeTraits<Real32>::getDefaultEps()) || !getSpecular ().equals(tother->getSpecular (), TypeTraits<Real32>::getDefaultEps()) || !getPosition ().equals(tother->getPosition (), TypeTraits<Real32>::getDefaultEps()) || !getDirection().equals(tother->getDirection(), TypeTraits<Real32>::getDefaultEps()) || getConstantAttenuation () != tother->getConstantAttenuation () || getLinearAttenuation () != tother->getLinearAttenuation () || getQuadraticAttenuation() != tother->getQuadraticAttenuation() || getCutoff () != tother->getCutoff () || getExponent () != tother->getExponent () ) { return false; } return true; }
const Color& Material::getSpecular() const { auto ptr = lock(); if ( ptr ) return ptr->getSpecular(); throw GreInvalidUserException("Material"); }
//! output the instance for debug purposes void DVRVolume::dump( UInt32 uiIndent, const BitVector ) const { DVRVolumePtr thisP(*this); thisP.dump(uiIndent, FCDumpFlags::RefCount); indentLog(uiIndent, PLOG); PLOG << "DVRVolume at " << this << std::endl; indentLog(uiIndent, PLOG); PLOG << "\trenderMaterial: " << getRenderMaterial() << std::endl; if (getRenderMaterial() != NullFC) getRenderMaterial()->dump(uiIndent); indentLog(uiIndent, PLOG); PLOG << "\ttextureStorage: " << getTextureStorage() << std::endl; if (getTextureStorage() != NullFC) getTextureStorage()->dump(uiIndent); #if 0 indentLog(uiIndent, PLOG); PLOG << "\tambient: " << getAmbient() << endl; indentLog(uiIndent, PLOG); PLOG << "\tdiffuse: " << getDiffuse() << endl; indentLog(uiIndent, PLOG); PLOG << "\tspecular: " << getSpecular() << endl; indentLog(uiIndent, PLOG); PLOG << "\tshininess: " << getShininess() << endl; indentLog(uiIndent, PLOG); PLOG << "\temission: " << getEmission() << endl; indentLog(uiIndent, PLOG); PLOG << "\ttransparency: " << getTransparency() << endl; indentLog(uiIndent, PLOG); PLOG << "\tlit: " << getLit() << endl; indentLog(uiIndent, PLOG); PLOG << "\tChunks: " << endl; for(MFStateChunkPtr::const_iterator i = _mfChunks.begin(); i != _mfChunks.end(); i++) { indentLog(uiIndent, PLOG); PLOG << "\t" << *i << endl; } #endif indentLog(uiIndent, PLOG); PLOG << "DVRVolume end " << this << std::endl; }
StatePtr PhongMaterial::makeState(void) { StatePtr state = State::create(); prepareLocalChunks(); Color3f v3; Color4f v4; float alpha = 1.f - getTransparency(); prepareLocalChunks(); beginEditCP(_materialChunk); v3 = getAmbient(); v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha); _materialChunk->setAmbient(v4); v3 = getDiffuse(); v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha); _materialChunk->setDiffuse(v4); v3 = getSpecular(); v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha); _materialChunk->setSpecular(v4); _materialChunk->setShininess(getShininess()); v3 = getEmission(); v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha); _materialChunk->setEmission(v4); _materialChunk->setLit(getLit()); _materialChunk->setColorMaterial(getColorMaterial()); endEditCP (_materialChunk); state->addChunk(_materialChunk); if(isTransparent()) state->addChunk(_blendChunk); if(_vpChunk != NullFC) state->addChunk(_vpChunk); createFragmentProgram(); if(_fpChunk != NullFC) state->addChunk(_fpChunk); for(MFStateChunkPtr::iterator i = _mfChunks.begin(); i != _mfChunks.end(); ++i) { state->addChunk(*i); } return state; }
void Candle::draw() { //Material GLfloat candle_amb[] = {0.55f,0.27f,0.05f,1.0f}; GLfloat candle_diff[] = {0.92f,0.61f,0.1f,1.0f}; GLfloat candle_spec[] = {0.53f,0.0f,0.0f,1.0f}; GLfloat candle_shine = 128; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, candle_amb); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, candle_diff); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, candle_spec); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, candle_shine); //Solido glColor3d(1.0, 1.5, 0); glPushMatrix(); glTranslated(getPosition()->getX(), getPosition()->getY(), 0.625); glScalef(1.0, 1.0, 10); glutSolidCube(0.025); glPopMatrix(); //Propriedades Luz GLfloat amb[] = { getAmbient()->getX(), getAmbient()->getY(), getAmbient()->getZ(), getAmbient()->getW() }; GLfloat diffuse[] = { getDiffuse()->getX(), getDiffuse()->getY(), getDiffuse()->getZ(),getDiffuse()->getW() }; GLfloat specular[] = { getSpecular()->getX(), getSpecular()->getY(), getSpecular()->getZ(), getSpecular()->getW() }; GLfloat pos[] = { getPosition()->getX(), getPosition()->getY(), 1.0, 1.0 }; glLightfv(_num, GL_AMBIENT, amb); glLightfv(_num, GL_DIFFUSE, diffuse); glLightfv(_num, GL_SPECULAR, specular); glLightfv(_num, GL_POSITION, pos); //atenuacao da luz glLightf(_num, GL_CONSTANT_ATTENUATION, 0); glLightf(_num, GL_LINEAR_ATTENUATION, 0); glLightf(_num, GL_QUADRATIC_ATTENUATION, 7); }
Color3 getPhong(const Vector3& p , const Vector3& visionDir , const Vector3& normal , const Vector3& lightSourcePos , const Color3& lightIntensity , Geometry* obj , const Real& directCoe) { Vector3 lightDir = lightSourcePos - p; lightDir.normalize(); Vector3 reflecDir = normal * ((normal ^ lightDir) * 2.0) - lightDir; reflecDir.normalize(); Color3 diffuseIntensity = getDiffuse(lightDir , normal , lightIntensity , obj->get_diffuse_color(p)); Color3 specularIntensity = getSpecular(reflecDir , visionDir , lightIntensity , obj->get_material().specular); Color3 ambientIntensity = getAmbient(lightIntensity , obj->get_material().ambient); Color3 res = (diffuseIntensity + specularIntensity) * directCoe + ambientIntensity; res.clamp(); return res; }
void MaterialMgr::save(FILE* f, unsigned int matId) { MAT_ID_OK(matId); const char* matName; if ((matName = getName(matId)) && (matName[0] != '#')) { fprintf(f, "\r\n#Material\r\n"); fprintf(f, "Name=%s\r\n", getName(matId)); fprintf(f, "ColoreR=%i\r\n", getColorRed(matId)); fprintf(f, "ColoreG=%i\r\n", getColorGreen(matId)); fprintf(f, "ColoreB=%i\r\n", getColorBlue(matId)); fprintf(f, "Specular=%i\r\n", getSpecular(matId)); fprintf(f, "Shininess=%i\r\n", getShininess(matId)); fprintf(f, "Luminosity=%i\r\n", getLuminosity(matId)); fprintf(f, "Emission=%i\r\n", getEmission(matId)); fprintf(f, "Trasparency=%i\r\n", getTrasparency(matId)); } }
Vector getPixel(Ray ray, Stack * stack, real magnitude, real refractiveIndex, int depth, ulong *seed) { ItemPtr item = getClosestItem(ray); if(item==NULL) { return ZERO; } Vector point = getIntersectPoint(item, ray) + ray.from; int specularRoughness = getSpecularRoughness(item, point); Vector normal = getNormal(item, ray, point); Vector diffuseColor = ZERO; Vector specularColor = ZERO; Ray reflection; reflection.ray = reflect(ray.ray, normal); reflection.from = point+(reflection.ray*.001f); if(length2(getDiffuse(item, point))>0 || length2(getSpecular(item, point))>0) { for(int i=0;i<lightNumber;i++) { ItemPtr light = &lights[i]; Vector lightVector = light->center-point; Vector lightPixel = fast_normalize(lightVector); real diffuseFactor = dot(normal, lightPixel); real specularFactor = dot(reflection.ray, lightPixel); if(diffuseFactor>0 || specularFactor>0) { int hitLight=0; Ray movedLightRay; movedLightRay.from=reflection.from; Vector right = getRight(lightPixel); Vector up = getUp(lightPixel, right); for(int i=0;i<SHADOW_RUNS;i++) { //TODO: this can be much faster methinks real r = random(seed)*2-1; real u = random(seed)*sqrt(1-r*r); movedLightRay.ray = fast_normalize(lightVector+right*r*light->radius+up*u*light->radius); ItemPtr closestItem = getClosestItem(movedLightRay); if(closestItem!=NULL && closestItem->type==LIGHT) { hitLight++; } } if(hitLight > 0) { real lightValue = ((real)hitLight) / SHADOW_RUNS; if(diffuseFactor>0) { diffuseFactor *= lightValue; diffuseColor = diffuseColor+light->light*diffuseFactor; } if(specularFactor>0) { specularFactor = lightValue * pow(specularFactor, specularRoughness); specularColor = specularColor+light->light*specularFactor; } } } } } Vector color = (diffuseColor*getDiffuse(item, point)+specularColor*getSpecular(item, point)) * magnitude; if(depth > 0) { Ray refraction; if(getRefraction(item, point)) { refraction.ray = refract(ray.ray, normal, item, refractiveIndex); refraction.from = point+(refraction.ray*.001f); if(length2(refraction.ray)>0) { push(stack, depth-1, refraction, magnitude, getRefraction(item, point)); } } if(getReflection(item, point) > 0) { push(stack, depth-1, reflection, magnitude * getReflection(item, point), refractiveIndex); } } return color; }