Many more GLES2 fixes

This commit is contained in:
Juan Linietsky 2018-09-29 19:17:34 -03:00
parent 0378a9ba80
commit 3333166b07
4 changed files with 114 additions and 72 deletions

View file

@ -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

View file

@ -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);

View file

@ -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_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
@ -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;
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);

View file

@ -817,7 +817,7 @@ void SpatialMaterial::_update_shader() {
code += "\tALPHA = albedo.a * albedo_tex.a;\n";
}
if (proximity_fade_enabled) {
if (!VisualServer::get_singleton()->is_low_end() && proximity_fade_enabled) {
code += "\tfloat depth_tex = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.0).r;\n";
code += "\tvec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV*2.0-1.0,depth_tex*2.0-1.0,1.0);\n";
code += "\tworld_pos.xyz/=world_pos.w;\n";
@ -825,43 +825,45 @@ void SpatialMaterial::_update_shader() {
}
if (distance_fade != DISTANCE_FADE_DISABLED) {
if (distance_fade == DISTANCE_FADE_OBJECT_DITHER || distance_fade == DISTANCE_FADE_PIXEL_DITHER) {
if ((distance_fade == DISTANCE_FADE_OBJECT_DITHER || distance_fade == DISTANCE_FADE_PIXEL_DITHER)) {
code += "\t{\n";
if (distance_fade == DISTANCE_FADE_OBJECT_DITHER) {
code += "\t\tfloat fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);\n";
if (!VisualServer::get_singleton()->is_low_end()) {
code += "\t{\n";
if (distance_fade == DISTANCE_FADE_OBJECT_DITHER) {
code += "\t\tfloat fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);\n";
} else {
code += "\t\tfloat fade_distance=-VERTEX.z;\n";
} else {
code += "\t\tfloat fade_distance=-VERTEX.z;\n";
}
code += "\t\tfloat fade=clamp(smoothstep(distance_fade_min,distance_fade_max,fade_distance),0.0,1.0);\n";
code += "\t\tint x = int(FRAGCOORD.x) % 4;\n";
code += "\t\tint y = int(FRAGCOORD.y) % 4;\n";
code += "\t\tint index = x + y * 4;\n";
code += "\t\tfloat limit = 0.0;\n\n";
code += "\t\tif (x < 8) {\n";
code += "\t\t\tif (index == 0) limit = 0.0625;\n";
code += "\t\t\tif (index == 1) limit = 0.5625;\n";
code += "\t\t\tif (index == 2) limit = 0.1875;\n";
code += "\t\t\tif (index == 3) limit = 0.6875;\n";
code += "\t\t\tif (index == 4) limit = 0.8125;\n";
code += "\t\t\tif (index == 5) limit = 0.3125;\n";
code += "\t\t\tif (index == 6) limit = 0.9375;\n";
code += "\t\t\tif (index == 7) limit = 0.4375;\n";
code += "\t\t\tif (index == 8) limit = 0.25;\n";
code += "\t\t\tif (index == 9) limit = 0.75;\n";
code += "\t\t\tif (index == 10) limit = 0.125;\n";
code += "\t\t\tif (index == 11) limit = 0.625;\n";
code += "\t\t\tif (index == 12) limit = 1.0;\n";
code += "\t\t\tif (index == 13) limit = 0.5;\n";
code += "\t\t\tif (index == 14) limit = 0.875;\n";
code += "\t\t\tif (index == 15) limit = 0.375;\n";
code += "\t\t}\n\n";
code += "\tif (fade < limit)\n";
code += "\t\tdiscard;\n";
code += "\t}\n\n";
}
code += "\t\tfloat fade=clamp(smoothstep(distance_fade_min,distance_fade_max,fade_distance),0.0,1.0);\n";
code += "\t\tint x = int(FRAGCOORD.x) % 4;\n";
code += "\t\tint y = int(FRAGCOORD.y) % 4;\n";
code += "\t\tint index = x + y * 4;\n";
code += "\t\tfloat limit = 0.0;\n\n";
code += "\t\tif (x < 8) {\n";
code += "\t\t\tif (index == 0) limit = 0.0625;\n";
code += "\t\t\tif (index == 1) limit = 0.5625;\n";
code += "\t\t\tif (index == 2) limit = 0.1875;\n";
code += "\t\t\tif (index == 3) limit = 0.6875;\n";
code += "\t\t\tif (index == 4) limit = 0.8125;\n";
code += "\t\t\tif (index == 5) limit = 0.3125;\n";
code += "\t\t\tif (index == 6) limit = 0.9375;\n";
code += "\t\t\tif (index == 7) limit = 0.4375;\n";
code += "\t\t\tif (index == 8) limit = 0.25;\n";
code += "\t\t\tif (index == 9) limit = 0.75;\n";
code += "\t\t\tif (index == 10) limit = 0.125;\n";
code += "\t\t\tif (index == 11) limit = 0.625;\n";
code += "\t\t\tif (index == 12) limit = 1.0;\n";
code += "\t\t\tif (index == 13) limit = 0.5;\n";
code += "\t\t\tif (index == 14) limit = 0.875;\n";
code += "\t\t\tif (index == 15) limit = 0.375;\n";
code += "\t\t}\n\n";
code += "\tif (fade < limit)\n";
code += "\t\tdiscard;\n";
code += "\t}\n\n";
} else {
code += "\tALPHA*=clamp(smoothstep(distance_fade_min,distance_fade_max,-VERTEX.z),0.0,1.0);\n";
}