2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
2016-10-03 21:33:42 +02:00
|
|
|
[vertex]
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
layout(location = 0) in highp vec2 vertex;
|
GLES3 fix normal map flipping with nvidia workaround
When not using TEXTURE_RECT path, flips have to sent via another method to the shader, to ensure that normal maps are correctly adjusted for direction. This PR adds an extra vertex attribute, LIGHT_ANGLE.
For nvidia workarounds, where the shader still has access to the final transform and extra matrix, the LIGHT_ANGLE can be 0 (no adjustment), 180 degrees for a horizontal flip, and negative indicates a vertical flip.
For batching path, the LIGHT_ANGLE can be used to directly specify the light angle for normal mapping, even when the final transform and extra matrix have been baked into vertex positions, so the same shader can be used for both.
2020-08-02 08:49:03 +02:00
|
|
|
|
2020-10-14 09:32:05 +02:00
|
|
|
#ifdef USE_ATTRIB_LIGHT_ANGLE
|
GLES3 fix normal map flipping with nvidia workaround
When not using TEXTURE_RECT path, flips have to sent via another method to the shader, to ensure that normal maps are correctly adjusted for direction. This PR adds an extra vertex attribute, LIGHT_ANGLE.
For nvidia workarounds, where the shader still has access to the final transform and extra matrix, the LIGHT_ANGLE can be 0 (no adjustment), 180 degrees for a horizontal flip, and negative indicates a vertical flip.
For batching path, the LIGHT_ANGLE can be used to directly specify the light angle for normal mapping, even when the final transform and extra matrix have been baked into vertex positions, so the same shader can be used for both.
2020-08-02 08:49:03 +02:00
|
|
|
layout(location = 2) in highp float light_angle;
|
|
|
|
#endif
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
2018-08-24 13:42:18 +02:00
|
|
|
layout(location = 3) in vec4 color_attrib;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2020-10-14 09:32:05 +02:00
|
|
|
#ifdef USE_ATTRIB_MODULATE
|
|
|
|
layout(location = 5) in vec4 modulate_attrib; // attrib:5
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_ATTRIB_LARGE_VERTEX
|
|
|
|
// shared with skeleton attributes, not used in batched shader
|
|
|
|
layout(location = 6) in vec2 translate_attrib; // attrib:6
|
|
|
|
layout(location = 7) in vec4 basis_attrib; // attrib:7
|
|
|
|
#endif
|
|
|
|
|
2018-05-03 22:29:15 +02:00
|
|
|
#ifdef USE_SKELETON
|
2018-08-24 13:42:18 +02:00
|
|
|
layout(location = 6) in uvec4 bone_indices; // attrib:6
|
|
|
|
layout(location = 7) in vec4 bone_weights; // attrib:7
|
2018-05-03 22:29:15 +02:00
|
|
|
#endif
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
#ifdef USE_TEXTURE_RECT
|
|
|
|
|
2017-06-19 03:55:02 +02:00
|
|
|
uniform vec4 dst_rect;
|
|
|
|
uniform vec4 src_rect;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-06-21 21:25:45 +02:00
|
|
|
#ifdef USE_INSTANCING
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
layout(location = 8) in highp vec4 instance_xform0;
|
|
|
|
layout(location = 9) in highp vec4 instance_xform1;
|
|
|
|
layout(location = 10) in highp vec4 instance_xform2;
|
|
|
|
layout(location = 11) in lowp vec4 instance_color;
|
2017-06-21 21:25:45 +02:00
|
|
|
|
|
|
|
#ifdef USE_INSTANCE_CUSTOM
|
2018-08-24 13:42:18 +02:00
|
|
|
layout(location = 12) in highp vec4 instance_custom_data;
|
2017-06-21 21:25:45 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
layout(location = 4) in highp vec2 uv_attrib;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
// skeleton
|
2016-10-03 21:33:42 +02:00
|
|
|
#endif
|
|
|
|
|
2017-06-21 21:25:45 +02:00
|
|
|
uniform highp vec2 color_texpixel_size;
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
layout(std140) uniform CanvasItemData { //ubo:0
|
|
|
|
|
|
|
|
highp mat4 projection_matrix;
|
2017-06-16 13:29:43 +02:00
|
|
|
highp float time;
|
2016-10-03 21:33:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
uniform highp mat4 modelview_matrix;
|
|
|
|
uniform highp mat4 extra_matrix;
|
|
|
|
|
2018-01-02 22:44:09 +01:00
|
|
|
out highp vec2 uv_interp;
|
2016-10-03 21:33:42 +02:00
|
|
|
out mediump vec4 color_interp;
|
2020-10-14 09:32:05 +02:00
|
|
|
|
|
|
|
#ifdef USE_ATTRIB_MODULATE
|
|
|
|
// modulate doesn't need interpolating but we need to send it to the fragment shader
|
|
|
|
out mediump vec4 modulate_interp;
|
|
|
|
#endif
|
|
|
|
|
2020-05-03 02:55:14 +02:00
|
|
|
#ifdef MODULATE_USED
|
|
|
|
uniform mediump vec4 final_modulate;
|
|
|
|
#endif
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-06-22 04:37:25 +02:00
|
|
|
#ifdef USE_NINEPATCH
|
|
|
|
|
|
|
|
out highp vec2 pixel_size_interp;
|
|
|
|
#endif
|
|
|
|
|
2018-05-03 22:29:15 +02:00
|
|
|
#ifdef USE_SKELETON
|
2019-12-23 01:00:18 +01:00
|
|
|
uniform mediump sampler2D skeleton_texture; // texunit:-4
|
2018-05-04 14:32:40 +02:00
|
|
|
uniform highp mat4 skeleton_transform;
|
|
|
|
uniform highp mat4 skeleton_transform_inverse;
|
2018-05-03 22:29:15 +02:00
|
|
|
#endif
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
#ifdef USE_LIGHTING
|
|
|
|
|
|
|
|
layout(std140) uniform LightData { //ubo:1
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
// light matrices
|
2016-10-03 21:33:42 +02:00
|
|
|
highp mat4 light_matrix;
|
|
|
|
highp mat4 light_local_matrix;
|
|
|
|
highp mat4 shadow_matrix;
|
|
|
|
highp vec4 light_color;
|
|
|
|
highp vec4 light_shadow_color;
|
|
|
|
highp vec2 light_pos;
|
|
|
|
highp float shadowpixel_size;
|
|
|
|
highp float shadow_gradient;
|
|
|
|
highp float light_height;
|
|
|
|
highp float light_outside_alpha;
|
|
|
|
highp float shadow_distance_mult;
|
|
|
|
};
|
|
|
|
|
|
|
|
out vec4 light_uv_interp;
|
2018-07-05 11:12:04 +02:00
|
|
|
out vec2 transformed_light_uv;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
out vec4 local_rot;
|
2017-06-18 04:26:49 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
#ifdef USE_SHADOWS
|
|
|
|
out highp vec2 pos;
|
|
|
|
#endif
|
|
|
|
|
2017-06-12 16:32:59 +02:00
|
|
|
const bool at_light_pass = true;
|
|
|
|
#else
|
|
|
|
const bool at_light_pass = false;
|
2016-10-03 21:33:42 +02:00
|
|
|
#endif
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
#if defined(USE_MATERIAL)
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
2016-10-10 23:31:01 +02:00
|
|
|
layout(std140) uniform UniformData { //ubo:2
|
|
|
|
|
|
|
|
MATERIAL_UNIFORMS
|
|
|
|
|
|
|
|
};
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
|
|
|
|
2017-06-27 03:58:03 +02:00
|
|
|
VERTEX_SHADER_GLOBALS
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
void main() {
|
|
|
|
|
2017-09-29 23:56:05 +02:00
|
|
|
vec4 color = color_attrib;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-06-21 21:25:45 +02:00
|
|
|
#ifdef USE_INSTANCING
|
2018-09-18 22:54:03 +02:00
|
|
|
mat4 extra_matrix_instance = extra_matrix * transpose(mat4(instance_xform0, instance_xform1, instance_xform2, vec4(0.0, 0.0, 0.0, 1.0)));
|
2018-08-24 13:42:18 +02:00
|
|
|
color *= instance_color;
|
2019-06-03 00:09:02 +02:00
|
|
|
|
|
|
|
#ifdef USE_INSTANCE_CUSTOM
|
2017-09-29 23:56:05 +02:00
|
|
|
vec4 instance_custom = instance_custom_data;
|
2019-06-03 00:09:02 +02:00
|
|
|
#else
|
|
|
|
vec4 instance_custom = vec4(0.0);
|
|
|
|
#endif
|
2017-09-29 23:56:05 +02:00
|
|
|
|
2017-06-21 21:25:45 +02:00
|
|
|
#else
|
2018-09-18 22:54:03 +02:00
|
|
|
mat4 extra_matrix_instance = extra_matrix;
|
2017-09-29 23:56:05 +02:00
|
|
|
vec4 instance_custom = vec4(0.0);
|
2017-06-21 21:25:45 +02:00
|
|
|
#endif
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#ifdef USE_TEXTURE_RECT
|
|
|
|
|
2017-09-04 22:21:55 +02:00
|
|
|
if (dst_rect.z < 0.0) { // Transpose is encoded as negative dst_rect.z
|
2017-08-18 12:57:03 +02:00
|
|
|
uv_interp = src_rect.xy + abs(src_rect.zw) * vertex.yx;
|
|
|
|
} else {
|
|
|
|
uv_interp = src_rect.xy + abs(src_rect.zw) * vertex;
|
|
|
|
}
|
2018-08-24 13:42:18 +02:00
|
|
|
highp vec4 outvec = vec4(dst_rect.xy + abs(dst_rect.zw) * mix(vertex, vec2(1.0, 1.0) - vertex, lessThan(src_rect.zw, vec2(0.0, 0.0))), 0.0, 1.0);
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
uv_interp = uv_attrib;
|
2018-08-24 13:42:18 +02:00
|
|
|
highp vec4 outvec = vec4(vertex, 0.0, 1.0);
|
2016-10-03 21:33:42 +02:00
|
|
|
#endif
|
|
|
|
|
2018-11-13 18:19:16 +01:00
|
|
|
#ifdef USE_PARTICLES
|
|
|
|
//scale by texture size
|
|
|
|
outvec.xy /= color_texpixel_size;
|
|
|
|
#endif
|
|
|
|
|
2018-09-18 22:54:03 +02:00
|
|
|
#define extra_matrix extra_matrix_instance
|
2018-05-04 14:32:40 +02:00
|
|
|
|
2019-12-11 08:08:20 +01:00
|
|
|
float point_size = 1.0;
|
2018-12-13 07:48:30 +01:00
|
|
|
//for compatibility with the fragment shader we need to use uv here
|
|
|
|
vec2 uv = uv_interp;
|
2018-08-27 07:31:48 +02:00
|
|
|
{
|
|
|
|
/* clang-format off */
|
2018-05-04 14:32:40 +02:00
|
|
|
|
|
|
|
VERTEX_SHADER_CODE
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
|
|
|
}
|
2018-05-04 14:32:40 +02:00
|
|
|
|
2019-12-11 08:08:20 +01:00
|
|
|
gl_PointSize = point_size;
|
2018-12-13 07:48:30 +01:00
|
|
|
uv_interp = uv;
|
|
|
|
|
2018-05-04 14:32:40 +02:00
|
|
|
#ifdef USE_NINEPATCH
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
pixel_size_interp = abs(dst_rect.zw) * vertex;
|
2018-05-04 14:32:40 +02:00
|
|
|
#endif
|
|
|
|
|
2020-10-14 09:32:05 +02:00
|
|
|
#ifdef USE_ATTRIB_MODULATE
|
|
|
|
// modulate doesn't need interpolating but we need to send it to the fragment shader
|
|
|
|
modulate_interp = modulate_attrib;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_ATTRIB_LARGE_VERTEX
|
|
|
|
// transform is in attributes
|
|
|
|
vec2 temp;
|
|
|
|
|
|
|
|
temp = outvec.xy;
|
|
|
|
temp.x = (outvec.x * basis_attrib.x) + (outvec.y * basis_attrib.z);
|
|
|
|
temp.y = (outvec.x * basis_attrib.y) + (outvec.y * basis_attrib.w);
|
|
|
|
|
|
|
|
temp += translate_attrib;
|
|
|
|
outvec.xy = temp;
|
|
|
|
#endif
|
|
|
|
|
2018-05-04 14:32:40 +02:00
|
|
|
#if !defined(SKIP_TRANSFORM_USED)
|
|
|
|
outvec = extra_matrix * outvec;
|
|
|
|
outvec = modelview_matrix * outvec;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef extra_matrix
|
|
|
|
|
|
|
|
color_interp = color;
|
|
|
|
|
|
|
|
#ifdef USE_PIXEL_SNAP
|
2018-08-24 13:42:18 +02:00
|
|
|
outvec.xy = floor(outvec + 0.5).xy;
|
2019-03-04 08:25:35 +01:00
|
|
|
// precision issue on some hardware creates artifacts within texture
|
|
|
|
// offset uv by a small amount to avoid
|
|
|
|
uv_interp += 1e-5;
|
2018-05-04 14:32:40 +02:00
|
|
|
#endif
|
|
|
|
|
2018-05-03 22:29:15 +02:00
|
|
|
#ifdef USE_SKELETON
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
if (bone_weights != vec4(0.0)) { //must be a valid bone
|
2018-05-03 22:29:15 +02:00
|
|
|
//skeleton transform
|
|
|
|
|
|
|
|
ivec4 bone_indicesi = ivec4(bone_indices);
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
ivec2 tex_ofs = ivec2(bone_indicesi.x % 256, (bone_indicesi.x / 256) * 2);
|
2018-05-03 22:29:15 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
highp mat2x4 m;
|
|
|
|
m = mat2x4(
|
|
|
|
texelFetch(skeleton_texture, tex_ofs, 0),
|
2018-08-27 07:31:48 +02:00
|
|
|
texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0)) *
|
|
|
|
bone_weights.x;
|
2018-05-03 22:29:15 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
tex_ofs = ivec2(bone_indicesi.y % 256, (bone_indicesi.y / 256) * 2);
|
2018-05-03 22:29:15 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
m += mat2x4(
|
2018-08-27 07:31:48 +02:00
|
|
|
texelFetch(skeleton_texture, tex_ofs, 0),
|
|
|
|
texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0)) *
|
|
|
|
bone_weights.y;
|
2018-05-03 22:29:15 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
tex_ofs = ivec2(bone_indicesi.z % 256, (bone_indicesi.z / 256) * 2);
|
2018-05-03 22:29:15 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
m += mat2x4(
|
2018-08-27 07:31:48 +02:00
|
|
|
texelFetch(skeleton_texture, tex_ofs, 0),
|
|
|
|
texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0)) *
|
|
|
|
bone_weights.z;
|
2018-05-03 22:29:15 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
tex_ofs = ivec2(bone_indicesi.w % 256, (bone_indicesi.w / 256) * 2);
|
2018-05-03 22:29:15 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
m += mat2x4(
|
2018-08-27 07:31:48 +02:00
|
|
|
texelFetch(skeleton_texture, tex_ofs, 0),
|
|
|
|
texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0)) *
|
|
|
|
bone_weights.w;
|
2018-05-03 22:29:15 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
mat4 bone_matrix = skeleton_transform * transpose(mat4(m[0], m[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))) * skeleton_transform_inverse;
|
2018-05-03 22:29:15 +02:00
|
|
|
|
|
|
|
outvec = bone_matrix * outvec;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
gl_Position = projection_matrix * outvec;
|
|
|
|
|
|
|
|
#ifdef USE_LIGHTING
|
|
|
|
|
|
|
|
light_uv_interp.xy = (light_matrix * outvec).xy;
|
2018-08-24 13:42:18 +02:00
|
|
|
light_uv_interp.zw = (light_local_matrix * outvec).xy;
|
2018-07-05 11:12:04 +02:00
|
|
|
|
|
|
|
mat3 inverse_light_matrix = mat3(inverse(light_matrix));
|
|
|
|
inverse_light_matrix[0] = normalize(inverse_light_matrix[0]);
|
|
|
|
inverse_light_matrix[1] = normalize(inverse_light_matrix[1]);
|
|
|
|
inverse_light_matrix[2] = normalize(inverse_light_matrix[2]);
|
2018-08-24 13:42:18 +02:00
|
|
|
transformed_light_uv = (inverse_light_matrix * vec3(light_uv_interp.zw, 0.0)).xy; //for normal mapping
|
2018-07-05 11:12:04 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
#ifdef USE_SHADOWS
|
2018-08-24 13:42:18 +02:00
|
|
|
pos = outvec.xy;
|
2016-10-03 21:33:42 +02:00
|
|
|
#endif
|
|
|
|
|
2020-10-14 09:32:05 +02:00
|
|
|
#ifdef USE_ATTRIB_LIGHT_ANGLE
|
GLES3 fix normal map flipping with nvidia workaround
When not using TEXTURE_RECT path, flips have to sent via another method to the shader, to ensure that normal maps are correctly adjusted for direction. This PR adds an extra vertex attribute, LIGHT_ANGLE.
For nvidia workarounds, where the shader still has access to the final transform and extra matrix, the LIGHT_ANGLE can be 0 (no adjustment), 180 degrees for a horizontal flip, and negative indicates a vertical flip.
For batching path, the LIGHT_ANGLE can be used to directly specify the light angle for normal mapping, even when the final transform and extra matrix have been baked into vertex positions, so the same shader can be used for both.
2020-08-02 08:49:03 +02:00
|
|
|
// we add a fixed offset because we are using the sign later,
|
|
|
|
// and don't want floating point error around 0.0
|
|
|
|
float la = abs(light_angle) - 1.0;
|
|
|
|
|
|
|
|
// vector light angle
|
|
|
|
vec4 vla;
|
|
|
|
vla.xy = vec2(cos(la), sin(la));
|
|
|
|
vla.zw = vec2(-vla.y, vla.x);
|
|
|
|
vla.zw *= sign(light_angle);
|
|
|
|
|
|
|
|
// apply the transform matrix.
|
|
|
|
// The rotate will be encoded in the transform matrix for single rects,
|
|
|
|
// and just the flips in the light angle.
|
|
|
|
// For batching we will encode the rotation and the flips
|
|
|
|
// in the light angle, and can use the same shader.
|
|
|
|
local_rot.xy = normalize((modelview_matrix * (extra_matrix_instance * vec4(vla.xy, 0.0, 0.0))).xy);
|
|
|
|
local_rot.zw = normalize((modelview_matrix * (extra_matrix_instance * vec4(vla.zw, 0.0, 0.0))).xy);
|
|
|
|
#else
|
2018-09-18 22:54:03 +02:00
|
|
|
local_rot.xy = normalize((modelview_matrix * (extra_matrix_instance * vec4(1.0, 0.0, 0.0, 0.0))).xy);
|
|
|
|
local_rot.zw = normalize((modelview_matrix * (extra_matrix_instance * vec4(0.0, 1.0, 0.0, 0.0))).xy);
|
2016-10-03 21:33:42 +02:00
|
|
|
#ifdef USE_TEXTURE_RECT
|
2018-08-24 13:42:18 +02:00
|
|
|
local_rot.xy *= sign(src_rect.z);
|
|
|
|
local_rot.zw *= sign(src_rect.w);
|
2016-10-03 21:33:42 +02:00
|
|
|
#endif
|
GLES3 fix normal map flipping with nvidia workaround
When not using TEXTURE_RECT path, flips have to sent via another method to the shader, to ensure that normal maps are correctly adjusted for direction. This PR adds an extra vertex attribute, LIGHT_ANGLE.
For nvidia workarounds, where the shader still has access to the final transform and extra matrix, the LIGHT_ANGLE can be 0 (no adjustment), 180 degrees for a horizontal flip, and negative indicates a vertical flip.
For batching path, the LIGHT_ANGLE can be used to directly specify the light angle for normal mapping, even when the final transform and extra matrix have been baked into vertex positions, so the same shader can be used for both.
2020-08-02 08:49:03 +02:00
|
|
|
#endif // not using light angle
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
2016-10-03 21:33:42 +02:00
|
|
|
[fragment]
|
|
|
|
|
|
|
|
uniform mediump sampler2D color_texture; // texunit:0
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
2016-10-10 23:31:01 +02:00
|
|
|
uniform highp vec2 color_texpixel_size;
|
2017-06-18 04:26:49 +02:00
|
|
|
uniform mediump sampler2D normal_texture; // texunit:1
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2018-01-02 22:44:09 +01:00
|
|
|
in highp vec2 uv_interp;
|
2016-10-03 21:33:42 +02:00
|
|
|
in mediump vec4 color_interp;
|
|
|
|
|
2020-10-14 09:32:05 +02:00
|
|
|
#ifdef USE_ATTRIB_MODULATE
|
|
|
|
in mediump vec4 modulate_interp;
|
|
|
|
#endif
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
#if defined(SCREEN_TEXTURE_USED)
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
uniform sampler2D screen_texture; // texunit:-3
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-06-27 03:58:03 +02:00
|
|
|
#if defined(SCREEN_UV_USED)
|
|
|
|
|
|
|
|
uniform vec2 screen_pixel_size;
|
|
|
|
#endif
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
layout(std140) uniform CanvasItemData {
|
|
|
|
|
|
|
|
highp mat4 projection_matrix;
|
2017-06-16 13:29:43 +02:00
|
|
|
highp float time;
|
2016-10-10 23:31:01 +02:00
|
|
|
};
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
#ifdef USE_LIGHTING
|
|
|
|
|
|
|
|
layout(std140) uniform LightData {
|
|
|
|
|
|
|
|
highp mat4 light_matrix;
|
|
|
|
highp mat4 light_local_matrix;
|
|
|
|
highp mat4 shadow_matrix;
|
|
|
|
highp vec4 light_color;
|
|
|
|
highp vec4 light_shadow_color;
|
|
|
|
highp vec2 light_pos;
|
|
|
|
highp float shadowpixel_size;
|
|
|
|
highp float shadow_gradient;
|
|
|
|
highp float light_height;
|
|
|
|
highp float light_outside_alpha;
|
|
|
|
highp float shadow_distance_mult;
|
|
|
|
};
|
|
|
|
|
|
|
|
uniform lowp sampler2D light_texture; // texunit:-1
|
|
|
|
in vec4 light_uv_interp;
|
2018-07-05 11:12:04 +02:00
|
|
|
in vec2 transformed_light_uv;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
in vec4 local_rot;
|
2017-06-18 04:26:49 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
#ifdef USE_SHADOWS
|
|
|
|
|
|
|
|
uniform highp sampler2D shadow_texture; // texunit:-2
|
|
|
|
in highp vec2 pos;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-06-12 16:32:59 +02:00
|
|
|
const bool at_light_pass = true;
|
|
|
|
#else
|
|
|
|
const bool at_light_pass = false;
|
2016-10-03 21:33:42 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
uniform mediump vec4 final_modulate;
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
layout(location = 0) out mediump vec4 frag_color;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
#if defined(USE_MATERIAL)
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
2016-10-10 23:31:01 +02:00
|
|
|
layout(std140) uniform UniformData {
|
|
|
|
|
|
|
|
MATERIAL_UNIFORMS
|
|
|
|
|
|
|
|
};
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
|
|
|
|
2017-06-27 03:58:03 +02:00
|
|
|
FRAGMENT_SHADER_GLOBALS
|
2017-06-01 23:55:24 +02:00
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
|
|
|
|
2018-03-10 00:21:38 +01:00
|
|
|
void light_compute(
|
2018-08-24 13:42:18 +02:00
|
|
|
inout vec4 light,
|
|
|
|
inout vec2 light_vec,
|
|
|
|
inout float light_height,
|
|
|
|
inout vec4 light_color,
|
|
|
|
vec2 light_uv,
|
|
|
|
inout vec4 shadow_color,
|
2019-08-08 15:24:44 +02:00
|
|
|
inout vec2 shadow_vec,
|
2018-08-24 13:42:18 +02:00
|
|
|
vec3 normal,
|
|
|
|
vec2 uv,
|
2018-03-10 00:21:38 +01:00
|
|
|
#if defined(SCREEN_UV_USED)
|
2018-08-24 13:42:18 +02:00
|
|
|
vec2 screen_uv,
|
2018-03-10 00:21:38 +01:00
|
|
|
#endif
|
2018-08-24 13:42:18 +02:00
|
|
|
vec4 color) {
|
2017-06-01 23:55:24 +02:00
|
|
|
|
|
|
|
#if defined(USE_LIGHT_SHADER_CODE)
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
|
|
|
|
2017-06-01 23:55:24 +02:00
|
|
|
LIGHT_SHADER_CODE
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
|
|
|
|
2017-06-01 23:55:24 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-06-19 03:55:02 +02:00
|
|
|
#ifdef USE_TEXTURE_RECT
|
|
|
|
|
|
|
|
uniform vec4 dst_rect;
|
|
|
|
uniform vec4 src_rect;
|
|
|
|
uniform bool clip_rect_uv;
|
|
|
|
|
2017-06-22 04:37:25 +02:00
|
|
|
#ifdef USE_NINEPATCH
|
|
|
|
|
|
|
|
in highp vec2 pixel_size_interp;
|
|
|
|
|
|
|
|
uniform int np_repeat_v;
|
|
|
|
uniform int np_repeat_h;
|
|
|
|
uniform bool np_draw_center;
|
2018-08-24 13:42:18 +02:00
|
|
|
// left top right bottom in pixel coordinates
|
2017-06-22 04:37:25 +02:00
|
|
|
uniform vec4 np_margins;
|
|
|
|
|
2020-10-14 09:32:05 +02:00
|
|
|
float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, float margin_begin, float margin_end, int np_repeat, inout int draw_center) {
|
2017-06-22 04:37:25 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
float tex_size = 1.0 / tex_pixel_size;
|
2017-06-22 04:37:25 +02:00
|
|
|
|
2020-10-14 09:32:05 +02:00
|
|
|
if (pixel < margin_begin) {
|
|
|
|
return pixel * tex_pixel_size;
|
|
|
|
} else if (pixel >= draw_size - margin_end) {
|
|
|
|
return (tex_size - (draw_size - pixel)) * tex_pixel_size;
|
2017-06-22 04:37:25 +02:00
|
|
|
} else {
|
2018-08-24 13:42:18 +02:00
|
|
|
if (!np_draw_center) {
|
2017-06-22 04:37:25 +02:00
|
|
|
draw_center--;
|
|
|
|
}
|
|
|
|
|
2020-01-01 11:49:58 +01:00
|
|
|
// np_repeat is passed as uniform using NinePatchRect::AxisStretchMode enum.
|
|
|
|
if (np_repeat == 0) { // Stretch.
|
|
|
|
// Convert to ratio.
|
2020-10-14 09:32:05 +02:00
|
|
|
float ratio = (pixel - margin_begin) / (draw_size - margin_begin - margin_end);
|
2020-01-01 11:49:58 +01:00
|
|
|
// Scale to source texture.
|
2017-06-22 04:37:25 +02:00
|
|
|
return (margin_begin + ratio * (tex_size - margin_begin - margin_end)) * tex_pixel_size;
|
2020-01-01 11:49:58 +01:00
|
|
|
} else if (np_repeat == 1) { // Tile.
|
|
|
|
// Convert to offset.
|
2020-10-14 09:32:05 +02:00
|
|
|
float ofs = mod((pixel - margin_begin), tex_size - margin_begin - margin_end);
|
2020-01-01 11:49:58 +01:00
|
|
|
// Scale to source texture.
|
2017-06-22 04:37:25 +02:00
|
|
|
return (margin_begin + ofs) * tex_pixel_size;
|
2020-01-01 11:49:58 +01:00
|
|
|
} else if (np_repeat == 2) { // Tile Fit.
|
|
|
|
// Calculate scale.
|
2020-10-14 09:32:05 +02:00
|
|
|
float src_area = draw_size - margin_begin - margin_end;
|
2017-06-22 04:37:25 +02:00
|
|
|
float dst_area = tex_size - margin_begin - margin_end;
|
2018-08-24 13:42:18 +02:00
|
|
|
float scale = max(1.0, floor(src_area / max(dst_area, 0.0000001) + 0.5));
|
2020-01-01 11:49:58 +01:00
|
|
|
// Convert to ratio.
|
2020-10-14 09:32:05 +02:00
|
|
|
float ratio = (pixel - margin_begin) / src_area;
|
2018-08-24 13:42:18 +02:00
|
|
|
ratio = mod(ratio * scale, 1.0);
|
2020-01-01 11:49:58 +01:00
|
|
|
// Scale to source texture.
|
2017-06-22 04:37:25 +02:00
|
|
|
return (margin_begin + ratio * dst_area) * tex_pixel_size;
|
2020-01-01 11:49:58 +01:00
|
|
|
} else { // Shouldn't happen, but silences compiler warning.
|
2020-01-01 13:14:51 +01:00
|
|
|
return 0.0;
|
2017-06-22 04:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2017-06-19 03:55:02 +02:00
|
|
|
#endif
|
|
|
|
|
2017-06-18 04:26:49 +02:00
|
|
|
uniform bool use_default_normal;
|
2017-06-01 23:55:24 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
void main() {
|
|
|
|
|
|
|
|
vec4 color = color_interp;
|
2017-06-19 03:55:02 +02:00
|
|
|
vec2 uv = uv_interp;
|
2017-06-18 04:26:49 +02:00
|
|
|
|
2017-06-19 03:55:02 +02:00
|
|
|
#ifdef USE_TEXTURE_RECT
|
2017-06-22 04:37:25 +02:00
|
|
|
|
|
|
|
#ifdef USE_NINEPATCH
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
int draw_center = 2;
|
2017-06-22 04:37:25 +02:00
|
|
|
uv = vec2(
|
2020-10-14 09:32:05 +02:00
|
|
|
map_ninepatch_axis(pixel_size_interp.x, abs(dst_rect.z), color_texpixel_size.x, np_margins.x, np_margins.z, np_repeat_h, draw_center),
|
|
|
|
map_ninepatch_axis(pixel_size_interp.y, abs(dst_rect.w), color_texpixel_size.y, np_margins.y, np_margins.w, np_repeat_v, draw_center));
|
2017-06-22 04:37:25 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
if (draw_center == 0) {
|
|
|
|
color.a = 0.0;
|
2017-06-22 04:37:25 +02:00
|
|
|
}
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
uv = uv * src_rect.zw + src_rect.xy; //apply region if needed
|
2017-06-22 04:37:25 +02:00
|
|
|
#endif
|
|
|
|
|
2017-06-19 03:55:02 +02:00
|
|
|
if (clip_rect_uv) {
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
uv = clamp(uv, src_rect.xy, src_rect.xy + abs(src_rect.zw));
|
2017-06-19 03:55:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
#if !defined(COLOR_USED)
|
2018-08-24 13:42:18 +02:00
|
|
|
//default behavior, texture by color
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
#ifdef USE_DISTANCE_FIELD
|
2018-08-24 13:42:18 +02:00
|
|
|
const float smoothing = 1.0 / 32.0;
|
|
|
|
float distance = textureLod(color_texture, uv, 0.0).a;
|
2016-10-03 21:33:42 +02:00
|
|
|
color.a = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance) * color.a;
|
|
|
|
#else
|
2018-08-24 13:42:18 +02:00
|
|
|
color *= texture(color_texture, uv);
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
#endif
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-06-18 04:26:49 +02:00
|
|
|
vec3 normal;
|
|
|
|
|
|
|
|
#if defined(NORMAL_USED)
|
|
|
|
|
|
|
|
bool normal_used = true;
|
|
|
|
#else
|
|
|
|
bool normal_used = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (use_default_normal) {
|
2018-08-24 13:42:18 +02:00
|
|
|
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;
|
2017-06-18 04:26:49 +02:00
|
|
|
} else {
|
2018-08-24 13:42:18 +02:00
|
|
|
normal = vec3(0.0, 0.0, 1.0);
|
2017-06-18 04:26:49 +02:00
|
|
|
}
|
|
|
|
|
2017-06-27 03:58:03 +02:00
|
|
|
#if defined(SCREEN_UV_USED)
|
2018-08-24 13:42:18 +02:00
|
|
|
vec2 screen_uv = gl_FragCoord.xy * screen_pixel_size;
|
2016-10-03 21:33:42 +02:00
|
|
|
#endif
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
{
|
|
|
|
float normal_depth = 1.0;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
#if defined(NORMALMAP_USED)
|
2018-08-24 13:42:18 +02:00
|
|
|
vec3 normal_map = vec3(0.0, 0.0, 1.0);
|
2018-11-28 10:21:07 +01:00
|
|
|
normal_used = true;
|
2016-10-03 21:33:42 +02:00
|
|
|
#endif
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
FRAGMENT_SHADER_CODE
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
#if defined(NORMALMAP_USED)
|
2018-08-24 13:42:18 +02:00
|
|
|
normal = mix(vec3(0.0, 0.0, 1.0), normal_map * vec3(2.0, -2.0, 1.0) - vec3(1.0, -1.0, 0.0), normal_depth);
|
2016-10-03 21:33:42 +02:00
|
|
|
#endif
|
2018-08-24 13:42:18 +02:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
#ifdef DEBUG_ENCODED_32
|
2019-02-24 23:55:37 +01:00
|
|
|
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.0));
|
2018-08-24 13:42:18 +02:00
|
|
|
color = vec4(vec3(enc32), 1.0);
|
2016-10-03 21:33:42 +02:00
|
|
|
#endif
|
|
|
|
|
2020-05-03 02:55:14 +02:00
|
|
|
#if !defined(MODULATE_USED)
|
2018-08-24 13:42:18 +02:00
|
|
|
color *= final_modulate;
|
2020-05-03 02:55:14 +02:00
|
|
|
#endif
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2020-10-14 09:32:05 +02:00
|
|
|
#ifdef USE_ATTRIB_MODULATE
|
|
|
|
// todo .. this won't be used at the same time as MODULATE_USED
|
|
|
|
color *= modulate_interp;
|
|
|
|
#endif
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
#ifdef USE_LIGHTING
|
|
|
|
|
2018-07-05 11:12:04 +02:00
|
|
|
vec2 light_vec = transformed_light_uv;
|
2019-08-08 15:24:44 +02:00
|
|
|
vec2 shadow_vec = transformed_light_uv;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-06-18 04:26:49 +02:00
|
|
|
if (normal_used) {
|
2018-08-24 13:42:18 +02:00
|
|
|
normal.xy = mat2(local_rot.xy, local_rot.zw) * normal.xy;
|
2017-06-18 04:26:49 +02:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
float att = 1.0;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
vec2 light_uv = light_uv_interp.xy;
|
2018-08-24 13:42:18 +02:00
|
|
|
vec4 light = texture(light_texture, light_uv);
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
if (any(lessThan(light_uv_interp.xy, vec2(0.0, 0.0))) || any(greaterThanEqual(light_uv_interp.xy, vec2(1.0, 1.0)))) {
|
|
|
|
color.a *= light_outside_alpha; //invisible
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
} else {
|
2018-03-10 00:21:38 +01:00
|
|
|
float real_light_height = light_height;
|
|
|
|
vec4 real_light_color = light_color;
|
|
|
|
vec4 real_light_shadow_color = light_shadow_color;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#if defined(USE_LIGHT_SHADER_CODE)
|
2018-08-24 13:42:18 +02:00
|
|
|
//light is written by the light shader
|
2018-03-10 00:21:38 +01:00
|
|
|
light_compute(
|
2018-08-24 13:42:18 +02:00
|
|
|
light,
|
|
|
|
light_vec,
|
|
|
|
real_light_height,
|
|
|
|
real_light_color,
|
|
|
|
light_uv,
|
|
|
|
real_light_shadow_color,
|
2019-08-08 15:24:44 +02:00
|
|
|
shadow_vec,
|
2018-08-24 13:42:18 +02:00
|
|
|
normal,
|
|
|
|
uv,
|
2018-03-10 00:21:38 +01:00
|
|
|
#if defined(SCREEN_UV_USED)
|
2018-08-24 13:42:18 +02:00
|
|
|
screen_uv,
|
2018-03-10 00:21:38 +01:00
|
|
|
#endif
|
2018-08-24 13:42:18 +02:00
|
|
|
color);
|
2018-03-10 00:21:38 +01:00
|
|
|
#endif
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2018-03-10 00:21:38 +01:00
|
|
|
light *= real_light_color;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-06-18 04:26:49 +02:00
|
|
|
if (normal_used) {
|
2018-08-24 13:42:18 +02:00
|
|
|
vec3 light_normal = normalize(vec3(light_vec, -real_light_height));
|
|
|
|
light *= max(dot(-light_normal, normal), 0.0);
|
2017-06-18 04:26:49 +02:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
color *= light;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#ifdef USE_SHADOWS
|
2019-08-08 15:24:44 +02:00
|
|
|
#ifdef SHADOW_VEC_USED
|
|
|
|
mat3 inverse_light_matrix = mat3(light_matrix);
|
|
|
|
inverse_light_matrix[0] = normalize(inverse_light_matrix[0]);
|
|
|
|
inverse_light_matrix[1] = normalize(inverse_light_matrix[1]);
|
|
|
|
inverse_light_matrix[2] = normalize(inverse_light_matrix[2]);
|
|
|
|
shadow_vec = (mat3(inverse_light_matrix) * vec3(shadow_vec, 0.0)).xy;
|
|
|
|
#else
|
|
|
|
shadow_vec = light_uv_interp.zw;
|
|
|
|
#endif
|
|
|
|
float angle_to_light = -atan(shadow_vec.x, shadow_vec.y);
|
2016-10-03 21:33:42 +02:00
|
|
|
float PI = 3.14159265358979323846264;
|
|
|
|
/*int i = int(mod(floor((angle_to_light+7.0*PI/6.0)/(4.0*PI/6.0))+1.0, 3.0)); // +1 pq os indices estao em ordem 2,0,1 nos arrays
|
|
|
|
float ang*/
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
float su, sz;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
float abs_angle = abs(angle_to_light);
|
|
|
|
vec2 point;
|
|
|
|
float sh;
|
2018-08-24 13:42:18 +02:00
|
|
|
if (abs_angle < 45.0 * PI / 180.0) {
|
2019-08-08 15:24:44 +02:00
|
|
|
point = shadow_vec;
|
2018-08-24 13:42:18 +02:00
|
|
|
sh = 0.0 + (1.0 / 8.0);
|
|
|
|
} else if (abs_angle > 135.0 * PI / 180.0) {
|
2019-08-08 15:24:44 +02:00
|
|
|
point = -shadow_vec;
|
2018-08-24 13:42:18 +02:00
|
|
|
sh = 0.5 + (1.0 / 8.0);
|
|
|
|
} else if (angle_to_light > 0.0) {
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2019-08-08 15:24:44 +02:00
|
|
|
point = vec2(shadow_vec.y, -shadow_vec.x);
|
2018-08-24 13:42:18 +02:00
|
|
|
sh = 0.25 + (1.0 / 8.0);
|
2016-10-03 21:33:42 +02:00
|
|
|
} else {
|
|
|
|
|
2019-08-08 15:24:44 +02:00
|
|
|
point = vec2(-shadow_vec.y, shadow_vec.x);
|
2018-08-24 13:42:18 +02:00
|
|
|
sh = 0.75 + (1.0 / 8.0);
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
highp vec4 s = shadow_matrix * vec4(point, 0.0, 1.0);
|
|
|
|
s.xyz /= s.w;
|
|
|
|
su = s.x * 0.5 + 0.5;
|
|
|
|
sz = s.z * 0.5 + 0.5;
|
2016-10-03 21:33:42 +02:00
|
|
|
//sz=lightlength(light_vec);
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
highp float shadow_attenuation = 0.0;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#ifdef USE_RGBA_SHADOWS
|
|
|
|
|
2019-07-27 17:05:26 +02:00
|
|
|
#define SHADOW_DEPTH(m_tex, m_uv) dot(texture((m_tex), (m_uv)), vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0))
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
#define SHADOW_DEPTH(m_tex, m_uv) (texture((m_tex), (m_uv)).r)
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SHADOW_USE_GRADIENT
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
#define SHADOW_TEST(m_ofs) \
|
|
|
|
{ \
|
|
|
|
highp float sd = SHADOW_DEPTH(shadow_texture, vec2(m_ofs, sh)); \
|
|
|
|
shadow_attenuation += 1.0 - smoothstep(sd, sd + shadow_gradient, sz); \
|
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
#define SHADOW_TEST(m_ofs) \
|
|
|
|
{ \
|
|
|
|
highp float sd = SHADOW_DEPTH(shadow_texture, vec2(m_ofs, sh)); \
|
|
|
|
shadow_attenuation += step(sz, sd); \
|
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SHADOW_FILTER_NEAREST
|
|
|
|
|
2017-06-13 06:23:04 +02:00
|
|
|
SHADOW_TEST(su);
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SHADOW_FILTER_PCF3
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
SHADOW_TEST(su + shadowpixel_size);
|
2016-10-03 21:33:42 +02:00
|
|
|
SHADOW_TEST(su);
|
2018-08-24 13:42:18 +02:00
|
|
|
SHADOW_TEST(su - shadowpixel_size);
|
|
|
|
shadow_attenuation /= 3.0;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SHADOW_FILTER_PCF5
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
SHADOW_TEST(su + shadowpixel_size * 2.0);
|
|
|
|
SHADOW_TEST(su + shadowpixel_size);
|
2016-10-03 21:33:42 +02:00
|
|
|
SHADOW_TEST(su);
|
2018-08-24 13:42:18 +02:00
|
|
|
SHADOW_TEST(su - shadowpixel_size);
|
|
|
|
SHADOW_TEST(su - shadowpixel_size * 2.0);
|
|
|
|
shadow_attenuation /= 5.0;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-09-01 15:01:24 +02:00
|
|
|
#ifdef SHADOW_FILTER_PCF7
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
SHADOW_TEST(su + shadowpixel_size * 3.0);
|
|
|
|
SHADOW_TEST(su + shadowpixel_size * 2.0);
|
|
|
|
SHADOW_TEST(su + shadowpixel_size);
|
2017-09-01 15:01:24 +02:00
|
|
|
SHADOW_TEST(su);
|
2018-08-24 13:42:18 +02:00
|
|
|
SHADOW_TEST(su - shadowpixel_size);
|
|
|
|
SHADOW_TEST(su - shadowpixel_size * 2.0);
|
|
|
|
SHADOW_TEST(su - shadowpixel_size * 3.0);
|
|
|
|
shadow_attenuation /= 7.0;
|
2017-09-01 15:01:24 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
#ifdef SHADOW_FILTER_PCF9
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
SHADOW_TEST(su + shadowpixel_size * 4.0);
|
|
|
|
SHADOW_TEST(su + shadowpixel_size * 3.0);
|
|
|
|
SHADOW_TEST(su + shadowpixel_size * 2.0);
|
|
|
|
SHADOW_TEST(su + shadowpixel_size);
|
2016-10-03 21:33:42 +02:00
|
|
|
SHADOW_TEST(su);
|
2018-08-24 13:42:18 +02:00
|
|
|
SHADOW_TEST(su - shadowpixel_size);
|
|
|
|
SHADOW_TEST(su - shadowpixel_size * 2.0);
|
|
|
|
SHADOW_TEST(su - shadowpixel_size * 3.0);
|
|
|
|
SHADOW_TEST(su - shadowpixel_size * 4.0);
|
|
|
|
shadow_attenuation /= 9.0;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SHADOW_FILTER_PCF13
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
SHADOW_TEST(su + shadowpixel_size * 6.0);
|
|
|
|
SHADOW_TEST(su + shadowpixel_size * 5.0);
|
|
|
|
SHADOW_TEST(su + shadowpixel_size * 4.0);
|
|
|
|
SHADOW_TEST(su + shadowpixel_size * 3.0);
|
|
|
|
SHADOW_TEST(su + shadowpixel_size * 2.0);
|
|
|
|
SHADOW_TEST(su + shadowpixel_size);
|
2016-10-03 21:33:42 +02:00
|
|
|
SHADOW_TEST(su);
|
2018-08-24 13:42:18 +02:00
|
|
|
SHADOW_TEST(su - shadowpixel_size);
|
|
|
|
SHADOW_TEST(su - shadowpixel_size * 2.0);
|
|
|
|
SHADOW_TEST(su - shadowpixel_size * 3.0);
|
|
|
|
SHADOW_TEST(su - shadowpixel_size * 4.0);
|
|
|
|
SHADOW_TEST(su - shadowpixel_size * 5.0);
|
|
|
|
SHADOW_TEST(su - shadowpixel_size * 6.0);
|
|
|
|
shadow_attenuation /= 13.0;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
//color *= shadow_attenuation;
|
|
|
|
color = mix(real_light_shadow_color, color, shadow_attenuation);
|
2016-10-03 21:33:42 +02:00
|
|
|
//use shadows
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//use lighting
|
|
|
|
#endif
|
2018-08-24 13:42:18 +02:00
|
|
|
//color.rgb *= color.a;
|
2016-10-03 21:33:42 +02:00
|
|
|
frag_color = color;
|
|
|
|
}
|