Commit 8d402aec authored by Georg Schaefer's avatar Georg Schaefer
Browse files

render planet in extra pass

parent 80813006
#version 330
in vec2 texcoord_;
out vec4 frag_color;
uniform sampler2D albedo_texture;
void main() {
frag_color = texture(albedo_texture, texcoord_);
}
#version 330
in vec3 _position;
in vec2 _texcoord;
in vec3 _normal;
in vec3 _tangent;
out vec2 texcoord_;
uniform mat4 projection;
uniform mat4 view;
uniform mat4 model;
void main() {
gl_Position = projection * view * model * vec4(_position, 1.f);
texcoord_ = _texcoord;
}
......@@ -88,6 +88,10 @@ namespace gdw {
unsigned int starfield_size_ = 0;
std::shared_ptr<const texture> star_texture_;
std::shared_ptr<const mesh> planet_;
program planet_program_;
glm::mat4 planet_model_;
std::unordered_map<unsigned long long, camera_component*> camera_components_;
std::vector<directional_light_component*> directional_light_components_;
std::vector<light_component*> light_components_;
......@@ -154,6 +158,7 @@ namespace gdw {
void render_final_image();
void generate_starfield();
void render_starfield(float delta_time, camera_component& camera);
void render_planet(camera_component& camera);
void register_component(camera_component* component);
......
......@@ -82,10 +82,10 @@ namespace gdw {
sun.emplace_back<directional_light_component>(glm::vec3(1.f), 0.5f);
sun.emplace_back<shadow_component>(50.f);
auto &planet = entity_manager.emplace_back(glm::vec3(80.f, -50.f, -100.f),
/*auto &planet = entity_manager.emplace_back(glm::vec3(80.f, -50.f, -100.f),
glm::angleAxis(glm::radians(0.f), glm::vec3(0.f)),
glm::vec3(100.f));
planet.emplace_back<staticmesh_component>("mesh/planet.msh");
planet.emplace_back<staticmesh_component>("mesh/planet.msh");*/
}
if (deathstar_ == 0) {
auto &deathstar = entity_manager.emplace_back(glm::vec3(-60.f, -20.f, -100.f),
......
......@@ -320,6 +320,27 @@ namespace gdw {
}
generate_starfield();
planet_ = mesh_manager_.load("mesh/planet.msh", staticmesh_layout_);
if (!planet_) {
throw std::runtime_error("could not load mesh/planet.msh");
}
planet_model_ = glm::translate(glm::mat4(1.f), glm::vec3(80.f, -50.f, -100.f));
planet_model_ *= glm::scale(glm::mat4(1.f), glm::vec3(100.f));
vertex_shader = shader_manager.load("shader/planet.vs", GL_VERTEX_SHADER);
if (!vertex_shader) {
throw std::runtime_error("could not load shader/planet.vs");
}
planet_program_.attach_shader(vertex_shader);
fragment_shader = shader_manager.load("shader/planet.fs", GL_FRAGMENT_SHADER);
if (!fragment_shader) {
throw std::runtime_error("could not load shader/planet.fs");
}
planet_program_.attach_shader(fragment_shader);
staticmesh_layout_.setup_program(planet_program_, "frag_color");
planet_program_.link();
}
void rendering_system::update(float delta_time) {
......@@ -330,6 +351,7 @@ namespace gdw {
render_gbuffer(delta_time, *camera);
render_lights(*camera);
render_planet(*camera);
render_starfield(delta_time, *camera);
render_non_opauqe_geometry(delta_time, *camera);
render_final_image();
......@@ -859,6 +881,24 @@ namespace gdw {
glDisable(GL_BLEND);
}
void rendering_system::render_planet(camera_component& camera) {
composition_buffer_.bind();
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
planet_program_.use();
planet_program_.uniform("projection", false, camera.projection());
planet_program_.uniform("view", false, camera.view());
planet_program_.uniform("model", false, planet_model_);
planet_program_.uniform("albedo_texture", 0);
planet_->draw(planet_program_);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
}
void rendering_system::register_component(camera_component* component) {
camera_components_.emplace(std::make_pair(component->owner().id(), component));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment