diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/alsa/audio_driver_alsa.cpp | 4 | ||||
-rw-r--r-- | drivers/dummy/rasterizer_dummy.h | 2 | ||||
-rw-r--r-- | drivers/gles2/rasterizer_scene_gles2.cpp | 12 | ||||
-rw-r--r-- | drivers/gles2/rasterizer_storage_gles2.cpp | 28 | ||||
-rw-r--r-- | drivers/gles2/rasterizer_storage_gles2.h | 9 | ||||
-rw-r--r-- | drivers/gles2/shader_compiler_gles2.cpp | 7 | ||||
-rw-r--r-- | drivers/gles2/shaders/canvas.glsl | 26 | ||||
-rw-r--r-- | drivers/gles2/shaders/copy.glsl | 4 | ||||
-rw-r--r-- | drivers/gles2/shaders/scene.glsl | 11 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.cpp | 9 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.cpp | 18 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.h | 6 | ||||
-rw-r--r-- | drivers/gles3/shader_compiler_gles3.cpp | 7 | ||||
-rw-r--r-- | drivers/gles3/shaders/canvas.glsl | 26 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 11 | ||||
-rw-r--r-- | drivers/unix/file_access_unix.cpp | 23 | ||||
-rw-r--r-- | drivers/unix/os_unix.cpp | 2 |
17 files changed, 91 insertions, 114 deletions
diff --git a/drivers/alsa/audio_driver_alsa.cpp b/drivers/alsa/audio_driver_alsa.cpp index 0611d7d4e0..42899c0f76 100644 --- a/drivers/alsa/audio_driver_alsa.cpp +++ b/drivers/alsa/audio_driver_alsa.cpp @@ -171,14 +171,14 @@ void AudioDriverALSA::thread_func(void *p_udata) { ad->start_counting_ticks(); if (!ad->active) { - for (unsigned int i = 0; i < ad->period_size * ad->channels; i++) { + for (uint64_t i = 0; i < ad->period_size * ad->channels; i++) { ad->samples_out.write[i] = 0; } } else { ad->audio_server_process(ad->period_size, ad->samples_in.ptrw()); - for (unsigned int i = 0; i < ad->period_size * ad->channels; i++) { + for (uint64_t i = 0; i < ad->period_size * ad->channels; i++) { ad->samples_out.write[i] = ad->samples_in[i] >> 16; } } diff --git a/drivers/dummy/rasterizer_dummy.h b/drivers/dummy/rasterizer_dummy.h index 3deaef09e7..8d5cf2ebea 100644 --- a/drivers/dummy/rasterizer_dummy.h +++ b/drivers/dummy/rasterizer_dummy.h @@ -181,8 +181,8 @@ public: DummyTexture *t = texture_owner.get(p_texture); ERR_FAIL_COND(!t); + ERR_FAIL_COND_MSG(p_image.is_null(), "It's not a reference to a valid Image object."); ERR_FAIL_COND(t->format != p_image->get_format()); - ERR_FAIL_COND(p_image.is_null()); ERR_FAIL_COND(src_w <= 0 || src_h <= 0); ERR_FAIL_COND(src_x < 0 || src_y < 0 || src_x + src_w > p_image->get_width() || src_y + src_h > p_image->get_height()); ERR_FAIL_COND(dst_x < 0 || dst_y < 0 || dst_x + src_w > t->width || dst_y + src_h > t->height); diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp index cc414c26af..a8fa30c709 100644 --- a/drivers/gles2/rasterizer_scene_gles2.cpp +++ b/drivers/gles2/rasterizer_scene_gles2.cpp @@ -1432,11 +1432,11 @@ void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element, Raste } } - bool clear_skeleton_buffer = !storage->config.float_texture_supported; + bool clear_skeleton_buffer = storage->config.use_skeleton_software; if (p_skeleton) { - if (storage->config.float_texture_supported) { + if (!storage->config.use_skeleton_software) { //use float texture workflow glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1); glBindTexture(GL_TEXTURE_2D, p_skeleton->tex_id); @@ -2452,7 +2452,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, if (skeleton) { state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, true); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, !storage->config.float_texture_supported); + state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, storage->config.use_skeleton_software); } else { state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, false); state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, false); @@ -2570,12 +2570,6 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, state.scene_shader.set_uniform(SceneShaderGLES2::WORLD_TRANSFORM, e->instance->transform); - if (skeleton) { - state.scene_shader.set_uniform(SceneShaderGLES2::SKELETON_IN_WORLD_COORDS, skeleton->use_world_transform); - state.scene_shader.set_uniform(SceneShaderGLES2::SKELETON_TRANSFORM, skeleton->world_transform); - state.scene_shader.set_uniform(SceneShaderGLES2::SKELETON_TRANSFORM_INVERSE, skeleton->world_transform_inverse); - } - if (use_lightmap_capture) { //this is per instance, must be set always if present glUniform4fv(state.scene_shader.get_uniform_location(SceneShaderGLES2::LIGHTMAP_CAPTURES), 12, (const GLfloat *)e->instance->lightmap_capture_data.ptr()); state.scene_shader.set_uniform(SceneShaderGLES2::LIGHTMAP_CAPTURE_SKY, false); diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index 5c02d8096d..9f511cd787 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -2432,7 +2432,7 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: // from surface->data. // if USE_SKELETON_SOFTWARE is active - if (!config.float_texture_supported) { + if (config.use_skeleton_software) { // if this geometry is used specifically for skinning if (p_format & (VS::ARRAY_FORMAT_BONES | VS::ARRAY_FORMAT_WEIGHTS)) surface->data = array; @@ -3514,7 +3514,7 @@ void RasterizerStorageGLES2::skeleton_allocate(RID p_skeleton, int p_bones, bool skeleton->size = p_bones; skeleton->use_2d = p_2d_skeleton; - if (config.float_texture_supported) { + if (!config.use_skeleton_software) { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, skeleton->tex_id); @@ -3663,23 +3663,6 @@ void RasterizerStorageGLES2::skeleton_set_base_transform_2d(RID p_skeleton, cons skeleton->base_transform_2d = p_base_transform; } -void RasterizerStorageGLES2::skeleton_set_world_transform(RID p_skeleton, bool p_enable, const Transform &p_world_transform) { - - Skeleton *skeleton = skeleton_owner.getornull(p_skeleton); - - ERR_FAIL_COND(skeleton->use_2d); - - skeleton->world_transform = p_world_transform; - skeleton->use_world_transform = p_enable; - if (p_enable) { - skeleton->world_transform_inverse = skeleton->world_transform.affine_inverse(); - } - - if (!skeleton->update_list.in_list()) { - skeleton_update_list.add(&skeleton->update_list); - } -} - void RasterizerStorageGLES2::_update_skeleton_transform_buffer(const PoolVector<float> &p_data, size_t p_size) { glBindBuffer(GL_ARRAY_BUFFER, resources.skeleton_transform_buffer); @@ -3699,7 +3682,7 @@ void RasterizerStorageGLES2::_update_skeleton_transform_buffer(const PoolVector< void RasterizerStorageGLES2::update_dirty_skeletons() { - if (!config.float_texture_supported) + if (config.use_skeleton_software) return; glActiveTexture(GL_TEXTURE0); @@ -5751,9 +5734,14 @@ void RasterizerStorageGLES2::initialize() { frame.current_rt = NULL; frame.clear_request = false; + glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &config.max_vertex_texture_image_units); glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &config.max_texture_image_units); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &config.max_texture_size); + // the use skeleton software path should be used if either float texture is not supported, + // OR max_vertex_texture_image_units is zero + config.use_skeleton_software = (config.float_texture_supported == false) || (config.max_vertex_texture_image_units == 0); + shaders.copy.init(); shaders.cubemap_filter.init(); bool ggx_hq = GLOBAL_GET("rendering/quality/reflections/high_quality_ggx"); diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h index d139697b86..ba9274b576 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -60,7 +60,9 @@ public: bool shrink_textures_x2; bool use_fast_texture_filter; + bool use_skeleton_software; + int max_vertex_texture_image_units; int max_texture_image_units; int max_texture_size; @@ -868,16 +870,12 @@ public: Set<RasterizerScene::InstanceBase *> instances; Transform2D base_transform_2d; - Transform world_transform; - Transform world_transform_inverse; - bool use_world_transform; Skeleton() : use_2d(false), size(0), tex_id(0), - update_list(this), - use_world_transform(false) { + update_list(this) { } }; @@ -895,7 +893,6 @@ public: virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform); virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const; virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform); - virtual void skeleton_set_world_transform(RID p_skeleton, bool p_enable, const Transform &p_world_transform); void _update_skeleton_transform_buffer(const PoolVector<float> &p_data, size_t p_size); diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp index 640d45ae65..1db8a870a2 100644 --- a/drivers/gles2/shader_compiler_gles2.cpp +++ b/drivers/gles2/shader_compiler_gles2.cpp @@ -353,6 +353,11 @@ String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, Gener varying_code += _typestr(E->get().type); varying_code += " "; varying_code += _mkid(E->key()); + if (E->get().array_size > 0) { + varying_code += "["; + varying_code += itos(E->get().array_size); + varying_code += "]"; + } varying_code += ";\n"; String final_code = varying_code.as_string(); @@ -943,6 +948,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() { actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_UV"] = "light_uv"; actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT"] = "light"; actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_COLOR"] = "shadow_color"; + actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_VEC"] = "shadow_vec"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["COLOR"] = "#define COLOR_USED\n"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_TEXTURE"] = "#define SCREEN_TEXTURE_USED\n"; @@ -952,6 +958,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() { actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"] = "#define NORMALMAP_USED\n"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; actions[VS::SHADER_CANVAS_ITEM].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n"; + actions[VS::SHADER_CANVAS_ITEM].usage_defines["SHADOW_VEC"] = "#define SHADOW_VEC_USED\n"; // Ported from GLES3 diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index fa0b315e29..08548ded17 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -331,6 +331,7 @@ void light_compute( inout vec4 light_color, vec2 light_uv, inout vec4 shadow_color, + inout vec2 shadow_vec, vec3 normal, vec2 uv, #if defined(SCREEN_UV_USED) @@ -407,6 +408,7 @@ FRAGMENT_SHADER_CODE #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; @@ -434,6 +436,7 @@ FRAGMENT_SHADER_CODE real_light_color, light_uv, real_light_shadow_color, + shadow_vec, normal, uv, #if defined(SCREEN_UV_USED) @@ -452,11 +455,18 @@ FRAGMENT_SHADER_CODE color *= light; #ifdef USE_SHADOWS - // Reset light_vec to compute shadows, the shadow map is created from the light origin, so it only - // makes sense to compute shadows from there. - light_vec = light_uv_interp.zw; - float angle_to_light = -atan(light_vec.x, light_vec.y); +#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 = (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*/ @@ -467,18 +477,18 @@ FRAGMENT_SHADER_CODE vec2 point; float sh; if (abs_angle < 45.0 * PI / 180.0) { - point = light_vec; + point = shadow_vec; sh = 0.0 + (1.0 / 8.0); } else if (abs_angle > 135.0 * PI / 180.0) { - point = -light_vec; + point = -shadow_vec; sh = 0.5 + (1.0 / 8.0); } else if (angle_to_light > 0.0) { - point = vec2(light_vec.y, -light_vec.x); + point = vec2(shadow_vec.y, -shadow_vec.x); sh = 0.25 + (1.0 / 8.0); } else { - point = vec2(-light_vec.y, light_vec.x); + point = vec2(-shadow_vec.y, shadow_vec.x); sh = 0.75 + (1.0 / 8.0); } diff --git a/drivers/gles2/shaders/copy.glsl b/drivers/gles2/shaders/copy.glsl index 195db7c45f..aa967115da 100644 --- a/drivers/gles2/shaders/copy.glsl +++ b/drivers/gles2/shaders/copy.glsl @@ -144,11 +144,11 @@ void main() { #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. - // Note that we're ignoring the x-offset for IPD, with Z sufficiently in the distance it becomes neglectible, as a result we could probably just set cube_normal.z to -1. + // 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 = -1000000.0; + 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; diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl index 8a9387f0b3..57c2d886b3 100644 --- a/drivers/gles2/shaders/scene.glsl +++ b/drivers/gles2/shaders/scene.glsl @@ -61,10 +61,6 @@ uniform ivec2 skeleton_texture_size; #endif -uniform highp mat4 skeleton_transform; -uniform highp mat4 skeleton_transform_inverse; -uniform bool skeleton_in_world_coords; - #endif #ifdef USE_INSTANCING @@ -410,12 +406,7 @@ void main() { #endif - if (skeleton_in_world_coords) { - bone_transform = skeleton_transform * (bone_transform * skeleton_transform_inverse); - world_matrix = bone_transform * world_matrix; - } else { - world_matrix = world_matrix * bone_transform; - } + world_matrix = world_matrix * bone_transform; #endif diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 1472954ebc..35f414cf09 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -2260,11 +2260,6 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_ _set_cull(e->sort_key & RenderList::SORT_KEY_MIRROR_FLAG, e->sort_key & RenderList::SORT_KEY_CULL_DISABLED_FLAG, p_reverse_cull); - if (skeleton) { - state.scene_shader.set_uniform(SceneShaderGLES3::SKELETON_TRANSFORM, skeleton->world_transform); - state.scene_shader.set_uniform(SceneShaderGLES3::SKELETON_IN_WORLD_COORDS, skeleton->use_world_transform); - } - state.scene_shader.set_uniform(SceneShaderGLES3::WORLD_TRANSFORM, e->instance->transform); _render_geometry(e); @@ -4335,6 +4330,10 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const if (storage->frame.current_rt->buffers.active) { current_fbo = storage->frame.current_rt->buffers.fbo; } else { + if (storage->frame.current_rt->effects.mip_maps[0].sizes.size() == 0) { + ERR_PRINT_ONCE("Can't use canvas background mode in a render target configured without sampling"); + return; + } current_fbo = storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo; } diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 5f4acbc2de..a29831e3f5 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -2955,7 +2955,9 @@ _FORCE_INLINE_ static void _fill_std140_ubo_empty(ShaderLanguage::DataType type, case ShaderLanguage::TYPE_BVEC3: case ShaderLanguage::TYPE_IVEC3: case ShaderLanguage::TYPE_UVEC3: - case ShaderLanguage::TYPE_VEC3: + case ShaderLanguage::TYPE_VEC3: { + zeromem(data, 12); + } break; case ShaderLanguage::TYPE_BVEC4: case ShaderLanguage::TYPE_IVEC4: case ShaderLanguage::TYPE_UVEC4: @@ -5160,20 +5162,6 @@ void RasterizerStorageGLES3::skeleton_set_base_transform_2d(RID p_skeleton, cons skeleton->base_transform_2d = p_base_transform; } -void RasterizerStorageGLES3::skeleton_set_world_transform(RID p_skeleton, bool p_enable, const Transform &p_world_transform) { - - Skeleton *skeleton = skeleton_owner.getornull(p_skeleton); - - ERR_FAIL_COND(skeleton->use_2d); - - skeleton->world_transform = p_world_transform; - skeleton->use_world_transform = p_enable; - - if (!skeleton->update_list.in_list()) { - skeleton_update_list.add(&skeleton->update_list); - } -} - void RasterizerStorageGLES3::update_dirty_skeletons() { glActiveTexture(GL_TEXTURE0); diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index 0a7e47e304..84632308b4 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -892,15 +892,12 @@ public: SelfList<Skeleton> update_list; Set<RasterizerScene::InstanceBase *> instances; //instances using skeleton Transform2D base_transform_2d; - bool use_world_transform; - Transform world_transform; Skeleton() : use_2d(false), size(0), texture(0), - update_list(this), - use_world_transform(false) { + update_list(this) { } }; @@ -918,7 +915,6 @@ public: virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform); virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const; virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform); - virtual void skeleton_set_world_transform(RID p_skeleton, bool p_enable, const Transform &p_world_transform); /* Light API */ diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp index 0121d88f4d..7499962da3 100644 --- a/drivers/gles3/shader_compiler_gles3.cpp +++ b/drivers/gles3/shader_compiler_gles3.cpp @@ -467,6 +467,11 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener vcode += _prestr(E->get().precision); vcode += _typestr(E->get().type); vcode += " " + _mkid(E->key()); + if (E->get().array_size > 0) { + vcode += "["; + vcode += itos(E->get().array_size); + vcode += "]"; + } vcode += ";\n"; r_gen_code.vertex_global += interp_mode + "out " + vcode; r_gen_code.fragment_global += interp_mode + "in " + vcode; @@ -936,6 +941,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() { actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_UV"] = "light_uv"; actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT"] = "light"; actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_COLOR"] = "shadow_color"; + actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_VEC"] = "shadow_vec"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["COLOR"] = "#define COLOR_USED\n"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_TEXTURE"] = "#define SCREEN_TEXTURE_USED\n"; @@ -944,6 +950,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() { actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMAL"] = "#define NORMAL_USED\n"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"] = "#define NORMALMAP_USED\n"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; + actions[VS::SHADER_CANVAS_ITEM].usage_defines["SHADOW_VEC"] = "#define SHADOW_VEC_USED\n"; actions[VS::SHADER_CANVAS_ITEM].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n"; /** SPATIAL SHADER **/ diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index 10c8764b8e..e83f53d648 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -345,6 +345,7 @@ void light_compute( inout vec4 light_color, vec2 light_uv, inout vec4 shadow_color, + inout vec2 shadow_vec, vec3 normal, vec2 uv, #if defined(SCREEN_UV_USED) @@ -512,6 +513,7 @@ FRAGMENT_SHADER_CODE #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; @@ -539,6 +541,7 @@ FRAGMENT_SHADER_CODE real_light_color, light_uv, real_light_shadow_color, + shadow_vec, normal, uv, #if defined(SCREEN_UV_USED) @@ -557,11 +560,16 @@ FRAGMENT_SHADER_CODE color *= light; #ifdef USE_SHADOWS - // Reset light_vec to compute shadows, the shadow map is created from the light origin, so it only - // makes sense to compute shadows from there. - light_vec = light_uv_interp.zw; - - float angle_to_light = -atan(light_vec.x, light_vec.y); +#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*/ @@ -572,18 +580,18 @@ FRAGMENT_SHADER_CODE vec2 point; float sh; if (abs_angle < 45.0 * PI / 180.0) { - point = light_vec; + point = shadow_vec; sh = 0.0 + (1.0 / 8.0); } else if (abs_angle > 135.0 * PI / 180.0) { - point = -light_vec; + point = -shadow_vec; sh = 0.5 + (1.0 / 8.0); } else if (angle_to_light > 0.0) { - point = vec2(light_vec.y, -light_vec.x); + point = vec2(shadow_vec.y, -shadow_vec.x); sh = 0.25 + (1.0 / 8.0); } else { - point = vec2(-light_vec.y, light_vec.x); + point = vec2(-shadow_vec.y, shadow_vec.x); sh = 0.75 + (1.0 / 8.0); } diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index f08d3f4d23..403de25dd0 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -302,8 +302,6 @@ out highp float dp_clip; #ifdef USE_SKELETON uniform highp sampler2D skeleton_texture; // texunit:-1 -uniform highp mat4 skeleton_transform; -uniform bool skeleton_in_world_coords; #endif out highp vec4 position_interp; @@ -432,14 +430,7 @@ void main() { vec4(0.0, 0.0, 0.0, 1.0)) * bone_weights.w; - if (skeleton_in_world_coords) { - highp mat4 bone_matrix = skeleton_transform * (transpose(m) * inverse(skeleton_transform)); - world_matrix = bone_matrix * world_matrix; - - } else { - - world_matrix = world_matrix * transpose(m); - } + world_matrix = world_matrix * transpose(m); } #endif diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 071734eb48..8be1d5d8f3 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -58,7 +58,7 @@ void FileAccessUnix::check_errors() const { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); if (feof(f)) { @@ -76,7 +76,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { path = fix_path(p_path); //printf("opening %ls, %i\n", path.c_str(), Memory::get_static_mem_usage()); - ERR_FAIL_COND_V(f, ERR_ALREADY_IN_USE); + ERR_FAIL_COND_V_MSG(f, ERR_ALREADY_IN_USE, "File is already in use."); const char *mode_string; if (p_mode_flags == READ) @@ -171,7 +171,7 @@ String FileAccessUnix::get_path_absolute() const { void FileAccessUnix::seek(size_t p_position) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); last_error = OK; if (fseek(f, p_position, SEEK_SET)) @@ -180,7 +180,7 @@ void FileAccessUnix::seek(size_t p_position) { void FileAccessUnix::seek_end(int64_t p_position) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); if (fseek(f, p_position, SEEK_END)) check_errors(); @@ -188,7 +188,7 @@ void FileAccessUnix::seek_end(int64_t p_position) { size_t FileAccessUnix::get_position() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); long pos = ftell(f); if (pos < 0) { @@ -200,7 +200,7 @@ size_t FileAccessUnix::get_position() const { size_t FileAccessUnix::get_len() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); long pos = ftell(f); ERR_FAIL_COND_V(pos < 0, 0); @@ -219,7 +219,7 @@ bool FileAccessUnix::eof_reached() const { uint8_t FileAccessUnix::get_8() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); uint8_t b; if (fread(&b, 1, 1, f) == 0) { check_errors(); @@ -230,7 +230,7 @@ uint8_t FileAccessUnix::get_8() const { int FileAccessUnix::get_buffer(uint8_t *p_dst, int p_length) const { - ERR_FAIL_COND_V(!f, -1); + ERR_FAIL_COND_V_MSG(!f, -1, "File must be opened before use."); int read = fread(p_dst, 1, p_length, f); check_errors(); return read; @@ -243,18 +243,19 @@ Error FileAccessUnix::get_error() const { void FileAccessUnix::flush() { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); fflush(f); } void FileAccessUnix::store_8(uint8_t p_dest) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND(fwrite(&p_dest, 1, 1, f) != 1); } void FileAccessUnix::store_buffer(const uint8_t *p_src, int p_length) { - ERR_FAIL_COND(!f); + + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND((int)fwrite(p_src, 1, p_length, f) != p_length); } diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index ab5590dba4..bc57c0b8df 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -298,7 +298,7 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo } FILE *f = popen(argss.utf8().get_data(), "r"); - ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot pipe stream from process running with following arguments '" + argss + "'."); char buf[65535]; |