void GraphicsGL2::DrawScene(std::ostream & error_output) { renderscene.SetFlags(using_shaders); renderscene.SetFSAA(fsaa); renderscene.SetContrast(contrast); renderscene.SetSunDirection(light_direction); postprocess.SetContrast(contrast); postprocess.SetSunDirection(light_direction); // sort the two dimentional drawlist so we get correct ordering std::sort(dynamic_drawlist.twodim.begin(),dynamic_drawlist.twodim.end(),&SortDraworder); // do fast culling queries for static geometry per pass std::map <std::string, PtrVector <Drawable> > culled_static_drawlist; for (std::vector <GraphicsConfigPass>::const_iterator i = config.passes.begin(); i != config.passes.end(); i++) { CullScenePass(*i, culled_static_drawlist, error_output); } // draw the passes for (std::vector <GraphicsConfigPass>::const_iterator i = config.passes.begin(); i != config.passes.end(); i++) { DrawScenePass(*i, culled_static_drawlist, error_output); } }
void GRAPHICS_GL2::DrawScene(std::ostream & error_output) { renderscene.SetFlags(using_shaders); renderscene.SetFSAA(fsaa); if (reflection_status == REFLECTION_STATIC) renderscene.SetReflection(&static_reflection); renderscene.SetAmbient(static_ambient); renderscene.SetContrast(contrast); postprocess.SetContrast(contrast); // sort the two dimentional drawlist so we get correct ordering std::sort(dynamic_drawlist.twodim.begin(),dynamic_drawlist.twodim.end(),&SortDraworder); std::map <std::string, PTRVECTOR <DRAWABLE> > culled_static_drawlist; // do fast culling queries for static geometry per pass for (std::vector <GRAPHICS_CONFIG_PASS>::const_iterator i = config.passes.begin(); i != config.passes.end(); i++) { CullScenePass(*i, culled_static_drawlist, error_output); } // construct light position MATHVECTOR <float, 3> lightposition(0,0,1); (-lightdirection).RotateVector(lightposition); renderscene.SetSunDirection(lightposition); postprocess.SetSunDirection(lightposition); // draw the passes for (std::vector <GRAPHICS_CONFIG_PASS>::const_iterator i = config.passes.begin(); i != config.passes.end(); i++) { DrawScenePass(*i, culled_static_drawlist, error_output); } }
void GraphicsGL2::DrawScene(std::ostream & error_output) { renderscene.SetFSAA(fsaa); renderscene.SetContrast(contrast); renderscene.SetSunDirection(light_direction); postprocess.SetContrast(contrast); postprocess.SetSunDirection(light_direction); // sort the two dimentional drawlist so we get correct ordering std::sort(dynamic_drawlist.twodim.begin(), dynamic_drawlist.twodim.end(), &SortDraworder); // do fast culling queries for static geometry per pass std::map <std::string, PtrVector <Drawable> > culled_static_drawlist; for (std::vector <GraphicsConfigPass>::const_iterator i = config.passes.begin(); i != config.passes.end(); i++) { CullScenePass(*i, culled_static_drawlist, error_output); } // draw the passes for (std::vector <GraphicsConfigPass>::const_iterator i = config.passes.begin(); i != config.passes.end(); i++) { assert(!i->draw.empty()); if (i->draw.back() != "postprocess") DrawScenePass(*i, culled_static_drawlist, error_output); else DrawScenePassPost(*i, error_output); } // reset texture and draw buffer glstate.BindTexture(0, GL_TEXTURE_2D, 0); glstate.BindFramebuffer(GL_FRAMEBUFFER, 0); }
void GraphicsGL2::SetupScene( float fov, float new_view_distance, const Vec3 cam_position, const Quat & cam_rotation, const Vec3 & dynamic_reflection_sample_pos, std::ostream & error_output) { // setup the default camera from the passed-in parameters { GraphicsCamera & cam = cameras["default"]; cam.fov = fov; cam.pos = cam_position; cam.rot = cam_rotation; cam.view_distance = new_view_distance; cam.w = w; cam.h = h; } // create a camera for the skybox with a long view distance { GraphicsCamera & cam = cameras["skybox"]; cam = cameras["default"]; cam.view_distance = 10000; cam.pos = Vec3(0); if (fixed_skybox) cam.pos[2] = cam_position[2]; } // create a camera for the dynamic reflections { GraphicsCamera & cam = cameras["dynamic_reflection"]; cam.pos = dynamic_reflection_sample_pos; cam.fov = 90; // this gets automatically overridden with the correct fov (which is 90 anyway) cam.rot.LoadIdentity(); // this gets automatically rotated for each cube side cam.view_distance = 100; cam.w = 1; // this gets automatically overridden with the cubemap dimensions cam.h = 1; // this gets automatically overridden with the cubemap dimensions } // create a camera for the dynamic reflection skybox { GraphicsCamera & cam = cameras["dynamic_reflection_skybox"]; cam = cameras["dynamic_reflection"]; cam.view_distance = 10000; cam.pos = Vec3(0); } // create an ortho camera for 2d drawing { GraphicsCamera & cam = cameras["2d"]; // this is the glOrtho call we want: glOrtho( 0, 1, 1, 0, -1, 1 ); cam.orthomode = true; cam.orthomin = Vec3(0, 1, -1); cam.orthomax = Vec3(1, 0, 1); } // create cameras for shadow passes if (shadows) { Mat4 view_matrix; cam_rotation.GetMatrix4(view_matrix); float translate[4] = {-cam_position[0], -cam_position[1], -cam_position[2], 0}; view_matrix.MultiplyVector4(translate); view_matrix.Translate(translate[0], translate[1], translate[2]); Mat4 view_matrix_inv = view_matrix.Inverse(); // derive light rotation quaternion from light direction vector Quat light_rotation; Vec3 up(0, 0, 1); float cosa = up.dot(light_direction); if (cosa * cosa < 1.0f) { float a = -acosf(cosa); Vec3 x = up.cross(light_direction).Normalize(); light_rotation.SetAxisAngle(a, x[0], x[1], x[2]); } std::vector <std::string> shadow_names; shadow_names.push_back("near"); shadow_names.push_back("medium"); shadow_names.push_back("far"); for (int i = 0; i < 3; i++) { float shadow_radius = (1<<i)*closeshadow+(i)*20.0; //5,30,60 Vec3 shadowbox(1,1,1); shadowbox = shadowbox * (shadow_radius*sqrt(2.0)); Vec3 shadowoffset(0,0,-1); shadowoffset = shadowoffset * shadow_radius; (-cam_rotation).RotateVector(shadowoffset); shadowbox[2] += 60.0; GraphicsCamera & cam = cameras["shadows_"+shadow_names[i]]; cam = cameras["default"]; cam.orthomode = true; cam.orthomin = -shadowbox; cam.orthomax = shadowbox; cam.pos = cam.pos + shadowoffset; cam.rot = light_rotation; // get camera clip matrix const Mat4 cam_proj_mat = GetProjMatrix(cam); const Mat4 cam_view_mat = GetViewMatrix(cam); Mat4 clip_matrix; clip_matrix.Scale(0.5f); clip_matrix.Translate(0.5f, 0.5f, 0.5f); clip_matrix = cam_proj_mat.Multiply(clip_matrix); clip_matrix = cam_view_mat.Multiply(clip_matrix); // premultiply the clip matrix with default camera view inverse matrix clip_matrix = view_matrix_inv.Multiply(clip_matrix); shadow_matrix[i] = clip_matrix; } assert(shadow_distance < 3); renderscene.SetShadowMatrix(shadow_matrix, shadow_distance + 1); postprocess.SetShadowMatrix(shadow_matrix, shadow_distance + 1); } else { renderscene.SetShadowMatrix(NULL, 0); postprocess.SetShadowMatrix(NULL, 0); } // sort the two dimentional drawlist so we get correct ordering std::sort(dynamic_drawlist.twodim.begin(), dynamic_drawlist.twodim.end(), &SortDraworder); // do fast culling queries for static geometry per pass ClearCulledDrawLists(); for (std::vector <GraphicsConfigPass>::const_iterator i = config.passes.begin(); i != config.passes.end(); i++) { CullScenePass(*i, error_output); } renderscene.SetFSAA(fsaa); renderscene.SetContrast(contrast); renderscene.SetSunDirection(light_direction); postprocess.SetContrast(contrast); postprocess.SetSunDirection(light_direction); }