diff options
Diffstat (limited to 'drivers/gles3/shaders')
-rw-r--r-- | drivers/gles3/shaders/canvas.glsl | 27 | ||||
-rw-r--r-- | drivers/gles3/shaders/copy.glsl | 8 | ||||
-rw-r--r-- | drivers/gles3/shaders/cubemap_filter.glsl | 12 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 85 |
4 files changed, 67 insertions, 65 deletions
diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index 7255b0425c..07ee9cd010 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -55,7 +55,7 @@ out highp vec2 pixel_size_interp; #endif #ifdef USE_SKELETON -uniform mediump sampler2D skeleton_texture; // texunit:-1 +uniform mediump sampler2D skeleton_texture; // texunit:-4 uniform highp mat4 skeleton_transform; uniform highp mat4 skeleton_transform_inverse; #endif @@ -150,6 +150,7 @@ void main() { #define extra_matrix extra_matrix_instance + float point_size = 1.0; //for compatibility with the fragment shader we need to use uv here vec2 uv = uv_interp; { @@ -160,6 +161,7 @@ VERTEX_SHADER_CODE /* clang-format on */ } + gl_PointSize = point_size; uv_interp = uv; #ifdef USE_NINEPATCH @@ -395,26 +397,29 @@ float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, flo draw_center--; } - if (np_repeat == 0) { //stretch - //convert to ratio + // np_repeat is passed as uniform using NinePatchRect::AxisStretchMode enum. + if (np_repeat == 0) { // Stretch. + // Convert to ratio. float ratio = (pixel - screen_margin_begin) / (draw_size - screen_margin_begin - screen_margin_end); - //scale to source texture + // Scale to source texture. return (margin_begin + ratio * (tex_size - margin_begin - margin_end)) * tex_pixel_size; - } else if (np_repeat == 1) { //tile - //convert to ratio + } else if (np_repeat == 1) { // Tile. + // Convert to offset. float ofs = mod((pixel - screen_margin_begin), tex_size - margin_begin - margin_end); - //scale to source texture + // Scale to source texture. return (margin_begin + ofs) * tex_pixel_size; - } else if (np_repeat == 2) { //tile fit - //convert to ratio + } else if (np_repeat == 2) { // Tile Fit. + // Calculate scale. float src_area = draw_size - screen_margin_begin - screen_margin_end; float dst_area = tex_size - margin_begin - margin_end; float scale = max(1.0, floor(src_area / max(dst_area, 0.0000001) + 0.5)); - - //convert to ratio + // Convert to ratio. float ratio = (pixel - screen_margin_begin) / src_area; ratio = mod(ratio * scale, 1.0); + // Scale to source texture. return (margin_begin + ratio * dst_area) * tex_pixel_size; + } else { // Shouldn't happen, but silences compiler warning. + return 0.0; } } } diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl index 1952e201aa..a3cdb3a543 100644 --- a/drivers/gles3/shaders/copy.glsl +++ b/drivers/gles3/shaders/copy.glsl @@ -104,6 +104,10 @@ uniform sampler2D CbCr; //texunit:1 /* clang-format on */ +#ifdef USE_LOD +uniform float mip_level; +#endif + #if defined(USE_TEXTURE3D) || defined(USE_TEXTURE2DARRAY) uniform float layer; #endif @@ -190,8 +194,12 @@ void main() { color.gb = textureLod(CbCr, uv_interp, 0.0).rg - vec2(0.5, 0.5); color.a = 1.0; #else +#ifdef USE_LOD + vec4 color = textureLod(source, uv_interp, mip_level); +#else vec4 color = textureLod(source, uv_interp, 0.0); #endif +#endif #ifdef LINEAR_TO_SRGB // regular Linear -> SRGB conversion diff --git a/drivers/gles3/shaders/cubemap_filter.glsl b/drivers/gles3/shaders/cubemap_filter.glsl index f94ac8c81c..e1872eb433 100644 --- a/drivers/gles3/shaders/cubemap_filter.glsl +++ b/drivers/gles3/shaders/cubemap_filter.glsl @@ -23,6 +23,7 @@ precision highp int; #ifdef USE_SOURCE_PANORAMA uniform sampler2D source_panorama; //texunit:0 +uniform float source_resolution; #endif #ifdef USE_SOURCE_DUAL_PARABOLOID_ARRAY @@ -44,7 +45,6 @@ uniform samplerCube source_cube; //texunit:0 uniform int face_id; uniform float roughness; -uniform float source_resolution; in highp vec2 uv_interp; @@ -183,12 +183,12 @@ vec2 Hammersley(uint i, uint N) { #ifdef LOW_QUALITY #define SAMPLE_COUNT 64u -#define SAMPLE_DELTA 0.05 +#define SAMPLE_DELTA 0.1 #else #define SAMPLE_COUNT 512u -#define SAMPLE_DELTA 0.01 +#define SAMPLE_DELTA 0.03 #endif @@ -309,7 +309,7 @@ void main() { } st /= vec2(M_PI * 2.0, M_PI); - irradiance += texture(source_panorama, st, source_mip_level).rgb * cos(theta) * sin(theta); + irradiance += textureLod(source_panorama, st, source_mip_level).rgb * cos(theta) * sin(theta); num_samples++; } } @@ -332,6 +332,7 @@ void main() { if (ndotl > 0.0) { +#ifdef USE_SOURCE_PANORAMA float D = DistributionGGX(N, H, roughness); float ndoth = max(dot(N, H), 0.0); float hdotv = max(dot(H, V), 0.0); @@ -342,17 +343,14 @@ void main() { float mipLevel = roughness == 0.0 ? 0.0 : 0.5 * log2(saSample / saTexel); -#ifdef USE_SOURCE_PANORAMA sum.rgb += texturePanorama(L, source_panorama, mipLevel).rgb * ndotl; #endif #ifdef USE_SOURCE_DUAL_PARABOLOID_ARRAY - sum.rgb += textureDualParaboloidArray(L).rgb * ndotl; #endif #ifdef USE_SOURCE_DUAL_PARABOLOID - sum.rgb += textureDualParaboloid(L).rgb * ndotl; #endif diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index e1b0e9f595..a45ac2eb8a 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -213,12 +213,10 @@ void light_compute(vec3 N, vec3 L, vec3 V, vec3 light_color, float roughness, in //normalized blinn always unless disabled vec3 H = normalize(V + L); float cNdotH = max(dot(N, H), 0.0); - float cVdotH = max(dot(V, H), 0.0); - float cLdotH = max(dot(L, H), 0.0); float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25; - float blinn = pow(cNdotH, shininess); + float blinn = pow(cNdotH, shininess) * cNdotL; blinn *= (shininess + 8.0) * (1.0 / (8.0 * M_PI)); - specular_brdf_NL = (blinn) / max(4.0 * cNdotV * cNdotL, 0.75); + specular_brdf_NL = blinn; #endif specular += specular_brdf_NL * light_color * (1.0 / M_PI); @@ -434,6 +432,8 @@ void main() { } #endif + float point_size = 1.0; + highp mat4 modelview = camera_inverse_matrix * world_matrix; { /* clang-format off */ @@ -443,6 +443,8 @@ VERTEX_SHADER_CODE /* clang-format on */ } + gl_PointSize = point_size; + // using local coordinates (default) #if !defined(SKIP_TRANSFORM_USED) && !defined(VERTEX_WORLD_COORDS_USED) @@ -895,18 +897,22 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) { bias += incr * 2.0; vec3 uv_depth = (source.xyz / source.w) * 0.5 + 0.5; - float depth = texture(depth_buffer, uv_depth.xy).r; - - if (depth < uv_depth.z) { - if (depth > (bias.z / bias.w) * 0.5 + 0.5) { - return min(pow(ratio, 4.0), 1.0); - } else { - return 1.0; + if (uv_depth.x > 0.0 && uv_depth.x < 1.0 && uv_depth.y > 0.0 && uv_depth.y < 1.0) { + float depth = texture(depth_buffer, uv_depth.xy).r; + + if (depth < uv_depth.z) { + if (depth > (bias.z / bias.w) * 0.5 + 0.5) { + return min(pow(ratio, 4.0), 1.0); + } else { + return 1.0; + } } - } - ratio += ratio_incr; - steps -= 1.0; + ratio += ratio_incr; + steps -= 1.0; + } else { + return 1.0; + } } return 1.0; @@ -1094,9 +1100,9 @@ LIGHT_SHADER_CODE //normalized blinn float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25; - float blinn = pow(cNdotH, shininess); + float blinn = pow(cNdotH, shininess) * cNdotL; blinn *= (shininess + 8.0) * (1.0 / (8.0 * M_PI)); - float intensity = (blinn) / max(4.0 * cNdotV * cNdotL, 0.75); + float intensity = blinn; specular_light += light_color * intensity * specular_blob_intensity * attenuation; @@ -1218,44 +1224,21 @@ in highp float dp_clip; #endif -#if 0 -// need to save texture depth for this -vec3 light_transmittance(float translucency,vec3 light_vec, vec3 normal, vec3 pos, float distance) { - - float scale = 8.25 * (1.0 - translucency) / subsurface_scatter_width; - float d = scale * distance; - - /** - * Armed with the thickness, we can now calculate the color by means of the - * precalculated transmittance profile. - * (It can be precomputed into a texture, for maximum performance): - */ - float dd = -d * d; - vec3 profile = - vec3(0.233, 0.455, 0.649) * exp(dd / 0.0064) + - vec3(0.1, 0.336, 0.344) * exp(dd / 0.0484) + - vec3(0.118, 0.198, 0.0) * exp(dd / 0.187) + - vec3(0.113, 0.007, 0.007) * exp(dd / 0.567) + - vec3(0.358, 0.004, 0.0) * exp(dd / 1.99) + - vec3(0.078, 0.0, 0.0) * exp(dd / 7.41); - - /** - * Using the profile, we finally approximate the transmitted lighting from - * the back of the object: - */ - return profile * clamp(0.3 + dot(light_vec, normal),0.0,1.0); -} -#endif - void light_process_omni(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 binormal, vec3 tangent, vec3 albedo, vec3 transmission, float roughness, float metallic, float specular, float rim, float rim_tint, float clearcoat, float clearcoat_gloss, float anisotropy, float p_blob_intensity, inout vec3 diffuse_light, inout vec3 specular_light, inout float alpha) { vec3 light_rel_vec = omni_lights[idx].light_pos_inv_radius.xyz - vertex; float light_length = length(light_rel_vec); float normalized_distance = light_length * omni_lights[idx].light_pos_inv_radius.w; - float omni_attenuation = pow(max(1.0 - normalized_distance, 0.0), omni_lights[idx].light_direction_attenuation.w); + float omni_attenuation; + if (normalized_distance < 1.0) { + omni_attenuation = pow(1.0 - normalized_distance, omni_lights[idx].light_direction_attenuation.w); + } else { + omni_attenuation = 0.0; + } vec3 light_attenuation = vec3(omni_attenuation); #if !defined(SHADOWS_DISABLED) +#ifdef USE_SHADOW if (omni_lights[idx].light_params.w > 0.5) { // there is a shadowmap @@ -1300,6 +1283,7 @@ void light_process_omni(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi #endif light_attenuation *= mix(omni_lights[idx].shadow_color_contact.rgb, vec3(1.0), shadow); } +#endif //USE_SHADOW #endif //SHADOWS_DISABLED light_compute(normal, normalize(light_rel_vec), eye_vec, binormal, tangent, omni_lights[idx].light_color_energy.rgb, light_attenuation, albedo, transmission, omni_lights[idx].light_params.z * p_blob_intensity, roughness, metallic, specular, rim * omni_attenuation, rim_tint, clearcoat, clearcoat_gloss, anisotropy, diffuse_light, specular_light, alpha); } @@ -1309,7 +1293,12 @@ void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi vec3 light_rel_vec = spot_lights[idx].light_pos_inv_radius.xyz - vertex; float light_length = length(light_rel_vec); float normalized_distance = light_length * spot_lights[idx].light_pos_inv_radius.w; - float spot_attenuation = pow(max(1.0 - normalized_distance, 0.001), spot_lights[idx].light_direction_attenuation.w); + float spot_attenuation; + if (normalized_distance < 1.0) { + spot_attenuation = pow(1.0 - normalized_distance, spot_lights[idx].light_direction_attenuation.w); + } else { + spot_attenuation = 0.0; + } vec3 spot_dir = spot_lights[idx].light_direction_attenuation.xyz; float spot_cutoff = spot_lights[idx].light_params.y; float scos = max(dot(-normalize(light_rel_vec), spot_dir), spot_cutoff); @@ -1318,6 +1307,7 @@ void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi vec3 light_attenuation = vec3(spot_attenuation); #if !defined(SHADOWS_DISABLED) +#ifdef USE_SHADOW if (spot_lights[idx].light_params.w > 0.5) { //there is a shadowmap highp vec4 splane = (spot_lights[idx].shadow_matrix * vec4(vertex, 1.0)); @@ -1334,6 +1324,7 @@ void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi #endif light_attenuation *= mix(spot_lights[idx].shadow_color_contact.rgb, vec3(1.0), shadow); } +#endif //USE_SHADOW #endif //SHADOWS_DISABLED light_compute(normal, normalize(light_rel_vec), eye_vec, binormal, tangent, spot_lights[idx].light_color_energy.rgb, light_attenuation, albedo, transmission, spot_lights[idx].light_params.z * p_blob_intensity, roughness, metallic, specular, rim * spot_attenuation, rim_tint, clearcoat, clearcoat_gloss, anisotropy, diffuse_light, specular_light, alpha); |