Shadow *Shadow::createShadow(Toplevel *toplevel) { if (!effects) { return NULL; } QVector<long> data = Shadow::readX11ShadowProperty(toplevel->window()); if (!data.isEmpty()) { Shadow *shadow = NULL; if (effects->compositingType() == OpenGLCompositing) { shadow = new SceneOpenGLShadow(toplevel); } else if (effects->compositingType() == XRenderCompositing) { #ifdef KWIN_HAVE_XRENDER_COMPOSITING shadow = new SceneXRenderShadow(toplevel); #endif } if (shadow) { if (!shadow->init(data)) { delete shadow; return NULL; } if (toplevel->effectWindow() && toplevel->effectWindow()->sceneWindow()) { toplevel->effectWindow()->sceneWindow()->updateShadow(shadow); } } return shadow; } else { return NULL; } }
void ToolbarPanel::OnSetOuterColor(wxCommandEvent& event) { Shadow* shadow = m_stage->GetSymbol()->GetShadow(); ee::RGBColorSettingDlg dlg(this, NULL, shadow->GetOuterColor()); if (dlg.ShowModal() == wxID_OK) { shadow->SetOuterColer(dlg.GetColor()); shadow->BuildFace(); ee::SetCanvasDirtySJ::Instance()->SetDirty(); } }
void Scroll::st(Widget *v) { Shadow *s; if(scroll) delete scroll; scroll=v; v->stscroll(); v->stborder(s=new Shadow()); s->ststyle(0,2,0); v->stx(0); v->sty(0); v->stsizenotifyfn(new Fn1_0<void,Scroll *>(dosizenotify,this)); add(v); }
void ToolbarPanel::SetValue(int key, const ee::UICallback::Data& data) { switch (key) { case S_RADIUS: { Shadow* shadow = m_stage->GetSymbol()->GetShadow(); shadow->SetRadius(data.val0); shadow->BuildOutterLine(); ee::SetCanvasDirtySJ::Instance()->SetDirty(); } break; } }
FBOTextureMaterial::FBOTextureMaterial(const std::string &jsonFileName, SPtr<ShaderProgram> shaderProgram, Shadow &fb) : Material(jsonFileName, shaderProgram) { texture_id = fb.getTextureID(); uTexture = shaderProgram->getUniform("uTexture"); aTexCoord = shaderProgram->getAttribute("aTexCoord"); }
Shadow *Shadow::createShadow(Toplevel *toplevel) { if (!effects) { return NULL; } auto data = Shadow::readX11ShadowProperty(toplevel->window()); if (!data.isEmpty()) { Shadow *shadow = Compositor::self()->scene()->createShadow(toplevel); if (!shadow->init(data)) { delete shadow; return NULL; } if (toplevel->effectWindow() && toplevel->effectWindow()->sceneWindow()) { toplevel->effectWindow()->sceneWindow()->updateShadow(shadow); } return shadow; } else { return NULL; } }
bool Engine::makeShadowForObject(GameObject* object, const InterfaceId id) { uid objectId = object->getObjectId(); if (idHash[id].find(objectId) != idHash[id].end()) { log_msg("error engine", "Duplicate object " + IntToStr(objectId) + " in shadow"); return false; } Shadow* newStorage = shadowClassFactory(object, id); if (newStorage == NULL) { log_msg("error engine", "Cannot find shadow for object " + IntToStr(objectId)); return false; } int shadowIndex = addShadow(newStorage, id); idHash[id][objectId] = shadowIndex; newStorage->shadowIndex = shadowIndex; newStorage->fill(object); makeShadowForObjectPost(object, newStorage); return true; }
static void display() { // Compute test camera [the one we will use for shadowing] Frustum cf(PM_PERSPECTIVE, fovy, aspect, nplane, fplane); cf.update(); cam_mv = Matrix4::MakeTranslate(Vector3(0, 0, -cam_dtt)); cam_mv *= Matrix4::MakeRotate(-cam_ypr[2], Vector3::UNIT_Z); cam_mv *= Matrix4::MakeRotate(-cam_ypr[1], Vector3::UNIT_X); cam_mv *= Matrix4::MakeRotate(-cam_ypr[0], Vector3::UNIT_Y); cam_mv *= Matrix4::MakeTranslate(-cam_aim); cam_imv = cam_mv.getFastInverse(); cam_proj = cf.getProjectionMatrix(); cam_mv2 = Matrix4::MakeTranslate(Vector3(0, 0, -cam_dtt2)); cam_mv2 *= Matrix4::MakeRotate(-cam_ypr2[2], Vector3::UNIT_Z); cam_mv2 *= Matrix4::MakeRotate(-cam_ypr2[1], Vector3::UNIT_X); cam_mv2 *= Matrix4::MakeRotate(-cam_ypr2[0], Vector3::UNIT_Y); cam_mv2 *= Matrix4::MakeTranslate(-cam_aim2); cam_imv2 = cam_mv2.getFastInverse(); cam_proj2 = cf.getProjectionMatrix(); // Compute Scene bounding box AABox sceneBB; unsigned int i; Vector3 off1(-10.0f, 0, -5.0f); Vector3 off2(2.0f, 0, 10.0f); Vector3 off3(10.0, 2.0f, -2.0f); for (i=0; i<CubeVertexCount; ++i) { sceneBB.merge(Vector3(CubeVertexData[i].pos)); sceneBB.merge(Vector3(CubeVertexData[i].pos) + off1); sceneBB.merge(Vector3(CubeVertexData[i].pos) + off2); sceneBB.merge(Vector3(CubeVertexData[i].pos) + off3); } for (i=0; i<PlaneVertexCount; ++i) { sceneBB.merge(Vector3(PlaneVertexData[i].pos)); } // Compute light params light_pos_eye = Vector3(cam_mv * light_pos); if (!useAdvShadows) { light_mv = Matrix4::MakeLookAt(Vector3(light_pos), light_aim, Vector3::UNIT_Y); light_imv = light_mv.getFastInverse(); Frustum lf(PM_PERSPECTIVE, 120, 1, nplane, fplane); lf.update(); light_proj = lf.getProjectionMatrix(); } else { #ifndef NEW_SHADOW shadow.setType(stype); #endif shadow.setSceneParameters(sceneBB, sceneBB); shadow.setShadowParameters(100.0f, 0.1f, shadowSize, 10000.0f); shadow.setCameraParameters(fovy, aspect, nplane, fplane, cam_mv); if (ltype == LT_DIR) { shadow.setDirLightParameters(light_dir); } else if (ltype == LT_SPOT) { shadow.setSpotLightParameters(Vector3(light_pos), light_dir, 80, 89); } else { shadow.setPointLightParameters(Vector3(light_pos)); } shadow.compute(); light_proj = shadow.getLightProj(); light_mv = shadow.getLightView(); light_imv = light_mv.getFastInverse(); } // RTT FBObind(); glClearColor(1,1,1,1); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glViewport(0, 0, shadowSize, shadowSize); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMultMatrixf(light_proj); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrixf(light_mv); cprog->bind(); #ifdef NEW_SHADOW //cprog->uniform("LS")->set(shadow.getLightView()); as set in light view, do not need to pass it cprog->uniform("depthOffset")->set(0.0f); #endif CubeMesh->render(); glPushMatrix(); glTranslatef(off1.x, off1.y, off1.z); CubeMesh->render(); glPopMatrix(); glPushMatrix(); glTranslatef(off2.x, off2.y, off2.z); CubeMesh->render(); glPopMatrix(); glPushMatrix(); glTranslatef(off3.x, off3.y, off3.z); CubeMesh->render(); glPopMatrix(); cprog->unbind(); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); FBOunbind(); // RTW glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // DRAW FIRST VIEWPORT // glViewport(0, 0, scr_hwidth, scr_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMultMatrixf(cam_proj); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrixf(cam_mv); // show light glLightfv(GL_LIGHT0, GL_POSITION, light_pos); glPushMatrix(); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glColor3f(0.8, 0.8, 0); glTranslatef(light_pos[0], light_pos[1], light_pos[2]); glutSolidSphere(1, 16, 16); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glPopMatrix(); // render cube MESHsetMaterial(&CubeMaterial); glBindTexture(GL_TEXTURE_2D, 0); CubeMesh->render(); glPushMatrix(); glTranslatef(off1.x, off1.y, off1.z); CubeMesh->render(); glPopMatrix(); glPushMatrix(); glTranslatef(off2.x, off2.y, off2.z); CubeMesh->render(); glPopMatrix(); glPushMatrix(); glTranslatef(off3.x, off3.y, off3.z); CubeMesh->render(); glPopMatrix(); // render plane width shadows Matrix4 eyeToLightProj = light_proj * light_mv * cam_imv; MESHsetMaterial(&PlaneMaterial); rprog->bind(); glBindTexture(GL_TEXTURE_2D, colorMap0); rprog->uniform("shadowMap")->set(GLint(0)); rprog->uniform("depthBias")->set(0.0f); // should be on caster !!! rprog->uniform("shadowWidth")->set((GLint)shadowSize); rprog->uniform("lightPosEye")->set(light_pos_eye); rprog->uniform("eyeToLightProj")->set(eyeToLightProj); #ifdef NEW_SHADOW rprog->uniform("LS")->set(light_mv * cam_imv); #endif PlaneMesh->render(); /* MESHsetMaterial(&CubeMaterial); glBindTexture(GL_TEXTURE_2D, 0); CubeMesh->render(); glPushMatrix(); glTranslatef(off1.x, off1.y, off1.z); CubeMesh->render(); glPopMatrix(); glPushMatrix(); glTranslatef(off2.x, off2.y, off2.z); CubeMesh->render(); glPopMatrix(); glPushMatrix(); glTranslatef(off3.x, off3.y, off3.z); CubeMesh->render(); glPopMatrix(); */ rprog->unbind(); // Draw Second viewport if (dbview == DV_HULLS) { glViewport(scr_hwidth, 0, scr_hwidth, scr_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMultMatrixf(cam_proj2); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrixf(cam_mv2); glLightfv(GL_LIGHT0, GL_POSITION, light_pos); glPushMatrix(); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glColor3f(0.8, 0.8, 0); glTranslatef(light_pos[0], light_pos[1], light_pos[2]); glutSolidSphere(1, 16, 16); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glPopMatrix(); MESHsetMaterial(&CubeMaterial); glBindTexture(GL_TEXTURE_2D, 0); CubeMesh->render(); glPushMatrix(); glTranslatef(off1.x, off1.y, off1.z); CubeMesh->render(); glPopMatrix(); glPushMatrix(); glTranslatef(off2.x, off2.y, off2.z); CubeMesh->render(); glPopMatrix(); glPushMatrix(); glTranslatef(off3.x, off3.y, off3.z); CubeMesh->render(); glPopMatrix(); MESHsetMaterial(&PlaneMaterial); PlaneMesh->render(); // render hulls / frustums #ifndef NEW_SHADOW if (useAdvShadows) { Vector3 fc = Vector3(0.8f, 0.5f, 0.2f); Vector3 bc = Vector3(0.2f, 0.2f, 0.7f); renderHull(shadow.getBodyFocus(), bc, Matrix4::IDENTITY); renderHull(shadow.getBodyB(), fc, Matrix4::IDENTITY); } glPushMatrix(); glColor3f(0.7f, 0.2f, 0.2f); glTranslatef(shadow.getE().x, shadow.getE().y, shadow.getE().z); glutSolidSphere(0.1, 16, 16); glPopMatrix(); #else // new shadow draw stuff Vector3 fc = Vector3(0.8f, 0.5f, 0.2f); Vector3 bc = Vector3(0.2f, 0.2f, 0.7f); ConvexHull3D ch; shadow.calcB(NULL, &ch); renderHull(ch, bc, Matrix4::IDENTITY); shadow.calcLVS(NULL, &ch); renderHull(ch, fc, Matrix4::IDENTITY); glPushMatrix(); glColor3f(0.7f, 0.2f, 0.2f); glTranslatef(shadow.getE().x, shadow.getE().y, shadow.getE().z); glutSolidSphere(0.1, 16, 16); glPopMatrix(); #endif } else if (dbview == DV_PPS) { glViewport(scr_hwidth, 0, scr_hwidth, scr_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); glMultMatrixf(light_proj); glMultMatrixf(light_mv); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); // in PPS, z is inversed !!! glDisable(GL_TEXTURE_2D); glColor3fv(PlaneMaterial.diff); PlaneMesh->render(); glPushMatrix(); glColor3f(0.7f, 0.2f, 0.2f); glTranslatef(cam_imv(0,3), cam_imv(1,3), cam_imv(2,3)); glutSolidSphere(0.1, 16, 16); glPopMatrix(); glColor3fv(CubeMaterial.diff); CubeMesh->render(); glPushMatrix(); glTranslatef(off1.x, off1.y, off1.z); CubeMesh->render(); glPopMatrix(); glPushMatrix(); glTranslatef(off2.x, off2.y, off2.z); CubeMesh->render(); glPopMatrix(); glPushMatrix(); glTranslatef(off3.x, off3.y, off3.z); CubeMesh->render(); glPopMatrix(); #ifndef NEW_SHADOW Vector3 fc = Vector3(0.8f, 0.5f, 0.2f); Vector3 bc = Vector3(0.2f, 0.2f, 0.7f); renderHull(shadow.getBodyLVS(), fc, Matrix4::IDENTITY); renderHull(shadow.getBodyB(), bc, Matrix4::IDENTITY); #else // new shadow stuff Vector3 fc = Vector3(0.8f, 0.5f, 0.2f); Vector3 bc = Vector3(0.2f, 0.2f, 0.7f); ConvexHull3D ch; shadow.calcB(NULL, &ch); renderHull(ch, bc, Matrix4::IDENTITY); #endif glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glPopMatrix(); } #ifdef NEW_SHADOW else if (dbview == DV_NT) { std::cout << "Debug TSM" << std::endl; drawTSM(shadow.getTSMData()); } #endif /* RENDER QUAD glPushMatrix(); glLoadIdentity(); glDisable(GL_LIGHTING); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, colorMap0); float top = 10 * tan(DegToRad * 0.5 * fovy); float left = top * aspect; glBegin(GL_QUADS); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0); glVertex3f(-left, -top, -10); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0); glVertex3f(left, -top, -10); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1); glVertex3f(left, top, -10); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1); glVertex3f(-left, top, -10); glEnd(); glEnable(GL_LIGHTING); glPopMatrix(); */ glutSwapBuffers(); }
static void keyboard(unsigned char key, int, int) { switch (key) { case 27: exit(0); //case 'p': // useAdvShadows = !useAdvShadows; // cout << (useAdvShadows ? "Advanced shadow mode" : "Simple shadow mode") << endl; // glutPostRedisplay(); // break; #ifdef NEW_SHADOW case '+': if (useAdvShadows && advShadowType == TSM) { shadow.setTSMStep(shadow.getTSMStep()+1); glutPostRedisplay(); } break; case '-': if (useAdvShadows && advShadowType == TSM) { shadow.setTSMStep(shadow.getTSMStep()-1); glutPostRedisplay(); } break; case 'a': if (useAdvShadows && advShadowType == TSM) { shadow.tryTSMCorrection(!shadow.tryTSMCorrection()); glutPostRedisplay(); } break; case 'z': orthoRange *= 0.5f; if (orthoRange <= 0.0f) { orthoRange = 1.0f; } glutPostRedisplay(); break; case 'Z': orthoRange *= 2.0f; glutPostRedisplay(); break; #endif case 's': #ifndef NEW_SHADOW if (!useAdvShadows) { useAdvShadows = true; stype = Shadow::ST_CUSTOM; cout << "Shadow algorithm: Custom" << endl; } else { if (stype == Shadow::ST_CUSTOM) { stype = Shadow::ST_UNIFORM; cout << "Shadow algorithm: Uniform" << endl; } else if (stype == Shadow::ST_UNIFORM) { stype = Shadow::ST_LiSPSM; cout << "Shadow algorithm: LiSPSM" << endl; } else if (stype == Shadow::ST_LiSPSM) { stype = Shadow::ST_UNIFORM2; cout << "Shadow algorithm: Uniform v2" << endl; } else if (stype == Shadow::ST_UNIFORM2) { stype = Shadow::ST_LiSPSM2; cout << "Shadow algorithm: LiSPSM v2" << endl; } else if (stype == Shadow::ST_LiSPSM2) { useAdvShadows = false; cout << "Shadow algorithm: Basic" << endl; } } #else if (useAdvShadows) { if (advShadowType == FOCUSED) { advShadowType = LiSPSM; shadow.useLiSPSM(true); shadow.useTSM(false); cout << "Shadow algorithm: LiSPSM" << endl; } else if (advShadowType == LiSPSM) { advShadowType = TSM; shadow.useLiSPSM(false); shadow.useTSM(true); cout << "Shadow algorithm: TSM" << endl; } else { useAdvShadows = false; cout << "Shadow algorithm: Default" << endl; } } else { useAdvShadows = true; advShadowType = FOCUSED; shadow.useLiSPSM(false); shadow.useTSM(false); cout << "Shadow algorithm: Focused" << endl; } if (useAdvShadows && advShadowType == TSM) { cprog->detach(cvert); cprog->detach(cfrag); cprog->attach(cvert_tsm); cprog->attach(cfrag_tsm); cprog->link(); rprog->detach(rvert); rprog->detach(rfrag); rprog->attach(rvert_tsm); rprog->attach(rfrag_tsm); rprog->link(); } else { if (useAdvShadows == false) { // just leave TSM mode cprog->detach(cvert_tsm); cprog->detach(cfrag_tsm); cprog->attach(cvert); cprog->attach(cfrag); cprog->link(); rprog->detach(rvert_tsm); rprog->detach(rfrag_tsm); rprog->attach(rvert); rprog->attach(rfrag); rprog->link(); } } //if (!useAdvShadows) { // useAdvShadows = true; // cout << "Shadow algorithm: Custom" << endl; //} else { // useAdvShadows = false; // cout << "Shadow algorithm: Basic" << endl; //} #endif glutPostRedisplay(); break; case 'd': if (dbview == DV_HULLS) { dbview = DV_PPS; } else if (dbview == DV_PPS) { #ifdef NEW_SHADOW dbview = DV_NT; } else if (dbview == DV_NT) { #endif dbview = DV_HULLS; } glutPostRedisplay(); break; case 'l': switch (ltype) { case LT_DIR: ltype = LT_POINT; cout << "POINT LIGHT" << endl; break; case LT_POINT: ltype = LT_SPOT; cout << "SPOT LIGHT" << endl; break; case LT_SPOT: ltype = LT_DIR; cout << "DIR LIGHT" << endl; default: break; } glutPostRedisplay(); break; case 'f': rprog->detach(rfrag); if (rfrag == rfrag_no) { rfrag = rfrag_2x2; cout << "PCF 2x2" << endl; } else if (rfrag == rfrag_2x2) { rfrag = rfrag_4x4; cout << "PCF 4x4" << endl; } else if (rfrag == rfrag_4x4) { rfrag = rfrag_disc; cout << "PCF: Poisson disc 12 samples" << endl; } else if (rfrag == rfrag_disc) { rfrag = rfrag_no; cout << "No PCF" << endl; } rprog->attach(rfrag); if (!rprog->link()) { cout << "Error changing fragment program: " << rprog->log() << endl; } glutPostRedisplay(); break; default: return; } }