diff options
Diffstat (limited to 'drivers')
40 files changed, 369 insertions, 111 deletions
diff --git a/drivers/coreaudio/audio_driver_coreaudio.cpp b/drivers/coreaudio/audio_driver_coreaudio.cpp index 689f1f462d..45d62e797f 100644 --- a/drivers/coreaudio/audio_driver_coreaudio.cpp +++ b/drivers/coreaudio/audio_driver_coreaudio.cpp @@ -331,55 +331,57 @@ bool AudioDriverCoreAudio::try_lock() { } void AudioDriverCoreAudio::finish() { - OSStatus result; + if (audio_unit) { + OSStatus result; - lock(); + lock(); - AURenderCallbackStruct callback; - zeromem(&callback, sizeof(AURenderCallbackStruct)); - result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, kOutputBus, &callback, sizeof(callback)); - if (result != noErr) { - ERR_PRINT("AudioUnitSetProperty failed"); - } - - if (active) { - result = AudioOutputUnitStop(audio_unit); + AURenderCallbackStruct callback; + zeromem(&callback, sizeof(AURenderCallbackStruct)); + result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, kOutputBus, &callback, sizeof(callback)); if (result != noErr) { - ERR_PRINT("AudioOutputUnitStop failed"); + ERR_PRINT("AudioUnitSetProperty failed"); } - active = false; - } + if (active) { + result = AudioOutputUnitStop(audio_unit); + if (result != noErr) { + ERR_PRINT("AudioOutputUnitStop failed"); + } - result = AudioUnitUninitialize(audio_unit); - if (result != noErr) { - ERR_PRINT("AudioUnitUninitialize failed"); - } + active = false; + } + + result = AudioUnitUninitialize(audio_unit); + if (result != noErr) { + ERR_PRINT("AudioUnitUninitialize failed"); + } #ifdef OSX_ENABLED - AudioObjectPropertyAddress prop; - prop.mSelector = kAudioHardwarePropertyDefaultOutputDevice; - prop.mScope = kAudioObjectPropertyScopeGlobal; - prop.mElement = kAudioObjectPropertyElementMaster; + AudioObjectPropertyAddress prop; + prop.mSelector = kAudioHardwarePropertyDefaultOutputDevice; + prop.mScope = kAudioObjectPropertyScopeGlobal; + prop.mElement = kAudioObjectPropertyElementMaster; - result = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &prop, &output_device_address_cb, this); - if (result != noErr) { - ERR_PRINT("AudioObjectRemovePropertyListener failed"); - } + result = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &prop, &output_device_address_cb, this); + if (result != noErr) { + ERR_PRINT("AudioObjectRemovePropertyListener failed"); + } #endif - result = AudioComponentInstanceDispose(audio_unit); - if (result != noErr) { - ERR_PRINT("AudioComponentInstanceDispose failed"); - } + result = AudioComponentInstanceDispose(audio_unit); + if (result != noErr) { + ERR_PRINT("AudioComponentInstanceDispose failed"); + } - unlock(); + unlock(); + } if (mutex) { memdelete(mutex); mutex = NULL; } -}; +} Error AudioDriverCoreAudio::capture_start() { @@ -576,6 +578,7 @@ String AudioDriverCoreAudio::capture_get_device() { #endif AudioDriverCoreAudio::AudioDriverCoreAudio() { + audio_unit = NULL; active = false; mutex = NULL; diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index 3cee42983d..22e56fbb09 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -365,6 +365,7 @@ void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_ ERR_FAIL_COND(!texture); texture->width = p_width; texture->height = p_height; + texture->depth = 0; texture->format = p_format; texture->flags = p_flags; texture->stored_cube_sides = 0; @@ -384,6 +385,7 @@ void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_ } break; case VS::TEXTURE_TYPE_3D: { texture->images.resize(p_depth_3d); + texture->depth = p_depth_3d; } break; default: { ERR_PRINT("Unknown texture type!"); @@ -396,6 +398,7 @@ void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_ texture->alloc_width = texture->width; texture->alloc_height = texture->height; + texture->alloc_depth = texture->depth; texture->gl_format_cache = format; texture->gl_type_cache = type; @@ -591,7 +594,9 @@ Ref<Image> RasterizerStorageGLES2::texture_get_data(RID p_texture, int p_layer) PoolVector<uint8_t> data; - int data_size = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, real_format, texture->mipmaps > 1 ? -1 : 0); + int alloc_depth = MAX(texture->alloc_depth, 1); + + int data_size = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, real_format, texture->mipmaps > 1 ? -1 : 0) * alloc_depth; data.resize(data_size * 2); //add some memory at the end, just in case for buggy drivers PoolVector<uint8_t>::Write wb = data.write(); @@ -620,7 +625,7 @@ Ref<Image> RasterizerStorageGLES2::texture_get_data(RID p_texture, int p_layer) wb = PoolVector<uint8_t>::Write(); - data.resize(data_size); + data.resize(data_size / alloc_depth); Image *img = memnew(Image(texture->alloc_width, texture->alloc_height, texture->mipmaps > 1 ? true : false, real_format, data)); @@ -780,7 +785,7 @@ void RasterizerStorageGLES2::texture_debug_usage(List<VS::TextureInfo> *r_info) tinfo.format = t->format; tinfo.width = t->alloc_width; tinfo.height = t->alloc_height; - tinfo.depth = 0; + tinfo.depth = t->alloc_depth; tinfo.bytes = t->total_data_size; r_info->push_back(tinfo); } @@ -3662,6 +3667,8 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { texture->alloc_width = rt->width; texture->height = rt->height; texture->alloc_height = rt->height; + texture->depth = 0; + texture->alloc_depth = 0; texture->active = true; texture_set_flags(rt->texture, texture->flags); @@ -3709,6 +3716,8 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) { Texture *tex = texture_owner.get(rt->texture); tex->alloc_height = 0; tex->alloc_width = 0; + tex->alloc_depth = 0; + tex->depth = 0; tex->width = 0; tex->height = 0; tex->active = false; @@ -3732,8 +3741,10 @@ RID RasterizerStorageGLES2::render_target_create() { t->flags = 0; t->width = 0; t->height = 0; - t->alloc_height = 0; + t->depth = 0; t->alloc_width = 0; + t->alloc_height = 0; + t->alloc_depth = 0; t->format = Image::FORMAT_R8; t->target = GL_TEXTURE_2D; t->gl_format_cache = 0; diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h index 88783d7160..c3066b754d 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -232,7 +232,7 @@ public: String path; uint32_t flags; int width, height, depth; - int alloc_width, alloc_height; + int alloc_width, alloc_height, alloc_depth; Image::Format format; VS::TextureType type; @@ -275,8 +275,10 @@ public: flags = 0; width = 0; height = 0; + depth = 0; alloc_width = 0; alloc_height = 0; + alloc_depth = 0; format = Image::FORMAT_L8; target = 0; diff --git a/drivers/gles2/shaders/blend_shape.glsl b/drivers/gles2/shaders/blend_shape.glsl index d019062ba0..a1e954e33d 100644 --- a/drivers/gles2/shaders/blend_shape.glsl +++ b/drivers/gles2/shaders/blend_shape.glsl @@ -1,3 +1,4 @@ +/* clang-format off */ [vertex] /* @@ -23,6 +24,7 @@ ARRAY_INDEX=8, /* INPUT ATTRIBS */ layout(location = 0) in highp VFORMAT vertex_attrib; +/* clang-format on */ layout(location = 1) in vec3 normal_attrib; #ifdef ENABLE_TANGENT @@ -183,8 +185,10 @@ void main() { gl_Position = vec4(0.0); } +/* clang-format off */ [fragment] void main() { } +/* clang-format on */ diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index cee68a58ff..ba69ca9b6e 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -1,3 +1,4 @@ +/* clang-format off */ [vertex] #ifdef USE_GLES_OVER_GL @@ -9,6 +10,7 @@ precision mediump int; #endif uniform highp mat4 projection_matrix; +/* clang-format on */ uniform highp mat4 modelview_matrix; uniform highp mat4 extra_matrix; attribute highp vec2 vertex; // attrib:0 @@ -29,8 +31,12 @@ uniform vec4 src_rect; uniform highp float time; +/* clang-format off */ + VERTEX_SHADER_GLOBALS +/* clang-format on */ + vec2 select(vec2 a, vec2 b, bvec2 c) { vec2 ret; @@ -74,17 +80,21 @@ void main() { #endif -{ - vec2 src_vtx = outvec.xy; + { + vec2 src_vtx = outvec.xy; + /* clang-format off */ + VERTEX_SHADER_CODE -} + /* clang-format on */ + } color_interp = color; gl_Position = projection_matrix * modelview_matrix * outvec; } +/* clang-format off */ [fragment] #ifdef USE_GLES_OVER_GL @@ -96,6 +106,7 @@ precision mediump int; #endif uniform sampler2D color_texture; // texunit:-1 +/* clang-format on */ uniform highp vec2 color_texpixel_size; uniform mediump sampler2D normal_texture; // texunit:-2 @@ -118,8 +129,12 @@ uniform vec2 screen_pixel_size; #endif +/* clang-format off */ + FRAGMENT_SHADER_GLOBALS +/* clang-format on */ + void main() { vec4 color = color_interp; @@ -129,11 +144,13 @@ void main() { #ifdef SCREEN_UV_USED vec2 screen_uv = gl_FragCoord.xy * screen_pixel_size; #endif -{ + { + /* clang-format off */ FRAGMENT_SHADER_CODE -} + /* clang-format on */ + } color *= final_modulate; diff --git a/drivers/gles2/shaders/canvas_shadow.glsl b/drivers/gles2/shaders/canvas_shadow.glsl index 81af486101..e3c8140e31 100644 --- a/drivers/gles2/shaders/canvas_shadow.glsl +++ b/drivers/gles2/shaders/canvas_shadow.glsl @@ -1,6 +1,8 @@ +/* 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; @@ -15,9 +17,11 @@ void main() { position_interp = gl_Position; } +/* clang-format off */ [fragment] in highp vec4 position_interp; +/* clang-format on */ #ifdef USE_RGBA_SHADOWS diff --git a/drivers/gles2/shaders/copy.glsl b/drivers/gles2/shaders/copy.glsl index 6e9aad2a5d..16bbde196d 100644 --- a/drivers/gles2/shaders/copy.glsl +++ b/drivers/gles2/shaders/copy.glsl @@ -1,3 +1,4 @@ +/* clang-format off */ [vertex] #ifdef USE_GLES_OVER_GL @@ -9,6 +10,7 @@ precision mediump int; #endif attribute highp vec4 vertex_attrib; // attrib:0 +/* clang-format on */ #if defined(USE_CUBEMAP) || defined(USE_PANORAMA) attribute vec3 cube_in; // attrib:4 @@ -46,6 +48,7 @@ void main() { #endif } +/* clang-format off */ [fragment] #define M_PI 3.14159265359 @@ -63,6 +66,7 @@ varying vec3 cube_interp; #else varying vec2 uv_interp; #endif +/* clang-format on */ #ifdef USE_CUBEMAP uniform samplerCube source_cube; // texunit:0 diff --git a/drivers/gles2/shaders/cube_to_dp.glsl b/drivers/gles2/shaders/cube_to_dp.glsl index b44aab8946..3d24c36336 100644 --- a/drivers/gles2/shaders/cube_to_dp.glsl +++ b/drivers/gles2/shaders/cube_to_dp.glsl @@ -1,3 +1,4 @@ +/* clang-format off */ [vertex] #ifdef USE_GLES_OVER_GL @@ -9,6 +10,7 @@ precision mediump int; #endif attribute highp vec4 vertex_attrib; // attrib:0 +/* clang-format on */ attribute vec2 uv_in; // attrib:4 varying vec2 uv_interp; @@ -19,6 +21,7 @@ void main() { gl_Position = vertex_attrib; } +/* clang-format off */ [fragment] #ifdef USE_GLES_OVER_GL @@ -30,6 +33,7 @@ precision mediump int; #endif uniform highp samplerCube source_cube; //texunit:0 +/* clang-format on */ varying vec2 uv_interp; uniform bool z_flip; diff --git a/drivers/gles2/shaders/cubemap_filter.glsl b/drivers/gles2/shaders/cubemap_filter.glsl index 0d60104480..2a1ad8d8f2 100644 --- a/drivers/gles2/shaders/cubemap_filter.glsl +++ b/drivers/gles2/shaders/cubemap_filter.glsl @@ -1,3 +1,4 @@ +/* clang-format off */ [vertex] #ifdef USE_GLES_OVER_GL @@ -9,6 +10,7 @@ precision mediump int; #endif attribute highp vec2 vertex; // attrib:0 +/* clang-format on */ attribute highp vec2 uv; // attrib:4 varying highp vec2 uv_interp; @@ -19,6 +21,7 @@ void main() { gl_Position = vec4(vertex, 0, 1); } +/* clang-format off */ [fragment] #extension GL_ARB_shader_texture_lod : enable @@ -41,6 +44,7 @@ uniform sampler2D source_panorama; //texunit:0 #else uniform samplerCube source_cube; //texunit:0 #endif +/* clang-format on */ uniform int face_id; uniform float roughness; diff --git a/drivers/gles2/shaders/effect_blur.glsl b/drivers/gles2/shaders/effect_blur.glsl index 0e2d28af20..a531802c75 100644 --- a/drivers/gles2/shaders/effect_blur.glsl +++ b/drivers/gles2/shaders/effect_blur.glsl @@ -1,6 +1,8 @@ +/* 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; @@ -22,6 +24,7 @@ void main() { #endif } +/* clang-format off */ [fragment] #if !defined(GLES_OVER_GL) @@ -29,6 +32,7 @@ precision mediump float; #endif in vec2 uv_interp; +/* clang-format on */ uniform sampler2D source_color; //texunit:0 #ifdef SSAO_MERGE diff --git a/drivers/gles2/shaders/exposure.glsl b/drivers/gles2/shaders/exposure.glsl index 18fff1ae36..759adcda06 100644 --- a/drivers/gles2/shaders/exposure.glsl +++ b/drivers/gles2/shaders/exposure.glsl @@ -1,15 +1,19 @@ +/* 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 diff --git a/drivers/gles2/shaders/particles.glsl b/drivers/gles2/shaders/particles.glsl index 5af4b65b28..5974050fc1 100644 --- a/drivers/gles2/shaders/particles.glsl +++ b/drivers/gles2/shaders/particles.glsl @@ -1,6 +1,8 @@ +/* clang-format off */ [vertex] 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; @@ -45,16 +47,22 @@ 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); @@ -165,9 +173,11 @@ void main() { //execute shader { + /* clang-format off */ VERTEX_SHADER_CODE + /* clang-format on */ } #if !defined(DISABLE_FORCE) @@ -223,6 +233,7 @@ VERTEX_SHADER_CODE #endif //PARTICLES_COPY } +/* clang-format off */ [fragment] //any code here is never executed, stuff is filled just so it works @@ -240,12 +251,16 @@ MATERIAL_UNIFORMS FRAGMENT_SHADER_GLOBALS void main() { - { + LIGHT_SHADER_CODE + } { + FRAGMENT_SHADER_CODE + } } +/* clang-format on */ diff --git a/drivers/gles2/shaders/resolve.glsl b/drivers/gles2/shaders/resolve.glsl index 05bb922eec..5c6f5d6561 100644 --- a/drivers/gles2/shaders/resolve.glsl +++ b/drivers/gles2/shaders/resolve.glsl @@ -1,6 +1,8 @@ +/* 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; @@ -11,6 +13,7 @@ void main() { gl_Position = vertex_attrib; } +/* clang-format off */ [fragment] #if !defined(GLES_OVER_GL) @@ -18,6 +21,7 @@ precision mediump float; #endif in vec2 uv_interp; +/* clang-format on */ uniform sampler2D source_specular; //texunit:0 uniform sampler2D source_ssr; //texunit:1 diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl index 8bcb3b5f1d..906c089170 100644 --- a/drivers/gles2/shaders/scene.glsl +++ b/drivers/gles2/shaders/scene.glsl @@ -1,3 +1,4 @@ +/* clang-format off */ [vertex] #ifdef USE_GLES_OVER_GL @@ -15,6 +16,7 @@ precision mediump int; // attribute highp vec4 vertex_attrib; // attrib:0 +/* clang-format on */ attribute vec3 normal_attrib; // attrib:1 #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) @@ -108,8 +110,12 @@ varying vec2 uv_interp; varying vec2 uv2_interp; #endif +/* clang-format off */ + VERTEX_SHADER_GLOBALS +/* clang-format on */ + void main() { highp vec4 vertex = vertex_attrib; @@ -206,11 +212,13 @@ void main() { #define world_transform world_matrix -{ + { + /* clang-format off */ VERTEX_SHADER_CODE -} + /* clang-format on */ + } vec4 outvec = vertex; @@ -254,6 +262,7 @@ VERTEX_SHADER_CODE gl_Position = projection_matrix * vec4(vertex_interp, 1.0); } +/* clang-format off */ [fragment] #extension GL_ARB_shader_texture_lod : enable @@ -279,6 +288,7 @@ precision mediump int; // uniform mat4 camera_matrix; +/* clang-format on */ uniform mat4 camera_inverse_matrix; uniform mat4 projection_matrix; uniform mat4 projection_inverse_matrix; @@ -390,8 +400,12 @@ vec3 metallic_to_specular_color(float metallic, float specular, vec3 albedo) { return mix(vec3(dielectric), albedo, metallic); // TODO: reference? } +/* clang-format off */ + FRAGMENT_SHADER_GLOBALS +/* clang-format on */ + #ifdef LIGHT_PASS void light_compute( vec3 N, @@ -504,11 +518,13 @@ void main() { vec2 screen_uv = gl_FragCoord.xy * screen_pixel_size; #endif -{ + { + /* clang-format off */ FRAGMENT_SHADER_CODE -} + /* clang-format on */ + } #if defined(ENABLE_NORMALMAP) normalmap.xy = normalmap.xy * 2.0 - 1.0; diff --git a/drivers/gles2/shaders/screen_space_reflection.glsl b/drivers/gles2/shaders/screen_space_reflection.glsl index 77af874ee4..a11da10b61 100644 --- a/drivers/gles2/shaders/screen_space_reflection.glsl +++ b/drivers/gles2/shaders/screen_space_reflection.glsl @@ -1,6 +1,8 @@ +/* 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; @@ -13,9 +15,11 @@ void main() { 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 diff --git a/drivers/gles2/shaders/ssao.glsl b/drivers/gles2/shaders/ssao.glsl index 8dbe8c6ba9..82eea8f274 100644 --- a/drivers/gles2/shaders/ssao.glsl +++ b/drivers/gles2/shaders/ssao.glsl @@ -1,6 +1,8 @@ +/* clang-format off */ [vertex] layout(location = 0) in highp vec4 vertex_attrib; +/* clang-format on */ void main() { @@ -8,6 +10,7 @@ void main() { gl_Position.z = 1.0; } +/* clang-format off */ [fragment] #define TWO_PI 6.283185307179586476925286766559 @@ -53,6 +56,7 @@ const int ROTATIONS[] = int[]( 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]; diff --git a/drivers/gles2/shaders/ssao_blur.glsl b/drivers/gles2/shaders/ssao_blur.glsl index 82b735a2b4..e4133ad534 100644 --- a/drivers/gles2/shaders/ssao_blur.glsl +++ b/drivers/gles2/shaders/ssao_blur.glsl @@ -1,6 +1,8 @@ +/* clang-format off */ [vertex] layout(location = 0) in highp vec4 vertex_attrib; +/* clang-format on */ void main() { @@ -8,9 +10,11 @@ void main() { 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 @@ -43,7 +47,7 @@ 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 +//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; diff --git a/drivers/gles2/shaders/ssao_minify.glsl b/drivers/gles2/shaders/ssao_minify.glsl index 777a0069fc..272f3e236e 100644 --- a/drivers/gles2/shaders/ssao_minify.glsl +++ b/drivers/gles2/shaders/ssao_minify.glsl @@ -1,12 +1,15 @@ +/* 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 @@ -14,6 +17,7 @@ void main() { #define SDEPTH_TYPE highp sampler2D uniform float camera_z_far; uniform float camera_z_near; +/* clang-format on */ #else diff --git a/drivers/gles2/shaders/subsurf_scattering.glsl b/drivers/gles2/shaders/subsurf_scattering.glsl index fb7908f06a..f40fb3a244 100644 --- a/drivers/gles2/shaders/subsurf_scattering.glsl +++ b/drivers/gles2/shaders/subsurf_scattering.glsl @@ -1,6 +1,8 @@ +/* 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; @@ -11,6 +13,7 @@ void main() { gl_Position = vertex_attrib; } +/* clang-format off */ [fragment] //#define QUALIFIER uniform // some guy on the interweb says it may be faster with this @@ -18,6 +21,7 @@ void main() { #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), diff --git a/drivers/gles2/shaders/tonemap.glsl b/drivers/gles2/shaders/tonemap.glsl index f3f6a85565..eae3b5a1ca 100644 --- a/drivers/gles2/shaders/tonemap.glsl +++ b/drivers/gles2/shaders/tonemap.glsl @@ -1,6 +1,8 @@ +/* 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; @@ -14,6 +16,7 @@ void main() { #endif } +/* clang-format off */ [fragment] #if !defined(GLES_OVER_GL) @@ -21,6 +24,7 @@ precision mediump float; #endif in vec2 uv_interp; +/* clang-format on */ uniform highp sampler2D source; //texunit:0 @@ -115,7 +119,7 @@ vec4 texture2D_bicubic(sampler2D tex, vec2 uv, int p_lod) { vec2 p3 = (vec2(iuv.x + h1x, iuv.y + h1y) - 0.5) * pixel_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))); + (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) diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index eebdbe9493..88f14890ef 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -1008,7 +1008,10 @@ RID RasterizerSceneGLES3::light_instance_create(RID p_light) { light_instance->light = p_light; light_instance->light_ptr = storage->light_owner.getornull(p_light); - ERR_FAIL_COND_V(!light_instance->light_ptr, RID()); + if (!light_instance->light_ptr) { + memdelete(light_instance); + ERR_FAIL_COND_V(!light_instance->light_ptr, RID()); + } light_instance->self = light_instance_owner.make_rid(light_instance); diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 3697cccef4..5ee6c28d83 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -667,7 +667,7 @@ void RasterizerStorageGLES3::texture_allocate(RID p_texture, int p_width, int p_ int mipmaps = 0; while (width != 1 && height != 1) { - glTexImage3D(texture->target, 0, internal_format, width, height, depth, 0, format, type, NULL); + glTexImage3D(texture->target, mipmaps, internal_format, width, height, depth, 0, format, type, NULL); width = MAX(1, width / 2); height = MAX(1, height / 2); @@ -1029,7 +1029,11 @@ Ref<Image> RasterizerStorageGLES3::texture_get_data(RID p_texture, int p_layer) PoolVector<uint8_t> data; - int data_size = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, real_format, texture->mipmaps > 1 ? -1 : 0); + int alloc_depth = MAX(texture->alloc_depth, 1); + + ERR_FAIL_COND_V(p_layer < 0 || p_layer >= alloc_depth, Ref<Image>()); + + int data_size = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, real_format, texture->mipmaps > 1 ? -1 : 0) * alloc_depth; data.resize(data_size * 2); //add some memory at the end, just in case for buggy drivers PoolVector<uint8_t>::Write wb = data.write(); @@ -1085,9 +1089,13 @@ Ref<Image> RasterizerStorageGLES3::texture_get_data(RID p_texture, int p_layer) img_format = real_format; } - wb = PoolVector<uint8_t>::Write(); + int slice_size = data_size / alloc_depth; + + if (p_layer) { + memcpy(&wb[0], &wb[slice_size * p_layer], slice_size); + } - data.resize(data_size); + data.resize(slice_size); Image *img = memnew(Image(texture->alloc_width, texture->alloc_height, texture->mipmaps > 1 ? true : false, img_format, data)); @@ -1275,7 +1283,7 @@ void RasterizerStorageGLES3::texture_debug_usage(List<VS::TextureInfo> *r_info) tinfo.format = t->format; tinfo.width = t->alloc_width; tinfo.height = t->alloc_height; - tinfo.depth = 0; + tinfo.depth = t->alloc_depth; tinfo.bytes = t->total_data_size; r_info->push_back(tinfo); } @@ -1442,6 +1450,7 @@ RID RasterizerStorageGLES3::texture_create_radiance_cubemap(RID p_source, int p_ ctex->height = p_resolution; ctex->alloc_width = p_resolution; ctex->alloc_height = p_resolution; + ctex->alloc_depth = 0; ctex->format = use_float ? Image::FORMAT_RGBAH : Image::FORMAT_RGBA8; ctex->target = GL_TEXTURE_CUBE_MAP; ctex->gl_format_cache = format; @@ -6464,6 +6473,7 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { Texture *tex = texture_owner.get(rt->texture); tex->alloc_height = 0; tex->alloc_width = 0; + tex->alloc_depth = 0; tex->width = 0; tex->height = 0; tex->active = false; @@ -6577,6 +6587,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { tex->height = rt->height; tex->alloc_height = rt->height; tex->active = true; + tex->alloc_depth = 0; texture_set_flags(rt->texture, tex->flags); } @@ -6865,8 +6876,10 @@ RID RasterizerStorageGLES3::render_target_create() { t->flags = 0; t->width = 0; t->height = 0; + t->depth = 0; t->alloc_height = 0; t->alloc_width = 0; + t->alloc_depth = 0; t->format = Image::FORMAT_R8; t->target = GL_TEXTURE_2D; t->gl_format_cache = 0; @@ -6998,7 +7011,10 @@ RID RasterizerStorageGLES3::canvas_light_shadow_buffer_create(int p_width) { //printf("errnum: %x\n",status); glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); - ERR_FAIL_COND_V(status != GL_FRAMEBUFFER_COMPLETE, RID()); + if (status != GL_FRAMEBUFFER_COMPLETE) { + memdelete(cls); + ERR_FAIL_COND_V(status != GL_FRAMEBUFFER_COMPLETE, RID()); + } return canvas_light_shadow_owner.make_rid(cls); } diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index b74dd77e26..43b7d5fc99 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -294,7 +294,13 @@ public: stored_cube_sides = 0; ignore_mipmaps = false; render_target = NULL; - flags = width = height = 0; + flags = 0; + width = 0; + height = 0; + depth = 0; + alloc_width = 0; + alloc_height = 0; + alloc_depth = 0; tex_id = 0; data_size = 0; format = Image::FORMAT_L8; diff --git a/drivers/gles3/shaders/blend_shape.glsl b/drivers/gles3/shaders/blend_shape.glsl index d019062ba0..a1e954e33d 100644 --- a/drivers/gles3/shaders/blend_shape.glsl +++ b/drivers/gles3/shaders/blend_shape.glsl @@ -1,3 +1,4 @@ +/* clang-format off */ [vertex] /* @@ -23,6 +24,7 @@ ARRAY_INDEX=8, /* INPUT ATTRIBS */ layout(location = 0) in highp VFORMAT vertex_attrib; +/* clang-format on */ layout(location = 1) in vec3 normal_attrib; #ifdef ENABLE_TANGENT @@ -183,8 +185,10 @@ void main() { gl_Position = vec4(0.0); } +/* clang-format off */ [fragment] void main() { } +/* clang-format on */ diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index 9e99305fe7..53f563303a 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -1,6 +1,8 @@ +/* clang-format off */ [vertex] layout(location = 0) in highp vec2 vertex; +/* clang-format on */ layout(location = 3) in vec4 color_attrib; #ifdef USE_SKELETON @@ -97,16 +99,22 @@ uniform int v_frames; #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; @@ -151,11 +159,13 @@ void main() { #define extra_matrix extra_matrix2 -{ + { + /* clang-format off */ VERTEX_SHADER_CODE -} + /* clang-format on */ + } #ifdef USE_NINEPATCH @@ -188,29 +198,29 @@ VERTEX_SHADER_CODE highp mat2x4 m; m = mat2x4( texelFetch(skeleton_texture, tex_ofs, 0), - texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0)) - * bone_weights.x; + 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; + 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; + 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; + 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; @@ -246,9 +256,11 @@ VERTEX_SHADER_CODE #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 @@ -313,16 +325,22 @@ 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, @@ -339,8 +357,12 @@ void light_compute( #if defined(USE_LIGHT_SHADER_CODE) + /* clang-format off */ + LIGHT_SHADER_CODE + /* clang-format on */ + #endif } @@ -472,8 +494,12 @@ void main() { vec3 normal_map = vec3(0.0, 0.0, 1.0); #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 diff --git a/drivers/gles3/shaders/canvas_shadow.glsl b/drivers/gles3/shaders/canvas_shadow.glsl index b06e9076d9..68d0713385 100644 --- a/drivers/gles3/shaders/canvas_shadow.glsl +++ b/drivers/gles3/shaders/canvas_shadow.glsl @@ -1,6 +1,8 @@ +/* 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; @@ -15,9 +17,11 @@ void main() { 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; diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl index e17b71df27..a5637537d2 100644 --- a/drivers/gles3/shaders/copy.glsl +++ b/drivers/gles3/shaders/copy.glsl @@ -1,6 +1,8 @@ +/* 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 @@ -45,6 +47,7 @@ void main() { #endif } +/* clang-format off */ [fragment] #define M_PI 3.14159265359 @@ -58,6 +61,7 @@ in vec3 cube_interp; #else in vec2 uv_interp; #endif +/* clang-format on */ #ifdef USE_ASYM_PANO uniform highp mat4 pano_transform; diff --git a/drivers/gles3/shaders/cube_to_dp.glsl b/drivers/gles3/shaders/cube_to_dp.glsl index 2911746bb7..2b74f054f9 100644 --- a/drivers/gles3/shaders/cube_to_dp.glsl +++ b/drivers/gles3/shaders/cube_to_dp.glsl @@ -1,6 +1,8 @@ +/* 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; @@ -11,9 +13,11 @@ void main() { 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; diff --git a/drivers/gles3/shaders/cubemap_filter.glsl b/drivers/gles3/shaders/cubemap_filter.glsl index 7f2dc5057c..f65f798ff0 100644 --- a/drivers/gles3/shaders/cubemap_filter.glsl +++ b/drivers/gles3/shaders/cubemap_filter.glsl @@ -1,6 +1,8 @@ +/* clang-format off */ [vertex] layout(location = 0) in highp vec2 vertex; +/* clang-format on */ layout(location = 4) in highp vec2 uv; @@ -12,9 +14,11 @@ void main() { gl_Position = vec4(vertex, 0, 1); } +/* clang-format off */ [fragment] precision highp float; +/* clang-format on */ precision highp int; #ifdef USE_SOURCE_PANORAMA diff --git a/drivers/gles3/shaders/effect_blur.glsl b/drivers/gles3/shaders/effect_blur.glsl index 3872ee8d1d..b67d06bc10 100644 --- a/drivers/gles3/shaders/effect_blur.glsl +++ b/drivers/gles3/shaders/effect_blur.glsl @@ -1,6 +1,8 @@ +/* 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; @@ -22,11 +24,13 @@ void main() { #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 diff --git a/drivers/gles3/shaders/exposure.glsl b/drivers/gles3/shaders/exposure.glsl index 18fff1ae36..759adcda06 100644 --- a/drivers/gles3/shaders/exposure.glsl +++ b/drivers/gles3/shaders/exposure.glsl @@ -1,15 +1,19 @@ +/* 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 diff --git a/drivers/gles3/shaders/particles.glsl b/drivers/gles3/shaders/particles.glsl index 56e5545efe..8523c08597 100644 --- a/drivers/gles3/shaders/particles.glsl +++ b/drivers/gles3/shaders/particles.glsl @@ -1,6 +1,8 @@ +/* clang-format off */ [vertex] 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; @@ -45,16 +47,22 @@ 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); @@ -165,7 +173,11 @@ void main() { //execute shader { + /* clang-format off */ + VERTEX_SHADER_CODE + + /* clang-format on */ } #if !defined(DISABLE_FORCE) @@ -221,6 +233,7 @@ VERTEX_SHADER_CODE #endif //PARTICLES_COPY } +/* clang-format off */ [fragment] // any code here is never executed, stuff is filled just so it works @@ -240,10 +253,15 @@ FRAGMENT_SHADER_GLOBALS void main() { { + LIGHT_SHADER_CODE + } { + FRAGMENT_SHADER_CODE + } } +/* clang-format on */ diff --git a/drivers/gles3/shaders/resolve.glsl b/drivers/gles3/shaders/resolve.glsl index d860fa544f..d64d8308c1 100644 --- a/drivers/gles3/shaders/resolve.glsl +++ b/drivers/gles3/shaders/resolve.glsl @@ -1,6 +1,8 @@ +/* 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; @@ -11,11 +13,13 @@ void main() { 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 diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index cacce93dc5..12cbe02d0c 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -1,3 +1,4 @@ +/* clang-format off */ [vertex] #define M_PI 3.14159265359 @@ -21,6 +22,7 @@ ARRAY_INDEX=8, /* INPUT ATTRIBS */ layout(location = 0) in highp vec4 vertex_attrib; +/* clang-format on */ layout(location = 1) in vec3 normal_attrib; #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY) layout(location = 2) in vec4 tangent_attrib; @@ -226,16 +228,22 @@ out vec3 binormal_interp; #if defined(USE_MATERIAL) +/* clang-format off */ layout(std140) uniform UniformData { // ubo:1 MATERIAL_UNIFORMS }; +/* clang-format on */ #endif +/* clang-format off */ + VERTEX_SHADER_GLOBALS +/* clang-format on */ + #ifdef RENDER_DEPTH_DUAL_PARABOLOID out highp float dp_clip; @@ -340,32 +348,32 @@ void main() { m = mat3x4( texelFetch(skeleton_texture, tex_ofs, 0), texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0), - texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0)) - * bone_weights.x; + texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0)) * + bone_weights.x; tex_ofs = ivec2(bone_indicesi.y % 256, (bone_indicesi.y / 256) * 3); m += mat3x4( - texelFetch(skeleton_texture, tex_ofs, 0), - texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0), - texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0)) - * bone_weights.y; + texelFetch(skeleton_texture, tex_ofs, 0), + texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0), + texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0)) * + bone_weights.y; tex_ofs = ivec2(bone_indicesi.z % 256, (bone_indicesi.z / 256) * 3); m += mat3x4( - texelFetch(skeleton_texture, tex_ofs, 0), - texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0), - texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0)) - * bone_weights.z; + texelFetch(skeleton_texture, tex_ofs, 0), + texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0), + texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0)) * + bone_weights.z; tex_ofs = ivec2(bone_indicesi.w % 256, (bone_indicesi.w / 256) * 3); m += mat3x4( - texelFetch(skeleton_texture, tex_ofs, 0), - texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0), - texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0)) - * bone_weights.w; + texelFetch(skeleton_texture, tex_ofs, 0), + texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0), + texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0)) * + bone_weights.w; mat4 bone_matrix = transpose(mat4(m[0], m[1], m[2], vec4(0.0, 0.0, 0.0, 1.0))); @@ -374,11 +382,13 @@ void main() { #endif mat4 modelview = camera_inverse_matrix * world_matrix; -{ + { + /* clang-format off */ VERTEX_SHADER_CODE -} + /* clang-format on */ + } // using local coordinates (default) #if !defined(SKIP_TRANSFORM_USED) && !defined(VERTEX_WORLD_COORDS_USED) @@ -501,6 +511,7 @@ VERTEX_SHADER_CODE #endif // USE_VERTEX_LIGHTING } +/* clang-format off */ [fragment] /* texture unit usage, N is max_texture_unity-N @@ -519,6 +530,7 @@ VERTEX_SHADER_CODE */ uniform highp mat4 world_transform; +/* clang-format on */ #define M_PI 3.14159265359 @@ -552,7 +564,6 @@ layout(std140) uniform Radiance { // ubo:2 mat4 radiance_inverse_xform; float radiance_ambient_contribution; - }; #define RADIANCE_MAX_LOD 5.0 @@ -608,16 +619,22 @@ vec3 textureDualParaboloid(sampler2D p_tex, vec3 p_vec, float p_roughness) { #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 */ + layout(std140) uniform SceneData { highp mat4 projection_matrix; @@ -663,7 +680,7 @@ layout(std140) uniform SceneData { highp float fog_height_curve; }; -//directional light data + //directional light data #ifdef USE_LIGHT_DIRECTIONAL @@ -701,7 +718,6 @@ struct LightData { mediump vec4 light_clamp; mediump vec4 shadow_color_contact; highp mat4 shadow_matrix; - }; layout(std140) uniform OmniLightData { // ubo:4 @@ -916,8 +932,12 @@ void light_compute(vec3 N, vec3 L, vec3 V, vec3 B, vec3 T, vec3 light_color, vec vec3 light = L; vec3 view = V; + /* clang-format off */ + LIGHT_SHADER_CODE + /* clang-format on */ + #else float NdotL = dot(N, L); float cNdotL = max(NdotL, 0.0); // clamped NdotL @@ -1599,11 +1619,13 @@ void main() { float sss_strength = 0.0; #endif -{ + { + /* clang-format off */ FRAGMENT_SHADER_CODE -} + /* clang-format on */ + } #if defined(ALPHA_SCISSOR_USED) if (alpha < alpha_scissor) { diff --git a/drivers/gles3/shaders/screen_space_reflection.glsl b/drivers/gles3/shaders/screen_space_reflection.glsl index 73b1ddbb0e..86546319a0 100644 --- a/drivers/gles3/shaders/screen_space_reflection.glsl +++ b/drivers/gles3/shaders/screen_space_reflection.glsl @@ -1,6 +1,8 @@ +/* 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; @@ -13,9 +15,11 @@ void main() { 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 diff --git a/drivers/gles3/shaders/ssao.glsl b/drivers/gles3/shaders/ssao.glsl index 2eeeac31c3..be44365169 100644 --- a/drivers/gles3/shaders/ssao.glsl +++ b/drivers/gles3/shaders/ssao.glsl @@ -1,6 +1,8 @@ +/* clang-format off */ [vertex] layout(location = 0) in highp vec4 vertex_attrib; +/* clang-format on */ void main() { @@ -8,6 +10,7 @@ void main() { gl_Position.z = 1.0; } +/* clang-format off */ [fragment] #define TWO_PI 6.283185307179586476925286766559 @@ -46,8 +49,8 @@ const int ROTATIONS[] = int[]( 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 -); + 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]; diff --git a/drivers/gles3/shaders/ssao_blur.glsl b/drivers/gles3/shaders/ssao_blur.glsl index 5526d0de18..c49ea1e957 100644 --- a/drivers/gles3/shaders/ssao_blur.glsl +++ b/drivers/gles3/shaders/ssao_blur.glsl @@ -1,6 +1,8 @@ +/* clang-format off */ [vertex] layout(location = 0) in highp vec4 vertex_attrib; +/* clang-format on */ void main() { @@ -8,9 +10,11 @@ void main() { 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 @@ -36,16 +40,14 @@ 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 + //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; diff --git a/drivers/gles3/shaders/ssao_minify.glsl b/drivers/gles3/shaders/ssao_minify.glsl index 777a0069fc..1696648dae 100644 --- a/drivers/gles3/shaders/ssao_minify.glsl +++ b/drivers/gles3/shaders/ssao_minify.glsl @@ -1,18 +1,22 @@ +/* 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 diff --git a/drivers/gles3/shaders/subsurf_scattering.glsl b/drivers/gles3/shaders/subsurf_scattering.glsl index af0d5a0e62..f40fb3a244 100644 --- a/drivers/gles3/shaders/subsurf_scattering.glsl +++ b/drivers/gles3/shaders/subsurf_scattering.glsl @@ -1,6 +1,8 @@ +/* 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; @@ -11,6 +13,7 @@ void main() { gl_Position = vertex_attrib; } +/* clang-format off */ [fragment] //#define QUALIFIER uniform // some guy on the interweb says it may be faster with this @@ -18,7 +21,8 @@ void main() { #ifdef USE_25_SAMPLES const int kernel_size = 25; -QUALIFIER vec2 kernel[25] = vec2[] ( +/* clang-format on */ +QUALIFIER vec2 kernel[25] = vec2[]( vec2(0.530605, 0.0), vec2(0.000973794, -3.0), vec2(0.00333804, -2.52083), @@ -43,8 +47,7 @@ QUALIFIER vec2 kernel[25] = vec2[] ( vec2(0.00700976, 1.6875), vec2(0.00500364, 2.08333), vec2(0.00333804, 2.52083), - vec2(0.000973794, 3.0) -); + vec2(0.000973794, 3.0)); #endif //USE_25_SAMPLES #ifdef USE_17_SAMPLES @@ -66,11 +69,9 @@ QUALIFIER vec2 kernel[17] = vec2[]( vec2(0.0216301, 0.78125), vec2(0.0144609, 1.125), vec2(0.0100386, 1.53125), - vec2(0.00317394, 2.0) -); + vec2(0.00317394, 2.0)); #endif //USE_17_SAMPLES - #ifdef USE_11_SAMPLES const int kernel_size = 11; QUALIFIER vec2 kernel[11] = vec2[]( @@ -84,8 +85,7 @@ QUALIFIER vec2 kernel[11] = vec2[]( vec2(0.0821904, 0.32), vec2(0.03639, 0.72), vec2(0.0192831, 1.28), - vec2(0.00471691, 2.0) -); + vec2(0.00471691, 2.0)); #endif //USE_11_SAMPLES uniform float max_radius; diff --git a/drivers/gles3/shaders/tonemap.glsl b/drivers/gles3/shaders/tonemap.glsl index 56876bdb72..e4aa8d5730 100644 --- a/drivers/gles3/shaders/tonemap.glsl +++ b/drivers/gles3/shaders/tonemap.glsl @@ -1,6 +1,8 @@ +/* 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; @@ -15,11 +17,13 @@ void main() { #endif } +/* clang-format off */ [fragment] #if !defined(GLES_OVER_GL) precision mediump float; #endif +/* clang-format on */ in vec2 uv_interp; @@ -110,10 +114,8 @@ vec4 texture2D_bicubic(sampler2D tex, vec2 uv, int p_lod) { vec2 p2 = (vec2(iuv.x + h0x, iuv.y + h1y) - vec2(0.5f)) * pixel_size; vec2 p3 = (vec2(iuv.x + h1x, iuv.y + h1y) - vec2(0.5f)) * pixel_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)); + 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) |