mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-06 19:09:37 +01:00
Removed the gles3 driver. There are still mentions of it in a few places, I did not removed all of those.
This commit is contained in:
parent
9e6d2fa653
commit
00285e8b24
@ -647,14 +647,7 @@ if selected_platform in platform_list:
|
||||
if not env["verbose"]:
|
||||
methods.no_verbose(sys, env)
|
||||
|
||||
if not env["platform"] == "server": # FIXME: detect GLES3
|
||||
env.Append(
|
||||
BUILDERS={
|
||||
"GLES3_GLSL": env.Builder(
|
||||
action=run_in_subprocess(gles_builders.build_gles3_headers), suffix="glsl.gen.h", src_suffix=".glsl"
|
||||
)
|
||||
}
|
||||
)
|
||||
if not env["platform"] == "server":
|
||||
env.Append(
|
||||
BUILDERS={
|
||||
"GLES2_GLSL": env.Builder(
|
||||
|
@ -1502,7 +1502,6 @@ void _OS::_bind_methods() {
|
||||
ADD_PROPERTY_DEFAULT("window_size", Vector2());
|
||||
|
||||
BIND_ENUM_CONSTANT(VIDEO_DRIVER_GLES2);
|
||||
BIND_ENUM_CONSTANT(VIDEO_DRIVER_GLES3);
|
||||
|
||||
BIND_ENUM_CONSTANT(DAY_SUNDAY);
|
||||
BIND_ENUM_CONSTANT(DAY_MONDAY);
|
||||
|
@ -105,7 +105,6 @@ protected:
|
||||
|
||||
public:
|
||||
enum VideoDriver {
|
||||
VIDEO_DRIVER_GLES3,
|
||||
VIDEO_DRIVER_GLES2,
|
||||
};
|
||||
|
||||
|
@ -739,9 +739,8 @@ const char *OS::get_video_driver_name(int p_driver) const {
|
||||
switch (p_driver) {
|
||||
case VIDEO_DRIVER_GLES2:
|
||||
return "GLES2";
|
||||
case VIDEO_DRIVER_GLES3:
|
||||
default:
|
||||
return "GLES3";
|
||||
return "GLES2";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,6 @@ public:
|
||||
virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const = 0;
|
||||
|
||||
enum VideoDriver {
|
||||
VIDEO_DRIVER_GLES3,
|
||||
VIDEO_DRIVER_GLES2,
|
||||
VIDEO_DRIVER_MAX,
|
||||
};
|
||||
|
@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
|
||||
env.add_source_files(env.drivers_sources, "*.cpp")
|
||||
|
||||
SConscript("shaders/SCsub")
|
File diff suppressed because it is too large
Load Diff
@ -1,162 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rasterizer_canvas_base_gles3.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef RASTERIZERCANVASBASEGLES3_H
|
||||
#define RASTERIZERCANVASBASEGLES3_H
|
||||
|
||||
#include "rasterizer_storage_gles3.h"
|
||||
#include "servers/visual/rasterizer.h"
|
||||
|
||||
#include "shaders/canvas_shadow.glsl.gen.h"
|
||||
#include "shaders/lens_distorted.glsl.gen.h"
|
||||
|
||||
class RasterizerSceneGLES3;
|
||||
|
||||
class RasterizerCanvasBaseGLES3 : public RasterizerCanvas {
|
||||
public:
|
||||
struct CanvasItemUBO {
|
||||
float projection_matrix[16];
|
||||
float time;
|
||||
uint8_t padding[12];
|
||||
};
|
||||
|
||||
RasterizerSceneGLES3 *scene_render;
|
||||
|
||||
struct Data {
|
||||
enum { NUM_QUAD_ARRAY_VARIATIONS = 8 };
|
||||
|
||||
GLuint canvas_quad_vertices;
|
||||
GLuint canvas_quad_array;
|
||||
|
||||
GLuint polygon_buffer;
|
||||
GLuint polygon_buffer_quad_arrays[NUM_QUAD_ARRAY_VARIATIONS];
|
||||
GLuint polygon_buffer_pointer_array;
|
||||
GLuint polygon_index_buffer;
|
||||
|
||||
GLuint particle_quad_vertices;
|
||||
GLuint particle_quad_array;
|
||||
|
||||
uint32_t polygon_buffer_size;
|
||||
uint32_t polygon_index_buffer_size;
|
||||
|
||||
} data;
|
||||
|
||||
struct State {
|
||||
CanvasItemUBO canvas_item_ubo_data;
|
||||
GLuint canvas_item_ubo;
|
||||
bool canvas_texscreen_used;
|
||||
CanvasShaderGLES3 canvas_shader;
|
||||
CanvasShadowShaderGLES3 canvas_shadow_shader;
|
||||
LensDistortedShaderGLES3 lens_shader;
|
||||
|
||||
bool using_texture_rect;
|
||||
bool using_ninepatch;
|
||||
|
||||
bool using_light_angle;
|
||||
bool using_modulate;
|
||||
bool using_large_vertex;
|
||||
|
||||
RID current_tex;
|
||||
RID current_normal;
|
||||
RasterizerStorageGLES3::Texture *current_tex_ptr;
|
||||
|
||||
Transform vp;
|
||||
|
||||
Color canvas_item_modulate;
|
||||
Transform2D extra_matrix;
|
||||
Transform2D final_transform;
|
||||
bool using_skeleton;
|
||||
Transform2D skeleton_transform;
|
||||
Transform2D skeleton_transform_inverse;
|
||||
|
||||
} state;
|
||||
|
||||
RasterizerStorageGLES3 *storage;
|
||||
|
||||
// allow user to choose api usage
|
||||
GLenum _buffer_upload_usage_flag;
|
||||
|
||||
struct LightInternal : public RID_Data {
|
||||
struct UBOData {
|
||||
float light_matrix[16];
|
||||
float local_matrix[16];
|
||||
float shadow_matrix[16];
|
||||
float color[4];
|
||||
float shadow_color[4];
|
||||
float light_pos[2];
|
||||
float shadowpixel_size;
|
||||
float shadow_gradient;
|
||||
float light_height;
|
||||
float light_outside_alpha;
|
||||
float shadow_distance_mult;
|
||||
uint8_t padding[4];
|
||||
} ubo_data;
|
||||
|
||||
GLuint ubo;
|
||||
};
|
||||
|
||||
RID_Owner<LightInternal> light_internal_owner;
|
||||
|
||||
virtual RID light_internal_create();
|
||||
virtual void light_internal_update(RID p_rid, Light *p_light);
|
||||
virtual void light_internal_free(RID p_rid);
|
||||
|
||||
virtual void canvas_begin();
|
||||
virtual void canvas_end();
|
||||
|
||||
void _set_texture_rect_mode(bool p_enable, bool p_ninepatch = false, bool p_light_angle = false, bool p_modulate = false, bool p_large_vertex = false);
|
||||
RasterizerStorageGLES3::Texture *_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map, bool p_force = false);
|
||||
|
||||
void _draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs, const float *p_light_angles = nullptr);
|
||||
void _draw_polygon(const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor, const int *p_bones, const float *p_weights);
|
||||
void _draw_generic(GLuint p_primitive, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor);
|
||||
void _draw_generic_indices(GLuint p_primitive, const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor);
|
||||
|
||||
void _copy_texscreen(const Rect2 &p_rect);
|
||||
|
||||
virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow);
|
||||
|
||||
virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache);
|
||||
|
||||
virtual void reset_canvas();
|
||||
|
||||
void draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src);
|
||||
void draw_lens_distortion_rect(const Rect2 &p_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample);
|
||||
void render_rect_nvidia_workaround(const Item::CommandRect *p_rect, const RasterizerStorageGLES3::Texture *p_texture);
|
||||
|
||||
void initialize();
|
||||
void finalize();
|
||||
|
||||
virtual void draw_window_margins(int *black_margin, RID *black_image);
|
||||
|
||||
RasterizerCanvasBaseGLES3();
|
||||
};
|
||||
|
||||
#endif // RASTERIZERCANVASBASEGLES3_H
|
File diff suppressed because it is too large
Load Diff
@ -1,78 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rasterizer_canvas_gles3.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef RASTERIZERCANVASGLES3_H
|
||||
#define RASTERIZERCANVASGLES3_H
|
||||
|
||||
#include "drivers/gles_common/rasterizer_canvas_batcher.h"
|
||||
#include "rasterizer_canvas_base_gles3.h"
|
||||
|
||||
class RasterizerCanvasGLES3 : public RasterizerCanvasBaseGLES3, public RasterizerCanvasBatcher<RasterizerCanvasGLES3, RasterizerStorageGLES3> {
|
||||
friend class RasterizerCanvasBatcher<RasterizerCanvasGLES3, RasterizerStorageGLES3>;
|
||||
|
||||
private:
|
||||
struct BatchGLData {
|
||||
// for batching
|
||||
GLuint batch_vertex_array[5];
|
||||
} batch_gl_data;
|
||||
|
||||
public:
|
||||
virtual void canvas_render_items_begin(const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform);
|
||||
virtual void canvas_render_items_end();
|
||||
virtual void canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform);
|
||||
virtual void canvas_begin();
|
||||
virtual void canvas_end();
|
||||
|
||||
private:
|
||||
// legacy codepath .. to remove after testing
|
||||
void _legacy_canvas_render_item(Item *p_ci, RenderItemState &r_ris);
|
||||
|
||||
// high level batch funcs
|
||||
void canvas_render_items_implementation(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform);
|
||||
void render_joined_item(const BItemJoined &p_bij, RenderItemState &r_ris);
|
||||
bool try_join_item(Item *p_ci, RenderItemState &r_ris, bool &r_batch_break);
|
||||
void render_batches(Item *p_current_clip, bool &r_reclip, RasterizerStorageGLES3::Material *p_material);
|
||||
|
||||
// low level batch funcs
|
||||
void _batch_upload_buffers();
|
||||
void _batch_render_prepare();
|
||||
void _batch_render_generic(const Batch &p_batch, RasterizerStorageGLES3::Material *p_material);
|
||||
void _batch_render_lines(const Batch &p_batch, RasterizerStorageGLES3::Material *p_material, bool p_anti_alias);
|
||||
|
||||
// funcs used from rasterizer_canvas_batcher template
|
||||
void gl_enable_scissor(int p_x, int p_y, int p_width, int p_height) const;
|
||||
void gl_disable_scissor() const;
|
||||
|
||||
public:
|
||||
void initialize();
|
||||
RasterizerCanvasGLES3();
|
||||
};
|
||||
|
||||
#endif // RASTERIZERCANVASGLES3_H
|
@ -1,506 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rasterizer_gles3.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "rasterizer_gles3.h"
|
||||
|
||||
#include "core/os/os.h"
|
||||
#include "core/project_settings.h"
|
||||
|
||||
RasterizerStorage *RasterizerGLES3::get_storage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
RasterizerCanvas *RasterizerGLES3::get_canvas() {
|
||||
return canvas;
|
||||
}
|
||||
|
||||
RasterizerScene *RasterizerGLES3::get_scene() {
|
||||
return scene;
|
||||
}
|
||||
|
||||
#define _EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242
|
||||
#define _EXT_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243
|
||||
#define _EXT_DEBUG_CALLBACK_FUNCTION_ARB 0x8244
|
||||
#define _EXT_DEBUG_CALLBACK_USER_PARAM_ARB 0x8245
|
||||
#define _EXT_DEBUG_SOURCE_API_ARB 0x8246
|
||||
#define _EXT_DEBUG_SOURCE_WINDOW_SYSTEM_ARB 0x8247
|
||||
#define _EXT_DEBUG_SOURCE_SHADER_COMPILER_ARB 0x8248
|
||||
#define _EXT_DEBUG_SOURCE_THIRD_PARTY_ARB 0x8249
|
||||
#define _EXT_DEBUG_SOURCE_APPLICATION_ARB 0x824A
|
||||
#define _EXT_DEBUG_SOURCE_OTHER_ARB 0x824B
|
||||
#define _EXT_DEBUG_TYPE_ERROR_ARB 0x824C
|
||||
#define _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB 0x824D
|
||||
#define _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB 0x824E
|
||||
#define _EXT_DEBUG_TYPE_PORTABILITY_ARB 0x824F
|
||||
#define _EXT_DEBUG_TYPE_PERFORMANCE_ARB 0x8250
|
||||
#define _EXT_DEBUG_TYPE_OTHER_ARB 0x8251
|
||||
#define _EXT_MAX_DEBUG_MESSAGE_LENGTH_ARB 0x9143
|
||||
#define _EXT_MAX_DEBUG_LOGGED_MESSAGES_ARB 0x9144
|
||||
#define _EXT_DEBUG_LOGGED_MESSAGES_ARB 0x9145
|
||||
#define _EXT_DEBUG_SEVERITY_HIGH_ARB 0x9146
|
||||
#define _EXT_DEBUG_SEVERITY_MEDIUM_ARB 0x9147
|
||||
#define _EXT_DEBUG_SEVERITY_LOW_ARB 0x9148
|
||||
#define _EXT_DEBUG_OUTPUT 0x92E0
|
||||
|
||||
#if defined(MINGW_ENABLED) || defined(_MSC_VER)
|
||||
#define strcpy strcpy_s
|
||||
#endif
|
||||
|
||||
#ifdef GLAD_ENABLED
|
||||
// Restricting to GLAD as only used in initialize() with GLAD_GL_ARB_debug_output
|
||||
static void GLAPIENTRY _gl_debug_print(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const GLvoid *userParam) {
|
||||
if (type == _EXT_DEBUG_TYPE_OTHER_ARB) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == _EXT_DEBUG_TYPE_PERFORMANCE_ARB) {
|
||||
return; //these are ultimately annoying, so removing for now
|
||||
}
|
||||
|
||||
char debSource[256], debType[256], debSev[256];
|
||||
if (source == _EXT_DEBUG_SOURCE_API_ARB) {
|
||||
strcpy(debSource, "OpenGL");
|
||||
} else if (source == _EXT_DEBUG_SOURCE_WINDOW_SYSTEM_ARB) {
|
||||
strcpy(debSource, "Windows");
|
||||
} else if (source == _EXT_DEBUG_SOURCE_SHADER_COMPILER_ARB) {
|
||||
strcpy(debSource, "Shader Compiler");
|
||||
} else if (source == _EXT_DEBUG_SOURCE_THIRD_PARTY_ARB) {
|
||||
strcpy(debSource, "Third Party");
|
||||
} else if (source == _EXT_DEBUG_SOURCE_APPLICATION_ARB) {
|
||||
strcpy(debSource, "Application");
|
||||
} else if (source == _EXT_DEBUG_SOURCE_OTHER_ARB) {
|
||||
strcpy(debSource, "Other");
|
||||
}
|
||||
|
||||
if (type == _EXT_DEBUG_TYPE_ERROR_ARB) {
|
||||
strcpy(debType, "Error");
|
||||
} else if (type == _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB) {
|
||||
strcpy(debType, "Deprecated behavior");
|
||||
} else if (type == _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB) {
|
||||
strcpy(debType, "Undefined behavior");
|
||||
} else if (type == _EXT_DEBUG_TYPE_PORTABILITY_ARB) {
|
||||
strcpy(debType, "Portability");
|
||||
} else if (type == _EXT_DEBUG_TYPE_PERFORMANCE_ARB) {
|
||||
strcpy(debType, "Performance");
|
||||
}
|
||||
|
||||
if (severity == _EXT_DEBUG_SEVERITY_HIGH_ARB) {
|
||||
strcpy(debSev, "High");
|
||||
} else if (severity == _EXT_DEBUG_SEVERITY_MEDIUM_ARB) {
|
||||
strcpy(debSev, "Medium");
|
||||
} else if (severity == _EXT_DEBUG_SEVERITY_LOW_ARB) {
|
||||
strcpy(debSev, "Low");
|
||||
}
|
||||
|
||||
String output = String() + "GL ERROR: Source: " + debSource + "\tType: " + debType + "\tID: " + itos(id) + "\tSeverity: " + debSev + "\tMessage: " + message;
|
||||
|
||||
ERR_PRINT(output);
|
||||
}
|
||||
#endif // GLAD_ENABLED
|
||||
|
||||
typedef void (*DEBUGPROCARB)(GLenum source,
|
||||
GLenum type,
|
||||
GLuint id,
|
||||
GLenum severity,
|
||||
GLsizei length,
|
||||
const char *message,
|
||||
const void *userParam);
|
||||
|
||||
typedef void (*DebugMessageCallbackARB)(DEBUGPROCARB callback, const void *userParam);
|
||||
|
||||
Error RasterizerGLES3::is_viable() {
|
||||
#ifdef GLAD_ENABLED
|
||||
if (!gladLoadGL()) {
|
||||
ERR_PRINT("Error initializing GLAD");
|
||||
return ERR_UNAVAILABLE;
|
||||
}
|
||||
|
||||
// GLVersion seems to be used for both GL and GL ES, so we need different version checks for them
|
||||
#ifdef OPENGL_ENABLED // OpenGL 3.3 Core Profile required
|
||||
if (GLVersion.major < 3 || (GLVersion.major == 3 && GLVersion.minor < 3)) {
|
||||
#else // OpenGL ES 3.0
|
||||
if (GLVersion.major < 3) {
|
||||
#endif
|
||||
return ERR_UNAVAILABLE;
|
||||
}
|
||||
|
||||
#endif // GLAD_ENABLED
|
||||
return OK;
|
||||
}
|
||||
|
||||
void RasterizerGLES3::initialize() {
|
||||
print_verbose("Using GLES3 video driver");
|
||||
|
||||
#ifdef GLAD_ENABLED
|
||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||
if (GLAD_GL_ARB_debug_output) {
|
||||
glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
||||
glDebugMessageCallbackARB(_gl_debug_print, nullptr);
|
||||
glEnable(_EXT_DEBUG_OUTPUT);
|
||||
} else {
|
||||
print_line("OpenGL debugging not supported!");
|
||||
}
|
||||
}
|
||||
#endif // GLAD_ENABLED
|
||||
|
||||
/* // For debugging
|
||||
if (GLAD_GL_ARB_debug_output) {
|
||||
glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_ERROR_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
|
||||
glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
|
||||
glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
|
||||
glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_PORTABILITY_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
|
||||
glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_PERFORMANCE_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
|
||||
glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_OTHER_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
|
||||
glDebugMessageInsertARB(
|
||||
GL_DEBUG_SOURCE_API_ARB,
|
||||
GL_DEBUG_TYPE_OTHER_ARB, 1,
|
||||
GL_DEBUG_SEVERITY_HIGH_ARB,5, "hello");
|
||||
}
|
||||
*/
|
||||
|
||||
print_line("OpenGL ES 3.0 Renderer: " + VisualServer::get_singleton()->get_video_adapter_name());
|
||||
storage->initialize();
|
||||
canvas->initialize();
|
||||
scene->initialize();
|
||||
}
|
||||
|
||||
void RasterizerGLES3::begin_frame(double frame_step) {
|
||||
time_total += frame_step * time_scale;
|
||||
|
||||
if (frame_step == 0) {
|
||||
//to avoid hiccups
|
||||
frame_step = 0.001;
|
||||
}
|
||||
|
||||
double time_roll_over = GLOBAL_GET("rendering/limits/time/time_rollover_secs");
|
||||
time_total = Math::fmod(time_total, time_roll_over);
|
||||
|
||||
storage->frame.time[0] = time_total;
|
||||
storage->frame.time[1] = Math::fmod(time_total, 3600);
|
||||
storage->frame.time[2] = Math::fmod(time_total, 900);
|
||||
storage->frame.time[3] = Math::fmod(time_total, 60);
|
||||
storage->frame.count++;
|
||||
storage->frame.shader_compiles_started = 0;
|
||||
storage->frame.delta = frame_step;
|
||||
|
||||
storage->update_dirty_resources();
|
||||
|
||||
storage->info.render_final = storage->info.render;
|
||||
storage->info.render.reset();
|
||||
|
||||
ShaderGLES3::current_frame = storage->frame.count;
|
||||
|
||||
scene->iteration();
|
||||
}
|
||||
|
||||
void RasterizerGLES3::set_current_render_target(RID p_render_target) {
|
||||
if (!p_render_target.is_valid() && storage->frame.current_rt && storage->frame.clear_request) {
|
||||
//handle pending clear request, if the framebuffer was not cleared
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo);
|
||||
|
||||
glClearColor(
|
||||
storage->frame.clear_request_color.r,
|
||||
storage->frame.clear_request_color.g,
|
||||
storage->frame.clear_request_color.b,
|
||||
storage->frame.clear_request_color.a);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
if (p_render_target.is_valid()) {
|
||||
RasterizerStorageGLES3::RenderTarget *rt = storage->render_target_owner.getornull(p_render_target);
|
||||
storage->frame.current_rt = rt;
|
||||
ERR_FAIL_COND(!rt);
|
||||
storage->frame.clear_request = false;
|
||||
|
||||
glViewport(0, 0, rt->width, rt->height);
|
||||
|
||||
} else {
|
||||
storage->frame.current_rt = nullptr;
|
||||
storage->frame.clear_request = false;
|
||||
glViewport(0, 0, OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
|
||||
}
|
||||
}
|
||||
|
||||
void RasterizerGLES3::restore_render_target(bool p_3d_was_drawn) {
|
||||
ERR_FAIL_COND(storage->frame.current_rt == nullptr);
|
||||
RasterizerStorageGLES3::RenderTarget *rt = storage->frame.current_rt;
|
||||
if (p_3d_was_drawn && rt->external.fbo != 0) {
|
||||
// our external render buffer is now leading, render 2d into that.
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, rt->external.fbo);
|
||||
} else {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, rt->fbo);
|
||||
}
|
||||
glViewport(0, 0, rt->width, rt->height);
|
||||
}
|
||||
|
||||
void RasterizerGLES3::clear_render_target(const Color &p_color) {
|
||||
ERR_FAIL_COND(!storage->frame.current_rt);
|
||||
|
||||
storage->frame.clear_request = true;
|
||||
storage->frame.clear_request_color = p_color;
|
||||
}
|
||||
|
||||
void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) {
|
||||
if (p_image.is_null() || p_image->empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
begin_frame(0.0);
|
||||
|
||||
int window_w = OS::get_singleton()->get_video_mode(0).width;
|
||||
int window_h = OS::get_singleton()->get_video_mode(0).height;
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
|
||||
glViewport(0, 0, window_w, window_h);
|
||||
glDisable(GL_BLEND);
|
||||
glDepthMask(GL_FALSE);
|
||||
if (OS::get_singleton()->get_window_per_pixel_transparency_enabled()) {
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
} else {
|
||||
glClearColor(p_color.r, p_color.g, p_color.b, 1.0);
|
||||
}
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
canvas->canvas_begin();
|
||||
|
||||
RID texture = RID_PRIME(storage->texture_create());
|
||||
storage->texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), VS::TEXTURE_TYPE_2D, p_use_filter ? (uint32_t)VS::TEXTURE_FLAG_FILTER : 0);
|
||||
storage->texture_set_data(texture, p_image);
|
||||
|
||||
Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height());
|
||||
Rect2 screenrect;
|
||||
if (p_scale) {
|
||||
if (window_w > window_h) {
|
||||
//scale horizontally
|
||||
screenrect.size.y = window_h;
|
||||
screenrect.size.x = imgrect.size.x * window_h / imgrect.size.y;
|
||||
screenrect.position.x = (window_w - screenrect.size.x) / 2;
|
||||
|
||||
} else {
|
||||
//scale vertically
|
||||
screenrect.size.x = window_w;
|
||||
screenrect.size.y = imgrect.size.y * window_w / imgrect.size.x;
|
||||
screenrect.position.y = (window_h - screenrect.size.y) / 2;
|
||||
}
|
||||
} else {
|
||||
screenrect = imgrect;
|
||||
screenrect.position += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor();
|
||||
}
|
||||
|
||||
RasterizerStorageGLES3::Texture *t = storage->texture_owner.get(texture);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, t->tex_id);
|
||||
canvas->draw_generic_textured_rect(screenrect, Rect2(0, 0, 1, 1));
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
canvas->canvas_end();
|
||||
|
||||
storage->free(texture); // free since it's only one frame that stays there
|
||||
|
||||
end_frame(true);
|
||||
}
|
||||
|
||||
void RasterizerGLES3::set_shader_time_scale(float p_scale) {
|
||||
time_scale = p_scale;
|
||||
}
|
||||
|
||||
void RasterizerGLES3::blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect, int p_screen) {
|
||||
ERR_FAIL_COND(storage->frame.current_rt);
|
||||
|
||||
RasterizerStorageGLES3::RenderTarget *rt = storage->render_target_owner.getornull(p_render_target);
|
||||
ERR_FAIL_COND(!rt);
|
||||
|
||||
if (rt->flags[RasterizerStorage::RENDER_TARGET_KEEP_3D_LINEAR]) {
|
||||
// We need to add an sRGB conversion here as we kept our buffer linear (+ a little tone mapping).
|
||||
|
||||
canvas->_set_texture_rect_mode(true);
|
||||
|
||||
canvas->state.canvas_shader.set_custom_shader(0);
|
||||
canvas->state.canvas_shader.set_conditional(CanvasShaderGLES3::LINEAR_TO_SRGB, true);
|
||||
canvas->state.canvas_shader.bind();
|
||||
|
||||
canvas->canvas_begin();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
// render to our framebuffer
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
|
||||
|
||||
// output our texture
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
if (rt->external.fbo != 0) {
|
||||
glBindTexture(GL_TEXTURE_2D, rt->external.color);
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, rt->color);
|
||||
}
|
||||
|
||||
canvas->draw_generic_textured_rect(p_screen_rect, Rect2(0, 0, 1, -1));
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
canvas->canvas_end();
|
||||
|
||||
canvas->state.canvas_shader.set_conditional(CanvasShaderGLES3::LINEAR_TO_SRGB, false);
|
||||
} else {
|
||||
// No conversion needed, take the faster approach
|
||||
|
||||
Size2 win_size = OS::get_singleton()->get_window_size();
|
||||
if (rt->external.fbo != 0) {
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, rt->external.fbo);
|
||||
} else {
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, rt->fbo);
|
||||
}
|
||||
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
|
||||
glBlitFramebuffer(0, 0, rt->width, rt->height, p_screen_rect.position.x, win_size.height - p_screen_rect.position.y - p_screen_rect.size.height, p_screen_rect.position.x + p_screen_rect.size.width, win_size.height - p_screen_rect.position.y, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
}
|
||||
}
|
||||
|
||||
void RasterizerGLES3::output_lens_distorted_to_screen(RID p_render_target, const Rect2 &p_screen_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample) {
|
||||
ERR_FAIL_COND(storage->frame.current_rt);
|
||||
|
||||
RasterizerStorageGLES3::RenderTarget *rt = storage->render_target_owner.getornull(p_render_target);
|
||||
ERR_FAIL_COND(!rt);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
// render to our framebuffer
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
|
||||
|
||||
// output our texture
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, rt->color);
|
||||
|
||||
canvas->draw_lens_distortion_rect(p_screen_rect, p_k1, p_k2, p_eye_center, p_oversample);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void RasterizerGLES3::end_frame(bool p_swap_buffers) {
|
||||
if (OS::get_singleton()->is_layered_allowed()) {
|
||||
if (!OS::get_singleton()->get_window_per_pixel_transparency_enabled()) {
|
||||
//clear alpha
|
||||
glColorMask(false, false, false, true);
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glColorMask(true, true, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
ShaderGLES3::advance_async_shaders_compilation();
|
||||
|
||||
if (p_swap_buffers) {
|
||||
OS::get_singleton()->swap_buffers();
|
||||
} else {
|
||||
glFinish();
|
||||
}
|
||||
}
|
||||
|
||||
void RasterizerGLES3::finalize() {
|
||||
storage->finalize();
|
||||
canvas->finalize();
|
||||
}
|
||||
|
||||
Rasterizer *RasterizerGLES3::_create_current() {
|
||||
return memnew(RasterizerGLES3);
|
||||
}
|
||||
|
||||
void RasterizerGLES3::make_current() {
|
||||
_create_func = _create_current;
|
||||
}
|
||||
|
||||
void RasterizerGLES3::register_config() {
|
||||
}
|
||||
|
||||
bool RasterizerGLES3::gl_check_errors() {
|
||||
bool error_found = false;
|
||||
GLenum error = glGetError();
|
||||
while (error != GL_NO_ERROR) {
|
||||
switch (error) {
|
||||
#ifdef DEBUG_ENABLED
|
||||
case GL_INVALID_ENUM: {
|
||||
WARN_PRINT("GL_INVALID_ENUM: An unacceptable value is specified for an enumerated argument.");
|
||||
} break;
|
||||
case GL_INVALID_VALUE: {
|
||||
WARN_PRINT("GL_INVALID_VALUE: A numeric argument is out of range.");
|
||||
} break;
|
||||
case GL_INVALID_OPERATION: {
|
||||
WARN_PRINT("GL_INVALID_OPERATION: The specified operation is not allowed in the current state.");
|
||||
} break;
|
||||
case GL_INVALID_FRAMEBUFFER_OPERATION: {
|
||||
WARN_PRINT("GL_INVALID_FRAMEBUFFER_OPERATION: The framebuffer object is not complete.");
|
||||
} break;
|
||||
#endif // DEBUG_ENABLED
|
||||
case GL_OUT_OF_MEMORY: {
|
||||
ERR_PRINT("GL_OUT_OF_MEMORY: There is not enough memory left to execute the command. The state of the GL is undefined.");
|
||||
} break;
|
||||
// GL_STACK_UNDERFLOW and GL_STACK_OVERFLOW are undefined in GLES2/gl2.h, which is used when not using GLAD.
|
||||
//case GL_STACK_UNDERFLOW: {
|
||||
// ERR_PRINT("GL_STACK_UNDERFLOW: An attempt has been made to perform an operation that would cause an internal stack to underflow.");
|
||||
//} break;
|
||||
//case GL_STACK_OVERFLOW: {
|
||||
// ERR_PRINT("GL_STACK_OVERFLOW: An attempt has been made to perform an operation that would cause an internal stack to overflow.");
|
||||
//} break;
|
||||
default: {
|
||||
#ifdef DEBUG_ENABLED
|
||||
ERR_PRINT("Unrecognized GLError");
|
||||
#endif // DEBUG_ENABLED
|
||||
} break;
|
||||
}
|
||||
error_found = true;
|
||||
error = glGetError();
|
||||
}
|
||||
|
||||
return error_found;
|
||||
}
|
||||
|
||||
RasterizerGLES3::RasterizerGLES3() {
|
||||
storage = memnew(RasterizerStorageGLES3);
|
||||
canvas = memnew(RasterizerCanvasGLES3);
|
||||
scene = memnew(RasterizerSceneGLES3);
|
||||
canvas->storage = storage;
|
||||
canvas->scene_render = scene;
|
||||
storage->canvas = canvas;
|
||||
scene->storage = storage;
|
||||
storage->scene = scene;
|
||||
|
||||
time_total = 0;
|
||||
time_scale = 1;
|
||||
|
||||
ShaderGLES3::compiles_started_this_frame = &storage->frame.shader_compiles_started;
|
||||
}
|
||||
|
||||
RasterizerGLES3::~RasterizerGLES3() {
|
||||
memdelete(scene);
|
||||
memdelete(canvas);
|
||||
|
||||
// storage must be deleted last,
|
||||
// because it contains RID_owners that are used by scene and canvas destructors
|
||||
memdelete(storage);
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rasterizer_gles3.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef RASTERIZERGLES3_H
|
||||
#define RASTERIZERGLES3_H
|
||||
|
||||
#include "rasterizer_canvas_gles3.h"
|
||||
#include "rasterizer_scene_gles3.h"
|
||||
#include "rasterizer_storage_gles3.h"
|
||||
#include "servers/visual/rasterizer.h"
|
||||
|
||||
class RasterizerGLES3 : public Rasterizer {
|
||||
static Rasterizer *_create_current();
|
||||
|
||||
RasterizerStorageGLES3 *storage;
|
||||
RasterizerCanvasGLES3 *canvas;
|
||||
RasterizerSceneGLES3 *scene;
|
||||
|
||||
double time_total;
|
||||
float time_scale;
|
||||
|
||||
public:
|
||||
virtual RasterizerStorage *get_storage();
|
||||
virtual RasterizerCanvas *get_canvas();
|
||||
virtual RasterizerScene *get_scene();
|
||||
|
||||
virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true);
|
||||
virtual void set_shader_time_scale(float p_scale);
|
||||
|
||||
virtual void initialize();
|
||||
virtual void begin_frame(double frame_step);
|
||||
virtual void set_current_render_target(RID p_render_target);
|
||||
virtual void restore_render_target(bool p_3d_was_drawn);
|
||||
virtual void clear_render_target(const Color &p_color);
|
||||
virtual void blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect, int p_screen = 0);
|
||||
virtual void output_lens_distorted_to_screen(RID p_render_target, const Rect2 &p_screen_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample);
|
||||
virtual void end_frame(bool p_swap_buffers);
|
||||
virtual void finalize();
|
||||
|
||||
static Error is_viable();
|
||||
static void make_current();
|
||||
static void register_config();
|
||||
|
||||
virtual bool is_low_end() const { return false; }
|
||||
|
||||
static bool gl_check_errors();
|
||||
|
||||
RasterizerGLES3();
|
||||
~RasterizerGLES3();
|
||||
};
|
||||
|
||||
#endif // RASTERIZERGLES3_H
|
File diff suppressed because it is too large
Load Diff
@ -1,873 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rasterizer_scene_gles3.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef RASTERIZERSCENEGLES3_H
|
||||
#define RASTERIZERSCENEGLES3_H
|
||||
|
||||
/* Must come before shaders or the Windows build fails... */
|
||||
#include "rasterizer_storage_gles3.h"
|
||||
|
||||
#include "drivers/gles3/shaders/cube_to_dp.glsl.gen.h"
|
||||
#include "drivers/gles3/shaders/effect_blur.glsl.gen.h"
|
||||
#include "drivers/gles3/shaders/exposure.glsl.gen.h"
|
||||
#include "drivers/gles3/shaders/resolve.glsl.gen.h"
|
||||
#include "drivers/gles3/shaders/scene.glsl.gen.h"
|
||||
#include "drivers/gles3/shaders/screen_space_reflection.glsl.gen.h"
|
||||
#include "drivers/gles3/shaders/ssao.glsl.gen.h"
|
||||
#include "drivers/gles3/shaders/ssao_blur.glsl.gen.h"
|
||||
#include "drivers/gles3/shaders/ssao_minify.glsl.gen.h"
|
||||
#include "drivers/gles3/shaders/subsurf_scattering.glsl.gen.h"
|
||||
#include "drivers/gles3/shaders/tonemap.glsl.gen.h"
|
||||
|
||||
class RasterizerSceneGLES3 : public RasterizerScene {
|
||||
public:
|
||||
enum ShadowFilterMode {
|
||||
SHADOW_FILTER_NEAREST,
|
||||
SHADOW_FILTER_PCF5,
|
||||
SHADOW_FILTER_PCF13,
|
||||
};
|
||||
|
||||
ShadowFilterMode shadow_filter_mode;
|
||||
|
||||
uint64_t shadow_atlas_realloc_tolerance_msec;
|
||||
|
||||
enum SubSurfaceScatterQuality {
|
||||
SSS_QUALITY_LOW,
|
||||
SSS_QUALITY_MEDIUM,
|
||||
SSS_QUALITY_HIGH,
|
||||
};
|
||||
|
||||
SubSurfaceScatterQuality subsurface_scatter_quality;
|
||||
float subsurface_scatter_size;
|
||||
bool subsurface_scatter_follow_surface;
|
||||
bool subsurface_scatter_weight_samples;
|
||||
|
||||
uint64_t render_pass;
|
||||
uint64_t scene_pass;
|
||||
uint32_t current_material_index;
|
||||
uint32_t current_geometry_index;
|
||||
|
||||
RID default_material;
|
||||
RID default_material_twosided;
|
||||
RID default_shader;
|
||||
RID default_shader_twosided;
|
||||
|
||||
RID default_worldcoord_material;
|
||||
RID default_worldcoord_material_twosided;
|
||||
RID default_worldcoord_shader;
|
||||
RID default_worldcoord_shader_twosided;
|
||||
|
||||
RID default_overdraw_material;
|
||||
RID default_overdraw_shader;
|
||||
|
||||
RasterizerStorageGLES3 *storage;
|
||||
|
||||
Vector<RasterizerStorageGLES3::RenderTarget::Exposure> exposure_shrink;
|
||||
int exposure_shrink_size;
|
||||
|
||||
struct State {
|
||||
bool texscreen_copied;
|
||||
int current_blend_mode;
|
||||
float current_line_width;
|
||||
int current_depth_draw;
|
||||
bool current_depth_test;
|
||||
GLuint current_main_tex;
|
||||
|
||||
SceneShaderGLES3 scene_shader;
|
||||
CubeToDpShaderGLES3 cube_to_dp_shader;
|
||||
ResolveShaderGLES3 resolve_shader;
|
||||
ScreenSpaceReflectionShaderGLES3 ssr_shader;
|
||||
EffectBlurShaderGLES3 effect_blur_shader;
|
||||
SubsurfScatteringShaderGLES3 sss_shader;
|
||||
SsaoMinifyShaderGLES3 ssao_minify_shader;
|
||||
SsaoShaderGLES3 ssao_shader;
|
||||
SsaoBlurShaderGLES3 ssao_blur_shader;
|
||||
ExposureShaderGLES3 exposure_shader;
|
||||
TonemapShaderGLES3 tonemap_shader;
|
||||
|
||||
struct SceneDataUBO {
|
||||
//this is a std140 compatible struct. Please read the OpenGL 3.3 Specification spec before doing any changes
|
||||
float projection_matrix[16];
|
||||
float inv_projection_matrix[16];
|
||||
float camera_inverse_matrix[16];
|
||||
float camera_matrix[16];
|
||||
float ambient_light_color[4];
|
||||
float bg_color[4];
|
||||
float fog_color_enabled[4];
|
||||
float fog_sun_color_amount[4];
|
||||
|
||||
float ambient_energy;
|
||||
float bg_energy;
|
||||
float z_offset;
|
||||
float z_slope_scale;
|
||||
float shadow_dual_paraboloid_render_zfar;
|
||||
float shadow_dual_paraboloid_render_side;
|
||||
float viewport_size[2];
|
||||
float screen_pixel_size[2];
|
||||
float shadow_atlas_pixel_size[2];
|
||||
float shadow_directional_pixel_size[2];
|
||||
|
||||
float time;
|
||||
float z_far;
|
||||
float reflection_multiplier;
|
||||
float subsurface_scatter_width;
|
||||
float ambient_occlusion_affect_light;
|
||||
float ambient_occlusion_affect_ssao;
|
||||
float opaque_prepass_threshold;
|
||||
|
||||
uint32_t fog_depth_enabled;
|
||||
float fog_depth_begin;
|
||||
float fog_depth_end;
|
||||
float fog_density;
|
||||
float fog_depth_curve;
|
||||
uint32_t fog_transmit_enabled;
|
||||
float fog_transmit_curve;
|
||||
uint32_t fog_height_enabled;
|
||||
float fog_height_min;
|
||||
float fog_height_max;
|
||||
float fog_height_curve;
|
||||
|
||||
uint32_t view_index;
|
||||
|
||||
// make sure this struct is padded to be a multiple of 16 bytes for webgl
|
||||
float pad[3];
|
||||
|
||||
} ubo_data;
|
||||
static_assert(sizeof(SceneDataUBO) % 16 == 0, "SceneDataUBO size must be a multiple of 16 bytes");
|
||||
|
||||
GLuint scene_ubo;
|
||||
|
||||
struct EnvironmentRadianceUBO {
|
||||
float transform[16];
|
||||
float ambient_contribution;
|
||||
uint8_t padding[12];
|
||||
|
||||
} env_radiance_data;
|
||||
|
||||
GLuint env_radiance_ubo;
|
||||
|
||||
GLuint sky_verts;
|
||||
GLuint sky_array;
|
||||
|
||||
GLuint directional_ubo;
|
||||
|
||||
GLuint spot_array_ubo;
|
||||
GLuint omni_array_ubo;
|
||||
GLuint reflection_array_ubo;
|
||||
|
||||
GLuint immediate_buffer;
|
||||
GLuint immediate_array;
|
||||
|
||||
uint32_t ubo_light_size;
|
||||
uint8_t *spot_array_tmp;
|
||||
uint8_t *omni_array_tmp;
|
||||
uint8_t *reflection_array_tmp;
|
||||
|
||||
int max_ubo_lights;
|
||||
int max_forward_lights_per_object;
|
||||
int max_ubo_reflections;
|
||||
int max_skeleton_bones;
|
||||
|
||||
bool used_contact_shadows;
|
||||
|
||||
int spot_light_count;
|
||||
int omni_light_count;
|
||||
int directional_light_count;
|
||||
int reflection_probe_count;
|
||||
|
||||
bool cull_front;
|
||||
bool cull_disabled;
|
||||
bool used_sss;
|
||||
bool used_screen_texture;
|
||||
|
||||
bool used_depth_prepass;
|
||||
|
||||
bool used_depth_texture;
|
||||
bool prepared_depth_texture;
|
||||
bool bound_depth_texture;
|
||||
|
||||
VS::ViewportDebugDraw debug_draw;
|
||||
} state;
|
||||
|
||||
/* SHADOW ATLAS API */
|
||||
|
||||
struct ShadowAtlas : public RID_Data {
|
||||
enum {
|
||||
QUADRANT_SHIFT = 27,
|
||||
SHADOW_INDEX_MASK = (1 << QUADRANT_SHIFT) - 1,
|
||||
SHADOW_INVALID = 0xFFFFFFFF
|
||||
};
|
||||
|
||||
struct Quadrant {
|
||||
uint32_t subdivision;
|
||||
|
||||
struct Shadow {
|
||||
RID owner;
|
||||
uint64_t version;
|
||||
uint64_t alloc_tick;
|
||||
|
||||
Shadow() {
|
||||
version = 0;
|
||||
alloc_tick = 0;
|
||||
}
|
||||
};
|
||||
|
||||
Vector<Shadow> shadows;
|
||||
|
||||
Quadrant() {
|
||||
subdivision = 0; //not in use
|
||||
}
|
||||
|
||||
} quadrants[4];
|
||||
|
||||
int size_order[4];
|
||||
uint32_t smallest_subdiv;
|
||||
|
||||
int size;
|
||||
|
||||
GLuint fbo;
|
||||
GLuint depth;
|
||||
|
||||
Map<RID, uint32_t> shadow_owners;
|
||||
};
|
||||
|
||||
struct ShadowCubeMap {
|
||||
GLuint fbo_id[6];
|
||||
GLuint cubemap;
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
Vector<ShadowCubeMap> shadow_cubemaps;
|
||||
|
||||
RID_Owner<ShadowAtlas> shadow_atlas_owner;
|
||||
|
||||
int directional_shadow_size;
|
||||
|
||||
void directional_shadow_create();
|
||||
RID shadow_atlas_create();
|
||||
void shadow_atlas_set_size(RID p_atlas, int p_size);
|
||||
void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision);
|
||||
bool _shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas, int *p_in_quadrants, int p_quadrant_count, int p_current_subdiv, uint64_t p_tick, int &r_quadrant, int &r_shadow);
|
||||
bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version);
|
||||
|
||||
struct DirectionalShadow {
|
||||
GLuint fbo;
|
||||
GLuint depth;
|
||||
int light_count;
|
||||
int size;
|
||||
int current_light;
|
||||
} directional_shadow;
|
||||
|
||||
virtual int get_directional_light_shadow_size(RID p_light_intance);
|
||||
virtual void set_directional_shadow_count(int p_count);
|
||||
|
||||
/* REFLECTION PROBE ATLAS API */
|
||||
|
||||
struct ReflectionAtlas : public RID_Data {
|
||||
int subdiv;
|
||||
int size;
|
||||
|
||||
struct Reflection {
|
||||
RID owner;
|
||||
uint64_t last_frame;
|
||||
};
|
||||
|
||||
GLuint fbo[6];
|
||||
GLuint color;
|
||||
|
||||
Vector<Reflection> reflections;
|
||||
};
|
||||
|
||||
mutable RID_Owner<ReflectionAtlas> reflection_atlas_owner;
|
||||
|
||||
virtual RID reflection_atlas_create();
|
||||
virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_size);
|
||||
virtual void reflection_atlas_set_subdivision(RID p_ref_atlas, int p_subdiv);
|
||||
|
||||
/* REFLECTION CUBEMAPS */
|
||||
|
||||
struct ReflectionCubeMap {
|
||||
GLuint fbo_id[6];
|
||||
GLuint cubemap;
|
||||
GLuint depth;
|
||||
int size;
|
||||
};
|
||||
|
||||
Vector<ReflectionCubeMap> reflection_cubemaps;
|
||||
|
||||
/* REFLECTION PROBE INSTANCE */
|
||||
|
||||
struct ReflectionProbeInstance : public RID_Data {
|
||||
RasterizerStorageGLES3::ReflectionProbe *probe_ptr;
|
||||
RID probe;
|
||||
RID self;
|
||||
RID atlas;
|
||||
|
||||
int reflection_atlas_index;
|
||||
|
||||
int render_step;
|
||||
|
||||
uint64_t last_pass;
|
||||
int reflection_index;
|
||||
|
||||
Transform transform;
|
||||
};
|
||||
|
||||
struct ReflectionProbeDataUBO {
|
||||
float box_extents[4];
|
||||
float box_ofs[4];
|
||||
float params[4]; // intensity, 0, 0, boxproject
|
||||
float ambient[4]; //color, probe contrib
|
||||
float atlas_clamp[4];
|
||||
float local_matrix[16]; //up to here for spot and omni, rest is for directional
|
||||
//notes: for ambientblend, use distance to edge to blend between already existing global environment
|
||||
};
|
||||
|
||||
mutable RID_Owner<ReflectionProbeInstance> reflection_probe_instance_owner;
|
||||
|
||||
virtual RID reflection_probe_instance_create(RID p_probe);
|
||||
virtual void reflection_probe_instance_set_transform(RID p_instance, const Transform &p_transform);
|
||||
virtual void reflection_probe_release_atlas_index(RID p_instance);
|
||||
virtual bool reflection_probe_instance_needs_redraw(RID p_instance);
|
||||
virtual bool reflection_probe_instance_has_reflection(RID p_instance);
|
||||
virtual bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas);
|
||||
virtual bool reflection_probe_instance_postprocess_step(RID p_instance);
|
||||
|
||||
/* ENVIRONMENT API */
|
||||
|
||||
struct Environment : public RID_Data {
|
||||
VS::EnvironmentBG bg_mode;
|
||||
|
||||
RID sky;
|
||||
float sky_custom_fov;
|
||||
Basis sky_orientation;
|
||||
|
||||
Color bg_color;
|
||||
float bg_energy;
|
||||
float sky_ambient;
|
||||
|
||||
int camera_feed_id;
|
||||
|
||||
Color ambient_color;
|
||||
float ambient_energy;
|
||||
float ambient_sky_contribution;
|
||||
|
||||
int canvas_max_layer;
|
||||
|
||||
bool ssr_enabled;
|
||||
int ssr_max_steps;
|
||||
float ssr_fade_in;
|
||||
float ssr_fade_out;
|
||||
float ssr_depth_tolerance;
|
||||
bool ssr_roughness;
|
||||
|
||||
bool ssao_enabled;
|
||||
float ssao_intensity;
|
||||
float ssao_radius;
|
||||
float ssao_intensity2;
|
||||
float ssao_radius2;
|
||||
float ssao_bias;
|
||||
float ssao_light_affect;
|
||||
float ssao_ao_channel_affect;
|
||||
Color ssao_color;
|
||||
VS::EnvironmentSSAOQuality ssao_quality;
|
||||
float ssao_bilateral_sharpness;
|
||||
VS::EnvironmentSSAOBlur ssao_filter;
|
||||
|
||||
bool glow_enabled;
|
||||
int glow_levels;
|
||||
float glow_intensity;
|
||||
float glow_strength;
|
||||
float glow_bloom;
|
||||
VS::EnvironmentGlowBlendMode glow_blend_mode;
|
||||
float glow_hdr_bleed_threshold;
|
||||
float glow_hdr_bleed_scale;
|
||||
float glow_hdr_luminance_cap;
|
||||
bool glow_bicubic_upscale;
|
||||
bool glow_high_quality;
|
||||
|
||||
VS::EnvironmentToneMapper tone_mapper;
|
||||
float tone_mapper_exposure;
|
||||
float tone_mapper_exposure_white;
|
||||
bool auto_exposure;
|
||||
float auto_exposure_speed;
|
||||
float auto_exposure_min;
|
||||
float auto_exposure_max;
|
||||
float auto_exposure_grey;
|
||||
|
||||
bool dof_blur_far_enabled;
|
||||
float dof_blur_far_distance;
|
||||
float dof_blur_far_transition;
|
||||
float dof_blur_far_amount;
|
||||
VS::EnvironmentDOFBlurQuality dof_blur_far_quality;
|
||||
|
||||
bool dof_blur_near_enabled;
|
||||
float dof_blur_near_distance;
|
||||
float dof_blur_near_transition;
|
||||
float dof_blur_near_amount;
|
||||
VS::EnvironmentDOFBlurQuality dof_blur_near_quality;
|
||||
|
||||
bool adjustments_enabled;
|
||||
float adjustments_brightness;
|
||||
float adjustments_contrast;
|
||||
float adjustments_saturation;
|
||||
RID color_correction;
|
||||
|
||||
bool fog_enabled;
|
||||
Color fog_color;
|
||||
Color fog_sun_color;
|
||||
float fog_sun_amount;
|
||||
|
||||
bool fog_depth_enabled;
|
||||
float fog_depth_begin;
|
||||
float fog_depth_end;
|
||||
float fog_depth_curve;
|
||||
bool fog_transmit_enabled;
|
||||
float fog_transmit_curve;
|
||||
bool fog_height_enabled;
|
||||
float fog_height_min;
|
||||
float fog_height_max;
|
||||
float fog_height_curve;
|
||||
|
||||
Environment() :
|
||||
bg_mode(VS::ENV_BG_CLEAR_COLOR),
|
||||
sky_custom_fov(0.0),
|
||||
bg_energy(1.0),
|
||||
sky_ambient(0),
|
||||
camera_feed_id(0),
|
||||
ambient_energy(1.0),
|
||||
ambient_sky_contribution(0.0),
|
||||
canvas_max_layer(0),
|
||||
ssr_enabled(false),
|
||||
ssr_max_steps(64),
|
||||
ssr_fade_in(0.15),
|
||||
ssr_fade_out(2.0),
|
||||
ssr_depth_tolerance(0.2),
|
||||
ssr_roughness(true),
|
||||
ssao_enabled(false),
|
||||
ssao_intensity(1.0),
|
||||
ssao_radius(1.0),
|
||||
ssao_intensity2(1.0),
|
||||
ssao_radius2(0.0),
|
||||
ssao_bias(0.01),
|
||||
ssao_light_affect(0),
|
||||
ssao_ao_channel_affect(0),
|
||||
ssao_quality(VS::ENV_SSAO_QUALITY_LOW),
|
||||
ssao_bilateral_sharpness(4),
|
||||
ssao_filter(VS::ENV_SSAO_BLUR_3x3),
|
||||
glow_enabled(false),
|
||||
glow_levels((1 << 2) | (1 << 4)),
|
||||
glow_intensity(0.8),
|
||||
glow_strength(1.0),
|
||||
glow_bloom(0.0),
|
||||
glow_blend_mode(VS::GLOW_BLEND_MODE_SOFTLIGHT),
|
||||
glow_hdr_bleed_threshold(1.0),
|
||||
glow_hdr_bleed_scale(2.0),
|
||||
glow_hdr_luminance_cap(12.0),
|
||||
glow_bicubic_upscale(false),
|
||||
glow_high_quality(false),
|
||||
tone_mapper(VS::ENV_TONE_MAPPER_LINEAR),
|
||||
tone_mapper_exposure(1.0),
|
||||
tone_mapper_exposure_white(1.0),
|
||||
auto_exposure(false),
|
||||
auto_exposure_speed(0.5),
|
||||
auto_exposure_min(0.05),
|
||||
auto_exposure_max(8),
|
||||
auto_exposure_grey(0.4),
|
||||
dof_blur_far_enabled(false),
|
||||
dof_blur_far_distance(10),
|
||||
dof_blur_far_transition(5),
|
||||
dof_blur_far_amount(0.1),
|
||||
dof_blur_far_quality(VS::ENV_DOF_BLUR_QUALITY_MEDIUM),
|
||||
dof_blur_near_enabled(false),
|
||||
dof_blur_near_distance(2),
|
||||
dof_blur_near_transition(1),
|
||||
dof_blur_near_amount(0.1),
|
||||
dof_blur_near_quality(VS::ENV_DOF_BLUR_QUALITY_MEDIUM),
|
||||
adjustments_enabled(false),
|
||||
adjustments_brightness(1.0),
|
||||
adjustments_contrast(1.0),
|
||||
adjustments_saturation(1.0),
|
||||
fog_enabled(false),
|
||||
fog_color(Color(0.5, 0.5, 0.5)),
|
||||
fog_sun_color(Color(0.8, 0.8, 0.0)),
|
||||
fog_sun_amount(0),
|
||||
fog_depth_enabled(true),
|
||||
fog_depth_begin(10),
|
||||
fog_depth_end(0),
|
||||
fog_depth_curve(1),
|
||||
fog_transmit_enabled(true),
|
||||
fog_transmit_curve(1),
|
||||
fog_height_enabled(false),
|
||||
fog_height_min(10),
|
||||
fog_height_max(0),
|
||||
fog_height_curve(1) {
|
||||
}
|
||||
};
|
||||
|
||||
RID_Owner<Environment> environment_owner;
|
||||
|
||||
virtual RID environment_create();
|
||||
|
||||
virtual void environment_set_background(RID p_env, VS::EnvironmentBG p_bg);
|
||||
virtual void environment_set_sky(RID p_env, RID p_sky);
|
||||
virtual void environment_set_sky_custom_fov(RID p_env, float p_scale);
|
||||
virtual void environment_set_sky_orientation(RID p_env, const Basis &p_orientation);
|
||||
virtual void environment_set_bg_color(RID p_env, const Color &p_color);
|
||||
virtual void environment_set_bg_energy(RID p_env, float p_energy);
|
||||
virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer);
|
||||
virtual void environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy = 1.0, float p_sky_contribution = 0.0);
|
||||
virtual void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id);
|
||||
|
||||
virtual void environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, VS::EnvironmentDOFBlurQuality p_quality);
|
||||
virtual void environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, VS::EnvironmentDOFBlurQuality p_quality);
|
||||
|
||||
virtual void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale, bool p_high_quality);
|
||||
virtual void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture);
|
||||
|
||||
virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_in, float p_fade_out, float p_depth_tolerance, bool p_roughness);
|
||||
virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, float p_ao_channel_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness);
|
||||
|
||||
virtual void environment_set_tonemap(RID p_env, VS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale);
|
||||
|
||||
virtual void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp);
|
||||
|
||||
virtual void environment_set_fog(RID p_env, bool p_enable, const Color &p_color, const Color &p_sun_color, float p_sun_amount);
|
||||
virtual void environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_end, float p_depth_curve, bool p_transmit, float p_transmit_curve);
|
||||
virtual void environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve);
|
||||
|
||||
virtual bool is_environment(RID p_env);
|
||||
|
||||
virtual VS::EnvironmentBG environment_get_background(RID p_env);
|
||||
virtual int environment_get_canvas_max_layer(RID p_env);
|
||||
|
||||
/* LIGHT INSTANCE */
|
||||
|
||||
struct LightDataUBO {
|
||||
float light_pos_inv_radius[4];
|
||||
float light_direction_attenuation[4];
|
||||
float light_color_energy[4];
|
||||
float light_params[4]; //spot attenuation, spot angle, specular, shadow enabled
|
||||
float light_clamp[4];
|
||||
float light_shadow_color_contact[4];
|
||||
union {
|
||||
struct {
|
||||
float matrix1[16]; //up to here for spot and omni, rest is for directional
|
||||
float matrix2[16];
|
||||
float matrix3[16];
|
||||
float matrix4[16];
|
||||
};
|
||||
float matrix[4 * 16];
|
||||
} shadow;
|
||||
float shadow_split_offsets[4];
|
||||
};
|
||||
|
||||
struct LightInstance : public RID_Data {
|
||||
struct ShadowTransform {
|
||||
CameraMatrix camera;
|
||||
Transform transform;
|
||||
float farplane;
|
||||
float split;
|
||||
float bias_scale;
|
||||
};
|
||||
|
||||
ShadowTransform shadow_transform[4];
|
||||
|
||||
RID self;
|
||||
RID light;
|
||||
RasterizerStorageGLES3::Light *light_ptr;
|
||||
Transform transform;
|
||||
|
||||
Vector3 light_vector;
|
||||
Vector3 spot_vector;
|
||||
float linear_att;
|
||||
|
||||
uint64_t shadow_pass;
|
||||
uint64_t last_scene_pass;
|
||||
uint64_t last_scene_shadow_pass;
|
||||
uint64_t last_pass;
|
||||
uint16_t light_index;
|
||||
uint16_t light_directional_index;
|
||||
|
||||
uint32_t current_shadow_atlas_key;
|
||||
|
||||
Vector2 dp;
|
||||
|
||||
Rect2 directional_rect;
|
||||
|
||||
Set<RID> shadow_atlases; //shadow atlases where this light is registered
|
||||
|
||||
LightInstance() {}
|
||||
};
|
||||
|
||||
mutable RID_Owner<LightInstance> light_instance_owner;
|
||||
|
||||
virtual RID light_instance_create(RID p_light);
|
||||
virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform);
|
||||
virtual void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0);
|
||||
virtual void light_instance_mark_visible(RID p_light_instance);
|
||||
|
||||
/* REFLECTION INSTANCE */
|
||||
|
||||
struct GIProbeInstance : public RID_Data {
|
||||
RID data;
|
||||
RasterizerStorageGLES3::GIProbe *probe;
|
||||
GLuint tex_cache;
|
||||
Vector3 cell_size_cache;
|
||||
Vector3 bounds;
|
||||
Transform transform_to_data;
|
||||
|
||||
GIProbeInstance() :
|
||||
probe(nullptr),
|
||||
tex_cache(0) {
|
||||
}
|
||||
};
|
||||
|
||||
mutable RID_Owner<GIProbeInstance> gi_probe_instance_owner;
|
||||
|
||||
virtual RID gi_probe_instance_create();
|
||||
virtual void gi_probe_instance_set_light_data(RID p_probe, RID p_base, RID p_data);
|
||||
virtual void gi_probe_instance_set_transform_to_data(RID p_probe, const Transform &p_xform);
|
||||
virtual void gi_probe_instance_set_bounds(RID p_probe, const Vector3 &p_bounds);
|
||||
|
||||
/* RENDER LIST */
|
||||
|
||||
struct RenderList {
|
||||
enum {
|
||||
DEFAULT_MAX_ELEMENTS = 65536,
|
||||
SORT_FLAG_SKELETON = 1,
|
||||
SORT_FLAG_INSTANCING = 2,
|
||||
MAX_DIRECTIONAL_LIGHTS = 16,
|
||||
DEFAULT_MAX_LIGHTS = 4096,
|
||||
DEFAULT_MAX_REFLECTIONS = 1024,
|
||||
DEFAULT_MAX_LIGHTS_PER_OBJECT = 32,
|
||||
|
||||
SORT_KEY_PRIORITY_SHIFT = 56,
|
||||
SORT_KEY_PRIORITY_MASK = 0xFF,
|
||||
//depth layer for opaque (56-52)
|
||||
SORT_KEY_OPAQUE_DEPTH_LAYER_SHIFT = 52,
|
||||
SORT_KEY_OPAQUE_DEPTH_LAYER_MASK = 0xF,
|
||||
//64 bits unsupported in MSVC
|
||||
#define SORT_KEY_UNSHADED_FLAG (uint64_t(1) << 50)
|
||||
#define SORT_KEY_NO_DIRECTIONAL_FLAG (uint64_t(1) << 49)
|
||||
#define SORT_KEY_LIGHTMAP_CAPTURE_FLAG (uint64_t(1) << 48)
|
||||
#define SORT_KEY_LIGHTMAP_LAYERED_FLAG (uint64_t(1) << 47)
|
||||
#define SORT_KEY_LIGHTMAP_FLAG (uint64_t(1) << 46)
|
||||
#define SORT_KEY_GI_PROBES_FLAG (uint64_t(1) << 45)
|
||||
#define SORT_KEY_VERTEX_LIT_FLAG (uint64_t(1) << 44)
|
||||
SORT_KEY_SHADING_SHIFT = 44,
|
||||
SORT_KEY_SHADING_MASK = 127,
|
||||
//44-28 material index
|
||||
SORT_KEY_MATERIAL_INDEX_SHIFT = 28,
|
||||
//28-8 geometry index
|
||||
SORT_KEY_GEOMETRY_INDEX_SHIFT = 8,
|
||||
//bits 5-7 geometry type
|
||||
SORT_KEY_GEOMETRY_TYPE_SHIFT = 5,
|
||||
//bits 0-5 for flags
|
||||
SORT_KEY_OPAQUE_PRE_PASS = 8,
|
||||
SORT_KEY_CULL_DISABLED_FLAG = 4,
|
||||
SORT_KEY_SKELETON_FLAG = 2,
|
||||
SORT_KEY_MIRROR_FLAG = 1
|
||||
|
||||
};
|
||||
|
||||
int max_elements;
|
||||
int max_lights;
|
||||
int max_reflections;
|
||||
int max_lights_per_object;
|
||||
|
||||
struct Element {
|
||||
RasterizerScene::InstanceBase *instance;
|
||||
RasterizerStorageGLES3::Geometry *geometry;
|
||||
RasterizerStorageGLES3::Material *material;
|
||||
RasterizerStorageGLES3::GeometryOwner *owner;
|
||||
uint64_t sort_key;
|
||||
};
|
||||
|
||||
Element *base_elements;
|
||||
Element **elements;
|
||||
|
||||
int element_count;
|
||||
int alpha_element_count;
|
||||
|
||||
void clear() {
|
||||
element_count = 0;
|
||||
alpha_element_count = 0;
|
||||
}
|
||||
|
||||
//should eventually be replaced by radix
|
||||
|
||||
struct SortByKey {
|
||||
_FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
|
||||
return A->sort_key < B->sort_key;
|
||||
}
|
||||
};
|
||||
|
||||
void sort_by_key(bool p_alpha) {
|
||||
SortArray<Element *, SortByKey> sorter;
|
||||
if (p_alpha) {
|
||||
sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count);
|
||||
} else {
|
||||
sorter.sort(elements, element_count);
|
||||
}
|
||||
}
|
||||
|
||||
struct SortByDepth {
|
||||
_FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
|
||||
return A->instance->depth < B->instance->depth;
|
||||
}
|
||||
};
|
||||
|
||||
void sort_by_depth(bool p_alpha) { //used for shadows
|
||||
|
||||
SortArray<Element *, SortByDepth> sorter;
|
||||
if (p_alpha) {
|
||||
sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count);
|
||||
} else {
|
||||
sorter.sort(elements, element_count);
|
||||
}
|
||||
}
|
||||
|
||||
struct SortByReverseDepthAndPriority {
|
||||
_FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
|
||||
uint32_t layer_A = uint32_t(A->sort_key >> SORT_KEY_PRIORITY_SHIFT);
|
||||
uint32_t layer_B = uint32_t(B->sort_key >> SORT_KEY_PRIORITY_SHIFT);
|
||||
if (layer_A == layer_B) {
|
||||
return A->instance->depth > B->instance->depth;
|
||||
} else {
|
||||
return layer_A < layer_B;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void sort_by_reverse_depth_and_priority(bool p_alpha) { //used for alpha
|
||||
|
||||
SortArray<Element *, SortByReverseDepthAndPriority> sorter;
|
||||
if (p_alpha) {
|
||||
sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count);
|
||||
} else {
|
||||
sorter.sort(elements, element_count);
|
||||
}
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Element *add_element() {
|
||||
if (element_count + alpha_element_count >= max_elements) {
|
||||
return nullptr;
|
||||
}
|
||||
elements[element_count] = &base_elements[element_count];
|
||||
return elements[element_count++];
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Element *add_alpha_element() {
|
||||
if (element_count + alpha_element_count >= max_elements) {
|
||||
return nullptr;
|
||||
}
|
||||
int idx = max_elements - alpha_element_count - 1;
|
||||
elements[idx] = &base_elements[idx];
|
||||
alpha_element_count++;
|
||||
return elements[idx];
|
||||
}
|
||||
|
||||
void init() {
|
||||
element_count = 0;
|
||||
alpha_element_count = 0;
|
||||
elements = memnew_arr(Element *, max_elements);
|
||||
base_elements = memnew_arr(Element, max_elements);
|
||||
for (int i = 0; i < max_elements; i++) {
|
||||
elements[i] = &base_elements[i]; // assign elements
|
||||
}
|
||||
}
|
||||
|
||||
RenderList() {
|
||||
max_elements = DEFAULT_MAX_ELEMENTS;
|
||||
max_lights = DEFAULT_MAX_LIGHTS;
|
||||
max_reflections = DEFAULT_MAX_REFLECTIONS;
|
||||
}
|
||||
|
||||
~RenderList() {
|
||||
memdelete_arr(elements);
|
||||
memdelete_arr(base_elements);
|
||||
}
|
||||
};
|
||||
|
||||
LightInstance *directional_light;
|
||||
LightInstance *directional_lights[RenderList::MAX_DIRECTIONAL_LIGHTS];
|
||||
RID first_directional_light;
|
||||
|
||||
RenderList render_list;
|
||||
|
||||
_FORCE_INLINE_ void _set_cull(bool p_front, bool p_disabled, bool p_reverse_cull);
|
||||
|
||||
_FORCE_INLINE_ bool _setup_material(RasterizerStorageGLES3::Material *p_material, bool p_depth_pass, bool p_alpha_pass);
|
||||
_FORCE_INLINE_ void _setup_geometry(RenderList::Element *e, const Transform &p_view_transform);
|
||||
_FORCE_INLINE_ void _render_geometry(RenderList::Element *e);
|
||||
void _setup_light(RenderList::Element *e, const Transform &p_view_transform);
|
||||
|
||||
void _render_list(RenderList::Element **p_elements, int p_element_count, const Transform &p_view_transform, const CameraMatrix &p_projection, RasterizerStorageGLES3::Sky *p_sky, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow, bool p_directional_add, bool p_directional_shadows);
|
||||
|
||||
_FORCE_INLINE_ void _add_geometry(RasterizerStorageGLES3::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES3::GeometryOwner *p_owner, int p_material, bool p_depth_pass, bool p_shadow_pass);
|
||||
|
||||
_FORCE_INLINE_ void _add_geometry_with_material(RasterizerStorageGLES3::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES3::GeometryOwner *p_owner, RasterizerStorageGLES3::Material *p_material, bool p_depth_pass, bool p_shadow_pass);
|
||||
|
||||
void _draw_sky(RasterizerStorageGLES3::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_custom_fov, float p_energy, const Basis &p_sky_orientation);
|
||||
|
||||
void _setup_environment(Environment *env, const CameraMatrix &p_cam_projection, const Transform &p_cam_transform, const int p_eye = 0, bool p_no_fog = false);
|
||||
void _setup_directional_light(int p_index, const Transform &p_camera_inverse_transform, bool p_use_shadows);
|
||||
void _setup_lights(RID *p_light_cull_result, int p_light_cull_count, const Transform &p_camera_inverse_transform, const CameraMatrix &p_camera_projection, RID p_shadow_atlas);
|
||||
void _setup_reflections(RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, const Transform &p_camera_inverse_transform, const CameraMatrix &p_camera_projection, RID p_reflection_atlas, Environment *p_env);
|
||||
|
||||
void _copy_screen(bool p_invalidate_color = false, bool p_invalidate_depth = false);
|
||||
void _copy_texture_to_front_buffer(GLuint p_texture); //used for debug
|
||||
|
||||
void _fill_render_list(InstanceBase **p_cull_result, int p_cull_count, bool p_depth_pass, bool p_shadow_pass);
|
||||
|
||||
void _blur_effect_buffer();
|
||||
void _render_mrts(Environment *env, const CameraMatrix &p_cam_projection);
|
||||
void _post_process(Environment *env, const CameraMatrix &p_cam_projection);
|
||||
|
||||
void _prepare_depth_texture();
|
||||
void _bind_depth_texture();
|
||||
|
||||
bool _element_needs_directional_add(RenderList::Element *e);
|
||||
virtual void render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, const int p_eye, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass);
|
||||
virtual void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count);
|
||||
virtual bool free(RID p_rid);
|
||||
|
||||
virtual void set_scene_pass(uint64_t p_pass);
|
||||
virtual void set_debug_draw_mode(VS::ViewportDebugDraw p_debug_draw);
|
||||
|
||||
void iteration();
|
||||
void initialize();
|
||||
void finalize();
|
||||
RasterizerSceneGLES3();
|
||||
~RasterizerSceneGLES3();
|
||||
};
|
||||
|
||||
#endif // RASTERIZERSCENEGLES3_H
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,196 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* shader_cache_gles3.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "shader_cache_gles3.h"
|
||||
|
||||
#include "core/crypto/crypto_core.h"
|
||||
#include "core/os/dir_access.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/project_settings.h"
|
||||
#include "core/sort_array.h"
|
||||
#include "core/ustring.h"
|
||||
|
||||
String ShaderCacheGLES3::hash_program(const char *const *p_strings_platform, const LocalVector<const char *> &p_vertex_strings, const LocalVector<const char *> &p_fragment_strings) {
|
||||
CryptoCore::SHA256Context ctx;
|
||||
ctx.start();
|
||||
|
||||
// GL may already reject a binary program if hardware/software has changed, but just in case
|
||||
for (const char *const *s = p_strings_platform; *s; s++) {
|
||||
uint8_t *bytes = reinterpret_cast<uint8_t *>(const_cast<char *>(*s));
|
||||
ctx.update(bytes, strlen(*s));
|
||||
}
|
||||
for (uint32_t i = 0; i < p_vertex_strings.size(); i++) {
|
||||
ctx.update((uint8_t *)p_vertex_strings[i], strlen(p_vertex_strings[i]));
|
||||
}
|
||||
for (uint32_t i = 0; i < p_fragment_strings.size(); i++) {
|
||||
ctx.update((uint8_t *)p_fragment_strings[i], strlen(p_fragment_strings[i]));
|
||||
}
|
||||
|
||||
uint8_t hash[32];
|
||||
ctx.finish(hash);
|
||||
return String::hex_encode_buffer(hash, 32);
|
||||
}
|
||||
|
||||
bool ShaderCacheGLES3::retrieve(const String &p_program_hash, uint32_t *r_format, PoolByteArray *r_data) {
|
||||
if (!storage_da) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FileAccessRef fa = FileAccess::open(storage_path.plus_file(p_program_hash), FileAccess::READ_WRITE);
|
||||
if (!fa) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*r_format = fa->get_32();
|
||||
uint32_t binary_len = fa->get_32();
|
||||
if (binary_len <= 0 || binary_len > 0x10000000) {
|
||||
ERR_PRINT("Program binary cache file is corrupted. Ignoring and removing.");
|
||||
fa->close();
|
||||
storage_da->remove(p_program_hash);
|
||||
return false;
|
||||
}
|
||||
r_data->resize(binary_len);
|
||||
PoolByteArray::Write w = r_data->write();
|
||||
if (fa->get_buffer(w.ptr(), binary_len) != static_cast<uint64_t>(binary_len)) {
|
||||
ERR_PRINT("Program binary cache file is truncated. Ignoring and removing.");
|
||||
fa->close();
|
||||
storage_da->remove(p_program_hash);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Force update modification time (for LRU purge)
|
||||
fa->seek(0);
|
||||
fa->store_32(*r_format);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ShaderCacheGLES3::store(const String &p_program_hash, uint32_t p_program_format, const PoolByteArray &p_program_data) {
|
||||
if (!storage_da) {
|
||||
return;
|
||||
}
|
||||
|
||||
FileAccessRef fa = FileAccess::open(storage_path.plus_file(p_program_hash), FileAccess::WRITE);
|
||||
ERR_FAIL_COND(!fa);
|
||||
fa->store_32(p_program_format);
|
||||
fa->store_32(p_program_data.size());
|
||||
PoolByteArray::Read r = p_program_data.read();
|
||||
fa->store_buffer(r.ptr(), p_program_data.size());
|
||||
}
|
||||
|
||||
void ShaderCacheGLES3::remove(const String &p_program_hash) {
|
||||
if (!storage_da) {
|
||||
return;
|
||||
}
|
||||
|
||||
storage_da->remove(p_program_hash);
|
||||
}
|
||||
|
||||
void ShaderCacheGLES3::_purge_excess() {
|
||||
if (!storage_da) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct Entry {
|
||||
String name;
|
||||
uint64_t timestamp;
|
||||
uint64_t size;
|
||||
|
||||
bool operator<(const Entry &p_rhs) const {
|
||||
return timestamp < p_rhs.timestamp;
|
||||
}
|
||||
};
|
||||
LocalVector<Entry> entries;
|
||||
uint64_t total_size = 0;
|
||||
|
||||
ERR_FAIL_COND(storage_da->list_dir_begin() != OK);
|
||||
while (true) {
|
||||
String f = storage_da->get_next();
|
||||
if (f == "") {
|
||||
break;
|
||||
}
|
||||
if (storage_da->current_is_dir()) {
|
||||
continue;
|
||||
}
|
||||
String path = storage_da->get_current_dir().plus_file(f);
|
||||
FileAccessRef fa = FileAccess::open(path, FileAccess::READ);
|
||||
ERR_CONTINUE(!fa);
|
||||
|
||||
Entry entry;
|
||||
entry.name = f;
|
||||
entry.timestamp = FileAccess::get_modified_time(path);
|
||||
entry.size = fa->get_len();
|
||||
entries.push_back(entry);
|
||||
total_size += entry.size;
|
||||
}
|
||||
storage_da->list_dir_end();
|
||||
|
||||
print_verbose("Shader cache size: " + itos(total_size / (1024 * 1024)) + " MiB (max. is " + (itos(storage_size / (1024 * 1024))) + " MiB)");
|
||||
if (total_size > storage_size) {
|
||||
print_verbose("Purging LRU from shader cache.");
|
||||
SortArray<Entry>().sort(entries.ptr(), entries.size());
|
||||
for (uint32_t i = 0; i < entries.size(); i++) {
|
||||
storage_da->remove(entries[i].name);
|
||||
total_size -= entries[i].size;
|
||||
if (total_size <= storage_size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ShaderCacheGLES3::ShaderCacheGLES3() {
|
||||
storage_size = (int)GLOBAL_GET("rendering/gles3/shaders/shader_cache_size_mb") * 1024 * 1024;
|
||||
|
||||
storage_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
storage_path = OS::get_singleton()->get_cache_path().plus_file(OS::get_singleton()->get_godot_dir_name()).plus_file("shaders");
|
||||
|
||||
print_verbose("Shader cache path: " + storage_path);
|
||||
if (storage_da->make_dir_recursive(storage_path) != OK) {
|
||||
ERR_PRINT("Couldn't create shader cache directory. Shader cache disabled.");
|
||||
memdelete(storage_da);
|
||||
storage_da = nullptr;
|
||||
return;
|
||||
}
|
||||
if (storage_da->change_dir(storage_path) != OK) {
|
||||
ERR_PRINT("Couldn't open shader cache directory. Shader cache disabled.");
|
||||
memdelete(storage_da);
|
||||
storage_da = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
_purge_excess();
|
||||
}
|
||||
|
||||
ShaderCacheGLES3::~ShaderCacheGLES3() {
|
||||
if (storage_da) {
|
||||
memdelete(storage_da);
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* shader_cache_gles3.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef SHADER_CACHE_GLES3_H
|
||||
#define SHADER_CACHE_GLES3_H
|
||||
|
||||
#include "core/local_vector.h"
|
||||
#include "core/reference.h"
|
||||
|
||||
class DirAccess;
|
||||
class String;
|
||||
|
||||
class ShaderCacheGLES3 {
|
||||
DirAccess *storage_da;
|
||||
String storage_path;
|
||||
uint64_t storage_size = 0;
|
||||
|
||||
void _purge_excess();
|
||||
|
||||
public:
|
||||
static String hash_program(const char *const *p_platform_strings, const LocalVector<const char *> &p_vertex_strings, const LocalVector<const char *> &p_fragment_strings);
|
||||
|
||||
bool retrieve(const String &p_program_hash, uint32_t *r_format, PoolByteArray *r_data);
|
||||
void store(const String &p_program_hash, uint32_t p_program_format, const PoolByteArray &p_program_data);
|
||||
void remove(const String &p_program_hash);
|
||||
|
||||
ShaderCacheGLES3();
|
||||
~ShaderCacheGLES3();
|
||||
};
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,103 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* shader_compiler_gles3.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef SHADERCOMPILERGLES3_H
|
||||
#define SHADERCOMPILERGLES3_H
|
||||
|
||||
#include "core/pair.h"
|
||||
#include "servers/visual/shader_language.h"
|
||||
#include "servers/visual/shader_types.h"
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
class ShaderCompilerGLES3 {
|
||||
public:
|
||||
struct IdentifierActions {
|
||||
Map<StringName, Pair<int *, int>> render_mode_values;
|
||||
Map<StringName, bool *> render_mode_flags;
|
||||
Map<StringName, bool *> usage_flag_pointers;
|
||||
Map<StringName, bool *> write_flag_pointers;
|
||||
|
||||
Map<StringName, ShaderLanguage::ShaderNode::Uniform> *uniforms;
|
||||
};
|
||||
|
||||
struct GeneratedCode {
|
||||
Vector<CharString> defines;
|
||||
Vector<StringName> texture_uniforms;
|
||||
Vector<ShaderLanguage::DataType> texture_types;
|
||||
Vector<ShaderLanguage::ShaderNode::Uniform::Hint> texture_hints;
|
||||
|
||||
Vector<uint32_t> uniform_offsets;
|
||||
uint32_t uniform_total_size;
|
||||
String uniforms;
|
||||
String vertex_global;
|
||||
String vertex;
|
||||
String fragment_global;
|
||||
String fragment;
|
||||
String light;
|
||||
|
||||
bool uses_fragment_time;
|
||||
bool uses_vertex_time;
|
||||
};
|
||||
|
||||
private:
|
||||
ShaderLanguage parser;
|
||||
|
||||
struct DefaultIdentifierActions {
|
||||
Map<StringName, String> renames;
|
||||
Map<StringName, String> render_mode_defines;
|
||||
Map<StringName, String> usage_defines;
|
||||
};
|
||||
|
||||
void _dump_function_deps(const ShaderLanguage::ShaderNode *p_node, const StringName &p_for_func, const Map<StringName, String> &p_func_code, String &r_to_add, Set<StringName> &added);
|
||||
String _dump_node_code(const ShaderLanguage::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions, bool p_assigning, bool p_use_scope = true);
|
||||
|
||||
const ShaderLanguage::ShaderNode *shader;
|
||||
const ShaderLanguage::FunctionNode *function;
|
||||
StringName current_func_name;
|
||||
StringName vertex_name;
|
||||
StringName fragment_name;
|
||||
StringName light_name;
|
||||
StringName time_name;
|
||||
|
||||
Set<StringName> used_name_defines;
|
||||
Set<StringName> used_flag_pointers;
|
||||
Set<StringName> used_rmode_defines;
|
||||
Set<StringName> internal_functions;
|
||||
Set<StringName> fragment_varyings;
|
||||
|
||||
DefaultIdentifierActions actions[VS::SHADER_MAX];
|
||||
|
||||
public:
|
||||
Error compile(VS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code);
|
||||
|
||||
ShaderCompilerGLES3();
|
||||
};
|
||||
|
||||
#endif // SHADERCOMPILERGLES3_H
|
File diff suppressed because it is too large
Load Diff
@ -1,446 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* shader_gles3.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef SHADER_GLES3_H
|
||||
#define SHADER_GLES3_H
|
||||
|
||||
#include "core/hash_map.h"
|
||||
#include "core/local_vector.h"
|
||||
#include "core/map.h"
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "core/safe_refcount.h"
|
||||
#include "core/self_list.h"
|
||||
#include "core/variant.h"
|
||||
|
||||
#include "platform_config.h"
|
||||
#ifndef GLES3_INCLUDE_H
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include GLES3_INCLUDE_H
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
template <class K>
|
||||
class ThreadedCallableQueue;
|
||||
class ShaderCacheGLES3;
|
||||
|
||||
class ShaderGLES3 {
|
||||
protected:
|
||||
struct Enum {
|
||||
uint64_t mask;
|
||||
uint64_t shift;
|
||||
const char *defines[16];
|
||||
};
|
||||
|
||||
struct EnumValue {
|
||||
uint64_t set_mask;
|
||||
uint64_t clear_mask;
|
||||
};
|
||||
|
||||
struct AttributePair {
|
||||
const char *name;
|
||||
int index;
|
||||
};
|
||||
|
||||
struct UniformPair {
|
||||
const char *name;
|
||||
Variant::Type type_hint;
|
||||
};
|
||||
|
||||
struct TexUnitPair {
|
||||
const char *name;
|
||||
int index;
|
||||
};
|
||||
|
||||
struct UBOPair {
|
||||
const char *name;
|
||||
int index;
|
||||
};
|
||||
|
||||
struct Feedback {
|
||||
const char *name;
|
||||
int conditional;
|
||||
};
|
||||
|
||||
virtual int get_ubershader_flags_uniform() const { return -1; }
|
||||
|
||||
private:
|
||||
//@TODO Optimize to a fixed set of shader pools and use a LRU
|
||||
int uniform_count;
|
||||
int texunit_pair_count;
|
||||
int conditional_count;
|
||||
int ubo_count;
|
||||
int feedback_count;
|
||||
int vertex_code_start;
|
||||
int fragment_code_start;
|
||||
int attribute_pair_count;
|
||||
|
||||
public:
|
||||
enum AsyncMode {
|
||||
ASYNC_MODE_VISIBLE,
|
||||
ASYNC_MODE_HIDDEN,
|
||||
};
|
||||
|
||||
private:
|
||||
struct CustomCode {
|
||||
String vertex;
|
||||
String vertex_globals;
|
||||
String fragment;
|
||||
String fragment_globals;
|
||||
String light;
|
||||
String uniforms;
|
||||
AsyncMode async_mode;
|
||||
uint32_t version;
|
||||
Vector<StringName> texture_uniforms;
|
||||
Vector<CharString> custom_defines;
|
||||
Set<uint32_t> versions;
|
||||
};
|
||||
|
||||
public:
|
||||
static ShaderCacheGLES3 *shader_cache;
|
||||
static ThreadedCallableQueue<GLuint> *cache_write_queue;
|
||||
|
||||
static ThreadedCallableQueue<GLuint> *compile_queue; // Non-null if using queued asynchronous compilation (via secondary context)
|
||||
static bool parallel_compile_supported; // True if using natively supported asyncrhonous compilation
|
||||
|
||||
static bool async_hidden_forbidden;
|
||||
static int *compiles_started_this_frame;
|
||||
static int max_simultaneous_compiles;
|
||||
#ifdef DEBUG_ENABLED
|
||||
static bool log_active_async_compiles_count;
|
||||
#endif
|
||||
static uint64_t current_frame;
|
||||
|
||||
static void advance_async_shaders_compilation();
|
||||
|
||||
private:
|
||||
static int active_compiles_count;
|
||||
|
||||
union VersionKey {
|
||||
static const uint32_t UBERSHADER_FLAG = ((uint32_t)1) << 31;
|
||||
struct {
|
||||
uint32_t version;
|
||||
uint32_t code_version;
|
||||
};
|
||||
uint64_t key;
|
||||
bool operator==(const VersionKey &p_key) const { return key == p_key.key; }
|
||||
bool operator<(const VersionKey &p_key) const { return key < p_key.key; }
|
||||
VersionKey() {}
|
||||
VersionKey(uint64_t p_key) :
|
||||
key(p_key) {}
|
||||
_FORCE_INLINE_ bool is_subject_to_caching() const { return (version & UBERSHADER_FLAG); }
|
||||
};
|
||||
|
||||
struct Version {
|
||||
VersionKey version_key;
|
||||
|
||||
// Set by the render thread upfront; the compile thread (for queued async.) reads them
|
||||
struct Ids {
|
||||
GLuint main;
|
||||
GLuint vert;
|
||||
GLuint frag;
|
||||
} ids;
|
||||
|
||||
ShaderGLES3 *shader;
|
||||
uint32_t code_version;
|
||||
|
||||
AsyncMode async_mode;
|
||||
GLint *uniform_location;
|
||||
Vector<GLint> texture_uniform_locations;
|
||||
bool uniforms_ready;
|
||||
uint64_t last_frame_processed;
|
||||
|
||||
enum CompileStatus {
|
||||
COMPILE_STATUS_PENDING,
|
||||
COMPILE_STATUS_SOURCE_PROVIDED,
|
||||
COMPILE_STATUS_COMPILING_VERTEX,
|
||||
COMPILE_STATUS_COMPILING_FRAGMENT,
|
||||
COMPILE_STATUS_COMPILING_VERTEX_AND_FRAGMENT,
|
||||
COMPILE_STATUS_PROCESSING_AT_QUEUE,
|
||||
COMPILE_STATUS_BINARY_READY,
|
||||
COMPILE_STATUS_BINARY_READY_FROM_CACHE,
|
||||
COMPILE_STATUS_LINKING,
|
||||
COMPILE_STATUS_ERROR,
|
||||
COMPILE_STATUS_RESTART_NEEDED,
|
||||
COMPILE_STATUS_OK,
|
||||
};
|
||||
CompileStatus compile_status;
|
||||
SelfList<Version> compiling_list;
|
||||
|
||||
struct ProgramBinary {
|
||||
String cache_hash;
|
||||
enum Source {
|
||||
SOURCE_NONE,
|
||||
SOURCE_LOCAL, // Binary data will only be available if cache enabled
|
||||
SOURCE_QUEUE,
|
||||
SOURCE_CACHE,
|
||||
} source;
|
||||
// Shared with the compile thread (for queued async.); otherwise render thread only
|
||||
GLenum format;
|
||||
PoolByteArray data;
|
||||
SafeNumeric<int> result_from_queue;
|
||||
} program_binary;
|
||||
|
||||
Version() :
|
||||
version_key(0),
|
||||
ids(),
|
||||
shader(nullptr),
|
||||
code_version(0),
|
||||
async_mode(ASYNC_MODE_VISIBLE),
|
||||
uniform_location(nullptr),
|
||||
uniforms_ready(false),
|
||||
last_frame_processed(UINT64_MAX),
|
||||
compile_status(COMPILE_STATUS_PENDING),
|
||||
compiling_list(this),
|
||||
program_binary() {}
|
||||
};
|
||||
static SelfList<Version>::List versions_compiling;
|
||||
|
||||
Version *version;
|
||||
|
||||
struct VersionKeyHash {
|
||||
static _FORCE_INLINE_ uint32_t hash(const VersionKey &p_key) { return HashMapHasherDefault::hash(p_key.key); };
|
||||
};
|
||||
|
||||
//this should use a way more cachefriendly version..
|
||||
HashMap<VersionKey, Version, VersionKeyHash> version_map;
|
||||
|
||||
HashMap<uint32_t, CustomCode> custom_code_map;
|
||||
uint32_t last_custom_code;
|
||||
|
||||
VersionKey conditional_version;
|
||||
VersionKey new_conditional_version;
|
||||
|
||||
virtual String get_shader_name() const = 0;
|
||||
|
||||
const char **conditional_defines;
|
||||
const char **uniform_names;
|
||||
const AttributePair *attribute_pairs;
|
||||
const TexUnitPair *texunit_pairs;
|
||||
const UBOPair *ubo_pairs;
|
||||
const Feedback *feedbacks;
|
||||
const char *vertex_code;
|
||||
const char *fragment_code;
|
||||
CharString fragment_code0;
|
||||
CharString fragment_code1;
|
||||
CharString fragment_code2;
|
||||
CharString fragment_code3;
|
||||
CharString fragment_code4;
|
||||
|
||||
CharString vertex_code0;
|
||||
CharString vertex_code1;
|
||||
CharString vertex_code2;
|
||||
CharString vertex_code3;
|
||||
|
||||
Vector<CharString> custom_defines;
|
||||
|
||||
int base_material_tex_index;
|
||||
|
||||
Version *get_current_version(bool &r_async_forbidden);
|
||||
// These will run on the shader compile thread if using que compile queue approach to async.
|
||||
void _set_source(Version::Ids p_ids, const LocalVector<const char *> &p_vertex_strings, const LocalVector<const char *> &p_fragment_strings) const;
|
||||
bool _complete_compile(Version::Ids p_ids, bool p_retrievable) const;
|
||||
bool _complete_link(Version::Ids p_ids, GLenum *r_program_format = nullptr, PoolByteArray *r_program_binary = nullptr) const;
|
||||
// ---
|
||||
static void _log_active_compiles();
|
||||
static bool _process_program_state(Version *p_version, bool p_async_forbidden);
|
||||
void _setup_uniforms(CustomCode *p_cc) const;
|
||||
void _dispose_program(Version *p_version);
|
||||
|
||||
static ShaderGLES3 *active;
|
||||
|
||||
int max_image_units;
|
||||
|
||||
_FORCE_INLINE_ void _set_uniform_variant(GLint p_uniform, const Variant &p_value) {
|
||||
if (p_uniform < 0) {
|
||||
return; // do none
|
||||
}
|
||||
switch (p_value.get_type()) {
|
||||
case Variant::BOOL:
|
||||
case Variant::INT: {
|
||||
int val = p_value;
|
||||
glUniform1i(p_uniform, val);
|
||||
} break;
|
||||
case Variant::REAL: {
|
||||
real_t val = p_value;
|
||||
glUniform1f(p_uniform, val);
|
||||
} break;
|
||||
case Variant::COLOR: {
|
||||
Color val = p_value;
|
||||
glUniform4f(p_uniform, val.r, val.g, val.b, val.a);
|
||||
} break;
|
||||
case Variant::VECTOR2: {
|
||||
Vector2 val = p_value;
|
||||
glUniform2f(p_uniform, val.x, val.y);
|
||||
} break;
|
||||
case Variant::VECTOR3: {
|
||||
Vector3 val = p_value;
|
||||
glUniform3f(p_uniform, val.x, val.y, val.z);
|
||||
} break;
|
||||
case Variant::PLANE: {
|
||||
Plane val = p_value;
|
||||
glUniform4f(p_uniform, val.normal.x, val.normal.y, val.normal.z, val.d);
|
||||
} break;
|
||||
case Variant::QUAT: {
|
||||
Quat val = p_value;
|
||||
glUniform4f(p_uniform, val.x, val.y, val.z, val.w);
|
||||
} break;
|
||||
|
||||
case Variant::TRANSFORM2D: {
|
||||
Transform2D tr = p_value;
|
||||
GLfloat matrix[16] = { /* build a 16x16 matrix */
|
||||
tr.elements[0][0],
|
||||
tr.elements[0][1],
|
||||
0,
|
||||
0,
|
||||
tr.elements[1][0],
|
||||
tr.elements[1][1],
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
tr.elements[2][0],
|
||||
tr.elements[2][1],
|
||||
0,
|
||||
1
|
||||
};
|
||||
|
||||
glUniformMatrix4fv(p_uniform, 1, false, matrix);
|
||||
|
||||
} break;
|
||||
case Variant::BASIS:
|
||||
case Variant::TRANSFORM: {
|
||||
Transform tr = p_value;
|
||||
GLfloat matrix[16] = { /* build a 16x16 matrix */
|
||||
tr.basis.elements[0][0],
|
||||
tr.basis.elements[1][0],
|
||||
tr.basis.elements[2][0],
|
||||
0,
|
||||
tr.basis.elements[0][1],
|
||||
tr.basis.elements[1][1],
|
||||
tr.basis.elements[2][1],
|
||||
0,
|
||||
tr.basis.elements[0][2],
|
||||
tr.basis.elements[1][2],
|
||||
tr.basis.elements[2][2],
|
||||
0,
|
||||
tr.origin.x,
|
||||
tr.origin.y,
|
||||
tr.origin.z,
|
||||
1
|
||||
};
|
||||
|
||||
glUniformMatrix4fv(p_uniform, 1, false, matrix);
|
||||
} break;
|
||||
default: {
|
||||
ERR_FAIL();
|
||||
} // do nothing
|
||||
}
|
||||
}
|
||||
|
||||
bool _bind(bool p_binding_fallback);
|
||||
bool _bind_ubershader();
|
||||
|
||||
protected:
|
||||
_FORCE_INLINE_ int _get_uniform(int p_which) const;
|
||||
_FORCE_INLINE_ void _set_conditional(int p_which, bool p_value);
|
||||
|
||||
void setup(const char **p_conditional_defines, int p_conditional_count, const char **p_uniform_names, int p_uniform_count, const AttributePair *p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count, const UBOPair *p_ubo_pairs, int p_ubo_pair_count, const Feedback *p_feedback, int p_feedback_count, const char *p_vertex_code, const char *p_fragment_code, int p_vertex_code_start, int p_fragment_code_start);
|
||||
|
||||
ShaderGLES3();
|
||||
|
||||
public:
|
||||
enum {
|
||||
CUSTOM_SHADER_DISABLED = 0
|
||||
};
|
||||
|
||||
GLint get_uniform_location(const String &p_name) const;
|
||||
GLint get_uniform_location(int p_index) const;
|
||||
|
||||
static _FORCE_INLINE_ ShaderGLES3 *get_active() { return active; };
|
||||
bool bind();
|
||||
void unbind();
|
||||
|
||||
void clear_caches();
|
||||
|
||||
uint32_t create_custom_shader();
|
||||
void set_custom_shader_code(uint32_t p_code_id, const String &p_vertex, const String &p_vertex_globals, const String &p_fragment, const String &p_light, const String &p_fragment_globals, const String &p_uniforms, const Vector<StringName> &p_texture_uniforms, const Vector<CharString> &p_custom_defines, AsyncMode p_async_mode);
|
||||
void set_custom_shader(uint32_t p_code_id);
|
||||
void free_custom_shader(uint32_t p_code_id);
|
||||
|
||||
uint32_t get_version() const { return new_conditional_version.version; }
|
||||
bool is_version_ubershader() const { return (new_conditional_version.version & VersionKey::UBERSHADER_FLAG); }
|
||||
_FORCE_INLINE_ bool is_version_valid() const { return version && version->compile_status == Version::COMPILE_STATUS_OK; }
|
||||
|
||||
virtual void init() = 0;
|
||||
void init_async_compilation();
|
||||
bool is_async_compilation_supported();
|
||||
void finish();
|
||||
|
||||
void set_base_material_tex_index(int p_idx);
|
||||
|
||||
void add_custom_define(const String &p_define) {
|
||||
custom_defines.push_back(p_define.utf8());
|
||||
}
|
||||
|
||||
void get_custom_defines(Vector<String> *p_defines) {
|
||||
for (int i = 0; i < custom_defines.size(); i++) {
|
||||
p_defines->push_back(custom_defines[i].get_data());
|
||||
}
|
||||
}
|
||||
|
||||
void remove_custom_define(const String &p_define) {
|
||||
custom_defines.erase(p_define.utf8());
|
||||
}
|
||||
|
||||
virtual ~ShaderGLES3();
|
||||
};
|
||||
|
||||
// called a lot, made inline
|
||||
|
||||
int ShaderGLES3::_get_uniform(int p_which) const {
|
||||
ERR_FAIL_INDEX_V(p_which, uniform_count, -1);
|
||||
ERR_FAIL_COND_V(!version, -1);
|
||||
return version->uniform_location[p_which];
|
||||
}
|
||||
|
||||
void ShaderGLES3::_set_conditional(int p_which, bool p_value) {
|
||||
ERR_FAIL_INDEX(p_which, conditional_count);
|
||||
if (p_value) {
|
||||
new_conditional_version.version |= (1 << p_which);
|
||||
} else {
|
||||
new_conditional_version.version &= ~(1 << p_which);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,23 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
|
||||
if "GLES3_GLSL" in env["BUILDERS"]:
|
||||
env.GLES3_GLSL("copy.glsl")
|
||||
env.GLES3_GLSL("resolve.glsl")
|
||||
env.GLES3_GLSL("canvas.glsl")
|
||||
env.GLES3_GLSL("canvas_shadow.glsl")
|
||||
env.GLES3_GLSL("scene.glsl")
|
||||
env.GLES3_GLSL("cubemap_filter.glsl")
|
||||
env.GLES3_GLSL("cube_to_dp.glsl")
|
||||
env.GLES3_GLSL("blend_shape.glsl")
|
||||
env.GLES3_GLSL("screen_space_reflection.glsl")
|
||||
env.GLES3_GLSL("effect_blur.glsl")
|
||||
env.GLES3_GLSL("subsurf_scattering.glsl")
|
||||
env.GLES3_GLSL("ssao.glsl")
|
||||
env.GLES3_GLSL("ssao_minify.glsl")
|
||||
env.GLES3_GLSL("ssao_blur.glsl")
|
||||
env.GLES3_GLSL("exposure.glsl")
|
||||
env.GLES3_GLSL("tonemap.glsl")
|
||||
env.GLES3_GLSL("particles.glsl")
|
||||
env.GLES3_GLSL("lens_distorted.glsl")
|
@ -1,226 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
/*
|
||||
from VisualServer:
|
||||
|
||||
ARRAY_VERTEX=0,
|
||||
ARRAY_NORMAL=1,
|
||||
ARRAY_TANGENT=2,
|
||||
ARRAY_COLOR=3,
|
||||
ARRAY_TEX_UV=4,
|
||||
ARRAY_TEX_UV2=5,
|
||||
ARRAY_BONES=6,
|
||||
ARRAY_WEIGHTS=7,
|
||||
ARRAY_INDEX=8,
|
||||
*/
|
||||
|
||||
#ifdef USE_2D_VERTEX
|
||||
#define VFORMAT vec2
|
||||
#else
|
||||
#define VFORMAT vec3
|
||||
#endif
|
||||
|
||||
/* INPUT ATTRIBS */
|
||||
|
||||
layout(location = 0) in highp VFORMAT vertex_attrib;
|
||||
/* clang-format on */
|
||||
#ifdef ENABLE_OCTAHEDRAL_COMPRESSION
|
||||
layout(location = 2) in vec4 normal_tangent_attrib;
|
||||
#else
|
||||
layout(location = 1) in vec3 normal_attrib;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_TANGENT
|
||||
#ifdef ENABLE_OCTAHEDRAL_COMPRESSION
|
||||
// packed into normal_attrib zw component
|
||||
#else
|
||||
layout(location = 2) in vec4 tangent_attrib;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
layout(location = 3) in vec4 color_attrib;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_UV
|
||||
layout(location = 4) in vec2 uv_attrib;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_UV2
|
||||
layout(location = 5) in vec2 uv2_attrib;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_SKELETON
|
||||
layout(location = 6) in ivec4 bone_attrib;
|
||||
layout(location = 7) in vec4 weight_attrib;
|
||||
#endif
|
||||
|
||||
/* BLEND ATTRIBS */
|
||||
|
||||
#ifdef ENABLE_BLEND
|
||||
|
||||
layout(location = 8) in highp VFORMAT vertex_attrib_blend;
|
||||
layout(location = 9) in vec3 normal_attrib_blend;
|
||||
|
||||
#ifdef ENABLE_TANGENT
|
||||
layout(location = 10) in vec4 tangent_attrib_blend;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
layout(location = 11) in vec4 color_attrib_blend;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_UV
|
||||
layout(location = 12) in vec2 uv_attrib_blend;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_UV2
|
||||
layout(location = 13) in vec2 uv2_attrib_blend;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_SKELETON
|
||||
layout(location = 14) in ivec4 bone_attrib_blend;
|
||||
layout(location = 15) in vec4 weight_attrib_blend;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* OUTPUTS */
|
||||
|
||||
out VFORMAT vertex_out; //tfb:
|
||||
|
||||
#ifdef ENABLE_NORMAL
|
||||
out vec3 normal_out; //tfb:ENABLE_NORMAL
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_TANGENT
|
||||
out vec4 tangent_out; //tfb:ENABLE_TANGENT
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
out vec4 color_out; //tfb:ENABLE_COLOR
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_UV
|
||||
out vec2 uv_out; //tfb:ENABLE_UV
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_UV2
|
||||
out vec2 uv2_out; //tfb:ENABLE_UV2
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_SKELETON
|
||||
out ivec4 bone_out; //tfb:ENABLE_SKELETON
|
||||
out vec4 weight_out; //tfb:ENABLE_SKELETON
|
||||
#endif
|
||||
|
||||
uniform float blend_amount;
|
||||
|
||||
#ifdef ENABLE_OCTAHEDRAL_COMPRESSION
|
||||
vec3 oct_to_vec3(vec2 e) {
|
||||
vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));
|
||||
float t = max(-v.z, 0.0);
|
||||
v.xy += t * -sign(v.xy);
|
||||
return normalize(v);
|
||||
}
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#ifdef ENABLE_BLEND
|
||||
|
||||
vertex_out = vertex_attrib_blend + vertex_attrib * blend_amount;
|
||||
|
||||
#ifdef ENABLE_NORMAL
|
||||
#ifdef ENABLE_OCTAHEDRAL_COMPRESSION
|
||||
normal_out = normal_attrib_blend + oct_to_vec3(normal_tangent_attrib.xy) * blend_amount;
|
||||
#else
|
||||
normal_out = normal_attrib_blend + normal_attrib * blend_amount;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_TANGENT
|
||||
#ifdef ENABLE_OCTAHEDRAL_COMPRESSION
|
||||
tangent_out.xyz = tangent_attrib_blend.xyz + oct_to_vec3(vec2(normal_tangent_attrib.z, abs(normal_tangent_attrib.w) * 2.0 - 1.0)) * blend_amount;
|
||||
tangent_out.w = sign(tangent_attrib_blend.w);
|
||||
#else
|
||||
tangent_out.xyz = tangent_attrib_blend.xyz + tangent_attrib.xyz * blend_amount;
|
||||
tangent_out.w = tangent_attrib_blend.w; //just copy, no point in blending his
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
|
||||
color_out = color_attrib_blend + color_attrib * blend_amount;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_UV
|
||||
|
||||
uv_out = uv_attrib_blend + uv_attrib * blend_amount;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_UV2
|
||||
|
||||
uv2_out = uv2_attrib_blend + uv2_attrib * blend_amount;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_SKELETON
|
||||
|
||||
bone_out = bone_attrib_blend;
|
||||
weight_out = weight_attrib_blend + weight_attrib * blend_amount;
|
||||
#endif
|
||||
|
||||
#else //ENABLE_BLEND
|
||||
|
||||
vertex_out = vertex_attrib * blend_amount;
|
||||
|
||||
#ifdef ENABLE_NORMAL
|
||||
#ifdef ENABLE_OCTAHEDRAL_COMPRESSION
|
||||
normal_out = oct_to_vec3(normal_tangent_attrib.xy) * blend_amount;
|
||||
#else
|
||||
normal_out = normal_attrib * blend_amount;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_TANGENT
|
||||
#ifdef ENABLE_OCTAHEDRAL_COMPRESSION
|
||||
tangent_out.xyz = oct_to_vec3(vec2(normal_tangent_attrib.z, abs(normal_tangent_attrib.w) * 2.0 - 1.0)) * blend_amount;
|
||||
tangent_out.w = sign(normal_tangent_attrib.w);
|
||||
#else
|
||||
tangent_out.xyz = tangent_attrib.xyz * blend_amount;
|
||||
tangent_out.w = tangent_attrib.w; //just copy, no point in blending his
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
|
||||
color_out = color_attrib * blend_amount;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_UV
|
||||
|
||||
uv_out = uv_attrib * blend_amount;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_UV2
|
||||
|
||||
uv2_out = uv2_attrib * blend_amount;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_SKELETON
|
||||
|
||||
bone_out = bone_attrib;
|
||||
weight_out = weight_attrib * blend_amount;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
gl_Position = vec4(0.0);
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
void main() {
|
||||
|
||||
}
|
||||
/* clang-format on */
|
@ -1,867 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec2 vertex;
|
||||
|
||||
#ifdef USE_ATTRIB_LIGHT_ANGLE
|
||||
layout(location = 2) in highp float light_angle;
|
||||
#endif
|
||||
|
||||
/* clang-format on */
|
||||
layout(location = 3) in vec4 color_attrib;
|
||||
|
||||
#ifdef USE_ATTRIB_MODULATE
|
||||
layout(location = 5) in vec4 modulate_attrib; // attrib:5
|
||||
#endif
|
||||
|
||||
// Usually, final_modulate is passed as a uniform. However during batching
|
||||
// If larger fvfs are used, final_modulate is passed as an attribute.
|
||||
// we need to read from the attribute in custom vertex shader
|
||||
// rather than the uniform. We do this by specifying final_modulate_alias
|
||||
// in shaders rather than final_modulate directly.
|
||||
#ifdef USE_ATTRIB_MODULATE
|
||||
#define final_modulate_alias modulate_attrib
|
||||
#else
|
||||
#define final_modulate_alias final_modulate
|
||||
#endif
|
||||
|
||||
#ifdef USE_ATTRIB_LARGE_VERTEX
|
||||
// shared with skeleton attributes, not used in batched shader
|
||||
layout(location = 6) in vec2 translate_attrib; // attrib:6
|
||||
layout(location = 7) in vec4 basis_attrib; // attrib:7
|
||||
#endif
|
||||
|
||||
#ifdef USE_SKELETON
|
||||
layout(location = 6) in uvec4 bone_indices; // attrib:6
|
||||
layout(location = 7) in vec4 bone_weights; // attrib:7
|
||||
#endif
|
||||
|
||||
#ifdef USE_TEXTURE_RECT
|
||||
|
||||
uniform vec4 dst_rect;
|
||||
uniform vec4 src_rect;
|
||||
|
||||
#else
|
||||
|
||||
#ifdef USE_INSTANCING
|
||||
|
||||
layout(location = 8) in highp vec4 instance_xform0;
|
||||
layout(location = 9) in highp vec4 instance_xform1;
|
||||
layout(location = 10) in highp vec4 instance_xform2;
|
||||
layout(location = 11) in lowp vec4 instance_color;
|
||||
|
||||
#ifdef USE_INSTANCE_CUSTOM
|
||||
layout(location = 12) in highp vec4 instance_custom_data;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
layout(location = 4) in highp vec2 uv_attrib;
|
||||
|
||||
// skeleton
|
||||
#endif
|
||||
|
||||
uniform highp vec2 color_texpixel_size;
|
||||
|
||||
layout(std140) uniform CanvasItemData { //ubo:0
|
||||
|
||||
highp mat4 projection_matrix;
|
||||
highp float time;
|
||||
};
|
||||
|
||||
uniform highp mat4 modelview_matrix;
|
||||
uniform highp mat4 extra_matrix;
|
||||
|
||||
out highp vec2 uv_interp;
|
||||
out mediump vec4 color_interp;
|
||||
|
||||
#ifdef USE_ATTRIB_MODULATE
|
||||
// modulate doesn't need interpolating but we need to send it to the fragment shader
|
||||
flat out mediump vec4 modulate_interp;
|
||||
#endif
|
||||
|
||||
#ifdef MODULATE_USED
|
||||
uniform mediump vec4 final_modulate;
|
||||
#endif
|
||||
|
||||
#ifdef USE_NINEPATCH
|
||||
|
||||
out highp vec2 pixel_size_interp;
|
||||
#endif
|
||||
|
||||
#ifdef USE_SKELETON
|
||||
uniform mediump sampler2D skeleton_texture; // texunit:-4
|
||||
uniform highp mat4 skeleton_transform;
|
||||
uniform highp mat4 skeleton_transform_inverse;
|
||||
#endif
|
||||
|
||||
#ifdef USE_LIGHTING
|
||||
|
||||
layout(std140) uniform LightData { //ubo:1
|
||||
|
||||
// light matrices
|
||||
highp mat4 light_matrix;
|
||||
highp mat4 light_local_matrix;
|
||||
highp mat4 shadow_matrix;
|
||||
highp vec4 light_color;
|
||||
highp vec4 light_shadow_color;
|
||||
highp vec2 light_pos;
|
||||
highp float shadowpixel_size;
|
||||
highp float shadow_gradient;
|
||||
highp float light_height;
|
||||
highp float light_outside_alpha;
|
||||
highp float shadow_distance_mult;
|
||||
};
|
||||
|
||||
out vec4 light_uv_interp;
|
||||
out vec2 transformed_light_uv;
|
||||
|
||||
out vec4 local_rot;
|
||||
|
||||
#ifdef USE_SHADOWS
|
||||
out highp vec2 pos;
|
||||
#endif
|
||||
|
||||
const bool at_light_pass = true;
|
||||
#else
|
||||
const bool at_light_pass = false;
|
||||
#endif
|
||||
|
||||
#if defined(USE_MATERIAL)
|
||||
|
||||
/* clang-format off */
|
||||
layout(std140) uniform UniformData { //ubo:2
|
||||
|
||||
MATERIAL_UNIFORMS
|
||||
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
VERTEX_SHADER_GLOBALS
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
void main() {
|
||||
vec4 color = color_attrib;
|
||||
|
||||
#ifdef USE_INSTANCING
|
||||
mat4 extra_matrix_instance = extra_matrix * transpose(mat4(instance_xform0, instance_xform1, instance_xform2, vec4(0.0, 0.0, 0.0, 1.0)));
|
||||
color *= instance_color;
|
||||
|
||||
#ifdef USE_INSTANCE_CUSTOM
|
||||
vec4 instance_custom = instance_custom_data;
|
||||
#else
|
||||
vec4 instance_custom = vec4(0.0);
|
||||
#endif
|
||||
|
||||
#else
|
||||
mat4 extra_matrix_instance = extra_matrix;
|
||||
vec4 instance_custom = vec4(0.0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_TEXTURE_RECT
|
||||
|
||||
if (dst_rect.z < 0.0) { // Transpose is encoded as negative dst_rect.z
|
||||
uv_interp = src_rect.xy + abs(src_rect.zw) * vertex.yx;
|
||||
} else {
|
||||
uv_interp = src_rect.xy + abs(src_rect.zw) * vertex;
|
||||
}
|
||||
highp vec4 outvec = vec4(dst_rect.xy + abs(dst_rect.zw) * mix(vertex, vec2(1.0, 1.0) - vertex, lessThan(src_rect.zw, vec2(0.0, 0.0))), 0.0, 1.0);
|
||||
|
||||
#else
|
||||
uv_interp = uv_attrib;
|
||||
highp vec4 outvec = vec4(vertex, 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_PARTICLES
|
||||
//scale by texture size
|
||||
outvec.xy /= color_texpixel_size;
|
||||
#endif
|
||||
|
||||
#define extra_matrix extra_matrix_instance
|
||||
|
||||
float point_size = 1.0;
|
||||
//for compatibility with the fragment shader we need to use uv here
|
||||
vec2 uv = uv_interp;
|
||||
{
|
||||
/* clang-format off */
|
||||
|
||||
VERTEX_SHADER_CODE
|
||||
|
||||
/* clang-format on */
|
||||
}
|
||||
|
||||
gl_PointSize = point_size;
|
||||
uv_interp = uv;
|
||||
|
||||
#ifdef USE_NINEPATCH
|
||||
|
||||
pixel_size_interp = abs(dst_rect.zw) * vertex;
|
||||
#endif
|
||||
|
||||
#ifdef USE_ATTRIB_MODULATE
|
||||
// modulate doesn't need interpolating but we need to send it to the fragment shader
|
||||
modulate_interp = modulate_attrib;
|
||||
#endif
|
||||
|
||||
#ifdef USE_ATTRIB_LARGE_VERTEX
|
||||
// transform is in attributes
|
||||
vec2 temp;
|
||||
|
||||
temp = outvec.xy;
|
||||
temp.x = (outvec.x * basis_attrib.x) + (outvec.y * basis_attrib.z);
|
||||
temp.y = (outvec.x * basis_attrib.y) + (outvec.y * basis_attrib.w);
|
||||
|
||||
temp += translate_attrib;
|
||||
outvec.xy = temp;
|
||||
|
||||
#else
|
||||
|
||||
// transform is in uniforms
|
||||
#if !defined(SKIP_TRANSFORM_USED)
|
||||
outvec = extra_matrix * outvec;
|
||||
outvec = modelview_matrix * outvec;
|
||||
#endif
|
||||
|
||||
#endif // not large integer
|
||||
|
||||
#undef extra_matrix
|
||||
|
||||
color_interp = color;
|
||||
|
||||
#ifdef USE_PIXEL_SNAP
|
||||
outvec.xy = floor(outvec + 0.5).xy;
|
||||
// precision issue on some hardware creates artifacts within texture
|
||||
// offset uv by a small amount to avoid
|
||||
uv_interp += 1e-5;
|
||||
#endif
|
||||
|
||||
#ifdef USE_SKELETON
|
||||
|
||||
if (bone_weights != vec4(0.0)) { //must be a valid bone
|
||||
//skeleton transform
|
||||
|
||||
ivec4 bone_indicesi = ivec4(bone_indices);
|
||||
|
||||
ivec2 tex_ofs = ivec2(bone_indicesi.x % 256, (bone_indicesi.x / 256) * 2);
|
||||
|
||||
highp mat2x4 m;
|
||||
m = mat2x4(
|
||||
texelFetch(skeleton_texture, tex_ofs, 0),
|
||||
texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0)) *
|
||||
bone_weights.x;
|
||||
|
||||
tex_ofs = ivec2(bone_indicesi.y % 256, (bone_indicesi.y / 256) * 2);
|
||||
|
||||
m += mat2x4(
|
||||
texelFetch(skeleton_texture, tex_ofs, 0),
|
||||
texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0)) *
|
||||
bone_weights.y;
|
||||
|
||||
tex_ofs = ivec2(bone_indicesi.z % 256, (bone_indicesi.z / 256) * 2);
|
||||
|
||||
m += mat2x4(
|
||||
texelFetch(skeleton_texture, tex_ofs, 0),
|
||||
texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0)) *
|
||||
bone_weights.z;
|
||||
|
||||
tex_ofs = ivec2(bone_indicesi.w % 256, (bone_indicesi.w / 256) * 2);
|
||||
|
||||
m += mat2x4(
|
||||
texelFetch(skeleton_texture, tex_ofs, 0),
|
||||
texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0)) *
|
||||
bone_weights.w;
|
||||
|
||||
mat4 bone_matrix = skeleton_transform * transpose(mat4(m[0], m[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))) * skeleton_transform_inverse;
|
||||
|
||||
outvec = bone_matrix * outvec;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
gl_Position = projection_matrix * outvec;
|
||||
|
||||
#ifdef USE_LIGHTING
|
||||
|
||||
light_uv_interp.xy = (light_matrix * outvec).xy;
|
||||
light_uv_interp.zw = (light_local_matrix * outvec).xy;
|
||||
|
||||
mat3 inverse_light_matrix = mat3(inverse(light_matrix));
|
||||
inverse_light_matrix[0] = normalize(inverse_light_matrix[0]);
|
||||
inverse_light_matrix[1] = normalize(inverse_light_matrix[1]);
|
||||
inverse_light_matrix[2] = normalize(inverse_light_matrix[2]);
|
||||
transformed_light_uv = (inverse_light_matrix * vec3(light_uv_interp.zw, 0.0)).xy; //for normal mapping
|
||||
|
||||
#ifdef USE_SHADOWS
|
||||
pos = outvec.xy;
|
||||
#endif
|
||||
|
||||
#ifdef USE_ATTRIB_LIGHT_ANGLE
|
||||
// we add a fixed offset because we are using the sign later,
|
||||
// and don't want floating point error around 0.0
|
||||
float la = abs(light_angle) - 1.0;
|
||||
|
||||
// vector light angle
|
||||
vec4 vla;
|
||||
vla.xy = vec2(cos(la), sin(la));
|
||||
vla.zw = vec2(-vla.y, vla.x);
|
||||
vla.zw *= sign(light_angle);
|
||||
|
||||
// apply the transform matrix.
|
||||
// The rotate will be encoded in the transform matrix for single rects,
|
||||
// and just the flips in the light angle.
|
||||
// For batching we will encode the rotation and the flips
|
||||
// in the light angle, and can use the same shader.
|
||||
local_rot.xy = normalize((modelview_matrix * (extra_matrix_instance * vec4(vla.xy, 0.0, 0.0))).xy);
|
||||
local_rot.zw = normalize((modelview_matrix * (extra_matrix_instance * vec4(vla.zw, 0.0, 0.0))).xy);
|
||||
#else
|
||||
local_rot.xy = normalize((modelview_matrix * (extra_matrix_instance * vec4(1.0, 0.0, 0.0, 0.0))).xy);
|
||||
local_rot.zw = normalize((modelview_matrix * (extra_matrix_instance * vec4(0.0, 1.0, 0.0, 0.0))).xy);
|
||||
#ifdef USE_TEXTURE_RECT
|
||||
local_rot.xy *= sign(src_rect.z);
|
||||
local_rot.zw *= sign(src_rect.w);
|
||||
#endif
|
||||
#endif // not using light angle
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
uniform mediump sampler2D color_texture; // texunit:0
|
||||
/* clang-format on */
|
||||
uniform highp vec2 color_texpixel_size;
|
||||
uniform mediump sampler2D normal_texture; // texunit:1
|
||||
|
||||
in highp vec2 uv_interp;
|
||||
in mediump vec4 color_interp;
|
||||
|
||||
#ifdef USE_ATTRIB_MODULATE
|
||||
flat in mediump vec4 modulate_interp;
|
||||
#endif
|
||||
|
||||
#if defined(SCREEN_TEXTURE_USED)
|
||||
|
||||
uniform sampler2D screen_texture; // texunit:-3
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(SCREEN_UV_USED)
|
||||
|
||||
uniform vec2 screen_pixel_size;
|
||||
#endif
|
||||
|
||||
layout(std140) uniform CanvasItemData {
|
||||
highp mat4 projection_matrix;
|
||||
highp float time;
|
||||
};
|
||||
|
||||
#ifdef USE_LIGHTING
|
||||
|
||||
layout(std140) uniform LightData {
|
||||
highp mat4 light_matrix;
|
||||
highp mat4 light_local_matrix;
|
||||
highp mat4 shadow_matrix;
|
||||
highp vec4 light_color;
|
||||
highp vec4 light_shadow_color;
|
||||
highp vec2 light_pos;
|
||||
highp float shadowpixel_size;
|
||||
highp float shadow_gradient;
|
||||
highp float light_height;
|
||||
highp float light_outside_alpha;
|
||||
highp float shadow_distance_mult;
|
||||
};
|
||||
|
||||
uniform lowp sampler2D light_texture; // texunit:-1
|
||||
in vec4 light_uv_interp;
|
||||
in vec2 transformed_light_uv;
|
||||
|
||||
in vec4 local_rot;
|
||||
|
||||
#ifdef USE_SHADOWS
|
||||
|
||||
uniform highp sampler2D shadow_texture; // texunit:-2
|
||||
in highp vec2 pos;
|
||||
|
||||
#endif
|
||||
|
||||
const bool at_light_pass = true;
|
||||
#else
|
||||
const bool at_light_pass = false;
|
||||
#endif
|
||||
|
||||
uniform mediump vec4 final_modulate;
|
||||
|
||||
layout(location = 0) out mediump vec4 frag_color;
|
||||
|
||||
#if defined(USE_MATERIAL)
|
||||
|
||||
/* clang-format off */
|
||||
layout(std140) uniform UniformData {
|
||||
|
||||
MATERIAL_UNIFORMS
|
||||
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
FRAGMENT_SHADER_GLOBALS
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
void light_compute(
|
||||
inout vec4 light,
|
||||
inout vec2 light_vec,
|
||||
inout float light_height,
|
||||
inout vec4 light_color,
|
||||
vec2 light_uv,
|
||||
inout vec4 shadow_color,
|
||||
inout vec2 shadow_vec,
|
||||
vec3 normal,
|
||||
vec2 uv,
|
||||
#if defined(SCREEN_UV_USED)
|
||||
vec2 screen_uv,
|
||||
#endif
|
||||
vec4 color) {
|
||||
|
||||
#if defined(USE_LIGHT_SHADER_CODE)
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
LIGHT_SHADER_CODE
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_TEXTURE_RECT
|
||||
|
||||
uniform vec4 dst_rect;
|
||||
uniform vec4 src_rect;
|
||||
uniform bool clip_rect_uv;
|
||||
|
||||
#ifdef USE_NINEPATCH
|
||||
|
||||
in highp vec2 pixel_size_interp;
|
||||
|
||||
uniform int np_repeat_v;
|
||||
uniform int np_repeat_h;
|
||||
uniform bool np_draw_center;
|
||||
// left top right bottom in pixel coordinates
|
||||
uniform vec4 np_margins;
|
||||
|
||||
// there are two ninepatch modes, and we don't want to waste a conditional
|
||||
#if defined USE_NINEPATCH_SCALING
|
||||
float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, float margin_begin, float margin_end, float s_ratio, int np_repeat, inout int draw_center) {
|
||||
float tex_size = 1.0 / tex_pixel_size;
|
||||
|
||||
float screen_margin_begin = margin_begin / s_ratio;
|
||||
float screen_margin_end = margin_end / s_ratio;
|
||||
if (pixel < screen_margin_begin) {
|
||||
return pixel * s_ratio * tex_pixel_size;
|
||||
} else if (pixel >= draw_size - screen_margin_end) {
|
||||
return (tex_size - (draw_size - pixel) * s_ratio) * tex_pixel_size;
|
||||
} else {
|
||||
if (!np_draw_center) {
|
||||
draw_center--;
|
||||
}
|
||||
|
||||
if (np_repeat == 0) { //stretch
|
||||
//convert to ratio
|
||||
float ratio = (pixel - screen_margin_begin) / (draw_size - screen_margin_begin - screen_margin_end);
|
||||
//scale to source texture
|
||||
return (margin_begin + ratio * (tex_size - margin_begin - margin_end)) * tex_pixel_size;
|
||||
} else if (np_repeat == 1) { //tile
|
||||
//convert to ratio
|
||||
float ofs = mod((pixel - screen_margin_begin), tex_size - margin_begin - margin_end);
|
||||
//scale to source texture
|
||||
return (margin_begin + ofs) * tex_pixel_size;
|
||||
} else if (np_repeat == 2) { //tile fit
|
||||
//convert to ratio
|
||||
float src_area = draw_size - screen_margin_begin - screen_margin_end;
|
||||
float dst_area = tex_size - margin_begin - margin_end;
|
||||
float scale = max(1.0, floor(src_area / max(dst_area, 0.0000001) + 0.5));
|
||||
|
||||
//convert to ratio
|
||||
float ratio = (pixel - screen_margin_begin) / src_area;
|
||||
ratio = mod(ratio * scale, 1.0);
|
||||
return (margin_begin + ratio * dst_area) * tex_pixel_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, float margin_begin, float margin_end, int np_repeat, inout int draw_center) {
|
||||
float tex_size = 1.0 / tex_pixel_size;
|
||||
|
||||
if (pixel < margin_begin) {
|
||||
return pixel * tex_pixel_size;
|
||||
} else if (pixel >= draw_size - margin_end) {
|
||||
return (tex_size - (draw_size - pixel)) * tex_pixel_size;
|
||||
} else {
|
||||
if (!np_draw_center) {
|
||||
draw_center--;
|
||||
}
|
||||
|
||||
// np_repeat is passed as uniform using NinePatchRect::AxisStretchMode enum.
|
||||
if (np_repeat == 0) { // Stretch.
|
||||
// Convert to ratio.
|
||||
float ratio = (pixel - margin_begin) / (draw_size - margin_begin - margin_end);
|
||||
// Scale to source texture.
|
||||
return (margin_begin + ratio * (tex_size - margin_begin - margin_end)) * tex_pixel_size;
|
||||
} else if (np_repeat == 1) { // Tile.
|
||||
// Convert to offset.
|
||||
float ofs = mod((pixel - margin_begin), tex_size - margin_begin - margin_end);
|
||||
// Scale to source texture.
|
||||
return (margin_begin + ofs) * tex_pixel_size;
|
||||
} else if (np_repeat == 2) { // Tile Fit.
|
||||
// Calculate scale.
|
||||
float src_area = draw_size - margin_begin - margin_end;
|
||||
float dst_area = tex_size - margin_begin - margin_end;
|
||||
float scale = max(1.0, floor(src_area / max(dst_area, 0.0000001) + 0.5));
|
||||
// Convert to ratio.
|
||||
float ratio = (pixel - margin_begin) / src_area;
|
||||
ratio = mod(ratio * scale, 1.0);
|
||||
// Scale to source texture.
|
||||
return (margin_begin + ratio * dst_area) * tex_pixel_size;
|
||||
} else { // Shouldn't happen, but silences compiler warning.
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uniform bool use_default_normal;
|
||||
|
||||
void main() {
|
||||
vec4 color = color_interp;
|
||||
vec2 uv = uv_interp;
|
||||
|
||||
#ifdef USE_TEXTURE_RECT
|
||||
|
||||
#ifdef USE_NINEPATCH
|
||||
|
||||
int draw_center = 2;
|
||||
#if defined USE_NINEPATCH_SCALING
|
||||
float s_ratio = max((1.0 / color_texpixel_size.x) / abs(dst_rect.z), (1.0 / color_texpixel_size.y) / abs(dst_rect.w));
|
||||
s_ratio = max(1.0, s_ratio);
|
||||
uv = vec2(
|
||||
map_ninepatch_axis(pixel_size_interp.x, abs(dst_rect.z), color_texpixel_size.x, np_margins.x, np_margins.z, s_ratio, np_repeat_h, draw_center),
|
||||
map_ninepatch_axis(pixel_size_interp.y, abs(dst_rect.w), color_texpixel_size.y, np_margins.y, np_margins.w, s_ratio, np_repeat_v, draw_center));
|
||||
|
||||
if (draw_center == 0) {
|
||||
color.a = 0.0;
|
||||
}
|
||||
#else
|
||||
uv = vec2(
|
||||
map_ninepatch_axis(pixel_size_interp.x, abs(dst_rect.z), color_texpixel_size.x, np_margins.x, np_margins.z, np_repeat_h, draw_center),
|
||||
map_ninepatch_axis(pixel_size_interp.y, abs(dst_rect.w), color_texpixel_size.y, np_margins.y, np_margins.w, np_repeat_v, draw_center));
|
||||
|
||||
if (draw_center == 0) {
|
||||
color.a = 0.0;
|
||||
}
|
||||
#endif
|
||||
uv = uv * src_rect.zw + src_rect.xy; //apply region if needed
|
||||
#endif
|
||||
|
||||
if (clip_rect_uv) {
|
||||
uv = clamp(uv, src_rect.xy, src_rect.xy + abs(src_rect.zw));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(COLOR_USED)
|
||||
//default behavior, texture by color
|
||||
|
||||
#ifdef USE_DISTANCE_FIELD
|
||||
const float smoothing = 1.0 / 32.0;
|
||||
float distance = textureLod(color_texture, uv, 0.0).a;
|
||||
color.a = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance) * color.a;
|
||||
#else
|
||||
color *= texture(color_texture, uv);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
vec3 normal;
|
||||
|
||||
#if defined(NORMAL_USED)
|
||||
|
||||
bool normal_used = true;
|
||||
#else
|
||||
bool normal_used = false;
|
||||
#endif
|
||||
|
||||
if (use_default_normal) {
|
||||
normal.xy = textureLod(normal_texture, uv, 0.0).xy * 2.0 - 1.0;
|
||||
normal.z = sqrt(max(0.0, 1.0 - dot(normal.xy, normal.xy)));
|
||||
normal_used = true;
|
||||
} else {
|
||||
normal = vec3(0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
#if defined(SCREEN_UV_USED)
|
||||
vec2 screen_uv = gl_FragCoord.xy * screen_pixel_size;
|
||||
#endif
|
||||
|
||||
{
|
||||
float normal_depth = 1.0;
|
||||
|
||||
#if defined(NORMALMAP_USED)
|
||||
vec3 normal_map = vec3(0.0, 0.0, 1.0);
|
||||
normal_used = true;
|
||||
#endif
|
||||
|
||||
// If larger fvfs are used, final_modulate is passed as an attribute.
|
||||
// we need to read from this in custom fragment shaders or applying in the post step,
|
||||
// rather than using final_modulate directly.
|
||||
#if defined(final_modulate_alias)
|
||||
#undef final_modulate_alias
|
||||
#endif
|
||||
#ifdef USE_ATTRIB_MODULATE
|
||||
#define final_modulate_alias modulate_interp
|
||||
#else
|
||||
#define final_modulate_alias final_modulate
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
FRAGMENT_SHADER_CODE
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
#if defined(NORMALMAP_USED)
|
||||
normal = mix(vec3(0.0, 0.0, 1.0), normal_map * vec3(2.0, -2.0, 1.0) - vec3(1.0, -1.0, 0.0), normal_depth);
|
||||
#endif
|
||||
}
|
||||
#ifdef DEBUG_ENCODED_32
|
||||
highp float enc32 = dot(color, highp vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0));
|
||||
color = vec4(vec3(enc32), 1.0);
|
||||
#endif
|
||||
|
||||
#if !defined(MODULATE_USED)
|
||||
color *= final_modulate_alias;
|
||||
#endif
|
||||
|
||||
#ifdef USE_LIGHTING
|
||||
|
||||
vec2 light_vec = transformed_light_uv;
|
||||
vec2 shadow_vec = transformed_light_uv;
|
||||
|
||||
if (normal_used) {
|
||||
normal.xy = mat2(local_rot.xy, local_rot.zw) * normal.xy;
|
||||
}
|
||||
|
||||
float att = 1.0;
|
||||
|
||||
vec2 light_uv = light_uv_interp.xy;
|
||||
vec4 light = texture(light_texture, light_uv);
|
||||
|
||||
if (any(lessThan(light_uv_interp.xy, vec2(0.0, 0.0))) || any(greaterThanEqual(light_uv_interp.xy, vec2(1.0, 1.0)))) {
|
||||
color.a *= light_outside_alpha; //invisible
|
||||
|
||||
} else {
|
||||
float real_light_height = light_height;
|
||||
vec4 real_light_color = light_color;
|
||||
vec4 real_light_shadow_color = light_shadow_color;
|
||||
|
||||
#if defined(USE_LIGHT_SHADER_CODE)
|
||||
//light is written by the light shader
|
||||
light_compute(
|
||||
light,
|
||||
light_vec,
|
||||
real_light_height,
|
||||
real_light_color,
|
||||
light_uv,
|
||||
real_light_shadow_color,
|
||||
shadow_vec,
|
||||
normal,
|
||||
uv,
|
||||
#if defined(SCREEN_UV_USED)
|
||||
screen_uv,
|
||||
#endif
|
||||
color);
|
||||
#endif
|
||||
|
||||
light *= real_light_color;
|
||||
|
||||
if (normal_used) {
|
||||
vec3 light_normal = normalize(vec3(light_vec, -real_light_height));
|
||||
light *= max(dot(-light_normal, normal), 0.0);
|
||||
}
|
||||
|
||||
color *= light;
|
||||
|
||||
#ifdef USE_SHADOWS
|
||||
#ifdef SHADOW_VEC_USED
|
||||
mat3 inverse_light_matrix = mat3(light_matrix);
|
||||
inverse_light_matrix[0] = normalize(inverse_light_matrix[0]);
|
||||
inverse_light_matrix[1] = normalize(inverse_light_matrix[1]);
|
||||
inverse_light_matrix[2] = normalize(inverse_light_matrix[2]);
|
||||
shadow_vec = (mat3(inverse_light_matrix) * vec3(shadow_vec, 0.0)).xy;
|
||||
#else
|
||||
shadow_vec = light_uv_interp.zw;
|
||||
#endif
|
||||
float angle_to_light = -atan(shadow_vec.x, shadow_vec.y);
|
||||
float PI = 3.14159265358979323846264;
|
||||
/*int i = int(mod(floor((angle_to_light+7.0*PI/6.0)/(4.0*PI/6.0))+1.0, 3.0)); // +1 pq os indices estao em ordem 2,0,1 nos arrays
|
||||
float ang*/
|
||||
|
||||
float su, sz;
|
||||
|
||||
float abs_angle = abs(angle_to_light);
|
||||
vec2 point;
|
||||
float sh;
|
||||
if (abs_angle < 45.0 * PI / 180.0) {
|
||||
point = shadow_vec;
|
||||
sh = 0.0 + (1.0 / 8.0);
|
||||
} else if (abs_angle > 135.0 * PI / 180.0) {
|
||||
point = -shadow_vec;
|
||||
sh = 0.5 + (1.0 / 8.0);
|
||||
} else if (angle_to_light > 0.0) {
|
||||
point = vec2(shadow_vec.y, -shadow_vec.x);
|
||||
sh = 0.25 + (1.0 / 8.0);
|
||||
} else {
|
||||
point = vec2(-shadow_vec.y, shadow_vec.x);
|
||||
sh = 0.75 + (1.0 / 8.0);
|
||||
}
|
||||
|
||||
highp vec4 s = shadow_matrix * vec4(point, 0.0, 1.0);
|
||||
s.xyz /= s.w;
|
||||
su = s.x * 0.5 + 0.5;
|
||||
sz = s.z * 0.5 + 0.5;
|
||||
//sz=lightlength(light_vec);
|
||||
|
||||
highp float shadow_attenuation = 0.0;
|
||||
|
||||
#ifdef USE_RGBA_SHADOWS
|
||||
|
||||
#define SHADOW_DEPTH(m_tex, m_uv) dot(texture((m_tex), (m_uv)), vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0))
|
||||
|
||||
#else
|
||||
|
||||
#define SHADOW_DEPTH(m_tex, m_uv) (texture((m_tex), (m_uv)).r)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SHADOW_USE_GRADIENT
|
||||
|
||||
#define SHADOW_TEST(m_ofs) \
|
||||
{ \
|
||||
highp float sd = SHADOW_DEPTH(shadow_texture, vec2(m_ofs, sh)); \
|
||||
shadow_attenuation += 1.0 - smoothstep(sd, sd + shadow_gradient, sz); \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define SHADOW_TEST(m_ofs) \
|
||||
{ \
|
||||
highp float sd = SHADOW_DEPTH(shadow_texture, vec2(m_ofs, sh)); \
|
||||
shadow_attenuation += step(sz, sd); \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SHADOW_FILTER_NEAREST
|
||||
|
||||
SHADOW_TEST(su);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SHADOW_FILTER_PCF3
|
||||
|
||||
SHADOW_TEST(su + shadowpixel_size);
|
||||
SHADOW_TEST(su);
|
||||
SHADOW_TEST(su - shadowpixel_size);
|
||||
shadow_attenuation /= 3.0;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SHADOW_FILTER_PCF5
|
||||
|
||||
SHADOW_TEST(su + shadowpixel_size * 2.0);
|
||||
SHADOW_TEST(su + shadowpixel_size);
|
||||
SHADOW_TEST(su);
|
||||
SHADOW_TEST(su - shadowpixel_size);
|
||||
SHADOW_TEST(su - shadowpixel_size * 2.0);
|
||||
shadow_attenuation /= 5.0;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SHADOW_FILTER_PCF7
|
||||
|
||||
SHADOW_TEST(su + shadowpixel_size * 3.0);
|
||||
SHADOW_TEST(su + shadowpixel_size * 2.0);
|
||||
SHADOW_TEST(su + shadowpixel_size);
|
||||
SHADOW_TEST(su);
|
||||
SHADOW_TEST(su - shadowpixel_size);
|
||||
SHADOW_TEST(su - shadowpixel_size * 2.0);
|
||||
SHADOW_TEST(su - shadowpixel_size * 3.0);
|
||||
shadow_attenuation /= 7.0;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SHADOW_FILTER_PCF9
|
||||
|
||||
SHADOW_TEST(su + shadowpixel_size * 4.0);
|
||||
SHADOW_TEST(su + shadowpixel_size * 3.0);
|
||||
SHADOW_TEST(su + shadowpixel_size * 2.0);
|
||||
SHADOW_TEST(su + shadowpixel_size);
|
||||
SHADOW_TEST(su);
|
||||
SHADOW_TEST(su - shadowpixel_size);
|
||||
SHADOW_TEST(su - shadowpixel_size * 2.0);
|
||||
SHADOW_TEST(su - shadowpixel_size * 3.0);
|
||||
SHADOW_TEST(su - shadowpixel_size * 4.0);
|
||||
shadow_attenuation /= 9.0;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SHADOW_FILTER_PCF13
|
||||
|
||||
SHADOW_TEST(su + shadowpixel_size * 6.0);
|
||||
SHADOW_TEST(su + shadowpixel_size * 5.0);
|
||||
SHADOW_TEST(su + shadowpixel_size * 4.0);
|
||||
SHADOW_TEST(su + shadowpixel_size * 3.0);
|
||||
SHADOW_TEST(su + shadowpixel_size * 2.0);
|
||||
SHADOW_TEST(su + shadowpixel_size);
|
||||
SHADOW_TEST(su);
|
||||
SHADOW_TEST(su - shadowpixel_size);
|
||||
SHADOW_TEST(su - shadowpixel_size * 2.0);
|
||||
SHADOW_TEST(su - shadowpixel_size * 3.0);
|
||||
SHADOW_TEST(su - shadowpixel_size * 4.0);
|
||||
SHADOW_TEST(su - shadowpixel_size * 5.0);
|
||||
SHADOW_TEST(su - shadowpixel_size * 6.0);
|
||||
shadow_attenuation /= 13.0;
|
||||
|
||||
#endif
|
||||
|
||||
//color *= shadow_attenuation;
|
||||
color = mix(real_light_shadow_color, color, shadow_attenuation);
|
||||
//use shadows
|
||||
#endif
|
||||
}
|
||||
|
||||
//use lighting
|
||||
#endif
|
||||
|
||||
#ifdef LINEAR_TO_SRGB
|
||||
// regular Linear -> SRGB conversion
|
||||
vec3 a = vec3(0.055);
|
||||
color.rgb = mix((vec3(1.0) + a) * pow(color.rgb, vec3(1.0 / 2.4)) - a, 12.92 * color.rgb, lessThan(color.rgb, vec3(0.0031308)));
|
||||
#endif
|
||||
|
||||
//color.rgb *= color.a;
|
||||
frag_color = color;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
uniform highp mat4 projection_matrix;
|
||||
/* clang-format on */
|
||||
uniform highp mat4 light_matrix;
|
||||
uniform highp mat4 world_matrix;
|
||||
uniform highp float distance_norm;
|
||||
|
||||
layout(location = 0) in highp vec3 vertex;
|
||||
|
||||
out highp vec4 position_interp;
|
||||
|
||||
void main() {
|
||||
gl_Position = projection_matrix * (light_matrix * (world_matrix * vec4(vertex, 1.0)));
|
||||
position_interp = gl_Position;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
in highp vec4 position_interp;
|
||||
/* clang-format on */
|
||||
|
||||
#ifdef USE_RGBA_SHADOWS
|
||||
layout(location = 0) out lowp vec4 distance_buf;
|
||||
#else
|
||||
layout(location = 0) out highp float distance_buf;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
highp float depth = ((position_interp.z / position_interp.w) + 1.0) * 0.5 + 0.0; // bias
|
||||
|
||||
#ifdef USE_RGBA_SHADOWS
|
||||
|
||||
highp vec4 comp = fract(depth * vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0));
|
||||
comp -= comp.xxyz * vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);
|
||||
distance_buf = comp;
|
||||
#else
|
||||
|
||||
distance_buf = depth;
|
||||
#endif
|
||||
}
|
@ -1,267 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec4 vertex_attrib;
|
||||
/* clang-format on */
|
||||
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
|
||||
layout(location = 4) in vec3 cube_in;
|
||||
#else
|
||||
layout(location = 4) in vec2 uv_in;
|
||||
#endif
|
||||
layout(location = 5) in vec2 uv2_in;
|
||||
|
||||
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
|
||||
out vec3 cube_interp;
|
||||
#else
|
||||
out vec2 uv_interp;
|
||||
#endif
|
||||
|
||||
out vec2 uv2_interp;
|
||||
|
||||
// These definitions are here because the shader-wrapper builder does
|
||||
// not understand `#elif defined()`
|
||||
#ifdef USE_DISPLAY_TRANSFORM
|
||||
#endif
|
||||
|
||||
#ifdef USE_COPY_SECTION
|
||||
|
||||
uniform vec4 copy_section;
|
||||
|
||||
#elif defined(USE_DISPLAY_TRANSFORM)
|
||||
|
||||
uniform highp mat4 display_transform;
|
||||
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
|
||||
cube_interp = cube_in;
|
||||
#elif defined(USE_ASYM_PANO)
|
||||
uv_interp = vertex_attrib.xy;
|
||||
#else
|
||||
uv_interp = uv_in;
|
||||
#ifdef V_FLIP
|
||||
uv_interp.y = 1.0 - uv_interp.y;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
uv2_interp = uv2_in;
|
||||
gl_Position = vertex_attrib;
|
||||
|
||||
#ifdef USE_COPY_SECTION
|
||||
|
||||
uv_interp = copy_section.xy + uv_interp * copy_section.zw;
|
||||
gl_Position.xy = (copy_section.xy + (gl_Position.xy * 0.5 + 0.5) * copy_section.zw) * 2.0 - 1.0;
|
||||
#elif defined(USE_DISPLAY_TRANSFORM)
|
||||
|
||||
uv_interp = (display_transform * vec4(uv_in, 1.0, 1.0)).xy;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
#define M_PI 3.14159265359
|
||||
|
||||
#if !defined(USE_GLES_OVER_GL)
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
|
||||
in vec3 cube_interp;
|
||||
#else
|
||||
in vec2 uv_interp;
|
||||
#endif
|
||||
|
||||
#ifdef USE_ASYM_PANO
|
||||
uniform highp mat4 pano_transform;
|
||||
uniform highp vec4 asym_proj;
|
||||
#endif
|
||||
|
||||
// These definitions are here because the shader-wrapper builder does
|
||||
// not understand `#elif defined()`
|
||||
#ifdef USE_TEXTURE3D
|
||||
#endif
|
||||
#ifdef USE_TEXTURE2DARRAY
|
||||
#endif
|
||||
#ifdef YCBCR_TO_SRGB
|
||||
#endif
|
||||
|
||||
#ifdef USE_CUBEMAP
|
||||
uniform samplerCube source_cube; //texunit:0
|
||||
#elif defined(USE_TEXTURE3D)
|
||||
uniform sampler3D source_3d; //texunit:0
|
||||
#elif defined(USE_TEXTURE2DARRAY)
|
||||
uniform sampler2DArray source_2d_array; //texunit:0
|
||||
#else
|
||||
uniform sampler2D source; //texunit:0
|
||||
#endif
|
||||
|
||||
#ifdef SEP_CBCR_TEXTURE
|
||||
uniform sampler2D CbCr; //texunit:1
|
||||
#endif
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
#ifdef USE_LOD
|
||||
uniform float mip_level;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TEXTURE3D) || defined(USE_TEXTURE2DARRAY)
|
||||
uniform float layer;
|
||||
#endif
|
||||
|
||||
#ifdef USE_MULTIPLIER
|
||||
uniform float multiplier;
|
||||
#endif
|
||||
|
||||
#if defined(USE_PANORAMA) || defined(USE_ASYM_PANO)
|
||||
uniform highp mat4 sky_transform;
|
||||
|
||||
vec4 texturePanorama(vec3 normal, sampler2D pano) {
|
||||
vec2 st = vec2(
|
||||
atan(normal.x, normal.z),
|
||||
acos(normal.y));
|
||||
|
||||
if (st.x < 0.0)
|
||||
st.x += M_PI * 2.0;
|
||||
|
||||
st /= vec2(M_PI * 2.0, M_PI);
|
||||
|
||||
return textureLod(pano, st, 0.0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
uniform vec2 pixel_size;
|
||||
|
||||
in vec2 uv2_interp;
|
||||
|
||||
#ifdef USE_BCS
|
||||
|
||||
uniform vec3 bcs;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_COLOR_CORRECTION
|
||||
|
||||
uniform sampler2D color_correction; //texunit:1
|
||||
|
||||
#endif
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
//vec4 color = color_interp;
|
||||
|
||||
#ifdef USE_PANORAMA
|
||||
|
||||
vec3 cube_normal = normalize(cube_interp);
|
||||
cube_normal.z = -cube_normal.z;
|
||||
cube_normal = mat3(sky_transform) * cube_normal;
|
||||
cube_normal.z = -cube_normal.z;
|
||||
|
||||
vec4 color = texturePanorama(cube_normal, source);
|
||||
|
||||
#elif defined(USE_ASYM_PANO)
|
||||
|
||||
// When an asymmetrical projection matrix is used (applicable for stereoscopic rendering i.e. VR) we need to do this calculation per fragment to get a perspective correct result.
|
||||
// Asymmetrical projection means the center of projection is no longer in the center of the screen but shifted.
|
||||
// The Matrix[2][0] (= asym_proj.x) and Matrix[2][1] (= asym_proj.z) values are what provide the right shift in the image.
|
||||
|
||||
vec3 cube_normal;
|
||||
cube_normal.z = -1.0;
|
||||
cube_normal.x = (cube_normal.z * (-uv_interp.x - asym_proj.x)) / asym_proj.y;
|
||||
cube_normal.y = (cube_normal.z * (-uv_interp.y - asym_proj.z)) / asym_proj.a;
|
||||
cube_normal = mat3(sky_transform) * mat3(pano_transform) * cube_normal;
|
||||
cube_normal.z = -cube_normal.z;
|
||||
|
||||
vec4 color = texturePanorama(normalize(cube_normal.xyz), source);
|
||||
|
||||
#elif defined(USE_CUBEMAP)
|
||||
vec4 color = texture(source_cube, normalize(cube_interp));
|
||||
|
||||
#elif defined(USE_TEXTURE3D)
|
||||
vec4 color = textureLod(source_3d, vec3(uv_interp, layer), 0.0);
|
||||
#elif defined(USE_TEXTURE2DARRAY)
|
||||
vec4 color = textureLod(source_2d_array, vec3(uv_interp, layer), 0.0);
|
||||
#elif defined(SEP_CBCR_TEXTURE)
|
||||
vec4 color;
|
||||
color.r = textureLod(source, uv_interp, 0.0).r;
|
||||
color.gb = textureLod(CbCr, uv_interp, 0.0).rg - vec2(0.5, 0.5);
|
||||
color.a = 1.0;
|
||||
#else
|
||||
#ifdef USE_LOD
|
||||
vec4 color = textureLod(source, uv_interp, mip_level);
|
||||
#else
|
||||
vec4 color = textureLod(source, uv_interp, 0.0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef LINEAR_TO_SRGB
|
||||
// regular Linear -> SRGB conversion
|
||||
vec3 a = vec3(0.055);
|
||||
color.rgb = mix((vec3(1.0) + a) * pow(color.rgb, vec3(1.0 / 2.4)) - a, 12.92 * color.rgb, lessThan(color.rgb, vec3(0.0031308)));
|
||||
|
||||
#elif defined(YCBCR_TO_SRGB)
|
||||
|
||||
// YCbCr -> SRGB conversion
|
||||
// Using BT.709 which is the standard for HDTV
|
||||
color.rgb = mat3(
|
||||
vec3(1.00000, 1.00000, 1.00000),
|
||||
vec3(0.00000, -0.18732, 1.85560),
|
||||
vec3(1.57481, -0.46813, 0.00000)) *
|
||||
color.rgb;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SRGB_TO_LINEAR
|
||||
|
||||
color.rgb = mix(pow((color.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), color.rgb * (1.0 / 12.92), lessThan(color.rgb, vec3(0.04045)));
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_GRADIENT
|
||||
color.rg = uv_interp;
|
||||
color.b = 0.0;
|
||||
#endif
|
||||
|
||||
#ifdef DISABLE_ALPHA
|
||||
color.a = 1.0;
|
||||
#endif
|
||||
|
||||
#ifdef GAUSSIAN_HORIZONTAL
|
||||
color *= 0.38774;
|
||||
color += texture(source, uv_interp + vec2(1.0, 0.0) * pixel_size) * 0.24477;
|
||||
color += texture(source, uv_interp + vec2(2.0, 0.0) * pixel_size) * 0.06136;
|
||||
color += texture(source, uv_interp + vec2(-1.0, 0.0) * pixel_size) * 0.24477;
|
||||
color += texture(source, uv_interp + vec2(-2.0, 0.0) * pixel_size) * 0.06136;
|
||||
#endif
|
||||
|
||||
#ifdef GAUSSIAN_VERTICAL
|
||||
color *= 0.38774;
|
||||
color += texture(source, uv_interp + vec2(0.0, 1.0) * pixel_size) * 0.24477;
|
||||
color += texture(source, uv_interp + vec2(0.0, 2.0) * pixel_size) * 0.06136;
|
||||
color += texture(source, uv_interp + vec2(0.0, -1.0) * pixel_size) * 0.24477;
|
||||
color += texture(source, uv_interp + vec2(0.0, -2.0) * pixel_size) * 0.06136;
|
||||
#endif
|
||||
|
||||
#ifdef USE_BCS
|
||||
|
||||
color.rgb = mix(vec3(0.0), color.rgb, bcs.x);
|
||||
color.rgb = mix(vec3(0.5), color.rgb, bcs.y);
|
||||
color.rgb = mix(vec3(dot(vec3(1.0), color.rgb) * 0.33333), color.rgb, bcs.z);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_COLOR_CORRECTION
|
||||
|
||||
color.r = texture(color_correction, vec2(color.r, 0.0)).r;
|
||||
color.g = texture(color_correction, vec2(color.g, 0.0)).g;
|
||||
color.b = texture(color_correction, vec2(color.b, 0.0)).b;
|
||||
#endif
|
||||
|
||||
#ifdef USE_MULTIPLIER
|
||||
color.rgb *= multiplier;
|
||||
#endif
|
||||
frag_color = color;
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec4 vertex_attrib;
|
||||
/* clang-format on */
|
||||
layout(location = 4) in vec2 uv_in;
|
||||
|
||||
out vec2 uv_interp;
|
||||
|
||||
void main() {
|
||||
uv_interp = uv_in;
|
||||
gl_Position = vertex_attrib;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
uniform highp samplerCube source_cube; //texunit:0
|
||||
/* clang-format on */
|
||||
in vec2 uv_interp;
|
||||
|
||||
uniform bool z_flip;
|
||||
uniform highp float z_far;
|
||||
uniform highp float z_near;
|
||||
uniform highp float bias;
|
||||
|
||||
void main() {
|
||||
highp vec3 normal = vec3(uv_interp * 2.0 - 1.0, 0.0);
|
||||
/*
|
||||
if (z_flip) {
|
||||
normal.z = 0.5 - 0.5 * ((normal.x * normal.x) + (normal.y * normal.y));
|
||||
} else {
|
||||
normal.z = -0.5 + 0.5 * ((normal.x * normal.x) + (normal.y * normal.y));
|
||||
}
|
||||
*/
|
||||
|
||||
//normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
|
||||
//normal.xy *= 1.0 + normal.z;
|
||||
|
||||
normal.z = 0.5 - 0.5 * ((normal.x * normal.x) + (normal.y * normal.y));
|
||||
normal = normalize(normal);
|
||||
/*
|
||||
normal.z = 0.5;
|
||||
normal = normalize(normal);
|
||||
*/
|
||||
|
||||
if (!z_flip) {
|
||||
normal.z = -normal.z;
|
||||
}
|
||||
|
||||
//normal = normalize(vec3(uv_interp * 2.0 - 1.0, 1.0));
|
||||
float depth = texture(source_cube, normal).r;
|
||||
|
||||
// absolute values for direction cosines, bigger value equals closer to basis axis
|
||||
vec3 unorm = abs(normal);
|
||||
|
||||
if ((unorm.x >= unorm.y) && (unorm.x >= unorm.z)) {
|
||||
// x code
|
||||
unorm = normal.x > 0.0 ? vec3(1.0, 0.0, 0.0) : vec3(-1.0, 0.0, 0.0);
|
||||
} else if ((unorm.y > unorm.x) && (unorm.y >= unorm.z)) {
|
||||
// y code
|
||||
unorm = normal.y > 0.0 ? vec3(0.0, 1.0, 0.0) : vec3(0.0, -1.0, 0.0);
|
||||
} else if ((unorm.z > unorm.x) && (unorm.z > unorm.y)) {
|
||||
// z code
|
||||
unorm = normal.z > 0.0 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 0.0, -1.0);
|
||||
} else {
|
||||
// oh-no we messed up code
|
||||
// has to be
|
||||
unorm = vec3(1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
float depth_fix = 1.0 / dot(normal, unorm);
|
||||
|
||||
depth = 2.0 * depth - 1.0;
|
||||
float linear_depth = 2.0 * z_near * z_far / (z_far + z_near - depth * (z_far - z_near));
|
||||
gl_FragDepth = (linear_depth * depth_fix + bias) / z_far;
|
||||
}
|
@ -1,365 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec2 vertex;
|
||||
/* clang-format on */
|
||||
|
||||
layout(location = 4) in highp vec2 uv;
|
||||
|
||||
out highp vec2 uv_interp;
|
||||
|
||||
void main() {
|
||||
uv_interp = uv;
|
||||
gl_Position = vec4(vertex, 0, 1);
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
precision highp float;
|
||||
/* clang-format on */
|
||||
precision highp int;
|
||||
|
||||
#ifdef USE_SOURCE_PANORAMA
|
||||
uniform sampler2D source_panorama; //texunit:0
|
||||
uniform float source_resolution;
|
||||
#endif
|
||||
|
||||
#ifdef USE_SOURCE_DUAL_PARABOLOID_ARRAY
|
||||
uniform sampler2DArray source_dual_paraboloid_array; //texunit:0
|
||||
uniform int source_array_index;
|
||||
#endif
|
||||
|
||||
#ifdef USE_SOURCE_DUAL_PARABOLOID
|
||||
uniform sampler2D source_dual_paraboloid; //texunit:0
|
||||
#endif
|
||||
|
||||
#if defined(USE_SOURCE_DUAL_PARABOLOID) || defined(COMPUTE_IRRADIANCE)
|
||||
uniform float source_mip_level;
|
||||
#endif
|
||||
|
||||
#if !defined(USE_SOURCE_DUAL_PARABOLOID_ARRAY) && !defined(USE_SOURCE_PANORAMA) && !defined(USE_SOURCE_DUAL_PARABOLOID)
|
||||
uniform samplerCube source_cube; //texunit:0
|
||||
#endif
|
||||
|
||||
uniform int face_id;
|
||||
uniform float roughness;
|
||||
|
||||
in highp vec2 uv_interp;
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
#define M_PI 3.14159265359
|
||||
|
||||
vec3 texelCoordToVec(vec2 uv, int faceID) {
|
||||
mat3 faceUvVectors[6];
|
||||
/*
|
||||
// -x
|
||||
faceUvVectors[1][0] = vec3(0.0, 0.0, 1.0); // u -> +z
|
||||
faceUvVectors[1][1] = vec3(0.0, -1.0, 0.0); // v -> -y
|
||||
faceUvVectors[1][2] = vec3(-1.0, 0.0, 0.0); // -x face
|
||||
|
||||
// +x
|
||||
faceUvVectors[0][0] = vec3(0.0, 0.0, -1.0); // u -> -z
|
||||
faceUvVectors[0][1] = vec3(0.0, -1.0, 0.0); // v -> -y
|
||||
faceUvVectors[0][2] = vec3(1.0, 0.0, 0.0); // +x face
|
||||
|
||||
// -y
|
||||
faceUvVectors[3][0] = vec3(1.0, 0.0, 0.0); // u -> +x
|
||||
faceUvVectors[3][1] = vec3(0.0, 0.0, -1.0); // v -> -z
|
||||
faceUvVectors[3][2] = vec3(0.0, -1.0, 0.0); // -y face
|
||||
|
||||
// +y
|
||||
faceUvVectors[2][0] = vec3(1.0, 0.0, 0.0); // u -> +x
|
||||
faceUvVectors[2][1] = vec3(0.0, 0.0, 1.0); // v -> +z
|
||||
faceUvVectors[2][2] = vec3(0.0, 1.0, 0.0); // +y face
|
||||
|
||||
// -z
|
||||
faceUvVectors[5][0] = vec3(-1.0, 0.0, 0.0); // u -> -x
|
||||
faceUvVectors[5][1] = vec3(0.0, -1.0, 0.0); // v -> -y
|
||||
faceUvVectors[5][2] = vec3(0.0, 0.0, -1.0); // -z face
|
||||
|
||||
// +z
|
||||
faceUvVectors[4][0] = vec3(1.0, 0.0, 0.0); // u -> +x
|
||||
faceUvVectors[4][1] = vec3(0.0, -1.0, 0.0); // v -> -y
|
||||
faceUvVectors[4][2] = vec3(0.0, 0.0, 1.0); // +z face
|
||||
*/
|
||||
|
||||
// -x
|
||||
faceUvVectors[0][0] = vec3(0.0, 0.0, 1.0); // u -> +z
|
||||
faceUvVectors[0][1] = vec3(0.0, -1.0, 0.0); // v -> -y
|
||||
faceUvVectors[0][2] = vec3(-1.0, 0.0, 0.0); // -x face
|
||||
|
||||
// +x
|
||||
faceUvVectors[1][0] = vec3(0.0, 0.0, -1.0); // u -> -z
|
||||
faceUvVectors[1][1] = vec3(0.0, -1.0, 0.0); // v -> -y
|
||||
faceUvVectors[1][2] = vec3(1.0, 0.0, 0.0); // +x face
|
||||
|
||||
// -y
|
||||
faceUvVectors[2][0] = vec3(1.0, 0.0, 0.0); // u -> +x
|
||||
faceUvVectors[2][1] = vec3(0.0, 0.0, -1.0); // v -> -z
|
||||
faceUvVectors[2][2] = vec3(0.0, -1.0, 0.0); // -y face
|
||||
|
||||
// +y
|
||||
faceUvVectors[3][0] = vec3(1.0, 0.0, 0.0); // u -> +x
|
||||
faceUvVectors[3][1] = vec3(0.0, 0.0, 1.0); // v -> +z
|
||||
faceUvVectors[3][2] = vec3(0.0, 1.0, 0.0); // +y face
|
||||
|
||||
// -z
|
||||
faceUvVectors[4][0] = vec3(-1.0, 0.0, 0.0); // u -> -x
|
||||
faceUvVectors[4][1] = vec3(0.0, -1.0, 0.0); // v -> -y
|
||||
faceUvVectors[4][2] = vec3(0.0, 0.0, -1.0); // -z face
|
||||
|
||||
// +z
|
||||
faceUvVectors[5][0] = vec3(1.0, 0.0, 0.0); // u -> +x
|
||||
faceUvVectors[5][1] = vec3(0.0, -1.0, 0.0); // v -> -y
|
||||
faceUvVectors[5][2] = vec3(0.0, 0.0, 1.0); // +z face
|
||||
|
||||
// out = u * s_faceUv[0] + v * s_faceUv[1] + s_faceUv[2].
|
||||
vec3 result = (faceUvVectors[faceID][0] * uv.x) + (faceUvVectors[faceID][1] * uv.y) + faceUvVectors[faceID][2];
|
||||
return normalize(result);
|
||||
}
|
||||
|
||||
vec3 ImportanceSampleGGX(vec2 Xi, float Roughness, vec3 N) {
|
||||
float a = Roughness * Roughness; // DISNEY'S ROUGHNESS [see Burley'12 siggraph]
|
||||
|
||||
// Compute distribution direction
|
||||
float Phi = 2.0 * M_PI * Xi.x;
|
||||
float CosTheta = sqrt((1.0 - Xi.y) / (1.0 + (a * a - 1.0) * Xi.y));
|
||||
float SinTheta = sqrt(1.0 - CosTheta * CosTheta);
|
||||
|
||||
// Convert to spherical direction
|
||||
vec3 H;
|
||||
H.x = SinTheta * cos(Phi);
|
||||
H.y = SinTheta * sin(Phi);
|
||||
H.z = CosTheta;
|
||||
|
||||
vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
|
||||
vec3 TangentX = normalize(cross(UpVector, N));
|
||||
vec3 TangentY = cross(N, TangentX);
|
||||
|
||||
// Tangent to world space
|
||||
return TangentX * H.x + TangentY * H.y + N * H.z;
|
||||
}
|
||||
|
||||
float DistributionGGX(vec3 N, vec3 H, float roughness) {
|
||||
float a = roughness * roughness;
|
||||
float a2 = a * a;
|
||||
float NdotH = max(dot(N, H), 0.0);
|
||||
float NdotH2 = NdotH * NdotH;
|
||||
|
||||
float nom = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
|
||||
denom = M_PI * denom * denom;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
|
||||
// http://graphicrants.blogspot.com.au/2013/08/specular-brdf-reference.html
|
||||
float GGX(float NdotV, float a) {
|
||||
float k = a / 2.0;
|
||||
return NdotV / (NdotV * (1.0 - k) + k);
|
||||
}
|
||||
|
||||
// http://graphicrants.blogspot.com.au/2013/08/specular-brdf-reference.html
|
||||
float G_Smith(float a, float nDotV, float nDotL) {
|
||||
return GGX(nDotL, a * a) * GGX(nDotV, a * a);
|
||||
}
|
||||
|
||||
float radicalInverse_VdC(uint bits) {
|
||||
bits = (bits << 16u) | (bits >> 16u);
|
||||
bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
|
||||
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
|
||||
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
|
||||
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
|
||||
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
|
||||
}
|
||||
|
||||
vec2 Hammersley(uint i, uint N) {
|
||||
return vec2(float(i) / float(N), radicalInverse_VdC(i));
|
||||
}
|
||||
|
||||
#ifdef LOW_QUALITY
|
||||
|
||||
#define SAMPLE_COUNT 64u
|
||||
#define SAMPLE_DELTA 0.1
|
||||
|
||||
#else
|
||||
|
||||
#define SAMPLE_COUNT 512u
|
||||
#define SAMPLE_DELTA 0.03
|
||||
|
||||
#endif
|
||||
|
||||
uniform bool z_flip;
|
||||
|
||||
#ifdef USE_SOURCE_PANORAMA
|
||||
|
||||
vec4 texturePanorama(vec3 normal, sampler2D pano, float mipLevel) {
|
||||
vec2 st = vec2(
|
||||
atan(normal.x, normal.z),
|
||||
acos(normal.y));
|
||||
|
||||
if (st.x < 0.0)
|
||||
st.x += M_PI * 2.0;
|
||||
|
||||
st /= vec2(M_PI * 2.0, M_PI);
|
||||
|
||||
return textureLod(pano, st, mipLevel);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_SOURCE_DUAL_PARABOLOID_ARRAY
|
||||
|
||||
vec4 textureDualParaboloidArray(vec3 normal) {
|
||||
vec3 norm = normalize(normal);
|
||||
norm.xy /= 1.0 + abs(norm.z);
|
||||
norm.xy = norm.xy * vec2(0.5, 0.25) + vec2(0.5, 0.25);
|
||||
if (norm.z < 0.0) {
|
||||
norm.y = 0.5 - norm.y + 0.5;
|
||||
}
|
||||
return textureLod(source_dual_paraboloid_array, vec3(norm.xy, float(source_array_index)), 0.0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_SOURCE_DUAL_PARABOLOID
|
||||
vec4 textureDualParaboloid(vec3 normal) {
|
||||
vec3 norm = normalize(normal);
|
||||
norm.xy /= 1.0 + abs(norm.z);
|
||||
norm.xy = norm.xy * vec2(0.5, 0.25) + vec2(0.5, 0.25);
|
||||
if (norm.z < 0.0) {
|
||||
norm.y = 0.5 - norm.y + 0.5;
|
||||
}
|
||||
return textureLod(source_dual_paraboloid, norm.xy, source_mip_level);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#ifdef USE_DUAL_PARABOLOID
|
||||
|
||||
vec3 N = vec3(uv_interp * 2.0 - 1.0, 0.0);
|
||||
N.z = 0.5 - 0.5 * ((N.x * N.x) + (N.y * N.y));
|
||||
N = normalize(N);
|
||||
|
||||
if (z_flip) {
|
||||
N.y = -N.y; //y is flipped to improve blending between both sides
|
||||
N.z = -N.z;
|
||||
}
|
||||
|
||||
#else
|
||||
vec2 uv = (uv_interp * 2.0) - 1.0;
|
||||
vec3 N = texelCoordToVec(uv, face_id);
|
||||
#endif
|
||||
//vec4 color = color_interp;
|
||||
|
||||
#ifdef USE_DIRECT_WRITE
|
||||
|
||||
#ifdef USE_SOURCE_PANORAMA
|
||||
|
||||
frag_color = vec4(texturePanorama(N, source_panorama, 0.0).rgb, 1.0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_SOURCE_DUAL_PARABOLOID_ARRAY
|
||||
|
||||
frag_color = vec4(textureDualParaboloidArray(N).rgb, 1.0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_SOURCE_DUAL_PARABOLOID
|
||||
|
||||
frag_color = vec4(textureDualParaboloid(N).rgb, 1.0);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_SOURCE_DUAL_PARABOLOID_ARRAY) && !defined(USE_SOURCE_PANORAMA) && !defined(USE_SOURCE_DUAL_PARABOLOID)
|
||||
|
||||
N.y = -N.y;
|
||||
frag_color = vec4(texture(N, source_cube).rgb, 1.0);
|
||||
#endif
|
||||
|
||||
#else // USE_DIRECT_WRITE
|
||||
|
||||
#ifdef COMPUTE_IRRADIANCE
|
||||
|
||||
vec3 irradiance = vec3(0.0);
|
||||
|
||||
// tangent space calculation from origin point
|
||||
vec3 UpVector = vec3(0.0, 1.0, 0.0);
|
||||
vec3 TangentX = cross(UpVector, N);
|
||||
vec3 TangentY = cross(N, TangentX);
|
||||
|
||||
float num_samples = 0.0f;
|
||||
|
||||
for (float phi = 0.0; phi < 2.0 * M_PI; phi += SAMPLE_DELTA) {
|
||||
for (float theta = 0.0; theta < 0.5 * M_PI; theta += SAMPLE_DELTA) {
|
||||
// Calculate sample positions
|
||||
vec3 tangentSample = vec3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
|
||||
// Find world vector of sample position
|
||||
vec3 H = tangentSample.x * TangentX + tangentSample.y * TangentY + tangentSample.z * N;
|
||||
|
||||
vec2 st = vec2(atan(H.x, H.z), acos(H.y));
|
||||
if (st.x < 0.0) {
|
||||
st.x += M_PI * 2.0;
|
||||
}
|
||||
st /= vec2(M_PI * 2.0, M_PI);
|
||||
|
||||
irradiance += textureLod(source_panorama, st, source_mip_level).rgb * cos(theta) * sin(theta);
|
||||
num_samples++;
|
||||
}
|
||||
}
|
||||
irradiance = M_PI * irradiance * (1.0 / float(num_samples));
|
||||
|
||||
frag_color = vec4(irradiance, 1.0);
|
||||
|
||||
#else
|
||||
|
||||
vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
for (uint sampleNum = 0u; sampleNum < SAMPLE_COUNT; sampleNum++) {
|
||||
vec2 xi = Hammersley(sampleNum, SAMPLE_COUNT);
|
||||
|
||||
vec3 H = normalize(ImportanceSampleGGX(xi, roughness, N));
|
||||
vec3 V = N;
|
||||
vec3 L = normalize(2.0 * dot(V, H) * H - V);
|
||||
|
||||
float ndotl = max(dot(N, L), 0.0);
|
||||
|
||||
if (ndotl > 0.0) {
|
||||
|
||||
#ifdef USE_SOURCE_PANORAMA
|
||||
float D = DistributionGGX(N, H, roughness);
|
||||
float ndoth = max(dot(N, H), 0.0);
|
||||
float hdotv = max(dot(H, V), 0.0);
|
||||
float pdf = D * ndoth / (4.0 * hdotv) + 0.0001;
|
||||
|
||||
float saTexel = 4.0 * M_PI / (6.0 * source_resolution * source_resolution);
|
||||
float saSample = 1.0 / (float(SAMPLE_COUNT) * pdf + 0.0001);
|
||||
|
||||
float mipLevel = roughness == 0.0 ? 0.0 : 0.5 * log2(saSample / saTexel);
|
||||
|
||||
sum.rgb += texturePanorama(L, source_panorama, mipLevel).rgb * ndotl;
|
||||
#endif
|
||||
|
||||
#ifdef USE_SOURCE_DUAL_PARABOLOID_ARRAY
|
||||
sum.rgb += textureDualParaboloidArray(L).rgb * ndotl;
|
||||
#endif
|
||||
|
||||
#ifdef USE_SOURCE_DUAL_PARABOLOID
|
||||
sum.rgb += textureDualParaboloid(L).rgb * ndotl;
|
||||
#endif
|
||||
|
||||
#if !defined(USE_SOURCE_DUAL_PARABOLOID_ARRAY) && !defined(USE_SOURCE_PANORAMA) && !defined(USE_SOURCE_DUAL_PARABOLOID)
|
||||
L.y = -L.y;
|
||||
sum.rgb += textureLod(source_cube, L, 0.0).rgb * ndotl;
|
||||
#endif
|
||||
sum.a += ndotl;
|
||||
}
|
||||
}
|
||||
sum /= sum.a;
|
||||
|
||||
frag_color = vec4(sum.rgb, 1.0);
|
||||
|
||||
#endif // COMPUTE_IRRADIANCE
|
||||
#endif // USE_DIRECT_WRITE
|
||||
}
|
@ -1,316 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec4 vertex_attrib;
|
||||
/* clang-format on */
|
||||
layout(location = 4) in vec2 uv_in;
|
||||
|
||||
out vec2 uv_interp;
|
||||
|
||||
#ifdef USE_BLUR_SECTION
|
||||
|
||||
uniform vec4 blur_section;
|
||||
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
uv_interp = uv_in;
|
||||
gl_Position = vertex_attrib;
|
||||
#ifdef USE_BLUR_SECTION
|
||||
|
||||
uv_interp = blur_section.xy + uv_interp * blur_section.zw;
|
||||
gl_Position.xy = (blur_section.xy + (gl_Position.xy * 0.5 + 0.5) * blur_section.zw) * 2.0 - 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
#if !defined(GLES_OVER_GL)
|
||||
precision mediump float;
|
||||
#endif
|
||||
/* clang-format on */
|
||||
|
||||
in vec2 uv_interp;
|
||||
uniform sampler2D source_color; //texunit:0
|
||||
|
||||
#ifdef SSAO_MERGE
|
||||
uniform sampler2D source_ssao; //texunit:1
|
||||
#endif
|
||||
|
||||
uniform float lod;
|
||||
uniform vec2 pixel_size;
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
#ifdef SSAO_MERGE
|
||||
|
||||
uniform vec4 ssao_color;
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(GLOW_GAUSSIAN_HORIZONTAL) || defined(GLOW_GAUSSIAN_VERTICAL)
|
||||
|
||||
uniform float glow_strength;
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(DOF_FAR_BLUR) || defined(DOF_NEAR_BLUR)
|
||||
|
||||
#ifdef DOF_QUALITY_LOW
|
||||
const int dof_kernel_size = 5;
|
||||
const int dof_kernel_from = 2;
|
||||
const float dof_kernel[5] = float[](0.153388, 0.221461, 0.250301, 0.221461, 0.153388);
|
||||
#endif
|
||||
|
||||
#ifdef DOF_QUALITY_MEDIUM
|
||||
const int dof_kernel_size = 11;
|
||||
const int dof_kernel_from = 5;
|
||||
const float dof_kernel[11] = float[](0.055037, 0.072806, 0.090506, 0.105726, 0.116061, 0.119726, 0.116061, 0.105726, 0.090506, 0.072806, 0.055037);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef DOF_QUALITY_HIGH
|
||||
const int dof_kernel_size = 21;
|
||||
const int dof_kernel_from = 10;
|
||||
const float dof_kernel[21] = float[](0.028174, 0.032676, 0.037311, 0.041944, 0.046421, 0.050582, 0.054261, 0.057307, 0.059587, 0.060998, 0.061476, 0.060998, 0.059587, 0.057307, 0.054261, 0.050582, 0.046421, 0.041944, 0.037311, 0.032676, 0.028174);
|
||||
#endif
|
||||
|
||||
uniform sampler2D dof_source_depth; //texunit:1
|
||||
uniform float dof_begin;
|
||||
uniform float dof_end;
|
||||
uniform vec2 dof_dir;
|
||||
uniform float dof_radius;
|
||||
|
||||
#ifdef DOF_NEAR_BLUR_MERGE
|
||||
|
||||
uniform sampler2D source_dof_original; //texunit:2
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef GLOW_FIRST_PASS
|
||||
|
||||
uniform float exposure;
|
||||
uniform float white;
|
||||
uniform highp float luminance_cap;
|
||||
|
||||
#ifdef GLOW_USE_AUTO_EXPOSURE
|
||||
|
||||
uniform highp sampler2D source_auto_exposure; //texunit:1
|
||||
uniform highp float auto_exposure_grey;
|
||||
|
||||
#endif
|
||||
|
||||
uniform float glow_bloom;
|
||||
uniform float glow_hdr_threshold;
|
||||
uniform float glow_hdr_scale;
|
||||
|
||||
#endif
|
||||
|
||||
uniform float camera_z_far;
|
||||
uniform float camera_z_near;
|
||||
|
||||
void main() {
|
||||
#ifdef GAUSSIAN_HORIZONTAL
|
||||
vec2 pix_size = pixel_size;
|
||||
pix_size *= 0.5; //reading from larger buffer, so use more samples
|
||||
// sigma 2
|
||||
vec4 color = textureLod(source_color, uv_interp + vec2(0.0, 0.0) * pix_size, lod) * 0.214607;
|
||||
color += textureLod(source_color, uv_interp + vec2(1.0, 0.0) * pix_size, lod) * 0.189879;
|
||||
color += textureLod(source_color, uv_interp + vec2(2.0, 0.0) * pix_size, lod) * 0.131514;
|
||||
color += textureLod(source_color, uv_interp + vec2(3.0, 0.0) * pix_size, lod) * 0.071303;
|
||||
color += textureLod(source_color, uv_interp + vec2(-1.0, 0.0) * pix_size, lod) * 0.189879;
|
||||
color += textureLod(source_color, uv_interp + vec2(-2.0, 0.0) * pix_size, lod) * 0.131514;
|
||||
color += textureLod(source_color, uv_interp + vec2(-3.0, 0.0) * pix_size, lod) * 0.071303;
|
||||
frag_color = color;
|
||||
#endif
|
||||
|
||||
#ifdef GAUSSIAN_VERTICAL
|
||||
vec4 color = textureLod(source_color, uv_interp + vec2(0.0, 0.0) * pixel_size, lod) * 0.38774;
|
||||
color += textureLod(source_color, uv_interp + vec2(0.0, 1.0) * pixel_size, lod) * 0.24477;
|
||||
color += textureLod(source_color, uv_interp + vec2(0.0, 2.0) * pixel_size, lod) * 0.06136;
|
||||
color += textureLod(source_color, uv_interp + vec2(0.0, -1.0) * pixel_size, lod) * 0.24477;
|
||||
color += textureLod(source_color, uv_interp + vec2(0.0, -2.0) * pixel_size, lod) * 0.06136;
|
||||
frag_color = color;
|
||||
#endif
|
||||
|
||||
//glow uses larger sigma for a more rounded blur effect
|
||||
|
||||
#ifdef GLOW_GAUSSIAN_HORIZONTAL
|
||||
vec2 pix_size = pixel_size;
|
||||
pix_size *= 0.5; //reading from larger buffer, so use more samples
|
||||
|
||||
#ifdef USE_GLOW_HIGH_QUALITY
|
||||
// Sample from two lines to capture single-pixel features.
|
||||
// This is significantly slower, but looks better and is more stable for moving objects.
|
||||
vec4 color = textureLod(source_color, uv_interp + vec2(0.0, 0.0) * pix_size, lod) * 0.152781;
|
||||
color += textureLod(source_color, uv_interp + vec2(1.0, 0.0) * pix_size, lod) * 0.144599;
|
||||
color += textureLod(source_color, uv_interp + vec2(2.0, 0.0) * pix_size, lod) * 0.122589;
|
||||
color += textureLod(source_color, uv_interp + vec2(3.0, 0.0) * pix_size, lod) * 0.093095;
|
||||
color += textureLod(source_color, uv_interp + vec2(4.0, 0.0) * pix_size, lod) * 0.063327;
|
||||
color += textureLod(source_color, uv_interp + vec2(-1.0, 0.0) * pix_size, lod) * 0.144599;
|
||||
color += textureLod(source_color, uv_interp + vec2(-2.0, 0.0) * pix_size, lod) * 0.122589;
|
||||
color += textureLod(source_color, uv_interp + vec2(-3.0, 0.0) * pix_size, lod) * 0.093095;
|
||||
color += textureLod(source_color, uv_interp + vec2(-4.0, 0.0) * pix_size, lod) * 0.063327;
|
||||
|
||||
color += textureLod(source_color, uv_interp + vec2(0.0, 1.0) * pix_size, lod) * 0.152781;
|
||||
color += textureLod(source_color, uv_interp + vec2(1.0, 1.0) * pix_size, lod) * 0.144599;
|
||||
color += textureLod(source_color, uv_interp + vec2(2.0, 1.0) * pix_size, lod) * 0.122589;
|
||||
color += textureLod(source_color, uv_interp + vec2(3.0, 1.0) * pix_size, lod) * 0.093095;
|
||||
color += textureLod(source_color, uv_interp + vec2(4.0, 1.0) * pix_size, lod) * 0.063327;
|
||||
color += textureLod(source_color, uv_interp + vec2(-1.0, 1.0) * pix_size, lod) * 0.144599;
|
||||
color += textureLod(source_color, uv_interp + vec2(-2.0, 1.0) * pix_size, lod) * 0.122589;
|
||||
color += textureLod(source_color, uv_interp + vec2(-3.0, 1.0) * pix_size, lod) * 0.093095;
|
||||
color += textureLod(source_color, uv_interp + vec2(-4.0, 1.0) * pix_size, lod) * 0.063327;
|
||||
color *= 0.5;
|
||||
#else
|
||||
vec4 color = textureLod(source_color, uv_interp + vec2(0.0, 0.0) * pix_size, lod) * 0.174938;
|
||||
color += textureLod(source_color, uv_interp + vec2(1.0, 0.0) * pix_size, lod) * 0.165569;
|
||||
color += textureLod(source_color, uv_interp + vec2(2.0, 0.0) * pix_size, lod) * 0.140367;
|
||||
color += textureLod(source_color, uv_interp + vec2(3.0, 0.0) * pix_size, lod) * 0.106595;
|
||||
color += textureLod(source_color, uv_interp + vec2(-1.0, 0.0) * pix_size, lod) * 0.165569;
|
||||
color += textureLod(source_color, uv_interp + vec2(-2.0, 0.0) * pix_size, lod) * 0.140367;
|
||||
color += textureLod(source_color, uv_interp + vec2(-3.0, 0.0) * pix_size, lod) * 0.106595;
|
||||
#endif //USE_GLOW_HIGH_QUALITY
|
||||
|
||||
color *= glow_strength;
|
||||
frag_color = color;
|
||||
#endif //GLOW_GAUSSIAN_HORIZONTAL
|
||||
|
||||
#ifdef GLOW_GAUSSIAN_VERTICAL
|
||||
vec4 color = textureLod(source_color, uv_interp + vec2(0.0, 0.0) * pixel_size, lod) * 0.288713;
|
||||
color += textureLod(source_color, uv_interp + vec2(0.0, 1.0) * pixel_size, lod) * 0.233062;
|
||||
color += textureLod(source_color, uv_interp + vec2(0.0, 2.0) * pixel_size, lod) * 0.122581;
|
||||
color += textureLod(source_color, uv_interp + vec2(0.0, -1.0) * pixel_size, lod) * 0.233062;
|
||||
color += textureLod(source_color, uv_interp + vec2(0.0, -2.0) * pixel_size, lod) * 0.122581;
|
||||
color *= glow_strength;
|
||||
frag_color = color;
|
||||
#endif
|
||||
|
||||
#ifdef DOF_FAR_BLUR
|
||||
|
||||
vec4 color_accum = vec4(0.0);
|
||||
|
||||
float depth = textureLod(dof_source_depth, uv_interp, 0.0).r;
|
||||
depth = depth * 2.0 - 1.0;
|
||||
#ifdef USE_ORTHOGONAL_PROJECTION
|
||||
depth = ((depth + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0;
|
||||
#else
|
||||
depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth * (camera_z_far - camera_z_near));
|
||||
#endif
|
||||
|
||||
float amount = smoothstep(dof_begin, dof_end, depth);
|
||||
float k_accum = 0.0;
|
||||
|
||||
for (int i = 0; i < dof_kernel_size; i++) {
|
||||
int int_ofs = i - dof_kernel_from;
|
||||
vec2 tap_uv = uv_interp + dof_dir * float(int_ofs) * amount * dof_radius;
|
||||
|
||||
float tap_k = dof_kernel[i];
|
||||
|
||||
float tap_depth = texture(dof_source_depth, tap_uv, 0.0).r;
|
||||
tap_depth = tap_depth * 2.0 - 1.0;
|
||||
#ifdef USE_ORTHOGONAL_PROJECTION
|
||||
tap_depth = ((tap_depth + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0;
|
||||
#else
|
||||
tap_depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - tap_depth * (camera_z_far - camera_z_near));
|
||||
#endif
|
||||
float tap_amount = mix(smoothstep(dof_begin, dof_end, tap_depth), 1.0, int_ofs == 0);
|
||||
tap_amount *= tap_amount * tap_amount; //prevent undesired glow effect
|
||||
|
||||
vec4 tap_color = textureLod(source_color, tap_uv, 0.0) * tap_k;
|
||||
|
||||
k_accum += tap_k * tap_amount;
|
||||
color_accum += tap_color * tap_amount;
|
||||
}
|
||||
|
||||
if (k_accum > 0.0) {
|
||||
color_accum /= k_accum;
|
||||
}
|
||||
|
||||
frag_color = color_accum; ///k_accum;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef DOF_NEAR_BLUR
|
||||
|
||||
vec4 color_accum = vec4(0.0);
|
||||
|
||||
float max_accum = 0.0;
|
||||
|
||||
for (int i = 0; i < dof_kernel_size; i++) {
|
||||
int int_ofs = i - dof_kernel_from;
|
||||
vec2 tap_uv = uv_interp + dof_dir * float(int_ofs) * dof_radius;
|
||||
float ofs_influence = max(0.0, 1.0 - float(abs(int_ofs)) / float(dof_kernel_from));
|
||||
|
||||
float tap_k = dof_kernel[i];
|
||||
|
||||
vec4 tap_color = textureLod(source_color, tap_uv, 0.0);
|
||||
|
||||
float tap_depth = texture(dof_source_depth, tap_uv, 0.0).r;
|
||||
tap_depth = tap_depth * 2.0 - 1.0;
|
||||
#ifdef USE_ORTHOGONAL_PROJECTION
|
||||
tap_depth = ((tap_depth + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0;
|
||||
#else
|
||||
tap_depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - tap_depth * (camera_z_far - camera_z_near));
|
||||
#endif
|
||||
float tap_amount = 1.0 - smoothstep(dof_end, dof_begin, tap_depth);
|
||||
tap_amount *= tap_amount * tap_amount; //prevent undesired glow effect
|
||||
|
||||
#ifdef DOF_NEAR_FIRST_TAP
|
||||
|
||||
tap_color.a = 1.0 - smoothstep(dof_end, dof_begin, tap_depth);
|
||||
|
||||
#endif
|
||||
|
||||
max_accum = max(max_accum, tap_amount * ofs_influence);
|
||||
|
||||
color_accum += tap_color * tap_k;
|
||||
}
|
||||
|
||||
color_accum.a = max(color_accum.a, sqrt(max_accum));
|
||||
|
||||
#ifdef DOF_NEAR_BLUR_MERGE
|
||||
|
||||
vec4 original = textureLod(source_dof_original, uv_interp, 0.0);
|
||||
color_accum = mix(original, color_accum, color_accum.a);
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef DOF_NEAR_FIRST_TAP
|
||||
//color_accum=vec4(vec3(color_accum.a),1.0);
|
||||
#endif
|
||||
frag_color = color_accum;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef GLOW_FIRST_PASS
|
||||
|
||||
#ifdef GLOW_USE_AUTO_EXPOSURE
|
||||
|
||||
frag_color /= texelFetch(source_auto_exposure, ivec2(0, 0), 0).r / auto_exposure_grey;
|
||||
#endif
|
||||
frag_color *= exposure;
|
||||
|
||||
float luminance = max(frag_color.r, max(frag_color.g, frag_color.b));
|
||||
float feedback = max(smoothstep(glow_hdr_threshold, glow_hdr_threshold + glow_hdr_scale, luminance), glow_bloom);
|
||||
|
||||
frag_color = min(frag_color * feedback, vec4(luminance_cap));
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SIMPLE_COPY
|
||||
vec4 color = textureLod(source_color, uv_interp, 0.0);
|
||||
frag_color = color;
|
||||
#endif
|
||||
|
||||
#ifdef SSAO_MERGE
|
||||
|
||||
vec4 color = textureLod(source_color, uv_interp, 0.0);
|
||||
float ssao = textureLod(source_ssao, uv_interp, 0.0).r;
|
||||
|
||||
frag_color = vec4(mix(color.rgb, color.rgb * mix(ssao_color.rgb, vec3(1.0), ssao), color.a), 1.0);
|
||||
|
||||
#endif
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec4 vertex_attrib;
|
||||
/* clang-format on */
|
||||
|
||||
void main() {
|
||||
gl_Position = vertex_attrib;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
uniform highp sampler2D source_exposure; //texunit:0
|
||||
/* clang-format on */
|
||||
|
||||
#ifdef EXPOSURE_BEGIN
|
||||
|
||||
uniform highp ivec2 source_render_size;
|
||||
uniform highp ivec2 target_size;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef EXPOSURE_END
|
||||
|
||||
uniform highp sampler2D prev_exposure; //texunit:1
|
||||
uniform highp float exposure_adjust;
|
||||
uniform highp float min_luminance;
|
||||
uniform highp float max_luminance;
|
||||
|
||||
#endif
|
||||
|
||||
layout(location = 0) out highp float exposure;
|
||||
|
||||
void main() {
|
||||
#ifdef EXPOSURE_BEGIN
|
||||
|
||||
ivec2 src_pos = ivec2(gl_FragCoord.xy) * source_render_size / target_size;
|
||||
|
||||
#if 1
|
||||
//more precise and expensive, but less jittery
|
||||
ivec2 next_pos = (ivec2(gl_FragCoord.xy) + ivec2(1)) * source_render_size / target_size;
|
||||
next_pos = max(next_pos, src_pos + ivec2(1)); //so it at least reads one pixel
|
||||
highp vec3 source_color = vec3(0.0);
|
||||
for (int i = src_pos.x; i < next_pos.x; i++) {
|
||||
for (int j = src_pos.y; j < next_pos.y; j++) {
|
||||
source_color += texelFetch(source_exposure, ivec2(i, j), 0).rgb;
|
||||
}
|
||||
}
|
||||
|
||||
source_color /= float((next_pos.x - src_pos.x) * (next_pos.y - src_pos.y));
|
||||
#else
|
||||
highp vec3 source_color = texelFetch(source_exposure, src_pos, 0).rgb;
|
||||
|
||||
#endif
|
||||
|
||||
exposure = max(source_color.r, max(source_color.g, source_color.b));
|
||||
|
||||
#else
|
||||
|
||||
ivec2 coord = ivec2(gl_FragCoord.xy);
|
||||
exposure = texelFetch(source_exposure, coord * 3 + ivec2(0, 0), 0).r;
|
||||
exposure += texelFetch(source_exposure, coord * 3 + ivec2(1, 0), 0).r;
|
||||
exposure += texelFetch(source_exposure, coord * 3 + ivec2(2, 0), 0).r;
|
||||
exposure += texelFetch(source_exposure, coord * 3 + ivec2(0, 1), 0).r;
|
||||
exposure += texelFetch(source_exposure, coord * 3 + ivec2(1, 1), 0).r;
|
||||
exposure += texelFetch(source_exposure, coord * 3 + ivec2(2, 1), 0).r;
|
||||
exposure += texelFetch(source_exposure, coord * 3 + ivec2(0, 2), 0).r;
|
||||
exposure += texelFetch(source_exposure, coord * 3 + ivec2(1, 2), 0).r;
|
||||
exposure += texelFetch(source_exposure, coord * 3 + ivec2(2, 2), 0).r;
|
||||
exposure *= (1.0 / 9.0);
|
||||
|
||||
#ifdef EXPOSURE_END
|
||||
|
||||
#ifdef EXPOSURE_FORCE_SET
|
||||
//will stay as is
|
||||
#else
|
||||
highp float prev_lum = texelFetch(prev_exposure, ivec2(0, 0), 0).r; //1 pixel previous exposure
|
||||
exposure = clamp(prev_lum + (exposure - prev_lum) * exposure_adjust, min_luminance, max_luminance);
|
||||
|
||||
#endif //EXPOSURE_FORCE_SET
|
||||
|
||||
#endif //EXPOSURE_END
|
||||
|
||||
#endif //EXPOSURE_BEGIN
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec4 vertex_attrib;
|
||||
/* clang-format on */
|
||||
|
||||
uniform vec2 offset;
|
||||
uniform vec2 scale;
|
||||
|
||||
out vec2 uv_interp;
|
||||
|
||||
void main() {
|
||||
uv_interp = vertex_attrib.xy * 2.0 - 1.0;
|
||||
|
||||
vec2 v = vertex_attrib.xy * scale + offset;
|
||||
gl_Position = vec4(v, 0.0, 1.0);
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
uniform sampler2D source; //texunit:0
|
||||
/* clang-format on */
|
||||
|
||||
uniform vec2 eye_center;
|
||||
uniform float k1;
|
||||
uniform float k2;
|
||||
uniform float upscale;
|
||||
uniform float aspect_ratio;
|
||||
|
||||
in vec2 uv_interp;
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
vec2 coords = uv_interp;
|
||||
vec2 offset = coords - eye_center;
|
||||
|
||||
// take aspect ratio into account
|
||||
offset.y /= aspect_ratio;
|
||||
|
||||
// distort
|
||||
vec2 offset_sq = offset * offset;
|
||||
float radius_sq = offset_sq.x + offset_sq.y;
|
||||
float radius_s4 = radius_sq * radius_sq;
|
||||
float distortion_scale = 1.0 + (k1 * radius_sq) + (k2 * radius_s4);
|
||||
offset *= distortion_scale;
|
||||
|
||||
// reapply aspect ratio
|
||||
offset.y *= aspect_ratio;
|
||||
|
||||
// add our eye center back in
|
||||
coords = offset + eye_center;
|
||||
coords /= upscale;
|
||||
|
||||
// and check our color
|
||||
if (coords.x < -1.0 || coords.y < -1.0 || coords.x > 1.0 || coords.y > 1.0) {
|
||||
frag_color = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
} else {
|
||||
coords = (coords + vec2(1.0)) / vec2(2.0);
|
||||
frag_color = textureLod(source, coords, 0.0);
|
||||
}
|
||||
}
|
@ -1,256 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
#if defined(IS_UBERSHADER)
|
||||
uniform highp uint ubershader_flags;
|
||||
#endif
|
||||
|
||||
layout(location = 0) in highp vec4 color;
|
||||
/* clang-format on */
|
||||
layout(location = 1) in highp vec4 velocity_active;
|
||||
layout(location = 2) in highp vec4 custom;
|
||||
layout(location = 3) in highp vec4 xform_1;
|
||||
layout(location = 4) in highp vec4 xform_2;
|
||||
layout(location = 5) in highp vec4 xform_3;
|
||||
|
||||
struct Attractor {
|
||||
vec3 pos;
|
||||
vec3 dir;
|
||||
float radius;
|
||||
float eat_radius;
|
||||
float strength;
|
||||
float attenuation;
|
||||
};
|
||||
|
||||
#define MAX_ATTRACTORS 64
|
||||
|
||||
uniform bool emitting;
|
||||
uniform float system_phase;
|
||||
uniform float prev_system_phase;
|
||||
uniform int total_particles;
|
||||
uniform float explosiveness;
|
||||
uniform float randomness;
|
||||
uniform float time;
|
||||
uniform float delta;
|
||||
|
||||
uniform int attractor_count;
|
||||
uniform Attractor attractors[MAX_ATTRACTORS];
|
||||
uniform bool clear;
|
||||
uniform uint cycle;
|
||||
uniform float lifetime;
|
||||
uniform mat4 emission_transform;
|
||||
uniform uint random_seed;
|
||||
|
||||
out highp vec4 out_color; //tfb:
|
||||
out highp vec4 out_velocity_active; //tfb:
|
||||
out highp vec4 out_custom; //tfb:
|
||||
out highp vec4 out_xform_1; //tfb:
|
||||
out highp vec4 out_xform_2; //tfb:
|
||||
out highp vec4 out_xform_3; //tfb:
|
||||
|
||||
#if defined(USE_MATERIAL)
|
||||
|
||||
/* clang-format off */
|
||||
layout(std140) uniform UniformData { //ubo:0
|
||||
|
||||
MATERIAL_UNIFORMS
|
||||
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
VERTEX_SHADER_GLOBALS
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
uint hash(uint x) {
|
||||
x = ((x >> uint(16)) ^ x) * uint(0x45d9f3b);
|
||||
x = ((x >> uint(16)) ^ x) * uint(0x45d9f3b);
|
||||
x = (x >> uint(16)) ^ x;
|
||||
return x;
|
||||
}
|
||||
|
||||
void main() {
|
||||
bool apply_forces = true;
|
||||
bool apply_velocity = true;
|
||||
float local_delta = delta;
|
||||
|
||||
float mass = 1.0;
|
||||
|
||||
float restart_phase = float(gl_VertexID) / float(total_particles);
|
||||
|
||||
if (randomness > 0.0) {
|
||||
uint seed = cycle;
|
||||
if (restart_phase >= system_phase) {
|
||||
seed -= uint(1);
|
||||
}
|
||||
seed *= uint(total_particles);
|
||||
seed += uint(gl_VertexID);
|
||||
float random = float(hash(seed) % uint(65536)) / 65536.0;
|
||||
restart_phase += randomness * random * 1.0 / float(total_particles);
|
||||
}
|
||||
|
||||
restart_phase *= (1.0 - explosiveness);
|
||||
bool restart = false;
|
||||
bool shader_active = velocity_active.a > 0.5;
|
||||
|
||||
if (system_phase > prev_system_phase) {
|
||||
// restart_phase >= prev_system_phase is used so particles emit in the first frame they are processed
|
||||
|
||||
if (restart_phase >= prev_system_phase && restart_phase < system_phase) {
|
||||
restart = true;
|
||||
#ifdef USE_FRACTIONAL_DELTA //ubershader-runtime
|
||||
local_delta = (system_phase - restart_phase) * lifetime;
|
||||
#endif //ubershader-runtime
|
||||
}
|
||||
|
||||
} else if (delta > 0.0) {
|
||||
if (restart_phase >= prev_system_phase) {
|
||||
restart = true;
|
||||
#ifdef USE_FRACTIONAL_DELTA //ubershader-runtime
|
||||
local_delta = (1.0 - restart_phase + system_phase) * lifetime;
|
||||
#endif //ubershader-runtime
|
||||
} else if (restart_phase < system_phase) {
|
||||
restart = true;
|
||||
#ifdef USE_FRACTIONAL_DELTA //ubershader-runtime
|
||||
local_delta = (system_phase - restart_phase) * lifetime;
|
||||
#endif //ubershader-runtime
|
||||
}
|
||||
}
|
||||
|
||||
uint current_cycle = cycle;
|
||||
|
||||
if (system_phase < restart_phase) {
|
||||
current_cycle -= uint(1);
|
||||
}
|
||||
|
||||
uint particle_number = current_cycle * uint(total_particles) + uint(gl_VertexID);
|
||||
int index = int(gl_VertexID);
|
||||
|
||||
if (restart) {
|
||||
shader_active = emitting;
|
||||
}
|
||||
|
||||
mat4 xform;
|
||||
|
||||
#if defined(ENABLE_KEEP_DATA)
|
||||
if (clear) {
|
||||
#else
|
||||
if (clear || restart) {
|
||||
#endif
|
||||
out_color = vec4(1.0);
|
||||
out_velocity_active = vec4(0.0);
|
||||
out_custom = vec4(0.0);
|
||||
if (!restart)
|
||||
shader_active = false;
|
||||
|
||||
xform = mat4(
|
||||
vec4(1.0, 0.0, 0.0, 0.0),
|
||||
vec4(0.0, 1.0, 0.0, 0.0),
|
||||
vec4(0.0, 0.0, 1.0, 0.0),
|
||||
vec4(0.0, 0.0, 0.0, 1.0));
|
||||
} else {
|
||||
out_color = color;
|
||||
out_velocity_active = velocity_active;
|
||||
out_custom = custom;
|
||||
xform = transpose(mat4(xform_1, xform_2, xform_3, vec4(vec3(0.0), 1.0)));
|
||||
}
|
||||
|
||||
if (shader_active) {
|
||||
//execute shader
|
||||
|
||||
{
|
||||
/* clang-format off */
|
||||
|
||||
VERTEX_SHADER_CODE
|
||||
|
||||
/* clang-format on */
|
||||
}
|
||||
|
||||
#if !defined(DISABLE_FORCE)
|
||||
|
||||
if (false) {
|
||||
vec3 force = vec3(0.0);
|
||||
for (int i = 0; i < attractor_count; i++) {
|
||||
vec3 rel_vec = xform[3].xyz - attractors[i].pos;
|
||||
float dist = length(rel_vec);
|
||||
if (attractors[i].radius < dist)
|
||||
continue;
|
||||
if (attractors[i].eat_radius > 0.0 && attractors[i].eat_radius > dist) {
|
||||
out_velocity_active.a = 0.0;
|
||||
}
|
||||
|
||||
rel_vec = normalize(rel_vec);
|
||||
|
||||
float attenuation = pow(dist / attractors[i].radius, attractors[i].attenuation);
|
||||
|
||||
if (attractors[i].dir == vec3(0.0)) {
|
||||
//towards center
|
||||
force += attractors[i].strength * rel_vec * attenuation * mass;
|
||||
} else {
|
||||
force += attractors[i].strength * attractors[i].dir * attenuation * mass;
|
||||
}
|
||||
}
|
||||
|
||||
out_velocity_active.xyz += force * local_delta;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(DISABLE_VELOCITY)
|
||||
|
||||
if (true) {
|
||||
xform[3].xyz += out_velocity_active.xyz * local_delta;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
xform = mat4(0.0);
|
||||
}
|
||||
|
||||
xform = transpose(xform);
|
||||
|
||||
out_velocity_active.a = mix(0.0, 1.0, shader_active);
|
||||
|
||||
out_xform_1 = xform[0];
|
||||
out_xform_2 = xform[1];
|
||||
out_xform_3 = xform[2];
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
#if defined(IS_UBERSHADER)
|
||||
uniform highp uint ubershader_flags;
|
||||
#endif
|
||||
|
||||
// any code here is never executed, stuff is filled just so it works
|
||||
|
||||
#if defined(USE_MATERIAL)
|
||||
|
||||
layout(std140) uniform UniformData {
|
||||
|
||||
MATERIAL_UNIFORMS
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
FRAGMENT_SHADER_GLOBALS
|
||||
|
||||
void main() {
|
||||
|
||||
{
|
||||
|
||||
LIGHT_SHADER_CODE
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
FRAGMENT_SHADER_CODE
|
||||
|
||||
}
|
||||
}
|
||||
/* clang-format on */
|
@ -1,42 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec4 vertex_attrib;
|
||||
/* clang-format on */
|
||||
layout(location = 4) in vec2 uv_in;
|
||||
|
||||
out vec2 uv_interp;
|
||||
|
||||
void main() {
|
||||
uv_interp = uv_in;
|
||||
gl_Position = vertex_attrib;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
#if !defined(GLES_OVER_GL)
|
||||
precision mediump float;
|
||||
#endif
|
||||
/* clang-format on */
|
||||
|
||||
in vec2 uv_interp;
|
||||
uniform sampler2D source_specular; // texunit:0
|
||||
uniform sampler2D source_ssr; // texunit:1
|
||||
|
||||
uniform vec2 pixel_size;
|
||||
|
||||
in vec2 uv2_interp;
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
vec4 specular = texture(source_specular, uv_interp);
|
||||
|
||||
#ifdef USE_SSR
|
||||
vec4 ssr = textureLod(source_ssr, uv_interp, 0.0);
|
||||
specular.rgb = mix(specular.rgb, ssr.rgb * specular.a, ssr.a);
|
||||
#endif
|
||||
|
||||
frag_color = vec4(specular.rgb, 1.0);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,281 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec4 vertex_attrib;
|
||||
/* clang-format on */
|
||||
layout(location = 4) in vec2 uv_in;
|
||||
|
||||
out vec2 uv_interp;
|
||||
out vec2 pos_interp;
|
||||
|
||||
void main() {
|
||||
uv_interp = uv_in;
|
||||
gl_Position = vertex_attrib;
|
||||
pos_interp.xy = gl_Position.xy;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
in vec2 uv_interp;
|
||||
/* clang-format on */
|
||||
in vec2 pos_interp;
|
||||
|
||||
uniform sampler2D source_diffuse; //texunit:0
|
||||
uniform sampler2D source_normal_roughness; //texunit:1
|
||||
uniform sampler2D source_depth; //texunit:2
|
||||
|
||||
uniform float camera_z_near;
|
||||
uniform float camera_z_far;
|
||||
|
||||
uniform vec2 viewport_size;
|
||||
uniform vec2 pixel_size;
|
||||
|
||||
uniform float filter_mipmap_levels;
|
||||
|
||||
uniform mat4 inverse_projection;
|
||||
uniform mat4 projection;
|
||||
|
||||
uniform int num_steps;
|
||||
uniform float depth_tolerance;
|
||||
uniform float distance_fade;
|
||||
uniform float curve_fade_in;
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
vec2 view_to_screen(vec3 view_pos, out float w) {
|
||||
vec4 projected = projection * vec4(view_pos, 1.0);
|
||||
projected.xyz /= projected.w;
|
||||
projected.xy = projected.xy * 0.5 + 0.5;
|
||||
w = projected.w;
|
||||
return projected.xy;
|
||||
}
|
||||
|
||||
#define M_PI 3.14159265359
|
||||
|
||||
void main() {
|
||||
vec4 diffuse = texture(source_diffuse, uv_interp);
|
||||
vec4 normal_roughness = texture(source_normal_roughness, uv_interp);
|
||||
|
||||
vec3 normal;
|
||||
normal = normal_roughness.xyz * 2.0 - 1.0;
|
||||
|
||||
float roughness = normal_roughness.w;
|
||||
|
||||
float depth_tex = texture(source_depth, uv_interp).r;
|
||||
|
||||
vec4 world_pos = inverse_projection * vec4(uv_interp * 2.0 - 1.0, depth_tex * 2.0 - 1.0, 1.0);
|
||||
vec3 vertex = world_pos.xyz / world_pos.w;
|
||||
|
||||
vec3 view_dir = normalize(vertex);
|
||||
vec3 ray_dir = normalize(reflect(view_dir, normal));
|
||||
|
||||
if (dot(ray_dir, normal) < 0.001) {
|
||||
frag_color = vec4(0.0);
|
||||
return;
|
||||
}
|
||||
//ray_dir = normalize(view_dir - normal * dot(normal,view_dir) * 2.0);
|
||||
//ray_dir = normalize(vec3(1.0, 1.0, -1.0));
|
||||
|
||||
////////////////
|
||||
|
||||
// make ray length and clip it against the near plane (don't want to trace beyond visible)
|
||||
float ray_len = (vertex.z + ray_dir.z * camera_z_far) > -camera_z_near ? (-camera_z_near - vertex.z) / ray_dir.z : camera_z_far;
|
||||
vec3 ray_end = vertex + ray_dir * ray_len;
|
||||
|
||||
float w_begin;
|
||||
vec2 vp_line_begin = view_to_screen(vertex, w_begin);
|
||||
float w_end;
|
||||
vec2 vp_line_end = view_to_screen(ray_end, w_end);
|
||||
vec2 vp_line_dir = vp_line_end - vp_line_begin;
|
||||
|
||||
// we need to interpolate w along the ray, to generate perspective correct reflections
|
||||
w_begin = 1.0 / w_begin;
|
||||
w_end = 1.0 / w_end;
|
||||
|
||||
float z_begin = vertex.z * w_begin;
|
||||
float z_end = ray_end.z * w_end;
|
||||
|
||||
vec2 line_begin = vp_line_begin / pixel_size;
|
||||
vec2 line_dir = vp_line_dir / pixel_size;
|
||||
float z_dir = z_end - z_begin;
|
||||
float w_dir = w_end - w_begin;
|
||||
|
||||
// clip the line to the viewport edges
|
||||
|
||||
float scale_max_x = min(1.0, 0.99 * (1.0 - vp_line_begin.x) / max(1e-5, vp_line_dir.x));
|
||||
float scale_max_y = min(1.0, 0.99 * (1.0 - vp_line_begin.y) / max(1e-5, vp_line_dir.y));
|
||||
float scale_min_x = min(1.0, 0.99 * vp_line_begin.x / max(1e-5, -vp_line_dir.x));
|
||||
float scale_min_y = min(1.0, 0.99 * vp_line_begin.y / max(1e-5, -vp_line_dir.y));
|
||||
float line_clip = min(scale_max_x, scale_max_y) * min(scale_min_x, scale_min_y);
|
||||
line_dir *= line_clip;
|
||||
z_dir *= line_clip;
|
||||
w_dir *= line_clip;
|
||||
|
||||
// clip z and w advance to line advance
|
||||
vec2 line_advance = normalize(line_dir); // down to pixel
|
||||
float step_size = length(line_advance) / length(line_dir);
|
||||
float z_advance = z_dir * step_size; // adapt z advance to line advance
|
||||
float w_advance = w_dir * step_size; // adapt w advance to line advance
|
||||
|
||||
// make line advance faster if direction is closer to pixel edges (this avoids sampling the same pixel twice)
|
||||
float advance_angle_adj = 1.0 / max(abs(line_advance.x), abs(line_advance.y));
|
||||
line_advance *= advance_angle_adj; // adapt z advance to line advance
|
||||
z_advance *= advance_angle_adj;
|
||||
w_advance *= advance_angle_adj;
|
||||
|
||||
vec2 pos = line_begin;
|
||||
float z = z_begin;
|
||||
float w = w_begin;
|
||||
float z_from = z / w;
|
||||
float z_to = z_from;
|
||||
float depth;
|
||||
vec2 prev_pos = pos;
|
||||
|
||||
bool found = false;
|
||||
|
||||
float steps_taken = 0.0;
|
||||
|
||||
for (int i = 0; i < num_steps; i++) {
|
||||
pos += line_advance;
|
||||
z += z_advance;
|
||||
w += w_advance;
|
||||
|
||||
// convert to linear depth
|
||||
|
||||
depth = texture(source_depth, pos * pixel_size).r * 2.0 - 1.0;
|
||||
#ifdef USE_ORTHOGONAL_PROJECTION
|
||||
depth = ((depth + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0;
|
||||
#else
|
||||
depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth * (camera_z_far - camera_z_near));
|
||||
#endif
|
||||
depth = -depth;
|
||||
|
||||
z_from = z_to;
|
||||
z_to = z / w;
|
||||
|
||||
if (depth > z_to) {
|
||||
// if depth was surpassed
|
||||
if ((depth <= max(z_to, z_from) + depth_tolerance) && (-depth < camera_z_far)) {
|
||||
// check the depth tolerance and far clip
|
||||
found = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
steps_taken += 1.0;
|
||||
prev_pos = pos;
|
||||
}
|
||||
|
||||
if (found) {
|
||||
float margin_blend = 1.0;
|
||||
|
||||
vec2 margin = vec2((viewport_size.x + viewport_size.y) * 0.5 * 0.05); // make a uniform margin
|
||||
if (any(bvec4(lessThan(pos, vec2(0.0, 0.0)), greaterThan(pos, viewport_size * 0.5)))) {
|
||||
// clip at the screen edges
|
||||
frag_color = vec4(0.0);
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
//blend fading out towards inner margin
|
||||
// 0.25 = midpoint of half-resolution reflection
|
||||
vec2 margin_grad = mix(viewport_size * 0.5 - pos, pos, lessThan(pos, viewport_size * 0.25));
|
||||
margin_blend = smoothstep(0.0, margin.x * margin.y, margin_grad.x * margin_grad.y);
|
||||
//margin_blend = 1.0;
|
||||
}
|
||||
|
||||
vec2 final_pos;
|
||||
float grad = (steps_taken + 1.0) / float(num_steps);
|
||||
float initial_fade = curve_fade_in == 0.0 ? 1.0 : pow(clamp(grad, 0.0, 1.0), curve_fade_in);
|
||||
float fade = pow(clamp(1.0 - grad, 0.0, 1.0), distance_fade) * initial_fade;
|
||||
final_pos = pos;
|
||||
|
||||
#ifdef REFLECT_ROUGHNESS
|
||||
|
||||
vec4 final_color;
|
||||
// if roughness is enabled, do screen space cone tracing
|
||||
if (roughness > 0.001) {
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
// use a blurred version (in consecutive mipmaps) of the screen to simulate roughness
|
||||
|
||||
float gloss = 1.0 - roughness;
|
||||
float cone_angle = roughness * M_PI * 0.5;
|
||||
vec2 cone_dir = final_pos - line_begin;
|
||||
float cone_len = length(cone_dir);
|
||||
cone_dir = normalize(cone_dir); // will be used normalized from now on
|
||||
float max_mipmap = filter_mipmap_levels - 1.0;
|
||||
float gloss_mult = gloss;
|
||||
|
||||
float rem_alpha = 1.0;
|
||||
final_color = vec4(0.0);
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
float op_len = 2.0 * tan(cone_angle) * cone_len; // opposite side of iso triangle
|
||||
float radius;
|
||||
{
|
||||
// fit to sphere inside cone (sphere ends at end of cone), something like this:
|
||||
// ___
|
||||
// \O/
|
||||
// V
|
||||
//
|
||||
// as it avoids bleeding from beyond the reflection as much as possible. As a plus
|
||||
// it also makes the rough reflection more elongated.
|
||||
float a = op_len;
|
||||
float h = cone_len;
|
||||
float a2 = a * a;
|
||||
float fh2 = 4.0f * h * h;
|
||||
radius = (a * (sqrt(a2 + fh2) - a)) / (4.0f * h);
|
||||
}
|
||||
|
||||
// find the place where screen must be sampled
|
||||
vec2 sample_pos = (line_begin + cone_dir * (cone_len - radius)) * pixel_size;
|
||||
// radius is in pixels, so it's natural that log2(radius) maps to the right mipmap for the amount of pixels
|
||||
float mipmap = clamp(log2(radius), 0.0, max_mipmap);
|
||||
//mipmap = max(mipmap - 1.0, 0.0);
|
||||
|
||||
// do sampling
|
||||
|
||||
vec4 sample_color;
|
||||
{
|
||||
sample_color = textureLod(source_diffuse, sample_pos, mipmap);
|
||||
}
|
||||
|
||||
// multiply by gloss
|
||||
sample_color.rgb *= gloss_mult;
|
||||
sample_color.a = gloss_mult;
|
||||
|
||||
rem_alpha -= sample_color.a;
|
||||
if (rem_alpha < 0.0) {
|
||||
sample_color.rgb *= (1.0 - abs(rem_alpha));
|
||||
}
|
||||
|
||||
final_color += sample_color;
|
||||
|
||||
if (final_color.a >= 0.95) {
|
||||
// This code of accumulating gloss and aborting on near one
|
||||
// makes sense when you think of cone tracing.
|
||||
// Think of it as if roughness was 0, then we could abort on the first
|
||||
// iteration. For lesser roughness values, we need more iterations, but
|
||||
// each needs to have less influence given the sphere is smaller
|
||||
break;
|
||||
}
|
||||
|
||||
cone_len -= radius * 2.0; // go to next (smaller) circle.
|
||||
|
||||
gloss_mult *= gloss;
|
||||
}
|
||||
} else {
|
||||
final_color = textureLod(source_diffuse, final_pos * pixel_size, 0.0);
|
||||
}
|
||||
|
||||
frag_color = vec4(final_color.rgb, fade * margin_blend);
|
||||
|
||||
#else
|
||||
frag_color = vec4(textureLod(source_diffuse, final_pos * pixel_size, 0.0).rgb, fade * margin_blend);
|
||||
#endif
|
||||
|
||||
} else {
|
||||
frag_color = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
@ -1,276 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec4 vertex_attrib;
|
||||
/* clang-format on */
|
||||
|
||||
void main() {
|
||||
gl_Position = vertex_attrib;
|
||||
gl_Position.z = 1.0;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
#define TWO_PI 6.283185307179586476925286766559
|
||||
|
||||
#ifdef SSAO_QUALITY_HIGH
|
||||
#define NUM_SAMPLES (16)
|
||||
#endif
|
||||
|
||||
#ifdef SSAO_QUALITY_LOW
|
||||
#define NUM_SAMPLES (8)
|
||||
#endif
|
||||
|
||||
#if !defined(SSAO_QUALITY_LOW) && !defined(SSAO_QUALITY_HIGH)
|
||||
#define NUM_SAMPLES (12)
|
||||
#endif
|
||||
|
||||
// If using depth mip levels, the log of the maximum pixel offset before we need to switch to a lower
|
||||
// miplevel to maintain reasonable spatial locality in the cache
|
||||
// If this number is too small (< 3), too many taps will land in the same pixel, and we'll get bad variance that manifests as flashing.
|
||||
// If it is too high (> 5), we'll get bad performance because we're not using the MIP levels effectively
|
||||
#define LOG_MAX_OFFSET (3)
|
||||
|
||||
// This must be less than or equal to the MAX_MIP_LEVEL defined in SSAO.cpp
|
||||
#define MAX_MIP_LEVEL (4)
|
||||
|
||||
// This is the number of turns around the circle that the spiral pattern makes. This should be prime to prevent
|
||||
// taps from lining up. This particular choice was tuned for NUM_SAMPLES == 9
|
||||
|
||||
const int ROTATIONS[] = int[](
|
||||
1, 1, 2, 3, 2, 5, 2, 3, 2,
|
||||
3, 3, 5, 5, 3, 4, 7, 5, 5, 7,
|
||||
9, 8, 5, 5, 7, 7, 7, 8, 5, 8,
|
||||
11, 12, 7, 10, 13, 8, 11, 8, 7, 14,
|
||||
11, 11, 13, 12, 13, 19, 17, 13, 11, 18,
|
||||
19, 11, 11, 14, 17, 21, 15, 16, 17, 18,
|
||||
13, 17, 11, 17, 19, 18, 25, 18, 19, 19,
|
||||
29, 21, 19, 27, 31, 29, 21, 18, 17, 29,
|
||||
31, 31, 23, 18, 25, 26, 25, 23, 19, 34,
|
||||
19, 27, 21, 25, 39, 29, 17, 21, 27);
|
||||
/* clang-format on */
|
||||
|
||||
//#define NUM_SPIRAL_TURNS (7)
|
||||
const int NUM_SPIRAL_TURNS = ROTATIONS[NUM_SAMPLES - 1];
|
||||
|
||||
uniform sampler2D source_depth; //texunit:0
|
||||
uniform highp usampler2D source_depth_mipmaps; //texunit:1
|
||||
uniform sampler2D source_normal; //texunit:2
|
||||
|
||||
uniform ivec2 screen_size;
|
||||
uniform float camera_z_far;
|
||||
uniform float camera_z_near;
|
||||
|
||||
uniform float intensity_div_r6;
|
||||
uniform float radius;
|
||||
|
||||
#ifdef ENABLE_RADIUS2
|
||||
uniform float intensity_div_r62;
|
||||
uniform float radius2;
|
||||
#endif
|
||||
|
||||
uniform float bias;
|
||||
uniform float proj_scale;
|
||||
|
||||
layout(location = 0) out float visibility;
|
||||
|
||||
uniform vec4 proj_info;
|
||||
|
||||
vec3 reconstructCSPosition(vec2 S, float z) {
|
||||
#ifdef USE_ORTHOGONAL_PROJECTION
|
||||
return vec3((S.xy * proj_info.xy + proj_info.zw), z);
|
||||
#else
|
||||
return vec3((S.xy * proj_info.xy + proj_info.zw) * z, z);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
vec3 getPosition(ivec2 ssP) {
|
||||
vec3 P;
|
||||
P.z = texelFetch(source_depth, ssP, 0).r;
|
||||
|
||||
P.z = P.z * 2.0 - 1.0;
|
||||
#ifdef USE_ORTHOGONAL_PROJECTION
|
||||
P.z = ((P.z + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0;
|
||||
#else
|
||||
P.z = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - P.z * (camera_z_far - camera_z_near));
|
||||
#endif
|
||||
P.z = -P.z;
|
||||
|
||||
// Offset to pixel center
|
||||
P = reconstructCSPosition(vec2(ssP) + vec2(0.5), P.z);
|
||||
return P;
|
||||
}
|
||||
|
||||
/** Reconstructs screen-space unit normal from screen-space position */
|
||||
vec3 reconstructCSFaceNormal(vec3 C) {
|
||||
return normalize(cross(dFdy(C), dFdx(C)));
|
||||
}
|
||||
|
||||
/** Returns a unit vector and a screen-space radius for the tap on a unit disk (the caller should scale by the actual disk radius) */
|
||||
vec2 tapLocation(int sampleNumber, float spinAngle, out float ssR) {
|
||||
// Radius relative to ssR
|
||||
float alpha = (float(sampleNumber) + 0.5) * (1.0 / float(NUM_SAMPLES));
|
||||
float angle = alpha * (float(NUM_SPIRAL_TURNS) * 6.28) + spinAngle;
|
||||
|
||||
ssR = alpha;
|
||||
return vec2(cos(angle), sin(angle));
|
||||
}
|
||||
|
||||
/** Read the camera-space position of the point at screen-space pixel ssP + unitOffset * ssR. Assumes length(unitOffset) == 1 */
|
||||
vec3 getOffsetPosition(ivec2 ssC, vec2 unitOffset, float ssR) {
|
||||
// Derivation:
|
||||
// mipLevel = floor(log(ssR / MAX_OFFSET));
|
||||
int mipLevel = clamp(int(floor(log2(ssR))) - LOG_MAX_OFFSET, 0, MAX_MIP_LEVEL);
|
||||
|
||||
ivec2 ssP = ivec2(ssR * unitOffset) + ssC;
|
||||
|
||||
vec3 P;
|
||||
|
||||
// We need to divide by 2^mipLevel to read the appropriately scaled coordinate from a MIP-map.
|
||||
// Manually clamp to the texture size because texelFetch bypasses the texture unit
|
||||
ivec2 mipP = clamp(ssP >> mipLevel, ivec2(0), (screen_size >> mipLevel) - ivec2(1));
|
||||
|
||||
if (mipLevel < 1) {
|
||||
//read from depth buffer
|
||||
P.z = texelFetch(source_depth, mipP, 0).r;
|
||||
P.z = P.z * 2.0 - 1.0;
|
||||
#ifdef USE_ORTHOGONAL_PROJECTION
|
||||
P.z = ((P.z + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0;
|
||||
#else
|
||||
P.z = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - P.z * (camera_z_far - camera_z_near));
|
||||
#endif
|
||||
P.z = -P.z;
|
||||
|
||||
} else {
|
||||
//read from mipmaps
|
||||
uint d = texelFetch(source_depth_mipmaps, mipP, mipLevel - 1).r;
|
||||
P.z = -(float(d) / 65535.0) * camera_z_far;
|
||||
}
|
||||
|
||||
// Offset to pixel center
|
||||
P = reconstructCSPosition(vec2(ssP) + vec2(0.5), P.z);
|
||||
|
||||
return P;
|
||||
}
|
||||
|
||||
/** Compute the occlusion due to sample with index \a i about the pixel at \a ssC that corresponds
|
||||
to camera-space point \a C with unit normal \a n_C, using maximum screen-space sampling radius \a ssDiskRadius
|
||||
|
||||
Note that units of H() in the HPG12 paper are meters, not
|
||||
unitless. The whole falloff/sampling function is therefore
|
||||
unitless. In this implementation, we factor out (9 / radius).
|
||||
|
||||
Four versions of the falloff function are implemented below
|
||||
*/
|
||||
float sampleAO(in ivec2 ssC, in vec3 C, in vec3 n_C, in float ssDiskRadius, in float p_radius, in int tapIndex, in float randomPatternRotationAngle) {
|
||||
// Offset on the unit disk, spun for this pixel
|
||||
float ssR;
|
||||
vec2 unitOffset = tapLocation(tapIndex, randomPatternRotationAngle, ssR);
|
||||
ssR *= ssDiskRadius;
|
||||
|
||||
// The occluding point in camera space
|
||||
vec3 Q = getOffsetPosition(ssC, unitOffset, ssR);
|
||||
|
||||
vec3 v = Q - C;
|
||||
|
||||
float vv = dot(v, v);
|
||||
float vn = dot(v, n_C);
|
||||
|
||||
const float epsilon = 0.01;
|
||||
float radius2 = p_radius * p_radius;
|
||||
|
||||
// A: From the HPG12 paper
|
||||
// Note large epsilon to avoid overdarkening within cracks
|
||||
//return float(vv < radius2) * max((vn - bias) / (epsilon + vv), 0.0) * radius2 * 0.6;
|
||||
|
||||
// B: Smoother transition to zero (lowers contrast, smoothing out corners). [Recommended]
|
||||
float f = max(radius2 - vv, 0.0);
|
||||
return f * f * f * max((vn - bias) / (epsilon + vv), 0.0);
|
||||
|
||||
// C: Medium contrast (which looks better at high radii), no division. Note that the
|
||||
// contribution still falls off with radius^2, but we've adjusted the rate in a way that is
|
||||
// more computationally efficient and happens to be aesthetically pleasing.
|
||||
// return 4.0 * max(1.0 - vv * invRadius2, 0.0) * max(vn - bias, 0.0);
|
||||
|
||||
// D: Low contrast, no division operation
|
||||
// return 2.0 * float(vv < radius * radius) * max(vn - bias, 0.0);
|
||||
}
|
||||
|
||||
void main() {
|
||||
// Pixel being shaded
|
||||
ivec2 ssC = ivec2(gl_FragCoord.xy);
|
||||
|
||||
// World space point being shaded
|
||||
vec3 C = getPosition(ssC);
|
||||
|
||||
/*
|
||||
if (C.z <= -camera_z_far * 0.999) {
|
||||
// We're on the skybox
|
||||
visibility=1.0;
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
//visibility = -C.z / camera_z_far;
|
||||
//return;
|
||||
#if 0
|
||||
vec3 n_C = texelFetch(source_normal, ssC, 0).rgb * 2.0 - 1.0;
|
||||
#else
|
||||
vec3 n_C = reconstructCSFaceNormal(C);
|
||||
n_C = -n_C;
|
||||
#endif
|
||||
|
||||
// Hash function used in the HPG12 AlchemyAO paper
|
||||
float randomPatternRotationAngle = mod(float((3 * ssC.x ^ ssC.y + ssC.x * ssC.y) * 10), TWO_PI);
|
||||
|
||||
// Reconstruct normals from positions. These will lead to 1-pixel black lines
|
||||
// at depth discontinuities, however the blur will wipe those out so they are not visible
|
||||
// in the final image.
|
||||
|
||||
// Choose the screen-space sample radius
|
||||
// proportional to the projected area of the sphere
|
||||
#ifdef USE_ORTHOGONAL_PROJECTION
|
||||
float ssDiskRadius = -proj_scale * radius;
|
||||
#else
|
||||
float ssDiskRadius = -proj_scale * radius / C.z;
|
||||
#endif
|
||||
float sum = 0.0;
|
||||
for (int i = 0; i < NUM_SAMPLES; ++i) {
|
||||
sum += sampleAO(ssC, C, n_C, ssDiskRadius, radius, i, randomPatternRotationAngle);
|
||||
}
|
||||
|
||||
float A = max(0.0, 1.0 - sum * intensity_div_r6 * (5.0 / float(NUM_SAMPLES)));
|
||||
|
||||
#ifdef ENABLE_RADIUS2
|
||||
|
||||
//go again for radius2
|
||||
randomPatternRotationAngle = mod(float((5 * ssC.x ^ ssC.y + ssC.x * ssC.y) * 11), TWO_PI);
|
||||
|
||||
// Reconstruct normals from positions. These will lead to 1-pixel black lines
|
||||
// at depth discontinuities, however the blur will wipe those out so they are not visible
|
||||
// in the final image.
|
||||
|
||||
// Choose the screen-space sample radius
|
||||
// proportional to the projected area of the sphere
|
||||
ssDiskRadius = -proj_scale * radius2 / C.z;
|
||||
|
||||
sum = 0.0;
|
||||
for (int i = 0; i < NUM_SAMPLES; ++i) {
|
||||
sum += sampleAO(ssC, C, n_C, ssDiskRadius, radius2, i, randomPatternRotationAngle);
|
||||
}
|
||||
|
||||
A = min(A, max(0.0, 1.0 - sum * intensity_div_r62 * (5.0 / float(NUM_SAMPLES))));
|
||||
#endif
|
||||
// Bilateral box-filter over a quad for free, respecting depth edges
|
||||
// (the difference that this makes is subtle)
|
||||
if (abs(dFdx(C.z)) < 0.02) {
|
||||
A -= dFdx(A) * (float(ssC.x & 1) - 0.5);
|
||||
}
|
||||
if (abs(dFdy(C.z)) < 0.02) {
|
||||
A -= dFdy(A) * (float(ssC.y & 1) - 0.5);
|
||||
}
|
||||
|
||||
visibility = A;
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec4 vertex_attrib;
|
||||
/* clang-format on */
|
||||
|
||||
void main() {
|
||||
gl_Position = vertex_attrib;
|
||||
gl_Position.z = 1.0;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
uniform sampler2D source_ssao; //texunit:0
|
||||
/* clang-format on */
|
||||
uniform sampler2D source_depth; //texunit:1
|
||||
uniform sampler2D source_normal; //texunit:3
|
||||
|
||||
layout(location = 0) out float visibility;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Tunable Parameters:
|
||||
|
||||
/** Increase to make depth edges crisper. Decrease to reduce flicker. */
|
||||
uniform float edge_sharpness;
|
||||
|
||||
/** Step in 2-pixel intervals since we already blurred against neighbors in the
|
||||
first AO pass. This constant can be increased while R decreases to improve
|
||||
performance at the expense of some dithering artifacts.
|
||||
|
||||
Morgan found that a scale of 3 left a 1-pixel checkerboard grid that was
|
||||
unobjectionable after shading was applied but eliminated most temporal incoherence
|
||||
from using small numbers of sample taps.
|
||||
*/
|
||||
|
||||
uniform int filter_scale;
|
||||
|
||||
/** Filter radius in pixels. This will be multiplied by SCALE. */
|
||||
#define R (4)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Gaussian coefficients
|
||||
const float gaussian[R + 1] =
|
||||
//float[](0.356642, 0.239400, 0.072410, 0.009869);
|
||||
//float[](0.398943, 0.241971, 0.053991, 0.004432, 0.000134); // stddev = 1.0
|
||||
float[](0.153170, 0.144893, 0.122649, 0.092902, 0.062970); // stddev = 2.0
|
||||
//float[](0.111220, 0.107798, 0.098151, 0.083953, 0.067458, 0.050920, 0.036108); // stddev = 3.0
|
||||
|
||||
/** (1, 0) or (0, 1) */
|
||||
uniform ivec2 axis;
|
||||
|
||||
uniform float camera_z_far;
|
||||
uniform float camera_z_near;
|
||||
|
||||
uniform ivec2 screen_size;
|
||||
|
||||
void main() {
|
||||
ivec2 ssC = ivec2(gl_FragCoord.xy);
|
||||
|
||||
float depth = texelFetch(source_depth, ssC, 0).r;
|
||||
//vec3 normal = texelFetch(source_normal, ssC, 0).rgb * 2.0 - 1.0;
|
||||
|
||||
depth = depth * 2.0 - 1.0;
|
||||
depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth * (camera_z_far - camera_z_near));
|
||||
|
||||
float depth_divide = 1.0 / camera_z_far;
|
||||
|
||||
//depth *= depth_divide;
|
||||
|
||||
/*
|
||||
if (depth > camera_z_far * 0.999) {
|
||||
discard; //skybox
|
||||
}
|
||||
*/
|
||||
|
||||
float sum = texelFetch(source_ssao, ssC, 0).r;
|
||||
|
||||
// Base weight for depth falloff. Increase this for more blurriness,
|
||||
// decrease it for better edge discrimination
|
||||
float BASE = gaussian[0];
|
||||
float totalWeight = BASE;
|
||||
sum *= totalWeight;
|
||||
|
||||
ivec2 clamp_limit = screen_size - ivec2(1);
|
||||
|
||||
for (int r = -R; r <= R; ++r) {
|
||||
// We already handled the zero case above. This loop should be unrolled and the static branch optimized out,
|
||||
// so the IF statement has no runtime cost
|
||||
if (r != 0) {
|
||||
ivec2 ppos = ssC + axis * (r * filter_scale);
|
||||
float value = texelFetch(source_ssao, clamp(ppos, ivec2(0), clamp_limit), 0).r;
|
||||
ivec2 rpos = clamp(ppos, ivec2(0), clamp_limit);
|
||||
float temp_depth = texelFetch(source_depth, rpos, 0).r;
|
||||
//vec3 temp_normal = texelFetch(source_normal, rpos, 0).rgb * 2.0 - 1.0;
|
||||
|
||||
temp_depth = temp_depth * 2.0 - 1.0;
|
||||
temp_depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - temp_depth * (camera_z_far - camera_z_near));
|
||||
//temp_depth *= depth_divide;
|
||||
|
||||
// spatial domain: offset gaussian tap
|
||||
float weight = 0.3 + gaussian[abs(r)];
|
||||
//weight *= max(0.0, dot(temp_normal, normal));
|
||||
|
||||
// range domain (the "bilateral" weight). As depth difference increases, decrease weight.
|
||||
weight *= max(0.0, 1.0 - edge_sharpness * abs(temp_depth - depth));
|
||||
|
||||
sum += value * weight;
|
||||
totalWeight += weight;
|
||||
}
|
||||
}
|
||||
|
||||
const float epsilon = 0.0001;
|
||||
visibility = sum / (totalWeight + epsilon);
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec4 vertex_attrib;
|
||||
/* clang-format on */
|
||||
|
||||
void main() {
|
||||
gl_Position = vertex_attrib;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
#ifdef MINIFY_START
|
||||
|
||||
#define SDEPTH_TYPE highp sampler2D
|
||||
uniform float camera_z_far;
|
||||
/* clang-format on */
|
||||
uniform float camera_z_near;
|
||||
|
||||
#else
|
||||
|
||||
#define SDEPTH_TYPE mediump usampler2D
|
||||
|
||||
#endif
|
||||
|
||||
uniform SDEPTH_TYPE source_depth; //texunit:0
|
||||
|
||||
uniform ivec2 from_size;
|
||||
uniform int source_mipmap;
|
||||
|
||||
layout(location = 0) out mediump uint depth;
|
||||
|
||||
void main() {
|
||||
ivec2 ssP = ivec2(gl_FragCoord.xy);
|
||||
|
||||
// Rotated grid subsampling to avoid XY directional bias or Z precision bias while downsampling.
|
||||
// On DX9, the bit-and can be implemented with floating-point modulo
|
||||
|
||||
#ifdef MINIFY_START
|
||||
float fdepth = texelFetch(source_depth, clamp(ssP * 2 + ivec2(ssP.y & 1, ssP.x & 1), ivec2(0), from_size - ivec2(1)), source_mipmap).r;
|
||||
fdepth = fdepth * 2.0 - 1.0;
|
||||
#ifdef USE_ORTHOGONAL_PROJECTION
|
||||
fdepth = ((fdepth + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0;
|
||||
#else
|
||||
fdepth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - fdepth * (camera_z_far - camera_z_near));
|
||||
#endif
|
||||
fdepth /= camera_z_far;
|
||||
depth = uint(clamp(fdepth * 65535.0, 0.0, 65535.0));
|
||||
|
||||
#else
|
||||
depth = texelFetch(source_depth, clamp(ssP * 2 + ivec2(ssP.y & 1, ssP.x & 1), ivec2(0), from_size - ivec2(1)), source_mipmap).r;
|
||||
#endif
|
||||
}
|
@ -1,171 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec4 vertex_attrib;
|
||||
/* clang-format on */
|
||||
layout(location = 4) in vec2 uv_in;
|
||||
|
||||
out vec2 uv_interp;
|
||||
|
||||
void main() {
|
||||
uv_interp = uv_in;
|
||||
gl_Position = vertex_attrib;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
//#define QUALIFIER uniform // some guy on the interweb says it may be faster with this
|
||||
#define QUALIFIER const
|
||||
|
||||
#ifdef USE_25_SAMPLES
|
||||
const int kernel_size = 25;
|
||||
/* clang-format on */
|
||||
QUALIFIER vec2 kernel[25] = vec2[](
|
||||
vec2(0.530605, 0.0),
|
||||
vec2(0.000973794, -3.0),
|
||||
vec2(0.00333804, -2.52083),
|
||||
vec2(0.00500364, -2.08333),
|
||||
vec2(0.00700976, -1.6875),
|
||||
vec2(0.0094389, -1.33333),
|
||||
vec2(0.0128496, -1.02083),
|
||||
vec2(0.017924, -0.75),
|
||||
vec2(0.0263642, -0.520833),
|
||||
vec2(0.0410172, -0.333333),
|
||||
vec2(0.0493588, -0.1875),
|
||||
vec2(0.0402784, -0.0833333),
|
||||
vec2(0.0211412, -0.0208333),
|
||||
vec2(0.0211412, 0.0208333),
|
||||
vec2(0.0402784, 0.0833333),
|
||||
vec2(0.0493588, 0.1875),
|
||||
vec2(0.0410172, 0.333333),
|
||||
vec2(0.0263642, 0.520833),
|
||||
vec2(0.017924, 0.75),
|
||||
vec2(0.0128496, 1.02083),
|
||||
vec2(0.0094389, 1.33333),
|
||||
vec2(0.00700976, 1.6875),
|
||||
vec2(0.00500364, 2.08333),
|
||||
vec2(0.00333804, 2.52083),
|
||||
vec2(0.000973794, 3.0));
|
||||
#endif //USE_25_SAMPLES
|
||||
|
||||
#ifdef USE_17_SAMPLES
|
||||
const int kernel_size = 17;
|
||||
QUALIFIER vec2 kernel[17] = vec2[](
|
||||
vec2(0.536343, 0.0),
|
||||
vec2(0.00317394, -2.0),
|
||||
vec2(0.0100386, -1.53125),
|
||||
vec2(0.0144609, -1.125),
|
||||
vec2(0.0216301, -0.78125),
|
||||
vec2(0.0347317, -0.5),
|
||||
vec2(0.0571056, -0.28125),
|
||||
vec2(0.0582416, -0.125),
|
||||
vec2(0.0324462, -0.03125),
|
||||
vec2(0.0324462, 0.03125),
|
||||
vec2(0.0582416, 0.125),
|
||||
vec2(0.0571056, 0.28125),
|
||||
vec2(0.0347317, 0.5),
|
||||
vec2(0.0216301, 0.78125),
|
||||
vec2(0.0144609, 1.125),
|
||||
vec2(0.0100386, 1.53125),
|
||||
vec2(0.00317394, 2.0));
|
||||
#endif //USE_17_SAMPLES
|
||||
|
||||
#ifdef USE_11_SAMPLES
|
||||
const int kernel_size = 11;
|
||||
QUALIFIER vec2 kernel[11] = vec2[](
|
||||
vec2(0.560479, 0.0),
|
||||
vec2(0.00471691, -2.0),
|
||||
vec2(0.0192831, -1.28),
|
||||
vec2(0.03639, -0.72),
|
||||
vec2(0.0821904, -0.32),
|
||||
vec2(0.0771802, -0.08),
|
||||
vec2(0.0771802, 0.08),
|
||||
vec2(0.0821904, 0.32),
|
||||
vec2(0.03639, 0.72),
|
||||
vec2(0.0192831, 1.28),
|
||||
vec2(0.00471691, 2.0));
|
||||
#endif //USE_11_SAMPLES
|
||||
|
||||
uniform float max_radius;
|
||||
uniform float camera_z_far;
|
||||
uniform float camera_z_near;
|
||||
uniform float unit_size;
|
||||
uniform vec2 dir;
|
||||
in vec2 uv_interp;
|
||||
|
||||
uniform sampler2D source_diffuse; //texunit:0
|
||||
uniform sampler2D source_sss; //texunit:1
|
||||
uniform sampler2D source_depth; //texunit:2
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
float strength = texture(source_sss, uv_interp).r;
|
||||
strength *= strength; //stored as sqrt
|
||||
|
||||
// Fetch color of current pixel:
|
||||
vec4 base_color = texture(source_diffuse, uv_interp);
|
||||
|
||||
if (strength > 0.0) {
|
||||
// Fetch linear depth of current pixel:
|
||||
float depth = texture(source_depth, uv_interp).r * 2.0 - 1.0;
|
||||
#ifdef USE_ORTHOGONAL_PROJECTION
|
||||
depth = ((depth + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0;
|
||||
float scale = unit_size; //remember depth is negative by default in OpenGL
|
||||
#else
|
||||
depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth * (camera_z_far - camera_z_near));
|
||||
float scale = unit_size / depth; //remember depth is negative by default in OpenGL
|
||||
#endif
|
||||
|
||||
// Calculate the final step to fetch the surrounding pixels:
|
||||
vec2 step = max_radius * scale * dir;
|
||||
step *= strength; // Modulate it using the alpha channel.
|
||||
step *= 1.0 / 3.0; // Divide by 3 as the kernels range from -3 to 3.
|
||||
|
||||
// Accumulate the center sample:
|
||||
vec3 color_accum = base_color.rgb;
|
||||
color_accum *= kernel[0].x;
|
||||
#ifdef ENABLE_STRENGTH_WEIGHTING
|
||||
float color_weight = kernel[0].x;
|
||||
#endif
|
||||
|
||||
// Accumulate the other samples:
|
||||
for (int i = 1; i < kernel_size; i++) {
|
||||
// Fetch color and depth for current sample:
|
||||
vec2 offset = uv_interp + kernel[i].y * step;
|
||||
vec3 color = texture(source_diffuse, offset).rgb;
|
||||
|
||||
#ifdef ENABLE_FOLLOW_SURFACE
|
||||
// If the difference in depth is huge, we lerp color back to "colorM":
|
||||
float depth_cmp = texture(source_depth, offset).r * 2.0 - 1.0;
|
||||
|
||||
#ifdef USE_ORTHOGONAL_PROJECTION
|
||||
depth_cmp = ((depth_cmp + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0;
|
||||
#else
|
||||
depth_cmp = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth_cmp * (camera_z_far - camera_z_near));
|
||||
#endif
|
||||
|
||||
float s = clamp(300.0f * scale * max_radius * abs(depth - depth_cmp), 0.0, 1.0);
|
||||
color = mix(color, base_color.rgb, s);
|
||||
#endif
|
||||
|
||||
// Accumulate:
|
||||
color *= kernel[i].x;
|
||||
|
||||
#ifdef ENABLE_STRENGTH_WEIGHTING
|
||||
float color_s = texture(source_sss, offset).r;
|
||||
color_weight += color_s * kernel[i].x;
|
||||
color *= color_s;
|
||||
#endif
|
||||
color_accum += color;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_STRENGTH_WEIGHTING
|
||||
color_accum /= color_weight;
|
||||
#endif
|
||||
frag_color = vec4(color_accum, base_color.a); //keep alpha (used for SSAO)
|
||||
} else {
|
||||
frag_color = base_color;
|
||||
}
|
||||
}
|
@ -1,479 +0,0 @@
|
||||
/* clang-format off */
|
||||
[vertex]
|
||||
|
||||
layout(location = 0) in highp vec4 vertex_attrib;
|
||||
/* clang-format on */
|
||||
layout(location = 4) in vec2 uv_in;
|
||||
|
||||
out vec2 uv_interp;
|
||||
|
||||
void main() {
|
||||
gl_Position = vertex_attrib;
|
||||
|
||||
uv_interp = uv_in;
|
||||
|
||||
#ifdef V_FLIP
|
||||
uv_interp.y = 1.0f - uv_interp.y;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
[fragment]
|
||||
|
||||
#if !defined(GLES_OVER_GL)
|
||||
precision mediump float;
|
||||
#endif
|
||||
/* clang-format on */
|
||||
|
||||
in vec2 uv_interp;
|
||||
|
||||
uniform highp sampler2D source; //texunit:0
|
||||
|
||||
uniform float exposure;
|
||||
uniform float white;
|
||||
|
||||
#ifdef USE_AUTO_EXPOSURE
|
||||
uniform highp sampler2D source_auto_exposure; //texunit:1
|
||||
uniform highp float auto_exposure_grey;
|
||||
#endif
|
||||
|
||||
#if defined(USE_GLOW_LEVEL1) || defined(USE_GLOW_LEVEL2) || defined(USE_GLOW_LEVEL3) || defined(USE_GLOW_LEVEL4) || defined(USE_GLOW_LEVEL5) || defined(USE_GLOW_LEVEL6) || defined(USE_GLOW_LEVEL7)
|
||||
#define USING_GLOW // only use glow when at least one glow level is selected
|
||||
|
||||
uniform highp sampler2D source_glow; //texunit:2
|
||||
uniform highp float glow_intensity;
|
||||
#endif
|
||||
|
||||
#ifdef USE_BCS
|
||||
uniform vec3 bcs;
|
||||
#endif
|
||||
|
||||
#ifdef USE_FXAA
|
||||
uniform vec2 pixel_size;
|
||||
#endif
|
||||
|
||||
#ifdef USE_SHARPENING
|
||||
uniform float sharpen_intensity;
|
||||
#endif
|
||||
|
||||
#ifdef USE_COLOR_CORRECTION
|
||||
uniform sampler2D color_correction; //texunit:3
|
||||
#endif
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
#ifdef USE_GLOW_FILTER_BICUBIC
|
||||
// w0, w1, w2, and w3 are the four cubic B-spline basis functions
|
||||
float w0(float a) {
|
||||
return (1.0f / 6.0f) * (a * (a * (-a + 3.0f) - 3.0f) + 1.0f);
|
||||
}
|
||||
|
||||
float w1(float a) {
|
||||
return (1.0f / 6.0f) * (a * a * (3.0f * a - 6.0f) + 4.0f);
|
||||
}
|
||||
|
||||
float w2(float a) {
|
||||
return (1.0f / 6.0f) * (a * (a * (-3.0f * a + 3.0f) + 3.0f) + 1.0f);
|
||||
}
|
||||
|
||||
float w3(float a) {
|
||||
return (1.0f / 6.0f) * (a * a * a);
|
||||
}
|
||||
|
||||
// g0 and g1 are the two amplitude functions
|
||||
float g0(float a) {
|
||||
return w0(a) + w1(a);
|
||||
}
|
||||
|
||||
float g1(float a) {
|
||||
return w2(a) + w3(a);
|
||||
}
|
||||
|
||||
// h0 and h1 are the two offset functions
|
||||
float h0(float a) {
|
||||
return -1.0f + w1(a) / (w0(a) + w1(a));
|
||||
}
|
||||
|
||||
float h1(float a) {
|
||||
return 1.0f + w3(a) / (w2(a) + w3(a));
|
||||
}
|
||||
|
||||
uniform ivec2 glow_texture_size;
|
||||
|
||||
vec4 texture2D_bicubic(sampler2D tex, vec2 uv, int p_lod) {
|
||||
float lod = float(p_lod);
|
||||
vec2 tex_size = vec2(glow_texture_size >> p_lod);
|
||||
vec2 texel_size = vec2(1.0f) / tex_size;
|
||||
|
||||
uv = uv * tex_size + vec2(0.5f);
|
||||
|
||||
vec2 iuv = floor(uv);
|
||||
vec2 fuv = fract(uv);
|
||||
|
||||
float g0x = g0(fuv.x);
|
||||
float g1x = g1(fuv.x);
|
||||
float h0x = h0(fuv.x);
|
||||
float h1x = h1(fuv.x);
|
||||
float h0y = h0(fuv.y);
|
||||
float h1y = h1(fuv.y);
|
||||
|
||||
vec2 p0 = (vec2(iuv.x + h0x, iuv.y + h0y) - vec2(0.5f)) * texel_size;
|
||||
vec2 p1 = (vec2(iuv.x + h1x, iuv.y + h0y) - vec2(0.5f)) * texel_size;
|
||||
vec2 p2 = (vec2(iuv.x + h0x, iuv.y + h1y) - vec2(0.5f)) * texel_size;
|
||||
vec2 p3 = (vec2(iuv.x + h1x, iuv.y + h1y) - vec2(0.5f)) * texel_size;
|
||||
|
||||
return (g0(fuv.y) * (g0x * textureLod(tex, p0, lod) + g1x * textureLod(tex, p1, lod))) +
|
||||
(g1(fuv.y) * (g0x * textureLod(tex, p2, lod) + g1x * textureLod(tex, p3, lod)));
|
||||
}
|
||||
|
||||
#define GLOW_TEXTURE_SAMPLE(m_tex, m_uv, m_lod) texture2D_bicubic(m_tex, m_uv, m_lod)
|
||||
#else
|
||||
#define GLOW_TEXTURE_SAMPLE(m_tex, m_uv, m_lod) textureLod(m_tex, m_uv, float(m_lod))
|
||||
#endif
|
||||
|
||||
vec3 tonemap_filmic(vec3 color, float white) {
|
||||
// exposure bias: input scale (color *= bias, white *= bias) to make the brightness consistent with other tonemappers
|
||||
// also useful to scale the input to the range that the tonemapper is designed for (some require very high input values)
|
||||
// has no effect on the curve's general shape or visual properties
|
||||
const float exposure_bias = 2.0f;
|
||||
const float A = 0.22f * exposure_bias * exposure_bias; // bias baked into constants for performance
|
||||
const float B = 0.30f * exposure_bias;
|
||||
const float C = 0.10f;
|
||||
const float D = 0.20f;
|
||||
const float E = 0.01f;
|
||||
const float F = 0.30f;
|
||||
|
||||
vec3 color_tonemapped = ((color * (A * color + C * B) + D * E) / (color * (A * color + B) + D * F)) - E / F;
|
||||
float white_tonemapped = ((white * (A * white + C * B) + D * E) / (white * (A * white + B) + D * F)) - E / F;
|
||||
|
||||
return clamp(color_tonemapped / white_tonemapped, vec3(0.0f), vec3(1.0f));
|
||||
}
|
||||
|
||||
vec3 tonemap_aces(vec3 color, float white) {
|
||||
const float exposure_bias = 0.85f;
|
||||
const float A = 2.51f * exposure_bias * exposure_bias;
|
||||
const float B = 0.03f * exposure_bias;
|
||||
const float C = 2.43f * exposure_bias * exposure_bias;
|
||||
const float D = 0.59f * exposure_bias;
|
||||
const float E = 0.14f;
|
||||
|
||||
vec3 color_tonemapped = (color * (A * color + B)) / (color * (C * color + D) + E);
|
||||
float white_tonemapped = (white * (A * white + B)) / (white * (C * white + D) + E);
|
||||
|
||||
return clamp(color_tonemapped / white_tonemapped, vec3(0.0f), vec3(1.0f));
|
||||
}
|
||||
|
||||
// Adapted from https://github.com/TheRealMJP/BakingLab/blob/master/BakingLab/ACES.hlsl
|
||||
// (MIT License).
|
||||
vec3 tonemap_aces_fitted(vec3 color, float white) {
|
||||
const float exposure_bias = 1.8f;
|
||||
const float A = 0.0245786f;
|
||||
const float B = 0.000090537f;
|
||||
const float C = 0.983729f;
|
||||
const float D = 0.432951f;
|
||||
const float E = 0.238081f;
|
||||
|
||||
// Exposure bias baked into transform to save shader instructions. Equivalent to `color *= exposure_bias`
|
||||
const mat3 rgb_to_rrt = mat3(
|
||||
vec3(0.59719f * exposure_bias, 0.35458f * exposure_bias, 0.04823f * exposure_bias),
|
||||
vec3(0.07600f * exposure_bias, 0.90834f * exposure_bias, 0.01566f * exposure_bias),
|
||||
vec3(0.02840f * exposure_bias, 0.13383f * exposure_bias, 0.83777f * exposure_bias));
|
||||
|
||||
const mat3 odt_to_rgb = mat3(
|
||||
vec3(1.60475f, -0.53108f, -0.07367f),
|
||||
vec3(-0.10208f, 1.10813f, -0.00605f),
|
||||
vec3(-0.00327f, -0.07276f, 1.07602f));
|
||||
|
||||
color *= rgb_to_rrt;
|
||||
vec3 color_tonemapped = (color * (color + A) - B) / (color * (C * color + D) + E);
|
||||
color_tonemapped *= odt_to_rgb;
|
||||
|
||||
white *= exposure_bias;
|
||||
float white_tonemapped = (white * (white + A) - B) / (white * (C * white + D) + E);
|
||||
|
||||
return clamp(color_tonemapped / white_tonemapped, vec3(0.0f), vec3(1.0f));
|
||||
}
|
||||
|
||||
vec3 tonemap_reinhard(vec3 color, float white) {
|
||||
return clamp((white * color + color) / (color * white + white), vec3(0.0f), vec3(1.0f));
|
||||
}
|
||||
|
||||
vec3 linear_to_srgb(vec3 color) { // convert linear rgb to srgb, assumes clamped input in range [0;1]
|
||||
const vec3 a = vec3(0.055f);
|
||||
return mix((vec3(1.0f) + a) * pow(color.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * color.rgb, lessThan(color.rgb, vec3(0.0031308f)));
|
||||
}
|
||||
|
||||
// inputs are LINEAR, If Linear tonemapping is selected no transform is performed else outputs are clamped [0, 1] color
|
||||
vec3 apply_tonemapping(vec3 color, float white) {
|
||||
// Ensure color values are positive.
|
||||
// They can be negative in the case of negative lights, which leads to undesired behavior.
|
||||
#if defined(USE_REINHARD_TONEMAPPER) || defined(USE_FILMIC_TONEMAPPER) || defined(USE_ACES_TONEMAPPER) || defined(USE_ACES_FITTED_TONEMAPPER)
|
||||
color = max(vec3(0.0f), color);
|
||||
#endif
|
||||
|
||||
#ifdef USE_REINHARD_TONEMAPPER
|
||||
return tonemap_reinhard(color, white);
|
||||
#endif
|
||||
|
||||
#ifdef USE_FILMIC_TONEMAPPER
|
||||
return tonemap_filmic(color, white);
|
||||
#endif
|
||||
|
||||
#ifdef USE_ACES_TONEMAPPER
|
||||
return tonemap_aces(color, white);
|
||||
#endif
|
||||
|
||||
#ifdef USE_ACES_FITTED_TONEMAPPER
|
||||
return tonemap_aces_fitted(color, white);
|
||||
#endif
|
||||
|
||||
return color; // no other selected -> linear: no color transform applied
|
||||
}
|
||||
|
||||
vec3 gather_glow(sampler2D tex, vec2 uv) { // sample all selected glow levels
|
||||
vec3 glow = vec3(0.0f);
|
||||
|
||||
#ifdef USE_GLOW_LEVEL1
|
||||
glow += GLOW_TEXTURE_SAMPLE(tex, uv, 1).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLOW_LEVEL2
|
||||
glow += GLOW_TEXTURE_SAMPLE(tex, uv, 2).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLOW_LEVEL3
|
||||
glow += GLOW_TEXTURE_SAMPLE(tex, uv, 3).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLOW_LEVEL4
|
||||
glow += GLOW_TEXTURE_SAMPLE(tex, uv, 4).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLOW_LEVEL5
|
||||
glow += GLOW_TEXTURE_SAMPLE(tex, uv, 5).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLOW_LEVEL6
|
||||
glow += GLOW_TEXTURE_SAMPLE(tex, uv, 6).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLOW_LEVEL7
|
||||
glow += GLOW_TEXTURE_SAMPLE(tex, uv, 7).rgb;
|
||||
#endif
|
||||
|
||||
return glow;
|
||||
}
|
||||
|
||||
vec3 apply_glow(vec3 color, vec3 glow) { // apply glow using the selected blending mode
|
||||
#ifdef USE_GLOW_REPLACE
|
||||
color = glow;
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLOW_SCREEN
|
||||
//need color clamping
|
||||
color = clamp(color, vec3(0.0f), vec3(1.0f));
|
||||
color = max((color + glow) - (color * glow), vec3(0.0));
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLOW_SOFTLIGHT
|
||||
//need color clamping
|
||||
color = clamp(color, vec3(0.0f), vec3(1.0));
|
||||
glow = glow * vec3(0.5f) + vec3(0.5f);
|
||||
|
||||
color.r = (glow.r <= 0.5f) ? (color.r - (1.0f - 2.0f * glow.r) * color.r * (1.0f - color.r)) : (((glow.r > 0.5f) && (color.r <= 0.25f)) ? (color.r + (2.0f * glow.r - 1.0f) * (4.0f * color.r * (4.0f * color.r + 1.0f) * (color.r - 1.0f) + 7.0f * color.r)) : (color.r + (2.0f * glow.r - 1.0f) * (sqrt(color.r) - color.r)));
|
||||
color.g = (glow.g <= 0.5f) ? (color.g - (1.0f - 2.0f * glow.g) * color.g * (1.0f - color.g)) : (((glow.g > 0.5f) && (color.g <= 0.25f)) ? (color.g + (2.0f * glow.g - 1.0f) * (4.0f * color.g * (4.0f * color.g + 1.0f) * (color.g - 1.0f) + 7.0f * color.g)) : (color.g + (2.0f * glow.g - 1.0f) * (sqrt(color.g) - color.g)));
|
||||
color.b = (glow.b <= 0.5f) ? (color.b - (1.0f - 2.0f * glow.b) * color.b * (1.0f - color.b)) : (((glow.b > 0.5f) && (color.b <= 0.25f)) ? (color.b + (2.0f * glow.b - 1.0f) * (4.0f * color.b * (4.0f * color.b + 1.0f) * (color.b - 1.0f) + 7.0f * color.b)) : (color.b + (2.0f * glow.b - 1.0f) * (sqrt(color.b) - color.b)));
|
||||
#endif
|
||||
|
||||
#if !defined(USE_GLOW_SCREEN) && !defined(USE_GLOW_SOFTLIGHT) && !defined(USE_GLOW_REPLACE) // no other selected -> additive
|
||||
color += glow;
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 apply_bcs(vec3 color, vec3 bcs) {
|
||||
color = mix(vec3(0.0f), color, bcs.x);
|
||||
color = mix(vec3(0.5f), color, bcs.y);
|
||||
color = mix(vec3(dot(vec3(1.0f), color) * 0.33333f), color, bcs.z);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 apply_color_correction(vec3 color, sampler2D correction_tex) {
|
||||
color.r = texture(correction_tex, vec2(color.r, 0.0f)).r;
|
||||
color.g = texture(correction_tex, vec2(color.g, 0.0f)).g;
|
||||
color.b = texture(correction_tex, vec2(color.b, 0.0f)).b;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 apply_fxaa(vec3 color, float exposure, vec2 uv_interp, vec2 pixel_size) {
|
||||
const float FXAA_REDUCE_MIN = (1.0 / 128.0);
|
||||
const float FXAA_REDUCE_MUL = (1.0 / 8.0);
|
||||
const float FXAA_SPAN_MAX = 8.0;
|
||||
|
||||
vec3 rgbNW = textureLod(source, uv_interp + vec2(-1.0, -1.0) * pixel_size, 0.0).xyz * exposure;
|
||||
vec3 rgbNE = textureLod(source, uv_interp + vec2(1.0, -1.0) * pixel_size, 0.0).xyz * exposure;
|
||||
vec3 rgbSW = textureLod(source, uv_interp + vec2(-1.0, 1.0) * pixel_size, 0.0).xyz * exposure;
|
||||
vec3 rgbSE = textureLod(source, uv_interp + vec2(1.0, 1.0) * pixel_size, 0.0).xyz * exposure;
|
||||
vec3 rgbM = color;
|
||||
vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
float lumaNW = dot(rgbNW, luma);
|
||||
float lumaNE = dot(rgbNE, luma);
|
||||
float lumaSW = dot(rgbSW, luma);
|
||||
float lumaSE = dot(rgbSE, luma);
|
||||
float lumaM = dot(rgbM, luma);
|
||||
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
|
||||
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
|
||||
|
||||
vec2 dir;
|
||||
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
|
||||
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
|
||||
|
||||
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *
|
||||
(0.25 * FXAA_REDUCE_MUL),
|
||||
FXAA_REDUCE_MIN);
|
||||
|
||||
float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
|
||||
dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
|
||||
max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
|
||||
dir * rcpDirMin)) *
|
||||
pixel_size;
|
||||
|
||||
vec3 rgbA = 0.5 * exposure * (textureLod(source, uv_interp + dir * (1.0 / 3.0 - 0.5), 0.0).xyz + textureLod(source, uv_interp + dir * (2.0 / 3.0 - 0.5), 0.0).xyz);
|
||||
vec3 rgbB = rgbA * 0.5 + 0.25 * exposure * (textureLod(source, uv_interp + dir * -0.5, 0.0).xyz + textureLod(source, uv_interp + dir * 0.5, 0.0).xyz);
|
||||
|
||||
float lumaB = dot(rgbB, luma);
|
||||
if ((lumaB < lumaMin) || (lumaB > lumaMax)) {
|
||||
return rgbA;
|
||||
} else {
|
||||
return rgbB;
|
||||
}
|
||||
}
|
||||
|
||||
// From http://alex.vlachos.com/graphics/Alex_Vlachos_Advanced_VR_Rendering_GDC2015.pdf
|
||||
// and https://www.shadertoy.com/view/MslGR8 (5th one starting from the bottom)
|
||||
// NOTE: `frag_coord` is in pixels (i.e. not normalized UV).
|
||||
vec3 screen_space_dither(vec2 frag_coord) {
|
||||
// Iestyn's RGB dither (7 asm instructions) from Portal 2 X360, slightly modified for VR.
|
||||
vec3 dither = vec3(dot(vec2(171.0, 231.0), frag_coord));
|
||||
dither.rgb = fract(dither.rgb / vec3(103.0, 71.0, 97.0));
|
||||
|
||||
// Subtract 0.5 to avoid slightly brightening the whole viewport.
|
||||
return (dither.rgb - 0.5) / 255.0;
|
||||
}
|
||||
|
||||
// Adapted from https://github.com/DadSchoorse/vkBasalt/blob/b929505ba71dea21d6c32a5a59f2d241592b30c4/src/shader/cas.frag.glsl
|
||||
// (MIT license).
|
||||
vec3 apply_cas(vec3 color, float exposure, vec2 uv_interp, float sharpen_intensity) {
|
||||
// Fetch a 3x3 neighborhood around the pixel 'e',
|
||||
// a b c
|
||||
// d(e)f
|
||||
// g h i
|
||||
vec3 a = textureLodOffset(source, uv_interp, 0.0, ivec2(-1, -1)).rgb * exposure;
|
||||
vec3 b = textureLodOffset(source, uv_interp, 0.0, ivec2(0, -1)).rgb * exposure;
|
||||
vec3 c = textureLodOffset(source, uv_interp, 0.0, ivec2(1, -1)).rgb * exposure;
|
||||
vec3 d = textureLodOffset(source, uv_interp, 0.0, ivec2(-1, 0)).rgb * exposure;
|
||||
vec3 e = color.rgb;
|
||||
vec3 f = textureLodOffset(source, uv_interp, 0.0, ivec2(1, 0)).rgb * exposure;
|
||||
vec3 g = textureLodOffset(source, uv_interp, 0.0, ivec2(-1, 1)).rgb * exposure;
|
||||
vec3 h = textureLodOffset(source, uv_interp, 0.0, ivec2(0, 1)).rgb * exposure;
|
||||
vec3 i = textureLodOffset(source, uv_interp, 0.0, ivec2(1, 1)).rgb * exposure;
|
||||
|
||||
// Soft min and max.
|
||||
// a b c b
|
||||
// d e f * 0.5 + d e f * 0.5
|
||||
// g h i h
|
||||
// These are 2.0x bigger (factored out the extra multiply).
|
||||
vec3 min_rgb = min(min(min(d, e), min(f, b)), h);
|
||||
vec3 min_rgb2 = min(min(min(min_rgb, a), min(g, c)), i);
|
||||
min_rgb += min_rgb2;
|
||||
|
||||
vec3 max_rgb = max(max(max(d, e), max(f, b)), h);
|
||||
vec3 max_rgb2 = max(max(max(max_rgb, a), max(g, c)), i);
|
||||
max_rgb += max_rgb2;
|
||||
|
||||
// Smooth minimum distance to signal limit divided by smooth max.
|
||||
vec3 rcp_max_rgb = vec3(1.0) / max_rgb;
|
||||
vec3 amp_rgb = clamp((min(min_rgb, 2.0 - max_rgb) * rcp_max_rgb), 0.0, 1.0);
|
||||
|
||||
// Shaping amount of sharpening.
|
||||
amp_rgb = inversesqrt(amp_rgb);
|
||||
float peak = 8.0 - 3.0 * sharpen_intensity;
|
||||
vec3 w_rgb = -vec3(1) / (amp_rgb * peak);
|
||||
vec3 rcp_weight_rgb = vec3(1.0) / (1.0 + 4.0 * w_rgb);
|
||||
|
||||
// 0 w 0
|
||||
// Filter shape: w 1 w
|
||||
// 0 w 0
|
||||
vec3 window = b + d + f + h;
|
||||
|
||||
return max(vec3(0.0), (window * w_rgb + e) * rcp_weight_rgb);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec3 color = textureLod(source, uv_interp, 0.0f).rgb;
|
||||
|
||||
// Exposure
|
||||
float full_exposure = exposure;
|
||||
|
||||
#ifdef USE_AUTO_EXPOSURE
|
||||
full_exposure /= texelFetch(source_auto_exposure, ivec2(0, 0), 0).r / auto_exposure_grey;
|
||||
#endif
|
||||
|
||||
color *= full_exposure;
|
||||
|
||||
#ifdef USE_FXAA
|
||||
// FXAA must be applied before tonemapping.
|
||||
color = apply_fxaa(color, full_exposure, uv_interp, pixel_size);
|
||||
#endif
|
||||
|
||||
#ifdef USE_SHARPENING
|
||||
// CAS gives best results when applied after tonemapping, but `source` isn't tonemapped.
|
||||
// As a workaround, apply CAS before tonemapping so that the image still has a correct appearance when tonemapped.
|
||||
color = apply_cas(color, full_exposure, uv_interp, sharpen_intensity);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DEBANDING
|
||||
// For best results, debanding should be done before tonemapping.
|
||||
// Otherwise, we're adding noise to an already-quantized image.
|
||||
color += screen_space_dither(gl_FragCoord.xy);
|
||||
#endif
|
||||
|
||||
// Early Tonemap & SRGB Conversion; note that Linear tonemapping does not clamp to [0, 1]; some operations below expect a [0, 1] range and will clamp
|
||||
color = apply_tonemapping(color, white);
|
||||
|
||||
#ifdef KEEP_3D_LINEAR
|
||||
// leave color as is (-> don't convert to SRGB)
|
||||
#else
|
||||
//need color clamping
|
||||
color = clamp(color, vec3(0.0f), vec3(1.0f));
|
||||
color = linear_to_srgb(color); // regular linear -> SRGB conversion (needs clamped values)
|
||||
#endif
|
||||
|
||||
// Glow
|
||||
|
||||
#ifdef USING_GLOW
|
||||
vec3 glow = gather_glow(source_glow, uv_interp) * glow_intensity;
|
||||
|
||||
// high dynamic range -> SRGB
|
||||
glow = apply_tonemapping(glow, white);
|
||||
glow = clamp(glow, vec3(0.0f), vec3(1.0f));
|
||||
glow = linear_to_srgb(glow);
|
||||
|
||||
color = apply_glow(color, glow);
|
||||
#endif
|
||||
|
||||
// Additional effects
|
||||
|
||||
#ifdef USE_BCS
|
||||
color = apply_bcs(color, bcs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_COLOR_CORRECTION
|
||||
color = apply_color_correction(color, color_correction);
|
||||
#endif
|
||||
|
||||
frag_color = vec4(color, 1.0f);
|
||||
}
|
@ -52,11 +52,6 @@
|
||||
#include "scene/gui/tool_button.h"
|
||||
#include "servers/navigation_server.h"
|
||||
|
||||
// Used to test for GLES3 support.
|
||||
#ifndef SERVER_ENABLED
|
||||
#include "drivers/gles3/rasterizer_gles3.h"
|
||||
#endif
|
||||
|
||||
static inline String get_project_key_from_path(const String &dir) {
|
||||
return dir.replace("/", "::");
|
||||
}
|
||||
@ -851,7 +846,7 @@ public:
|
||||
|
||||
// Enable GLES3 by default as it's the default value for the project setting.
|
||||
#ifndef SERVER_ENABLED
|
||||
bool gles3_viable = RasterizerGLES3::is_viable() == OK;
|
||||
bool gles3_viable = false;
|
||||
#else
|
||||
// Whatever, project manager isn't even used in headless builds.
|
||||
bool gles3_viable = false;
|
||||
@ -860,30 +855,11 @@ public:
|
||||
Container *rvb = memnew(VBoxContainer);
|
||||
rvb->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
rshb->add_child(rvb);
|
||||
Button *rs_button = memnew(CheckBox);
|
||||
rs_button->set_button_group(rasterizer_button_group);
|
||||
rs_button->set_text(TTR("OpenGL ES 3.0"));
|
||||
rs_button->set_meta("driver_name", "GLES3");
|
||||
rvb->add_child(rs_button);
|
||||
if (gles3_viable) {
|
||||
rs_button->set_pressed(true);
|
||||
} else {
|
||||
// If GLES3 can't be used, don't let users shoot themselves in the foot.
|
||||
rs_button->set_disabled(true);
|
||||
l = memnew(Label);
|
||||
l->set_text(TTR("Not supported by your GPU drivers."));
|
||||
rvb->add_child(l);
|
||||
}
|
||||
l = memnew(Label);
|
||||
l->set_text(TTR("Higher visual quality\nAll features available\nIncompatible with older hardware\nNot recommended for web games"));
|
||||
rvb->add_child(l);
|
||||
|
||||
rshb->add_child(memnew(VSeparator));
|
||||
|
||||
rvb = memnew(VBoxContainer);
|
||||
rvb->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
rshb->add_child(rvb);
|
||||
rs_button = memnew(CheckBox);
|
||||
Button *rs_button = memnew(CheckBox);
|
||||
rs_button->set_button_group(rasterizer_button_group);
|
||||
rs_button->set_text(TTR("OpenGL ES 2.0"));
|
||||
rs_button->set_meta("driver_name", "GLES2");
|
||||
|
@ -592,11 +592,6 @@ def build_legacygl_header(filename, include, class_suffix, output_attribs, gles2
|
||||
fd.close()
|
||||
|
||||
|
||||
def build_gles3_headers(target, source, env):
|
||||
for x in source:
|
||||
build_legacygl_header(str(x), include="drivers/gles3/shader_gles3.h", class_suffix="GLES3", output_attribs=True)
|
||||
|
||||
|
||||
def build_gles2_headers(target, source, env):
|
||||
for x in source:
|
||||
build_legacygl_header(
|
||||
|
@ -1055,8 +1055,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
|
||||
|
||||
OS::get_singleton()->set_cmdline(execpath, main_args);
|
||||
|
||||
GLOBAL_DEF("rendering/quality/driver/driver_name", "GLES3");
|
||||
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/driver/driver_name", PropertyInfo(Variant::STRING, "rendering/quality/driver/driver_name", PROPERTY_HINT_ENUM, "GLES2,GLES3"));
|
||||
GLOBAL_DEF("rendering/quality/driver/driver_name", "GLES2");
|
||||
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/driver/driver_name", PropertyInfo(Variant::STRING, "rendering/quality/driver/driver_name", PROPERTY_HINT_ENUM, "GLES2"));
|
||||
if (video_driver == "") {
|
||||
video_driver = GLOBAL_GET("rendering/quality/driver/driver_name");
|
||||
}
|
||||
|
@ -32,7 +32,6 @@
|
||||
|
||||
#include "core/project_settings.h"
|
||||
#include "drivers/gles2/rasterizer_gles2.h"
|
||||
#include "drivers/gles3/rasterizer_gles3.h"
|
||||
#include "drivers/unix/dir_access_unix.h"
|
||||
#include "drivers/unix/file_access_unix.h"
|
||||
#include "main/main.h"
|
||||
@ -82,8 +81,6 @@ int OS_Android::get_video_driver_count() const {
|
||||
|
||||
const char *OS_Android::get_video_driver_name(int p_driver) const {
|
||||
switch (p_driver) {
|
||||
case VIDEO_DRIVER_GLES3:
|
||||
return "GLES3";
|
||||
case VIDEO_DRIVER_GLES2:
|
||||
return "GLES2";
|
||||
}
|
||||
@ -127,28 +124,13 @@ int OS_Android::get_current_video_driver() const {
|
||||
}
|
||||
|
||||
Error OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
|
||||
bool use_gl3 = godot_java->get_gles_version_code() >= 0x00030000;
|
||||
use_gl3 = use_gl3 && (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES3");
|
||||
//bool use_gl3 = godot_java->get_gles_version_code() >= 0x00030000;
|
||||
//use_gl3 = use_gl3 && (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES3");
|
||||
bool use_gl2 = (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES2");
|
||||
bool gl_initialization_error = false;
|
||||
|
||||
while (true) {
|
||||
if (use_gl3) {
|
||||
if (RasterizerGLES3::is_viable() == OK) {
|
||||
godot_java->gfx_init(false);
|
||||
RasterizerGLES3::register_config();
|
||||
RasterizerGLES3::make_current();
|
||||
break;
|
||||
} else {
|
||||
if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
|
||||
p_video_driver = VIDEO_DRIVER_GLES2;
|
||||
use_gl3 = false;
|
||||
continue;
|
||||
} else {
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (use_gl2) {
|
||||
if (RasterizerGLES2::is_viable() == OK) {
|
||||
godot_java->gfx_init(true);
|
||||
RasterizerGLES2::register_config();
|
||||
@ -158,6 +140,8 @@ Error OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include "os_iphone.h"
|
||||
|
||||
#include "drivers/gles2/rasterizer_gles2.h"
|
||||
#include "drivers/gles3/rasterizer_gles3.h"
|
||||
#include "servers/visual/visual_server_raster.h"
|
||||
#include "servers/visual/visual_server_wrap_mt.h"
|
||||
|
||||
@ -75,8 +74,6 @@ int OSIPhone::get_video_driver_count() const {
|
||||
|
||||
const char *OSIPhone::get_video_driver_name(int p_driver) const {
|
||||
switch (p_driver) {
|
||||
case VIDEO_DRIVER_GLES3:
|
||||
return "GLES3";
|
||||
case VIDEO_DRIVER_GLES2:
|
||||
return "GLES2";
|
||||
}
|
||||
@ -119,26 +116,12 @@ void OSIPhone::start() {
|
||||
}
|
||||
|
||||
Error OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
|
||||
bool use_gl3 = GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES3";
|
||||
//bool use_gl3 = GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES3";
|
||||
bool use_gl2 = GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES2";
|
||||
bool gl_initialization_error = false;
|
||||
|
||||
while (true) {
|
||||
if (use_gl3) {
|
||||
if (RasterizerGLES3::is_viable() == OK && gles3_available) {
|
||||
RasterizerGLES3::register_config();
|
||||
RasterizerGLES3::make_current();
|
||||
break;
|
||||
} else {
|
||||
if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
|
||||
p_video_driver = VIDEO_DRIVER_GLES2;
|
||||
use_gl3 = false;
|
||||
continue;
|
||||
} else {
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (use_gl2) {
|
||||
if (RasterizerGLES2::is_viable() == OK) {
|
||||
RasterizerGLES2::register_config();
|
||||
RasterizerGLES2::make_current();
|
||||
@ -147,6 +130,8 @@ Error OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include <alloca.h>
|
||||
|
||||
#define GLES2_INCLUDE_H <ES2/gl.h>
|
||||
#define GLES3_INCLUDE_H <ES3/gl.h>
|
||||
|
||||
#define PLATFORM_REFCOUNT
|
||||
|
||||
|
@ -4,7 +4,6 @@ Import("env")
|
||||
|
||||
javascript_files = [
|
||||
"audio_driver_javascript.cpp",
|
||||
"godot_webgl2.cpp",
|
||||
"http_client_javascript.cpp",
|
||||
"javascript_singleton.cpp",
|
||||
"javascript_main.cpp",
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* godot_webgl2.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "godot_webgl2.h"
|
||||
|
||||
extern "C" {
|
||||
extern void godot_js_display_glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data);
|
||||
}
|
||||
|
||||
void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data) {
|
||||
godot_js_display_glGetBufferSubData(target, offset, size, data);
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* godot_webgl2.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef GODOT_WEBGL2_H
|
||||
#include "GLES3/gl3.h"
|
||||
|
||||
// We could include "webgl/webgl2.h", but old (< 2.0.17) emscripten versions do not have it, so use our own wrapper instead.
|
||||
void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data);
|
||||
|
||||
#endif
|
@ -32,7 +32,6 @@
|
||||
|
||||
#include "core/io/json.h"
|
||||
#include "drivers/gles2/rasterizer_gles2.h"
|
||||
#include "drivers/gles3/rasterizer_gles3.h"
|
||||
#include "drivers/unix/dir_access_unix.h"
|
||||
#include "drivers/unix/file_access_unix.h"
|
||||
#include "main/main.h"
|
||||
@ -627,8 +626,6 @@ int OS_JavaScript::get_video_driver_count() const {
|
||||
|
||||
const char *OS_JavaScript::get_video_driver_name(int p_driver) const {
|
||||
switch (p_driver) {
|
||||
case VIDEO_DRIVER_GLES3:
|
||||
return "GLES3";
|
||||
case VIDEO_DRIVER_GLES2:
|
||||
return "GLES2";
|
||||
}
|
||||
@ -694,31 +691,15 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
|
||||
set_window_per_pixel_transparency_enabled(true);
|
||||
}
|
||||
|
||||
bool gles3 = true;
|
||||
if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
gles3 = false;
|
||||
}
|
||||
bool gles2 = true;
|
||||
//if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
// gles3 = true;
|
||||
//}
|
||||
|
||||
bool gl_initialization_error = false;
|
||||
|
||||
while (true) {
|
||||
if (gles3) {
|
||||
if (godot_js_display_has_webgl(2) && RasterizerGLES3::is_viable() == OK) {
|
||||
attributes.majorVersion = 2;
|
||||
RasterizerGLES3::register_config();
|
||||
RasterizerGLES3::make_current();
|
||||
break;
|
||||
} else {
|
||||
if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
|
||||
p_video_driver = VIDEO_DRIVER_GLES2;
|
||||
gles3 = false;
|
||||
continue;
|
||||
} else {
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (godot_js_display_has_webgl(1) && RasterizerGLES2::is_viable() == OK) {
|
||||
attributes.majorVersion = 1;
|
||||
RasterizerGLES2::register_config();
|
||||
@ -728,6 +709,8 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,4 +30,3 @@
|
||||
|
||||
#include <alloca.h>
|
||||
|
||||
#define GLES3_INCLUDE_H "platform/javascript/godot_webgl2.h"
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "core/version_generated.gen.h"
|
||||
#include "dir_access_osx.h"
|
||||
#include "drivers/gles2/rasterizer_gles2.h"
|
||||
#include "drivers/gles3/rasterizer_gles3.h"
|
||||
#include "main/main.h"
|
||||
#include "servers/visual/visual_server_raster.h"
|
||||
|
||||
@ -1723,31 +1722,16 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
|
||||
|
||||
/*** END OSX INITIALIZATION ***/
|
||||
|
||||
bool gles3 = true;
|
||||
if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
gles3 = false;
|
||||
}
|
||||
bool gles2 = true;
|
||||
//if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
// gles3 = false;
|
||||
//}
|
||||
|
||||
bool editor = Engine::get_singleton()->is_editor_hint();
|
||||
bool gl_initialization_error = false;
|
||||
|
||||
while (true) {
|
||||
if (gles3) {
|
||||
if (RasterizerGLES3::is_viable() == OK) {
|
||||
RasterizerGLES3::register_config();
|
||||
RasterizerGLES3::make_current();
|
||||
break;
|
||||
} else {
|
||||
if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2") || editor) {
|
||||
p_video_driver = VIDEO_DRIVER_GLES2;
|
||||
gles3 = false;
|
||||
continue;
|
||||
} else {
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (RasterizerGLES2::is_viable() == OK) {
|
||||
RasterizerGLES2::register_config();
|
||||
RasterizerGLES2::make_current();
|
||||
@ -1756,6 +1740,8 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,5 @@
|
||||
|
||||
#include <alloca.h>
|
||||
|
||||
#define GLES3_INCLUDE_H "thirdparty/glad/glad/glad.h"
|
||||
#define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h"
|
||||
#define PTHREAD_RENAME_SELF
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include "core/io/marshalls.h"
|
||||
#include "core/project_settings.h"
|
||||
#include "drivers/gles2/rasterizer_gles2.h"
|
||||
#include "drivers/gles3/rasterizer_gles3.h"
|
||||
#include "drivers/unix/ip_unix.h"
|
||||
#include "drivers/unix/net_socket_posix.h"
|
||||
#include "drivers/windows/dir_access_windows.h"
|
||||
@ -163,9 +162,9 @@ Error OS_UWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
|
||||
|
||||
ContextEGL_UWP::Driver opengl_api_type = ContextEGL_UWP::GLES_2_0;
|
||||
|
||||
if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
opengl_api_type = ContextEGL_UWP::GLES_2_0;
|
||||
}
|
||||
//if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
// opengl_api_type = ContextEGL_UWP::GLES_2_0;
|
||||
//}
|
||||
|
||||
bool gl_initialization_error = false;
|
||||
|
||||
@ -193,23 +192,6 @@ Error OS_UWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (opengl_api_type == ContextEGL_UWP::GLES_3_0) {
|
||||
if (RasterizerGLES3::is_viable() == OK) {
|
||||
RasterizerGLES3::register_config();
|
||||
RasterizerGLES3::make_current();
|
||||
break;
|
||||
} else {
|
||||
if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
|
||||
p_video_driver = VIDEO_DRIVER_GLES2;
|
||||
opengl_api_type = ContextEGL_UWP::GLES_2_0;
|
||||
continue;
|
||||
} else {
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (opengl_api_type == ContextEGL_UWP::GLES_2_0) {
|
||||
if (RasterizerGLES2::is_viable() == OK) {
|
||||
RasterizerGLES2::register_config();
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include "core/math/geometry.h"
|
||||
#include "core/version_generated.gen.h"
|
||||
#include "drivers/gles2/rasterizer_gles2.h"
|
||||
#include "drivers/gles3/rasterizer_gles3.h"
|
||||
#include "drivers/unix/net_socket_posix.h"
|
||||
#include "drivers/windows/dir_access_windows.h"
|
||||
#include "drivers/windows/file_access_windows.h"
|
||||
@ -1488,54 +1487,29 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
|
||||
|
||||
#if defined(OPENGL_ENABLED)
|
||||
|
||||
bool gles3_context = true;
|
||||
if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
gles3_context = false;
|
||||
}
|
||||
bool gles2_context = true;
|
||||
//if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
// gles2_context = true;
|
||||
//}
|
||||
|
||||
bool editor = Engine::get_singleton()->is_editor_hint();
|
||||
bool gl_initialization_error = false;
|
||||
|
||||
gl_context = NULL;
|
||||
while (!gl_context) {
|
||||
gl_context = memnew(ContextGL_Windows(hWnd, gles3_context));
|
||||
gl_context = memnew(ContextGL_Windows(hWnd, !gles2_context));
|
||||
|
||||
if (gl_context->initialize() != OK) {
|
||||
memdelete(gl_context);
|
||||
gl_context = NULL;
|
||||
|
||||
if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2") || editor) {
|
||||
if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
|
||||
p_video_driver = VIDEO_DRIVER_GLES2;
|
||||
gles3_context = false;
|
||||
} else {
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (gles3_context) {
|
||||
if (RasterizerGLES3::is_viable() == OK) {
|
||||
RasterizerGLES3::register_config();
|
||||
RasterizerGLES3::make_current();
|
||||
break;
|
||||
} else {
|
||||
if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2") || editor) {
|
||||
p_video_driver = VIDEO_DRIVER_GLES2;
|
||||
gles3_context = false;
|
||||
continue;
|
||||
} else {
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (gles2_context) {
|
||||
if (RasterizerGLES2::is_viable() == OK) {
|
||||
RasterizerGLES2::register_config();
|
||||
RasterizerGLES2::make_current();
|
||||
@ -1544,6 +1518,8 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,5 +32,4 @@
|
||||
//#else
|
||||
//#include <alloca.h>
|
||||
//#endif
|
||||
#define GLES3_INCLUDE_H "thirdparty/glad/glad/glad.h"
|
||||
#define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h"
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include "core/print_string.h"
|
||||
#include "detect_prime.h"
|
||||
#include "drivers/gles2/rasterizer_gles2.h"
|
||||
#include "drivers/gles3/rasterizer_gles3.h"
|
||||
#include "key_mapping_x11.h"
|
||||
#include "main/main.h"
|
||||
#include "servers/visual/visual_server_raster.h"
|
||||
@ -302,11 +301,11 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
|
||||
}
|
||||
}
|
||||
|
||||
ContextGL_X11::ContextType opengl_api_type = ContextGL_X11::GLES_3_0_COMPATIBLE;
|
||||
ContextGL_X11::ContextType opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
|
||||
|
||||
if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
|
||||
}
|
||||
//if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
// opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
|
||||
//}
|
||||
|
||||
bool editor = Engine::get_singleton()->is_editor_hint();
|
||||
bool gl_initialization_error = false;
|
||||
@ -335,23 +334,6 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (opengl_api_type == ContextGL_X11::GLES_3_0_COMPATIBLE) {
|
||||
if (RasterizerGLES3::is_viable() == OK) {
|
||||
RasterizerGLES3::register_config();
|
||||
RasterizerGLES3::make_current();
|
||||
break;
|
||||
} else {
|
||||
if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2") || editor) {
|
||||
p_video_driver = VIDEO_DRIVER_GLES2;
|
||||
opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
|
||||
continue;
|
||||
} else {
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (opengl_api_type == ContextGL_X11::GLES_2_0_COMPATIBLE) {
|
||||
if (RasterizerGLES2::is_viable() == OK) {
|
||||
RasterizerGLES2::register_config();
|
||||
|
@ -44,5 +44,4 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define GLES3_INCLUDE_H "thirdparty/glad/glad/glad.h"
|
||||
#define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h"
|
||||
|
Loading…
Reference in New Issue
Block a user