summaryrefslogtreecommitdiff
path: root/drivers/gles2/shaders
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-05-29 10:56:39 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-05-29 10:56:39 -0300
commit6f0b4678e26c04abfc88c0226c803e78a108de98 (patch)
tree51b99b2ece75e5782c0b14c97bb6913c48e7f363 /drivers/gles2/shaders
parentd9adf2627a70ab37408aca9ae4140c6280dfe6df (diff)
More 3D Improvements
-=-=-=-=-=-=-=-=-=-= -Sprite3D and AnimatedSprite3D support. -Opaque pre-pass works, is compatible with shadows -Improved shadow map rendering (can differentiate between plain opaque and opaque with shaders/discard/etc) -Added option to use alpha discard in FixedMaterial -Improved Glow FX, many more options (three modes, Additive, Screen and SoftLight), strength and scale -Ability for Background (image or cubemap) to send to glow buffer -Dumb Deploy of clients now actually works in Android -Many Many rendering fixes, 3D is much more usable now.
Diffstat (limited to 'drivers/gles2/shaders')
-rw-r--r--drivers/gles2/shaders/copy.glsl56
-rw-r--r--drivers/gles2/shaders/material.glsl20
2 files changed, 55 insertions, 21 deletions
diff --git a/drivers/gles2/shaders/copy.glsl b/drivers/gles2/shaders/copy.glsl
index bea651bceb..2f1b349618 100644
--- a/drivers/gles2/shaders/copy.glsl
+++ b/drivers/gles2/shaders/copy.glsl
@@ -99,6 +99,8 @@ uniform float bloom_treshold;
#if defined(BLUR_V_PASS) || defined(BLUR_H_PASS) || defined(USE_HDR_REDUCE)
uniform vec2 pixel_size;
+uniform float pixel_scale;
+uniform float blur_magnitude;
#ifdef USE_HDR_STORE
@@ -123,6 +125,10 @@ uniform highp float energy;
#endif
+#ifdef USE_CUSTOM_ALPHA
+uniform float custom_alpha;
+#endif
+
void main() {
@@ -195,28 +201,28 @@ void main() {
#ifdef BLUR_V_PASS
- color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-3.0));
- color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-2.0));
- color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-1.0));
- color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*1.0));
- color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*2.0));
- color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*3.0));
+ color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-3.0)*pixel_scale);
+ color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-2.0)*pixel_scale);
+ color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-1.0)*pixel_scale);
+ color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*1.0)*pixel_scale);
+ color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*2.0)*pixel_scale);
+ color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*3.0)*pixel_scale);
- color*=(1.0/7.0);
+ color*=(1.0/7.0)*blur_magnitude;
#endif
#ifdef BLUR_H_PASS
- color+=texture2D(source,uv_interp+vec2(pixel_size.x*-3.0,0.0));
- color+=texture2D(source,uv_interp+vec2(pixel_size.x*-2.0,0.0));
- color+=texture2D(source,uv_interp+vec2(pixel_size.x*-1.0,0.0));
- color+=texture2D(source,uv_interp+vec2(pixel_size.x*1.0,0.0));
- color+=texture2D(source,uv_interp+vec2(pixel_size.x*2.0,0.0));
- color+=texture2D(source,uv_interp+vec2(pixel_size.x*3.0,0.0));
+ color+=texture2D(source,uv_interp+vec2(pixel_size.x*-3.0,0.0)*pixel_scale);
+ color+=texture2D(source,uv_interp+vec2(pixel_size.x*-2.0,0.0)*pixel_scale);
+ color+=texture2D(source,uv_interp+vec2(pixel_size.x*-1.0,0.0)*pixel_scale);
+ color+=texture2D(source,uv_interp+vec2(pixel_size.x*1.0,0.0)*pixel_scale);
+ color+=texture2D(source,uv_interp+vec2(pixel_size.x*2.0,0.0)*pixel_scale);
+ color+=texture2D(source,uv_interp+vec2(pixel_size.x*3.0,0.0)*pixel_scale);
- color*=(1.0/7.0);
+ color*=(1.0/7.0)*blur_magnitude;
#endif
@@ -249,12 +255,25 @@ void main() {
vec4 glow = texture2D( glow_source, uv2_interp );
-#if 1
-//ifdef USE_GLOW_SCREEN
+#ifdef USE_GLOW_SCREEN
color.rgb = clamp((color.rgb + glow.rgb) - (color.rgb * glow.rgb), 0.0, 1.0);
-#else
+#endif
+
+#ifdef USE_GLOW_SOFTLIGHT
+
+ {
+
+ glow.rgb = (glow.rgb * 0.5) + 0.5;
+ color.r = (glow.r <= 0.5) ? (color.r - (1.0 - 2.0 * glow.r) * color.r * (1.0 - color.r)) : (((glow.r > 0.5) && (color.r <= 0.25)) ? (color.r + (2.0 * glow.r - 1.0) * (4.0 * color.r * (4.0 * color.r + 1.0) * (color.r - 1.0) + 7.0 * color.r)) : (color.r + (2.0 * glow.r - 1.0) * (sqrt(color.r) - color.r)));
+ color.g = (glow.g <= 0.5) ? (color.g - (1.0 - 2.0 * glow.g) * color.g * (1.0 - color.g)) : (((glow.g > 0.5) && (color.g <= 0.25)) ? (color.g + (2.0 * glow.g - 1.0) * (4.0 * color.g * (4.0 * color.g + 1.0) * (color.g - 1.0) + 7.0 * color.g)) : (color.g + (2.0 * glow.g - 1.0) * (sqrt(color.g) - color.g)));
+ color.b = (glow.b <= 0.5) ? (color.b - (1.0 - 2.0 * glow.b) * color.b * (1.0 - color.b)) : (((glow.b > 0.5) && (color.b <= 0.25)) ? (color.b + (2.0 * glow.b - 1.0) * (4.0 * color.b * (4.0 * color.b + 1.0) * (color.b - 1.0) + 7.0 * color.b)) : (color.b + (2.0 * glow.b - 1.0) * (sqrt(color.b) - color.b)));
+ }
+
+#endif
+
+#if !defined(USE_GLOW_SCREEN) && !defined(USE_GLOW_SOFTLIGHT)
color.rgb+=glow.rgb;
#endif
@@ -316,6 +335,9 @@ void main() {
color.a=1.0;
#endif
+#ifdef USE_CUSTOM_ALPHA
+ color.a=custom_alpha;
+#endif
gl_FragColor = color;
}
diff --git a/drivers/gles2/shaders/material.glsl b/drivers/gles2/shaders/material.glsl
index 1794f18801..a919e3b1e2 100644
--- a/drivers/gles2/shaders/material.glsl
+++ b/drivers/gles2/shaders/material.glsl
@@ -386,6 +386,7 @@ VERTEX_SHADER_CODE
specular_interp=vec3(0.0);
}
}
+
#else
#ifdef SHADELESS
@@ -722,21 +723,28 @@ void main() {
-#ifdef FRAGMENT_SHADER_CODE_USE_DISCARD
- float discard_=0.0;
+#if defined(ENABLE_DISCARD)
+ bool discard_=false;
#endif
FRAGMENT_SHADER_CODE
-#ifdef FRAGMENT_SHADER_CODE_USE_DISCARD
- if (discard_>0.0) {
+#if defined(ENABLE_DISCARD)
+ if (discard_) {
//easy to eliminate dead code
discard;
}
#endif
+#ifdef ENABLE_CLIP_ALPHA
+ if (diffuse.a<0.99) {
+ //used for doublepass and shadowmapping
+ discard;
+ }
+#endif
+
float shadow_attenuation = 1.0;
@@ -902,7 +910,10 @@ FRAGMENT_SHADER_CODE
# if !defined(LIGHT_TYPE_DIRECTIONAL) && !defined(LIGHT_TYPE_OMNI) && !defined (LIGHT_TYPE_SPOT)
//none
+#ifndef SHADELESS
diffuse.rgb=vec3(0.0,0.0,0.0);
+#endif
+
# endif
diffuse.rgb+=const_light_mult*emission;
@@ -959,6 +970,7 @@ FRAGMENT_SHADER_CODE
#ifdef USE_HDR
diffuse.rgb*=0.25;
#endif
+
gl_FragColor = diffuse;
#endif
}