summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles2/rasterizer_gles2.cpp2
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.cpp40
-rw-r--r--drivers/gles2/rasterizer_storage_gles2.cpp14
-rw-r--r--drivers/gles2/shaders/cubemap_filter.glsl13
-rw-r--r--drivers/gles2/shaders/scene.glsl349
-rw-r--r--drivers/gles2/shaders/stdlib.glsl11
-rw-r--r--drivers/gles3/rasterizer_gles3.cpp2
-rw-r--r--drivers/png/SCsub2
-rw-r--r--drivers/register_driver_types.cpp6
-rw-r--r--drivers/unix/os_unix.cpp2
10 files changed, 312 insertions, 129 deletions
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp
index bd03bd71f6..1dd594cc20 100644
--- a/drivers/gles2/rasterizer_gles2.cpp
+++ b/drivers/gles2/rasterizer_gles2.cpp
@@ -32,7 +32,7 @@
#include "core/os/os.h"
#include "core/project_settings.h"
-#include "gl_context/context_gl.h"
+#include "drivers/gl_context/context_gl.h"
#define _EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242
#define _EXT_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243
diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp
index feefb74480..22cc45a0f6 100644
--- a/drivers/gles2/rasterizer_scene_gles2.cpp
+++ b/drivers/gles2/rasterizer_scene_gles2.cpp
@@ -1804,8 +1804,7 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado
float range = light_ptr->param[VS::LIGHT_PARAM_RANGE];
state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_RANGE, range);
- Color attenuation = Color(0.0, 0.0, 0.0, 0.0);
- attenuation.a = light_ptr->param[VS::LIGHT_PARAM_ATTENUATION];
+ float attenuation = light_ptr->param[VS::LIGHT_PARAM_ATTENUATION];
state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_ATTENUATION, attenuation);
if (!state.render_no_shadows && light_ptr->shadow && shadow_atlas && shadow_atlas->shadow_owners.has(light->self)) {
@@ -1858,8 +1857,7 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado
Vector3 direction = p_view_transform.inverse().basis.xform(light->transform.basis.xform(Vector3(0, 0, -1))).normalized();
state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_DIRECTION, direction);
- Color attenuation = Color(0.0, 0.0, 0.0, 0.0);
- attenuation.a = light_ptr->param[VS::LIGHT_PARAM_ATTENUATION];
+ float attenuation = light_ptr->param[VS::LIGHT_PARAM_ATTENUATION];
float range = light_ptr->param[VS::LIGHT_PARAM_RANGE];
float spot_attenuation = light_ptr->param[VS::LIGHT_PARAM_SPOT_ATTENUATION];
float angle = light_ptr->param[VS::LIGHT_PARAM_SPOT_ANGLE];
@@ -2024,6 +2022,9 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
ReflectionProbeInstance *refprobe_2 = NULL;
RasterizerStorageGLES2::Texture *lightmap = NULL;
bool use_lightmap_capture = false;
+ bool rebind_light = false;
+ bool rebind_reflection = false;
+ bool rebind_lightmap = false;
if (!p_shadow) {
@@ -2059,6 +2060,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
_setup_light_type(light, shadow_atlas);
rebind = true;
+ rebind_light = true;
}
int blend_mode = p_alpha_pass ? material->shader->spatial.blend_mode : -1; // -1 no blend, no mix
@@ -2142,6 +2144,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
glBindTexture(GL_TEXTURE_CUBE_MAP, refprobe_2->cubemap);
}
rebind = true;
+ rebind_reflection = true;
}
use_lightmap_capture = !unshaded && !accum_pass && !e->instance->lightmap_capture_data.empty();
@@ -2171,6 +2174,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
glBindTexture(GL_TEXTURE_2D, lightmap->tex_id);
}
rebind = true;
+ rebind_lightmap = true;
}
}
@@ -2223,6 +2227,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
if (p_env) {
state.scene_shader.set_uniform(SceneShaderGLES2::BG_ENERGY, p_env->bg_energy);
state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_SKY_CONTRIBUTION, p_env->ambient_sky_contribution);
+
state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_COLOR, p_env->ambient_color);
state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_ENERGY, p_env->ambient_energy);
@@ -2233,17 +2238,10 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_ENERGY, 1.0);
}
- if (light) {
- _setup_light(light, shadow_atlas, p_view_transform);
- }
-
- if (refprobe_1 || refprobe_2) {
- _setup_refprobes(refprobe_1, refprobe_2, p_view_transform, p_env);
- }
-
- if (lightmap) {
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHTMAP_ENERGY, lightmap_energy);
- }
+ //rebind all these
+ rebind_light = true;
+ rebind_reflection = true;
+ rebind_lightmap = true;
}
state.scene_shader.set_uniform(SceneShaderGLES2::CAMERA_MATRIX, view_transform_inverse);
@@ -2257,6 +2255,18 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
state.scene_shader.set_uniform(SceneShaderGLES2::NORMAL_MULT, 1.0); // TODO mirror?
}
+ if (rebind_light && light) {
+ _setup_light(light, shadow_atlas, p_view_transform);
+ }
+
+ if (rebind_reflection && (refprobe_1 || refprobe_2)) {
+ _setup_refprobes(refprobe_1, refprobe_2, p_view_transform, p_env);
+ }
+
+ if (rebind_lightmap && lightmap) {
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHTMAP_ENERGY, lightmap_energy);
+ }
+
state.scene_shader.set_uniform(SceneShaderGLES2::WORLD_TRANSFORM, e->instance->transform);
if (use_lightmap_capture) { //this is per instance, must be set always if present
diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp
index 0863e03b76..6314a69a90 100644
--- a/drivers/gles2/rasterizer_storage_gles2.cpp
+++ b/drivers/gles2/rasterizer_storage_gles2.cpp
@@ -54,6 +54,8 @@ GLuint RasterizerStorageGLES2::system_fbo = 0;
#define _EXT_TEXTURE_CUBE_MAP_SEAMLESS 0x884F
+#define _DEPTH_COMPONENT24_OES 0x81A6
+
void RasterizerStorageGLES2::bind_quad_array() const {
glBindBuffer(GL_ARRAY_BUFFER, resources.quadie);
glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0);
@@ -948,6 +950,7 @@ void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_ra
shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES2::FACE_ID, i);
float roughness = mm_level ? lod / (float)(mipmaps - 1) : 1;
+ roughness = MIN(1.0, roughness); //keep max at 1
shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES2::ROUGHNESS, roughness);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
@@ -3914,7 +3917,7 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) {
glGenRenderbuffers(1, &rt->depth);
glBindRenderbuffer(GL_RENDERBUFFER, rt->depth);
- glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, rt->width, rt->height);
+ glRenderbufferStorage(GL_RENDERBUFFER, _DEPTH_COMPONENT24_OES, rt->width, rt->height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
@@ -4492,13 +4495,13 @@ void RasterizerStorageGLES2::initialize() {
// radical inverse vdc cache texture
// used for cubemap filtering
- if (config.float_texture_supported) {
+ if (true /*||config.float_texture_supported*/) { //uint8 is similar and works everywhere
glGenTextures(1, &resources.radical_inverse_vdc_cache_tex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, resources.radical_inverse_vdc_cache_tex);
- float radical_inverse[512];
+ uint8_t radical_inverse[512];
for (uint32_t i = 0; i < 512; i++) {
uint32_t bits = i;
@@ -4510,11 +4513,10 @@ void RasterizerStorageGLES2::initialize() {
bits = ((bits & 0x00FF00FF) << 8) | ((bits & 0xFF00FF00) >> 8);
float value = float(bits) * 2.3283064365386963e-10;
-
- radical_inverse[i] = value;
+ radical_inverse[i] = uint8_t(CLAMP(value * 255.0, 0, 255));
}
- glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 512, 1, 0, GL_LUMINANCE, GL_FLOAT, radical_inverse);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 512, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, radical_inverse);
glBindTexture(GL_TEXTURE_2D, 0);
}
diff --git a/drivers/gles2/shaders/cubemap_filter.glsl b/drivers/gles2/shaders/cubemap_filter.glsl
index 67b937984e..b1553c7cd5 100644
--- a/drivers/gles2/shaders/cubemap_filter.glsl
+++ b/drivers/gles2/shaders/cubemap_filter.glsl
@@ -167,17 +167,21 @@ void main() {
vec3 H = ImportanceSampleGGX(xi, roughness, N);
vec3 V = N;
- vec3 L = normalize(2.0 * dot(V, H) * H - V);
+ vec3 L = (2.0 * dot(V, H) * H - V);
float NdotL = clamp(dot(N, L), 0.0, 1.0);
if (NdotL > 0.0) {
#ifdef USE_SOURCE_PANORAMA
- sum.rgb += texturePanorama(source_panorama, L).rgb * NdotL;
+ vec3 val = texturePanorama(source_panorama, L).rgb;
#else
- sum.rgb += textureCubeLod(source_cube, L, 0.0).rgb * NdotL;
+ vec3 val = textureCubeLod(source_cube, L, 0.0).rgb;
#endif
+ //mix using Linear, to approximate high end back-end
+ val = mix(pow((val + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), val * (1.0 / 12.92), vec3(lessThan(val, vec3(0.04045))));
+
+ sum.rgb += val * NdotL;
sum.a += NdotL;
}
@@ -185,5 +189,8 @@ void main() {
sum /= sum.a;
+ vec3 a = vec3(0.055);
+ sum.rgb = mix((vec3(1.0) + a) * pow(sum.rgb, vec3(1.0 / 2.4)) - a, 12.92 * sum.rgb, vec3(lessThan(sum.rgb, vec3(0.0031308))));
+
gl_FragColor = vec4(sum.rgb, 1.0);
}
diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl
index 462aff8828..2b0b095ac9 100644
--- a/drivers/gles2/shaders/scene.glsl
+++ b/drivers/gles2/shaders/scene.glsl
@@ -15,6 +15,7 @@ precision highp int;
#define M_PI 3.14159265359
+
//
// attributes
//
@@ -165,7 +166,7 @@ uniform vec3 light_direction;
uniform vec3 light_position;
uniform float light_range;
-uniform vec4 light_attenuation;
+uniform float light_attenuation;
// spot
uniform float light_spot_attenuation;
@@ -285,7 +286,6 @@ varying mediump vec3 refprobe2_ambient_normal;
#endif //vertex lighting for refprobes
-
void main() {
highp vec4 vertex = vertex_attrib;
@@ -463,10 +463,15 @@ VERTEX_SHADER_CODE
float normalized_distance = light_length / light_range;
- float omni_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
+ if (normalized_distance < 1.0) {
- vec3 attenuation = vec3(omni_attenuation);
- light_att = vec3(omni_attenuation);
+ float omni_attenuation = pow(1.0 - normalized_distance, light_attenuation);
+
+ vec3 attenuation = vec3(omni_attenuation);
+ light_att = vec3(omni_attenuation);
+ } else {
+ light_att = vec3(0.0);
+ }
L = normalize(light_vec);
@@ -478,17 +483,30 @@ VERTEX_SHADER_CODE
float light_length = length(light_rel_vec);
float normalized_distance = light_length / light_range;
- float spot_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
- vec3 spot_dir = light_direction;
+ if (normalized_distance < 1.0) {
- float spot_cutoff = light_spot_angle;
+ float spot_attenuation = pow(1.0 - normalized_distance, light_attenuation);
+ vec3 spot_dir = light_direction;
- float scos = max(dot(-normalize(light_rel_vec), spot_dir), spot_cutoff);
- float spot_rim = max(0.0001, (1.0 - scos) / (1.0 - spot_cutoff));
+ float spot_cutoff = light_spot_angle;
- spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
+ float angle = dot(-normalize(light_rel_vec), spot_dir);
+
+ if (angle > spot_cutoff) {
+
+ float scos = max(angle, spot_cutoff);
+ float spot_rim = max(0.0001, (1.0 - scos) / (1.0 - spot_cutoff));
+
+ spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
+
+ light_att = vec3(spot_attenuation);
+ } else {
+ light_att = vec3(0.0);
+ }
+ } else {
+ light_att = vec3(0.0);
+ }
- light_att = vec3(spot_attenuation);
L = normalize(light_rel_vec);
#endif
@@ -528,7 +546,7 @@ VERTEX_SHADER_CODE
#ifdef USE_REFLECTION_PROBE1
{
vec3 ref_normal = normalize(reflect(vertex_interp, normal_interp));
- vec3 local_pos = (refprobe1_local_matrix * vec4(vertex_interp, 1.0)).xyz;
+ vec3 local_pos = (refprobe1_local_matrix * vec4(vertex_interp, 1.0)).xyz;
vec3 inner_pos = abs(local_pos / refprobe1_box_extents);
float blend = max(inner_pos.x, max(inner_pos.y, inner_pos.z));
@@ -536,7 +554,6 @@ VERTEX_SHADER_CODE
vec3 local_ref_vec = (refprobe1_local_matrix * vec4(ref_normal, 0.0)).xyz;
refprobe1_reflection_normal_blend.xyz = local_ref_vec;
refprobe1_reflection_normal_blend.a = blend;
-
}
#ifndef USE_LIGHTMAP
@@ -546,7 +563,6 @@ VERTEX_SHADER_CODE
#endif //USE_REFLECTION_PROBE1
-
#ifdef USE_REFLECTION_PROBE2
{
vec3 ref_normal = normalize(reflect(vertex_interp, normal_interp));
@@ -558,7 +574,6 @@ VERTEX_SHADER_CODE
vec3 local_ref_vec = (refprobe2_local_matrix * vec4(ref_normal, 0.0)).xyz;
refprobe2_reflection_normal_blend.xyz = local_ref_vec;
refprobe2_reflection_normal_blend.a = blend;
-
}
#ifndef USE_LIGHTMAP
@@ -679,18 +694,18 @@ uniform vec4 refprobe2_ambient;
void reflection_process(samplerCube reflection_map,
#ifdef USE_VERTEX_LIGHTING
- vec3 ref_normal,
+ vec3 ref_normal,
#ifndef USE_LIGHTMAP
- vec3 amb_normal,
+ vec3 amb_normal,
#endif
- float ref_blend,
+ float ref_blend,
#else //no vertex lighting
- vec3 normal, vec3 vertex,
- mat4 local_matrix,
- bool use_box_project, vec3 box_extents, vec3 box_offset,
+ vec3 normal, vec3 vertex,
+ mat4 local_matrix,
+ bool use_box_project, vec3 box_extents, vec3 box_offset,
#endif //vertex lighting
- bool exterior,float intensity, vec4 ref_ambient, float roughness, vec3 ambient, vec3 skybox, inout highp vec4 reflection_accum, inout highp vec4 ambient_accum) {
+ bool exterior, float intensity, vec4 ref_ambient, float roughness, vec3 ambient, vec3 skybox, inout highp vec4 reflection_accum, inout highp vec4 ambient_accum) {
vec4 reflection;
@@ -745,7 +760,6 @@ void reflection_process(samplerCube reflection_map,
reflection_accum += reflection;
-
#ifndef USE_LIGHTMAP
vec4 ambient_out;
@@ -782,7 +796,6 @@ uniform bool lightmap_capture_sky;
#ifdef USE_RADIANCE_MAP
-
uniform samplerCube radiance_map; // texunit:-2
uniform mat4 radiance_inverse_xform;
@@ -814,7 +827,7 @@ uniform vec3 light_direction;
// omni
uniform vec3 light_position;
-uniform vec4 light_attenuation;
+uniform float light_attenuation;
// spot
uniform float light_spot_attenuation;
@@ -891,8 +904,6 @@ 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
@@ -1204,14 +1215,17 @@ LIGHT_SHADER_CODE
#ifdef USE_SHADOW
#define SAMPLE_SHADOW_TEXEL(p_shadow, p_pos, p_depth) step(p_depth, texture2D(p_shadow, p_pos).r)
+#define SAMPLE_SHADOW_TEXEL_PROJ(p_shadow, p_pos) step(p_pos.z, texture2DProj(p_shadow, p_pos).r)
float sample_shadow(
- highp sampler2D shadow,
- highp vec2 pos,
- highp float depth) {
+ highp sampler2D shadow,highp vec4 spos) {
#ifdef SHADOW_MODE_PCF_13
+ spos.xyz/=spos.w;
+ vec2 pos = spos.xy;
+ float depth = spos.z;
+
float avg = SAMPLE_SHADOW_TEXEL(shadow, pos, depth);
avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(shadow_pixel_size.x, 0.0), depth);
avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(-shadow_pixel_size.x, 0.0), depth);
@@ -1230,6 +1244,10 @@ float sample_shadow(
#ifdef SHADOW_MODE_PCF_5
+ spos.xyz/=spos.w;
+ vec2 pos = spos.xy;
+ float depth = spos.z;
+
float avg = SAMPLE_SHADOW_TEXEL(shadow, pos, depth);
avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(shadow_pixel_size.x, 0.0), depth);
avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(-shadow_pixel_size.x, 0.0), depth);
@@ -1241,7 +1259,7 @@ float sample_shadow(
#if !defined(SHADOW_MODE_PCF_5) || !defined(SHADOW_MODE_PCF_13)
- return SAMPLE_SHADOW_TEXEL(shadow, pos, depth);
+ return SAMPLE_SHADOW_TEXEL_PROJ(shadow, spos);
#endif
}
@@ -1267,6 +1285,7 @@ void main() {
float clearcoat_gloss = 0.0;
float anisotropy = 0.0;
vec2 anisotropy_flow = vec2(1.0, 0.0);
+ float sss_strength = 0.0; //unused
float alpha = 1.0;
float side = 1.0;
@@ -1310,8 +1329,8 @@ FRAGMENT_SHADER_CODE
normalmap.xy = normalmap.xy * 2.0 - 1.0;
normalmap.z = sqrt(max(0.0, 1.0 - dot(normalmap.xy, normalmap.xy)));
- // normal = normalize(mix(normal_interp, tangent * normalmap.x + binormal * normalmap.y + normal * normalmap.z, normaldepth)) * side;
- normal = normalmap;
+ normal = normalize(mix(normal_interp, tangent * normalmap.x + binormal * normalmap.y + normal * normalmap.z, normaldepth)) * side;
+ //normal = normalmap;
#endif
normal = normalize(normal);
@@ -1356,11 +1375,8 @@ FRAGMENT_SHADER_CODE
ambient_light *= ambient_energy;
-
#if defined(USE_REFLECTION_PROBE1) || defined(USE_REFLECTION_PROBE2)
-
-
vec4 ambient_accum = vec4(0.0);
vec4 reflection_accum = vec4(0.0);
@@ -1368,19 +1384,17 @@ FRAGMENT_SHADER_CODE
reflection_process(reflection_probe1,
#ifdef USE_VERTEX_LIGHTING
- refprobe1_reflection_normal_blend.rgb,
-#ifndef USE_LIGHTMAP
- refprobe1_ambient_normal,
-#endif
- refprobe1_reflection_normal_blend.a,
+ refprobe1_reflection_normal_blend.rgb,
+#ifndef USE_LIGHTMAP
+ refprobe1_ambient_normal,
+#endif
+ refprobe1_reflection_normal_blend.a,
#else
- normal_interp,vertex_interp,refprobe1_local_matrix,
- refprobe1_use_box_project,refprobe1_box_extents,refprobe1_box_offset,
+ normal_interp, vertex_interp, refprobe1_local_matrix,
+ refprobe1_use_box_project, refprobe1_box_extents, refprobe1_box_offset,
#endif
- refprobe1_exterior,refprobe1_intensity, refprobe1_ambient, roughness,
- ambient_light, specular_light, reflection_accum, ambient_accum);
-
-
+ refprobe1_exterior, refprobe1_intensity, refprobe1_ambient, roughness,
+ ambient_light, specular_light, reflection_accum, ambient_accum);
#endif // USE_REFLECTION_PROBE1
@@ -1388,17 +1402,17 @@ FRAGMENT_SHADER_CODE
reflection_process(reflection_probe2,
#ifdef USE_VERTEX_LIGHTING
- refprobe2_reflection_normal_blend.rgb,
+ refprobe2_reflection_normal_blend.rgb,
#ifndef USE_LIGHTMAP
- refprobe2_ambient_normal,
+ refprobe2_ambient_normal,
#endif
- refprobe2_reflection_normal_blend.a,
+ refprobe2_reflection_normal_blend.a,
#else
- normal_interp,vertex_interp,refprobe2_local_matrix,
- refprobe2_use_box_project,refprobe2_box_extents,refprobe2_box_offset,
+ normal_interp, vertex_interp, refprobe2_local_matrix,
+ refprobe2_use_box_project, refprobe2_box_extents, refprobe2_box_offset,
#endif
- refprobe2_exterior,refprobe2_intensity, refprobe2_ambient, roughness,
- ambient_light, specular_light, reflection_accum, ambient_accum);
+ refprobe2_exterior, refprobe2_intensity, refprobe2_ambient, roughness,
+ ambient_light, specular_light, reflection_accum, ambient_accum);
#endif // USE_REFLECTION_PROBE2
@@ -1454,7 +1468,6 @@ FRAGMENT_SHADER_CODE
}
#endif
-
#endif //BASE PASS
//
@@ -1474,20 +1487,24 @@ FRAGMENT_SHADER_CODE
float light_length = length(light_vec);
float normalized_distance = light_length / light_range;
+ if (normalized_distance < 1.0) {
- float omni_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
+ float omni_attenuation = pow(1.0 - normalized_distance, light_attenuation);
- light_att = vec3(omni_attenuation);
+ light_att = vec3(omni_attenuation);
+ } else {
+ light_att = vec3(0.0);
+ }
L = normalize(light_vec);
#endif
#ifdef USE_SHADOW
{
- highp vec3 splane = shadow_coord.xyz;
- float shadow_len = length(splane);
+ highp vec4 splane = shadow_coord;
+ float shadow_len = length(splane.xyz);
- splane = normalize(splane);
+ splane = normalize(splane.xyz);
vec4 clamp_rect = light_clamp;
@@ -1504,8 +1521,9 @@ FRAGMENT_SHADER_CODE
splane.z = shadow_len / light_range;
splane.xy = clamp_rect.xy + splane.xy * clamp_rect.zw;
+ splane.w = 1.0;
- float shadow = sample_shadow(light_shadow_atlas, splane.xy, splane.z);
+ float shadow = sample_shadow(light_shadow_atlas, splane);
light_att *= shadow;
}
@@ -1522,6 +1540,126 @@ FRAGMENT_SHADER_CODE
float depth_z = -vertex.z;
#ifdef USE_SHADOW
+
+
+#ifdef USE_VERTEX_LIGHTING
+//compute shadows in a mobile friendly way
+
+#ifdef LIGHT_USE_PSSM4
+ //take advantage of prefetch
+ float shadow1 = sample_shadow(light_directional_shadow, shadow_coord);
+ float shadow2 = sample_shadow(light_directional_shadow, shadow_coord2);
+ float shadow3 = sample_shadow(light_directional_shadow, shadow_coord3);
+ float shadow4 = sample_shadow(light_directional_shadow, shadow_coord4);
+
+
+ if (depth_z < light_split_offsets.w) {
+ float pssm_fade = 0.0;
+ float shadow_att = 1.0;
+#ifdef LIGHT_USE_PSSM_BLEND
+ float shadow_att2 = 1.0;
+ float pssm_blend = 0.0;
+ bool use_blend = true;
+#endif
+ if (depth_z < light_split_offsets.y) {
+ if (depth_z < light_split_offsets.x) {
+ shadow_att = shadow1;
+
+#ifdef LIGHT_USE_PSSM_BLEND
+ shadow_att2 = shadow2;
+
+ pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z);
+#endif
+ } else {
+ shadow_att = shadow2;
+
+#ifdef LIGHT_USE_PSSM_BLEND
+ shadow_att2 = shadow3;
+
+ pssm_blend = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z);
+#endif
+ }
+ } else {
+ if (depth_z < light_split_offsets.z) {
+
+ shadow_att = shadow3;
+
+#if defined(LIGHT_USE_PSSM_BLEND)
+ shadow_att2 = shadow4;
+ pssm_blend = smoothstep(light_split_offsets.y, light_split_offsets.z, depth_z);
+#endif
+
+ } else {
+
+ shadow_att = shadow4;
+ pssm_fade = smoothstep(light_split_offsets.z, light_split_offsets.w, depth_z);
+
+#if defined(LIGHT_USE_PSSM_BLEND)
+ use_blend = false;
+#endif
+ }
+ }
+#if defined(LIGHT_USE_PSSM_BLEND)
+ if (use_blend) {
+ shadow_att = mix(shadow_att, shadow_att2, pssm_blend);
+ }
+#endif
+ light_att *= shadow_att;
+
+ }
+
+#endif //LIGHT_USE_PSSM4
+
+#ifdef LIGHT_USE_PSSM2
+
+ //take advantage of prefetch
+ float shadow1 = sample_shadow(light_directional_shadow, shadow_coord);
+ float shadow2 = sample_shadow(light_directional_shadow, shadow_coord2);
+
+
+
+ if (depth_z < light_split_offsets.y) {
+ float shadow_att = 1.0;
+ float pssm_fade = 0.0;
+
+#ifdef LIGHT_USE_PSSM_BLEND
+ float shadow_att2 = 1.0;
+ float pssm_blend = 0.0;
+ bool use_blend = true;
+#endif
+ if (depth_z < light_split_offsets.x) {
+ float pssm_fade = 0.0;
+ shadow_att = shadow1;
+
+#ifdef LIGHT_USE_PSSM_BLEND
+ shadow_att2 = shadow2;
+ pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z);
+#endif
+ } else {
+
+ shadow_att = shadow2;
+ pssm_fade = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z);
+#ifdef LIGHT_USE_PSSM_BLEND
+ use_blend = false;
+#endif
+ }
+#ifdef LIGHT_USE_PSSM_BLEND
+ if (use_blend) {
+ shadow_att = mix(shadow_att, shadow_att2, pssm_blend);
+ }
+#endif
+ light_att *= shadow_att;
+ }
+
+#endif //LIGHT_USE_PSSM2
+
+#if !defined(LIGHT_USE_PSSM4) && !defined(LIGHT_USE_PSSM2)
+
+ light_att *= sample_shadow(light_directional_shadow, shadow_coord);
+#endif //orthogonal
+
+#else //fragment version of pssm
+
{
#ifdef LIGHT_USE_PSSM4
if (depth_z < light_split_offsets.w) {
@@ -1531,34 +1669,32 @@ FRAGMENT_SHADER_CODE
if (depth_z < light_split_offsets.x) {
#endif //pssm2
- vec3 pssm_coord;
+ highp vec4 pssm_coord;
float pssm_fade = 0.0;
#ifdef LIGHT_USE_PSSM_BLEND
float pssm_blend;
- vec3 pssm_coord2;
+ highp vec4 pssm_coord2;
bool use_blend = true;
#endif
#ifdef LIGHT_USE_PSSM4
+
+
if (depth_z < light_split_offsets.y) {
- if (depth_z < light_split_offsets.x) {
- highp vec4 splane = shadow_coord;
- pssm_coord = splane.xyz / splane.w;
+ if (depth_z < light_split_offsets.x) {
+ pssm_coord = shadow_coord;
-#ifdef LIGHT_USE_PSSM_BLEND
- splane = shadow_coord2;
- pssm_coord2 = splane.xyz / splane.w;
+#ifdef LIGHT_USE_PSSM_BLEND
+ pssm_coord2 = shadow_coord2;
pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z);
#endif
} else {
- highp vec4 splane = shadow_coord2;
- pssm_coord = splane.xyz / splane.w;
+ pssm_coord = shadow_coord2;
#ifdef LIGHT_USE_PSSM_BLEND
- splane = shadow_coord3;
- pssm_coord2 = splane.xyz / splane.w;
+ pssm_coord2 = shadow_coord3;
pssm_blend = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z);
#endif
@@ -1566,19 +1702,16 @@ FRAGMENT_SHADER_CODE
} else {
if (depth_z < light_split_offsets.z) {
- highp vec4 splane = shadow_coord3;
- pssm_coord = splane.xyz / splane.w;
+ pssm_coord = shadow_coord3;
#if defined(LIGHT_USE_PSSM_BLEND)
- splane = shadow_coord4;
- pssm_coord2 = splane.xyz / splane.w;
+ pssm_coord2 = shadow_coord4;
pssm_blend = smoothstep(light_split_offsets.y, light_split_offsets.z, depth_z);
#endif
} else {
- highp vec4 splane = shadow_coord4;
- pssm_coord = splane.xyz / splane.w;
+ pssm_coord = shadow_coord4;
pssm_fade = smoothstep(light_split_offsets.z, light_split_offsets.w, depth_z);
#if defined(LIGHT_USE_PSSM_BLEND)
@@ -1592,17 +1725,15 @@ FRAGMENT_SHADER_CODE
#ifdef LIGHT_USE_PSSM2
if (depth_z < light_split_offsets.x) {
- highp vec4 splane = shadow_coord;
- pssm_coord = splane.xyz / splane.w;
+ pssm_coord = shadow_coord;
#ifdef LIGHT_USE_PSSM_BLEND
- splane = shadow_coord2;
- pssm_coord2 = splane.xyz / splane.w;
+ pssm_coord2 = shadow_coord2;
pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z);
#endif
} else {
- highp vec4 splane = shadow_coord2;
- pssm_coord = splane.xyz / splane.w;
+
+ pssm_coord = shadow_coord2;
pssm_fade = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z);
#ifdef LIGHT_USE_PSSM_BLEND
use_blend = false;
@@ -1613,22 +1744,23 @@ FRAGMENT_SHADER_CODE
#if !defined(LIGHT_USE_PSSM4) && !defined(LIGHT_USE_PSSM2)
{
- highp vec4 splane = shadow_coord;
- pssm_coord = splane.xyz / splane.w;
+ pssm_coord = shadow_coord;
}
#endif
- float shadow = sample_shadow(light_directional_shadow, pssm_coord.xy, pssm_coord.z);
+ float shadow = sample_shadow(light_directional_shadow, pssm_coord);
#ifdef LIGHT_USE_PSSM_BLEND
if (use_blend) {
- shadow = mix(shadow, sample_shadow(light_directional_shadow, pssm_coord2.xy, pssm_coord2.z), pssm_blend);
+ shadow = mix(shadow, sample_shadow(light_directional_shadow, pssm_coord2), pssm_blend);
}
#endif
light_att *= shadow;
}
}
+#endif //use vertex lighting
+
#endif //use shadow
#endif
@@ -1643,17 +1775,25 @@ FRAGMENT_SHADER_CODE
float light_length = length(light_rel_vec);
float normalized_distance = light_length / light_range;
- float spot_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
- vec3 spot_dir = light_direction;
+ if (normalized_distance < 1.0) {
+ float spot_attenuation = pow(1.0 - normalized_distance, light_attenuation);
+ vec3 spot_dir = light_direction;
- float spot_cutoff = light_spot_angle;
+ float spot_cutoff = light_spot_angle;
+ float angle = dot(-normalize(light_rel_vec), spot_dir);
- float scos = max(dot(-normalize(light_rel_vec), spot_dir), spot_cutoff);
- float spot_rim = max(0.0001, (1.0 - scos) / (1.0 - spot_cutoff));
+ if (angle > spot_cutoff) {
+ float scos = max(angle, spot_cutoff);
+ float spot_rim = max(0.0001, (1.0 - scos) / (1.0 - spot_cutoff));
+ spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
- spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
-
- light_att = vec3(spot_attenuation);
+ light_att = vec3(spot_attenuation);
+ } else {
+ light_att = vec3(0.0);
+ }
+ } else {
+ light_att = vec3(0.0);
+ }
L = normalize(light_rel_vec);
@@ -1726,8 +1866,13 @@ FRAGMENT_SHADER_CODE
// environment BRDF approximation
- // TODO shadeless
{
+
+#if defined(DIFFUSE_TOON)
+ //simplify for toon, as
+ specular_light *= specular * metallic * albedo * 2.0;
+#else
+ //TODO: this curve is not really designed for gammaspace, should be adjusted
const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);
const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);
vec4 r = roughness * c0 + c1;
@@ -1737,9 +1882,15 @@ FRAGMENT_SHADER_CODE
vec3 specular_color = metallic_to_specular_color(metallic, specular, albedo);
specular_light *= AB.x * specular_color + AB.y;
+#endif
}
gl_FragColor = vec4(ambient_light + diffuse_light + specular_light, alpha);
+
+ //add emission if in base pass
+#ifdef BASE_PASS
+ gl_FragColor.rgb += emission;
+#endif
// gl_FragColor = vec4(normal, 1.0);
#endif //unshaded
diff --git a/drivers/gles2/shaders/stdlib.glsl b/drivers/gles2/shaders/stdlib.glsl
index 6bc81a22d8..8662dcfe53 100644
--- a/drivers/gles2/shaders/stdlib.glsl
+++ b/drivers/gles2/shaders/stdlib.glsl
@@ -35,3 +35,14 @@ highp vec4 texel2DFetch(highp sampler2D tex, ivec2 size, ivec2 coord) {
return texture2DLod(tex, vec2(x_coord, y_coord), 0.0);
}
+
+#ifndef USE_GLES_OVER_GL
+highp mat4 transpose(highp mat4 src) {
+ return mat4(
+ vec4( src[0].x, src[1].x, src[2].x, src[3].x ),
+ vec4( src[0].y, src[1].y, src[2].y, src[3].y ),
+ vec4( src[0].z, src[1].z, src[2].z, src[3].z ),
+ vec4( src[0].w, src[1].w, src[2].w, src[3].w )
+ );
+}
+#endif
diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp
index d3f6dcd497..6f13df621f 100644
--- a/drivers/gles3/rasterizer_gles3.cpp
+++ b/drivers/gles3/rasterizer_gles3.cpp
@@ -32,7 +32,7 @@
#include "core/os/os.h"
#include "core/project_settings.h"
-#include "gl_context/context_gl.h"
+#include "drivers/gl_context/context_gl.h"
RasterizerStorage *RasterizerGLES3::get_storage() {
diff --git a/drivers/png/SCsub b/drivers/png/SCsub
index 986c36c67c..22fb1817d1 100644
--- a/drivers/png/SCsub
+++ b/drivers/png/SCsub
@@ -27,6 +27,8 @@ if env['builtin_libpng']:
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
env_png.Append(CPPPATH=[thirdparty_dir])
+ # Needed for drivers includes and in platform/javascript
+ env.Append(CPPPATH=[thirdparty_dir])
# Currently .ASM filter_neon.S does not compile on NT.
import os
diff --git a/drivers/register_driver_types.cpp b/drivers/register_driver_types.cpp
index c6d36a5749..9f5d9c1abf 100644
--- a/drivers/register_driver_types.cpp
+++ b/drivers/register_driver_types.cpp
@@ -31,11 +31,11 @@
#include "register_driver_types.h"
#include "core/math/geometry.h"
-#include "png/image_loader_png.h"
-#include "png/resource_saver_png.h"
+#include "drivers/png/image_loader_png.h"
+#include "drivers/png/resource_saver_png.h"
#ifdef TOOLS_ENABLED
-#include "convex_decomp/b2d_decompose.h"
+#include "drivers/convex_decomp/b2d_decompose.h"
#endif
#ifdef TOOLS_ENABLED
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index 7d3e6b412c..6c70934bc6 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -74,7 +74,7 @@ static void _setup_clock() {
kern_return_t ret = mach_timebase_info(&info);
ERR_EXPLAIN("OS CLOCK IS NOT WORKING!");
ERR_FAIL_COND(ret != 0);
- _clock_scale = (double)info.numer / (double)info.denom;
+ _clock_scale = ((double)info.numer / (double)info.denom) / 1000.0;
_clock_start = mach_absolute_time() * _clock_scale;
}
#else