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::getAmbient() const { auto ptr = lock(); if ( ptr ) return ptr->getAmbient(); 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; }
Colour Scene::getColourAtIntersection(const Ray &r, const NodeIntersection &ni, const Colour &cEnvironment, uint8_t rayRecursion) const { /* * Do a simple variation on the phong lighting model. This could be improved. * * In my ray tracer the Colour class is analogous to a spectral distribution. * (ie: light flux) */ /* * Evaluation of material properties at this intersection. */ Colour cDiffuse; Colour cSpecular; double phongCoeff = 0.0; double reflectivity = 0.0; double opacity = 1.0; double indexOfRefraction = 1.0; PrimitivePatch bumpedPatch = ni.pPatch; if (ni.mat) { ni.mat->evaluate(ni.pPatch, &cDiffuse, &cSpecular, &phongCoeff, &reflectivity, &opacity, &indexOfRefraction); ni.mat->evaluateBumpMap(ni.pPatch, &bumpedPatch); } /* * Calculate the lighting. */ // XXX need to calculate light attenuation due to distance. Colour diffuseLight; Colour specularLight; for(std::list<Light*>::const_iterator lightIter = mLights.begin(); lightIter != mLights.end(); lightIter++) { Light &curLight = **lightIter; double intersectionTransmissiveness = 0.0; Ray patchToCurLightRay(bumpedPatch.p, normalize(curLight.getPosition() - bumpedPatch.p)); /* * Check if there are any obstructions. */ if (!intersects(patchToCurLightRay, &intersectionTransmissiveness) || !isZero(intersectionTransmissiveness)) { // Rely on short-circuit || to test intersects && intersectionTransmissiveness > 0.0 // Diffuse - cosine weighted angle between normal and light source double diffuseWeight = dot(bumpedPatch.shadingNorm, patchToCurLightRay.d); if (lessThanZero(diffuseWeight)) { diffuseWeight = 0.0; } diffuseLight += (diffuseWeight //* intersectionTransmissiveness * curLight.getColour()); /* * Specular - exponential of cosine weighted angle between the incoming * ray and the reflected ray from the light source. */ Vector reflected = normalize(computeReflection(-patchToCurLightRay.d, bumpedPatch)); double specularWeight = dot(reflected, normalize(-r.d)); if (lessThanZero(specularWeight)) { specularWeight = 0.0; } specularLight += (pow(specularWeight, phongCoeff) * curLight.getColour()); } } /* * Recursive case. */ if (rayRecursion > 0) { /* * Check to see if the material is reflective or transmissive. If it is * this will directly affect the diffuse Colour before it is used in the * final colour computation. */ Ray recR; NodeIntersection recNI; Colour recColour; if (reflectivity > 0.0) { recR = Ray(bumpedPatch.p, computeReflection(r.d, bumpedPatch)); if (intersect(recR, &recNI)) { recColour = getColourAtIntersection(recR, recNI, cEnvironment, rayRecursion - 1); // Do a simple Alpha composite. cDiffuse = (cDiffuse * (1-reflectivity)) + (recColour * reflectivity); } else { // Didn't intersect with anything so take the env colour. cDiffuse = (cDiffuse * (1-reflectivity)) + (cEnvironment * reflectivity); } } if (opacity < 1.0) { // XXX need to work out the refraction using Snell's law. recR = Ray(bumpedPatch.p, r.d); if (intersect(recR, &recNI)) { recColour = getColourAtIntersection(recR, recNI, cEnvironment, rayRecursion - 1); // Do a simple Alpha composite. cDiffuse = (cDiffuse * opacity) + (recColour * (1 - opacity)); } else { // Didn't intersect with anything so take the env colour. cDiffuse = (cDiffuse * opacity) + (cEnvironment * (1 - opacity)); } } } /* * Base Case. */ /* * Apply lighting calculations onto the diffuse and specular lighting * components of the material evaluated at the curent intersection point. */ Colour c = getAmbient(); // XXX need to multiply emmissive component if the object is a light source. if (!cDiffuse.isBlack()) { c += cDiffuse * diffuseLight; } // Need to calculate attenuation from distance of the light if (!cSpecular.isBlack()) { c += cSpecular * specularLight; } return c; }