evas: Evas_3D - refactor shader system.

Reviewers: Hermet, raster, jpeg, cedric

Subscribers: artem.popov, cedric

Differential Revision: https://phab.enlightenment.org/D1947

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
Dmytro Dadyka 2015-02-18 21:19:28 +01:00 committed by Cedric BAIL
parent 42912e6e44
commit b9b5ced501
20 changed files with 1554 additions and 1063 deletions

1
.gitignore vendored
View File

@ -67,4 +67,5 @@ tags
/config.rpath
/coverage
/src/lib/ecore_x/ecore_x_vsync
/src/modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x
Session.vim

View File

@ -586,6 +586,7 @@ modules/evas/engines/gl_common/evas_gl_api.c \
modules/evas/engines/gl_common/evas_gl_api_gles1.c \
modules/evas/engines/gl_common/evas_gl_api_ext.c \
modules/evas/engines/gl_common/shader/evas_gl_shaders.x \
modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x \
modules/evas/engines/gl_common/shader/evas_gl_enum.x
# 3D
@ -729,6 +730,35 @@ modules/evas/engines/gl_common/shader/evas_gl_shaders.x: modules/evas/engines/gl
modules/evas/engines/gl_common/shader/evas_gl_enum.x: modules/evas/engines/gl_common/shader/evas_gl_shaders.x
# NOTE: order here should be equal with modes in file Evas_Eo.h
GL_SHADERS_3D_GEN = \
modules/evas/engines/gl_common/shader_3d/vertex_color_vert.shd \
modules/evas/engines/gl_common/shader_3d/vertex_color_frag.shd \
modules/evas/engines/gl_common/shader_3d/diffuse_vert.shd \
modules/evas/engines/gl_common/shader_3d/diffuse_frag.shd \
modules/evas/engines/gl_common/shader_3d/flat_vert.shd \
modules/evas/engines/gl_common/shader_3d/flat_frag.shd \
modules/evas/engines/gl_common/shader_3d/phong_vert.shd \
modules/evas/engines/gl_common/shader_3d/phong_frag.shd \
modules/evas/engines/gl_common/shader_3d/normal_map_vert.shd \
modules/evas/engines/gl_common/shader_3d/normal_map_frag.shd \
modules/evas/engines/gl_common/shader_3d/shadow_map_vert.shd \
modules/evas/engines/gl_common/shader_3d/shadow_map_frag.shd \
modules/evas/engines/gl_common/shader_3d/color_pick_vert.shd \
modules/evas/engines/gl_common/shader_3d/color_pick_frag.shd \
$(NULL)
EXTRA_DIST += \
modules/evas/engines/gl_common/shader_3d/gen_shaders_3d.sh
BUILT_SOURCES += \
modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x
modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x: modules/evas/engines/gl_common/shader_3d/gen_shaders_3d.sh $(GL_SHADERS_3D_GEN)
@echo " SHADERS_3D $@"
@modules/evas/engines/gl_common/shader_3d/gen_shaders_3d.sh $(GL_SHADERS_3D_GEN)
GL_GENERIC_SOURCES = \
modules/evas/engines/gl_generic/evas_engine.c \
modules/evas/engines/gl_generic/Evas_Engine_GL_Generic.h

View File

@ -1144,13 +1144,10 @@ _mesh_draw_data_build(E3D_Draw_Data *data,
}
if (pdmesh->shadowed)
data->flags |= E3D_SHADER_FLAG_SHADOWED;
data->flags |= E3D_SHADER_FLAG_SHADOWED;
if (pdmesh->color_pick_enabled)
{
data->flags |= E3D_SHADER_FLAG_COLOR_PICK_ENABLED;
data->color_pick_key = pdmesh->color_pick_key;
}
data->color_pick_key = pdmesh->color_pick_key;
data->blending = pdmesh->blending;
data->blend_sfactor = pdmesh->blend_sfactor;

View File

@ -7,6 +7,7 @@ typedef struct _E3D_Program E3D_Program;
typedef struct _E3D_Draw_Data E3D_Draw_Data;
typedef unsigned long E3D_Shader_Flag;
// NOTE: order here should be equal with flag names in file evas_gl_3d_shader.c
#define E3D_SHADER_FLAG_NORMALIZE_NORMALS (1 << 0)
#define E3D_SHADER_FLAG_VERTEX_POSITION (1 << 1)
#define E3D_SHADER_FLAG_VERTEX_POSITION_BLEND (1 << 2)
@ -25,19 +26,19 @@ typedef unsigned long E3D_Shader_Flag;
#define E3D_SHADER_FLAG_DIFFUSE (1 << 15)
#define E3D_SHADER_FLAG_SPECULAR (1 << 16)
#define E3D_SHADER_FLAG_EMISSION (1 << 17)
#define E3D_SHADER_FLAG_DIFFUSE_TEXTURE (1 << 19)
#define E3D_SHADER_FLAG_AMBIENT_TEXTURE (1 << 20)
#define E3D_SHADER_FLAG_SPECULAR_TEXTURE (1 << 21)
#define E3D_SHADER_FLAG_EMISSION_TEXTURE (1 << 22)
#define E3D_SHADER_FLAG_NORMAL_TEXTURE (1 << 23)
#define E3D_SHADER_FLAG_DIFFUSE_TEXTURE_BLEND (1 << 24)
#define E3D_SHADER_FLAG_AMBIENT_TEXTURE_BLEND (1 << 25)
#define E3D_SHADER_FLAG_SPECULAR_TEXTURE_BLEND (1 << 26)
#define E3D_SHADER_FLAG_EMISSION_TEXTURE_BLEND (1 << 27)
#define E3D_SHADER_FLAG_NORMAL_TEXTURE_BLEND (1 << 28)
#define E3D_SHADER_FLAG_FOG_ENABLED (1 << 29)
#define E3D_SHADER_FLAG_SHADOWED (1 << 30)
#define E3D_SHADER_FLAG_COLOR_PICK_ENABLED (1 << 31)
#define E3D_SHADER_FLAG_DIFFUSE_TEXTURE (1 << 18)
#define E3D_SHADER_FLAG_AMBIENT_TEXTURE (1 << 19)
#define E3D_SHADER_FLAG_SPECULAR_TEXTURE (1 << 20)
#define E3D_SHADER_FLAG_EMISSION_TEXTURE (1 << 21)
#define E3D_SHADER_FLAG_NORMAL_TEXTURE (1 << 22)
#define E3D_SHADER_FLAG_DIFFUSE_TEXTURE_BLEND (1 << 23)
#define E3D_SHADER_FLAG_AMBIENT_TEXTURE_BLEND (1 << 24)
#define E3D_SHADER_FLAG_SPECULAR_TEXTURE_BLEND (1 << 25)
#define E3D_SHADER_FLAG_EMISSION_TEXTURE_BLEND (1 << 26)
#define E3D_SHADER_FLAG_NORMAL_TEXTURE_BLEND (1 << 27)
#define E3D_SHADER_FLAG_FOG_ENABLED (1 << 28)
#define E3D_SHADER_FLAG_SHADOWED (1 << 29)
#define E3D_SHADER_FLAG_COUNT 30
static inline Eina_Bool
_flags_need_tex_coord(E3D_Shader_Flag flags)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
uniform float uColorPick;
void main()
{
gl_FragColor = vec4(uColorPick);
}

View File

@ -0,0 +1,28 @@
uniform mat4 uMatrixMvp;
#ifdef VERTEX_POSITION
attribute vec4 aPosition0;
#endif //VERTEX_POSITION
#ifdef VERTEX_POSITION_BLEND
attribute vec4 aPosition1;
uniform float uPositionWeight;
#endif //VERTEX_POSITION_BLEND
void main()
{
#ifdef VERTEX_POSITION_BLEND
vec4 position = aPosition0 * uPositionWeight +
aPosition1 * (1.0 - uPositionWeight);
position = vec4(position.xyz, 1.0);
#else
#ifdef VERTEX_POSITION
vec4 position = vec4(aPosition0.xyz, 1.0);
#endif // VERTEX_POSITION
#endif //VERTEX_POSITION_BLEND
gl_Position = uMatrixMvp * position;
}

View File

@ -0,0 +1,47 @@
#ifdef NEED_TEX_COORD
varying vec2 vTexCoord;
#endif //TEX_COORD
#ifdef FOG_ENABLED
uniform float uFogFactor;
uniform vec4 uFogColor;
#endif //FOG_ENABLED
#ifdef DIFFUSE
uniform vec4 uMaterialDiffuse;
#ifdef DIFFUSE_TEXTURE
uniform sampler2D uTextureDiffuse0;
#endif //DIFFUSE_TEXTURE
#ifdef DIFFUSE_TEXTURE_BLEND
uniform sampler2D uTextureDiffuse1;
uniform float uTextureDiffuseWeight;
#endif //DIFFUSE_TEXTURE_BLEND
#endif //DIFFUSE
void main() {
#ifdef DIFFUSE_TEXTURE_BLEND
gl_FragColor = (texture2D(uTextureDiffuse0, vTexCoord) *
uTextureDiffuseWeight + texture2D(uTextureDiffuse1, vTexCoord) *
(1.0 - uTextureDiffuseWeight)) * uMaterialDiffuse;
#else
#ifdef DIFFUSE_TEXTURE
gl_FragColor = texture2D(uTextureDiffuse0, vTexCoord) * uMaterialDiffuse;
#else
gl_FragColor = uMaterialDiffuse;
#endif //DIFFUSE_TEXTURE
#endif //DIFFUSE_TEXTURE_BLEND
#ifdef FOG_ENABLED
float z = gl_FragCoord.z / gl_FragCoord.w;
float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);
fogFactor = clamp(fogFactor, 0.0, 1.0);
gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);
#endif //FOG_ENABLED
}

View File

@ -0,0 +1,52 @@
uniform mat4 uMatrixMvp;
#ifdef VERTEX_POSITION
attribute vec4 aPosition0;
#endif //VERTEX_POSITION
#ifdef VERTEX_POSITION_BLEND
attribute vec4 aPosition1;
uniform float uPositionWeight;
#endif //VERTEX_POSITION_BLEND
#ifdef VERTEX_TEXCOORD
attribute vec4 aTexCoord0;
#endif //VERTEX_TEXCOORD
#ifdef VERTEX_TEXCOORD_BLEND
attribute vec4 aTexCoord1;
uniform float uTexCoordWeight;
#endif //VERTEX_TEXCOORD_BLEND
#ifdef NEED_TEX_COORD
varying vec2 vTexCoord;
#endif //NEED_TEX_COORD
void main()
{
#ifdef VERTEX_POSITION_BLEND
vec4 position = aPosition0 * uPositionWeight +
aPosition1 * (1.0 - uPositionWeight);
position = vec4(position.xyz, 1.0);
#else
#ifdef VERTEX_POSITION
vec4 position = vec4(aPosition0.xyz, 1.0);
#endif // VERTEX_POSITION
#endif //VERTEX_POSITION_BLEND
#ifdef VERTEX_TEXCOORD_BLEND
vTexCoord = aTexCoord0.st * uTexCoordWeight +
aTexCoord1.st * (1.0 - uTexCoordWeight);
#else
#ifdef VERTEX_TEXCOORD
vTexCoord = aTexCoord0.st;
#endif //VERTEX_TEXCOORD
#endif //VERTEX_TEXCOORD_BLEND
gl_Position = uMatrixMvp * position;
}

View File

@ -0,0 +1,195 @@
varying vec2 vFactor;
#ifdef NEED_TEX_COORD
varying vec2 vTexCoord;
#endif //TEX_COORD
#ifdef FOG_ENABLED
uniform float uFogFactor;
uniform vec4 uFogColor;
#endif //FOG_ENABLED
#ifdef SHADOWED
varying vec4 vLightPosition;
uniform sampler2D uShadowMap;
float shadow;
#endif //SHADOWED
#ifdef DIFFUSE
uniform vec4 uMaterialDiffuse;
uniform vec4 uLightDiffuse;
#ifdef DIFFUSE_TEXTURE
uniform sampler2D uTextureDiffuse0;
#endif //DIFFUSE_TEXTURE
#ifdef DIFFUSE_TEXTURE_BLEND
uniform sampler2D uTextureDiffuse1;
uniform float uTextureDiffuseWeight;
#endif //DIFFUSE_TEXTURE_BLEND
#endif //DIFFUSE
#ifdef SPECULAR
uniform vec4 uLightSpecular;
uniform float uMaterialShininess;
uniform vec4 uMaterialSpecular;
#ifdef SPECULAR_TEXTURE
uniform sampler2D uTextureSpecular0;
#endif //SPECULAR_TEXTURE
#ifdef SPECULAR_TEXTURE_BLEND
uniform sampler2D uTextureSpecular1;
uniform float uTextureSpecularWeight;
#endif //SPECULAR_TEXTURE_BLEND
#endif //SPECULAR
#ifdef AMBIENT
uniform vec4 uMaterialAmbient;
uniform vec4 uLightAmbient;
#ifdef AMBIENT_TEXTURE
uniform sampler2D uTextureAmbient0;
#endif //AMBIENT_TEXTURE
#ifdef AMBIENT_TEXTURE_BLEND
uniform sampler2D uTextureAmbient1;
uniform float uTextureAmbientWeight;
#endif //AMBIENT_TEXTURE_BLEND
#endif //AMBIENT
#ifdef EMISSION
uniform vec4 uMaterialEmission;
#ifdef EMISSION_TEXTURE
uniform sampler2D uTextureEmission0;
#endif //EMISSION_TEXTURE
#ifdef EMISSION_TEXTURE_BLEND
uniform sampler2D uTextureEmission1;
uniform float uTextureEmissionWeight;
#endif //EMISSION_TEXTURE_BLEND
#endif //EMISSION
#ifdef SHADOWED
float pcf(vec4 lpos, float size)
{
vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;
float i, j, randx, randy, shadow;
shadow = 0.0;
for (i = -4.0; i < 4.0; i++)
for (j = -4.0; j < 4.0; j++)
shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy +vec2(i / 8.0, j / 8.0)*size).x);
return shadow / 64.0;
}
#endif //SHADOWED
void fragmentFlat()
{
vec4 color;
#ifdef DIFFUSE
#ifdef DIFFUSE_TEXTURE_BLEND
color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +
texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);
color *= uMaterialDiffuse;
#else
#ifdef DIFFUSE_TEXTURE
color = texture2D(uTextureDiffuse0, vTexCoord) * uMaterialDiffuse;
#else
color = uMaterialDiffuse;
#endif //DIFFUSE_TEXTURE
#endif //DIFFUSE_TEXTURE_BLEND
gl_FragColor = uLightDiffuse * color * vFactor.x;
#else
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
#endif //DIFFUSE
#ifdef SPECULAR
#ifdef SPECULAR_TEXTURE_BLEND
color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +
texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);
color *= uMaterialSpecular;
#else
#ifdef SPECULAR_TEXTURE
color = texture2D(uTextureSpecular0, vTexCoord) * uMaterialSpecular;
#else
color = uMaterialSpecular;
#endif //SPECULAR_TEXTURE
#endif //SPECULAR_TEXTURE_BLEND
gl_FragColor += uLightSpecular * color * vFactor.y;
#endif //SPECULAR
#ifdef SHADOWED
gl_FragColor *= shadow;
#endif //SHADOWED
#ifdef E3D_SHADER_FLAG_AMBIENT
#ifdef AMBIENT_TEXTURE_BLEND
color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +
texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);
color *= uMaterialAmbient;
#else
#ifdef AMBIENT_TEXTURE
color = texture2D(uTextureAmbient0, vTexCoord) * uMaterialAmbient;
#else
color = uMaterialAmbient;
#endif //AMBIENT_TEXTURE
#endif //AMBIENT_TEXTURE_BLEND
gl_FragColor += uLightAmbient * color;
#endif //AMBIENT
#ifdef EMISSION
#ifdef EMISSION_TEXTURE_BLEND
color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +
texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);
color *= uMaterialEmission;
#else
#ifdef EMISSION_TEXTURE
color = texture2D(uTextureEmission0, vTexCoord) * uMaterialEmission;
#else
color = uMaterialEmission;
#endif //EMISSION_TEXTURE
#endif //EMISSION_TEXTURE_BLEND
gl_FragColor += color;
#endif //EMISSION
}
void main() {
#ifdef SHADOWED
shadow = pcf(vLightPosition, 1.0 / 200.0);
#endif //SHADOWED
fragmentFlat();
#ifdef FOG_ENABLED
float z = gl_FragCoord.z / gl_FragCoord.w;
float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);
fogFactor = clamp(fogFactor, 0.0, 1.0);
gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);
#endif //FOG_ENABLED
}

View File

@ -0,0 +1,154 @@
uniform mat4 uMatrixMvp;
uniform mat3 uMatrixNormal;
uniform mat4 uMatrixModelview;
uniform vec4 uLightPosition;
varying vec2 vFactor;
#ifdef SHADOWED
uniform mat4 uMatrixLight;
varying vec4 vLightPosition;
#endif //SHADOWED
#ifdef VERTEX_POSITION
attribute vec4 aPosition0;
#endif //VERTEX_POSITION
#ifdef VERTEX_POSITION_BLEND
attribute vec4 aPosition1;
uniform float uPositionWeight;
#endif //VERTEX_POSITION_BLEND
#ifdef VERTEX_NORMAL
attribute vec4 aNormal0;
#endif //VERTEX_NORMAL
#ifdef VERTEX_NORMAL_BLEND
attribute vec4 aNormal1;
uniform float uNormalWeight;
#endif //VERTEX_NORMAL_BLEND
#ifdef VERTEX_TEXCOORD
attribute vec4 aTexCoord0;
#endif //VERTEX_TEXCOORD
#ifdef VERTEX_TEXCOORD_BLEND
attribute vec4 aTexCoord1;
uniform float uTexCoordWeight;
#endif //VERTEX_TEXCOORD_BLEND
#ifdef NEED_TEX_COORD
varying vec2 vTexCoord;
#endif //NEED_TEX_COORD
#ifdef LIGHT_SPOT
uniform vec3 uLightSpotDir;
uniform float uLightSpotExp;
uniform float uLightSpotCutoffCos;
#endif //LIGHT_SPOT
#ifdef SPECULAR
uniform float uMaterialShininess;
#endif //SPECULAR
#ifdef LIGHT_ATTENUATION
uniform vec3 uLightAtten;
#endif //LIGHT_ATTENUATION
void vertexFlat(vec4 position, vec3 normal)
{
vec3 lv;
float factor;
normal = uMatrixNormal * normal;
position = uMatrixModelview * position;
#ifdef NORMALIZE_NORMALS
normal = normalize(normal);
#endif //NORMALIZE_NORMALS
#ifdef LIGHT_DIRECTIONAL
lv = uLightPosition.xyz;
#else
lv = uLightPosition.xyz - position.xyz;
lv = normalize(lv);
#endif //LIGHT_DIRECTIONAL
factor = max(dot(lv, normal), 0.0);
#ifdef LIGHT_SPOT
float f = dot(-lv, uLightSpotDir);
if (f > uLightSpotCutoffCos)
factor *= pow(f, uLightSpotExp);
else
factor = 0.0;
#endif //LIGHT_SPOT
if (factor > 0.0)
{
#ifdef DIFFUSE
vFactor.x = factor;
#else
vFactor.x = 0.0;
#endif //DIFFUSE
#ifdef SPECULAR
vec3 hv = normalize(normalize(-position.xyz) + lv);
factor = pow(max(dot(hv, normal), 0.0), uMaterialShininess);
vFactor.y = factor;
#endif //SPECULAR
}
else
vFactor = vec2(0.0, 0.0);
/* Light attenuation. */
#ifdef LIGHT_ATTENUATION
float dist = length(lv);
vFactor /= dot(uLightAtten, vec3(1.0, dist, dist * dist));
#endif //LIGHT_ATTENUATION
}
void main()
{
#ifdef VERTEX_POSITION_BLEND
vec4 position = aPosition0 * uPositionWeight +
aPosition1 * (1.0 - uPositionWeight);
position = vec4(position.xyz, 1.0);
#else
#ifdef VERTEX_POSITION
vec4 position = vec4(aPosition0.xyz, 1.0);
#endif // VERTEX_POSITION
#endif //VERTEX_POSITION_BLEND
#ifdef VERTEX_NORMAL_BLEND
vec3 normal = aNormal0.xyz * uNormalWeight +
aNormal1.xyz * (1.0 - uNormalWeight);
#else
#ifdef VERTEX_NORMAL
vec3 normal = aNormal0.xyz;
#endif //VERTEX_NORMAL
#endif //VERTEX_NORMAL_BLEND
#ifdef VERTEX_TEXCOORD_BLEND
vTexCoord = aTexCoord0.st * uTexCoordWeight +
aTexCoord1.st * (1.0 - uTexCoordWeight);
#else
#ifdef VERTEX_TEXCOORD
vTexCoord = aTexCoord0.st;
#endif //VERTEX_TEXCOORD
#endif //VERTEX_TEXCOORD_BLEND
gl_Position = uMatrixMvp * position;
vertexFlat(position, normal);
#ifdef SHADOWED
vLightPosition = uMatrixLight * position;
#endif
}

View File

@ -0,0 +1,45 @@
#!/bin/bash
# This script will generate a C file containing all the shaders used by Evas_3D
DIR=`dirname $0`
OUTPUT=${DIR}/evas_gl_3d_shaders.x
exec 1<&-
exec 1>${OUTPUT}
SHADERS="$@"
vert_shaders_source=""
frag_shaders_source=""
# Write header
printf "/* DO NOT MODIFY THIS FILE AS IT IS AUTO-GENERATED\n * See: $0 */\n\n"
for shd in ${SHADERS} ; do
lname=`basename ${shd} .shd`
if echo ${lname} |grep _vert 2>&1 >> /dev/null ; then
vert_shaders_source="${vert_shaders_source} ${lname}_glsl,\n"
fi
if echo ${lname} |grep _frag 2>&1 >> /dev/null ; then
frag_shaders_source="${frag_shaders_source} ${lname}_glsl,\n"
fi
OIFS=$IFS
IFS=$'\n'
printf "static const char const ${lname}_glsl[] ="
for line in `cat ${shd}` ; do
printf "\n \"${line}\\\n\""
done
printf ";\n\n"
IFS=${OIFS}
done
printf "static const char *vertex_shaders[] =
{\n"
printf "${vert_shaders_source}"
printf "};\n\n"
printf "static const char *fragment_shaders[] =
{\n"
printf "${frag_shaders_source}"
printf "};\n"

View File

@ -0,0 +1,283 @@
varying vec3 vLightVector;
varying vec3 vLightHalfVector;
uniform sampler2D uTextureNormal0;
varying vec3 vEyeVector;
#ifdef NEED_TEX_COORD
varying vec2 vTexCoord;
#endif //TEX_COORD
#ifdef FOG_ENABLED
uniform float uFogFactor;
uniform vec4 uFogColor;
#endif //FOG_ENABLED
#ifdef SHADOWED
varying vec4 vLightPosition;
uniform sampler2D uShadowMap;
float shadow;
#endif //SHADOWED
#ifdef NORMAL_TEXTURE_BLEND
uniform sampler2D uTextureNormal1;
uniform float uTextureNormalWeight;
#endif //NORMAL_TEXTURE_BLEND
#ifndef VERTEX_TANGENT
varying vec3 vNormal;
#endif //VERTEX_TANGENT
#ifdef DIFFUSE
uniform vec4 uMaterialDiffuse;
uniform vec4 uLightDiffuse;
#ifdef DIFFUSE_TEXTURE
uniform sampler2D uTextureDiffuse0;
#endif //DIFFUSE_TEXTURE
#ifdef DIFFUSE_TEXTURE_BLEND
uniform sampler2D uTextureDiffuse1;
uniform float uTextureDiffuseWeight;
#endif //DIFFUSE_TEXTURE_BLEND
#endif //DIFFUSE
#ifdef SPECULAR
uniform vec4 uLightSpecular;
uniform float uMaterialShininess;
uniform vec4 uMaterialSpecular;
#ifdef SPECULAR_TEXTURE
uniform sampler2D uTextureSpecular0;
#endif //SPECULAR_TEXTURE
#ifdef SPECULAR_TEXTURE_BLEND
uniform sampler2D uTextureSpecular1;
uniform float uTextureSpecularWeight;
#endif //SPECULAR_TEXTURE_BLEND
#endif //SPECULAR
#ifdef AMBIENT
uniform vec4 uMaterialAmbient;
uniform vec4 uLightAmbient;
#ifdef AMBIENT_TEXTURE
uniform sampler2D uTextureAmbient0;
#endif //AMBIENT_TEXTURE
#ifdef AMBIENT_TEXTURE_BLEND
uniform sampler2D uTextureAmbient1;
uniform float uTextureAmbientWeight;
#endif //AMBIENT_TEXTURE_BLEND
#endif //AMBIENT
#ifdef EMISSION
uniform vec4 uMaterialEmission;
#ifdef EMISSION_TEXTURE
uniform sampler2D uTextureEmission0;
#endif //EMISSION_TEXTURE
#ifdef EMISSION_TEXTURE_BLEND
uniform sampler2D uTextureEmission1;
uniform float uTextureEmissionWeight;
#endif //EMISSION_TEXTURE_BLEND
#endif //EMISSION
#ifdef LIGHT_SPOT
uniform vec3 uLightSpotDir;
uniform float uLightSpotExp;
uniform float uLightSpotCutoffCos;
#endif //LIGHT_SPOT
#ifdef LIGHT_ATTENUATION
varying float vLightDist;
#endif //LIGHT_ATTENUATION
#ifndef VERTEX_TANGENT
mat3 cotangent_frame(vec3 n, vec3 p, vec2 uv)
{
vec3 dp1 = dFdx(p);
vec3 dp2 = dFdy(p);
vec2 duv1 = dFdx(uv);
vec2 duv2 = dFdy(uv);
vec3 dp2perp = cross(dp2, n);
vec3 dp1perp = cross(n, dp1);
vec3 t = dp2perp * duv1.x + dp1perp * duv2.x;
vec3 b = dp2perp * duv1.y + dp1perp * duv2.y;
float invmax = inversesqrt(max(dot(t, t), dot(b, b)));
return mat3(t * invmax, b * invmax, n);
}
vec3 perturb_normal(vec3 normal)
{
mat3 tbn = cotangent_frame(vNormal, -vEyeVector, vTexCoord);
return normalize(tbn * normal);
}
#endif //VERTEX_TANGENT
void fragmentNormalMap()
{
float factor;
vec3 normal;
vec4 color;
#ifdef NORMAL_TEXTURE_BLEND
normal = texture2D(uTextureNormal0, vTexCoord).rgb * uTextureNormalWeight;
normal += texture2D(uTextureNormal1, vTexCoord).rgb *
(1.0 - uTextureNormalWeight);
#else
normal = texture2D(uTextureNormal0, vTexCoord).rgb;
#endif //NORMAL_TEXTURE_BLEND
normal = 2.0 * normal - 1.0;
#ifndef VERTEX_TANGENT
normal = perturb_normal(normal);
#endif //VERTEX_TANGENT
vec3 lv = normalize(vLightVector);
normal = normalize(normal);
factor = dot(lv, normal);
#ifdef LIGHT_SPOT
float f = dot(-lv, normalize(uLightSpotDir));
if (f > uLightSpotCutoffCos)
factor *= pow(f, uLightSpotExp);
else
factor = 0.0;
#endif //LIGHT_SPOT
if (factor > 0.0)
{
#ifdef DIFFUSE
#ifdef DIFFUSE_TEXTURE_BLEND
color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +
texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);
#else
#ifdef DIFFUSE_TEXTURE
color = texture2D(uTextureDiffuse0, vTexCoord);
#else
color = uMaterialDiffuse;
#endif //DIFFUSE_TEXTURE
#endif //DIFFUSE_TEXTURE_BLEND
gl_FragColor = uLightDiffuse * color * factor;
#else
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
#endif //DIFFUSE
#ifdef SPECULAR
factor = dot(normalize(vLightHalfVector), normal);
if (factor > 0.0)
{
factor = pow(factor, uMaterialShininess);
#ifdef SPECULAR_TEXTURE_BLEND
color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +
texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);
#else
#ifdef SPECULAR_TEXTURE
color = texture2D(uTextureSpecular0, vTexCoord);
#else
color = uMaterialSpecular;
#endif //SPECULAR_TEXTURE
#endif //SPECULAR_TEXTURE_BLEND
gl_FragColor += uLightSpecular * color * factor;
}
#endif //SPECULAR
#ifdef SHADOWED
gl_FragColor *= shadow;
#endif //SHADOWED
}
else
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
#ifdef AMBIENT
#ifdef AMBIENT_TEXTURE_BLEND
color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +
texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);
#else
#ifdef AMBIENT_TEXTURE
color = texture2D(uTextureAmbient0, vTexCoord);
#else
color = uMaterialAmbient;
#endif //AMBIENT_TEXTURE
#endif //AMBIENT_TEXTURE_BLEND
gl_FragColor += uLightAmbient * color;
#endif //AMBIENT
#ifdef LIGHT_ATTENUATION
gl_FragColor /= dot(uLightAtten, vec3(1.0, vLightDist, vLightDist * vLightDist));
#endif //LIGHT_ATTENUATION
#ifdef EMISSION
#ifdef EMISSION_TEXTURE_BLEND
color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +
texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);
#else
#ifdef EMISSION_TEXTURE
color = texture2D(uTextureEmission0, vTexCoord);
#else
color = uMaterialEmission;
#endif //EMISSION_TEXTURE
#endif //EMISSION_TEXTURE_BLEND
gl_FragColor += color;
#endif //EMISSION
}
#ifdef SHADOWED
float pcf(vec4 lpos, float size)
{
vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;
float i, j, randx, randy, shadow;
shadow = 0.0;
for (i = -4.0; i < 4.0; i++)
for (j = -4.0; j < 4.0; j++)
shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy +vec2(i / 8.0, j / 8.0)*size).x);
return shadow / 64.0;
}
#endif //SHADOWED
void main() {
#ifdef SHADOWED
shadow = pcf(vLightPosition, 1.0 / 200.0);
#endif //SHADOWED
fragmentNormalMap();
#ifdef FOG_ENABLED
float z = gl_FragCoord.z / gl_FragCoord.w;
float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);
fogFactor = clamp(fogFactor, 0.0, 1.0);
gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);
#endif //FOG_ENABLED
}

View File

@ -0,0 +1,189 @@
uniform mat4 uMatrixMvp;
uniform mat3 uMatrixNormal;
uniform mat4 uMatrixModelview;
uniform vec4 uLightPosition;
varying vec3 vLightVector;
varying vec3 vLightHalfVector;
varying vec3 vEyeVector;
#ifndef VERTEX_TANGENT
varying vec3 vNormal;
#endif //VERTEX_TANGENT
#ifdef SHADOWED
uniform mat4 uMatrixLight;
varying vec4 vLightPosition;
#endif //SHADOWED
#ifdef VERTEX_POSITION
attribute vec4 aPosition0;
#endif //VERTEX_POSITION
#ifdef VERTEX_POSITION_BLEND
attribute vec4 aPosition1;
uniform float uPositionWeight;
#endif //VERTEX_POSITION_BLEND
#ifdef VERTEX_NORMAL
attribute vec4 aNormal0;
#endif //VERTEX_NORMAL
#ifdef VERTEX_NORMAL_BLEND
attribute vec4 aNormal1;
uniform float uNormalWeight;
#endif //VERTEX_NORMAL_BLEND
#ifdef VERTEX_TANGENT
attribute vec4 aTangent0;
#endif //VERTEX_TANGENT
#ifdef VERTEX_TANGENT_BLEND
attribute vec4 aTangent1;
uniform float uTangentWeight;
#endif //VERTEX_TANGENT_BLEND
#ifdef VERTEX_TEXCOORD
attribute vec4 aTexCoord0;
#endif //VERTEX_TEXCOORD
#ifdef VERTEX_TEXCOORD_BLEND
attribute vec4 aTexCoord1;
uniform float uTexCoordWeight;
#endif //VERTEX_TEXCOORD_BLEND
#ifdef NEED_TEX_COORD
varying vec2 vTexCoord;
#endif //NEED_TEX_COORD
#ifdef LIGHT_ATTENUATION
varying float vLightDist;
#endif //LIGHT_ATTENUATION
#ifndef VERTEX_TANGENT
void vertexNormalMap(vec4 position, vec3 normal)
{
normal = uMatrixNormal * normal;
position = uMatrixModelview * position;
vEyeVector = normalize(-position.xyz);
#ifdef NORMALIZE_NORMALS
normal = normalize(normal);
#endif //NORMALIZE_NORMALS
#ifdef LIGHT_DIRECTIONAL
vLightVector = uLightPosition.xyz;
#else
vLightVector = uLightPosition.xyz - position.xyz;
#ifdef LIGHT_ATTENUATION
vLightDist = length(vLightVector);
#endif //LIGHT_ATTENUATION
vLightVector = normalize(vLightVector);
#endif //LIGHT_DIRECTIONAL
vLightHalfVector = normalize(vEyeVector + vLightVector);
vNormal = normal;
}
#else
void vertexNormalMap(vec4 position, vec3 normal, vec3 tangent)
{
vec3 n = normalize(uMatrixNormal * normal);
vec3 t = normalize(uMatrixNormal * tangent);
vec3 b = cross(n, t);
vec3 tmp;
position = uMatrixModelview * position;
#ifdef LIGHT_DIRECTIONAL
vec3 lightDir = uLightPosition.xyz;
#else
vec3 lightDir = uLightPosition.xyz - position.xyz;
#ifdef LIGHT_ATTENUATION
vLightDist = length(lightDir);
#endif //LIGHT_ATTENUATION
lightDir = normalize(lightDir);
#endif //LIGHT_DIRECTIONAL
tmp.x = dot(lightDir, t);
tmp.y = dot(lightDir, b);
tmp.z = dot(lightDir, n);
vLightVector = tmp;
tmp.x = dot(position.xyz, t);
tmp.y = dot(position.xyz, b);
tmp.z = dot(position.xyz, n);
vEyeVector = normalize(tmp);
vec3 hv = normalize(normalize(-position.xyz) + lightDir);
tmp.x = dot(hv, t);
tmp.y = dot(hv, b);
tmp.z = dot(hv, n);
vLightHalfVector = tmp;
}
#endif //VERTEX_TANGENT
void main()
{
#ifdef VERTEX_POSITION_BLEND
vec4 position = aPosition0 * uPositionWeight +
aPosition1 * (1.0 - uPositionWeight);
position = vec4(position.xyz, 1.0);
#else
#ifdef VERTEX_POSITION
vec4 position = vec4(aPosition0.xyz, 1.0);
#endif // VERTEX_POSITION
#endif //VERTEX_POSITION_BLEND
#ifdef VERTEX_NORMAL_BLEND
vec3 normal = aNormal0.xyz * uNormalWeight +
aNormal1.xyz * (1.0 - uNormalWeight);
#else
#ifdef VERTEX_NORMAL
vec3 normal = aNormal0.xyz;
#endif //VERTEX_NORMAL
#endif //VERTEX_NORMAL_BLEND
#ifdef VERTEX_TANGENT_BLEND
vec3 tangent = aTangent0.xyz * uTangentWeight +
aTangent1.xyz * (1.0 - uTangentWeight);
#else
#ifdef VERTEX_TANGENT
vec3 tangent = aTangent0.xyz;
#endif //VERTEX_TANGENT
#endif //VERTEX_TANGENT_BLEND
#ifdef VERTEX_TEXCOORD_BLEND
vTexCoord = aTexCoord0.st * uTexCoordWeight +
aTexCoord1.st * (1.0 - uTexCoordWeight);
#else
#ifdef VERTEX_TEXCOORD
vTexCoord = aTexCoord0.st;
#endif //VERTEX_TEXCOORD
#endif //VERTEX_TEXCOORD_BLEND
gl_Position = uMatrixMvp * position;
#ifdef VERTEX_TANGENT
vertexNormalMap(position, normal, tangent);
#else
vertexNormalMap(position, normal);
#endif //VERTEX_TANGENT
#ifdef SHADOWED
vLightPosition = uMatrixLight * position;
#endif
}

View File

@ -0,0 +1,235 @@
varying vec3 vLightVector;
varying vec3 vLightHalfVector;
varying vec3 vNormal;
#ifdef NEED_TEX_COORD
varying vec2 vTexCoord;
#endif //TEX_COORD
#ifdef FOG_ENABLED
uniform float uFogFactor;
uniform vec4 uFogColor;
#endif //FOG_ENABLED
#ifdef SHADOWED
varying vec4 vLightPosition;
uniform sampler2D uShadowMap;
float shadow;
#endif //SHADOWED
#ifdef DIFFUSE
uniform vec4 uMaterialDiffuse;
uniform vec4 uLightDiffuse;
#ifdef DIFFUSE_TEXTURE
uniform sampler2D uTextureDiffuse0;
#endif //DIFFUSE_TEXTURE
#ifdef DIFFUSE_TEXTURE_BLEND
uniform sampler2D uTextureDiffuse1;
uniform float uTextureDiffuseWeight;
#endif //DIFFUSE_TEXTURE_BLEND
#endif //DIFFUSE
#ifdef SPECULAR
uniform vec4 uLightSpecular;
uniform float uMaterialShininess;
uniform vec4 uMaterialSpecular;
#ifdef SPECULAR_TEXTURE
uniform sampler2D uTextureSpecular0;
#endif //SPECULAR_TEXTURE
#ifdef SPECULAR_TEXTURE_BLEND
uniform sampler2D uTextureSpecular1;
uniform float uTextureSpecularWeight;
#endif //SPECULAR_TEXTURE_BLEND
#endif //SPECULAR
#ifdef AMBIENT
uniform vec4 uMaterialAmbient;
uniform vec4 uLightAmbient;
#ifdef AMBIENT_TEXTURE
uniform sampler2D uTextureAmbient0;
#endif //AMBIENT_TEXTURE
#ifdef AMBIENT_TEXTURE_BLEND
uniform sampler2D uTextureAmbient1;
uniform float uTextureAmbientWeight;
#endif //AMBIENT_TEXTURE_BLEND
#endif //AMBIENT
#ifdef EMISSION
uniform vec4 uMaterialEmission;
#ifdef EMISSION_TEXTURE
uniform sampler2D uTextureEmission0;
#endif //EMISSION_TEXTURE
#ifdef EMISSION_TEXTURE_BLEND
uniform sampler2D uTextureEmission1;
uniform float uTextureEmissionWeight;
#endif //EMISSION_TEXTURE_BLEND
#endif //EMISSION
#ifdef LIGHT_SPOT
uniform vec3 uLightSpotDir;
uniform float uLightSpotExp;
uniform float uLightSpotCutoffCos;
#endif //LIGHT_SPOT
#ifdef LIGHT_ATTENUATION
varying float vLightDist;
#endif //LIGHT_ATTENUATION
void fragmentPhong()
{
vec3 normal = normalize(vNormal);
vec3 lv = normalize(vLightVector);
float factor = dot(lv, normal);
vec4 color;
#ifdef LIGHT_SPOT
float f = dot(-lv, normalize(uLightSpotDir));
if (f > uLightSpotCutoffCos)
factor *= pow(f, uLightSpotExp);
else
factor = 0.0;
#endif //LIGHT_SPOT
if (factor > 0.0)
{
/* Diffuse term. */
#ifdef DIFFUSE
#ifdef DIFFUSE_TEXTURE_BLEND
color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +
texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);
#else
#ifdef DIFFUSE_TEXTURE
color = texture2D(uTextureDiffuse0, vTexCoord);
#else
color = uMaterialDiffuse;
#endif //DIFFUSE_TEXTURE
#endif //DIFFUSE_TEXTURE_BLEND
gl_FragColor = uLightDiffuse * color * factor;
#else
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
#endif //DIFFUSE
/* Specular term. */
#ifdef SPECULAR
factor = dot(normalize(vLightHalfVector), normal);
if (factor > 0.0)
{
factor = pow(factor, uMaterialShininess);
#ifdef SPECULAR_TEXTURE_BLEND
color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +
texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);
#else
#ifdef SPECULAR_TEXTURE
color = texture2D(uTextureSpecular0, vTexCoord);
#else
color = uMaterialSpecular;
#endif
#endif
gl_FragColor += uLightSpecular * color * factor;
}
#endif
}
else
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
#ifdef SHADOWED
gl_FragColor *= shadow;
#endif //SHADOWED
#ifdef AMBIENT
#ifdef AMBIENT_TEXTURE_BLEND
color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +
texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);
#else
#ifdef AMBIENT_TEXTURE
color = texture2D(uTextureAmbient0, vTexCoord);
#else
color = uMaterialAmbient;
#endif
#endif
gl_FragColor += uLightAmbient * color;
#endif
/* Light attenuation. */
#ifdef LIGHT_ATTENUATION
gl_FragColor /= dot(uLightAtten, vec3(1.0, vLightDist, vLightDist * vLightDist));
#endif
/* Emission term. */
#ifdef EMISSION
#ifdef EMISSION_TEXTURE_BLEND
color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +
texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);
#else
#ifdef EMISSION_TEXTURE
color = texture2D(uTextureEmission0, vTexCoord);
#else
color = uMaterialEmission;
#endif
#endif
gl_FragColor += color;
#endif
}
#ifdef SHADOWED
float pcf(vec4 lpos, float size)
{
vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;
float i, j, randx, randy, shadow;
shadow = 0.0;
for (i = -4.0; i < 4.0; i++)
for (j = -4.0; j < 4.0; j++)
shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy +vec2(i / 8.0, j / 8.0)*size).x);
return shadow / 64.0;
}
#endif //SHADOWED
void main()
{
#ifdef SHADOWED
shadow = pcf(vLightPosition, 1.0 / 300.0);
#endif //SHADOWED
fragmentPhong();
#ifdef FOG_ENABLED
float z = gl_FragCoord.z / gl_FragCoord.w;
float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);
fogFactor = clamp(fogFactor, 0.0, 1.0);
gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);
#endif //FOG_ENABLED
}

View File

@ -0,0 +1,116 @@
uniform mat4 uMatrixMvp;
uniform mat3 uMatrixNormal;
uniform mat4 uMatrixModelview;
uniform vec4 uLightPosition;
varying vec3 vLightVector;
varying vec3 vLightHalfVector;
varying vec3 vNormal;
#ifdef SHADOWED
uniform mat4 uMatrixLight;
varying vec4 vLightPosition;
#endif //SHADOWED
#ifdef VERTEX_POSITION
attribute vec4 aPosition0;
#endif //VERTEX_POSITION
#ifdef VERTEX_POSITION_BLEND
attribute vec4 aPosition1;
uniform float uPositionWeight;
#endif //VERTEX_POSITION_BLEND
#ifdef VERTEX_NORMAL
attribute vec4 aNormal0;
#endif //VERTEX_NORMAL
#ifdef VERTEX_NORMAL_BLEND
attribute vec4 aNormal1;
uniform float uNormalWeight;
#endif //VERTEX_NORMAL_BLEND
#ifdef VERTEX_TEXCOORD
attribute vec4 aTexCoord0;
#endif //VERTEX_TEXCOORD
#ifdef VERTEX_TEXCOORD_BLEND
attribute vec4 aTexCoord1;
uniform float uTexCoordWeight;
#endif //VERTEX_TEXCOORD_BLEND
#ifdef NEED_TEX_COORD
varying vec2 vTexCoord;
#endif //NEED_TEX_COORD
#ifdef LIGHT_ATTENUATION
varying float vLightDist;
#endif //LIGHT_ATTENUATION
void vertexPhong(vec4 position, vec3 normal)
{
normal = uMatrixNormal * normal;
position = uMatrixModelview * position;
#ifdef NORMALIZE_NORMALS
normal = normalize(normal);
#endif //NORMALIZE_NORMALS
#ifdef LIGHT_DIRECTIONAL
vLightVector = uLightPosition.xyz;
#else
vLightVector = uLightPosition.xyz - position.xyz;
#ifdef LIGHT_ATTENUATION
vLightDist = length(vLightVector);
#endif //LIGHT_ATTENUATION
vLightVector = normalize(vLightVector);
#endif //LIGHT_DIRECTIONAL
vLightHalfVector = normalize(normalize(-position.xyz) + vLightVector);
vNormal = normal;
}
void main() {
#ifdef VERTEX_POSITION_BLEND
vec4 position = aPosition0 * uPositionWeight +
aPosition1 * (1.0 - uPositionWeight);
position = vec4(position.xyz, 1.0);
#else
#ifdef VERTEX_POSITION
vec4 position = vec4(aPosition0.xyz, 1.0);
#endif // VERTEX_POSITION
#endif //VERTEX_POSITION_BLEND
#ifdef VERTEX_NORMAL_BLEND
vec3 normal = aNormal0.xyz * uNormalWeight +
aNormal1.xyz * (1.0 - uNormalWeight);
#else
#ifdef VERTEX_NORMAL
vec3 normal = aNormal0.xyz;
#endif //VERTEX_NORMAL
#endif //VERTEX_NORMAL_BLEND
#ifdef VERTEX_TEXCOORD_BLEND
vTexCoord = aTexCoord0.st * uTexCoordWeight +
aTexCoord1.st * (1.0 - uTexCoordWeight);
#else
#ifdef VERTEX_TEXCOORD
vTexCoord = aTexCoord0.st;
#endif //VERTEX_TEXCOORD
#endif //VERTEX_TEXCOORD_BLEND
gl_Position = uMatrixMvp * position;
vertexPhong(position, normal);
#ifdef SHADOWED
vLightPosition = uMatrixLight * position;
#endif //SHADOWED
}

View File

@ -0,0 +1,4 @@
void main()
{
gl_FragColor.r = gl_FragCoord.z;
}

View File

@ -0,0 +1,28 @@
uniform mat4 uMatrixMvp;
#ifdef VERTEX_POSITION
attribute vec4 aPosition0;
#endif //VERTEX_POSITION
#ifdef VERTEX_POSITION_BLEND
attribute vec4 aPosition1;
uniform float uPositionWeight;
#endif //VERTEX_POSITION_BLEND
void main()
{
#ifdef VERTEX_POSITION_BLEND
vec4 position = aPosition0 * uPositionWeight +
aPosition1 * (1.0 - uPositionWeight);
position = vec4(position.xyz, 1.0);
#else
#ifdef VERTEX_POSITION
vec4 position = vec4(aPosition0.xyz, 1.0);
#endif // VERTEX_POSITION
#endif //VERTEX_POSITION_BLEND
gl_Position = uMatrixMvp * position;
}

View File

@ -0,0 +1,20 @@
varying vec4 vColor;
#ifdef FOG_ENABLED
uniform float uFogFactor;
uniform vec4 uFogColor;
#endif //FOG_ENABLED
void main()
{
gl_FragColor = vColor;
#ifdef FOG_ENABLED
float z = gl_FragCoord.z / gl_FragCoord.w;
float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);
fogFactor = clamp(fogFactor, 0.0, 1.0);
gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);
#endif //FOG_ENABLED
}

View File

@ -0,0 +1,50 @@
uniform mat4 uMatrixMvp;
varying vec4 vColor;
#ifdef VERTEX_POSITION
attribute vec4 aPosition0;
#endif //VERTEX_POSITION
#ifdef VERTEX_POSITION_BLEND
attribute vec4 aPosition1;
uniform float uPositionWeight;
#endif //VERTEX_POSITION_BLEND
#ifdef VERTEX_COLOR
attribute vec4 aColor0;
#endif //VERTEX_COLOR
#ifdef VERTEX_COLOR_BLEND
attribute vec4 aColor1;
uniform float uColorWeight;
#endif //VERTEX_COLOR_BLEND
void main()
{
#ifdef VERTEX_POSITION_BLEND
vec4 position = aPosition0 * uPositionWeight +
aPosition1 * (1.0 - uPositionWeight);
position = vec4(position.xyz, 1.0);
#else
#ifdef VERTEX_POSITION
vec4 position = vec4(aPosition0.xyz, 1.0);
#endif // VERTEX_POSITION
#endif //VERTEX_POSITION_BLEND
#ifdef VERTEX_COLOR_BLEND
vec4 color = aColor0 * uColorWeight + aColor1 * (1.0 - uColorWeight);
#else
#ifdef VERTEX_COLOR
vec4 color = aColor0;
#endif //VERTEX_COLOR
#endif //VERTEX_COLOR_BLEND
vColor = color;
gl_Position = uMatrixMvp * position;
}