- Joined
- Feb 24, 2024
- Messages
- 141
- Reaction score
- 423
Disclaimer:
The shader files provided in this post are shared for educational and informational purposes only. They are intended to help developers and enthusiasts learn and enhance their skills in shader programming. By downloading or using these files, you agree to the following terms:
The shader files provided in this post are shared for educational and informational purposes only. They are intended to help developers and enthusiasts learn and enhance their skills in shader programming. By downloading or using these files, you agree to the following terms:
- Usage: These shader files are not to be used for any commercial purposes or integrated into any proprietary software without proper authorization. They are shared freely for personal use, learning, and experimentation.
- Ownership and Copyright: All intellectual property rights related to these shader files remain with their original creators. If these files were modified or enhanced, the modifications are shared under the same terms as the original files. Any original shader code remains the property of its respective authors.
- No Warranty: The files are provided "as is" without any warranties or guarantees. The poster does not guarantee that these files are free of errors, bugs, or vulnerabilities. Use them at your own risk.
- Liability: The poster is not liable for any damage, data loss, or issues arising from the use of these shader files. Users are responsible for ensuring that these files are compatible with their systems and for backing up any important data before use.
- Attribution: If you use or distribute these shader files, please give appropriate credit to the original authors. Do not remove or alter any copyright notices within the files.
- Compliance: Ensure that your use of these shader files complies with all applicable laws and regulations, as well as the terms and conditions of the platform you are using them with.
C-like:
precision highp float;
uniform mat4 uniform_world_matrix;
uniform mat4 uniform_view_matrix;
uniform mat4 uniform_project_matrix;
uniform vec2 uniform_flow_dir_0;
uniform vec2 uniform_flow_dir_1;
attribute vec4 attribute_position;
attribute vec2 attribute_texture_coord_0;
attribute vec2 attribute_texture_coord_1;
varying mediump vec2 varing_bumpmap_coord_0;
varying mediump vec2 varing_bumpmap_coord_1;
varying lowp vec3 varing_position_view;
void main()
{
vec4 pos = uniform_world_matrix * attribute_position;
gl_Position = uniform_project_matrix * (uniform_view_matrix * pos);
varing_bumpmap_coord_0 = attribute_texture_coord_0 + uniform_flow_dir_0;
varing_bumpmap_coord_1 = attribute_texture_coord_1 - uniform_flow_dir_1;
//varing_position_view = pos.xyz - uniform_eye_pos;
varing_position_view = vec3(0.074, -0.669, -0.739);
}
C-like:
precision lowp float;
uniform lowp sampler2D uniform_sampler_bumpmap;
uniform lowp vec4 uniform_water_color;
uniform lowp vec3 uniform_light;
varying mediump vec2 varing_bumpmap_coord_0;
varying mediump vec2 varing_bumpmap_coord_1;
varying lowp vec3 varing_position_view;
void main()
{
gl_FragColor = uniform_water_color;
vec3 normal = texture2D(uniform_sampler_bumpmap, varing_bumpmap_coord_0).xzy;
normal.xz = normal.xz + texture2D(uniform_sampler_bumpmap, varing_bumpmap_coord_1).xz - 1.0;
float black_face = -normal.x * 0.15 + 1.0;
gl_FragColor.rgb *= black_face;
vec3 reflect_vec = normalize(reflect(uniform_light, normal));
float spec = pow(max(dot(normalize(varing_position_view), -reflect_vec), 0.0), 30.0) * 0.45;
//spec -= max((gl_FragCoord.z - 0.9997) * 1200.0, 0.0);
gl_FragColor += clamp(spec, 0.0, 1.0);
gl_FragColor.a *= 0.76;
//gl_FragColor.a += max((gl_FragCoord.z - 0.9996) * 2000.0, 0.0);
//gl_FragColor.a += max((gl_FragCoord.z - 0.9996) * 1000.0, 0.0);
}
C-like:
precision highp float;
uniform mat4 uniform_main_matrix[4];
uniform vec2 uniform_shadow_pos;
uniform float uniform_shadow_size;
uniform float uniform_userheight;
uniform float uniform_shadowheight;
attribute mediump vec4 attribute_position;
attribute highp vec2 attribute_texture_coord_0;
attribute lowp vec4 attribute_diffuse;
varying lowp vec4 varing_diffuse;
varying mediump vec2 varing_texture_coord[MAX_TEXTURE_STAGE];
uniform mediump mat4 uniform_texture_coord_matrix[MAX_TEXTURE_STAGE];
varying highp vec3 varing_dynamic_shadow_coord;
varying lowp float shadow_height;
#ifdef SNAKE_ENABLE_MERGE_TERRAIN_TEXTURE
varying mediump float texture_number;
#endif
void main()
{
vec4 pos = uniform_main_matrix[0] * attribute_position;
vec4 pos2 = uniform_main_matrix[1] * pos;
gl_Position = uniform_main_matrix[2] * pos2;
float shadow_length = CalcShadowHeight(pos.y - uniform_userheight) * uniform_shadowheight;
float shadow_start = uniform_shadow_size / 2.0;
varing_dynamic_shadow_coord.z = CalcHeightMap(pos.y) - 0.02;
varing_dynamic_shadow_coord.y = pos.z - uniform_shadow_pos.y + shadow_start - shadow_length;
varing_dynamic_shadow_coord.x = pos.x - uniform_shadow_pos.x + shadow_start - shadow_length;
varing_dynamic_shadow_coord.xy /= uniform_shadow_size;
varing_diffuse.rgba = attribute_diffuse.bgra;
#ifdef SNAKE_ENABLE_MERGE_TERRAIN_TEXTURE
texture_number = floor(attribute_texture_coord_0.y / TERRAIN_TEXTURE_INDEX_BASE);
varing_texture_coord[0].x = attribute_texture_coord_0.x;
varing_texture_coord[0].y = attribute_texture_coord_0.y - texture_number * TERRAIN_TEXTURE_INDEX_BASE;
#else
varing_texture_coord[0] = attribute_texture_coord_0;
#endif
varing_texture_coord[1] = (uniform_texture_coord_matrix[1] * (pos2)).xy * 0.0001;
shadow_height = uniform_shadowheight;//알수없는이유로 uniform을 픽셀쉐이더에서 그냥쓰면 갤럭시기기에서 안됨;;
}
C-like:
precision lowp float;
uniform lowp sampler2D uniform_sampler[MAX_TEXTURE_STAGE];
varying lowp vec4 varing_diffuse;
varying mediump vec2 varing_texture_coord[MAX_TEXTURE_STAGE];
uniform int uniform_texture_stage;
uniform lowp float uniform_color_op[MAX_TEXTURE_STAGE * MAX_TEXTURE_STAGE_OP];
uniform lowp float uniform_color_arg1[MAX_TEXTURE_STAGE * MAX_TEXTURE_STAGE_ARG];
uniform lowp float uniform_color_arg2[MAX_TEXTURE_STAGE * MAX_TEXTURE_STAGE_ARG];
uniform lowp float uniform_alpha_op[MAX_TEXTURE_STAGE * MAX_TEXTURE_STAGE_OP];
uniform lowp float uniform_alpha_arg1[MAX_TEXTURE_STAGE * MAX_TEXTURE_STAGE_ARG];
uniform lowp float uniform_alpha_arg2[MAX_TEXTURE_STAGE * MAX_TEXTURE_STAGE_ARG];
uniform lowp vec4 uniform_texture_factor;
varying lowp float shadow_height;
uniform lowp sampler2D uniform_sampler_dynamic_shadow;
varying highp vec3 varing_dynamic_shadow_coord;
#ifdef SNAKE_ENABLE_MERGE_TERRAIN_TEXTURE
uniform highp float uniform_texture_count;
varying mediump float texture_number;
#endif
float CalcShadow(in highp vec2 bias)
{
if(varing_dynamic_shadow_coord.x + bias.x < 0.0 || varing_dynamic_shadow_coord.x + bias.x > 1.0
|| varing_dynamic_shadow_coord.y + bias.y < 0.0 || varing_dynamic_shadow_coord.y + bias.y > 1.0)
{
return 0.0;
}
vec4 tex = texture2D(uniform_sampler_dynamic_shadow, varing_dynamic_shadow_coord.xy + bias);
float height = unpack(tex);
if(shadow_height > 0.0)
{
float diff = height - varing_dynamic_shadow_coord.z;
return (sign(diff) + 1.0) / 2.6 * (1.0 - tex.a);
}
if(height > 0.0)
{
return 1.0 - tex.a;
}
return 0.0;
}
float CalcShadow2(in highp float bias)
{
if (varing_dynamic_shadow_coord.x < 0.0 || varing_dynamic_shadow_coord.x > 1.0
|| varing_dynamic_shadow_coord.y < 0.0 || varing_dynamic_shadow_coord.y > 1.0)
{
return 0.0;
}
vec4 tex0 = texture2D(uniform_sampler_dynamic_shadow, varing_dynamic_shadow_coord.xy + vec2(0.0, 0.0));
vec4 tex1 = texture2D(uniform_sampler_dynamic_shadow, varing_dynamic_shadow_coord.xy + vec2(0.0, -bias));
vec4 tex2 = texture2D(uniform_sampler_dynamic_shadow, varing_dynamic_shadow_coord.xy + vec2(0.0, bias));
vec4 tex3 = texture2D(uniform_sampler_dynamic_shadow, varing_dynamic_shadow_coord.xy + vec2(-bias, 0.0));
vec4 tex4 = texture2D(uniform_sampler_dynamic_shadow, varing_dynamic_shadow_coord.xy + vec2(bias, 0.0));
float height0 = unpack(tex0);
float height1 = unpack(tex1);
float height2 = unpack(tex2);
float height3 = unpack(tex3);
float height4 = unpack(tex4);
if (shadow_height > 0.0)
{
float diff;
diff = height0 - varing_dynamic_shadow_coord.z;
height0 = (sign(diff) + 1.0) * (1.0 - tex0.a);
diff = height1 - varing_dynamic_shadow_coord.z;
height1 = (sign(diff) + 1.0) * (1.0 - tex1.a);
diff = height2 - varing_dynamic_shadow_coord.z;
height2 = (sign(diff) + 1.0) * (1.0 - tex2.a);
diff = height3 - varing_dynamic_shadow_coord.z;
height3 = (sign(diff) + 1.0) * (1.0 - tex3.a);
diff = height4 - varing_dynamic_shadow_coord.z;
height4 = (sign(diff) + 1.0) * (1.0 - tex4.a);
return (height0 + height1 + height2 + height3 + height4) / 2.6 / 5.0;
}
float result = 0.0;
if (height0 > 0.0)
{
result += 1.0 - tex0.a;
}
if (height1 > 0.0)
{
result += 1.0 - tex1.a;
}
if (height2 > 0.0)
{
result += 1.0 - tex2.a;
}
if (height3 > 0.0)
{
result += 1.0 - tex3.a;
}
if (height4 > 0.0)
{
result += 1.0 - tex4.a;
}
return result / 5.0;
}
void main()
{
#ifdef SNAKE_ENABLE_MERGE_TERRAIN_TEXTURE
float t1fract = fract(varing_texture_coord[0].y);
float ty = (t1fract + (texture_number * (TERRAIN_TEXTURE_SIZE + 4.0) + 2.0) / TERRAIN_TEXTURE_SIZE) / uniform_texture_count;
vec4 color_texture = texture2D(uniform_sampler[0], vec2(varing_texture_coord[0].x, ty));
#else
vec4 color_texture = texture2D(uniform_sampler[0], varing_texture_coord[0]);
#endif
float alpha1 =
uniform_alpha_arg1[1] * color_texture.a +
uniform_alpha_arg1[2] * uniform_texture_factor.a;
float alpha2 =
uniform_alpha_arg2[0] * varing_diffuse.a +
uniform_alpha_arg2[2] * uniform_texture_factor.a;
gl_FragColor.a = varing_diffuse.a;
vec3 color1 = uniform_color_arg1[1] * color_texture.rgb
+ uniform_color_arg1[2] * uniform_texture_factor.rgb;
vec3 color2 = uniform_color_arg2[0] * varing_diffuse.rgb
+ uniform_color_arg2[2] * uniform_texture_factor.rgb
+ uniform_color_arg2[3] * color_texture.a;
gl_FragColor.rgb =
uniform_color_op[0] * color1 +
uniform_color_op[4] * color1 * color2;
color_texture = texture2D(uniform_sampler[1], varing_texture_coord[1]);
vec4 color1_all =
uniform_color_arg1[MAX_TEXTURE_STAGE_ARG + 0] * gl_FragColor +
uniform_color_arg1[MAX_TEXTURE_STAGE_ARG + 1] * color_texture;
color1 = color1_all.rgb;
color2 =
uniform_color_arg2[MAX_TEXTURE_STAGE_ARG + 0] * gl_FragColor.rgb +
uniform_color_arg2[MAX_TEXTURE_STAGE_ARG + 1] * color_texture.rgb +
uniform_color_arg2[MAX_TEXTURE_STAGE_ARG + 2] * uniform_texture_factor.rgb;
float coef1 =
uniform_color_op[MAX_TEXTURE_STAGE_OP + 0] * 1.0 +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 5] * color_texture.a +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 6] * gl_FragColor.a;
float coef2 =
uniform_color_op[MAX_TEXTURE_STAGE_OP + 1] * 1.0 +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 10] * (1.0 - color_texture.a) +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 6] * (1.0 - gl_FragColor.a) +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 8] * (1.0 - uniform_texture_factor.a) +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 7] * (color1_all.a) +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 9] * (1.0 - color1_all.a);
gl_FragColor.rgb =
uniform_color_op[MAX_TEXTURE_STAGE_OP + 3] *
(
coef1 * color1
+ coef2 * color2
+ uniform_color_op[MAX_TEXTURE_STAGE_OP + 2]
)
+ uniform_color_op[MAX_TEXTURE_STAGE_OP + 4] * color1 * color2
+ uniform_color_op[MAX_TEXTURE_STAGE_OP + 12] * (color1 * color2 + color1_all.a)
+ uniform_color_op[MAX_TEXTURE_STAGE_OP + 13] * ((1.0 - color1) * color2 + color1_all.a);
alpha1 =
uniform_alpha_arg1[MAX_TEXTURE_STAGE_ARG + 0] * gl_FragColor.a +
uniform_alpha_arg1[MAX_TEXTURE_STAGE_ARG + 1] * color_texture.a;
alpha2 =
uniform_alpha_arg2[MAX_TEXTURE_STAGE_ARG + 0] * gl_FragColor.a +
uniform_alpha_arg2[MAX_TEXTURE_STAGE_ARG + 1] * color_texture.a;
gl_FragColor.a =
uniform_alpha_op[MAX_TEXTURE_STAGE_OP + 3] *
(
uniform_alpha_op[MAX_TEXTURE_STAGE_OP + 0] * alpha1 +
uniform_alpha_op[MAX_TEXTURE_STAGE_OP + 1] * alpha2 +
uniform_alpha_op[MAX_TEXTURE_STAGE_OP + 2]
) +
uniform_alpha_op[4] * alpha1 * alpha2;
/*
const float bias = 1.0 / 2048.0;
float shadow = CalcShadow(vec2(0, 0));
shadow += CalcShadow(vec2(bias, 0));
shadow += CalcShadow(vec2(-bias, 0));
shadow += CalcShadow(vec2(0, bias));
shadow += CalcShadow(vec2(0, -bias));
shadow /= 5.0;
shadow = shadow * shadow * (1.0 - GetBrightness(gl_FragColor.rgb));
gl_FragColor.rgb *= 1.0 - shadow;
*/
const float bias = 1.0 / 2048.0;
float shadow = CalcShadow2(bias);
shadow = shadow * shadow * (1.0 - GetBrightness(gl_FragColor.rgb));
gl_FragColor.rgb *= 1.0 - shadow;
}
C-like:
precision highp float;
uniform mat4 uniform_main_matrix;// [4];
uniform int uniform_vertex_blend;
uniform mat4 uniform_bone_matrix[MAX_BONE_MATRIX];
uniform vec3 uniform_light;
uniform vec2 uniform_shadow_pos;
uniform float uniform_shadow_size;
uniform float uniform_userheight;
uniform float uniform_shadowheight;
attribute vec4 attribute_position;
attribute mediump vec2 attribute_texture_coord_0;
attribute float attribute_bone_id;
varying float vHeight;
varying lowp float shadow_height;
varying mediump vec2 texture_coord;
void main()
{
vec4 pos;
if (uniform_vertex_blend != 0)
{
pos = uniform_bone_matrix[int(attribute_bone_id)] * attribute_position /** attribute_weight*/;
}
else
{
pos = uniform_main_matrix * attribute_position;
}
texture_coord = attribute_texture_coord_0;
float shadow_length = CalcShadowHeight(pos.y - uniform_userheight) * uniform_shadowheight;
gl_Position.z = (pos.y + 500.0) * 0.1;
gl_Position.y = pos.z - uniform_shadow_pos.y - shadow_length;
gl_Position.x = pos.x - uniform_shadow_pos.x - shadow_length;
gl_Position.w = uniform_shadow_size / 2.0;
vHeight = CalcHeightMap(pos.y);
shadow_height = uniform_shadowheight;//알수없는이유로 uniform을 픽셀쉐이더에서 그냥쓰면 갤럭시기기에서 안됨;;
}
C-like:
uniform lowp float uniform_alpha_test;
uniform lowp sampler2D uniform_sampler_shadow;
precision highp float;
varying mediump vec2 texture_coord;
varying highp float vHeight;
varying lowp float shadow_height;
void main()
{
float alpha = texture2D(uniform_sampler_shadow, texture_coord).a;
if(shadow_height > 0.0)
{
if (alpha < uniform_alpha_test)
{
gl_FragColor.a = 0.0;
discard;
return;
}
else
{
gl_FragColor.a = 1.0;
}
}
else
{
gl_FragColor.a = alpha * alpha;
}
float temp = vHeight;
gl_FragColor.b = fract(temp);
temp = (temp - gl_FragColor.b) * 0.1;
gl_FragColor.g = fract(temp);
temp = (temp - gl_FragColor.g) * 0.1;
gl_FragColor.r = fract(temp);
}
C-like:
const lowp float STATIC_SHADOW_SIZE = 25600.0;
const lowp float HEIGHTMAP_HELPER = 2000.0;
const lowp float HEIGHTMAP_BIAS = 0.001 * HEIGHTMAP_HELPER;
const lowp float HEIGHTMAP_TERRAIN_BIAS = 0.03 * HEIGHTMAP_HELPER;
//hsb
highp float GetBrightness(highp vec3 RGB)
{
return (max(max(RGB.x, RGB.y), RGB.z)) * 0.4 + 0.3;
}
//shadow
highp float unpack(highp vec4 color)
{
return color.r * 100.0 + color.g * 10.0 + color.b;
}
highp float CalcShadowHeight(highp float y)
{
return (y + 500.0) * 0.707;
}
highp float CalcHeightMap(highp float height)
{
return (height + 500.0) / 64.0;
}
//lighting
highp float WorldLight(highp float light_val)
{
return max(light_val + 0.5, 0.5);
}
highp float LobbyLight(highp float light_val)
{
if (0.0 < light_val)
{
return 1.0 + light_val;
}
else if (-0.5 < light_val)
{
return 1.0 + light_val * 0.6;
}
else
{
return 0.7 + -(0.5 + light_val) * 1.3;
}
}
//etc
highp mat3 MyTranspose(highp mat4 inMat)
{
highp mat3 outMat = mat3(
vec3(inMat[0].x, inMat[1].x, inMat[2].x),
vec3(inMat[0].y, inMat[1].y, inMat[2].y),
vec3(inMat[0].z, inMat[1].z, inMat[2].z)
);
return outMat;
}
highp mat3 MyInverse(highp mat4 m)
{
highp float a00 = m[0].x, a01 = m[0].y, a02 = m[0].z;
highp float a10 = m[1].x, a11 = m[1].y, a12 = m[1].z;
highp float a20 = m[2].x, a21 = m[2].y, a22 = m[2].z;
highp float b01 = a22 * a11 - a12 * a21;
highp float b11 = -a22 * a10 + a12 * a20;
highp float b21 = a21 * a10 - a11 * a20;
highp float det = a00 * b01 + a01 * b11 + a02 * b21;
return mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11),
b11, (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10),
b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;
}
C-like:
precision highp float;
uniform lowp int uniform_shader_type;
uniform lowp vec3 uniform_light;
uniform vec2 uniform_shadow_pos;
uniform float uniform_shadow_size;
uniform float uniform_userheight;
uniform float uniform_shadowheight;
uniform mat4 uniform_main_matrix[4];
// 0 - world
// 1 - view
// 2 - project
// 3 - inverse(view * world)
uniform int uniform_vertex_blend;
uniform mat4 uniform_bone_matrix[MAX_BONE_MATRIX];
uniform lowp float uniform_texture_coord_index[MAX_TEXTURE_STAGE * MAX_TEXTURE_COORD_INDEX];
uniform mat4 uniform_texture_coord_matrix[MAX_TEXTURE_STAGE];
uniform lowp float uniform_outline;
#ifndef SNAKE_DISABLE_CLIPPING_PLANE
uniform vec4 uniform_clipping_plane;
#endif
attribute vec4 attribute_position;
attribute mediump vec2 attribute_texture_coord_0;
attribute mediump vec2 attribute_texture_coord_1;
attribute vec3 attribute_normal;
#ifdef MACOSX_ENABLE_MAXIMUM_BONE_SUPPORT
attribute lowp vec4 attribute_bone_id;
attribute vec4 attribute_weight;
#else
attribute lowp float attribute_bone_id;
#endif //MACOSX_ENABLE_MAXIMUM_BONE_SUPPORT
attribute lowp vec4 attribute_diffuse;
attribute mat4 attribute_instance_mats;
varying lowp vec4 varing_diffuse;
varying highp vec2 varing_texture_coord[MAX_TEXTURE_STAGE];
varying highp vec3 varing_dynamic_shadow_coord;
varying lowp float shadow_height;
varying lowp float varing_light;
varying lowp float varing_specular;
void main()
{
vec4 pos;
mat4 worldMat;
mat3 invMatrix;
if (uniform_shader_type == 3)
{
worldMat = attribute_instance_mats;
invMatrix = mat3(MyInverse(uniform_main_matrix[1] * attribute_instance_mats));
}
else
{
worldMat = uniform_main_matrix[0];
invMatrix = mat3(uniform_main_matrix[3]);
}
if (uniform_vertex_blend != 0)
{
#ifdef MACOSX_ENABLE_MAXIMUM_BONE_SUPPORT
mat4 skin;
skin = uniform_bone_matrix[int(attribute_bone_id.x)] * attribute_weight.x
+ uniform_bone_matrix[int(attribute_bone_id.y)] * attribute_weight.y
+ uniform_bone_matrix[int(attribute_bone_id.z)] * attribute_weight.z
+ uniform_bone_matrix[int(attribute_bone_id.w)] * attribute_weight.w;
gl_Position =
uniform_main_matrix[2] *
(uniform_main_matrix[1] *
(skin * (attribute_position + vec4(normalize(attribute_normal) * uniform_outline * 1.5, 0.0))));
#else
gl_Position =
uniform_main_matrix[2] *
(uniform_main_matrix[1] *
(uniform_bone_matrix[int(attribute_bone_id)] * (attribute_position + vec4(normalize(attribute_normal) * uniform_outline * 1.5, 0.0))/* * attribute_weight*/));
#endif
pos = uniform_bone_matrix[int(attribute_bone_id)] * (attribute_position + vec4(normalize(attribute_normal) * uniform_outline * 1.5, 0.0));
}
else
{
pos = worldMat * (attribute_position + vec4(normalize(attribute_normal) * uniform_outline * 1.5, 0.0));
gl_Position = uniform_main_matrix[2] * (uniform_main_matrix[1] * pos);
}
vec4 position_view = uniform_main_matrix[1] * (worldMat * (attribute_position + vec4(normalize(attribute_normal) * uniform_outline * 1.5, 0.0)));
varing_diffuse.rgba = attribute_diffuse.bgra;
vec3 reflect_view;
if(length(position_view.xyz) > 0.0)
{
reflect_view = reflect(normalize(position_view.xyz), normalize(attribute_normal * invMatrix));
}
varing_texture_coord[0] =
(uniform_texture_coord_matrix[0] *
(
uniform_texture_coord_index[0] * vec4(attribute_texture_coord_0, 1, 1)
+ uniform_texture_coord_index[3] * vec4(reflect_view, 1)
)).xy;
varing_texture_coord[1] =
(uniform_texture_coord_matrix[1] *
(
uniform_texture_coord_index[MAX_TEXTURE_COORD_INDEX + 0] * vec4(attribute_texture_coord_0, 1, 1)
+ uniform_texture_coord_index[MAX_TEXTURE_COORD_INDEX + 1] * vec4(attribute_texture_coord_1, 1, 1)
+ uniform_texture_coord_index[MAX_TEXTURE_COORD_INDEX + 2] * position_view * 0.0001
+ uniform_texture_coord_index[MAX_TEXTURE_COORD_INDEX + 3] * vec4(reflect_view, 1)
)).xy;
#ifndef SNAKE_DISABLE_CLIPPING_PLANE
gl_ClipDistance[0] = dot(inverse(uniform_main_matrix[2] * uniform_main_matrix[1]) * gl_Position, uniform_clipping_plane);
#endif
varing_specular = 0.0;
varing_light = 1.0;
if (uniform_shader_type != 0)
{
vec3 normal = normalize(normalize(attribute_normal) * MyTranspose(uniform_main_matrix[0]));
float light_val = dot(normal, -uniform_light);
if (uniform_shader_type == 1) // lobby light
{
if (0.0 < light_val)
{
float rDotV = max(0.0, dot(vec3(0.0, 0.0, 1.0), reflect_view));
varing_specular = 1.0 * pow(rDotV, 5.0);
}
varing_diffuse.rgb *= LobbyLight(light_val);
varing_diffuse.g *= 0.92;
varing_diffuse.r *= 0.95;
}
else// if (uniform_shader_type == 2) // world light
{
varing_light = WorldLight(light_val);
}
}
float shadow_length = CalcShadowHeight(pos.y - uniform_userheight) * uniform_shadowheight;
float shadow_start = uniform_shadow_size / 2.0;
varing_dynamic_shadow_coord.z = CalcHeightMap(pos.y) - 0.02;
varing_dynamic_shadow_coord.y = pos.z - uniform_shadow_pos.y + shadow_start - shadow_length;
varing_dynamic_shadow_coord.x = pos.x - uniform_shadow_pos.x + shadow_start - shadow_length;
varing_dynamic_shadow_coord.xy /= uniform_shadow_size;
shadow_height = uniform_shadowheight;//알수없는이유로 uniform을 픽셀쉐이더에서 그냥쓰면 갤럭시기기에서 안됨;;
}
C-like:
precision lowp float;
uniform lowp sampler2D uniform_sampler[MAX_TEXTURE_STAGE];
uniform lowp float uniform_alpha_test;
uniform int uniform_texture_stage;
uniform lowp float uniform_color_op[MAX_TEXTURE_STAGE * MAX_TEXTURE_STAGE_OP];
uniform lowp float uniform_color_arg1[MAX_TEXTURE_STAGE * MAX_TEXTURE_STAGE_ARG];
uniform lowp float uniform_color_arg2[MAX_TEXTURE_STAGE * MAX_TEXTURE_STAGE_ARG];
uniform lowp float uniform_alpha_op[MAX_TEXTURE_STAGE * MAX_TEXTURE_STAGE_OP];
uniform lowp float uniform_alpha_arg1[MAX_TEXTURE_STAGE * MAX_TEXTURE_STAGE_ARG];
uniform lowp float uniform_alpha_arg2[MAX_TEXTURE_STAGE * MAX_TEXTURE_STAGE_ARG];
uniform lowp vec4 uniform_texture_factor;
varying lowp vec4 varing_diffuse;
varying highp vec2 varing_texture_coord[MAX_TEXTURE_STAGE];
varying lowp vec3 varing_normal;
uniform lowp vec3 uniform_light;
varying lowp vec3 varing_reflect;
varying lowp float varing_specular;
uniform int uniform_shader_type;
varying lowp float varing_light;
uniform lowp float uniform_outline;
uniform lowp float uniform_stepable_shadow;
uniform lowp float uniform_disable_item;
varying lowp float shadow_height;
uniform lowp sampler2D uniform_sampler_dynamic_shadow;
varying highp vec3 varing_dynamic_shadow_coord;
float CalcShadow(vec2 bias)
{
if(varing_dynamic_shadow_coord.x + bias.x < 0.0 || varing_dynamic_shadow_coord.x + bias.x > 1.0
|| varing_dynamic_shadow_coord.y + bias.y < 0.0 || varing_dynamic_shadow_coord.y + bias.y > 1.0)
{
return 0.0;
}
vec4 tex = texture2D(uniform_sampler_dynamic_shadow, varing_dynamic_shadow_coord.xy + bias);
float height = unpack(tex);
if(shadow_height > 0.0)
{
float diff = height - varing_dynamic_shadow_coord.z;
return (sign(diff) + 1.0) / 2.6 * (1.0 - tex.a);
}
if(height > 0.0)
{
return 1.0 - tex.a;
}
return 0.0;
}
float CalcShadow2(in highp float bias)
{
if (varing_dynamic_shadow_coord.x < 0.0 || varing_dynamic_shadow_coord.x > 1.0
|| varing_dynamic_shadow_coord.y < 0.0 || varing_dynamic_shadow_coord.y > 1.0)
{
return 0.0;
}
vec4 tex0 = texture2D(uniform_sampler_dynamic_shadow, varing_dynamic_shadow_coord.xy + vec2(0.0, 0.0));
vec4 tex1 = texture2D(uniform_sampler_dynamic_shadow, varing_dynamic_shadow_coord.xy + vec2(0.0, -bias));
vec4 tex2 = texture2D(uniform_sampler_dynamic_shadow, varing_dynamic_shadow_coord.xy + vec2(0.0, bias));
vec4 tex3 = texture2D(uniform_sampler_dynamic_shadow, varing_dynamic_shadow_coord.xy + vec2(-bias, 0.0));
vec4 tex4 = texture2D(uniform_sampler_dynamic_shadow, varing_dynamic_shadow_coord.xy + vec2(bias, 0.0));
float height0 = unpack(tex0);
float height1 = unpack(tex1);
float height2 = unpack(tex2);
float height3 = unpack(tex3);
float height4 = unpack(tex4);
if (shadow_height > 0.0)
{
float diff;
diff = height0 - varing_dynamic_shadow_coord.z;
height0 = (sign(diff) + 1.0) * (1.0 - tex0.a);
diff = height1 - varing_dynamic_shadow_coord.z;
height1 = (sign(diff) + 1.0) * (1.0 - tex1.a);
diff = height2 - varing_dynamic_shadow_coord.z;
height2 = (sign(diff) + 1.0) * (1.0 - tex2.a);
diff = height3 - varing_dynamic_shadow_coord.z;
height3 = (sign(diff) + 1.0) * (1.0 - tex3.a);
diff = height4 - varing_dynamic_shadow_coord.z;
height4 = (sign(diff) + 1.0) * (1.0 - tex4.a);
return (height0 + height1 + height2 + height3 + height4) / 2.6 / 5.0;
}
float result = 0.0;
if (height0 > 0.0)
{
result += 1.0 - tex0.a;
}
if (height1 > 0.0)
{
result += 1.0 - tex1.a;
}
if (height2 > 0.0)
{
result += 1.0 - tex2.a;
}
if (height3 > 0.0)
{
result += 1.0 - tex3.a;
}
if (height4 > 0.0)
{
result += 1.0 - tex4.a;
}
return result / 5.0;
}
void main()
{
vec4 color_texture = texture2D(uniform_sampler[0], varing_texture_coord[0]);
float alpha1 =
uniform_alpha_arg1[1] * color_texture.a +
uniform_alpha_arg1[2] * uniform_texture_factor.a;
float alpha2 =
uniform_alpha_arg2[0] * varing_diffuse.a +
uniform_alpha_arg2[2] * uniform_texture_factor.a;
gl_FragColor.a =
uniform_alpha_op[0] * alpha1 +
uniform_alpha_op[4] * alpha1 * alpha2;
if (gl_FragColor.a <= uniform_alpha_test)
{
discard;
}
vec3 color1 = uniform_color_arg1[1] * color_texture.rgb
+ uniform_color_arg1[2] * uniform_texture_factor.rgb;
vec3 color2 = uniform_color_arg2[0] * varing_diffuse.rgb
+ uniform_color_arg2[2] * uniform_texture_factor.rgb
+ uniform_color_arg2[3] * color_texture.a;
gl_FragColor.rgb =
uniform_color_op[0] * color1 +
uniform_color_op[4] * color1 * color2;
if (uniform_texture_stage >= 2)
{
color_texture = texture2D(uniform_sampler[1], varing_texture_coord[1]);
vec4 color1_all =
uniform_color_arg1[MAX_TEXTURE_STAGE_ARG + 0] * gl_FragColor +
uniform_color_arg1[MAX_TEXTURE_STAGE_ARG + 1] * color_texture;
vec3 color1 = color1_all.rgb;
vec3 color2 =
uniform_color_arg2[MAX_TEXTURE_STAGE_ARG + 0] * gl_FragColor.rgb +
uniform_color_arg2[MAX_TEXTURE_STAGE_ARG + 1] * color_texture.rgb +
uniform_color_arg2[MAX_TEXTURE_STAGE_ARG + 2] * uniform_texture_factor.rgb;
float coef1 =
uniform_color_op[MAX_TEXTURE_STAGE_OP + 0] * 1.0 +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 5] * color_texture.a +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 6] * gl_FragColor.a +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 14] * varing_diffuse.a;
float coef2 =
uniform_color_op[MAX_TEXTURE_STAGE_OP + 1] * 1.0 +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 10] * (1.0 - color_texture.a) +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 6] * (1.0 - gl_FragColor.a) +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 8] * (1.0 - uniform_texture_factor.a) +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 7] * (color1_all.a) +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 9] * (1.0 - color1_all.a) +
uniform_color_op[MAX_TEXTURE_STAGE_OP + 14] * (1.0 - varing_diffuse.a);
gl_FragColor.rgb =
uniform_color_op[MAX_TEXTURE_STAGE_OP + 3] *
(
coef1 * color1
+ coef2 * color2
+ uniform_color_op[MAX_TEXTURE_STAGE_OP + 2]
)
+ uniform_color_op[MAX_TEXTURE_STAGE_OP + 4] * color1 * color2
+ uniform_color_op[MAX_TEXTURE_STAGE_OP + 12] * (color1 * color2 + color1_all.a)
+ uniform_color_op[MAX_TEXTURE_STAGE_OP + 13] * ((1.0 - color1) * color2 + color1_all.a);
float alpha1 =
uniform_alpha_arg1[MAX_TEXTURE_STAGE_ARG + 0] * gl_FragColor.a +
uniform_alpha_arg1[MAX_TEXTURE_STAGE_ARG + 1] * color_texture.a;
float alpha2 =
uniform_alpha_arg2[MAX_TEXTURE_STAGE_ARG + 0] * gl_FragColor.a +
uniform_alpha_arg2[MAX_TEXTURE_STAGE_ARG + 1] * color_texture.a;
gl_FragColor.a =
uniform_alpha_op[MAX_TEXTURE_STAGE_OP + 3] *
(
uniform_alpha_op[MAX_TEXTURE_STAGE_OP + 0] * alpha1 +
uniform_alpha_op[MAX_TEXTURE_STAGE_OP + 1] * alpha2 +
uniform_alpha_op[MAX_TEXTURE_STAGE_OP + 2]
) +
uniform_alpha_op[4] * alpha1 * alpha2;
if (gl_FragColor.a <= uniform_alpha_test)
{
discard;
}
}
if(uniform_stepable_shadow > 0.0)
{
/*
const float bias = 1.0 / 2048.0;
float shadow = CalcShadow(vec2(0, 0));
shadow += CalcShadow(vec2(bias, 0));
shadow += CalcShadow(vec2(-bias, 0));
shadow += CalcShadow(vec2(0, bias));
shadow += CalcShadow(vec2(0, -bias));
shadow /= 5.0;
shadow = shadow * shadow * (1.0 - GetBrightness(gl_FragColor.rgb));
gl_FragColor.rgb *= 1.0 - shadow;
*/
const float bias = 1.0 / 2048.0;
float shadow = CalcShadow2(bias);
shadow = shadow * shadow * (1.0 - GetBrightness(gl_FragColor.rgb));
gl_FragColor.rgb *= 1.0 - shadow;
}
if(uniform_disable_item > 0.0)
{
float maxColor = (gl_FragColor.r + gl_FragColor.g + gl_FragColor.b) / 3.0;
gl_FragColor.rgb += (maxColor - gl_FragColor.rgb) * 1.0;
gl_FragColor.a *= 0.5;
}
gl_FragColor = (1.0 - uniform_outline) * gl_FragColor + (vec4(1.0, 0.0, 0.0, gl_FragColor.a) * uniform_outline);
}
Last edited:

