summaryrefslogtreecommitdiff
path: root/drivers/gles2/shaders
diff options
context:
space:
mode:
authorJuan Linietsky <juan@godotengine.org>2019-02-25 21:46:24 -0300
committerJuan Linietsky <juan@godotengine.org>2019-02-25 21:47:29 -0300
commita32b26dfa26f2a039bf9c84b90d10666bcf785c9 (patch)
tree71ba0cf141b34b242edbe39f266ef36d6054a761 /drivers/gles2/shaders
parent51c1d55cf9089cefbde034893b4784a5d554ddcc (diff)
Several fixes to make GLES2 on HTML5 work much better.
Changed math class error reporting to be a bit less paranoid.
Diffstat (limited to 'drivers/gles2/shaders')
-rw-r--r--drivers/gles2/shaders/cubemap_filter.glsl13
-rw-r--r--drivers/gles2/shaders/scene.glsl46
2 files changed, 54 insertions, 5 deletions
diff --git a/drivers/gles2/shaders/cubemap_filter.glsl b/drivers/gles2/shaders/cubemap_filter.glsl
index 7643297a14..c32aabc4bf 100644
--- a/drivers/gles2/shaders/cubemap_filter.glsl
+++ b/drivers/gles2/shaders/cubemap_filter.glsl
@@ -187,6 +187,18 @@ void main() {
vec2 uv = (uv_interp * 2.0) - 1.0;
vec3 N = texelCoordToVec(uv, face_id);
+#ifdef USE_DIRECT_WRITE
+
+#ifdef USE_SOURCE_PANORAMA
+
+ gl_FragColor = vec4(texturePanorama(source_panorama, N).rgb, 1.0);
+#else
+
+ gl_FragColor = vec4(textureCube(source_cube,N).rgb, 1.0);
+#endif //USE_SOURCE_PANORAMA
+
+#else
+
vec4 sum = vec4(0.0);
for (int sample_num = 0; sample_num < SAMPLE_COUNT; sample_num++) {
@@ -221,4 +233,5 @@ void main() {
sum.rgb = mix((vec3(1.0) + a) * pow(sum.rgb, vec3(1.0 / 2.4)) - a, 12.92 * sum.rgb, vec3(lessThan(sum.rgb, vec3(0.0031308))));
gl_FragColor = vec4(sum.rgb, 1.0);
+#endif
}
diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl
index f90c6a6651..e638e94402 100644
--- a/drivers/gles2/shaders/scene.glsl
+++ b/drivers/gles2/shaders/scene.glsl
@@ -96,6 +96,10 @@ uniform float light_normal_bias;
// varyings
//
+#if defined(RENDER_DEPTH) && defined(USE_RGBA_SHADOWS)
+varying highp vec4 position_interp;
+#endif
+
varying highp vec3 vertex_interp;
varying vec3 normal_interp;
@@ -355,7 +359,7 @@ void main() {
uv2_interp = uv2_attrib;
#endif
-#ifdef OVERRIDE_POSITION
+#if defined(OVERRIDE_POSITION)
highp vec4 position;
#endif
@@ -647,11 +651,16 @@ VERTEX_SHADER_CODE
#endif //use vertex lighting
-#ifdef OVERRIDE_POSITION
+#if defined(OVERRIDE_POSITION)
gl_Position = position;
#else
gl_Position = projection_matrix * vec4(vertex_interp, 1.0);
#endif
+
+#if defined(RENDER_DEPTH) && defined(USE_RGBA_SHADOWS)
+ position_interp = gl_Position;
+#endif
+
}
/* clang-format off */
@@ -975,6 +984,10 @@ uniform vec4 light_clamp;
// varyings
//
+#if defined(RENDER_DEPTH) && defined(USE_RGBA_SHADOWS)
+varying highp vec4 position_interp;
+#endif
+
varying highp vec3 vertex_interp;
varying vec3 normal_interp;
@@ -1335,8 +1348,21 @@ LIGHT_SHADER_CODE
#ifdef USE_SHADOW
-#define SAMPLE_SHADOW_TEXEL(p_shadow, p_pos, p_depth) step(p_depth, texture2D(p_shadow, p_pos).r)
-#define SAMPLE_SHADOW_TEXEL_PROJ(p_shadow, p_pos) step(p_pos.z, texture2DProj(p_shadow, p_pos).r)
+#ifdef USE_RGBA_SHADOWS
+
+#define SHADOW_DEPTH(m_val) dot(m_val, vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0))
+
+#else
+
+#define SHADOW_DEPTH(m_val) (m_val).r
+
+#endif
+
+
+#define SAMPLE_SHADOW_TEXEL(p_shadow, p_pos, p_depth) step(p_depth, SHADOW_DEPTH(texture2D(p_shadow, p_pos)))
+#define SAMPLE_SHADOW_TEXEL_PROJ(p_shadow, p_pos) step(p_pos.z, SHADOW_DEPTH(texture2DProj(p_shadow, p_pos)))
+
+
float sample_shadow(highp sampler2D shadow, highp vec4 spos) {
@@ -2105,5 +2131,15 @@ FRAGMENT_SHADER_CODE
#endif // defined(FOG_DEPTH_ENABLED) || defined(FOG_HEIGHT_ENABLED)
-#endif // not RENDER_DEPTH
+#else // not RENDER_DEPTH
+//depth render
+#ifdef USE_RGBA_SHADOWS
+
+ highp float depth = ((position_interp.z / position_interp.w) + 1.0) * 0.5 + 0.0; // bias
+ highp vec4 comp = fract(depth * vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0));
+ comp -= comp.xxyz * vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
+ gl_FragColor = comp;
+
+#endif
+#endif
}