summaryrefslogtreecommitdiff
path: root/drivers/gles2/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gles2/shaders')
-rw-r--r--drivers/gles2/shaders/material.glsl88
1 files changed, 85 insertions, 3 deletions
diff --git a/drivers/gles2/shaders/material.glsl b/drivers/gles2/shaders/material.glsl
index 17365ea264..ad8a364ac1 100644
--- a/drivers/gles2/shaders/material.glsl
+++ b/drivers/gles2/shaders/material.glsl
@@ -4,10 +4,14 @@
#ifdef USE_GLES_OVER_GL
#define mediump
#define highp
+#define roundfix( m_val ) floor( (m_val) + 0.5 )
#else
precision mediump float;
precision mediump int;
#endif
+
+
+
/*
from VisualServer:
@@ -22,6 +26,26 @@ ARRAY_WEIGHTS=7,
ARRAY_INDEX=8,
*/
+//hack to use uv if no uv present so it works with lightmap
+#ifdef ENABLE_AMBIENT_LIGHTMAP
+
+#ifdef USE_LIGHTMAP_ON_UV2
+
+#ifndef ENABLE_UV2_INTERP
+#define ENABLE_UV2_INTERP
+#endif
+
+#else
+
+#ifndef ENABLE_UV_INTERP
+#define ENABLE_UV_INTERP
+#endif
+
+#endif
+
+#endif
+
+
/* INPUT ATTRIBS */
attribute highp vec4 vertex_attrib; // attrib:0
@@ -238,6 +262,7 @@ void main() {
#if defined(ENABLE_TANGENT_INTERP)
vec3 tangent_in = tangent_attrib.xyz;
tangent_in*=normal_mult;
+ float binormalf = tangent_attrib.a;
#endif
#ifdef USE_SKELETON
@@ -272,7 +297,7 @@ void main() {
#if defined(ENABLE_TANGENT_INTERP)
tangent_interp=normalize(tangent_in);
- binormal_interp = normalize( cross(normal_interp,tangent_interp) * tangent_attrib.a );
+ binormal_interp = normalize( cross(normal_interp,tangent_interp) * binormalf );
#endif
#if defined(ENABLE_UV_INTERP)
@@ -446,6 +471,7 @@ VERTEX_SHADER_CODE
#ifdef USE_GLES_OVER_GL
#define mediump
#define highp
+#define roundfix( m_val ) floor( (m_val) + 0.5 )
#else
precision mediump float;
@@ -453,6 +479,27 @@ precision mediump int;
#endif
+
+//hack to use uv if no uv present so it works with lightmap
+#ifdef ENABLE_AMBIENT_LIGHTMAP
+
+#ifdef USE_LIGHTMAP_ON_UV2
+
+#ifndef ENABLE_UV2_INTERP
+#define ENABLE_UV2_INTERP
+#endif
+
+#else
+
+#ifndef ENABLE_UV_INTERP
+#define ENABLE_UV_INTERP
+#endif
+
+#endif
+
+#endif
+
+
/* Varyings */
#if defined(ENABLE_COLOR_INTERP)
@@ -545,6 +592,13 @@ uniform int ambient_octree_steps;
#endif
+#ifdef ENABLE_AMBIENT_LIGHTMAP
+
+uniform highp sampler2D ambient_lightmap;
+uniform float ambient_lightmap_multiplier;
+
+#endif
+
FRAGMENT_SHADER_GLOBALS
@@ -783,6 +837,34 @@ FRAGMENT_SHADER_CODE
}
#endif
+ float shadow_attenuation = 1.0;
+
+#ifdef ENABLE_AMBIENT_LIGHTMAP
+
+ vec3 ambientmap_color = vec3(0.0,0.0,0.0);
+ vec2 ambientmap_uv = vec2(0.0,0.0);
+
+#ifdef USE_LIGHTMAP_ON_UV2
+
+ ambientmap_uv = uv2_interp;
+
+#else
+
+ ambientmap_uv = uv_interp;
+
+#endif
+
+ vec4 amcol = texture2D(ambient_lightmap,ambientmap_uv);
+ shadow_attenuation=amcol.a;
+ ambientmap_color = amcol.rgb;
+ ambientmap_color*=ambient_lightmap_multiplier;
+ ambientmap_color*=diffuse.rgb;
+
+
+
+#endif
+
+
#ifdef ENABLE_AMBIENT_OCTREE
vec3 ambientmap_color = vec3(0.0,0.0,0.0);
@@ -828,7 +910,7 @@ FRAGMENT_SHADER_CODE
#endif
- float shadow_attenuation = 1.0;
+
@@ -1120,7 +1202,7 @@ LIGHT_SHADER_CODE
#endif
-#ifdef ENABLE_AMBIENT_OCTREE
+#if defined(ENABLE_AMBIENT_OCTREE) || defined(ENABLE_AMBIENT_LIGHTMAP)
diffuse.rgb+=ambientmap_color;
#endif