[Evas: Evas_3D] Refactor shaders: used m4 for removing duplication of code.
Reviewers: Hermet, raster, cedric, jpeg Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2076
This commit is contained in:
parent
5bc4b89115
commit
1bf3ca03f7
|
@ -466,7 +466,7 @@ static const char const phong_vert_glsl[] =
|
|||
" vNormal = normal;\n"
|
||||
"}\n"
|
||||
"void main() {\n"
|
||||
"#ifdef VERTEX_POSITION_BLEND\n"
|
||||
" #ifdef VERTEX_POSITION_BLEND\n"
|
||||
" vec4 position = aPosition0 * uPositionWeight +\n"
|
||||
" aPosition1 * (1.0 - uPositionWeight);\n"
|
||||
" position = vec4(position.xyz, 1.0);\n"
|
||||
|
@ -475,7 +475,7 @@ static const char const phong_vert_glsl[] =
|
|||
" vec4 position = vec4(aPosition0.xyz, 1.0);\n"
|
||||
"#endif // VERTEX_POSITION\n"
|
||||
"#endif //VERTEX_POSITION_BLEND\n"
|
||||
"#ifdef VERTEX_NORMAL_BLEND\n"
|
||||
" #ifdef VERTEX_NORMAL_BLEND\n"
|
||||
" vec3 normal = aNormal0.xyz * uNormalWeight +\n"
|
||||
" aNormal1.xyz * (1.0 - uNormalWeight);\n"
|
||||
"#else\n"
|
||||
|
@ -483,7 +483,7 @@ static const char const phong_vert_glsl[] =
|
|||
" vec3 normal = aNormal0.xyz;\n"
|
||||
"#endif //VERTEX_NORMAL\n"
|
||||
"#endif //VERTEX_NORMAL_BLEND\n"
|
||||
"#ifdef VERTEX_TEXCOORD_BLEND\n"
|
||||
" #ifdef VERTEX_TEXCOORD_BLEND\n"
|
||||
" vTexCoord = aTexCoord0.st * uTexCoordWeight +\n"
|
||||
" aTexCoord1.st * (1.0 - uTexCoordWeight);\n"
|
||||
"#else\n"
|
||||
|
@ -493,7 +493,7 @@ static const char const phong_vert_glsl[] =
|
|||
"#endif //VERTEX_TEXCOORD_BLEND\n"
|
||||
" gl_Position = uMatrixMvp * position;\n"
|
||||
" vertexPhong(position, normal);\n"
|
||||
"#ifdef SHADOWED\n"
|
||||
" #ifdef SHADOWED\n"
|
||||
" vLightPosition = uMatrixLight * position;\n"
|
||||
"#endif //SHADOWED\n"
|
||||
"}\n";
|
||||
|
@ -513,6 +513,16 @@ static const char const phong_frag_glsl[] =
|
|||
"varying vec4 vLightPosition;\n"
|
||||
"uniform sampler2D uShadowMap;\n"
|
||||
"float shadow;\n"
|
||||
"float pcf(vec4 lpos, float size)\n"
|
||||
" {\n"
|
||||
" vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
|
||||
" float i, j, randx, randy, shadow;\n"
|
||||
" shadow = 0.0;\n"
|
||||
" for (i = -4.0; i < 4.0; i++)\n"
|
||||
" for (j = -4.0; j < 4.0; j++)\n"
|
||||
" shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0)*size).x);\n"
|
||||
" return shadow / 64.0;\n"
|
||||
"}\n"
|
||||
"#endif //SHADOWED\n"
|
||||
"#ifdef DIFFUSE\n"
|
||||
"uniform vec4 uMaterialDiffuse;\n"
|
||||
|
@ -583,14 +593,15 @@ static const char const phong_frag_glsl[] =
|
|||
" {\n"
|
||||
" /* Diffuse term. */\n"
|
||||
"#ifdef DIFFUSE\n"
|
||||
" \n"
|
||||
"#ifdef DIFFUSE_TEXTURE_BLEND\n"
|
||||
" color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +\n"
|
||||
" texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);\n"
|
||||
" color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +\n"
|
||||
" texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);\n"
|
||||
"#else\n"
|
||||
"#ifdef DIFFUSE_TEXTURE\n"
|
||||
" color = texture2D(uTextureDiffuse0, vTexCoord);\n"
|
||||
" color = texture2D(uTextureDiffuse0, vTexCoord);\n"
|
||||
"#else\n"
|
||||
" color = uMaterialDiffuse;\n"
|
||||
" color = uMaterialDiffuse;\n"
|
||||
"#endif //DIFFUSE_TEXTURE\n"
|
||||
"#endif //DIFFUSE_TEXTURE_BLEND\n"
|
||||
" gl_FragColor = uLightDiffuse * color * factor;\n"
|
||||
|
@ -603,16 +614,17 @@ static const char const phong_frag_glsl[] =
|
|||
" if (factor > 0.0)\n"
|
||||
" {\n"
|
||||
" factor = pow(factor, uMaterialShininess);\n"
|
||||
" \n"
|
||||
"#ifdef SPECULAR_TEXTURE_BLEND\n"
|
||||
" color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +\n"
|
||||
" texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);\n"
|
||||
" color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +\n"
|
||||
" texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);\n"
|
||||
"#else\n"
|
||||
"#ifdef SPECULAR_TEXTURE\n"
|
||||
" color = texture2D(uTextureSpecular0, vTexCoord);\n"
|
||||
"#ifdef SPECULAR_TEXTURE\n"
|
||||
" color = texture2D(uTextureSpecular0, vTexCoord);\n"
|
||||
"#else\n"
|
||||
" color = uMaterialSpecular;\n"
|
||||
"#endif\n"
|
||||
"#endif\n"
|
||||
" color = uMaterialSpecular;\n"
|
||||
"#endif //SPECULAR_TEXTURE\n"
|
||||
"#endif //SPECULAR_TEXTURE_BLEND\n"
|
||||
" gl_FragColor += uLightSpecular * color * factor;\n"
|
||||
" }\n"
|
||||
"#endif\n"
|
||||
|
@ -623,16 +635,17 @@ static const char const phong_frag_glsl[] =
|
|||
" gl_FragColor *= shadow;\n"
|
||||
"#endif //SHADOWED\n"
|
||||
"#ifdef AMBIENT\n"
|
||||
"#ifdef AMBIENT_TEXTURE_BLEND\n"
|
||||
" \n"
|
||||
"#ifdef AMBIENT_TEXTURE_BLEND\n"
|
||||
" color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +\n"
|
||||
" texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);\n"
|
||||
"#else\n"
|
||||
"#ifdef AMBIENT_TEXTURE\n"
|
||||
"#ifdef AMBIENT_TEXTURE\n"
|
||||
" color = texture2D(uTextureAmbient0, vTexCoord);\n"
|
||||
"#else\n"
|
||||
" color = uMaterialAmbient;\n"
|
||||
"#endif\n"
|
||||
"#endif\n"
|
||||
"#endif //AMBIENT_TEXTURE\n"
|
||||
"#endif //AMBIENT_TEXTURE_BLEND\n"
|
||||
" gl_FragColor += uLightAmbient * color;\n"
|
||||
"#endif\n"
|
||||
" /* Light attenuation. */\n"
|
||||
|
@ -641,6 +654,7 @@ static const char const phong_frag_glsl[] =
|
|||
"#endif\n"
|
||||
" /* Emission term. */\n"
|
||||
"#ifdef EMISSION\n"
|
||||
" \n"
|
||||
"#ifdef EMISSION_TEXTURE_BLEND\n"
|
||||
" color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +\n"
|
||||
" texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);\n"
|
||||
|
@ -649,32 +663,21 @@ static const char const phong_frag_glsl[] =
|
|||
" color = texture2D(uTextureEmission0, vTexCoord);\n"
|
||||
"#else\n"
|
||||
" color = uMaterialEmission;\n"
|
||||
"#endif\n"
|
||||
"#endif\n"
|
||||
"#endif //EMISSION_TEXTURE\n"
|
||||
"#endif //EMISSION_TEXTURE_BLEND\n"
|
||||
" gl_FragColor += color;\n"
|
||||
"#endif\n"
|
||||
"}\n"
|
||||
"#ifdef SHADOWED\n"
|
||||
"float pcf(vec4 lpos, float size)\n"
|
||||
"{\n"
|
||||
" vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
|
||||
" float i, j, randx, randy, shadow;\n"
|
||||
" shadow = 0.0;\n"
|
||||
" for (i = -4.0; i < 4.0; i++)\n"
|
||||
" for (j = -4.0; j < 4.0; j++)\n"
|
||||
" shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy +vec2(i / 8.0, j / 8.0)*size).x);\n"
|
||||
" return shadow / 64.0;\n"
|
||||
"}\n"
|
||||
"#endif //SHADOWED\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
"#ifdef SHADOWED\n"
|
||||
" shadow = pcf(vLightPosition, 1.0 / 300.0);\n"
|
||||
"#endif //SHADOWED\n"
|
||||
" fragmentPhong();\n"
|
||||
" \n"
|
||||
"#ifdef FOG_ENABLED\n"
|
||||
" float z = gl_FragCoord.z / gl_FragCoord.w;\n"
|
||||
" float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);\n"
|
||||
" float fogFactor = exp2(-uFogFactor * uFogFactor * z * z * 1.44);\n"
|
||||
" fogFactor = clamp(fogFactor, 0.0, 1.0);\n"
|
||||
" gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);\n"
|
||||
"#endif //FOG_ENABLED\n"
|
||||
|
|
|
@ -24,14 +24,19 @@ for shd in ${SHADERS} ; do
|
|||
if echo ${lname} |grep _frag 2>&1 >> /dev/null ; then
|
||||
frag_shaders_source="${frag_shaders_source} ${lname}_glsl,\n"
|
||||
fi
|
||||
|
||||
m4 ${DIR}/include.shd ${shd} > ${shd}.tmp
|
||||
|
||||
OIFS=$IFS
|
||||
IFS=$'\n'
|
||||
printf "static const char const ${lname}_glsl[] ="
|
||||
for line in `cat ${shd}` ; do
|
||||
for line in `cat ${shd}.tmp` ; do
|
||||
printf "\n \"${line}\\\n\""
|
||||
done
|
||||
printf ";\n\n"
|
||||
IFS=${OIFS}
|
||||
|
||||
rm ${shd}.tmp
|
||||
done
|
||||
|
||||
printf "static const char *vertex_shaders[] =
|
||||
|
|
|
@ -0,0 +1,183 @@
|
|||
define(`FRAGMENT_SHADER_USE_TEX_COORD',`
|
||||
#ifdef NEED_TEX_COORD
|
||||
varying vec2 vTexCoord;
|
||||
#endif //TEX_COORD')
|
||||
|
||||
define(`FRAGMENT_SHADER_USE_TEXTURE', `
|
||||
#ifdef $1_TEXTURE
|
||||
uniform sampler2D uTexture$2`0';
|
||||
#endif //$1_TEXTURE
|
||||
#ifdef $1_TEXTURE_BLEND
|
||||
uniform sampler2D uTexture$2`1';
|
||||
uniform float uTexture$2Weight;
|
||||
#endif //$1_TEXTURE_BLEND')
|
||||
|
||||
define(`FRAGMENT_SHADER_USE_FOG', `
|
||||
#ifdef FOG_ENABLED
|
||||
uniform float uFogFactor;
|
||||
uniform vec4 uFogColor;
|
||||
#endif //FOG_ENABLED')
|
||||
|
||||
define(`FRAGMENT_SHADER_USE_SHADOWS', `
|
||||
#ifdef SHADOWED
|
||||
varying vec4 vLightPosition;
|
||||
uniform sampler2D uShadowMap;
|
||||
float shadow;
|
||||
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')
|
||||
|
||||
define(`FRAGMENT_SHADER_FOG_APPLY', `
|
||||
#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')
|
||||
|
||||
define(`FRAGMENT_SHADER_USE_LIGHT', `
|
||||
#ifdef LIGHT_SPOT
|
||||
uniform vec3 uLightSpotDir;
|
||||
uniform float uLightSpotExp;
|
||||
uniform float uLightSpotCutoffCos;
|
||||
#endif //LIGHT_SPOT
|
||||
#ifdef LIGHT_ATTENUATION
|
||||
varying float vLightDist;
|
||||
#endif //LIGHT_ATTENUATION')
|
||||
|
||||
define(`FRAGMENT_SHADER_TEXTURE_BLEND', `
|
||||
#ifdef $1_TEXTURE_BLEND
|
||||
color = texture2D(uTexture$2`0', vTexCoord) * uTexture$2Weight +
|
||||
texture2D(uTexture$2`1', vTexCoord) * (1.0 - uTexture$2Weight);
|
||||
#else
|
||||
#ifdef $1_TEXTURE
|
||||
color = texture2D(uTexture$2`0', vTexCoord);
|
||||
#else
|
||||
color = uMaterial$2;
|
||||
#endif //$1_TEXTURE
|
||||
#endif //$1_TEXTURE_BLEND')
|
||||
|
||||
define(`FRAGMENT_SHADER_USE_EMISSION_TERM',
|
||||
`#ifdef EMISSION'
|
||||
uniform vec4 uMaterialEmission;
|
||||
FRAGMENT_SHADER_USE_TEXTURE(EMISSION, Emission)
|
||||
`#endif //EMISSION')
|
||||
|
||||
define(`FRAGMENT_SHADER_USE_SPECULAR_TERM',
|
||||
`#ifdef SPECULAR'
|
||||
uniform vec4 uLightSpecular;
|
||||
uniform float uMaterialShininess;
|
||||
uniform vec4 uMaterialSpecular;
|
||||
FRAGMENT_SHADER_USE_TEXTURE(SPECULAR, Specular)
|
||||
`#endif //SPECULAR')
|
||||
|
||||
define(`FRAGMENT_SHADER_USE_AMBIENT_TERM',
|
||||
`#ifdef AMBIENT'
|
||||
uniform vec4 uMaterialAmbient;
|
||||
uniform vec4 uLightAmbient;
|
||||
FRAGMENT_SHADER_USE_TEXTURE(AMBIENT, Ambient)
|
||||
`#endif //AMBIENT')
|
||||
|
||||
define(`FRAGMENT_SHADER_USE_DIFFUSE_TERM',
|
||||
`#ifdef DIFFUSE'
|
||||
uniform vec4 uMaterialDiffuse;
|
||||
uniform vec4 uLightDiffuse;
|
||||
FRAGMENT_SHADER_USE_TEXTURE(DIFFUSE, Diffuse)
|
||||
`#endif //DIFFUSE')
|
||||
|
||||
define(`VERTEX_SHADER_NEED_TEX_COORD',
|
||||
`#ifdef NEED_TEX_COORD'
|
||||
varying vec2 vTexCoord;
|
||||
`#endif //NEED_TEX_COORD')
|
||||
|
||||
define(`VERTEX_SHADER_USE_LIGHT_ATTENUATION',
|
||||
`#ifdef LIGHT_ATTENUATION'
|
||||
varying float vLightDist;
|
||||
`#endif //LIGHT_ATTENUATION')
|
||||
|
||||
define(`VERTEX_SHADER_USE_SHADOWS',
|
||||
`#ifdef SHADOWED'
|
||||
uniform mat4 uMatrixLight;
|
||||
varying vec4 vLightPosition;
|
||||
`#endif //SHADOWED')
|
||||
|
||||
define(`VERTEX_SHADER_USE_POSITION',
|
||||
`#ifdef VERTEX_POSITION'
|
||||
attribute vec4 aPosition0;
|
||||
`#endif //VERTEX_POSITION'
|
||||
|
||||
`#ifdef VERTEX_POSITION_BLEND'
|
||||
attribute vec4 aPosition1;
|
||||
uniform float uPositionWeight;
|
||||
`#endif //VERTEX_POSITION_BLEND')
|
||||
|
||||
define(`VERTEX_SHADER_USE_NORMALS',
|
||||
`#ifdef VERTEX_NORMAL'
|
||||
attribute vec4 aNormal0;
|
||||
`#endif //VERTEX_NORMAL'
|
||||
|
||||
`#ifdef VERTEX_NORMAL_BLEND'
|
||||
attribute vec4 aNormal1;
|
||||
uniform float uNormalWeight;
|
||||
`#endif //VERTEX_NORMAL_BLEND'
|
||||
)
|
||||
|
||||
define(`VERTEX_SHADER_USE_TEXCOORD',
|
||||
`#ifdef VERTEX_TEXCOORD'
|
||||
attribute vec4 aTexCoord0;
|
||||
`#endif //VERTEX_TEXCOORD'
|
||||
|
||||
`#ifdef VERTEX_TEXCOORD_BLEND'
|
||||
attribute vec4 aTexCoord1;
|
||||
uniform float uTexCoordWeight;
|
||||
`#endif //VERTEX_TEXCOORD_BLEND'
|
||||
)
|
||||
|
||||
define(`VERTEX_SHADER_POSITION',
|
||||
`#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')
|
||||
|
||||
define(`VERTEX_SHADER_NORMAL',
|
||||
`#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')
|
||||
|
||||
define(`VERTEX_SHADER_TEXCOORD',
|
||||
`#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')
|
||||
|
||||
define(`VERTEX_SHADER_SHADOWED',
|
||||
`#ifdef SHADOWED'
|
||||
vLightPosition = uMatrixLight * position;
|
||||
`#endif //SHADOWED')
|
|
@ -2,90 +2,14 @@ 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
|
||||
FRAGMENT_SHADER_USE_TEX_COORD
|
||||
FRAGMENT_SHADER_USE_FOG
|
||||
FRAGMENT_SHADER_USE_SHADOWS
|
||||
FRAGMENT_SHADER_USE_DIFFUSE_TERM
|
||||
FRAGMENT_SHADER_USE_SPECULAR_TERM
|
||||
FRAGMENT_SHADER_USE_AMBIENT_TERM
|
||||
FRAGMENT_SHADER_USE_EMISSION_TERM
|
||||
FRAGMENT_SHADER_USE_LIGHT
|
||||
|
||||
void fragmentPhong()
|
||||
{
|
||||
|
@ -109,18 +33,7 @@ void fragmentPhong()
|
|||
/* 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
|
||||
FRAGMENT_SHADER_TEXTURE_BLEND(DIFFUSE, Diffuse)
|
||||
|
||||
gl_FragColor = uLightDiffuse * color * factor;
|
||||
#else
|
||||
|
@ -134,18 +47,7 @@ void fragmentPhong()
|
|||
{
|
||||
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
|
||||
FRAGMENT_SHADER_TEXTURE_BLEND(SPECULAR, Specular)
|
||||
|
||||
gl_FragColor += uLightSpecular * color * factor;
|
||||
}
|
||||
|
@ -160,18 +62,7 @@ void fragmentPhong()
|
|||
#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
|
||||
FRAGMENT_SHADER_TEXTURE_BLEND(AMBIENT, Ambient)
|
||||
|
||||
gl_FragColor += uLightAmbient * color;
|
||||
#endif
|
||||
|
@ -184,37 +75,12 @@ void fragmentPhong()
|
|||
/* 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
|
||||
|
||||
FRAGMENT_SHADER_TEXTURE_BLEND(EMISSION, Emission)
|
||||
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()
|
||||
{
|
||||
|
||||
|
@ -224,12 +90,6 @@ void main()
|
|||
|
||||
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
|
||||
|
||||
FRAGMENT_SHADER_FOG_APPLY
|
||||
}
|
||||
|
||||
|
|
|
@ -6,45 +6,12 @@ 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
|
||||
VERTEX_SHADER_USE_SHADOWS
|
||||
VERTEX_SHADER_USE_POSITION
|
||||
VERTEX_SHADER_USE_NORMALS
|
||||
VERTEX_SHADER_USE_TEXCOORD
|
||||
VERTEX_SHADER_NEED_TEX_COORD
|
||||
VERTEX_SHADER_USE_LIGHT_ATTENUATION
|
||||
|
||||
void vertexPhong(vec4 position, vec3 normal)
|
||||
{
|
||||
|
@ -73,44 +40,12 @@ void vertexPhong(vec4 position, vec3 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
|
||||
VERTEX_SHADER_POSITION
|
||||
VERTEX_SHADER_NORMAL
|
||||
VERTEX_SHADER_TEXCOORD
|
||||
|
||||
gl_Position = uMatrixMvp * position;
|
||||
vertexPhong(position, normal);
|
||||
|
||||
#ifdef SHADOWED
|
||||
vLightPosition = uMatrixLight * position;
|
||||
#endif //SHADOWED
|
||||
VERTEX_SHADER_SHADOWED
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue