// the generated shader strings
#include "dali-shaders.h"
-
// Use pre-compiler constants in order to utilize string concatenation
#define SHADER_DEF_USE_BONES "#define USE_BONES\n"
-#define SHADER_DEF_USE_LIGHTING "#define USE_LIGHTING\n"
#define SHADER_DEF_USE_COLOR "#define USE_COLOR\n"
#define SHADER_DEF_USE_GRADIENT "#define USE_GRADIENT\n"
mDefaultShader->SendProgramMessage( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_OUTLINE_GLOW, TextDistanceFieldOutlineGlowVertex, TextDistanceFieldOutlineGlowFragment, false );
// Untextured meshes
- mDefaultShader->SendProgramMessage( GEOMETRY_TYPE_UNTEXTURED_MESH, SHADER_DEFAULT,
- UntexturedMeshVertex,
- std::string( SHADER_DEF_USE_LIGHTING ) + UntexturedMeshFragment,
- false );
-
mDefaultShader->SendProgramMessage( GEOMETRY_TYPE_UNTEXTURED_MESH, SHADER_EVENLY_LIT,
UntexturedMeshVertex,
UntexturedMeshFragment,
false );
- mDefaultShader->SendProgramMessage( GEOMETRY_TYPE_UNTEXTURED_MESH, SHADER_RIGGED_AND_LIT,
- std::string( SHADER_DEF_USE_BONES ) + UntexturedMeshVertex,
- std::string( SHADER_DEF_USE_LIGHTING ) + UntexturedMeshFragment,
- true );
-
mDefaultShader->SendProgramMessage( GEOMETRY_TYPE_UNTEXTURED_MESH, SHADER_RIGGED_AND_EVENLY_LIT,
std::string( SHADER_DEF_USE_BONES ) + UntexturedMeshVertex,
UntexturedMeshFragment,
false );
// Textured meshes
- mDefaultShader->SendProgramMessage( GEOMETRY_TYPE_TEXTURED_MESH, SHADER_DEFAULT,
- TexturedMeshVertex,
- std::string( SHADER_DEF_USE_LIGHTING ) + TexturedMeshFragment,
- false );
-
mDefaultShader->SendProgramMessage( GEOMETRY_TYPE_TEXTURED_MESH, SHADER_EVENLY_LIT,
TexturedMeshVertex,
TexturedMeshFragment,
false );
- mDefaultShader->SendProgramMessage( GEOMETRY_TYPE_TEXTURED_MESH, SHADER_RIGGED_AND_LIT,
- std::string( SHADER_DEF_USE_BONES ) + TexturedMeshVertex,
- std::string( SHADER_DEF_USE_LIGHTING ) + TexturedMeshFragment,
- true );
-
mDefaultShader->SendProgramMessage( GEOMETRY_TYPE_TEXTURED_MESH, SHADER_RIGGED_AND_EVENLY_LIT,
std::string( SHADER_DEF_USE_BONES ) + TexturedMeshVertex,
TexturedMeshFragment,
void main()
{
mediump vec4 vertexPosition = vec4(aPosition, 1.0);
- mediump float lightIntensity;
#ifdef USE_BONES
if(uBoneCount > 0)
varying highp vec4 vVertex;
varying highp vec3 vNormal;
-#ifdef USE_LIGHTING
-struct Light
-{
- int mType; // 0=AMBIENT,1=DIRECTIONAL,2=SPOT,3=POINT
- highp vec2 mFallOff; // x,y = falloff start, falloff end
- mediump vec2 mSpotAngle; // x,y = inner cone and outer cone
- mediump vec3 mLightPos; // position
- mediump vec3 mLightDir; // directional (for direction/spot lights)
- lowp vec3 mAmbient; // ambient component of the light's color
- lowp vec3 mDiffuse; // diffuse component of the light's color
- lowp vec3 mSpecular; // specular component of the light's color
-};
-
-uniform int uNumberOfLights;
-uniform Light uLight0;
-
-lowp vec3 lightColor;
-lowp vec3 specularColor;
-
-void calculateLight(Light light)
-{
- // Ensure that the varying vertex position doesn't lose precision
- highp vec3 lightVector = light.mLightPos - vVertex.xyz;
- mediump vec3 N = normalize(vNormal);
- mediump vec3 L = normalize(lightVector);
- // TODO: for directional light, should use mLightDir for light direction not lightVector
- mediump float NdotL = dot(N, L);
-
- mediump vec3 color = light.mAmbient * uMaterial.mAmbient.rgb;
- color += light.mDiffuse * uMaterial.mDiffuse.rgb * abs(NdotL);
-
- // Attenuation
- highp float attenuation = 1.0; // requires highp
- if (light.mType >= 2)
- {
- attenuation -= smoothstep(light.mFallOff.x, light.mFallOff.y, length(lightVector));
- }
-
- // TODO spotlights
-
- // add color to cumulative light total. TODO: don't attenuate directional light
- lightColor += color * attenuation;
-
- if (light.mType != 0 && NdotL > 0.0 && light.mType != 0)
- {
- // Specular highlight
- highp vec3 E = normalize(vVertex.xyz);
- highp vec3 R = reflect(L, N);
- highp float specular = pow(max(dot(R, E), 0.0), uMaterial.mShininess);
- specularColor += uMaterial.mSpecular.rgb * light.mSpecular * specular * attenuation;
- }
-}
-#endif
-
void main()
{
// sample the texture for the initial color
mediump vec4 fragColor = texture2D(sTexture, vTexCoord);
-#ifdef USE_LIGHTING
-
- // apply lighting and material properties
- specularColor = vec3(0.0);
- lightColor = vec3(0.0);
-
- // @TODO conditionally compile different shaders for different number of lights
- if( uNumberOfLights > 0 )
- {
- calculateLight(uLight0);
- }
-
- fragColor.rgb *= lightColor;
- fragColor.rgb += specularColor;
-
-#else
-
// apply material properties
fragColor.rgb *= (uMaterial.mAmbient + uMaterial.mDiffuse).rgb;
-#endif
-
// apply material alpha/opacity to alpha channel
fragColor.a *= uMaterial.mOpacity * uMaterial.mDiffuse.a;
varying highp vec4 vVertex;
varying highp vec3 vNormal;
-#ifdef USE_LIGHTING
-struct Light
-{
- int mType; // 0=AMBIENT,1=DIRECTIONAL,2=SPOT,3=POINT
- highp vec2 mFallOff; // x,y = falloff start, falloff end
- mediump vec2 mSpotAngle; // x,y = inner cone and outer cone
- mediump vec3 mLightPos; // position
- mediump vec3 mLightDir; // directional (for direction/spot lights)
- lowp vec3 mAmbient; // ambient component of the light's color
- lowp vec3 mDiffuse; // diffuse component of the light's color
- lowp vec3 mSpecular; // specular component of the light's color
-};
-#endif
-
-#ifdef USE_LIGHTING
-uniform int uNumberOfLights;
-uniform Light uLight0;
-uniform Light uLight1;
-uniform Light uLight2;
-#endif
-
#ifdef USE_COLOR
varying mediump vec3 vColor;
#endif
-#ifdef USE_LIGHTING
-lowp vec3 lightColor;
-lowp vec3 specularColor;
-
-void calculateLight(Light light)
-{
- highp vec3 lightVector = light.mLightPos - vVertex.xyz;
- mediump vec3 N = normalize(vNormal);
- mediump vec3 L = normalize(lightVector);
- // TODO: for directional light, should use mLightDir for light direction not lightVector
- mediump float NdotL = dot(N, L);
-
- mediump vec3 color = light.mAmbient * uMaterial.mAmbient.rgb;
- color += light.mDiffuse * uMaterial.mDiffuse.rgb * abs(NdotL);
-
- // Attenuation
- highp float attenuation = 1.0; // requires highp
- if (light.mType >= 2)
- {
- attenuation -= smoothstep(light.mFallOff.x, light.mFallOff.y, length(lightVector));
- }
-
- // TODO spotlights
-
- // add color to cumulative light total. TODO: don't attenuate directional light
- lightColor += color * attenuation;
-
- if (light.mType > 1 && NdotL > 0.0 && uMaterial.mShininess > 0.0)
- {
- // Specular highlight
- highp vec3 E = normalize(vVertex.xyz);
- highp vec3 R = reflect(L, N);
- highp float specular = pow(max(dot(R, E), 0.0), uMaterial.mShininess);
- specularColor += uMaterial.mSpecular.rgb * light.mSpecular * specular * attenuation;
- }
-}
-#endif
-
void main()
{
#ifdef USE_COLOR
#endif
-#ifdef USE_LIGHTING
- // apply lighting and material properties
- specularColor = vec3(0.0);
- lightColor = vec3(0.0);
-
- // @TODO conditionally compile different shaders for different number of lights
- if (uNumberOfLights > 0)
- {
- calculateLight(uLight0);
- }
-
- fragColor.rgb *= lightColor;
- fragColor.rgb += specularColor;
-
-#endif
-
// apply material alpha/opacity to alpha channel
fragColor.a *= uMaterial.mOpacity * uMaterial.mDiffuse.a;