Commit a4f01011 authored by Jerry's avatar Jerry
Browse files

Merge branch 'local/demo' into feature/ui

parents 3e833e99 028325f0
......@@ -8,13 +8,26 @@ project(gdw_ss15_cpp)
find_package(OpenGL)
include(FindPkgConfig)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2MIXER REQUIRED SDL2_mixer)
include_directories(
${SDL2_INCLUDE_DIRS}
${SDL2_mixer_INCLUDE_DIRS}
)
if(UNIX)
include(FindPkgConfig)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2MIXER REQUIRED SDL2_mixer)
include_directories(
${SDL2_INCLUDE_DIRS}
${SDL2_mixer_INCLUDE_DIRS}
)
elseif(WIN32)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/lib/sdl2/include
${CMAKE_CURRENT_SOURCE_DIR}/lib/sdl2_mixer/x86_64-w64-mingw32/include/SDL2
)
link_directories(
${CMAKE_CURRENT_SOURCE_DIR}/lib/sdl2/x86_64-w64-mingw32/lib
${CMAKE_CURRENT_SOURCE_DIR}/lib/sdl2_mixer/x86_64-w64-mingw32/lib
)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/lib/sdl2/x86_64-w64-mingw32/bin/SDL2.dll DESTINATION .)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/lib/sdl2_mixer/x86_64-w64-mingw32/bin/ DESTINATION . FILES_MATCHING PATTERN *.dll)
endif()
#gli library
......@@ -151,14 +164,28 @@ set(LINKED_LIBRARIES
DetourCrowd
Detour
Recast
SDL2
SDL2main
SDL2main
SDL2
SDL2_mixer
GL
c++
c++abi
)
if(UNIX)
set( LINKED_LIBRARIES
${LINKED_LIBRARIES}
GL
c++
c++abi)
elseif(WIN32)
set( LINKED_LIBRARIES
imagehlp
mingw32
${LINKED_LIBRARIES}
opengl32
-static-libgcc
-static-libstdc++)
endif()
#build executable and then link to the libraries
add_executable(Game ${project_SRC} ${project_HDR} ${project_INL})
target_link_libraries(Game ${LINKED_LIBRARIES})
......
#version 330
in vec2 texcoord_;
in vec3 color_;
out vec4 frag_color;
uniform sampler2D albedo_texture;
uniform vec2 resolution;
uniform vec2 inverse_resolution;
uniform vec3 origin;
uniform mat2 rotation;
uniform float zoom;
#define iterations 15
#define volsteps 6
#define sparsity 0.5f
#define stepsize 0.3f
#define frequency_variation 1.3f
#define brightness 0.0018f
#define distfading 0.68f
void main() {
vec4 color = texture(albedo_texture, texcoord_);
if (color.a <= 0.f) {
discard;
vec2 uv = gl_FragCoord.xy * inverse_resolution - 0.5f;
uv.y *= resolution.y * inverse_resolution.x;
vec3 direction = vec3(uv * zoom, 1.f);
direction.xy *= rotation;
float s = 0.1f;
float fade = 0.01f;
frag_color = vec4(0.f);
for (int r = 0; r < volsteps; ++r) {
vec3 p = origin + direction * (s * 0.5f);
p = abs(vec3(frequency_variation) - mod(p, vec3(frequency_variation * 2.f)));
float prevlen = 0.f;
float a = 0.f;
for (int i = 0; i < iterations; ++i) {
p = abs(p);
p = p * (1.f / dot(p, p)) + (-sparsity);
float len = length(p);
a += abs(len - prevlen);
prevlen = len;
}
a *= a * a;
frag_color.rgb += (vec3(s, s * s, s * s * s) * a * brightness + 1.f) * fade;
fade *= distfading;
s += stepsize;
}
frag_color = color * vec4(color_, 1.f);
frag_color.rgb = min(frag_color.rgb, vec3(1.2f));
float intensity = min(frag_color.r + frag_color.g + frag_color.b, 0.7f);
ivec2 sgn = (ivec2(gl_FragCoord.xy) & 1) * 2 - 1;
vec2 gradient = vec2(dFdx(intensity) * sgn.x, dFdy(intensity) * sgn.y);
float cutoff = max(max(gradient.x, gradient.y) - 0.1f, 0.f);
frag_color.rgb *= max(1.f - cutoff * 0.6f, 0.3f);
frag_color.a = 1.f;
}
#version 330
in vec3 _position;
in float _size;
in vec3 _color;
out float _size_;
out vec3 _color_;
uniform mat4 projection;
uniform mat4 view;
uniform mat4 model;
void main() {
vec4 position = view * model * vec4(_position, 1.f);
gl_Position = position;
_size_ = _size;
_color_ = _color;
gl_Position = projection * view * model * vec4(_position, 1.f);
}
......@@ -80,13 +80,8 @@ namespace gdw {
vertex_array simple_render_vao_;
int simple_render_element_size_;
vertex_layout starfield_vertex_layout_;
program starfield_program_;
vertex_buffer starfield_point_;
vertex_buffer starfield_vbo_;
vertex_array starfield_vao_;
unsigned int starfield_size_ = 0;
std::shared_ptr<const texture> star_texture_;
std::shared_ptr<const mesh> starfield_;
std::shared_ptr<const mesh> planet_;
program planet_program_;
......@@ -158,7 +153,6 @@ namespace gdw {
void render_non_opauqe_geometry(float delta_time, camera_component& camera);
void render_navMesh(camera_component &camera);
void render_final_image();
void generate_starfield();
void render_starfield(float delta_time, camera_component& camera);
void render_planet(camera_component& camera);
......
......@@ -9,17 +9,17 @@ deathstar.dds : 20
dome_material.dds : 18
beam_stripes.dds : 13
weighted_companion_cube_export_material.dds : 3
piratenschiff_diffuse.dds : 5
Meteor_normal_2.dds : 21
piratenschiff_diffuse.dds : 5
beam.dds : 12
piratenschiff_normal.dds : 6
cannon.dds : 11
victim_diffuse.dds : 15
Texture_Meteor.dds : 9
weighted_companion_cube_export.dds : 1
Meteor_LOW_Normals.dds : 10
cannon.dds : 11
victim_diffuse.dds : 15
greyscale_normal.dds : 2
black.dds : 7
piratenschiff_material.dds : 4
planet_normal.dds : 24
dome_diffuse.dds : 17
black.dds : 7
greyscale_normal.dds : 2
planet_normal.dds : 24
......@@ -32,8 +32,7 @@
namespace gdw {
rendering_system::rendering_system(engine& engine)
: engine_(engine), mesh_manager_(engine), active_camera_(0), debug_mode_(false), point_light_instance_data_(GL_DYNAMIC_DRAW),
shadow_resolution_(256),simple_render_vbo_(GL_STATIC_DRAW),simple_render_element_size_(0), baked_(true), starfield_vbo_(GL_STATIC_DRAW),
starfield_point_(GL_STATIC_DRAW) {
shadow_resolution_(256),simple_render_vbo_(GL_STATIC_DRAW),simple_render_element_size_(0), baked_(true) {
staticmesh_layout_.emplace_back("_position", 3, GL_FLOAT, false, sizeof(mesh_vertex), offsetof(mesh_vertex, position));
staticmesh_layout_.emplace_back("_texcoord", 2, GL_FLOAT, false, sizeof(mesh_vertex), offsetof(mesh_vertex, texcoord));
staticmesh_layout_.emplace_back("_normal", 3, GL_FLOAT, false, sizeof(mesh_vertex), offsetof(mesh_vertex, normal));
......@@ -284,43 +283,24 @@ namespace gdw {
staticmesh_layout_.setup_program(traktor_beam_program_, "frag_color");
traktor_beam_program_.link();
starfield_vertex_layout_.emplace_back("_point", 3, GL_FLOAT, false, sizeof(glm::vec3), 0);
starfield_vertex_layout_.emplace_back("_position", 3, GL_FLOAT, false, sizeof(star_vertex), offsetof(star_vertex, position), 1, 1);
starfield_vertex_layout_.emplace_back("_size", 1, GL_FLOAT, false, sizeof(star_vertex), offsetof(star_vertex, size), 1, 1);
starfield_vertex_layout_.emplace_back("_color", 3, GL_FLOAT, false, sizeof(star_vertex), offsetof(star_vertex, color), 1, 1);
starfield_ = mesh_manager_.load("mesh/starfield.msh", staticmesh_layout_);
if (!starfield_) {
throw std::runtime_error("could not load mesh/starfield.msh");
}
vertex_shader = shader_manager.load("shader/starfield.vs", GL_VERTEX_SHADER);
if (!vertex_shader) {
throw std::runtime_error("could not load shader/starfield.vs");
}
starfield_program_.attach_shader(vertex_shader);
auto geometry_shader = shader_manager.load("shader/starfield.gs", GL_GEOMETRY_SHADER);
if (!geometry_shader) {
throw std::runtime_error("could not load shader/starfield.gs");
}
starfield_program_.attach_shader(geometry_shader);
fragment_shader = shader_manager.load("shader/starfield.fs", GL_FRAGMENT_SHADER);
if (!fragment_shader) {
throw std::runtime_error("could not load shader/starfield.fs");
}
starfield_program_.attach_shader(fragment_shader);
starfield_vertex_layout_.setup_program(starfield_program_, "frag_color");
staticmesh_layout_.setup_program(starfield_program_, "frag_color");
starfield_program_.link();
auto point = glm::vec3(0.f);
starfield_point_.bind();
starfield_point_.data(sizeof(glm::vec3), &point);
const vertex_buffer* buff[2] = {&starfield_point_, &starfield_vbo_};
starfield_vertex_layout_.setup_layout(starfield_vao_, buff);
star_texture_ = graphics_system.texture_manager().load("texture/star.dds");
if (!star_texture_) {
throw std::runtime_error("could not load texture/star.dds");
}
generate_starfield();
planet_ = mesh_manager_.load("mesh/planet.msh", staticmesh_layout_);
if (!planet_) {
throw std::runtime_error("could not load mesh/planet.msh");
......@@ -366,8 +346,8 @@ namespace gdw {
render_gbuffer(delta_time, *camera);
render_lights(*camera);
render_planet(*camera);
render_starfield(delta_time, *camera);
render_planet(*camera);
render_non_opauqe_geometry(delta_time, *camera);
render_final_image();
if(engine_.getConfig().get("navDebug",true))
......@@ -853,47 +833,42 @@ namespace gdw {
tractor_beams_.emplace_back(beam);
}
void rendering_system::generate_starfield() {
static std::vector<star_vertex> stars;
for (auto i = 0; i < 10000; ++i) {
static const auto white = glm::vec3(1.f);
static const auto yellow = glm::vec3(1.f, 1.f, 0.8f);
auto alpha = glm::gaussRand(0.f, 1.f);
star_vertex v = {glm::sphericalRand(500.f), glm::gaussRand(1.f, 2.f), glm::lerp(white, yellow, alpha)};
stars.emplace_back(v);
}
starfield_vbo_.bind();
starfield_vbo_.data(stars.size() * sizeof(star_vertex), stars.data());
starfield_size_ = stars.size();
}
void rendering_system::render_starfield(float delta_time, camera_component& camera) {
const static auto model = glm::scale(glm::mat4(1.f), glm::vec3(500.f));
const static auto width = static_cast<float>(engine_.graphics_system().width());
const static auto height = static_cast<float>(engine_.graphics_system().height());
static auto origin = glm::vec3(width / 2.f, height / 2.f, -100.f);
origin.x += delta_time / 1000.f;
static auto alpha = 0.f;
static const auto planet_acceleration_ = 0.005f;
static const auto planet_center = glm::vec3(80.f, -20.f, -100.f);
alpha += planet_acceleration_ * delta_time;
alpha += delta_time / 500.f;
if (alpha >= 2.f * glm::pi<float>()) {
alpha = 0.f;
}
auto model = glm::translate(glm::mat4(1.f), planet_center);
model *= glm::toMat4(glm::angleAxis(alpha, glm::vec3(0.f, 1.f, 0.f)));
model *= glm::translate(glm::mat4(1.f), -planet_center);
auto rotation = glm::mat2(glm::cos(alpha), -glm::sin(alpha), glm::sin(alpha), glm::cos(alpha));
composition_buffer_.bind();
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
starfield_vao_.bind();
starfield_program_.use();
starfield_program_.uniform("projection", false, camera.projection());
starfield_program_.uniform("view", false, camera.view());
starfield_program_.uniform("model", false, model);
starfield_program_.uniform("albedo_texture", 0);
star_texture_->bind(0);
glDrawArraysInstanced(GL_POINTS, 0, 1, starfield_size_);
glDepthMask(GL_TRUE);
starfield_program_.uniform("resolution", glm::vec2(width, height));
starfield_program_.uniform("inverse_resolution", 1.f / glm::vec2(width, height));
starfield_program_.uniform("origin", origin);
starfield_program_.uniform("rotation", false, rotation);
starfield_program_.uniform("zoom", 1.f);
starfield_->draw(starfield_program_);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
}
void rendering_system::render_planet(camera_component& camera) {
......
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