void DeferredRenderer::DrawDirectionalLight(const Light &light) { SR_ASSERT(light.type == kLightDirection); //동적 라이팅중에서 구조가 가장 간단한 방향으로 뱉어지는 빛이다. 이것의 경우 //그냥 화면 전체에 대해서 2d로 잘 적용하면 된다 Device *device = Device::GetInstance(); RenderState &render_state = device->render_state(); Shader &shader = directional_shader(); render_state.UseShader(shader); //빛 계산에 쓰이는 공용 속성 설정 SetCommonLightUniform(shader, light); //방향성빛은 방향만 잇으니까 행렬의 3*3만 쓴다 mat3 model_mat(render_state.model_mat()); mat3 light_mat(model_mat); vec3 light_target_pos(light.dir); vec3 viewspace_light_target_pos(light_mat * light_target_pos); vec3 light_dir = normalize(viewspace_light_target_pos); //빛 방향을 디버깅을 위해서 출력하기 //Draw2DManager *draw_2d_mgr = device->draw_2d(); //char light_dir_buf[128]; //sprintf(light_dir_buf, "LightDir:%.4f, %.4f, %.4f", light_dir.x, light_dir.y, light_dir.z); //draw_2d_mgr->AddString(vec2(0, 100), light_dir_buf, Color4ub::Red(), 1.0f); shader.SetUniformVector("u_lightDir", light_dir); SetCommonLightQuadDraw(shader); }
TexturedQuadPassDescription::TexturedQuadPassDescription() : PipelinePassDescription() { vertex_shader_ = "resources/shaders/common/quad.vert"; fragment_shader_ = "resources/shaders/textured_quad.frag"; name_ = "TexturedQuadPass"; needs_color_buffer_as_input_ = false; writes_only_color_buffer_ = false; enable_for_shadows_ = true; rendermode_ = RenderMode::Callback; rasterizer_state_ = boost::make_optional(scm::gl::rasterizer_state_desc( scm::gl::FILL_SOLID, scm::gl::CULL_NONE)); depth_stencil_state_ = boost::make_optional( scm::gl::depth_stencil_state_desc( true, true, scm::gl::COMPARISON_LESS, true, 1, 0, scm::gl::stencil_ops(scm::gl::COMPARISON_EQUAL) ) ); process_ = []( PipelinePass & pass, PipelinePassDescription const&, Pipeline & pipe) { for (auto const& node : pipe.current_viewstate().scene->nodes[std::type_index(typeid(node::TexturedQuadNode))]) { auto quad_node(reinterpret_cast<node::TexturedQuadNode*>(node)); UniformValue model_mat(scm::math::mat4f(quad_node->get_scaled_world_transform())); UniformValue normal_mat(scm::math::mat4f(scm::math::transpose(scm::math::inverse(quad_node->get_scaled_world_transform())))); UniformValue tex(quad_node->data.get_texture()); UniformValue flip(scm::math::vec2i(quad_node->data.get_flip_x() ? -1 : 1, quad_node->data.get_flip_y() ? -1 : 1)); auto const& ctx(pipe.get_context()); pass.shader_->apply_uniform(ctx, "gua_model_matrix", model_mat); pass.shader_->apply_uniform(ctx, "gua_normal_matrix", normal_mat); pass.shader_->apply_uniform(ctx, "gua_in_texture", tex); pass.shader_->apply_uniform(ctx, "flip", flip); pipe.draw_quad(); } }; }