summaryrefslogtreecommitdiffstats
path: root/drivers/gles2
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gles2')
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.cpp39
-rw-r--r--drivers/gles2/rasterizer_storage_gles2.cpp2
-rw-r--r--drivers/gles2/shaders/scene.glsl75
3 files changed, 78 insertions, 38 deletions
diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp
index feefb74480..c7506c6775 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;
}
}
@@ -2233,17 +2237,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 +2254,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..5f5dfadcc5 100644
--- a/drivers/gles2/rasterizer_storage_gles2.cpp
+++ b/drivers/gles2/rasterizer_storage_gles2.cpp
@@ -3914,7 +3914,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, GL_DEPTH_COMPONENT, rt->width, rt->height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl
index 462aff8828..fc20cb81a2 100644
--- a/drivers/gles2/shaders/scene.glsl
+++ b/drivers/gles2/shaders/scene.glsl
@@ -165,7 +165,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;
@@ -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_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) {
- spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
+ 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
@@ -814,7 +832,7 @@ uniform vec3 light_direction;
// omni
uniform vec3 light_position;
-uniform vec4 light_attenuation;
+uniform float light_attenuation;
// spot
uniform float light_spot_attenuation;
@@ -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;
@@ -1474,10 +1493,14 @@ 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
@@ -1643,17 +1666,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;
-
- float spot_cutoff = light_spot_angle;
+ if (normalized_distance < 1.0) {
+ 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;
+ float angle = dot(-normalize(light_rel_vec), spot_dir);
- spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
+ 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);
+ light_att = vec3(spot_attenuation);
+ } else {
+ light_att = vec3(0.0);
+ }
+ } else {
+ light_att = vec3(0.0);
+ }
L = normalize(light_rel_vec);