summaryrefslogtreecommitdiff
path: root/drivers/gles3/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gles3/shaders')
-rw-r--r--drivers/gles3/shaders/canvas.glsl87
-rw-r--r--drivers/gles3/shaders/particles.glsl3
-rw-r--r--drivers/gles3/shaders/scene.glsl24
-rw-r--r--drivers/gles3/shaders/screen_space_reflection.glsl47
-rw-r--r--drivers/gles3/shaders/ssao.glsl16
5 files changed, 102 insertions, 75 deletions
diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl
index 017009015e..7be6ee857a 100644
--- a/drivers/gles3/shaders/canvas.glsl
+++ b/drivers/gles3/shaders/canvas.glsl
@@ -6,8 +6,8 @@ layout(location=3) in vec4 color_attrib;
#ifdef USE_TEXTURE_RECT
-layout(location=1) in highp vec4 dst_rect;
-layout(location=2) in highp vec4 src_rect;
+uniform vec4 dst_rect;
+uniform vec4 src_rect;
#else
@@ -20,7 +20,7 @@ layout(location=4) in highp vec2 uv_attrib;
layout(std140) uniform CanvasItemData { //ubo:0
highp mat4 projection_matrix;
- highp vec4 time;
+ highp float time;
};
uniform highp mat4 modelview_matrix;
@@ -51,17 +51,21 @@ layout(std140) uniform LightData { //ubo:1
out vec4 light_uv_interp;
-#if defined(NORMAL_USED)
+
out vec4 local_rot;
-#endif
+
#ifdef USE_SHADOWS
out highp vec2 pos;
#endif
+const bool at_light_pass = true;
+#else
+const bool at_light_pass = false;
#endif
+
VERTEX_SHADER_GLOBALS
#if defined(USE_MATERIAL)
@@ -121,7 +125,7 @@ VERTEX_SHADER_CODE
pos=outvec.xy;
#endif
-#if defined(NORMAL_USED)
+
local_rot.xy=normalize( (modelview_matrix * ( extra_matrix * vec4(1.0,0.0,0.0,0.0) )).xy );
local_rot.zw=normalize( (modelview_matrix * ( extra_matrix * vec4(0.0,1.0,0.0,0.0) )).xy );
#ifdef USE_TEXTURE_RECT
@@ -129,7 +133,7 @@ VERTEX_SHADER_CODE
local_rot.zw*=sign(src_rect.w);
#endif
-#endif
+
#endif
@@ -141,6 +145,7 @@ VERTEX_SHADER_CODE
uniform mediump sampler2D color_texture; // texunit:0
uniform highp vec2 color_texpixel_size;
+uniform mediump sampler2D normal_texture; // texunit:1
in mediump vec2 uv_interp;
in mediump vec4 color_interp;
@@ -155,7 +160,7 @@ uniform sampler2D screen_texture; // texunit:-3
layout(std140) uniform CanvasItemData {
highp mat4 projection_matrix;
- highp vec4 time;
+ highp float time;
};
@@ -180,9 +185,8 @@ uniform lowp sampler2D light_texture; // texunit:-1
in vec4 light_uv_interp;
-#if defined(NORMAL_USED)
in vec4 local_rot;
-#endif
+
#ifdef USE_SHADOWS
@@ -191,6 +195,9 @@ in highp vec2 pos;
#endif
+const bool at_light_pass = true;
+#else
+const bool at_light_pass = false;
#endif
uniform mediump vec4 final_modulate;
@@ -222,12 +229,28 @@ LIGHT_SHADER_CODE
}
+#ifdef USE_TEXTURE_RECT
+
+uniform vec4 dst_rect;
+uniform vec4 src_rect;
+uniform bool clip_rect_uv;
+
+#endif
+
+uniform bool use_default_normal;
void main() {
vec4 color = color_interp;
-#if defined(NORMAL_USED)
- vec3 normal = vec3(0.0,0.0,1.0);
+ vec2 uv = uv_interp;
+
+#ifdef USE_TEXTURE_RECT
+ if (clip_rect_uv) {
+
+ vec2 half_texpixel = color_texpixel_size * 0.5;
+ uv = clamp(uv,src_rect.xy+half_texpixel,src_rect.xy+abs(src_rect.zw)-color_texpixel_size);
+ }
+
#endif
#if !defined(COLOR_USED)
@@ -235,15 +258,34 @@ void main() {
#ifdef USE_DISTANCE_FIELD
const float smoothing = 1.0/32.0;
- float distance = texture(color_texture, uv_interp).a;
+ float distance = textureLod(color_texture, uv,0.0).a;
color.a = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance) * color.a;
#else
- color *= texture( color_texture, uv_interp );
+ color *= texture( color_texture, uv );
#endif
#endif
+ vec3 normal;
+
+#if defined(NORMAL_USED)
+
+ bool normal_used = true;
+#else
+ bool normal_used = false;
+#endif
+
+ if (use_default_normal) {
+ normal.xy = textureLod(normal_texture, uv,0.0).xy * 2.0 - 1.0;
+ normal.z = sqrt(1.0-dot(normal.xy,normal.xy));
+ normal_used=true;
+ } else {
+ normal = vec3(0.0,0.0,1.0);
+ }
+
+
+
#if defined(ENABLE_SCREEN_UV)
vec2 screen_uv = gl_FragCoord.xy*screen_uv_mult;
#endif
@@ -278,9 +320,9 @@ FRAGMENT_SHADER_CODE
vec2 light_vec = light_uv_interp.zw;; //for shadow and normal mapping
-#if defined(NORMAL_USED)
- normal.xy = mat2(local_rot.xy,local_rot.zw) * normal.xy;
-#endif
+ if (normal_used) {
+ normal.xy = mat2(local_rot.xy,local_rot.zw) * normal.xy;
+ }
float att=1.0;
@@ -301,10 +343,11 @@ FRAGMENT_SHADER_CODE
#else
-#if defined(NORMAL_USED)
- vec3 light_normal = normalize(vec3(light_vec,-light_height));
- light*=max(dot(-light_normal,normal),0.0);
-#endif
+ if (normal_used) {
+
+ vec3 light_normal = normalize(vec3(light_vec,-light_height));
+ light*=max(dot(-light_normal,normal),0.0);
+ }
color*=light;
/*
@@ -381,7 +424,7 @@ FRAGMENT_SHADER_CODE
#ifdef SHADOW_FILTER_NEAREST
- SHADOW_TEST(su+shadowpixel_size);
+ SHADOW_TEST(su);
#endif
diff --git a/drivers/gles3/shaders/particles.glsl b/drivers/gles3/shaders/particles.glsl
index 5d8a532f87..7e7b083f73 100644
--- a/drivers/gles3/shaders/particles.glsl
+++ b/drivers/gles3/shaders/particles.glsl
@@ -28,7 +28,7 @@ uniform float prev_system_phase;
uniform int total_particles;
uniform float explosiveness;
uniform float randomness;
-uniform vec4 time;
+uniform float time;
uniform float delta;
uniform int attractor_count;
@@ -132,6 +132,7 @@ void main() {
}
uint particle_number = current_cycle * uint(total_particles) + uint(gl_VertexID);
+ int index = int(gl_VertexID);
if (restart) {
shader_active=emitting;
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index 60efc953f9..a047e693cb 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -63,7 +63,6 @@ layout(std140) uniform SceneData { //ubo:0
highp mat4 projection_matrix;
highp mat4 camera_inverse_matrix;
highp mat4 camera_matrix;
- highp vec4 time;
highp vec4 ambient_light_color;
highp vec4 bg_color;
@@ -74,8 +73,8 @@ layout(std140) uniform SceneData { //ubo:0
float ambient_energy;
float bg_energy;
- float shadow_z_offset;
- float shadow_z_slope_scale;
+ float z_offset;
+ float z_slope_scale;
float shadow_dual_paraboloid_render_zfar;
float shadow_dual_paraboloid_render_side;
@@ -83,6 +82,7 @@ layout(std140) uniform SceneData { //ubo:0
vec2 shadow_atlas_pixel_size;
vec2 directional_shadow_pixel_size;
+ float time;
float z_far;
float reflection_multiplier;
float subsurface_scatter_width;
@@ -245,7 +245,7 @@ void main() {
normal = vec4(normal,0.0) * m;
#if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
- tangent.xyz = vec4(tangent.xyz,0.0) * mn;
+ tangent.xyz = vec4(tangent.xyz,0.0) * m;
#endif
}
#endif
@@ -319,7 +319,7 @@ VERTEX_SHADER_CODE
//for dual paraboloid shadow mapping, this is the fastest but least correct way, as it curves straight edges
- highp vec3 vtx = vertex_interp+normalize(vertex_interp)*shadow_z_offset;
+ highp vec3 vtx = vertex_interp+normalize(vertex_interp)*z_offset;
highp float distance = length(vtx);
vtx = normalize(vtx);
vtx.xy/=1.0-vtx.z;
@@ -332,8 +332,8 @@ VERTEX_SHADER_CODE
#else
- float z_ofs = shadow_z_offset;
- z_ofs += (1.0-abs(normal_interp.z))*shadow_z_slope_scale;
+ float z_ofs = z_offset;
+ z_ofs += (1.0-abs(normal_interp.z))*z_slope_scale;
vertex_interp.z-=z_ofs;
#endif //RENDER_DEPTH_DUAL_PARABOLOID
@@ -368,6 +368,8 @@ VERTEX_SHADER_CODE
*/
+uniform highp mat4 world_transform;
+
#define M_PI 3.14159265359
/* Varyings */
@@ -435,7 +437,6 @@ layout(std140) uniform SceneData {
highp mat4 projection_matrix;
highp mat4 camera_inverse_matrix;
highp mat4 camera_matrix;
- highp vec4 time;
highp vec4 ambient_light_color;
highp vec4 bg_color;
@@ -446,8 +447,8 @@ layout(std140) uniform SceneData {
float ambient_energy;
float bg_energy;
- float shadow_z_offset;
- float shadow_z_slope_scale;
+ float z_offset;
+ float z_slope_scale;
float shadow_dual_paraboloid_render_zfar;
float shadow_dual_paraboloid_render_side;
@@ -455,6 +456,7 @@ layout(std140) uniform SceneData {
vec2 shadow_atlas_pixel_size;
vec2 directional_shadow_pixel_size;
+ float time;
float z_far;
float reflection_multiplier;
float subsurface_scatter_width;
@@ -1543,7 +1545,7 @@ FRAGMENT_SHADER_CODE
#if defined(LIGHT_USE_PSSM_BLEND)
if (use_blend) {
- shadow=mix(shadow, sample_shadow(directional_shadow,directional_shadow_pixel_size,pssm_coord2.xy,pssm_coord2.z,light_clamp));
+ shadow=mix(shadow, sample_shadow(directional_shadow,directional_shadow_pixel_size,pssm_coord2.xy,pssm_coord2.z,light_clamp),pssm_blend);
}
#endif
diff --git a/drivers/gles3/shaders/screen_space_reflection.glsl b/drivers/gles3/shaders/screen_space_reflection.glsl
index 8eec71ecb6..cc41d36c37 100644
--- a/drivers/gles3/shaders/screen_space_reflection.glsl
+++ b/drivers/gles3/shaders/screen_space_reflection.glsl
@@ -38,7 +38,8 @@ uniform mat4 projection;
uniform int num_steps;
uniform float depth_tolerance;
uniform float distance_fade;
-uniform float acceleration;
+uniform float curve_fade_in;
+
layout(location = 0) out vec4 frag_color;
@@ -148,8 +149,6 @@ void main() {
bool found=false;
- //if acceleration > 0, distance between pixels gets larger each step. This allows covering a larger area
- float accel=1.0+acceleration;
float steps_taken=0.0;
for(int i=0;i<num_steps;i++) {
@@ -177,9 +176,6 @@ void main() {
steps_taken+=1.0;
prev_pos=pos;
- z_advance*=accel;
- w_advance*=accel;
- line_advance*=accel;
}
@@ -207,41 +203,14 @@ void main() {
vec2 final_pos;
float grad;
+ grad=steps_taken/float(num_steps);
+ float initial_fade = curve_fade_in==0.0 ? 1.0 : pow(clamp(grad,0.0,1.0),curve_fade_in);
+ float fade = pow(clamp(1.0-grad,0.0,1.0),distance_fade)*initial_fade;
+ final_pos=pos;
-#ifdef SMOOTH_ACCEL
- //if the distance between point and prev point is >1, then take some samples in the middle for smoothing out the image
- vec2 blend_dir = pos - prev_pos;
- float steps = min(8.0,length(blend_dir));
- if (steps>2.0) {
- vec2 blend_step = blend_dir/steps;
- float blend_z = (z_to-z_from)/steps;
- vec2 new_pos;
- float subgrad=0.0;
- for(float i=0.0;i<steps;i++) {
-
- new_pos = (prev_pos+blend_step*i);
- float z = z_from+blend_z*i;
-
- depth = texture(source_depth, new_pos*pixel_size).r * 2.0 - 1.0;
- depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth * (camera_z_far - camera_z_near));
- depth=-depth;
-
- subgrad=i/steps;
- if (depth>z)
- break;
- }
- final_pos = new_pos;
- grad=(steps_taken+subgrad)/float(num_steps);
- } else {
-#endif
- grad=steps_taken/float(num_steps);
- final_pos=pos;
-#ifdef SMOOTH_ACCEL
- }
-#endif
@@ -327,10 +296,10 @@ void main() {
final_color = textureLod(source_diffuse,final_pos*pixel_size,0.0);
}
- frag_color = vec4(final_color.rgb,pow(clamp(1.0-grad,0.0,1.0),distance_fade)*margin_blend);
+ frag_color = vec4(final_color.rgb,fade*margin_blend);
#else
- frag_color = vec4(textureLod(source_diffuse,final_pos*pixel_size,0.0).rgb,pow(clamp(1.0-grad,0.0,1.0),distance_fade)*margin_blend);
+ frag_color = vec4(textureLod(source_diffuse,final_pos*pixel_size,0.0).rgb,fade*margin_blend);
#endif
diff --git a/drivers/gles3/shaders/ssao.glsl b/drivers/gles3/shaders/ssao.glsl
index ba29ec52c7..d8302bd46e 100644
--- a/drivers/gles3/shaders/ssao.glsl
+++ b/drivers/gles3/shaders/ssao.glsl
@@ -12,7 +12,7 @@ void main() {
[fragment]
-#define NUM_SAMPLES (11)
+#define NUM_SAMPLES (15)
// If using depth mip levels, the log of the maximum pixel offset before we need to switch to a lower
// miplevel to maintain reasonable spatial locality in the cache
@@ -25,8 +25,20 @@ void main() {
// This is the number of turns around the circle that the spiral pattern makes. This should be prime to prevent
// taps from lining up. This particular choice was tuned for NUM_SAMPLES == 9
-#define NUM_SPIRAL_TURNS (7)
+const int ROTATIONS[] = int[]( 1, 1, 2, 3, 2, 5, 2, 3, 2,
+3, 3, 5, 5, 3, 4, 7, 5, 5, 7,
+9, 8, 5, 5, 7, 7, 7, 8, 5, 8,
+11, 12, 7, 10, 13, 8, 11, 8, 7, 14,
+11, 11, 13, 12, 13, 19, 17, 13, 11, 18,
+19, 11, 11, 14, 17, 21, 15, 16, 17, 18,
+13, 17, 11, 17, 19, 18, 25, 18, 19, 19,
+29, 21, 19, 27, 31, 29, 21, 18, 17, 29,
+31, 31, 23, 18, 25, 26, 25, 23, 19, 34,
+19, 27, 21, 25, 39, 29, 17, 21, 27 );
+
+//#define NUM_SPIRAL_TURNS (7)
+const int NUM_SPIRAL_TURNS = ROTATIONS[NUM_SAMPLES-1];
uniform sampler2D source_depth; //texunit:0
uniform highp usampler2D source_depth_mipmaps; //texunit:1