Skip to content

Commit

Permalink
Update everything
Browse files Browse the repository at this point in the history
Major changes to lighting, noise, cloud maps and more
  • Loading branch information
Faruk Eroğlu committed Nov 23, 2020
1 parent 06857d5 commit 22f6ae8
Show file tree
Hide file tree
Showing 16 changed files with 518 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

in vec2 fullscreen_texture_position;

uniform sampler2D rendering_texture;
uniform sampler2D current_rendering_texture;

layout(location = 0) out vec4 fragment_color;

Expand All @@ -19,7 +19,7 @@ vec3 tone_mapping(vec3 input_color)

void main()
{
vec4 rendered_color = texture(rendering_texture, fullscreen_texture_position);
vec4 rendered_color = texture(current_rendering_texture, fullscreen_texture_position);
rendered_color.xyz = tone_mapping(rendered_color.xyz);

fragment_color = rendered_color;
Expand Down
337 changes: 210 additions & 127 deletions Enhanced Cloudscapes/shaders/rendering/fragment_shader.glsl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Enhanced Cloudscapes/shaders/rendering/vertex_shader.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ layout(location = 0) in vec2 input_vertex;
uniform float near_clip_z;
uniform float far_clip_z;

uniform mat4 inverse_projection_matrix;
uniform mat4 inverse_modelview_matrix;
uniform mat4 inverse_projection_matrix;

out vec3 ray_start_position;
out vec3 ray_end_position;
Expand Down
Binary file modified Enhanced Cloudscapes/textures/base_noise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Enhanced Cloudscapes/textures/cloud_map_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Enhanced Cloudscapes/textures/cloud_map_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Enhanced Cloudscapes/textures/cloud_map_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Enhanced Cloudscapes/textures/detail_noise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions include/plugin_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

namespace plugin_objects
{
extern int depth_texture;
extern int previous_depth_texture;
extern int current_depth_texture;

extern int cloud_map_textures[CLOUD_LAYER_COUNT];

Expand All @@ -15,7 +16,8 @@ namespace plugin_objects

extern int blue_noise_texture;

extern int rendering_texture;
extern int previous_rendering_texture;
extern int current_rendering_texture;

extern GLuint framebuffer;
extern GLuint vertex_array;
Expand Down
33 changes: 23 additions & 10 deletions include/simulator_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,37 @@
#include <glm/mat4x4.hpp>

#define CLOUD_LAYER_COUNT 3
#define CLOUD_TYPE_COUNT 5
#define CLOUD_TYPE_COUNT 6

namespace simulator_objects
{
extern int version;

extern glm::ivec4 previous_viewport;
extern glm::ivec4 current_viewport;

extern glm::ivec2 previous_rendering_resolution;
extern glm::ivec2 current_rendering_resolution;

extern int skip_fragments;
extern int frame_index;

extern int reverse_z;

extern float near_clip_z;
extern float far_clip_z;

extern glm::mat4 inverse_projection_matrix;
extern glm::mat4 inverse_modelview_matrix;
extern glm::dmat4 previous_mvp_matrix;
extern glm::dmat4 current_mvp_matrix;

extern glm::dmat4 inverse_modelview_matrix;
extern glm::dmat4 inverse_projection_matrix;

extern int skip_fragments;
extern int frame_index;

extern int sample_step_count;
extern int sun_step_count;

extern float maximum_sample_step_size;
extern float maximum_sun_step_size;

extern int use_blue_noise_dithering;

extern float cloud_map_scale;

Expand All @@ -49,9 +58,14 @@ namespace simulator_objects

extern glm::vec3 wind_offsets[CLOUD_LAYER_COUNT];

extern float base_anvil;
extern float top_anvil;

extern float fade_start_distance;
extern float fade_end_distance;

extern float light_attenuation;

extern glm::vec3 sun_direction;

extern glm::vec3 sun_tint;
Expand All @@ -60,8 +74,7 @@ namespace simulator_objects
extern glm::vec3 ambient_tint;
extern float ambient_gain;

extern float backward_mie_scattering;
extern float forward_mie_scattering;
extern float mie_scattering;

extern glm::vec3 atmosphere_bottom_tint;
extern glm::vec3 atmosphere_top_tint;
Expand Down
18 changes: 5 additions & 13 deletions src/enhanced_cloudscapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

#include <cstring>

XPLMDataRef callback_type_dataref;

#ifdef IBM
BOOL APIENTRY DllMain(IN HINSTANCE dll_handle, IN DWORD call_reason, IN LPVOID reserved)
{
Expand All @@ -26,14 +24,11 @@ BOOL APIENTRY DllMain(IN HINSTANCE dll_handle, IN DWORD call_reason, IN LPVOID r

int draw_callback(XPLMDrawingPhase drawing_phase, int is_before, void* callback_reference)
{
if ((simulator_objects::version >= 115000) || (XPLMGetDatai(callback_type_dataref) == 2))
{
simulator_objects::update();
plugin_objects::update();
simulator_objects::update();
plugin_objects::update();

rendering_program::call();
post_processing_program::call();
}
rendering_program::call();
post_processing_program::call();

return 1;
}
Expand All @@ -52,10 +47,7 @@ PLUGIN_API int XPluginStart(char* plugin_name, char* plugin_signature, char* plu
rendering_program::initialize();
post_processing_program::initialize();

callback_type_dataref = XPLMFindDataRef("sim/graphics/view/plane_render_type");

if (simulator_objects::version >= 115000) XPLMRegisterDrawCallback(draw_callback, xplm_Phase_Modern3D, 0, nullptr);
else XPLMRegisterDrawCallback(draw_callback, xplm_Phase_Airplanes, 0, nullptr);
XPLMRegisterDrawCallback(draw_callback, xplm_Phase_Modern3D, 0, nullptr);

return 1;
}
Expand Down
28 changes: 25 additions & 3 deletions src/opengl_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ int create_fullscreen_texture()
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture_reference);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

XPLMBindTexture2d(EMPTY_OBJECT, 0);

Expand Down Expand Up @@ -207,12 +207,34 @@ GLuint load_shader(const char* shader_path, GLenum shader_type)

GLuint create_program(GLuint vertex_shader, GLuint fragment_shader)
{
GLuint output_program = EMPTY_OBJECT;

GLuint program_reference = glCreateProgram();

glAttachShader(program_reference, vertex_shader);
glAttachShader(program_reference, fragment_shader);

glLinkProgram(program_reference);

return program_reference;
GLint program_link_status;
glGetProgramiv(program_reference, GL_LINK_STATUS, &program_link_status);

if (program_link_status == GL_TRUE) output_program = program_reference;
else
{
GLint compilation_log_length;
glGetProgramiv(program_reference, GL_INFO_LOG_LENGTH, &compilation_log_length);

GLchar* compilation_message = new GLchar[compilation_log_length];
glGetProgramInfoLog(program_reference, compilation_log_length, nullptr, compilation_message);

XPLMDebugString("\nProgram compilation failed!\n\n");

XPLMDebugString("Compilation error message is:\n");
XPLMDebugString(compilation_message);

delete[] compilation_message;
}

return output_program;
}
37 changes: 26 additions & 11 deletions src/plugin_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

namespace plugin_objects
{
int depth_texture;
int previous_depth_texture;
int current_depth_texture;

int cloud_map_textures[CLOUD_LAYER_COUNT];

Expand All @@ -15,14 +16,16 @@ namespace plugin_objects

int blue_noise_texture;

int rendering_texture;
int previous_rendering_texture;
int current_rendering_texture;

GLuint framebuffer;
GLuint vertex_array;

void initialize()
{
depth_texture = create_fullscreen_texture();
previous_depth_texture = create_fullscreen_texture();
current_depth_texture = create_fullscreen_texture();

cloud_map_textures[0] = load_png_texture("Resources/plugins/Enhanced Cloudscapes/textures/cloud_map_1.png", false);
cloud_map_textures[1] = load_png_texture("Resources/plugins/Enhanced Cloudscapes/textures/cloud_map_2.png", false);
Expand All @@ -33,15 +36,16 @@ namespace plugin_objects

blue_noise_texture = load_png_texture("Resources/plugins/Enhanced Cloudscapes/textures/blue_noise.png", false);

rendering_texture = create_fullscreen_texture();
previous_rendering_texture = create_fullscreen_texture();
current_rendering_texture = create_fullscreen_texture();

GLint previous_framebuffer;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &previous_framebuffer);

glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer);

glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, rendering_texture, 0);
glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, current_rendering_texture, 0);

glBindFramebuffer(GL_DRAW_FRAMEBUFFER, previous_framebuffer);

Expand Down Expand Up @@ -77,31 +81,42 @@ namespace plugin_objects
void update()
{
XPLMSetGraphicsState(0, 1, 0, 0, 0, 0, 0);

glActiveTexture(GL_TEXTURE0);

if ((simulator_objects::current_viewport.z != simulator_objects::previous_viewport.z) || (simulator_objects::current_viewport.w != simulator_objects::previous_viewport.w))
{
glBindTexture(GL_TEXTURE_2D, depth_texture);

GLenum depth_format;

if (simulator_objects::reverse_z == 0) depth_format = GL_DEPTH_COMPONENT24;
else depth_format = GL_DEPTH_COMPONENT32F;

glBindTexture(GL_TEXTURE_2D, previous_depth_texture);

glTexImage2D(GL_TEXTURE_2D, 0, depth_format, simulator_objects::current_viewport.z, simulator_objects::current_viewport.w, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, nullptr);
glCopyImageSubData(current_depth_texture, GL_TEXTURE_2D, 0, 0, 0, 0, previous_depth_texture, GL_TEXTURE_2D, 0, 0, 0, 0, simulator_objects::current_viewport.z, simulator_objects::current_viewport.w, 1);

glBindTexture(GL_TEXTURE_2D, current_depth_texture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, depth_format, simulator_objects::current_viewport.x, simulator_objects::current_viewport.y, simulator_objects::current_viewport.z, simulator_objects::current_viewport.w, 0);
}
else
{
glBindTexture(GL_TEXTURE_2D, depth_texture);
glCopyImageSubData(current_depth_texture, GL_TEXTURE_2D, 0, 0, 0, 0, previous_depth_texture, GL_TEXTURE_2D, 0, 0, 0, 0, simulator_objects::current_viewport.z, simulator_objects::current_viewport.w, 1);

glBindTexture(GL_TEXTURE_2D, current_depth_texture);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, simulator_objects::current_viewport.x, simulator_objects::current_viewport.y, simulator_objects::current_viewport.z, simulator_objects::current_viewport.w);
}

if ((simulator_objects::current_rendering_resolution.x != simulator_objects::previous_rendering_resolution.x) || (simulator_objects::current_rendering_resolution.y != simulator_objects::previous_rendering_resolution.y))
{
glBindTexture(GL_TEXTURE_2D, rendering_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, simulator_objects::current_rendering_resolution.x, simulator_objects::current_rendering_resolution.y, 0, GL_RGBA, GL_FLOAT, nullptr);
glBindTexture(GL_TEXTURE_2D, previous_rendering_texture);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, simulator_objects::current_rendering_resolution.x, simulator_objects::current_rendering_resolution.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glCopyImageSubData(current_rendering_texture, GL_TEXTURE_2D, 0, 0, 0, 0, previous_rendering_texture, GL_TEXTURE_2D, 0, 0, 0, 0, simulator_objects::current_rendering_resolution.x, simulator_objects::current_rendering_resolution.y, 1);

glBindTexture(GL_TEXTURE_2D, current_rendering_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, simulator_objects::current_rendering_resolution.x, simulator_objects::current_rendering_resolution.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
}
else glCopyImageSubData(current_rendering_texture, GL_TEXTURE_2D, 0, 0, 0, 0, previous_rendering_texture, GL_TEXTURE_2D, 0, 0, 0, 0, simulator_objects::current_rendering_resolution.x, simulator_objects::current_rendering_resolution.y, 1);

XPLMBindTexture2d(EMPTY_OBJECT, 0);
}
Expand Down
6 changes: 3 additions & 3 deletions src/post_processing_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace post_processing_program
reference = create_program(vertex_shader, fragment_shader);
glUseProgram(reference);

GLint rendering_texture = glGetUniformLocation(reference, "rendering_texture");
glUniform1i(rendering_texture, 0);
GLint current_rendering_texture = glGetUniformLocation(reference, "current_rendering_texture");
glUniform1i(current_rendering_texture, 0);

near_clip_z = glGetUniformLocation(reference, "near_clip_z");

Expand All @@ -38,7 +38,7 @@ namespace post_processing_program
glUseProgram(reference);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, plugin_objects::rendering_texture);
glBindTexture(GL_TEXTURE_2D, plugin_objects::current_rendering_texture);

glUniform1f(near_clip_z, simulator_objects::near_clip_z);

Expand Down
Loading

0 comments on commit 22f6ae8

Please sign in to comment.