2014-02-10 02:10:30 +01:00
|
|
|
[vertex]
|
|
|
|
|
|
|
|
#ifdef USE_GLES_OVER_GL
|
|
|
|
#define mediump
|
|
|
|
#define highp
|
|
|
|
#else
|
|
|
|
precision mediump float;
|
|
|
|
precision mediump int;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
uniform highp mat4 projection_matrix;
|
|
|
|
uniform highp mat4 modelview_matrix;
|
|
|
|
uniform highp mat4 extra_matrix;
|
|
|
|
attribute highp vec3 vertex; // attrib:0
|
|
|
|
attribute vec4 color_attrib; // attrib:3
|
|
|
|
attribute highp vec2 uv_attrib; // attrib:4
|
|
|
|
|
|
|
|
varying vec2 uv_interp;
|
|
|
|
varying vec4 color_interp;
|
|
|
|
|
2015-01-11 15:43:31 +01:00
|
|
|
#if defined(USE_TIME)
|
|
|
|
uniform float time;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_LIGHTING
|
|
|
|
|
|
|
|
uniform highp mat4 light_matrix;
|
|
|
|
varying vec4 light_tex_pos;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(ENABLE_VAR1_INTERP)
|
|
|
|
varying vec4 var1_interp;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(ENABLE_VAR2_INTERP)
|
|
|
|
varying vec4 var2_interp;
|
|
|
|
#endif
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
//uniform bool snap_pixels;
|
|
|
|
|
2015-01-11 15:43:31 +01:00
|
|
|
VERTEX_SHADER_GLOBALS
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void main() {
|
|
|
|
|
|
|
|
color_interp = color_attrib;
|
|
|
|
uv_interp = uv_attrib;
|
2015-01-19 06:39:58 +01:00
|
|
|
highp vec4 outvec = vec4(vertex, 1.0);
|
2015-01-11 15:43:31 +01:00
|
|
|
{
|
2015-01-19 06:39:58 +01:00
|
|
|
vec2 src_vtx=outvec.xy;
|
2015-01-11 15:43:31 +01:00
|
|
|
VERTEX_SHADER_CODE
|
|
|
|
|
|
|
|
}
|
2015-01-21 00:25:19 +01:00
|
|
|
#if !defined(USE_WORLD_VEC)
|
2015-01-19 06:39:58 +01:00
|
|
|
outvec = extra_matrix * outvec;
|
|
|
|
outvec = modelview_matrix * outvec;
|
2015-01-21 00:25:19 +01:00
|
|
|
#endif
|
2015-01-19 06:39:58 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifdef USE_PIXEL_SNAP
|
|
|
|
|
2015-01-11 15:43:31 +01:00
|
|
|
outvec.xy=floor(outvec.xy+0.5);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2015-01-21 00:25:19 +01:00
|
|
|
gl_Position = projection_matrix * outvec;
|
|
|
|
|
2015-01-11 15:43:31 +01:00
|
|
|
#ifdef USE_LIGHTING
|
|
|
|
|
2015-01-21 00:25:19 +01:00
|
|
|
light_tex_pos.xy = light_matrix * gl_Position;
|
2015-01-11 15:43:31 +01:00
|
|
|
light_tex_pos.zw=outvec.xy - light_matrix[4].xy; //likely wrong
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
2015-01-11 15:43:31 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
[fragment]
|
|
|
|
|
|
|
|
#ifdef USE_GLES_OVER_GL
|
|
|
|
#define mediump
|
|
|
|
#define highp
|
|
|
|
#else
|
|
|
|
precision mediump float;
|
|
|
|
precision mediump int;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// texunit:0
|
|
|
|
uniform sampler2D texture;
|
|
|
|
|
|
|
|
varying vec2 uv_interp;
|
|
|
|
varying vec4 color_interp;
|
|
|
|
|
|
|
|
#ifdef MOMO
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-01-11 15:43:31 +01:00
|
|
|
#if defined(ENABLE_SCREEN_UV)
|
|
|
|
|
|
|
|
uniform vec2 screen_uv_mult;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(ENABLE_TEXSCREEN)
|
|
|
|
|
|
|
|
uniform vec2 texscreen_screen_mult;
|
2015-01-13 14:49:26 +01:00
|
|
|
uniform vec4 texscreen_screen_clamp;
|
2015-01-11 15:43:31 +01:00
|
|
|
uniform sampler2D texscreen_tex;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_VAR1_INTERP)
|
|
|
|
varying vec4 var1_interp;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(ENABLE_VAR2_INTERP)
|
|
|
|
varying vec4 var2_interp;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_TIME)
|
|
|
|
uniform float time;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_LIGHTING
|
|
|
|
|
|
|
|
uniform sampler2D light_texture;
|
|
|
|
varying vec4 light_tex_pos;
|
|
|
|
|
|
|
|
#ifdef USE_SHADOWS
|
|
|
|
|
|
|
|
uniform sampler2D shadow_texture;
|
|
|
|
uniform float shadow_attenuation;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-01-12 14:19:09 +01:00
|
|
|
#if defined(USE_TEXPIXEL_SIZE)
|
|
|
|
uniform vec2 texpixel_size;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2015-01-11 15:43:31 +01:00
|
|
|
FRAGMENT_SHADER_GLOBALS
|
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void main() {
|
|
|
|
|
|
|
|
vec4 color = color_interp;
|
2015-01-11 15:43:31 +01:00
|
|
|
#if defined(NORMAL_USED)
|
|
|
|
vec3 normal = vec3(0,0,1);
|
|
|
|
#endif
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
color *= texture2D( texture, uv_interp );
|
2015-01-11 15:43:31 +01:00
|
|
|
#if defined(ENABLE_SCREEN_UV)
|
|
|
|
vec2 screen_uv = gl_FragCoord.xy*screen_uv_mult;
|
|
|
|
#endif
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-01-11 15:43:31 +01:00
|
|
|
{
|
|
|
|
FRAGMENT_SHADER_CODE
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifdef DEBUG_ENCODED_32
|
|
|
|
highp float enc32 = dot( color,highp vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1) );
|
|
|
|
color = vec4(vec3(enc32),1.0);
|
|
|
|
#endif
|
2014-05-24 06:35:47 +02:00
|
|
|
|
2015-01-11 15:43:31 +01:00
|
|
|
#ifdef USE_LIGHTING
|
|
|
|
|
|
|
|
float att=1.0;
|
|
|
|
|
|
|
|
vec3 light = texture2D(light_texture,light_tex_pos).rgb;
|
|
|
|
#ifdef USE_SHADOWS
|
|
|
|
//this might not be that great on mobile?
|
|
|
|
float light_dist = length(light_texture.zw);
|
|
|
|
float light_angle = atan2(light_texture.x,light_texture.z) + 1.0 * 0.5;
|
|
|
|
float shadow_dist = texture2D(shadow_texture,vec2(light_angle,0));
|
|
|
|
if (light_dist>shadow_dist) {
|
|
|
|
light*=shadow_attenuation;
|
|
|
|
}
|
|
|
|
//use shadows
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_LIGHT_SHADER_CODE)
|
|
|
|
//light is written by the light shader
|
|
|
|
{
|
|
|
|
vec2 light_dir = normalize(light_tex_pos.zw);
|
|
|
|
float light_distance = length(light_tex_pos.zw);
|
|
|
|
LIGHT_SHADER_CODE
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
#if defined(NORMAL_USED)
|
|
|
|
vec2 light_normal = normalize(light_tex_pos.zw);
|
|
|
|
light = color.rgb * light * max(dot(light_normal,normal),0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
color.rgb=light;
|
|
|
|
//light shader code
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//use lighting
|
|
|
|
#endif
|
2014-05-24 06:35:47 +02:00
|
|
|
// color.rgb*=color.a;
|
2014-02-10 02:10:30 +01:00
|
|
|
gl_FragColor = color;
|
2014-05-24 06:35:47 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|