├── .gitignore ├── README.md ├── include ├── rendering_program.hpp ├── post_processing_program.hpp ├── dataref_helpers.hpp ├── opengl_helpers.hpp ├── plugin_objects.hpp └── simulator_objects.hpp ├── Enhanced Cloudscapes ├── textures │ ├── base_noise.png │ ├── blue_noise.png │ ├── cloud_map_1.png │ ├── cloud_map_2.png │ ├── cloud_map_3.png │ └── detail_noise.png └── shaders │ ├── post_processing │ ├── vertex_shader.glsl │ └── fragment_shader.glsl │ └── rendering │ ├── vertex_shader.glsl │ └── fragment_shader.glsl ├── src ├── post_processing_program.cpp ├── enhanced_cloudscapes.cpp ├── dataref_helpers.cpp ├── plugin_objects.cpp ├── opengl_helpers.cpp ├── rendering_program.cpp └── simulator_objects.cpp ├── CMakeLists.txt └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | out/ 3 | CMakeSettings.json 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Enhanced-Cloudscapes 2 | A freeware volumetric cloud replacement add-on for X-Plane 11 3 | -------------------------------------------------------------------------------- /include/rendering_program.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace rendering_program 4 | { 5 | void initialize(); 6 | void call(); 7 | } -------------------------------------------------------------------------------- /include/post_processing_program.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace post_processing_program 4 | { 5 | void initialize(); 6 | void call(); 7 | } -------------------------------------------------------------------------------- /Enhanced Cloudscapes/textures/base_noise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MayaMaya4096/Enhanced-Cloudscapes/HEAD/Enhanced Cloudscapes/textures/base_noise.png -------------------------------------------------------------------------------- /Enhanced Cloudscapes/textures/blue_noise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MayaMaya4096/Enhanced-Cloudscapes/HEAD/Enhanced Cloudscapes/textures/blue_noise.png -------------------------------------------------------------------------------- /Enhanced Cloudscapes/textures/cloud_map_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MayaMaya4096/Enhanced-Cloudscapes/HEAD/Enhanced Cloudscapes/textures/cloud_map_1.png -------------------------------------------------------------------------------- /Enhanced Cloudscapes/textures/cloud_map_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MayaMaya4096/Enhanced-Cloudscapes/HEAD/Enhanced Cloudscapes/textures/cloud_map_2.png -------------------------------------------------------------------------------- /Enhanced Cloudscapes/textures/cloud_map_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MayaMaya4096/Enhanced-Cloudscapes/HEAD/Enhanced Cloudscapes/textures/cloud_map_3.png -------------------------------------------------------------------------------- /Enhanced Cloudscapes/textures/detail_noise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MayaMaya4096/Enhanced-Cloudscapes/HEAD/Enhanced Cloudscapes/textures/detail_noise.png -------------------------------------------------------------------------------- /include/dataref_helpers.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | XPLMDataRef export_int_dataref(char* dataref_name, int initial_value); 8 | XPLMDataRef export_float_dataref(char* dataref_name, float initial_value); 9 | XPLMDataRef export_vec3_dataref(char* dataref_name, glm::vec3 initial_value); -------------------------------------------------------------------------------- /Enhanced Cloudscapes/shaders/post_processing/vertex_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | 3 | layout(location = 0) in vec2 input_vertex; 4 | 5 | uniform float near_clip_z; 6 | 7 | out vec2 fullscreen_texture_position; 8 | 9 | void main() 10 | { 11 | fullscreen_texture_position = (input_vertex / 2.0) + 0.5; 12 | gl_Position = vec4(input_vertex, near_clip_z, 1.0); 13 | } -------------------------------------------------------------------------------- /include/opengl_helpers.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define EMPTY_OBJECT 0 6 | 7 | int create_fullscreen_texture(); 8 | 9 | int create_texture(GLsizei texture_width, GLsizei texture_height, GLenum data_format, const void* texture_data); 10 | int create_texture(GLsizei texture_width, GLsizei texture_height, GLsizei texture_depth, GLenum data_format, const void* texture_data); 11 | 12 | int load_png_texture(const char* texture_path, bool add_depth); 13 | 14 | GLuint load_shader(const char* shader_path, GLenum shader_type); 15 | 16 | GLuint create_program(GLuint vertex_shader, GLuint fragment_shader); -------------------------------------------------------------------------------- /include/plugin_objects.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace plugin_objects 8 | { 9 | extern int previous_depth_texture; 10 | extern int current_depth_texture; 11 | 12 | extern int cloud_map_textures[CLOUD_LAYER_COUNT]; 13 | 14 | extern int base_noise_texture; 15 | extern int detail_noise_texture; 16 | 17 | extern int blue_noise_texture; 18 | 19 | extern int previous_rendering_texture; 20 | extern int current_rendering_texture; 21 | 22 | extern GLuint framebuffer; 23 | extern GLuint vertex_array; 24 | 25 | void initialize(); 26 | void update(); 27 | }; -------------------------------------------------------------------------------- /Enhanced Cloudscapes/shaders/post_processing/fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | 3 | in vec2 fullscreen_texture_position; 4 | 5 | uniform sampler2D current_rendering_texture; 6 | 7 | layout(location = 0) out vec4 fragment_color; 8 | 9 | #define CONSTANT_1 2.51 10 | #define CONSTANT_2 0.03 11 | #define CONSTANT_3 2.43 12 | #define CONSTANT_4 0.59 13 | #define CONSTANT_5 0.14 14 | 15 | vec3 tone_mapping(vec3 input_color) 16 | { 17 | return (input_color * ((CONSTANT_1 * input_color) + CONSTANT_2)) / ((input_color * ((CONSTANT_3 * input_color) + CONSTANT_4)) + CONSTANT_5); 18 | } 19 | 20 | void main() 21 | { 22 | vec4 rendered_color = texture(current_rendering_texture, fullscreen_texture_position); 23 | rendered_color.xyz = tone_mapping(rendered_color.xyz); 24 | 25 | fragment_color = rendered_color; 26 | } -------------------------------------------------------------------------------- /Enhanced Cloudscapes/shaders/rendering/vertex_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | 3 | layout(location = 0) in vec2 input_vertex; 4 | 5 | uniform float near_clip_z; 6 | uniform float far_clip_z; 7 | 8 | uniform mat4 inverse_modelview_matrix; 9 | uniform mat4 inverse_projection_matrix; 10 | 11 | out vec3 ray_start_position; 12 | out vec3 ray_end_position; 13 | 14 | out vec2 fullscreen_texture_position; 15 | 16 | void main() 17 | { 18 | vec4 ray_start_vector = inverse_projection_matrix * vec4(input_vertex, near_clip_z, 1.0); 19 | vec4 ray_end_vector = inverse_projection_matrix * vec4(input_vertex, far_clip_z, 1.0); 20 | 21 | ray_start_vector /= ray_start_vector.w; 22 | ray_end_vector /= ray_end_vector.w; 23 | 24 | ray_start_position = vec3(inverse_modelview_matrix * ray_start_vector); 25 | ray_end_position = vec3(inverse_modelview_matrix * ray_end_vector); 26 | 27 | fullscreen_texture_position = (input_vertex / 2.0) + 0.5; 28 | 29 | gl_Position = vec4(input_vertex, near_clip_z, 1.0); 30 | } -------------------------------------------------------------------------------- /src/post_processing_program.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace post_processing_program 11 | { 12 | GLuint reference; 13 | 14 | GLint near_clip_z; 15 | 16 | void initialize() 17 | { 18 | GLuint vertex_shader = load_shader("Resources/plugins/Enhanced Cloudscapes/shaders/post_processing/vertex_shader.glsl", GL_VERTEX_SHADER); 19 | GLuint fragment_shader = load_shader("Resources/plugins/Enhanced Cloudscapes/shaders/post_processing/fragment_shader.glsl", GL_FRAGMENT_SHADER); 20 | 21 | reference = create_program(vertex_shader, fragment_shader); 22 | glUseProgram(reference); 23 | 24 | GLint current_rendering_texture = glGetUniformLocation(reference, "current_rendering_texture"); 25 | glUniform1i(current_rendering_texture, 0); 26 | 27 | near_clip_z = glGetUniformLocation(reference, "near_clip_z"); 28 | 29 | glUseProgram(EMPTY_OBJECT); 30 | } 31 | 32 | void call() 33 | { 34 | XPLMSetGraphicsState(0, 1, 0, 0, 1, 0, 0); 35 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 36 | 37 | glBindVertexArray(plugin_objects::vertex_array); 38 | glUseProgram(reference); 39 | 40 | glActiveTexture(GL_TEXTURE0); 41 | glBindTexture(GL_TEXTURE_2D, plugin_objects::current_rendering_texture); 42 | 43 | glUniform1f(near_clip_z, simulator_objects::near_clip_z); 44 | 45 | glDrawArrays(GL_TRIANGLES, 0, 6); 46 | 47 | XPLMBindTexture2d(EMPTY_OBJECT, 0); 48 | 49 | glUseProgram(EMPTY_OBJECT); 50 | glBindVertexArray(EMPTY_OBJECT); 51 | 52 | glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 53 | } 54 | } -------------------------------------------------------------------------------- /src/enhanced_cloudscapes.cpp: -------------------------------------------------------------------------------- 1 | #ifdef IBM 2 | #include 3 | #endif 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #ifdef IBM 19 | BOOL APIENTRY DllMain(IN HINSTANCE dll_handle, IN DWORD call_reason, IN LPVOID reserved) 20 | { 21 | return TRUE; 22 | } 23 | #endif 24 | 25 | int draw_callback(XPLMDrawingPhase drawing_phase, int is_before, void* callback_reference) 26 | { 27 | simulator_objects::update(); 28 | plugin_objects::update(); 29 | 30 | rendering_program::call(); 31 | post_processing_program::call(); 32 | 33 | return 1; 34 | } 35 | 36 | PLUGIN_API int XPluginStart(char* plugin_name, char* plugin_signature, char* plugin_description) 37 | { 38 | std::strcpy(plugin_name, "Enhanced Cloudscapes"); 39 | std::strcpy(plugin_signature, "FarukEroglu2048.enhanced_cloudscapes"); 40 | std::strcpy(plugin_description, "Volumetric Clouds for X-Plane 11"); 41 | 42 | glewInit(); 43 | 44 | simulator_objects::initialize(); 45 | plugin_objects::initialize(); 46 | 47 | rendering_program::initialize(); 48 | post_processing_program::initialize(); 49 | 50 | XPLMRegisterDrawCallback(draw_callback, xplm_Phase_Modern3D, 0, nullptr); 51 | 52 | return 1; 53 | } 54 | 55 | PLUGIN_API void XPluginStop(void) 56 | { 57 | 58 | } 59 | 60 | PLUGIN_API int XPluginEnable(void) 61 | { 62 | return 1; 63 | } 64 | 65 | PLUGIN_API void XPluginDisable(void) 66 | { 67 | 68 | } 69 | 70 | PLUGIN_API void XPluginReceiveMessage(XPLMPluginID sender_plugin, int message_type, void* callback_parameters) 71 | { 72 | 73 | } -------------------------------------------------------------------------------- /include/simulator_objects.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #define CLOUD_LAYER_COUNT 3 9 | #define CLOUD_TYPE_COUNT 6 10 | 11 | namespace simulator_objects 12 | { 13 | extern glm::ivec4 previous_viewport; 14 | extern glm::ivec4 current_viewport; 15 | 16 | extern glm::ivec2 previous_rendering_resolution; 17 | extern glm::ivec2 current_rendering_resolution; 18 | 19 | extern int reverse_z; 20 | 21 | extern float near_clip_z; 22 | extern float far_clip_z; 23 | 24 | extern glm::dmat4 previous_mvp_matrix; 25 | extern glm::dmat4 current_mvp_matrix; 26 | 27 | extern glm::dmat4 inverse_modelview_matrix; 28 | extern glm::dmat4 inverse_projection_matrix; 29 | 30 | extern int skip_fragments; 31 | extern int frame_index; 32 | 33 | extern int sample_step_count; 34 | extern int sun_step_count; 35 | 36 | extern float maximum_sample_step_size; 37 | extern float maximum_sun_step_size; 38 | 39 | extern int use_blue_noise_dithering; 40 | 41 | extern float cloud_map_scale; 42 | 43 | extern float base_noise_scale; 44 | extern float detail_noise_scale; 45 | 46 | extern float blue_noise_scale; 47 | 48 | extern int cloud_types[CLOUD_LAYER_COUNT]; 49 | 50 | extern float cloud_bases[CLOUD_LAYER_COUNT]; 51 | extern float cloud_tops[CLOUD_LAYER_COUNT]; 52 | 53 | extern float cloud_coverages[CLOUD_TYPE_COUNT]; 54 | extern float cloud_densities[CLOUD_TYPE_COUNT]; 55 | 56 | extern glm::vec3 base_noise_ratios[CLOUD_TYPE_COUNT]; 57 | extern glm::vec3 detail_noise_ratios[CLOUD_TYPE_COUNT]; 58 | 59 | extern glm::vec3 wind_offsets[CLOUD_LAYER_COUNT]; 60 | 61 | extern float base_anvil; 62 | extern float top_anvil; 63 | 64 | extern float fade_start_distance; 65 | extern float fade_end_distance; 66 | 67 | extern float light_attenuation; 68 | 69 | extern glm::vec3 sun_direction; 70 | 71 | extern glm::vec3 sun_tint; 72 | extern float sun_gain; 73 | 74 | extern glm::vec3 ambient_tint; 75 | extern float ambient_gain; 76 | 77 | extern float mie_scattering; 78 | 79 | extern glm::vec3 atmosphere_bottom_tint; 80 | extern glm::vec3 atmosphere_top_tint; 81 | 82 | extern float atmospheric_blending; 83 | 84 | void initialize(); 85 | void update(); 86 | } -------------------------------------------------------------------------------- /src/dataref_helpers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int read_int_callback(void* float_pointer) 4 | { 5 | return *static_cast(float_pointer); 6 | } 7 | 8 | void write_int_callback(void* float_pointer, int new_value) 9 | { 10 | *static_cast(float_pointer) = new_value; 11 | } 12 | 13 | float read_float_callback(void* float_pointer) 14 | { 15 | return *static_cast(float_pointer); 16 | } 17 | 18 | void write_float_callback(void* float_pointer, float new_value) 19 | { 20 | *static_cast(float_pointer) = new_value; 21 | } 22 | 23 | int read_vec3_callback(void* vec3_pointer, float* output_values, int read_offset, int read_size) 24 | { 25 | glm::vec3& input_vec3 = *static_cast(vec3_pointer); 26 | 27 | if (output_values != nullptr) 28 | { 29 | int read_start = read_offset % input_vec3.length(); 30 | int read_end = read_start + read_size; 31 | 32 | if (read_end < read_start) read_end = read_start; 33 | else if (read_end > input_vec3.length()) read_end = input_vec3.length(); 34 | 35 | for (int index = read_start; index < read_end; index++) output_values[index] = input_vec3[index]; 36 | 37 | return read_end - read_start; 38 | } 39 | else return input_vec3.length(); 40 | } 41 | 42 | void write_vec3_callback(void* vector_pointer, float* input_values, int write_offset, int write_size) 43 | { 44 | glm::vec3& output_vec3 = *static_cast(vector_pointer); 45 | 46 | int write_start = write_offset % output_vec3.length(); 47 | int write_end = write_start + write_size; 48 | 49 | if (write_end < write_start) write_end = write_start; 50 | else if (write_end > output_vec3.length()) write_end = output_vec3.length(); 51 | 52 | for (int index = write_start; index < write_end; index++) output_vec3[index] = input_values[index]; 53 | } 54 | 55 | XPLMDataRef export_int_dataref(char* dataref_name, int initial_value) 56 | { 57 | int* int_pointer = new int(initial_value); 58 | 59 | return XPLMRegisterDataAccessor(dataref_name, xplmType_Int, 1, read_int_callback, write_int_callback, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, int_pointer, int_pointer); 60 | } 61 | 62 | XPLMDataRef export_float_dataref(char* dataref_name, float initial_value) 63 | { 64 | float* float_pointer = new float(initial_value); 65 | 66 | return XPLMRegisterDataAccessor(dataref_name, xplmType_Float, 1, nullptr, nullptr, read_float_callback, write_float_callback, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, float_pointer, float_pointer); 67 | } 68 | 69 | XPLMDataRef export_vec3_dataref(char* dataref_name, glm::vec3 initial_value) 70 | { 71 | glm::vec3* vec3_pointer = new glm::vec3(initial_value); 72 | 73 | return XPLMRegisterDataAccessor(dataref_name, xplmType_FloatArray, 1, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, read_vec3_callback, write_vec3_callback, nullptr, nullptr, vec3_pointer, vec3_pointer); 74 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | 3 | project("Enhanced Cloudscapes") 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED True) 7 | 8 | set(XPLM_SDK_INCLUDE_DIRECTORY "" CACHE PATH "X-Plane SDK include directory") 9 | set(XPLM_SDK_LIBRARY_FILE "" CACHE FILEPATH "X-Plane SDK library file (leave empty on Linux)") 10 | 11 | find_package(OpenGL REQUIRED) 12 | 13 | set(GLEW_INCLUDE_DIRECTORY "" CACHE PATH "GLEW include directory") 14 | set(GLEW_LIBRARY_FILE "" CACHE FILEPATH "GLEW library file") 15 | 16 | set(ZLIB_INCLUDE_DIRECTORY "" CACHE PATH "zlib include directory") 17 | set(ZLIB_LIBRARY_FILE "" CACHE FILEPATH "zlib library file") 18 | 19 | set(LIBPNG_INCLUDE_DIRECTORY "" CACHE PATH "libpng include directory") 20 | set(LIBPNG_LIBRARY_FILE "" CACHE FILEPATH "libpng library file") 21 | 22 | set(GLM_INCLUDE_DIRECTORY "" CACHE PATH "GLM include directory") 23 | 24 | add_library(enhanced_cloudscapes SHARED "include/dataref_helpers.hpp" "include/opengl_helpers.hpp" "include/simulator_objects.hpp" "include/plugin_objects.hpp" "include/rendering_program.hpp" "include/post_processing_program.hpp" "src/dataref_helpers.cpp" "src/opengl_helpers.cpp" "src/simulator_objects.cpp" "src/plugin_objects.cpp" "src/rendering_program.cpp" "src/post_processing_program.cpp" "src/enhanced_cloudscapes.cpp") 25 | 26 | target_include_directories(enhanced_cloudscapes PRIVATE "include" ${XPLM_SDK_INCLUDE_DIRECTORY} ${GLEW_INCLUDE_DIRECTORY} ${ZLIB_INCLUDE_DIRECTORY} ${LIBPNG_INCLUDE_DIRECTORY} ${GLM_INCLUDE_DIRECTORY}) 27 | target_link_libraries(enhanced_cloudscapes PRIVATE ${XPLM_SDK_LIBRARY_FILE} OpenGL::GL ${GLEW_LIBRARY_FILE} ${ZLIB_LIBRARY_FILE} ${LIBPNG_LIBRARY_FILE}) 28 | 29 | target_compile_definitions(enhanced_cloudscapes PRIVATE "XPLM200=1" "XPLM210=1" "XPLM300=1" "XPLM301=1" "XPLM302=1" "XPLM303=1" "XPLM_DEPRECATED=1") 30 | 31 | set_target_properties(enhanced_cloudscapes PROPERTIES PREFIX "") 32 | set_target_properties(enhanced_cloudscapes PROPERTIES SUFFIX ".xpl") 33 | 34 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows") 35 | target_compile_definitions(enhanced_cloudscapes PRIVATE "IBM=1" "GLEW_BUILD=1" "NOMINMAX=1") 36 | 37 | set_target_properties(enhanced_cloudscapes PROPERTIES OUTPUT_NAME "win") 38 | 39 | install(DIRECTORY "Enhanced Cloudscapes" DESTINATION ${CMAKE_INSTALL_PREFIX}) 40 | install(TARGETS enhanced_cloudscapes RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/Enhanced Cloudscapes") 41 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 42 | target_compile_definitions(enhanced_cloudscapes PRIVATE "LIN=1") 43 | 44 | set_target_properties(enhanced_cloudscapes PROPERTIES OUTPUT_NAME "lin") 45 | 46 | install(DIRECTORY "Enhanced Cloudscapes" DESTINATION ${CMAKE_INSTALL_PREFIX}) 47 | install(TARGETS enhanced_cloudscapes LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/Enhanced Cloudscapes") 48 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") 49 | target_compile_definitions(enhanced_cloudscapes PRIVATE "APL=1") 50 | 51 | set_target_properties(enhanced_cloudscapes PROPERTIES OUTPUT_NAME "mac") 52 | 53 | install(DIRECTORY "Enhanced Cloudscapes" DESTINATION ${CMAKE_INSTALL_PREFIX}) 54 | install(TARGETS enhanced_cloudscapes FRAMEWORK DESTINATION "${CMAKE_INSTALL_PREFIX}/Enhanced Cloudscapes") 55 | endif() -------------------------------------------------------------------------------- /src/plugin_objects.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace plugin_objects 8 | { 9 | int previous_depth_texture; 10 | int current_depth_texture; 11 | 12 | int cloud_map_textures[CLOUD_LAYER_COUNT]; 13 | 14 | int base_noise_texture; 15 | int detail_noise_texture; 16 | 17 | int blue_noise_texture; 18 | 19 | int previous_rendering_texture; 20 | int current_rendering_texture; 21 | 22 | GLuint framebuffer; 23 | GLuint vertex_array; 24 | 25 | void initialize() 26 | { 27 | previous_depth_texture = create_fullscreen_texture(); 28 | current_depth_texture = create_fullscreen_texture(); 29 | 30 | cloud_map_textures[0] = load_png_texture("Resources/plugins/Enhanced Cloudscapes/textures/cloud_map_1.png", false); 31 | cloud_map_textures[1] = load_png_texture("Resources/plugins/Enhanced Cloudscapes/textures/cloud_map_2.png", false); 32 | cloud_map_textures[2] = load_png_texture("Resources/plugins/Enhanced Cloudscapes/textures/cloud_map_3.png", false); 33 | 34 | base_noise_texture = load_png_texture("Resources/plugins/Enhanced Cloudscapes/textures/base_noise.png", true); 35 | detail_noise_texture = load_png_texture("Resources/plugins/Enhanced Cloudscapes/textures/detail_noise.png", true); 36 | 37 | blue_noise_texture = load_png_texture("Resources/plugins/Enhanced Cloudscapes/textures/blue_noise.png", false); 38 | 39 | previous_rendering_texture = create_fullscreen_texture(); 40 | current_rendering_texture = create_fullscreen_texture(); 41 | 42 | GLint previous_framebuffer; 43 | glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &previous_framebuffer); 44 | 45 | glGenFramebuffers(1, &framebuffer); 46 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer); 47 | 48 | glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, current_rendering_texture, 0); 49 | 50 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, previous_framebuffer); 51 | 52 | glGenVertexArrays(1, &vertex_array); 53 | glBindVertexArray(vertex_array); 54 | 55 | GLuint vertex_buffer; 56 | glGenBuffers(1, &vertex_buffer); 57 | 58 | glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); 59 | 60 | GLfloat quad_vertices[] = 61 | { 62 | -1.0, -1.0, 63 | -1.0, 1.0, 64 | 1.0, -1.0, 65 | 66 | 1.0, -1.0, 67 | -1.0, 1.0, 68 | 1.0, 1.0 69 | }; 70 | 71 | glBufferData(GL_ARRAY_BUFFER, sizeof(quad_vertices), quad_vertices, GL_STATIC_DRAW); 72 | 73 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); 74 | glEnableVertexAttribArray(0); 75 | 76 | glBindBuffer(GL_ARRAY_BUFFER, EMPTY_OBJECT); 77 | 78 | glBindVertexArray(EMPTY_OBJECT); 79 | } 80 | 81 | void update() 82 | { 83 | XPLMSetGraphicsState(0, 1, 0, 0, 0, 0, 0); 84 | glActiveTexture(GL_TEXTURE0); 85 | 86 | if ((simulator_objects::current_viewport.z != simulator_objects::previous_viewport.z) || (simulator_objects::current_viewport.w != simulator_objects::previous_viewport.w)) 87 | { 88 | GLenum depth_format; 89 | 90 | if (simulator_objects::reverse_z == 0) depth_format = GL_DEPTH_COMPONENT24; 91 | else depth_format = GL_DEPTH_COMPONENT32F; 92 | 93 | glBindTexture(GL_TEXTURE_2D, previous_depth_texture); 94 | 95 | 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); 96 | 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); 97 | 98 | glBindTexture(GL_TEXTURE_2D, current_depth_texture); 99 | 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); 100 | } 101 | else 102 | { 103 | 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); 104 | 105 | glBindTexture(GL_TEXTURE_2D, current_depth_texture); 106 | 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); 107 | } 108 | 109 | 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)) 110 | { 111 | glBindTexture(GL_TEXTURE_2D, previous_rendering_texture); 112 | 113 | 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); 114 | 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); 115 | 116 | glBindTexture(GL_TEXTURE_2D, current_rendering_texture); 117 | 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); 118 | } 119 | 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); 120 | 121 | XPLMBindTexture2d(EMPTY_OBJECT, 0); 122 | } 123 | } -------------------------------------------------------------------------------- /src/opengl_helpers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | void read_stream_callback(png_structp png_struct, png_bytep output_data, png_size_t read_size) 11 | { 12 | png_voidp stream_pointer = png_get_io_ptr(png_struct); 13 | 14 | std::ifstream& input_stream = *static_cast(stream_pointer); 15 | input_stream.read(reinterpret_cast(output_data), read_size); 16 | } 17 | 18 | png_size_t get_bytes_per_pixel(png_byte color_type) 19 | { 20 | switch (color_type) 21 | { 22 | case PNG_COLOR_TYPE_GRAY: 23 | return 1; 24 | case PNG_COLOR_TYPE_GRAY_ALPHA: 25 | return 2; 26 | case PNG_COLOR_TYPE_RGB: 27 | return 3; 28 | case PNG_COLOR_TYPE_RGB_ALPHA: 29 | return 4; 30 | } 31 | } 32 | 33 | GLenum get_texture_format(png_byte color_type) 34 | { 35 | switch (color_type) 36 | { 37 | case PNG_COLOR_TYPE_GRAY: 38 | return GL_RED; 39 | case PNG_COLOR_TYPE_GRAY_ALPHA: 40 | return GL_RG; 41 | case PNG_COLOR_TYPE_RGB: 42 | return GL_RGB; 43 | case PNG_COLOR_TYPE_RGB_ALPHA: 44 | return GL_RGBA; 45 | } 46 | } 47 | 48 | png_size_t integer_square_root(png_size_t input_value) 49 | { 50 | png_size_t square_root = 0; 51 | while ((square_root * square_root) < input_value) square_root++; 52 | 53 | return square_root; 54 | } 55 | 56 | int create_fullscreen_texture() 57 | { 58 | int texture_reference; 59 | XPLMGenerateTextureNumbers(&texture_reference, 1); 60 | 61 | glActiveTexture(GL_TEXTURE0); 62 | glBindTexture(GL_TEXTURE_2D, texture_reference); 63 | 64 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 65 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 66 | 67 | XPLMBindTexture2d(EMPTY_OBJECT, 0); 68 | 69 | return texture_reference; 70 | } 71 | 72 | int create_texture(GLsizei texture_width, GLsizei texture_height, GLenum data_format, const void* texture_data) 73 | { 74 | int texture_reference; 75 | XPLMGenerateTextureNumbers(&texture_reference, 1); 76 | 77 | glActiveTexture(GL_TEXTURE0); 78 | glBindTexture(GL_TEXTURE_2D, texture_reference); 79 | 80 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 81 | glTexImage2D(GL_TEXTURE_2D, 0, data_format, texture_width, texture_height, 0, data_format, GL_UNSIGNED_BYTE, texture_data); 82 | 83 | XPLMBindTexture2d(EMPTY_OBJECT, 0); 84 | 85 | return texture_reference; 86 | } 87 | 88 | int create_texture(GLsizei texture_width, GLsizei texture_height, GLsizei texture_depth, GLenum data_format, const void* texture_data) 89 | { 90 | int texture_reference; 91 | XPLMGenerateTextureNumbers(&texture_reference, 1); 92 | 93 | glActiveTexture(GL_TEXTURE0); 94 | glBindTexture(GL_TEXTURE_3D, texture_reference); 95 | 96 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 97 | glTexImage3D(GL_TEXTURE_3D, 0, data_format, texture_width, texture_height, texture_depth, 0, data_format, GL_UNSIGNED_BYTE, texture_data); 98 | 99 | XPLMBindTexture2d(EMPTY_OBJECT, 0); 100 | 101 | return texture_reference; 102 | } 103 | 104 | int load_png_texture(const char* texture_path, bool add_depth) 105 | { 106 | int output_texture = EMPTY_OBJECT; 107 | 108 | std::ifstream texture_file(texture_path, std::ifstream::binary); 109 | 110 | if (texture_file.fail() == false) 111 | { 112 | png_structp png_struct = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); 113 | png_infop png_info = png_create_info_struct(png_struct); 114 | 115 | png_set_read_fn(png_struct, &texture_file, read_stream_callback); 116 | 117 | png_read_info(png_struct, png_info); 118 | 119 | png_set_scale_16(png_struct); 120 | png_set_expand(png_struct); 121 | 122 | png_byte color_type = png_get_color_type(png_struct, png_info); 123 | 124 | png_size_t bytes_per_pixel = get_bytes_per_pixel(color_type); 125 | 126 | png_uint_32 image_width = png_get_image_width(png_struct, png_info); 127 | png_uint_32 image_height = png_get_image_height(png_struct, png_info); 128 | 129 | png_bytep texture_data = new png_byte[image_height * image_width * bytes_per_pixel]; 130 | png_bytepp texture_row_pointers = new png_bytep[image_height]; 131 | 132 | for (png_size_t row_index = 0; row_index < image_height; row_index++) texture_row_pointers[row_index] = &texture_data[row_index * image_width * bytes_per_pixel]; 133 | 134 | png_read_image(png_struct, texture_row_pointers); 135 | 136 | if (add_depth == true) output_texture = create_texture(image_width, integer_square_root(image_height), integer_square_root(image_height), get_texture_format(color_type), texture_data); 137 | else output_texture = create_texture(image_width, image_height, get_texture_format(color_type), texture_data); 138 | 139 | delete[] texture_row_pointers; 140 | delete[] texture_data; 141 | 142 | png_destroy_read_struct(&png_struct, &png_info, nullptr); 143 | } 144 | else 145 | { 146 | XPLMDebugString("Could not open texture file!"); 147 | 148 | XPLMDebugString("Texture file path is:"); 149 | XPLMDebugString(texture_path); 150 | } 151 | 152 | return output_texture; 153 | } 154 | 155 | GLuint load_shader(const char* shader_path, GLenum shader_type) 156 | { 157 | GLuint output_shader = EMPTY_OBJECT; 158 | 159 | std::ifstream shader_file(shader_path, std::ifstream::binary | std::ifstream::ate); 160 | 161 | if (shader_file.fail() == false) 162 | { 163 | GLint shader_file_size = shader_file.tellg(); 164 | 165 | shader_file.seekg(0); 166 | 167 | GLchar* shader_string = new GLchar[shader_file_size]; 168 | shader_file.read(shader_string, shader_file_size); 169 | 170 | GLuint shader_reference = glCreateShader(shader_type); 171 | 172 | glShaderSource(shader_reference, 1, &shader_string, &shader_file_size); 173 | glCompileShader(shader_reference); 174 | 175 | delete[] shader_string; 176 | 177 | GLint shader_compilation_status; 178 | glGetShaderiv(shader_reference, GL_COMPILE_STATUS, &shader_compilation_status); 179 | 180 | if (shader_compilation_status == GL_TRUE) output_shader = shader_reference; 181 | else 182 | { 183 | GLint compilation_log_length; 184 | glGetShaderiv(shader_reference, GL_INFO_LOG_LENGTH, &compilation_log_length); 185 | 186 | GLchar* compilation_message = new GLchar[compilation_log_length]; 187 | glGetShaderInfoLog(shader_reference, compilation_log_length, nullptr, compilation_message); 188 | 189 | XPLMDebugString("\nShader compilation failed!\n\n"); 190 | 191 | XPLMDebugString("Compilation error message is:\n"); 192 | XPLMDebugString(compilation_message); 193 | 194 | delete[] compilation_message; 195 | } 196 | } 197 | else 198 | { 199 | XPLMDebugString("\nCould not open shader file!\n\n"); 200 | 201 | XPLMDebugString("Shader file path is:\n"); 202 | XPLMDebugString(shader_path); 203 | } 204 | 205 | return output_shader; 206 | } 207 | 208 | GLuint create_program(GLuint vertex_shader, GLuint fragment_shader) 209 | { 210 | GLuint output_program = EMPTY_OBJECT; 211 | 212 | GLuint program_reference = glCreateProgram(); 213 | 214 | glAttachShader(program_reference, vertex_shader); 215 | glAttachShader(program_reference, fragment_shader); 216 | 217 | glLinkProgram(program_reference); 218 | 219 | GLint program_link_status; 220 | glGetProgramiv(program_reference, GL_LINK_STATUS, &program_link_status); 221 | 222 | if (program_link_status == GL_TRUE) output_program = program_reference; 223 | else 224 | { 225 | GLint compilation_log_length; 226 | glGetProgramiv(program_reference, GL_INFO_LOG_LENGTH, &compilation_log_length); 227 | 228 | GLchar* compilation_message = new GLchar[compilation_log_length]; 229 | glGetProgramInfoLog(program_reference, compilation_log_length, nullptr, compilation_message); 230 | 231 | XPLMDebugString("\nProgram compilation failed!\n\n"); 232 | 233 | XPLMDebugString("Compilation error message is:\n"); 234 | XPLMDebugString(compilation_message); 235 | 236 | delete[] compilation_message; 237 | } 238 | 239 | return output_program; 240 | } -------------------------------------------------------------------------------- /src/rendering_program.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace rendering_program 13 | { 14 | GLint reference; 15 | 16 | GLint near_clip_z; 17 | GLint far_clip_z; 18 | 19 | GLint previous_mvp_matrix; 20 | GLint current_mvp_matrix; 21 | 22 | GLint inverse_modelview_matrix; 23 | GLint inverse_projection_matrix; 24 | 25 | GLint skip_fragments; 26 | GLint frame_index; 27 | 28 | GLint sample_step_count; 29 | GLint sun_step_count; 30 | 31 | GLint maximum_sample_step_size; 32 | GLint maximum_sun_step_size; 33 | 34 | GLint use_blue_noise_dithering; 35 | 36 | GLint cloud_map_scale; 37 | 38 | GLint base_noise_scale; 39 | GLint detail_noise_scale; 40 | 41 | GLint blue_noise_scale; 42 | 43 | GLint cloud_types; 44 | 45 | GLint cloud_bases; 46 | GLint cloud_tops; 47 | 48 | GLint cloud_coverages; 49 | GLint cloud_densities; 50 | 51 | GLint base_noise_ratios; 52 | GLint detail_noise_ratios; 53 | 54 | GLint wind_offsets; 55 | 56 | GLint base_anvil; 57 | GLint top_anvil; 58 | 59 | GLint fade_start_distance; 60 | GLint fade_end_distance; 61 | 62 | GLint light_attenuation; 63 | 64 | GLint sun_direction; 65 | 66 | GLint sun_tint; 67 | GLint sun_gain; 68 | 69 | GLint ambient_tint; 70 | GLint ambient_gain; 71 | 72 | GLint mie_scattering; 73 | 74 | GLint atmosphere_bottom_tint; 75 | GLint atmosphere_top_tint; 76 | 77 | GLint atmospheric_blending; 78 | 79 | void initialize() 80 | { 81 | GLuint vertex_shader = load_shader("Resources/plugins/Enhanced Cloudscapes/shaders/rendering/vertex_shader.glsl", GL_VERTEX_SHADER); 82 | GLuint fragment_shader = load_shader("Resources/plugins/Enhanced Cloudscapes/shaders/rendering/fragment_shader.glsl", GL_FRAGMENT_SHADER); 83 | 84 | reference = create_program(vertex_shader, fragment_shader); 85 | glUseProgram(reference); 86 | 87 | GLint previous_depth_texture = glGetUniformLocation(reference, "previous_depth_texture"); 88 | GLint current_depth_texture = glGetUniformLocation(reference, "current_depth_texture"); 89 | 90 | GLint cloud_map_textures = glGetUniformLocation(reference, "cloud_map_textures"); 91 | 92 | GLint base_noise_texture = glGetUniformLocation(reference, "base_noise_texture"); 93 | GLint detail_noise_texture = glGetUniformLocation(reference, "detail_noise_texture"); 94 | 95 | GLint blue_noise_texture = glGetUniformLocation(reference, "blue_noise_texture"); 96 | 97 | GLint previous_rendering_texture = glGetUniformLocation(reference, "previous_rendering_texture"); 98 | 99 | glUniform1i(previous_depth_texture, 0); 100 | glUniform1i(current_depth_texture, 1); 101 | 102 | GLint texture_indices[CLOUD_LAYER_COUNT] = {2, 3, 4}; 103 | glUniform1iv(cloud_map_textures, CLOUD_LAYER_COUNT, texture_indices); 104 | 105 | glUniform1i(base_noise_texture, 5); 106 | glUniform1i(detail_noise_texture, 6); 107 | 108 | glUniform1i(blue_noise_texture, 7); 109 | 110 | glUniform1i(previous_rendering_texture, 8); 111 | 112 | near_clip_z = glGetUniformLocation(reference, "near_clip_z"); 113 | far_clip_z = glGetUniformLocation(reference, "far_clip_z"); 114 | 115 | previous_mvp_matrix = glGetUniformLocation(reference, "previous_mvp_matrix"); 116 | current_mvp_matrix = glGetUniformLocation(reference, "current_mvp_matrix"); 117 | 118 | inverse_modelview_matrix = glGetUniformLocation(reference, "inverse_modelview_matrix"); 119 | inverse_projection_matrix = glGetUniformLocation(reference, "inverse_projection_matrix"); 120 | 121 | skip_fragments = glGetUniformLocation(reference, "skip_fragments"); 122 | frame_index = glGetUniformLocation(reference, "frame_index"); 123 | 124 | sample_step_count = glGetUniformLocation(reference, "sample_step_count"); 125 | sun_step_count = glGetUniformLocation(reference, "sun_step_count"); 126 | 127 | maximum_sample_step_size = glGetUniformLocation(reference, "maximum_sample_step_size"); 128 | maximum_sun_step_size = glGetUniformLocation(reference, "maximum_sun_step_size"); 129 | 130 | use_blue_noise_dithering = glGetUniformLocation(reference, "use_blue_noise_dithering"); 131 | 132 | cloud_map_scale = glGetUniformLocation(reference, "cloud_map_scale"); 133 | 134 | base_noise_scale = glGetUniformLocation(reference, "base_noise_scale"); 135 | detail_noise_scale = glGetUniformLocation(reference, "detail_noise_scale"); 136 | 137 | blue_noise_scale = glGetUniformLocation(reference, "blue_noise_scale"); 138 | 139 | cloud_types = glGetUniformLocation(reference, "cloud_types"); 140 | 141 | cloud_bases = glGetUniformLocation(reference, "cloud_bases"); 142 | cloud_tops = glGetUniformLocation(reference, "cloud_tops"); 143 | 144 | cloud_coverages = glGetUniformLocation(reference, "cloud_coverages"); 145 | cloud_densities = glGetUniformLocation(reference, "cloud_densities"); 146 | 147 | base_noise_ratios = glGetUniformLocation(reference, "base_noise_ratios"); 148 | detail_noise_ratios = glGetUniformLocation(reference, "detail_noise_ratios"); 149 | 150 | wind_offsets = glGetUniformLocation(reference, "wind_offsets"); 151 | 152 | base_anvil = glGetUniformLocation(reference, "base_anvil"); 153 | top_anvil = glGetUniformLocation(reference, "top_anvil"); 154 | 155 | fade_start_distance = glGetUniformLocation(reference, "fade_start_distance"); 156 | fade_end_distance = glGetUniformLocation(reference, "fade_end_distance"); 157 | 158 | light_attenuation = glGetUniformLocation(reference, "light_attenuation"); 159 | 160 | sun_direction = glGetUniformLocation(reference, "sun_direction"); 161 | 162 | sun_tint = glGetUniformLocation(reference, "sun_tint"); 163 | sun_gain = glGetUniformLocation(reference, "sun_gain"); 164 | 165 | ambient_tint = glGetUniformLocation(reference, "ambient_tint"); 166 | ambient_gain = glGetUniformLocation(reference, "ambient_gain"); 167 | 168 | mie_scattering = glGetUniformLocation(reference, "mie_scattering"); 169 | 170 | atmosphere_bottom_tint = glGetUniformLocation(reference, "atmosphere_bottom_tint"); 171 | atmosphere_top_tint = glGetUniformLocation(reference, "atmosphere_top_tint"); 172 | 173 | atmospheric_blending = glGetUniformLocation(reference, "atmospheric_blending"); 174 | 175 | glUseProgram(EMPTY_OBJECT); 176 | } 177 | 178 | void call() 179 | { 180 | XPLMSetGraphicsState(0, 9, 0, 0, 0, 0, 0); 181 | 182 | GLint previous_framebuffer; 183 | glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &previous_framebuffer); 184 | 185 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, plugin_objects::framebuffer); 186 | glViewport(0, 0, simulator_objects::current_rendering_resolution.x, simulator_objects::current_rendering_resolution.y); 187 | 188 | glBindVertexArray(plugin_objects::vertex_array); 189 | 190 | glUseProgram(reference); 191 | 192 | glActiveTexture(GL_TEXTURE0); 193 | glBindTexture(GL_TEXTURE_2D, plugin_objects::previous_depth_texture); 194 | 195 | glActiveTexture(GL_TEXTURE1); 196 | glBindTexture(GL_TEXTURE_2D, plugin_objects::current_depth_texture); 197 | 198 | glActiveTexture(GL_TEXTURE2); 199 | glBindTexture(GL_TEXTURE_2D, plugin_objects::cloud_map_textures[0]); 200 | 201 | glActiveTexture(GL_TEXTURE3); 202 | glBindTexture(GL_TEXTURE_2D, plugin_objects::cloud_map_textures[1]); 203 | 204 | glActiveTexture(GL_TEXTURE4); 205 | glBindTexture(GL_TEXTURE_2D, plugin_objects::cloud_map_textures[2]); 206 | 207 | glActiveTexture(GL_TEXTURE5); 208 | glBindTexture(GL_TEXTURE_3D, plugin_objects::base_noise_texture); 209 | 210 | glActiveTexture(GL_TEXTURE6); 211 | glBindTexture(GL_TEXTURE_3D, plugin_objects::detail_noise_texture); 212 | 213 | glActiveTexture(GL_TEXTURE7); 214 | glBindTexture(GL_TEXTURE_2D, plugin_objects::blue_noise_texture); 215 | 216 | glActiveTexture(GL_TEXTURE8); 217 | glBindTexture(GL_TEXTURE_2D, plugin_objects::previous_rendering_texture); 218 | 219 | glUniform1f(near_clip_z, simulator_objects::near_clip_z); 220 | glUniform1f(far_clip_z, simulator_objects::far_clip_z); 221 | 222 | glUniformMatrix4fv(previous_mvp_matrix, 1, GL_FALSE, glm::value_ptr(glm::mat4(simulator_objects::previous_mvp_matrix))); 223 | glUniformMatrix4fv(current_mvp_matrix, 1, GL_FALSE, glm::value_ptr(glm::mat4(simulator_objects::current_mvp_matrix))); 224 | 225 | glUniformMatrix4fv(inverse_modelview_matrix, 1, GL_FALSE, glm::value_ptr(glm::mat4(simulator_objects::inverse_modelview_matrix))); 226 | glUniformMatrix4fv(inverse_projection_matrix, 1, GL_FALSE, glm::value_ptr(glm::mat4(simulator_objects::inverse_projection_matrix))); 227 | 228 | glUniform1i(skip_fragments, simulator_objects::skip_fragments); 229 | glUniform1i(frame_index, simulator_objects::frame_index); 230 | 231 | glUniform1i(sample_step_count, simulator_objects::sample_step_count); 232 | glUniform1i(sun_step_count, simulator_objects::sun_step_count); 233 | 234 | glUniform1f(maximum_sample_step_size, simulator_objects::maximum_sample_step_size); 235 | glUniform1f(maximum_sun_step_size, simulator_objects::maximum_sun_step_size); 236 | 237 | glUniform1i(use_blue_noise_dithering, simulator_objects::use_blue_noise_dithering); 238 | 239 | glUniform1f(cloud_map_scale, simulator_objects::cloud_map_scale); 240 | 241 | glUniform1f(base_noise_scale, simulator_objects::base_noise_scale); 242 | glUniform1f(detail_noise_scale, simulator_objects::detail_noise_scale); 243 | 244 | glUniform1f(blue_noise_scale, simulator_objects::blue_noise_scale); 245 | 246 | glUniform1iv(cloud_types, CLOUD_LAYER_COUNT, simulator_objects::cloud_types); 247 | 248 | glUniform1fv(cloud_bases, CLOUD_LAYER_COUNT, simulator_objects::cloud_bases); 249 | glUniform1fv(cloud_tops, CLOUD_LAYER_COUNT, simulator_objects::cloud_tops); 250 | 251 | glUniform1fv(cloud_coverages, CLOUD_TYPE_COUNT, simulator_objects::cloud_coverages); 252 | glUniform1fv(cloud_densities, CLOUD_TYPE_COUNT, simulator_objects::cloud_densities); 253 | 254 | glUniform3fv(base_noise_ratios, CLOUD_TYPE_COUNT, reinterpret_cast(simulator_objects::base_noise_ratios)); 255 | glUniform3fv(detail_noise_ratios, CLOUD_TYPE_COUNT, reinterpret_cast(simulator_objects::detail_noise_ratios)); 256 | 257 | glUniform3fv(wind_offsets, CLOUD_LAYER_COUNT, reinterpret_cast(simulator_objects::wind_offsets)); 258 | 259 | glUniform1f(base_anvil, simulator_objects::base_anvil); 260 | glUniform1f(top_anvil, simulator_objects::top_anvil); 261 | 262 | glUniform1f(fade_start_distance, simulator_objects::fade_start_distance); 263 | glUniform1f(fade_end_distance, simulator_objects::fade_end_distance); 264 | 265 | glUniform1f(light_attenuation, simulator_objects::light_attenuation); 266 | 267 | glUniform3fv(sun_direction, 1, glm::value_ptr(simulator_objects::sun_direction)); 268 | 269 | glUniform3fv(sun_tint, 1, glm::value_ptr(simulator_objects::sun_tint)); 270 | glUniform1f(sun_gain, simulator_objects::sun_gain); 271 | 272 | glUniform3fv(ambient_tint, 1, glm::value_ptr(simulator_objects::ambient_tint)); 273 | glUniform1f(ambient_gain, simulator_objects::ambient_gain); 274 | 275 | glUniform1f(mie_scattering, simulator_objects::mie_scattering); 276 | 277 | glUniform3fv(atmosphere_bottom_tint, 1, glm::value_ptr(simulator_objects::atmosphere_bottom_tint)); 278 | glUniform3fv(atmosphere_top_tint, 1, glm::value_ptr(simulator_objects::atmosphere_top_tint)); 279 | 280 | glUniform1f(atmospheric_blending, simulator_objects::atmospheric_blending); 281 | 282 | glDrawArrays(GL_TRIANGLES, 0, 6); 283 | 284 | XPLMBindTexture2d(EMPTY_OBJECT, 0); 285 | XPLMBindTexture2d(EMPTY_OBJECT, 1); 286 | 287 | XPLMBindTexture2d(EMPTY_OBJECT, 2); 288 | XPLMBindTexture2d(EMPTY_OBJECT, 3); 289 | XPLMBindTexture2d(EMPTY_OBJECT, 4); 290 | 291 | XPLMBindTexture2d(EMPTY_OBJECT, 5); 292 | XPLMBindTexture2d(EMPTY_OBJECT, 6); 293 | 294 | XPLMBindTexture2d(EMPTY_OBJECT, 7); 295 | 296 | XPLMBindTexture2d(EMPTY_OBJECT, 8); 297 | 298 | glUseProgram(EMPTY_OBJECT); 299 | 300 | glBindVertexArray(EMPTY_OBJECT); 301 | 302 | glViewport(simulator_objects::current_viewport.x, simulator_objects::current_viewport.y, simulator_objects::current_viewport.z, simulator_objects::current_viewport.w); 303 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, previous_framebuffer); 304 | } 305 | } -------------------------------------------------------------------------------- /Enhanced Cloudscapes/shaders/rendering/fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | 3 | #define CLOUD_LAYER_COUNT 3 4 | #define CLOUD_TYPE_COUNT 6 5 | 6 | #define EARTH_RADIUS 6378100.0 7 | #define EARTH_CENTER vec3(0.0, -1.0 * EARTH_RADIUS, 0.0) 8 | 9 | #define PI 3.141592653589793 10 | 11 | in vec3 ray_start_position; 12 | in vec3 ray_end_position; 13 | 14 | in vec2 fullscreen_texture_position; 15 | 16 | uniform sampler2D previous_depth_texture; 17 | uniform sampler2D current_depth_texture; 18 | 19 | uniform sampler2D[CLOUD_LAYER_COUNT] cloud_map_textures; 20 | 21 | uniform sampler3D base_noise_texture; 22 | uniform sampler3D detail_noise_texture; 23 | 24 | uniform sampler2D blue_noise_texture; 25 | 26 | uniform sampler2D previous_rendering_texture; 27 | 28 | uniform int skip_fragments; 29 | uniform int frame_index; 30 | 31 | uniform int sample_step_count; 32 | uniform int sun_step_count; 33 | 34 | uniform float maximum_sample_step_size; 35 | uniform float maximum_sun_step_size; 36 | 37 | uniform int use_blue_noise_dithering; 38 | 39 | uniform float near_clip_z; 40 | uniform float far_clip_z; 41 | 42 | uniform mat4 previous_mvp_matrix; 43 | uniform mat4 current_mvp_matrix; 44 | 45 | uniform mat4 inverse_modelview_matrix; 46 | uniform mat4 inverse_projection_matrix; 47 | 48 | uniform float cloud_map_scale; 49 | 50 | uniform float base_noise_scale; 51 | uniform float detail_noise_scale; 52 | 53 | uniform float blue_noise_scale; 54 | 55 | uniform int[CLOUD_LAYER_COUNT] cloud_types; 56 | 57 | uniform float[CLOUD_LAYER_COUNT] cloud_bases; 58 | uniform float[CLOUD_LAYER_COUNT] cloud_tops; 59 | 60 | uniform float[CLOUD_TYPE_COUNT] cloud_coverages; 61 | uniform float[CLOUD_TYPE_COUNT] cloud_densities; 62 | 63 | uniform vec3[CLOUD_TYPE_COUNT] base_noise_ratios; 64 | uniform vec3[CLOUD_TYPE_COUNT] detail_noise_ratios; 65 | 66 | uniform vec3[CLOUD_TYPE_COUNT] wind_offsets; 67 | 68 | uniform float base_anvil; 69 | uniform float top_anvil; 70 | 71 | uniform float fade_start_distance; 72 | uniform float fade_end_distance; 73 | 74 | uniform float light_attenuation; 75 | 76 | uniform vec3 sun_direction; 77 | 78 | uniform vec3 sun_tint; 79 | uniform float sun_gain; 80 | 81 | uniform vec3 ambient_tint; 82 | uniform float ambient_gain; 83 | 84 | uniform float mie_scattering; 85 | 86 | uniform vec3 atmosphere_bottom_tint; 87 | uniform vec3 atmosphere_top_tint; 88 | 89 | uniform float atmospheric_blending; 90 | 91 | layout(location = 0) out vec4 fragment_color; 92 | 93 | vec3 sample_direction; 94 | 95 | vec3 world_intersection; 96 | float world_distance; 97 | 98 | int bayer_filter[16] = 99 | { 100 | 0, 8, 2, 10, 101 | 12, 4, 14, 6, 102 | 3, 11, 1, 9, 103 | 15, 7, 13, 5 104 | }; 105 | 106 | float map(in float input_value, in float input_start, in float input_end, in float output_start, in float output_end) 107 | { 108 | float slope = (output_end - output_start) / (input_end - input_start); 109 | 110 | return clamp((slope * (input_value - input_start)) + output_start, min(output_start, output_end), max(output_start, output_end)); 111 | } 112 | 113 | float get_height_ratio(in vec3 ray_position, in int layer_index) 114 | { 115 | return map(length(ray_position - EARTH_CENTER) - EARTH_RADIUS, cloud_bases[layer_index], cloud_tops[layer_index], 0.0, 1.0); 116 | } 117 | 118 | vec2 ray_sphere_intersections(in vec3 ray_position, in vec3 ray_direction, in float sphere_height) 119 | { 120 | vec3 ray_earth_vector = ray_position - EARTH_CENTER; 121 | 122 | float coefficient_1 = 2.0 * dot(ray_direction, ray_earth_vector); 123 | float coefficient_2 = dot(ray_earth_vector, ray_earth_vector) - pow(EARTH_RADIUS + sphere_height, 2.0); 124 | 125 | float discriminant = pow(coefficient_1, 2.0) - (4.0 * coefficient_2); 126 | 127 | if (discriminant < 0.0) return vec2(0.0, 0.0); 128 | else 129 | { 130 | float lower_solution = ((-1.0 * coefficient_1) - sqrt(discriminant)) / 2.0; 131 | float higher_solution = ((-1.0 * coefficient_1) + sqrt(discriminant)) / 2.0; 132 | 133 | if (lower_solution < 0.0) return vec2(max(higher_solution, 0.0), 0.0); 134 | else return vec2(lower_solution, higher_solution); 135 | } 136 | } 137 | 138 | vec2 ray_layer_intersections(in vec3 ray_position, in vec3 ray_direction, in int layer_index) 139 | { 140 | vec2 layer_intersections = vec2(0.0, 0.0); 141 | 142 | vec2 inner_sphere_intersections = ray_sphere_intersections(ray_position, ray_direction, cloud_bases[layer_index]); 143 | vec2 outer_sphere_intersections = ray_sphere_intersections(ray_position, ray_direction, cloud_tops[layer_index]); 144 | 145 | float height_ratio = get_height_ratio(ray_position, layer_index); 146 | 147 | if (height_ratio == 0.0) 148 | { 149 | layer_intersections.x = inner_sphere_intersections.x; 150 | layer_intersections.y = outer_sphere_intersections.x - inner_sphere_intersections.x; 151 | } 152 | else if ((height_ratio > 0.0) && (height_ratio < 1.0)) 153 | { 154 | float lower_distance = min(inner_sphere_intersections.x, outer_sphere_intersections.x); 155 | float higher_distance = max(inner_sphere_intersections.x, outer_sphere_intersections.x); 156 | 157 | if (lower_distance == 0.0) layer_intersections.y = higher_distance; 158 | else layer_intersections.y = lower_distance; 159 | } 160 | else if (height_ratio == 1.0) 161 | { 162 | if (inner_sphere_intersections.x == 0.0) 163 | { 164 | layer_intersections.x = outer_sphere_intersections.x; 165 | layer_intersections.y = outer_sphere_intersections.y - outer_sphere_intersections.x; 166 | } 167 | else 168 | { 169 | layer_intersections.x = outer_sphere_intersections.x; 170 | layer_intersections.y = inner_sphere_intersections.x - outer_sphere_intersections.x; 171 | } 172 | } 173 | 174 | return layer_intersections; 175 | } 176 | 177 | int get_closest_layer(in vec3 ray_position, in vec3 ray_direction) 178 | { 179 | int closest_layer; 180 | 181 | if (ray_direction.y < 0.0) 182 | { 183 | closest_layer = CLOUD_LAYER_COUNT - 1; 184 | while ((closest_layer > 0) && ((cloud_types[closest_layer] == 0) || (get_height_ratio(ray_position, closest_layer) == 0.0))) closest_layer--; 185 | } 186 | else 187 | { 188 | closest_layer = 0; 189 | while ((closest_layer < (CLOUD_LAYER_COUNT - 1)) && ((cloud_types[closest_layer] == 0) || (get_height_ratio(ray_position, closest_layer) == 1.0))) closest_layer++; 190 | } 191 | 192 | return closest_layer; 193 | } 194 | 195 | float henyey_greenstein(in float dot_angle, in float scattering_value) 196 | { 197 | float squared_scattering_value = pow(scattering_value, 2.0); 198 | 199 | return (1.0 - squared_scattering_value) / (4.0 * PI * pow(squared_scattering_value - (2.0 * scattering_value * dot_angle) + 1.0, 1.5)); 200 | } 201 | 202 | float sample_clouds(in vec3 ray_position, in int layer_index) 203 | { 204 | vec4 base_noise_sample = texture(base_noise_texture, (ray_position + wind_offsets[layer_index]) * base_noise_scale); 205 | float base_noise = map(base_noise_sample.x, dot(base_noise_sample.yzw, base_noise_ratios[cloud_types[layer_index] - 1]), 1.0, 0.0, 1.0); 206 | 207 | vec2 cloud_map_sample = texture(cloud_map_textures[layer_index], (ray_position.xz + wind_offsets[layer_index].xz) * cloud_map_scale).xy; 208 | 209 | if (cloud_types[layer_index] == 1) cloud_map_sample.y = 1.0; 210 | else cloud_map_sample.y = map(cloud_map_sample.y, 0.0, 1.0, 0.25, 1.0); 211 | 212 | float height_ratio = get_height_ratio(ray_position, layer_index); 213 | float height_multiplier = min(map(height_ratio, 0.0, 0.125, 0.0, 1.0), map(height_ratio, 0.625 * cloud_map_sample.y, cloud_map_sample.y, 1.0, 0.0)); 214 | 215 | float anvil_multiplier = max(map(height_ratio, 0.125, 0.25, base_anvil, 1.0), map(height_ratio, 0.5 * cloud_map_sample.y, 0.625 * cloud_map_sample.y, 1.0, top_anvil)); 216 | float cloud_coverage = clamp(max(cloud_map_sample.x, cloud_coverages[cloud_types[layer_index] - 1]) * anvil_multiplier, 0.0, 1.0); 217 | 218 | float base_erosion = map(base_noise * height_multiplier, 1.0 - cloud_coverage, 1.0, 0.0, 1.0); 219 | 220 | if (base_erosion > 0.01) 221 | { 222 | vec3 detail_noise_sample = texture(detail_noise_texture, ray_position * detail_noise_scale).xyz; 223 | float detail_noise = dot(detail_noise_sample, detail_noise_ratios[cloud_types[layer_index] - 1]); 224 | 225 | return map(base_erosion, 0.75 * detail_noise, 1.0, 0.0, 1.0) * cloud_densities[cloud_types[layer_index] - 1] * map(cloud_coverages[cloud_types[layer_index] - 1], 0.0, 1.0, 1.0, 1.5); 226 | } 227 | else return 0.0; 228 | } 229 | 230 | float sun_ray_march(in float input_transmittance, in vec3 ray_position, in int layer_index) 231 | { 232 | float output_transmittance = input_transmittance; 233 | 234 | if (cloud_types[layer_index] != 0) 235 | { 236 | vec2 layer_intersections = ray_layer_intersections(ray_position, sun_direction, layer_index); 237 | 238 | vec3 current_ray_position = ray_position + (sun_direction * layer_intersections.x); 239 | float step_size = min(layer_intersections.y / float(sun_step_count), maximum_sun_step_size); 240 | 241 | for (int step_index = 0; step_index < sun_step_count; step_index++) 242 | { 243 | output_transmittance *= exp(-1.0 * light_attenuation * sample_clouds(current_ray_position, layer_index) * step_size); 244 | if (output_transmittance < 0.01) break; 245 | 246 | current_ray_position += sun_direction * step_size; 247 | } 248 | } 249 | 250 | return output_transmittance; 251 | } 252 | 253 | vec4 sample_ray_march(in vec4 input_color, in int layer_index) 254 | { 255 | vec4 output_color = input_color; 256 | 257 | if (cloud_types[layer_index] != 0) 258 | { 259 | vec2 layer_intersections = ray_layer_intersections(ray_start_position, sample_direction, layer_index); 260 | 261 | float maximum_distance = min(world_distance, fade_end_distance * map(abs(ray_start_position.y - cloud_bases[layer_index]), 0.0, 15240.0, 1.0, 24.0)); 262 | 263 | layer_intersections.x = min(layer_intersections.x, maximum_distance); 264 | layer_intersections.y = min(layer_intersections.y, maximum_distance - layer_intersections.x); 265 | 266 | if (layer_intersections.y > 5.0) 267 | { 268 | vec3 current_ray_position = ray_start_position + (sample_direction * layer_intersections.x); 269 | float current_ray_distance = 0.0; 270 | 271 | float step_size = min(layer_intersections.y / float(sample_step_count), maximum_sample_step_size); 272 | 273 | float sun_angle_multiplier = map(sun_direction.y, 0.05, -0.125, 1.0, 0.175); 274 | 275 | float sun_dot_angle = dot(sample_direction, sun_direction); 276 | float mie_scattering_gain = clamp(henyey_greenstein(sun_dot_angle, mie_scattering) + henyey_greenstein(sun_dot_angle, mie_scattering * 0.75) + henyey_greenstein(sun_dot_angle, mie_scattering * 0.5), 1.0, 2.75); 277 | 278 | while (current_ray_distance <= layer_intersections.y) 279 | { 280 | float distance_multiplier; 281 | 282 | if (current_ray_distance < 40000.0) distance_multiplier = map(current_ray_distance, 0.0, 40000.0, 1.0, 4.0); 283 | else distance_multiplier = map(current_ray_distance, 40000.0, layer_intersections.y, 4.0, 16.0); 284 | 285 | float current_step_size = step_size * distance_multiplier; 286 | if (use_blue_noise_dithering != 0) current_step_size *= map(texture(blue_noise_texture, current_ray_position.xz * blue_noise_scale).x, 0.0, 1.0, 0.75, 1.0); 287 | 288 | float cloud_sample = sample_clouds(current_ray_position, layer_index); 289 | 290 | if (cloud_sample != 0.0) 291 | { 292 | float sample_attenuation = 1.0; 293 | 294 | if (sun_direction.y < 0.0) 295 | { 296 | for (int current_layer_index = layer_index; current_layer_index >= 0; current_layer_index--) sample_attenuation = sun_ray_march(sample_attenuation, current_ray_position, current_layer_index); 297 | } 298 | else 299 | { 300 | for (int current_layer_index = layer_index; current_layer_index < CLOUD_LAYER_COUNT; current_layer_index++) sample_attenuation = sun_ray_march(sample_attenuation, current_ray_position, current_layer_index); 301 | } 302 | 303 | vec3 sun_color = sun_tint * sun_gain * mie_scattering_gain * sample_attenuation * sun_angle_multiplier; 304 | vec3 ambient_color = mix(ambient_tint, mix(atmosphere_bottom_tint, atmosphere_top_tint, get_height_ratio(current_ray_position, layer_index)) * dot(ambient_tint, vec3(0.21, 0.72, 0.07)), atmospheric_blending) * ambient_gain * sun_angle_multiplier; 305 | 306 | vec3 sample_color = ambient_color + sun_color; 307 | float sample_transmittance = exp(-1.0 * cloud_sample * current_step_size); 308 | 309 | output_color.xyz += (sample_color - (sample_color * sample_transmittance)) * output_color.w; 310 | output_color.w *= sample_transmittance; 311 | 312 | if (output_color.w < 0.01) break; 313 | } 314 | 315 | current_ray_position += sample_direction * current_step_size; 316 | current_ray_distance += current_step_size; 317 | } 318 | } 319 | } 320 | 321 | return output_color; 322 | } 323 | 324 | void main() 325 | { 326 | sample_direction = normalize(ray_end_position - ray_start_position); 327 | 328 | vec4 world_vector = inverse_projection_matrix * vec4((fullscreen_texture_position * 2.0) - 1.0, map(texture(current_depth_texture, fullscreen_texture_position).x, 0.0, 1.0, min(near_clip_z, far_clip_z), max(near_clip_z, far_clip_z)), 1.0); 329 | world_vector /= world_vector.w; 330 | 331 | world_intersection = vec3(inverse_modelview_matrix * world_vector); 332 | world_distance = length(world_intersection - ray_start_position); 333 | 334 | vec4 previous_fragment_vector = previous_mvp_matrix * vec4(ray_end_position, 1.0); 335 | previous_fragment_vector /= previous_fragment_vector.w; 336 | 337 | bool skip_fragment; 338 | 339 | if (skip_fragments != 0) 340 | { 341 | ivec2 fragment_indices = ivec2(gl_FragCoord.xy) % 4; 342 | int fragment_index = (fragment_indices.y * 4) + fragment_indices.x; 343 | 344 | if (fragment_index != bayer_filter[frame_index % 16]) 345 | { 346 | if ((abs(previous_fragment_vector.x) < 1.0) && (abs(previous_fragment_vector.y) < 1.0)) 347 | { 348 | if (abs(texture(current_depth_texture, fullscreen_texture_position).x - texture(previous_depth_texture, fullscreen_texture_position).x) < 0.001) skip_fragment = true; 349 | else skip_fragment = false; 350 | } 351 | else skip_fragment = false; 352 | } 353 | else skip_fragment = false; 354 | } 355 | else skip_fragment = false; 356 | 357 | if (skip_fragment == false) 358 | { 359 | vec4 output_color = vec4(0.0, 0.0, 0.0, 1.0); 360 | 361 | int closest_layer = get_closest_layer(ray_start_position, sample_direction); 362 | int world_closest_layer = get_closest_layer(world_intersection, sun_direction); 363 | 364 | if (sample_direction.y < 0.0) 365 | { 366 | for (int layer_index = closest_layer; layer_index >= 0; layer_index--) output_color = sample_ray_march(output_color, layer_index); 367 | } 368 | else 369 | { 370 | for (int layer_index = closest_layer; layer_index < CLOUD_LAYER_COUNT; layer_index++) output_color = sample_ray_march(output_color, layer_index); 371 | } 372 | 373 | if (get_height_ratio(ray_start_position, closest_layer) == 0.0) 374 | { 375 | float altitude_multiplier = map(cloud_bases[closest_layer] - ray_start_position.y, 0.0, 15240.0, 1.0, 24.0); 376 | 377 | float ray_end_distance = length(ray_end_position - ray_start_position); 378 | float ray_end_ratio = min(ray_end_distance / (fade_end_distance * altitude_multiplier), 1.0); 379 | 380 | output_color.w = mix(output_color.w, 1.0, map(ray_layer_intersections(ray_start_position, sample_direction, closest_layer).x, fade_start_distance * altitude_multiplier * ray_end_ratio, fade_end_distance * altitude_multiplier * ray_end_ratio, 0.0, 1.0)); 381 | } 382 | 383 | float shadow_attenuation = 1.0; 384 | 385 | if (sun_direction.y < 0.0) 386 | { 387 | for (int layer_index = world_closest_layer; layer_index >= 0; layer_index--) shadow_attenuation = sun_ray_march(shadow_attenuation, world_intersection, layer_index); 388 | } 389 | else 390 | { 391 | for (int layer_index = world_closest_layer; layer_index < CLOUD_LAYER_COUNT; layer_index++) shadow_attenuation = sun_ray_march(shadow_attenuation, world_intersection, layer_index); 392 | } 393 | 394 | shadow_attenuation = mix(map(shadow_attenuation, 0.0, 1.0, 0.25, 1.0), 1.0, max(map(length(ray_start_position - world_intersection), fade_start_distance, fade_end_distance, 0.0, 1.0), map(sun_direction.y, 0.15, 0.0, 0.0, 1.0))); 395 | 396 | output_color.xyz += mix(vec3(0.0, 0.0, 0.0), atmosphere_bottom_tint, 0.1) * (1.0 - shadow_attenuation) * output_color.w; 397 | output_color.w *= shadow_attenuation; 398 | 399 | output_color.w = 1.0 - output_color.w; 400 | fragment_color = vec4(output_color.xyz / output_color.w, output_color.w); 401 | } 402 | else fragment_color = texture(previous_rendering_texture, (previous_fragment_vector.xy / 2.0) + 0.5); 403 | } -------------------------------------------------------------------------------- /src/simulator_objects.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | #define WIND_LAYER_COUNT 3 14 | 15 | #define MPS_PER_KNOTS 0.514444444f 16 | 17 | namespace simulator_objects 18 | { 19 | XPLMDataRef current_eye_dataref; 20 | 21 | XPLMDataRef viewport_dataref; 22 | XPLMDataRef rendering_resolution_ratio_dataref; 23 | 24 | XPLMDataRef reverse_z_dataref; 25 | 26 | XPLMDataRef modelview_matrix_dataref; 27 | XPLMDataRef projection_matrix_dataref; 28 | 29 | XPLMDataRef skip_fragments_dataref; 30 | 31 | XPLMDataRef sample_step_count_dataref; 32 | XPLMDataRef sun_step_count_dataref; 33 | 34 | XPLMDataRef maximum_sample_step_size_dataref; 35 | XPLMDataRef maximum_sun_step_size_dataref; 36 | 37 | XPLMDataRef use_blue_noise_dithering_dataref; 38 | 39 | XPLMDataRef cloud_map_scale_dataref; 40 | 41 | XPLMDataRef base_noise_scale_dataref; 42 | XPLMDataRef detail_noise_scale_dataref; 43 | 44 | XPLMDataRef blue_noise_scale_dataref; 45 | 46 | XPLMDataRef cloud_type_datarefs[CLOUD_LAYER_COUNT]; 47 | 48 | XPLMDataRef cloud_base_datarefs[CLOUD_LAYER_COUNT]; 49 | XPLMDataRef cloud_top_datarefs[CLOUD_TYPE_COUNT]; 50 | 51 | XPLMDataRef cloud_coverage_datarefs[CLOUD_TYPE_COUNT]; 52 | XPLMDataRef cloud_density_datarefs[CLOUD_TYPE_COUNT]; 53 | 54 | XPLMDataRef base_noise_ratio_datarefs[CLOUD_TYPE_COUNT]; 55 | XPLMDataRef detail_noise_ratio_datarefs[CLOUD_TYPE_COUNT]; 56 | 57 | XPLMDataRef wind_altitude_datarefs[WIND_LAYER_COUNT]; 58 | 59 | XPLMDataRef wind_direction_datarefs[WIND_LAYER_COUNT]; 60 | XPLMDataRef wind_speed_datarefs[WIND_LAYER_COUNT]; 61 | 62 | XPLMDataRef zulu_time_dataref; 63 | 64 | XPLMDataRef base_anvil_dataref; 65 | XPLMDataRef top_anvil_dataref; 66 | 67 | XPLMDataRef fade_start_distance_dataref; 68 | XPLMDataRef fade_end_distance_dataref; 69 | 70 | XPLMDataRef light_attenuation_dataref; 71 | 72 | XPLMDataRef sun_pitch_dataref; 73 | XPLMDataRef sun_heading_dataref; 74 | 75 | XPLMDataRef sun_tint_red_dataref; 76 | XPLMDataRef sun_tint_green_dataref; 77 | XPLMDataRef sun_tint_blue_dataref; 78 | 79 | XPLMDataRef sun_gain_dataref; 80 | 81 | XPLMDataRef ambient_tint_red_dataref; 82 | XPLMDataRef ambient_tint_green_dataref; 83 | XPLMDataRef ambient_tint_blue_dataref; 84 | 85 | XPLMDataRef ambient_gain_dataref; 86 | 87 | XPLMDataRef mie_scattering_dataref; 88 | 89 | XPLMDataRef atmosphere_bottom_tint_dataref; 90 | XPLMDataRef atmosphere_top_tint_dataref; 91 | 92 | XPLMDataRef atmospheric_blending_dataref; 93 | 94 | glm::ivec4 previous_viewport; 95 | glm::ivec4 current_viewport; 96 | 97 | glm::ivec2 previous_rendering_resolution; 98 | glm::ivec2 current_rendering_resolution; 99 | 100 | int reverse_z; 101 | 102 | float near_clip_z; 103 | float far_clip_z; 104 | 105 | glm::dmat4 previous_mvp_matrix; 106 | glm::dmat4 current_mvp_matrix; 107 | 108 | glm::dmat4 inverse_modelview_matrix; 109 | glm::dmat4 inverse_projection_matrix; 110 | 111 | int skip_fragments; 112 | int frame_index; 113 | 114 | int sample_step_count; 115 | int sun_step_count; 116 | 117 | float maximum_sample_step_size; 118 | float maximum_sun_step_size; 119 | 120 | int use_blue_noise_dithering; 121 | 122 | float cloud_map_scale; 123 | 124 | float base_noise_scale; 125 | float detail_noise_scale; 126 | 127 | float blue_noise_scale; 128 | 129 | int cloud_types[CLOUD_LAYER_COUNT]; 130 | 131 | float cloud_bases[CLOUD_LAYER_COUNT]; 132 | float cloud_tops[CLOUD_LAYER_COUNT]; 133 | 134 | float cloud_coverages[CLOUD_TYPE_COUNT]; 135 | float cloud_densities[CLOUD_TYPE_COUNT]; 136 | 137 | glm::vec3 base_noise_ratios[CLOUD_TYPE_COUNT]; 138 | glm::vec3 detail_noise_ratios[CLOUD_TYPE_COUNT]; 139 | 140 | glm::vec3 wind_offsets[CLOUD_LAYER_COUNT]; 141 | 142 | float base_anvil; 143 | float top_anvil; 144 | 145 | float fade_start_distance; 146 | float fade_end_distance; 147 | 148 | float light_attenuation; 149 | 150 | glm::vec3 sun_direction; 151 | 152 | glm::vec3 sun_tint; 153 | float sun_gain; 154 | 155 | glm::vec3 ambient_tint; 156 | float ambient_gain; 157 | 158 | float mie_scattering; 159 | 160 | glm::vec3 atmosphere_bottom_tint; 161 | glm::vec3 atmosphere_top_tint; 162 | 163 | float atmospheric_blending; 164 | 165 | float previous_zulu_time; 166 | float current_zulu_time; 167 | 168 | void initialize() 169 | { 170 | XPLMDataRef override_clouds_dataref = XPLMFindDataRef("sim/operation/override/override_clouds"); 171 | XPLMSetDatai(override_clouds_dataref, 1); 172 | 173 | current_eye_dataref = XPLMFindDataRef("sim/graphics/view/draw_call_type"); 174 | 175 | viewport_dataref = XPLMFindDataRef("sim/graphics/view/viewport"); 176 | rendering_resolution_ratio_dataref = export_float_dataref("enhanced_cloudscapes/rendering_resolution_ratio", 0.7); 177 | 178 | reverse_z_dataref = XPLMFindDataRef("sim/graphics/view/is_reverse_float_z"); 179 | 180 | modelview_matrix_dataref = XPLMFindDataRef("sim/graphics/view/world_matrix"); 181 | projection_matrix_dataref = XPLMFindDataRef("sim/graphics/view/projection_matrix"); 182 | 183 | skip_fragments_dataref = export_int_dataref("enhanced_cloudscapes/skip_fragments", 0); 184 | 185 | sample_step_count_dataref = export_int_dataref("enhanced_cloudscapes/sample_step_count", 64); 186 | sun_step_count_dataref = export_int_dataref("enhanced_cloudscapes/sun_step_count", 6); 187 | 188 | maximum_sample_step_size_dataref = export_float_dataref("enhanced_cloudscapes/maximum_sample_step_size", 100.0f); 189 | maximum_sun_step_size_dataref = export_float_dataref("enhanced_cloudscapes/maximum_sun_step_size", 1000.0f); 190 | 191 | use_blue_noise_dithering_dataref = export_int_dataref("enhanced_cloudscapes/use_blue_noise_dithering", 1); 192 | 193 | cloud_map_scale_dataref = export_float_dataref("enhanced_cloudscapes/cloud_map_scale", 0.0000125f); 194 | 195 | base_noise_scale_dataref = export_float_dataref("enhanced_cloudscapes/base_noise_scale", 0.0000325f); 196 | detail_noise_scale_dataref = export_float_dataref("enhanced_cloudscapes/detail_noise_scale", 0.000325f); 197 | 198 | blue_noise_scale_dataref = export_float_dataref("enhanced_cloudscapes/blue_noise_scale", 0.01f); 199 | 200 | cloud_type_datarefs[0] = XPLMFindDataRef("sim/weather/cloud_coverage[0]"); 201 | cloud_type_datarefs[1] = XPLMFindDataRef("sim/weather/cloud_coverage[1]"); 202 | cloud_type_datarefs[2] = XPLMFindDataRef("sim/weather/cloud_coverage[2]"); 203 | 204 | cloud_base_datarefs[0] = XPLMFindDataRef("sim/weather/cloud_base_msl_m[0]"); 205 | cloud_base_datarefs[1] = XPLMFindDataRef("sim/weather/cloud_base_msl_m[1]"); 206 | cloud_base_datarefs[2] = XPLMFindDataRef("sim/weather/cloud_base_msl_m[2]"); 207 | 208 | cloud_top_datarefs[0] = XPLMFindDataRef("sim/weather/cloud_tops_msl_m[0]"); 209 | cloud_top_datarefs[1] = XPLMFindDataRef("sim/weather/cloud_tops_msl_m[1]"); 210 | cloud_top_datarefs[2] = XPLMFindDataRef("sim/weather/cloud_tops_msl_m[2]"); 211 | 212 | cloud_coverage_datarefs[0] = export_float_dataref("enhanced_cloudscapes/cirrus/coverage", 0.85f); 213 | cloud_coverage_datarefs[1] = export_float_dataref("enhanced_cloudscapes/few/coverage", 0.05f); 214 | cloud_coverage_datarefs[2] = export_float_dataref("enhanced_cloudscapes/scattered/coverage", 0.25f); 215 | cloud_coverage_datarefs[3] = export_float_dataref("enhanced_cloudscapes/broken/coverage", 0.5f); 216 | cloud_coverage_datarefs[4] = export_float_dataref("enhanced_cloudscapes/overcast/coverage", 0.75f); 217 | cloud_coverage_datarefs[5] = export_float_dataref("enhanced_cloudscapes/stratus/coverage", 1.0f); 218 | 219 | cloud_density_datarefs[0] = export_float_dataref("enhanced_cloudscapes/cirrus/density", 0.0015f); 220 | cloud_density_datarefs[1] = export_float_dataref("enhanced_cloudscapes/few/density", 0.0015f); 221 | cloud_density_datarefs[2] = export_float_dataref("enhanced_cloudscapes/scattered/density", 0.0015f); 222 | cloud_density_datarefs[3] = export_float_dataref("enhanced_cloudscapes/broken/density", 0.002f); 223 | cloud_density_datarefs[4] = export_float_dataref("enhanced_cloudscapes/overcast/density", 0.002f); 224 | cloud_density_datarefs[5] = export_float_dataref("enhanced_cloudscapes/stratus/density", 0.0025f); 225 | 226 | base_noise_ratio_datarefs[0] = export_vec3_dataref("enhanced_cloudscapes/cirrus/base_noise_ratios", glm::vec3(0.625f, 0.25f, 0.125f)); 227 | base_noise_ratio_datarefs[1] = export_vec3_dataref("enhanced_cloudscapes/few/base_noise_ratios", glm::vec3(0.625f, 0.25f, 0.125f)); 228 | base_noise_ratio_datarefs[2] = export_vec3_dataref("enhanced_cloudscapes/scattered/base_noise_ratios", glm::vec3(0.625f, 0.25f, 0.125f)); 229 | base_noise_ratio_datarefs[3] = export_vec3_dataref("enhanced_cloudscapes/broken/base_noise_ratios", glm::vec3(0.625f, 0.25f, 0.125f)); 230 | base_noise_ratio_datarefs[4] = export_vec3_dataref("enhanced_cloudscapes/overcast/base_noise_ratios", glm::vec3(0.625f, 0.25f, 0.125f)); 231 | base_noise_ratio_datarefs[5] = export_vec3_dataref("enhanced_cloudscapes/stratus/base_noise_ratios", glm::vec3(0.625f, 0.25f, 0.125f)); 232 | 233 | detail_noise_ratio_datarefs[0] = export_vec3_dataref("enhanced_cloudscapes/cirrus/detail_noise_ratios", glm::vec3(0.25f, 0.125f, 0.0625f)); 234 | detail_noise_ratio_datarefs[1] = export_vec3_dataref("enhanced_cloudscapes/few/detail_noise_ratios", glm::vec3(0.625f, 0.25f, 0.125f)); 235 | detail_noise_ratio_datarefs[2] = export_vec3_dataref("enhanced_cloudscapes/scattered/detail_noise_ratios", glm::vec3(0.625f, 0.25f, 0.125f)); 236 | detail_noise_ratio_datarefs[3] = export_vec3_dataref("enhanced_cloudscapes/broken/detail_noise_ratios", glm::vec3(0.625f, 0.25f, 0.125f)); 237 | detail_noise_ratio_datarefs[4] = export_vec3_dataref("enhanced_cloudscapes/overcast/detail_noise_ratios", glm::vec3(0.625f, 0.25f, 0.125f)); 238 | detail_noise_ratio_datarefs[5] = export_vec3_dataref("enhanced_cloudscapes/stratus/detail_noise_ratios", glm::vec3(0.625f, 0.25f, 0.125f)); 239 | 240 | wind_altitude_datarefs[0] = XPLMFindDataRef("sim/weather/wind_altitude_msl_m[0]"); 241 | wind_altitude_datarefs[1] = XPLMFindDataRef("sim/weather/wind_altitude_msl_m[1]"); 242 | wind_altitude_datarefs[2] = XPLMFindDataRef("sim/weather/wind_altitude_msl_m[2]"); 243 | 244 | wind_direction_datarefs[0] = XPLMFindDataRef("sim/weather/wind_direction_degt[0]"); 245 | wind_direction_datarefs[1] = XPLMFindDataRef("sim/weather/wind_direction_degt[1]"); 246 | wind_direction_datarefs[2] = XPLMFindDataRef("sim/weather/wind_direction_degt[2]"); 247 | 248 | wind_speed_datarefs[0] = XPLMFindDataRef("sim/weather/wind_speed_kt[0]"); 249 | wind_speed_datarefs[1] = XPLMFindDataRef("sim/weather/wind_speed_kt[1]"); 250 | wind_speed_datarefs[2] = XPLMFindDataRef("sim/weather/wind_speed_kt[2]"); 251 | 252 | zulu_time_dataref = XPLMFindDataRef("sim/time/zulu_time_sec"); 253 | 254 | base_anvil_dataref = export_float_dataref("enhanced_cloudscapes/base_anvil", 2.5f); 255 | top_anvil_dataref = export_float_dataref("enhanced_cloudscapes/top_anvil", 1.0f); 256 | 257 | light_attenuation_dataref = export_float_dataref("enhanced_cloudscapes/light_attenuation", 2.25f); 258 | 259 | sun_pitch_dataref = XPLMFindDataRef("sim/graphics/scenery/sun_pitch_degrees"); 260 | sun_heading_dataref = XPLMFindDataRef("sim/graphics/scenery/sun_heading_degrees"); 261 | 262 | sun_gain_dataref = export_float_dataref("enhanced_cloudscapes/sun_gain", 10.0f); 263 | 264 | ambient_tint_red_dataref = XPLMFindDataRef("sim/graphics/misc/outside_light_level_r"); 265 | ambient_tint_green_dataref = XPLMFindDataRef("sim/graphics/misc/outside_light_level_g"); 266 | ambient_tint_blue_dataref = XPLMFindDataRef("sim/graphics/misc/outside_light_level_b"); 267 | 268 | ambient_gain_dataref = export_float_dataref("enhanced_cloudscapes/ambient_gain", 0.95f); 269 | 270 | mie_scattering_dataref = export_float_dataref("enhanced_cloudscapes/mie_scattering", 0.85f); 271 | 272 | atmosphere_bottom_tint_dataref = export_vec3_dataref("enhanced_cloudscapes/atmosphere_bottom_tint", glm::vec3(0.55f, 0.775f, 1.0f)); 273 | atmosphere_top_tint_dataref = export_vec3_dataref("enhanced_cloudscapes/atmosphere_top_tint", glm::vec3(0.45f, 0.675f, 1.0f)); 274 | 275 | atmospheric_blending_dataref = export_float_dataref("enhanced_cloudscapes/atmospheric_blending", 0.325f); 276 | } 277 | 278 | void update() 279 | { 280 | XPLMDataRef fog_clip_scale_dataref = XPLMFindDataRef("sim/private/controls/terrain/fog_clip_scale"); 281 | XPLMSetDataf(fog_clip_scale_dataref, -400.0); 282 | 283 | int eye_index = XPLMGetDatai(current_eye_dataref); 284 | 285 | previous_viewport = current_viewport; 286 | XPLMGetDatavi(viewport_dataref, glm::value_ptr(current_viewport), 0, current_viewport.length()); 287 | 288 | current_viewport.z -= current_viewport.x; 289 | current_viewport.w -= current_viewport.y; 290 | 291 | if (eye_index == 4) current_viewport.x += current_viewport.z; 292 | 293 | int screen_width; 294 | int screen_height; 295 | 296 | XPLMGetScreenSize(&screen_width, &screen_height); 297 | 298 | float rendering_resolution_ratio = XPLMGetDataf(rendering_resolution_ratio_dataref); 299 | 300 | previous_rendering_resolution = current_rendering_resolution; 301 | current_rendering_resolution = glm::ivec2(screen_width * rendering_resolution_ratio, screen_height * rendering_resolution_ratio); 302 | 303 | reverse_z = XPLMGetDatai(reverse_z_dataref); 304 | 305 | if (reverse_z == 0) 306 | { 307 | near_clip_z = -1.0; 308 | far_clip_z = 1.0; 309 | } 310 | else 311 | { 312 | near_clip_z = 1.0; 313 | far_clip_z = 0.0; 314 | } 315 | 316 | glm::mat4 float_modelview_matrix; 317 | glm::mat4 float_projection_matrix; 318 | 319 | XPLMGetDatavf(modelview_matrix_dataref, glm::value_ptr(float_modelview_matrix), 0, float_modelview_matrix.length() * float_modelview_matrix.length()); 320 | XPLMGetDatavf(projection_matrix_dataref, glm::value_ptr(float_projection_matrix), 0, float_projection_matrix.length() * float_projection_matrix.length()); 321 | 322 | glm::dmat4 double_modelview_matrix = glm::dmat4(float_modelview_matrix); 323 | glm::dmat4 double_projection_matrix = glm::dmat4(float_projection_matrix); 324 | 325 | previous_mvp_matrix = current_mvp_matrix; 326 | current_mvp_matrix = double_projection_matrix * double_modelview_matrix; 327 | 328 | inverse_modelview_matrix = glm::inverse(double_modelview_matrix); 329 | inverse_projection_matrix = glm::inverse(double_projection_matrix); 330 | 331 | if ((eye_index == 3) || (eye_index == 4)) skip_fragments = 0; 332 | else skip_fragments = XPLMGetDatai(skip_fragments_dataref); 333 | 334 | frame_index++; 335 | 336 | sample_step_count = XPLMGetDatai(sample_step_count_dataref); 337 | sun_step_count = XPLMGetDatai(sun_step_count_dataref); 338 | 339 | maximum_sample_step_size = XPLMGetDataf(maximum_sample_step_size_dataref); 340 | maximum_sun_step_size = XPLMGetDataf(maximum_sun_step_size_dataref); 341 | 342 | use_blue_noise_dithering = XPLMGetDatai(use_blue_noise_dithering_dataref); 343 | 344 | cloud_map_scale = XPLMGetDataf(cloud_map_scale_dataref); 345 | 346 | base_noise_scale = XPLMGetDataf(base_noise_scale_dataref); 347 | detail_noise_scale = XPLMGetDataf(detail_noise_scale_dataref); 348 | 349 | blue_noise_scale = XPLMGetDataf(blue_noise_scale_dataref); 350 | 351 | for (int layer_index = 0; layer_index < CLOUD_LAYER_COUNT; layer_index++) cloud_types[layer_index] = static_cast(XPLMGetDataf(cloud_type_datarefs[layer_index])); 352 | 353 | for (int layer_index = 0; layer_index < CLOUD_LAYER_COUNT; layer_index++) 354 | { 355 | cloud_bases[layer_index] = XPLMGetDataf(cloud_base_datarefs[layer_index]); 356 | 357 | float new_height; 358 | 359 | if (cloud_types[layer_index] == 1) new_height = 125.0; 360 | else new_height = glm::max((XPLMGetDataf(cloud_top_datarefs[layer_index]) - cloud_bases[layer_index]) * 1.25f, 3250.0f); 361 | 362 | cloud_tops[layer_index] = cloud_bases[layer_index] + new_height; 363 | } 364 | 365 | for (int type_index = 0; type_index < CLOUD_TYPE_COUNT; type_index++) 366 | { 367 | cloud_coverages[type_index] = XPLMGetDataf(cloud_coverage_datarefs[type_index]); 368 | cloud_densities[type_index] = XPLMGetDataf(cloud_density_datarefs[type_index]); 369 | } 370 | 371 | for (int type_index = 0; type_index < CLOUD_TYPE_COUNT; type_index++) 372 | { 373 | XPLMGetDatavf(base_noise_ratio_datarefs[type_index], glm::value_ptr(base_noise_ratios[type_index]), 0, base_noise_ratios[type_index].length()); 374 | XPLMGetDatavf(detail_noise_ratio_datarefs[type_index], glm::value_ptr(detail_noise_ratios[type_index]), 0, detail_noise_ratios[type_index].length()); 375 | } 376 | 377 | float wind_altitudes[WIND_LAYER_COUNT]; 378 | glm::vec3 wind_vectors[WIND_LAYER_COUNT]; 379 | 380 | for (int layer_index = 0; layer_index < WIND_LAYER_COUNT; layer_index++) 381 | { 382 | wind_altitudes[layer_index] = XPLMGetDataf(wind_altitude_datarefs[layer_index]); 383 | 384 | float wind_heading = glm::radians(XPLMGetDataf(wind_direction_datarefs[layer_index])); 385 | wind_vectors[layer_index] = glm::vec3(glm::sin(wind_heading), 0.0f, -1.0f * glm::cos(wind_heading)) * XPLMGetDataf(wind_speed_datarefs[layer_index]) * MPS_PER_KNOTS; 386 | } 387 | 388 | previous_zulu_time = current_zulu_time; 389 | current_zulu_time = XPLMGetDataf(zulu_time_dataref); 390 | 391 | float time_difference = current_zulu_time - previous_zulu_time; 392 | if (glm::abs(time_difference) > 5.0) time_difference = 0.0; 393 | 394 | for (int cloud_layer_index = 0; cloud_layer_index < CLOUD_LAYER_COUNT; cloud_layer_index++) 395 | { 396 | for (int wind_layer_index = 0; wind_layer_index < WIND_LAYER_COUNT; wind_layer_index++) wind_offsets[cloud_layer_index] += wind_vectors[wind_layer_index] * glm::clamp(glm::pow(glm::abs(cloud_bases[cloud_layer_index] - wind_altitudes[wind_layer_index]) * 0.001f, 2.0f), 0.0f, 1.0f) * time_difference; 397 | 398 | wind_offsets[cloud_layer_index].y += 0.05 * time_difference; 399 | } 400 | 401 | base_anvil = XPLMGetDataf(base_anvil_dataref); 402 | top_anvil = XPLMGetDataf(top_anvil_dataref); 403 | 404 | XPLMDataRef fade_start_distance_dataref = XPLMFindDataRef("sim/private/stats/skyc/fog/near_fog_cld"); 405 | XPLMDataRef fade_end_distance_dataref = XPLMFindDataRef("sim/private/stats/skyc/fog/far_fog_cld"); 406 | 407 | fade_start_distance = XPLMGetDataf(fade_start_distance_dataref); 408 | fade_end_distance = XPLMGetDataf(fade_end_distance_dataref); 409 | 410 | light_attenuation = XPLMGetDataf(light_attenuation_dataref); 411 | 412 | float sun_pitch = glm::radians(XPLMGetDataf(sun_pitch_dataref)); 413 | float sun_heading = glm::radians(XPLMGetDataf(sun_heading_dataref)); 414 | 415 | sun_direction = glm::vec3(glm::cos(sun_pitch) * glm::sin(sun_heading), glm::sin(sun_pitch), -1.0f * glm::cos(sun_pitch) * glm::cos(sun_heading)); 416 | 417 | sun_tint_red_dataref = XPLMFindDataRef("sim/private/stats/skyc/sun_dir_r"); 418 | sun_tint_green_dataref = XPLMFindDataRef("sim/private/stats/skyc/sun_dir_g"); 419 | sun_tint_blue_dataref = XPLMFindDataRef("sim/private/stats/skyc/sun_dir_b"); 420 | 421 | sun_tint = glm::vec3(XPLMGetDataf(sun_tint_red_dataref), XPLMGetDataf(sun_tint_green_dataref), XPLMGetDataf(sun_tint_blue_dataref)); 422 | sun_gain = XPLMGetDataf(sun_gain_dataref); 423 | 424 | ambient_tint = glm::vec3(XPLMGetDataf(ambient_tint_red_dataref), XPLMGetDataf(ambient_tint_green_dataref), XPLMGetDataf(ambient_tint_blue_dataref)); 425 | ambient_gain = XPLMGetDataf(ambient_gain_dataref); 426 | 427 | mie_scattering = XPLMGetDataf(mie_scattering_dataref); 428 | 429 | XPLMGetDatavf(atmosphere_bottom_tint_dataref, glm::value_ptr(atmosphere_bottom_tint), 0, atmosphere_bottom_tint.length()); 430 | XPLMGetDatavf(atmosphere_top_tint_dataref, glm::value_ptr(atmosphere_top_tint), 0, atmosphere_top_tint.length()); 431 | 432 | atmospheric_blending = XPLMGetDataf(atmospheric_blending_dataref); 433 | } 434 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------