template <typename T, typename X> void core_solver_pretty_printer<T, X>::init_costs() { vector<T> local_y(m_core_solver.m_m); m_core_solver.solve_yB(local_y); for (unsigned i = 0; i < ncols(); i++) { if (m_core_solver.m_basis_heading[i] < 0) { T t = m_core_solver.m_costs[i] - m_core_solver.m_A.dot_product_with_column(local_y, i); set_coeff(m_costs, m_cost_signs, i, t, m_core_solver.column_name(i)); } } }
KOKKOS_INLINE_FUNCTION void operator() (device_type device) const { typename local_view_type::Partition part( device.team_rank() , device.team_size() ); const local_view_type local_x( dev_x , part ); const local_view_type local_y( dev_y , part ); const int element = device.league_rank(); // Apply evaluation function to this thread's fix-sized UQ sample set. simple_function< value_type >( local_x(element) , local_y(element) ); // Print x and y if (print) { device.team_barrier(); if ( ! device.league_rank() && ! device.team_rank() ) { printf("view_kernel league(%d:%d) team_size(%d) dim(%d) size(%d)\n", device.league_rank(), device.league_size(),device.team_size(), int(dev_x.dimension_1()), int(local_x(element).size()) ); } if ( ! device.team_rank() ) { printf("x(%i) = { ",element); for (int sample=0; sample< int(dev_x.dimension_1()); ++sample) { printf("%g ", dev_x(element,sample)); } printf("}\n\n"); printf("y(%i) = { ",element); for (int sample=0; sample< int(dev_y.dimension_1()); ++sample) { printf("%g ", dev_y(element,sample)); } printf("}\n\n"); } device.team_barrier(); } }
void MovableLight::render_shadow_map(const Camera &camera, std::function<void()> render_geometry) { if(shadow_map.fbo == nullptr) shadow_map.create_fbo(); float near, far; near = camera.near(); far = camera.far() * shadowmap_far_factor; glm::mat4 view_matrix, projection_matrix; switch(type) { case DIRECTIONAL_LIGHT: { glm::vec3 lightv[3]; lightv[0] = glm::normalize(position()); glm::vec3 hint; if(abs(lightv[0].x) <= abs(lightv[0].y)) { if(abs(lightv[0].x) <= abs(lightv[0].z)) { hint = glm::vec3(1.f, 0.f, 0.f); } else { hint = glm::vec3(0.f, 0.f, 1.f); } } else { if(abs(lightv[0].y) <= abs(lightv[0].z)) { hint = glm::vec3(0.f, 1.f, 0.f); } else { hint = glm::vec3(0.f, 0.f, 1.f); } } lightv[1] = glm::normalize(glm::cross(lightv[0], hint)); lightv[2] = glm::normalize(glm::cross(lightv[1], lightv[0])); glm::vec3 frustrum_corners[8]; glm::vec3 frustrum_center = calculateFrustrumData(camera, near, far, frustrum_corners); float min_v[3] = { FLT_MAX, FLT_MAX, FLT_MAX }; float max_v[3] = { -FLT_MAX, -FLT_MAX, -FLT_MAX }; for(glm::vec3 &corner : frustrum_corners) { for(int i=0; i < 3; ++i) { float l = glm::dot(corner, lightv[i]); if(l < min_v[i]) min_v[i] = l; if(l > max_v[i]) max_v[i] = l; } } float center[3]; for(int i=0; i < 3; ++i) { center[i] = glm::dot(frustrum_center, lightv[i]); min_v[i] -= 5.f; max_v[i] += 5.f; } glm::vec3 eye = frustrum_center + lightv[0] * (min_v[0] - center[0]); float left, right, bottom, top, far_dist; left = min_v[1]; right = max_v[1]; bottom = min_v[2]; top = max_v[2]; far_dist = max_v[0] - min_v[0]; float halfw, halfh; halfw = (right - left)/2.f; halfh = (top - bottom)/2.f; view_matrix = glm::lookAt(eye, frustrum_center, lightv[2]); projection_matrix = glm::ortho(-halfw, halfw, halfh, -halfh, 0.f, far_dist); /*glm::vec4 test4 = projection_matrix * view_matrix * glm::vec4(frustrum_center, 1.f); glm::vec3 test = glm::vec3(test4.x, test4.y, test4.z) / test4.w; printf("%f, %f, %f\n", test.x, test.y, test.z);*/ break; } case POINT_LIGHT: { view_matrix = glm::lookAt(position(), position() + local_z(), local_y()); projection_matrix = glm::perspective(90.f, 1.f, 0.1f, 100.f); break; } default: printf("Shadowmaps are only implemented for directional lights at the moment\n"); util_abort(); } shadow_map.matrix = glm::translate(glm::mat4(1.f), glm::vec3(0.5f)) * glm::scale(glm::mat4(1.f),glm::vec3(0.5f)) * projection_matrix * view_matrix; Shader::upload_projection_view_matrices(projection_matrix, view_matrix); shadow_map.fbo->bind(); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); shaders[SHADER_PASSTHRU]->bind(); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); render_geometry(); shadow_map.fbo->unbind(); }