From: Kimmo Hoikka Date: Fri, 27 Feb 2015 12:08:21 +0000 (+0000) Subject: Remove unused lighting model programs and shader source X-Git-Tag: dali_1.0.32~9^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F25%2F36025%2F2;p=platform%2Fcore%2Fuifw%2Fdali-core.git Remove unused lighting model programs and shader source Change-Id: I95a19e60f179ac8e07b5abd59e9231266879a305 --- diff --git a/dali/internal/event/effects/shader-factory.cpp b/dali/internal/event/effects/shader-factory.cpp index 0dec5d4..f706227 100644 --- a/dali/internal/event/effects/shader-factory.cpp +++ b/dali/internal/event/effects/shader-factory.cpp @@ -32,10 +32,8 @@ // 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" @@ -130,21 +128,11 @@ void ShaderFactory::LoadDefaultShaders() 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, @@ -161,21 +149,11 @@ void ShaderFactory::LoadDefaultShaders() 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, diff --git a/dali/internal/render/shader-source/textured-mesh.txt b/dali/internal/render/shader-source/textured-mesh.txt index 4f7cbfa..5051e39 100644 --- a/dali/internal/render/shader-source/textured-mesh.txt +++ b/dali/internal/render/shader-source/textured-mesh.txt @@ -29,7 +29,6 @@ attribute mediump vec4 aBoneIndices; void main() { mediump vec4 vertexPosition = vec4(aPosition, 1.0); - mediump float lightIntensity; #ifdef USE_BONES if(uBoneCount > 0) @@ -98,87 +97,14 @@ uniform lowp vec4 uColor; 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; diff --git a/dali/internal/render/shader-source/untextured-mesh.txt b/dali/internal/render/shader-source/untextured-mesh.txt index db6f7ba..a2cd5b9 100644 --- a/dali/internal/render/shader-source/untextured-mesh.txt +++ b/dali/internal/render/shader-source/untextured-mesh.txt @@ -101,69 +101,10 @@ uniform lowp vec4 uColor; 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 @@ -178,22 +119,6 @@ void main() #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;