bool ATOM_InstanceMesh::setupParameters (ATOM_RenderDevice *device, ATOM_Camera *camera, ATOM_Material *material, bool skinning) { if (_mesh->diffuseTexture && _mesh->diffuseTexture->getLoadInterface()->getLoadingState () != ATOM_LoadInterface::LS_LOADED) { if (GT_HWINSTANCING == _mesh->geometry->getType()) { ((ATOM_HWInstancingGeometry*)_mesh->geometry)->clearInstances (); } return false; } ATOM_Texture *glareTexture = getGlareMap(); if (glareTexture && glareTexture->getLoadInterface()->getLoadingState () != ATOM_LoadInterface::LS_LOADED) { if (GT_HWINSTANCING == _mesh->geometry->getType()) { ((ATOM_HWInstancingGeometry*)_mesh->geometry)->clearInstances (); } return false; } ATOM_Vector4f diffuseColor = getDiffuseColor(); material->getParameterTable()->setVector ("viewPoint", ATOM_Vector4f(camera->getPosition ())); material->getParameterTable()->setMatrix44 ("viewProjectionMatrix", camera->getViewProjectionMatrix()); material->getParameterTable()->setMatrix44 ("viewProjectionMatrixGBuffer", camera->getProjectionMatrix()); material->getParameterTable()->setVector ("diffuseColor", diffuseColor); material->getParameterTable()->setMatrix44 ("worldMatrixGBuffer", camera->getViewProjectionMatrix()); ATOM_Texture *texture = getAlbedoMap (); material->getParameterTable()->setTexture ("diffuseTexture", texture?texture:_mesh->diffuseTexture.get()); material->getParameterTable()->setFloat ("depthScale", 1.f/ATOM_RenderSettings::getDepthScale()); return true; }
//---------------------------------------- void ofLight::setup() { if(glIndex==-1){ bool bLightFound = false; // search for the first free block for(int i=0; i<OF_MAX_LIGHTS; i++) { if(getActiveLights()[i] == false) { glIndex = i; retain(glIndex); bLightFound = true; break; } } if( !bLightFound ){ ofLog(OF_LOG_ERROR, "ofLight : Trying to create too many lights: " + ofToString(glIndex)); } if(bLightFound) { // run this the first time, since it was not found before // onPositionChanged(); setAmbientColor( getAmbientColor() ); setDiffuseColor( getDiffuseColor() ); setSpecularColor( getSpecularColor() ); setAttenuation( getAttenuationConstant(), getAttenuationLinear(), getAttenuationQuadratic() ); if(getIsSpotlight()) { setSpotlightCutOff(getSpotlightCutOff()); setSpotConcentration(getSpotConcentration()); } if(getIsSpotlight() || getIsDirectional()) { onOrientationChanged(); } } } }
int Material::ApplyMaterial(X3DDrawContext* pDC) { Graphics::Direct3D10_I* pD10 = pDC->m_renderContext->GetRT()->m_d3d10; Graphics::OpenGL_I* pGL = pDC->m_renderContext->GetRT()->m_opengl; if (pD10) { X3DMaterial material; memset(&material, 0, sizeof(material)); material.diffuseColor = Vec4f(getDiffuseColor(), 1); // material.ambientColor = Vec4f(getDiffuseColor(), 1); HRESULT hr = pD10->m_d3d10_materialVariable->SetRawValue(&material, 0, sizeof(X3DMaterial)); ASSERT(SUCCEEDED(hr)); } else { ASSERT(0); } #if 0 /* SFFloat* ambientIntensity = static_cast<SFFloat*>(m_ambientIntensity); SFColor* diffuseColor = static_cast<SFColor*>(m_diffuseColor); SFColor* emissiveColor = static_cast<SFColor*>(m_emissiveColor); SFFloat* shininess = static_cast<SFFloat*>(m_shininess); SFColor* specularColor = static_cast<SFColor*>(m_specularColor); SFFloat* transparency = static_cast<SFFloat*>(m_transparency); */ float MatEmiss[4] = { m_emissiveColor->m_value[0], m_emissiveColor->m_value[1], m_emissiveColor->m_value[2], 0}; float MatAmb[4] = { m_diffuseColor->m_value[0] * m_ambientIntensity->m_value, m_diffuseColor->m_value[1] * m_ambientIntensity->m_value, m_diffuseColor->m_value[2] * m_ambientIntensity->m_value, 0}; // ?? float MatDiff[4] = { m_diffuseColor->m_value[0], m_diffuseColor->m_value[1], m_diffuseColor->m_value[2], 1-m_transparency->m_value}; float MatSpec[4] = { m_specularColor->m_value[0], m_specularColor->m_value[1], m_specularColor->m_value[2], 0}; pDC->m_pGraphics3D->Materialfv(GL_FRONT_AND_BACK, GL_EMISSION, MatEmiss); pDC->m_pGraphics3D->Materialfv(GL_FRONT_AND_BACK, GL_AMBIENT, MatAmb); pDC->m_pGraphics3D->Materialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MatDiff); pDC->m_pGraphics3D->Materialfv(GL_FRONT_AND_BACK, GL_SPECULAR, MatSpec); pDC->m_pGraphics3D->Materialf(GL_FRONT_AND_BACK, GL_SHININESS, m_shininess->m_value*128); if (m_transparency->m_value > 0) { pDC->m_pGraphics3D->Disable(GL_DEPTH_TEST); pDC->m_pGraphics3D->Enable(GL_BLEND); pDC->m_pGraphics3D->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } #endif return 1; }
virtual void draw() { vec4 diffuse = getDiffuseColor(); vec4 glow = getGlowColor(); vec4 light = m_light_color; vec4 flash = getDamageColor(); if(getState()==State_Fadein) { float32 s = (float32)m_st_frame / FADEIN_TIME; float shininess = diffuse.w; diffuse *= stl::min<float32>(s*2.0f, 1.0f); diffuse.w = shininess; glow *= stl::max<float32>(s*2.0f-1.0f, 0.0f); light *= s; } else if(getState()==State_Fadeout) { float32 s = 1.0f - ((float32)m_st_frame / FADEOUT_TIME); light *= s; } if(m_light_radius > 0.0f) { if(atmGetConfig()->lighting_level>=atmE_Lighting_Medium) { PointLight l; l.setPosition(getPositionAbs() + vec3(0.0f, 0.0f, m_light_radius*0.5f)); l.setColor(light); l.setRadius(m_light_radius); atmGetLightPass()->addLight(l); } else { flash += light*0.05f; glow *= 2.0f; } } if(m_state!=State_Fadeout) { PSetInstance inst; inst.diffuse = diffuse; inst.glow = glow; inst.flash = flash; inst.elapsed = getPastTime(); inst.appear_radius = inst.elapsed * 0.004f; inst.transform = inst.rotate = getTransformMatrix(); atmGetFluidPass()->addParticles(getModel(), inst, computeNumParticles()); atmGetBloodStainPass()->addBloodstainParticles(getTransformMatrix(), getBloodStainParticles(), getNumBloodstainParticles()); } }
//---------------------------------------- void ofLight::setup() { if(data->glIndex==-1){ bool bLightFound = false; // search for the first free block for(size_t i=0; i<ofLightsData().size(); i++) { if(ofLightsData()[i].expired()) { data->glIndex = i; data->isEnabled = true; ofLightsData()[i] = data; bLightFound = true; break; } } if(!bLightFound && ofIsGLProgrammableRenderer()){ ofLightsData().push_back(data); data->glIndex = ofLightsData().size() - 1; data->isEnabled = true; bLightFound = true; } if( bLightFound ){ // run this the first time, since it was not found before // onPositionChanged(); setAmbientColor( getAmbientColor() ); setDiffuseColor( getDiffuseColor() ); setSpecularColor( getSpecularColor() ); setAttenuation( getAttenuationConstant(), getAttenuationLinear(), getAttenuationQuadratic() ); if(getIsSpotlight()) { setSpotlightCutOff(getSpotlightCutOff()); setSpotConcentration(getSpotConcentration()); } if(getIsSpotlight() || getIsDirectional()) { onOrientationChanged(); } }else{ ofLogError("ofLight") << "setup(): couldn't get active GL light, maximum number of "<< ofLightsData().size() << " reached"; } } }
Vec3f Material::Shade(const Ray &ray, const Hit &hit, const Vec3f &dirToLight, const Vec3f &lightColor, ArgParser *args) const { Vec3f point = ray.pointAtParameter(hit.getT()); Vec3f n = hit.getNormal(); Vec3f e = ray.getDirection()*-1.0f; Vec3f l = dirToLight; Vec3f answer = Vec3f(0,0,0); // emitted component // ----------------- answer += getEmittedColor(); // diffuse component // ----------------- double dot_nl = n.Dot3(l); if (dot_nl < 0) dot_nl = 0; answer += lightColor * getDiffuseColor(hit.get_s(),hit.get_t()) * dot_nl; // specular component (Phong) // ------------------ // make up reasonable values for other Phong parameters Vec3f specularColor = reflectiveColor; double exponent = 100; // compute ideal reflection angle Vec3f r = (l*-1.0f) + n * (2 * dot_nl); r.Normalize(); double dot_er = e.Dot3(r); if (dot_er < 0) dot_er = 0; answer += lightColor*specularColor*pow(dot_er,exponent)* dot_nl; return answer; }
glm::vec3 Material::Shade(const Ray &ray, const Hit &hit, const glm::vec3 &dirToLight, const glm::vec3 &lightColor, ArgParser *args) const { glm::vec3 point = ray.pointAtParameter(hit.getT()); glm::vec3 n = hit.getNormal(); glm::vec3 e = ray.getDirection()*-1.0f; glm::vec3 l = dirToLight; glm::vec3 answer = glm::vec3(0,0,0); // emitted component // ----------------- answer += getEmittedColor(); // diffuse component // ----------------- float dot_nl = glm::dot(n,l); if (dot_nl < 0) dot_nl = 0; answer += lightColor * getDiffuseColor(hit.get_s(),hit.get_t()) * dot_nl; // specular component (Phong) // ------------------ // make up reasonable values for other Phong parameters glm::vec3 specularColor = reflectiveColor; float exponent = 100; // compute ideal reflection angle glm::vec3 r = (l*-1.0f) + n * (2 * dot_nl); r = glm::normalize(r); float dot_er = glm::dot(e,r); if (dot_er < 0) dot_er = 0; answer += lightColor*specularColor*float(pow(dot_er,exponent))* dot_nl; return answer; }
// ----------------------------------------------------------------- // Name : clone // ----------------------------------------------------------------- guiObject * guiLabel::clone() { guiLabel * pObj = new guiLabel(); pObj->init(m_sText, m_FontId, getDiffuseColor(), m_sCpntId, m_iXPxl, m_iYPxl, m_iBoxWidth, m_iHeight); return pObj; }