core
.clangd/
compile_commands.json
+dali-toolkit/internal/graphics/generated/*
+dali-toolkit/internal/graphics/builtin-shader-extern-gen.h
SET(LIBTYPE STATIC)
ENDIF()
+# Generate source files for shaders
+SET(SHADER_SOURCE_DIR "${ROOT_SRC_DIR}/dali-toolkit/internal/graphics/shaders/")
+SET(SHADER_GENERATED_DIR "${ROOT_SRC_DIR}/dali-toolkit/internal/graphics/generated")
+EXECUTE_PROCESS( COMMAND bash -c "${CMAKE_CURRENT_SOURCE_DIR}/shader-generator.sh ${SHADER_SOURCE_DIR} ${SHADER_GENERATED_DIR}" )
+
+SET(GENERATED_SHADER_DIR ${ROOT_SRC_DIR}/dali-toolkit/internal/graphics/)
+SET_PROPERTY(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
+ "${GENERATED_SHADER_DIR}/generated/"
+ "${GENERATED_SHADER_DIR}/builtin-shader-extern-gen.h")
+
IF( WIN32 OR APPLE )
SET( DALICORE_LDFLAGS
"${DALICORE_LDFLAGS}"
--- /dev/null
+#!/bin/bash
+
+indir=$1
+outdir=$2
+
+mkdir -p $outdir
+
+if [ ! -e $indir ] ; then
+ echo "Error! "$indir" not found!"
+ exit 0
+fi
+
+cd $indir
+all_shaders=$(ls -1 *.{vert,frag,def})
+cd $OLDPWD
+
+# Generate one header file per shader which is defined as a const std::string_view
+for name in $all_shaders ; do
+ echo "Generating header files for $name..."
+ varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;')
+
+ newname=$(echo ${name} | sed -e 's/\./-/;')".h"
+ echo Writing $newname
+
+ shader_fullpath=$(echo ${indir})$name
+
+ header_name="${varname}_GEN_H"
+ echo "const std::string_view" "$varname""{" > $outdir/$newname
+ cat $shader_fullpath | sed -e 's/^..*$/"&\\n"/' >> $outdir/$newname
+ echo "};" >> $outdir/$newname
+done
+
+# Generate one cpp file that includes all the previously generated string_views for shaders
+echo "Generating cpp file..."
+echo -e "#include \"../builtin-shader-extern-gen.h\"\n" > $outdir/builtin-shader-gen.cpp
+
+varnames=
+for name in $all_shaders ; do
+ varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;')
+ newname=$(echo ${name} | sed -e 's/\./-/;')".h"
+ varnames="${varnames} $varname"
+ echo "#include \"$newname\"" >> $outdir/builtin-shader-gen.cpp
+done
+
+# Generate one header file that defines all the shader string_views as extern variables
+echo "Generating extern header file ( for external use )..."
+echo "#ifndef GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H" > $outdir/../builtin-shader-extern-gen.h
+echo -e "#define GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H\n" >> $outdir/../builtin-shader-extern-gen.h
+
+echo "#include <string_view>" >> $outdir/../builtin-shader-extern-gen.h
+echo "" >> $outdir/../builtin-shader-extern-gen.h
+
+for name in $all_shaders ; do
+ varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;')
+ newname=$(echo ${name} | sed -e 's/\./-/;')".h"
+ echo "extern const std::string_view $varname;" >> $outdir/../builtin-shader-extern-gen.h
+done
+cat >> $outdir/../builtin-shader-extern-gen.h << EOF
+
+#endif // GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H
+EOF
+
// INTERNAL INCLUDES
#include <dali-toolkit/devel-api/controls/gaussian-blur-view/gaussian-blur-view.h>
#include <dali-toolkit/devel-api/controls/bloom-view/bloom-view.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.h>
#include <dali-toolkit/internal/controls/control/control-renderers.h>
#include <dali-toolkit/internal/controls/control/control-data-impl.h>
const char* const IMAGE_INTENSITY_PROPERTY_NAME = "uImageIntensity";
const char* const IMAGE_SATURATION_PROPERTY_NAME = "uImageSaturation";
-///////////////////////////////////////////////////////
-//
-// Bloom shaders
-//
-
-const char* const BLOOM_EXTRACT_FRAGMENT_SOURCE =
- "varying mediump vec2 vTexCoord;\n"
- "uniform sampler2D sTexture;\n"
- "uniform lowp vec4 uColor;\n"
- "uniform mediump float uBloomThreshold;\n"
- "uniform mediump float uRecipOneMinusBloomThreshold;\n"
- "void main()\n"
- "{\n"
- " mediump vec4 col;\n"
- " col = texture2D(sTexture, vTexCoord);\n"
- " col = (col - uBloomThreshold) * uRecipOneMinusBloomThreshold;\n" // remove intensities lower than the thresold and remap intensities above the threshold to [0..1]
- " gl_FragColor = clamp(col, 0.0, 1.0);\n"
- "}\n";
-
-const char* const COMPOSITE_FRAGMENT_SOURCE =
- "precision mediump float;\n"
- "varying mediump vec2 vTexCoord;\n"
- "uniform sampler2D sTexture;\n"
- "uniform sampler2D sEffect;\n"
- "uniform lowp vec4 uColor;\n"
- "uniform float uBloomIntensity;\n"
- "uniform float uImageIntensity;\n"
- "uniform float uBloomSaturation;\n"
- "uniform float uImageSaturation;\n"
-
- "vec4 ChangeSaturation(vec4 col, float sat)\n"
- "{\n"
- " float grey = dot(col.rgb, vec3(0.3, 0.6, 0.1));\n"
- " return mix(vec4(grey, grey, grey, 1.0), col, sat);\n"
- "}\n"
-
- "void main()\n"
- "{\n"
- " mediump vec4 image;\n"
- " mediump vec4 bloom;\n"
- " image = texture2D(sTexture, vTexCoord);\n"
- " bloom = texture2D(sEffect, vTexCoord);\n"
- " image = ChangeSaturation(image, uImageSaturation) * uImageIntensity;\n"
- " bloom = ChangeSaturation(bloom, uBloomSaturation) * uBloomIntensity;\n"
- " image *= 1.0 - clamp(bloom, 0.0, 1.0);\n" // darken base where bloom is strong, to prevent excessive burn-out of result
- " gl_FragColor = image + bloom;\n"
- "}\n";
-
} // namespace
//////////////////////////////////////////////////////
// Point actors and render tasks at new render targets
- Renderer bloomRenderer = CreateRenderer( BASIC_VERTEX_SOURCE, BLOOM_EXTRACT_FRAGMENT_SOURCE );
+ Renderer bloomRenderer = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_BLOOM_VIEW_EXTRACT_SHADER_FRAG );
SetRendererTexture( bloomRenderer, mRenderTargetForRenderingChildren );
mBloomExtractActor.AddRenderer( bloomRenderer );
mBloomExtractActor.SetProperty( Actor::Property::SIZE, Vector2( mDownsampledWidth, mDownsampledHeight ) ); // size needs to match render target
mGaussianBlurView.SetUserImageAndOutputRenderTarget( mBloomExtractTarget.GetColorTexture(), blurExtractTarget );
// use the completed blur in the first buffer and composite with the original child actors render
- Renderer compositeRenderer = CreateRenderer( BASIC_VERTEX_SOURCE, COMPOSITE_FRAGMENT_SOURCE );
+ Renderer compositeRenderer = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_BLOOM_VIEW_COMPOSITE_SHADER_FRAG );
SetRendererTexture( compositeRenderer, mRenderTargetForRenderingChildren );
TextureSet textureSet = compositeRenderer.GetTextures();
textureSet.SetTexture( 0u, mRenderTargetForRenderingChildren.GetColorTexture() );
// EXTERNAL INCLUDES
#include <sstream>
#include <dali/public-api/rendering/shader.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
*/
inline Shader CreateBubbleShader( unsigned int numBubble )
{
- const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute mediump float aIndex;\n
- attribute mediump vec2 aPosition;\n
- attribute highp vec2 aTexCoord;\n
- varying mediump vec2 vTexCoord;\n
- uniform mediump mat4 uMvpMatrix;\n
- // the gravity applied to the y direction
- uniform mediump float uGravity;\n
- // xy: the emit position of the bubble; zw: the destination of the bubble.
- // The bubble is moving from (xy) to (zw plus the y drop influenced by gravity).
- uniform vec4 uStartEndPosition[NUMBER_OF_BUBBLE];\n
- // The undergoing percentage of the bubble movement. 0.0: start from emit position, 1.0: reach the destination
- uniform float uPercentage[NUMBER_OF_BUBBLE];\n
- uniform vec2 uInvertedMovementArea;\n
- // The bubble number is restricted by the available uniform num.
- // To increase the displayed bubble, every uStartEndPosition and uPercentage uniform is applied to a small bunch of bubbles (9 here)
- // The offset defines the random offset between bubbles within the bunch.
- uniform vec2 uOffset[9];\n
- // This uniform is used to change the bubble size during running time
- uniform float uDynamicScale;\n
- varying float vPercentage;\n
- varying vec2 vEffectTexCoord;\n
- void main()\n
- {\n
- vec4 position = vec4( aPosition, 0.0, 1.0 );\n
- // The Z coordinate is used to record the bubble index within current mesh actor
- int index = int(aIndex); \n
- //for some i between 0 ~ NUMBER_OF_BUBBLE-1: i,i+NUMBER_OF_BUBBLE, i+NUMBER_OF_BUBBLE*2, ... (up to i+NUMBER_OF_BUBBLE*8) belongs to the same bunch.
- int groupIdx = index / NUMBER_OF_BUBBLE;\n
- // The bubbles within the same bunch applies the same uniforms uStartEndPosition[idx] & uPercentage[idx]
- int idx = index - groupIdx*NUMBER_OF_BUBBLE;\n
- float percentage = uPercentage[idx];
- // early out if uPercentage is (zero || one) setting position to zero (zero sized triangles)
- if( percentage <= 0.0 || percentage >= 1.0 )\n
- {\n
- gl_Position = vec4(0.0);\n
- return;\n
- }\n
- vec4 startAndEnd = uStartEndPosition[idx];\n
- // The final position is added up different offset for bubbles
- startAndEnd.zw += uOffset[groupIdx];\n
- \n
- // increase the bubble size from 0% to 100% during the first 1/5 of movement & apply the dynamic scale
- // the new xy value containes both the new scale and new bubble position
- position.xy *= uDynamicScale*min(percentage*5.0, 1.0);\n
- position.xy += mix(startAndEnd.xy, startAndEnd.zw, percentage);\n
- // The gravity is g*t*t on the y direction
- position.y += uGravity * pow(percentage, 2.0);\n
- gl_Position = uMvpMatrix * position;\n
- \n
- // Add multiple bubble shapes in the effect
- vTexCoord = aTexCoord;\n
- vPercentage = percentage;\n
- // Use the emit position color for the bubble
- vEffectTexCoord = startAndEnd.xy * uInvertedMovementArea + vec2(0.5);\n
- }\n
- );
-
- const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform lowp vec4 uColor;\n
- uniform sampler2D sBackground;\n
- uniform sampler2D sBubbleShape;\n
- varying mediump float vPercentage;\n
- varying mediump vec2 vEffectTexCoord;\n
- \n
- void main()\n
- {\n
- // Get the emit pisition color, and Mix with the actor color
- mediump vec4 fragColor = texture2D(sBackground, vEffectTexCoord)*uColor;\n
- // Apply the shape defined by the texture contained sBubbleShape
- // And make the opacity being 0.7, and animate from 0.7 to 0 during the last 1/3 of movement
- fragColor.a *= texture2D(sBubbleShape, vTexCoord).a * ( 2.1 - max( vPercentage*2.1, 1.4 ) );\n
- gl_FragColor = fragColor;\n
- }\n
- );
-
std::ostringstream vertexShaderStringStream;
vertexShaderStringStream << "#define NUMBER_OF_BUBBLE "<< numBubble << "\n"
- << VERTEX_SHADER;
- Shader shader = Shader::New( vertexShaderStringStream.str(), FRAGMENT_SHADER );
+ << SHADER_BUBBLE_EFFECT_VERT;
+ Shader shader = Shader::New( vertexShaderStringStream.str(), SHADER_BUBBLE_EFFECT_FRAG );
return shader;
}
// INTERNAL INCLUDES
#include <dali-toolkit/internal/controls/bubble-effect/bubble-effect.h>
#include <dali-toolkit/internal/controls/bubble-effect/bubble-renderer.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace
{
return f0 + (rand_r( &seed ) & 0xfff) * (f1-f0) * (1.0f/4095.0f);
}
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- attribute mediump vec2 aTexCoord;\n
- uniform mediump vec3 uSize;\n
- uniform mediump mat4 uMvpMatrix;\n
- varying mediump vec2 vTexCoord;\n
- \n
-
- void main()\n
- {\n
- gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy,0.0,1.0);
- vTexCoord = aTexCoord;\n
- }\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- precision highp float;\n
- uniform vec3 uHSVDelta;\n
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- float rand(vec2 co) \n
- {\n
- return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); \n}
- \n
- vec3 rgb2hsv(vec3 c)\n
- {\n
- vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n
- vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n
- vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n
- \n
- float d = q.x - min(q.w, q.y);\n
- float e = 1.0e-10;\n
- return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n
- }\n
- vec3 hsv2rgb(vec3 c)\n
- {\n
- vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n
- vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n
- return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n
- }\n
- void main() {\n
- vec4 color = texture2D(sTexture, vTexCoord); \n
- vec3 hsvColor = rgb2hsv( color.rgb );\n
- // modify the hsv Value
- hsvColor += uHSVDelta * rand(vTexCoord); \n
- // if the new vale exceeds one, then decrease it
- hsvColor -= max(hsvColor*2.0 - vec3(2.0), 0.0);\n
- // if the new vale drops below zero, then increase it
- hsvColor -= min(hsvColor*2.0, 0.0);\n
- color = vec4( hsv2rgb( hsvColor ), 1.0 ); \n
- gl_FragColor = color; \n
- }\n
- );
-
Dali::Geometry CreateTexturedQuad()
{
struct Vertex
//Create renderer
Dali::Geometry geometry = CreateTexturedQuad();
- Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+ Shader shader = Shader::New( SHADER_BUBBLE_EMITTER_VERT, SHADER_BUBBLE_EMITTER_FRAG );
Renderer renderer = Renderer::New( geometry, shader );
TextureSet textureSet = TextureSet::New();
textureSet.SetTexture(0u, bgTexture );
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/visuals/visual-properties.h>
-
-#define DALI_COMPOSE_SHADER(STR) #STR
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
*/
inline Property::Map CreateColorAdjuster()
{
- std::string fragmentShader = DALI_COMPOSE_SHADER(
- precision highp float;\n
- uniform vec3 uHSVDelta;\n
- uniform float uIgnoreAlpha;\n
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- float rand(vec2 co) \n
- {\n
- return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); \n}
- \n
- vec3 rgb2hsv(vec3 c)\n
- {\n
- vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n
- vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n
- vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n
- \n
- float d = q.x - min(q.w, q.y);\n
- float e = 1.0e-10;\n
- return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n
- }\n
- vec3 hsv2rgb(vec3 c)\n
- {\n
- vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n
- vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n
- return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n
- }\n
- void main() {\n
- vec4 color = texture2D(sTexture, vTexCoord); \n
- vec3 hsvColor = rgb2hsv( color.rgb );\n
- // modify the hsv Value
- hsvColor += uHSVDelta * rand(vTexCoord); \n
- // if the new vale exceeds one, then decrease it
- hsvColor -= max(hsvColor*2.0 - vec3(2.0), 0.0);\n
- // if the new vale drops below zero, then increase it
- hsvColor -= min(hsvColor*2.0, 0.0);\n
- color.rgb = hsv2rgb( hsvColor ); \n
- // uIgnoreAlpha decide the result alpha will be 1.0 or source's alpha
- color.a += uIgnoreAlpha;\n
- gl_FragColor = color; \n
- }\n
- );
-
Property::Map customShader;
- customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = fragmentShader;
+ customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = SHADER_BUBBLE_EFFECT_COLOR_ADJUSTER_FRAG.data();
Property::Map map;
map[ Toolkit::Visual::Property::SHADER ] = customShader;
namespace Internal
{
-#define DALI_COMPOSE_SHADER(STR) #STR
-
-const char * const BASIC_VERTEX_SOURCE = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- attribute mediump vec2 aPosition;\n
- varying mediump vec2 vTexCoord;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump vec3 uSize;\n
- \n
- void main()\n
- {\n
- mediump vec4 vertexPosition = vec4(aPosition * uSize.xy, 0.0, 1.0);\n
- vTexCoord = aPosition + vec2(0.5);
- gl_Position = uMvpMatrix * vertexPosition;\n
- }\n
-);
-
-const char * const BASIC_FRAGMENT_SOURCE = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform vec4 uColor;\n
- \n
- void main()\n
- {\n
- gl_FragColor = texture2D(sTexture, vTexCoord);\n
- gl_FragColor *= uColor;
- }\n
-);
-
Geometry CreateGridGeometry( Uint16Pair gridSize )
{
uint16_t gridWidth = gridSize.GetWidth();
return geometry;
}
-Dali::Renderer CreateRenderer( const char* vertexSrc, const char* fragmentSrc )
+Dali::Renderer CreateRenderer( std::string_view vertexSrc, std::string_view fragmentSrc )
{
Dali::Shader shader = Dali::Shader::New( vertexSrc, fragmentSrc );
return renderer;
}
-Dali::Renderer CreateRenderer( const char* vertexSrc, const char* fragmentSrc, Dali::Shader::Hint::Value hints, Uint16Pair gridSize )
+Dali::Renderer CreateRenderer( std::string_view vertexSrc, std::string_view fragmentSrc, Dali::Shader::Hint::Value hints, Uint16Pair gridSize )
{
Dali::Shader shader = Dali::Shader::New( vertexSrc, fragmentSrc, hints );
*/
#include <dali/dali.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
namespace Internal
{
-extern const char* const BASIC_VERTEX_SOURCE;
-
-extern const char* const BASIC_FRAGMENT_SOURCE;
+#define BASIC_VERTEX_SOURCE SHADER_CONTROL_RENDERERS_VERT
+#define BASIC_FRAGMENT_SOURCE SHADER_CONTROL_RENDERERS_FRAG
/**
* Helper method for rendering an image with custom shader.
* @param[in] fragmentSrc The custom fragment shader.
* @return A newly created renderer.
*/
-Dali::Renderer CreateRenderer( const char* vertexSrc, const char* fragmentSrc );
+Dali::Renderer CreateRenderer( std::string_view vertexSrc, std::string_view fragmentSrc );
/**
* Helper method for rendering an image with custom shader.
* @param[in] gridSize The number of grid sub-divisions required.
* @return A newly created renderer.
*/
-Dali::Renderer CreateRenderer( const char* vertexSrc, const char* fragmentSrc, Dali::Shader::Hint::Value hints, Dali::Uint16Pair gridSize );
+Dali::Renderer CreateRenderer( std::string_view vertexSrc, std::string_view fragmentSrc, Dali::Shader::Hint::Value hints, Dali::Uint16Pair gridSize );
/**
* Helper method for setting the first texture passed to a renderer.
// INTERNAL INCLUDES
#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/filters/blur-two-pass-filter.h>
#include <dali-toolkit/internal/filters/emboss-filter.h>
#include <dali-toolkit/internal/filters/spread-filter.h>
const Vector4 EFFECTS_VIEW_DEFAULT_BACKGROUND_COLOR( 0.0f, 0.0f, 0.0f, 0.0 );
const bool EFFECTS_VIEW_REFRESH_ON_DEMAND(false);
-#define DALI_COMPOSE_SHADER(STR) #STR
-
-const char* EFFECTS_VIEW_VERTEX_SOURCE = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- varying mediump vec2 vTexCoord;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump vec3 uSize;\n
- uniform mediump vec3 effectOffset;\n
- \n
- void main()\n
- {\n
- mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
- vertexPosition.xyz *= uSize;\n
- vertexPosition.xyz += effectOffset;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
- \n
- vTexCoord = aPosition + vec2(0.5);\n
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* EFFECTS_VIEW_FRAGMENT_SOURCE = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 effectColor;\n
- \n
- void main()\n
- {\n
- gl_FragColor = effectColor;\n
- gl_FragColor.a *= texture2D( sTexture, vTexCoord).a;\n
- }\n
-);
-
const float BLUR_KERNEL0[] = { 12.0f/16.0f,
2.0f/16.0f, 2.0f/16.0f };
Actor self( Self() );
// Create renderers
- mRendererPostFilter = CreateRenderer( EFFECTS_VIEW_VERTEX_SOURCE, EFFECTS_VIEW_FRAGMENT_SOURCE );
+ mRendererPostFilter = CreateRenderer( SHADER_EFFECTS_VIEW_VERT,
+ SHADER_EFFECTS_VIEW_FRAG );
mRendererPostFilter.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, DepthIndex::CONTENT );
self.AddRenderer( mRendererPostFilter );
#include <dali-toolkit/public-api/visuals/visual-properties.h>
#include <dali-toolkit/internal/controls/control/control-renderers.h>
#include <dali-toolkit/internal/controls/control/control-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
// TODO:
// pixel format / size - set from JSON
const float ARBITRARY_FIELD_OF_VIEW = Math::PI / 4.0f;
-const char* const GAUSSIAN_BLUR_FRAGMENT_SOURCE = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
- uniform mediump vec2 uSampleOffsets[NUM_SAMPLES];\n
- uniform mediump float uSampleWeights[NUM_SAMPLES];\n
-
- void main()\n
- {\n
- mediump vec4 col = texture2D(sTexture, vTexCoord + uSampleOffsets[0]) * uSampleWeights[0];\n
- for (int i=1; i<NUM_SAMPLES; ++i)\n
- {\n
- col += texture2D(sTexture, vTexCoord + uSampleOffsets[i]) * uSampleWeights[i];\n
- }\n
- gl_FragColor = col;\n
- }\n
-);
-
} // namespace
std::ostringstream fragmentStringStream;
fragmentStringStream << "#define NUM_SAMPLES " << mNumSamples << "\n";
- fragmentStringStream << GAUSSIAN_BLUR_FRAGMENT_SOURCE;
+ fragmentStringStream << SHADER_GAUSSIAN_BLUR_VIEW_FRAG;
std::string fragmentSource(fragmentStringStream.str());
//////////////////////////////////////////////////////
// Create an actor for performing a horizontal blur on the texture
mHorizBlurActor = Actor::New();
mHorizBlurActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER );
+
Renderer renderer = CreateRenderer( BASIC_VERTEX_SOURCE, fragmentSource.c_str() );
mHorizBlurActor.AddRenderer( renderer );
#include <dali/devel-api/adaptor-framework/image-loading.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/controls/model3d-view/obj-loader.h>
#include <dali-toolkit/internal/controls/control/control-data-impl.h>
DALI_TYPE_REGISTRATION_END()
-
-#define MAKE_SHADER(A)#A
-
-// Diffuse illumination shader
-
-const char* SIMPLE_VERTEX_SHADER = MAKE_SHADER(
- attribute highp vec3 aPosition;\n
- attribute highp vec2 aTexCoord;\n
- attribute highp vec3 aNormal;\n
- varying mediump vec3 vIllumination;\n
- uniform mediump vec3 uSize;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump mat4 uModelView;\n
- uniform mediump mat3 uNormalMatrix;
- uniform mediump mat4 uObjectMatrix;\n
- uniform mediump vec3 uLightPosition;\n
-
- void main()\n
- {\n
- vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);\n
- vertexPosition = uObjectMatrix * vertexPosition;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
-
- //Illumination in Model-View space - Transform attributes and uniforms\n
- vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);\n
- vec3 normal = uNormalMatrix * aNormal;\n
- vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);\n
- vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );\n
-
- float lightDiffuse = max( dot( vecToLight, normal ), 0.0 );\n
- vIllumination = vec3(lightDiffuse * 0.5 + 0.5);\n
-
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* SIMPLE_FRAGMENT_SHADER = MAKE_SHADER(
- precision mediump float;\n
- varying mediump vec3 vIllumination;\n
- uniform lowp vec4 uColor;\n
-
- void main()\n
- {\n
- gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a);\n
- }\n
-);
-
-// Diffuse and specular illumination shader with albedo texture
-
-const char* VERTEX_SHADER = MAKE_SHADER(
- attribute highp vec3 aPosition;\n
- attribute highp vec2 aTexCoord;\n
- attribute highp vec3 aNormal;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec3 vIllumination;\n
- varying mediump float vSpecular;\n
- uniform mediump vec3 uSize;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump mat4 uModelView;
- uniform mediump mat3 uNormalMatrix;
- uniform mediump mat4 uObjectMatrix;\n
- uniform mediump vec3 uLightPosition;\n
-
- void main()
- {\n
- vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);\n
- vertexPosition = uObjectMatrix * vertexPosition;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
-
- //Illumination in Model-View space - Transform attributes and uniforms\n
- vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);\n
- vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);\n
- vec3 normal = normalize(uNormalMatrix * aNormal);\n
-
- vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );\n
- vec3 viewDir = normalize(-vertPos.xyz);
-
- vec3 halfVector = normalize(viewDir + vecToLight);
-
- float lightDiffuse = dot( vecToLight, normal );\n
- lightDiffuse = max(0.0,lightDiffuse);\n
- vIllumination = vec3(lightDiffuse * 0.5 + 0.5);\n
-
- vec3 reflectDir = reflect(-vecToLight, normal);
- vSpecular = pow( max(dot(reflectDir, viewDir), 0.0), 4.0 );
-
- vTexCoord = aTexCoord;\n
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* FRAGMENT_SHADER = MAKE_SHADER(
- precision mediump float;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec3 vIllumination;\n
- varying mediump float vSpecular;\n
- uniform sampler2D sDiffuse;\n
- uniform lowp vec4 uColor;\n
-
- void main()\n
- {\n
- vec4 texture = texture2D( sDiffuse, vTexCoord );\n
- gl_FragColor = vec4( vIllumination.rgb * texture.rgb * uColor.rgb + vSpecular * 0.3, texture.a * uColor.a);\n
- }\n
-);
-
-// Diffuse and specular illumination shader with albedo texture, normal map and gloss map shader
-
-const char* NRMMAP_VERTEX_SHADER = MAKE_SHADER(
- attribute highp vec3 aPosition;\n
- attribute highp vec2 aTexCoord;\n
- attribute highp vec3 aNormal;\n
- attribute highp vec3 aTangent;\n
- attribute highp vec3 aBiNormal;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec3 vLightDirection;\n
- varying mediump vec3 vHalfVector;\n
- uniform mediump vec3 uSize;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump mat4 uModelView;
- uniform mediump mat3 uNormalMatrix;
- uniform mediump mat4 uObjectMatrix;\n
- uniform mediump vec3 uLightPosition;\n
-
- void main()
- {\n
- vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);\n
- vertexPosition = uObjectMatrix * vertexPosition;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
-
- vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);\n
- vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);\n
-
- vec3 tangent = normalize(uNormalMatrix * aTangent);
- vec3 binormal = normalize(uNormalMatrix * aBiNormal);
- vec3 normal = normalize(uNormalMatrix * aNormal);
-
- vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );\n
- vLightDirection.x = dot(vecToLight, tangent);
- vLightDirection.y = dot(vecToLight, binormal);
- vLightDirection.z = dot(vecToLight, normal);
-
- vec3 viewDir = normalize(-vertPos.xyz);
- vec3 halfVector = normalize(viewDir + vecToLight);
- vHalfVector.x = dot(halfVector, tangent);
- vHalfVector.y = dot(halfVector, binormal);
- vHalfVector.z = dot(halfVector, normal);
-
- vTexCoord = aTexCoord;\n
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* NRMMAP_FRAGMENT_SHADER = MAKE_SHADER(
- precision mediump float;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec3 vLightDirection;\n
- varying mediump vec3 vHalfVector;\n
- uniform sampler2D sDiffuse;\n
- uniform sampler2D sNormal;\n
- uniform sampler2D sGloss;\n
- uniform lowp vec4 uColor;\n
-
- void main()\n
- {\n
- vec4 texture = texture2D( sDiffuse, vTexCoord );\n
- vec3 normal = normalize( texture2D( sNormal, vTexCoord ).xyz * 2.0 - 1.0 );\n
- vec4 glossMap = texture2D( sGloss, vTexCoord );\n
-
- float lightDiffuse = max( 0.0, dot( normal, normalize(vLightDirection) ) );\n
- lightDiffuse = lightDiffuse * 0.5 + 0.5;\n
-
- float shininess = pow (max (dot (normalize( vHalfVector ), normal), 0.0), 16.0) ;
-
- gl_FragColor = vec4( texture.rgb * uColor.rgb * lightDiffuse + shininess * glossMap.rgb, texture.a * uColor.a);\n
- }\n
-);
-
-
} // anonymous namespace
using namespace Dali;
{
//Create empty versions of the geometry and material so we always have a Renderer
Geometry mesh = Geometry::New();
- Shader shader = Shader::New( SIMPLE_VERTEX_SHADER, SIMPLE_FRAGMENT_SHADER );
+ Shader shader = Shader::New( SHADER_MODEL3D_VIEW_SIMPLE_SHADER_VERT, SHADER_MODEL3D_VIEW_SIMPLE_SHADER_FRAG );
mRenderer = Renderer::New( mesh, shader );
DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) {
{
if( (mTexture2Url != "") && (mTexture1Url != "") && (mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP) )
{
- mShader = Shader::New( NRMMAP_VERTEX_SHADER, NRMMAP_FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_MODEL3D_VIEW_NRMMAP_SHADER_VERT, SHADER_MODEL3D_VIEW_NRMMAP_SHADER_FRAG );
}
else if( mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_TEXTURE ||
mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP )
{
- mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_MODEL3D_VIEW_SHADER_VERT, SHADER_MODEL3D_VIEW_SHADER_FRAG );
}
else
{
- mShader = Shader::New( SIMPLE_VERTEX_SHADER, SIMPLE_FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_MODEL3D_VIEW_SIMPLE_SHADER_VERT, SHADER_MODEL3D_VIEW_SIMPLE_SHADER_FRAG );
}
}
else
{
- mShader = Shader::New( SIMPLE_VERTEX_SHADER, SIMPLE_FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_MODEL3D_VIEW_SIMPLE_SHADER_VERT, SHADER_MODEL3D_VIEW_SIMPLE_SHADER_FRAG );
}
mTextureSet = TextureSet::New();
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/visuals/visual-properties.h>
-
-#define DALI_COMPOSE_SHADER(STR) #STR
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
**/
inline Property::Map CreatePageTurnBookSpineEffect()
{
- const char* vertexSource = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- attribute mediump vec2 aPosition;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform vec3 uSize;\n
- uniform float uTextureWidth;\n
- varying vec2 vTexCoord;\n
- void main()\n
- {\n
- mediump vec4 vertexPosition = vec4(aPosition*uSize.xy, 0.0, 1.0);\n
- gl_Position = uMvpMatrix * vertexPosition;\n
- vTexCoord = aPosition + vec2(0.5);\n
- vTexCoord.x /= uTextureWidth;
- }\n);
-
- // the simplified version of the fragment shader of page turn effect
- const char* fragmentSource = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- varying mediump vec2 vTexCoord;\n
- uniform vec3 uSize;\n
- uniform vec2 uSpineShadowParameter;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
-
- void main()\n
- {\n
- if( gl_FrontFacing )\n // display front side
- {\n
- gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
- }\n
- else\n // display back side, flip the image horizontally by changing the x component of the texture coordinate
- {\n
- gl_FragColor = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) ) * uColor;\n
- }\n
- // display book spine, a stripe of shadowed texture
- float pixelPos = vTexCoord.x * uSize.x;\n
- if( pixelPos < uSpineShadowParameter.x )\n
- {\n
- float x = pixelPos - uSpineShadowParameter.x;\n
- float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );\n
- vec2 spineNormal = normalize(vec2(uSpineShadowParameter.y*x/uSpineShadowParameter.x, y));\n
- gl_FragColor.rgb *= spineNormal.y; \n
- }\n
- } );
-
Property::Map map;
Property::Map customShader;
- customShader[ Toolkit::Visual::Shader::Property::VERTEX_SHADER ] = vertexSource;
- customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = fragmentSource;
+ customShader[ Toolkit::Visual::Shader::Property::VERTEX_SHADER ] = SHADER_PAGE_TURN_BOOK_SPINE_EFFECT_VERT.data();
+ customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = SHADER_PAGE_TURN_BOOK_SPINE_EFFECT_FRAG.data();
map[ Toolkit::Visual::Property::SHADER ] = customShader;
return map;
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/visuals/visual-properties.h>
#include <dali-toolkit/internal/controls/page-turn-view/page-turn-effect.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
using namespace Dali;
using namespace Dali::Toolkit;
namespace
{
-#define DALI_COMPOSE_SHADER(STR) #STR
const char * const PROPERTY_COMMON_PARAMETERS( "uCommonParameters" );
const char * const PROPERTY_ORIGINAL_CENTER( "originalCenter" );
const char * const PROPERTY_CURRENT_CENTER( "currentCenter" );
Property::Map Dali::Toolkit::Internal::CreatePageTurnEffect()
{
- const char* vertexShader = DALI_COMPOSE_SHADER(
- /*
- * The common parameters for all the vertices, calculate in CPU then pass into the shader as uniforms
- *
- * first part of the page, (outside the the line passing through original center and vertical to curve direction)
- * no Z change, only 2D rotation and translation
- * ([0][0],[0][1],[1][0],[1][1]) mat2 rotateMatrix
- * ([2][0],[2][1]) vec2 translationVector
- *
- * ([0][2],[0][3]) vec2 originalCenter: Typically the press down position of the Pan Gesture
- * ([1][2],[1][3]) vec2 currentCenter: Typically the current position of the Pan Gesture
- * ([3][0],[3][1]) vec2 curveDirection: The normalized vector pointing from original center to current center
- * ([2][2]) float vanishingPointY: The Y coordinate of the intersection of the spine
- * and the line which goes through the original center and is vertical to the curveDirection
- * ([2][3]) float curveEndY: The Y coordinate of intersection of the spine and the line through both original and current center
- * ([3][2]) float curveHeight: The height of the interpolated hermite curve.
- * ([3][3]) float currentLength: The length from the current center to the curveEnd.
- */
- precision mediump float;\n
- \n
- attribute mediump vec2 aPosition;\n
- \n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump mat3 uNormalMatrix;\n
- uniform mediump mat4 uModelView;\n
- \n
- uniform mat4 uCommonParameters;\n
- \n
- uniform vec3 uSize;\n
- uniform float uIsTurningBack;\n
- uniform float uTextureWidth;\n
- varying vec3 vNormal;\n
- varying vec4 vPosition;\n
- varying mediump vec2 vTexCoord;\n
- \n
- void main()\n
- {\n
- vec4 position = vec4( aPosition*uSize.xy, 0.0, 1.0);\n
- vec2 currentCenter = vec2( uCommonParameters[1][2], uCommonParameters[1][3]);\n
- vec2 originalCenter = vec2( uCommonParameters[0][2], uCommonParameters[0][3]);\n
- vec3 normal = vec3(0.0,0.0,1.0);\n
- \n
- if(currentCenter.x < originalCenter.x)\n
- {\n
- // change the coordinate origin from the center of the page to its top-left
- position.xy += uSize.xy * 0.5;\n
- vec2 curveDirection = vec2( uCommonParameters[3]);\n
- vec3 vanishingPoint = vec3(0.0, uCommonParameters[2][2], 0.0);\n
- // first part of the page, (outside the the line passing through original center and vertical to curve direction)
- //no Z change, only 2D rotation and translation
- if( dot(curveDirection, position.xy - originalCenter) < 0.0 )
- {\n
- position.y -= vanishingPoint.y;\n
- position.xy = mat2(uCommonParameters)*position.xy + vec2( uCommonParameters[2]);\n
- }\n
- // second part of the page, bent as a ruled surface
- else\n
- {\n
- // calculate on the flat plane, between
- // the first line passing through current vertex and vanishing point
- // the second line passing through original center and current center
- vec2 curveEnd = vec2( 0.0, uCommonParameters[2][3] );\n
- vec2 curFlatDirection = vec2(0.0,1.0);\n
- float lengthFromCurve = position.y - originalCenter.y;\n
- float lengthOnCurve = position.x;\n
- if(currentCenter.y != originalCenter.y)\n
- {\n
- curFlatDirection = normalize(position.xy - vanishingPoint.xy);\n
- lengthFromCurve = (curveEnd.x*curveDirection.y-curveEnd.y*curveDirection.x-position.x*curveDirection.y+position.y*curveDirection.x)
- / (curFlatDirection.x*curveDirection.y-curFlatDirection.y*curveDirection.x);\n
- lengthOnCurve = length(position.xy+lengthFromCurve*curFlatDirection-curveEnd);\n
- }\n
- \n
- // define the control points of hermite curve, composed with two segments
- // calculation is carried out on the 2D plane which is passing through both current and original center and vertical to the image plane
- float currentLength = uCommonParameters[3][3];\n
- float originalLength = abs(originalCenter.x/curveDirection.x);\n
- float height = uCommonParameters[3][2];\n
- float percentage = currentLength/originalLength;\n
- //vec2 SegmentOneControlPoint0 = vec2(0.0, 0.0);
- vec2 SegmentOneControlPoint1 = vec2((0.65*percentage - 0.15)*originalLength, (0.8 + 0.2 * percentage)*height); \n
- vec2 SegmentTwoControlPoint0 = SegmentOneControlPoint1;\n
- vec2 SegmentTwoControlPoint1 = vec2(currentLength, 0.0); \n
- vec2 SegmentOneTangentVector0 = SegmentOneControlPoint1;\n
- vec2 SegmentOneTangentVector1 = vec2(0.5*originalLength,0.0);\n
- vec2 SegmentTwoTangentVector0 = SegmentOneTangentVector1;\n
- vec2 SegmentTwoTangentVector1 = SegmentOneTangentVector1;\n
- \n
- // calculate the corresponding curve point position and its tangent vector
- // it is a linear mapping onto nonlinear curves, might cause some unwanted deformation
- // but as there are no analytical method to calculate the curve length on arbitrary segment
- // no efficient way to solve this nonlinear mapping, Numerical approximation would cost too much computation in shader
- vec2 curvePoint2D;\n
- vec2 tangent;\n
- float t0 = lengthOnCurve / originalLength;\n
- if(t0<=0.5)\n
- {\n
- float t = 2.0*t0;\n
- float t_2 = t*t;\n
- float t_3 = t*t_2;\n
- curvePoint2D = (-2.0*t_3+3.0*t_2)*SegmentOneControlPoint1
- + (t_3-2.0*t_2+t)*SegmentOneTangentVector0 + (t_3-t_2)*SegmentOneTangentVector1;\n
- tangent = (-6.0*t_2+6.0*t)*SegmentOneControlPoint1
- + (3.0*t_2-4.0*t+1.0)*SegmentOneTangentVector0 + (3.0*t_2-2.0*t)*SegmentOneTangentVector1;\n
- }\n
- else\n
- {\n
- float t = 2.0*t0-1.0;\n
- float t_2 = t*t;\n
- float t_3 = t*t_2;\n
- curvePoint2D = (2.0*t_3-3.0*t_2+1.0)*SegmentTwoControlPoint0 + (-2.0*t_3+3.0*t_2)*SegmentTwoControlPoint1
- + (t_3-2.0*t_2+t)*SegmentTwoTangentVector0 + (t_3-t_2)*SegmentTwoTangentVector1;\n
- tangent = (6.0*t_2-6.0*t)*SegmentTwoControlPoint0 + (-6.0*t_2+6.0*t)*SegmentTwoControlPoint1
- + (3.0*t_2-4.0*t+1.0)*SegmentTwoTangentVector0 + (3.0*t_2-2.0*t)*SegmentTwoTangentVector1;\n
- // a trick to eliminate some optical illusion caused by the gradient matter of normal in per-fragment shading
- // which is caused by linear interpolation of normal vs. nonlinear lighting
- // will notice some artifact in the areas with dramatically normal changes, so compress the normal differences here
- tangent.y *= min(1.0, length(position.xyz - vanishingPoint) / uSize.y ); \n
- }\n
- vec3 curvePoint = vec3(curveEnd - curvePoint2D.x*curveDirection,max(0.0,curvePoint2D.y));\n
- vec3 tangentVector = vec3(-tangent.x*curveDirection,tangent.y);\n
- \n
- // locate the new vertex position on the line passing through both vanishing point and the calculated curve point position
- vec3 curLiftDirection = vec3(0.0,-1.0,0.0);\n
- if(currentCenter.y != originalCenter.y)\n
- {\n
- curLiftDirection = normalize(curvePoint - vanishingPoint);\n
- tangentVector *= (curveDirection.y > 0.0) ? -1.0 : 1.0;\n
- // an heuristic adjustment here, to compensate the linear parameter mapping onto the nonlinear curve
- float Y0 = position.y - curveDirection.y * (position.x/curveDirection.x); \n
- float proportion;
- float refLength;\n
- if(abs(Y0-vanishingPoint.y) > abs(curveEnd.y-vanishingPoint.y)) \n
- {\n
- proportion = abs(curveEnd.y - Y0) / (abs(curveEnd.y-Y0)+abs(curveEnd.y - vanishingPoint.y)); \n
- refLength = proportion*length(originalCenter-vanishingPoint.xy) / (proportion-1.0); \n
- }\n
- else\n
- {\n
- proportion = abs(curveEnd.y - Y0) / abs(curveEnd.y - vanishingPoint.y);\n
- refLength = proportion*length(originalCenter-vanishingPoint.xy); \n
- }\n
- float Y1 = currentCenter.y - (normalize(currentCenter-vanishingPoint.xy)).y * refLength; \n
- position.y = mix(Y0, Y1, t0); \n
- }\n
- position.xz = curvePoint.xz - lengthFromCurve*curLiftDirection.xz;\n
- // calculate the normal vector, will be used for lighting
- normal = cross(curLiftDirection, normalize(tangentVector));\n
- // the signature of Z is decided by the page turning direction:
- // from left to right(negative); from right to left (positive)
- position.z *= -uIsTurningBack;\n
- normal.xy *= -uIsTurningBack;\n
- }\n
- // change the coordinate origin from the top-left of the page to its center
- position.xy -= uSize.xy * 0.5; \n
- }\n
- vNormal = uNormalMatrix * normal;\n
- gl_Position = uMvpMatrix * position;
- // varying parameters for fragment shader
- vTexCoord = aPosition + vec2(0.5);\n
- vTexCoord.x /= uTextureWidth;
- vPosition = uModelView * position;\n
- }\n
- );
-
- const char* fragmentShader = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- \n
- varying mediump vec2 vTexCoord;\n
- \n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
- uniform vec3 uSize;\n
- uniform vec2 uSpineShadowParameter;\n
- varying vec3 vNormal;\n
- varying vec4 vPosition;\n
- \n
- void main()\n
- {\n
- // need to re-normalize the interpolated normal
- vec3 normal = normalize( vNormal );\n
- // display page content
- vec4 texel;
- // display back image of the page, flip the texture
- if( dot(vPosition.xyz, normal) > 0.0 ) texel = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) );\n
- // display front image of the page
- else texel = texture2D( sTexture, vTexCoord );\n
-
- // display book spine, a stripe of shadowed texture
- float pixelPos = vTexCoord.x * uSize.x; \n
- float spineShadowCoef = 1.0; \n
- if( pixelPos < uSpineShadowParameter.x ) \n
- {\n
- float x = pixelPos - uSpineShadowParameter.x;\n
- float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );\n
- spineShadowCoef = normalize( vec2( uSpineShadowParameter.y*x/uSpineShadowParameter.x, y ) ).y;\n
- }\n
- // calculate the lighting
- // set the ambient color as vec3(0.4);
- float lightColor = abs( normal.z ) * 0.6 + 0.4;\n
- gl_FragColor = vec4( ( spineShadowCoef * lightColor ) * texel.rgb , texel.a ) * uColor;\n
- }
- );
-
Property::Map map;
Property::Map customShader;
- customShader[ Toolkit::Visual::Shader::Property::VERTEX_SHADER ] = vertexShader;
- customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = fragmentShader;
+ customShader[ Toolkit::Visual::Shader::Property::VERTEX_SHADER ] = SHADER_PAGE_TURN_EFFECT_VERT.data();
+ customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = SHADER_PAGE_TURN_EFFECT_FRAG.data();
customShader[ Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_X ] = 20;
customShader[ Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_Y ] = 20;
#include <dali/public-api/rendering/shader.h>
#include <dali/public-api/rendering/texture-set.h>
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
namespace Dali
{
26.f / 130.f
};
-#define MAKE_SHADER(A)#A
-
-// Modify the vertex position according to the bounce coefficient;
-const char* MESH_VERTEX_SHADER = MAKE_SHADER(
-attribute mediump vec3 aPosition1;\n
-attribute mediump vec3 aPosition2;\n
-uniform mediump mat4 uMvpMatrix;\n
-uniform mediump vec3 uSize;
-uniform mediump float uBounceCoefficient;\n
-\n
-void main()\n
-{\n
- gl_Position = uMvpMatrix * vec4(mix( aPosition1, aPosition2, abs(uBounceCoefficient) )*uSize, 1.0);\n
-}
-);
-
-// use the actor color to paint every layer
-const char* MESH_FRAGMENT_SHADER = MAKE_SHADER(
-uniform lowp vec4 uColor;\n
-void main()\n
-{\n
- gl_FragColor = uColor;\n
-}\n
-);
-
} // namespace Anon
Actor CreateBouncingEffectActor( Property::Index& bouncePropertyIndex )
meshGeometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) );
// Create the shader
- Shader shader = Shader::New( MESH_VERTEX_SHADER, MESH_FRAGMENT_SHADER );
+ Shader shader = Shader::New( SHADER_BOUNCING_EFFECT_MESH_SHADER_VERT, SHADER_BOUNCING_EFFECT_MESH_SHADER_FRAG );
// Create renderer
Renderer renderer = Renderer::New( meshGeometry, shader );
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/controls/control/control-renderers.h>
#include <dali-toolkit/internal/controls/shadow-view/shadow-view-impl.h>
#include <dali-toolkit/internal/filters/blur-two-pass-filter.h>
const char* const BLUR_STRENGTH_PROPERTY_NAME = "BlurStrengthProperty";
const char* const SHADOW_COLOR_PROPERTY_NAME = "ShadowColorProperty";
-const char* const RENDER_SHADOW_VERTEX_SOURCE =
-
- " attribute mediump vec2 aPosition;\n"
- " uniform mediump mat4 uMvpMatrix;\n"
- " uniform mediump mat4 uModelMatrix;\n"
- " uniform vec3 uSize;\n"
- " varying vec2 vTexCoord;\n"
-
- " uniform mediump mat4 uLightCameraProjectionMatrix;\n"
- " uniform mediump mat4 uLightCameraViewMatrix;\n"
- "\n"
- "void main()\n"
- "{\n"
- " mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n"
- " vertexPosition.xyz *= uSize;\n"
- " gl_Position = uMvpMatrix * vertexPosition;\n"
- " vec4 textureCoords = uLightCameraProjectionMatrix * uLightCameraViewMatrix * uModelMatrix * vertexPosition;\n"
- " vTexCoord = 0.5 + 0.5 * (textureCoords.xy/textureCoords.w);\n"
- "}\n";
-
-const char* const RENDER_SHADOW_FRAGMENT_SOURCE =
- "varying mediump vec2 vTexCoord;\n"
- "uniform lowp vec4 uShadowColor;\n"
- "uniform sampler2D sTexture;\n"
-
- "void main()\n"
- "{\n"
- " lowp float alpha;\n"
- " alpha = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y)).a;\n"
- " gl_FragColor = vec4(uShadowColor.rgb, uShadowColor.a * alpha);\n"
- "}\n";
-
} // namespace
ShadowView::ShadowView( float downsampleWidthScale, float downsampleHeightScale )
mShadowPlane.SetProperty( Actor::Property::NAME, "SHADOW_PLANE" );
mShadowPlane.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
mShadowPlane.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
- Renderer shadowRenderer = CreateRenderer( RENDER_SHADOW_VERTEX_SOURCE, RENDER_SHADOW_FRAGMENT_SOURCE, Shader::Hint::OUTPUT_IS_TRANSPARENT, Uint16Pair(20,20) );
+ Renderer shadowRenderer = CreateRenderer( SHADER_SHADOW_VIEW_RENDER_SHADER_VERT, SHADER_SHADOW_VIEW_RENDER_SHADER_FRAG,
+ Shader::Hint::OUTPUT_IS_TRANSPARENT,
+ Uint16Pair(20,20) );
TextureSet textureSet = shadowRenderer.GetTextures();
textureSet.SetTexture( 0u, mOutputFrameBuffer.GetColorTexture() );
mShadowPlane.AddRenderer( shadowRenderer );
// INTERNAL_INCLUDES
#include <dali-toolkit/public-api/image-loader/sync-image-loader.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/controls/control/control-renderers.h>
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
#include <dali-toolkit/internal/visuals/visual-factory-impl.h>
const float GAUSSIAN_BLUR_DOWNSAMPLE_HEIGHT_SCALE = 0.5f;
const char* ALPHA_UNIFORM_NAME( "uAlpha" );
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
- uniform lowp float uAlpha;\n
- \n
- void main()\n
- {\n
- gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
- gl_FragColor.a *= uAlpha;
- }\n
-);
/**
* The constraint is used to blend the group of blurred images continuously with a unified blur strength property value which ranges from zero to one.
for(unsigned int i=0; i<mBlurLevels+1;i++)
{
- mRenderers[i] = CreateRenderer( BASIC_VERTEX_SOURCE, FRAGMENT_SHADER );
+ mRenderers[i] = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_SUPER_BLUR_VIEW_FRAG );
mRenderers[i].SetProperty( Dali::Renderer::Property::DEPTH_INDEX, (int)i );
self.AddRenderer( mRenderers[i] );
${toolkit_src_dir}/transition-effects/cube-transition-wave-effect-impl.cpp
${toolkit_src_dir}/text/xhtml-entities.cpp
${toolkit_src_dir}/drag-drop-detector/drag-and-drop-detector-impl.cpp
+ ${toolkit_src_dir}/graphics/generated/builtin-shader-gen.cpp
)
SET( SOURCES ${SOURCES}
--- /dev/null
+varying mediump vec2 vTexCoord;
+
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ mediump vec4 color = texture2D( sTexture, vTexCoord );
+ if(color.a <= 0.0001)
+ {
+ discard;
+ }
+ gl_FragColor = color * uColor;
+}
--- /dev/null
+precision mediump float;
+
+uniform mediump vec4 start_color;
+uniform mediump vec4 end_color;
+uniform mediump float gradient_offset;
+
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vStart;
+varying mediump vec2 vEnd;
+
+float get_position(vec2 x, vec2 s, vec2 e)
+{
+ vec2 df = e - s;
+ vec2 dx = x - s;
+
+#ifdef GRADIENT_TYPE_LINEAR
+ return dot(dx,df)/dot(df,df);
+#endif
+/* GradientType::LINEAR */
+
+#ifdef GRADIENT_TYPE_RADIAL
+ return sqrt(dot(dx,dx)/dot(df,df));
+#endif
+/* GradientType::RADIAL */
+}
+
+float recalculate(float r)
+{
+#ifdef SPREAD_TYPE_REFLECT
+ return 1.0 - abs(mod(r, 2.0) - 1.0);
+#endif
+/* SpreadType::REFLECT */
+
+#ifdef SPREAD_TYPE_REPEAT
+ return fract(r);
+#endif
+/* SpreadType::REPEAT*/
+
+#ifdef SPREAD_TYPE_CLAMP
+ return clamp(r, 0.0, 1.0);
+#endif
+/* SpreadType::CLAMP */
+}
+
+void main()
+{
+ float r = get_position( vTexCoord, vStart, vEnd );
+ r = recalculate( r + gradient_offset );
+ vec4 color = mix( start_color, end_color, r );
+ gl_FragColor = color;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+uniform mediump vec2 start_point;
+uniform mediump vec2 end_point;
+uniform mediump vec2 rotate_center;
+uniform mediump float rotate_angle;
+
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vStart;
+varying mediump vec2 vEnd;
+
+vec2 rotate(vec2 x, vec2 c, float a)
+{
+ vec2 d = x - c;
+ vec2 r = vec2(d.x * cos(a) - d.y * sin(a), d.x * sin(a) + d.y * cos(a));
+
+#ifdef UNIT_TYPE_BOUNDING_BOX
+ return r + c;
+#endif
+
+ /* UnitType::OBJECT_BOUNDING_BOX */
+#ifdef UNIT_TYPE_USER
+ return (r + c) / uSize.x;
+#endif
+ /* UnitType::USER_SPACE*/
+}
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix( uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy );
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ vStart = rotate( start_point, rotate_center, rotate_angle );
+ vEnd = rotate( end_point, rotate_center, rotate_angle );
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+
+#ifdef UNIT_TYPE_BOUNDING_BOX
+ vTexCoord = vec2(aPosition.x, -aPosition.y);
+#endif
+/* UnitType::OBJECT_BOUNDING_BOX */
+
+#ifdef UNIT_TYPE_USER
+ vTexCoord = vec2(aPosition.x, -aPosition.y * uSize.y / uSize.x);
+#endif
+/* UnitType::USER_SPACE*/
+}
--- /dev/null
+INPUT mediump vec2 vPosition;
+
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform mediump float thickness;
+uniform mediump float radius;
+uniform mediump float startAngle;
+uniform mediump float sweepAngle;
+
+const mediump float M_PI_OVER_2 = 1.57079632679;
+const mediump float M_PI = 3.14159265359;
+const mediump float M_PI_2 = 6.28318530718;
+
+mediump float GetOpacity()
+{
+ mediump float start = radians( mod( startAngle, 360.0 ) );
+ mediump float angle = mod( atan( vPosition.y, vPosition.x ) + M_PI_OVER_2 - start, M_PI_2 );
+ mediump float dist = length( vPosition );
+ if( angle <= radians( sweepAngle ) )
+ {
+ return smoothstep( -1.0, 1.0, thickness / 2.0 - ( abs( dist - radius ) ) );
+ }
+ mediump float end = radians( mod( startAngle + sweepAngle, 360.0 ) );
+ mediump vec2 q0 = vec2( dist * cos( start - M_PI_OVER_2 ), dist * sin( start - M_PI_OVER_2 ) );
+ mediump vec2 q1 = vec2( dist * cos( end - M_PI_OVER_2 ), dist * sin( end - M_PI_OVER_2 ) );
+ mediump float opacity = 1.0 - smoothstep( 0.0, 2.0, min( length( vPosition - q0 ), length( vPosition - q1 ) ) );
+ opacity *= step( 0.0, thickness / 2.0 - abs( dist - radius ) );
+ return opacity;
+}
+
+void main()
+{
+ OUT_COLOR = vec4( mixColor, 1.0 ) * uColor;
+ OUT_COLOR.a *= GetOpacity();
+}
--- /dev/null
+INPUT mediump vec2 vPosition;
+
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform mediump float thickness;
+uniform mediump float radius;
+uniform mediump float startAngle;
+uniform mediump float sweepAngle;
+
+const mediump float M_PI_OVER_2 = 1.57079632679;
+const mediump float M_PI_2 = 6.28318530718;
+
+mediump float GetOpacity()
+{
+ mediump float start = radians( mod( startAngle, 360.0 ) );
+ mediump float angle = mod( atan( vPosition.y, vPosition.x ) + M_PI_OVER_2 - start, M_PI_2 );
+ mediump float dist = length( vPosition );
+ if( angle <= radians( sweepAngle ) )
+ {
+ return smoothstep( -1.0, 1.0, thickness / 2.0 - ( abs( dist - radius ) ) );
+ }
+ mediump float end = radians( mod( startAngle + sweepAngle, 360.0 ) );
+ mediump vec2 q0 = vec2( radius * cos( start - M_PI_OVER_2 ), radius * sin( start - M_PI_OVER_2 ) );
+ mediump vec2 q1 = vec2( radius * cos( end - M_PI_OVER_2 ), radius * sin( end - M_PI_OVER_2 ) );
+ return smoothstep( -1.0, 1.0, thickness / 2.0 - min( length( vPosition - q0 ), length( vPosition - q1 ) ) );
+}
+
+void main()
+{
+ OUT_COLOR = vec4( mixColor, 1.0 ) * uColor;
+ OUT_COLOR.a *= GetOpacity();
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+OUTPUT mediump vec2 vPosition;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ vPosition = aPosition* visualSize;
+ return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
\ No newline at end of file
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform sampler2D sEffect;
+uniform lowp vec4 uColor;
+uniform float uBloomIntensity;
+uniform float uImageIntensity;
+uniform float uBloomSaturation;
+uniform float uImageSaturation;
+
+vec4 ChangeSaturation(vec4 col, float sat)
+{
+ float grey = dot(col.rgb, vec3(0.3, 0.6, 0.1));
+ return mix(vec4(grey, grey, grey, 1.0), col, sat);
+}
+
+void main()
+{
+ mediump vec4 image;
+ mediump vec4 bloom;
+ image = texture2D(sTexture, vTexCoord);
+ bloom = texture2D(sEffect, vTexCoord);
+ image = ChangeSaturation(image, uImageSaturation) * uImageIntensity;
+ bloom = ChangeSaturation(bloom, uBloomSaturation) * uBloomIntensity;
+ image *= 1.0 - clamp(bloom, 0.0, 1.0); // darken base where bloom is strong, to prevent excessive burn-out of result
+ gl_FragColor = image + bloom;
+}
\ No newline at end of file
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform mediump float uBloomThreshold;
+uniform mediump float uRecipOneMinusBloomThreshold;
+
+void main()
+{
+ mediump vec4 col;
+ col = texture2D(sTexture, vTexCoord);
+ col = (col - uBloomThreshold) * uRecipOneMinusBloomThreshold; // remove intensities lower than the thresold and remap intensities above the threshold to [0..1]
+ gl_FragColor = clamp(col, 0.0, 1.0);
+}
\ No newline at end of file
--- /dev/null
+precision highp float;
+uniform float uBlurStrength;
+uniform sampler2D sTexture;
+uniform sampler2D sEffect;
+varying mediump vec2 vTexCoord;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uBlurStrength
+ + texture2D( sEffect, vTexCoord )*(1.0-uBlurStrength);
+}
\ No newline at end of file
--- /dev/null
+precision highp float;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform vec2 uSampleOffsets[NUM_SAMPLES];
+uniform float uSampleWeights[NUM_SAMPLES];
+
+void main()
+{
+ vec4 color = vec4(0.0);
+ for( int i = 0; i < NUM_SAMPLES; ++i )
+ {
+ color += texture2D( sTexture, vTexCoord + uSampleOffsets[i] ) * uSampleWeights[i];
+ }
+ gl_FragColor = color;
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump float vAlpha;
+
+uniform lowp vec4 uColor;
+uniform lowp vec4 borderColor;
+uniform lowp vec3 mixColor;
+uniform mediump float borderSize;
+
+void main()
+{
+ OUT_COLOR = vec4(mixColor, 1.0) * borderColor * uColor;
+ OUT_COLOR.a *= smoothstep(0.0, 1.5, vAlpha) * smoothstep( borderSize + 1.5, borderSize, vAlpha );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+INPUT mediump vec2 aDrift;
+OUTPUT mediump float vAlpha;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump float borderSize;
+
+void main()
+{
+ vec2 position = aPosition*(uSize.xy+vec2(0.75)) + aDrift*(borderSize+1.5);
+ gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);
+ vAlpha = min( abs(aDrift.x), abs(aDrift.y) )*(borderSize+1.5);
+}
\ No newline at end of file
--- /dev/null
+uniform lowp vec4 uColor;
+uniform lowp vec4 borderColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ OUT_COLOR = vec4(mixColor, 1.0) * borderColor * uColor;
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+INPUT mediump vec2 aDrift;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump float borderSize;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec2 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy;
+}
+
+void main()
+{
+ vec2 position = ComputeVertexPosition() + aDrift*borderSize;
+ gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);
+}
\ No newline at end of file
--- /dev/null
+// Use the actor color to paint every layer
+uniform lowp vec4 uColor;
+
+void main()
+{
+ gl_FragColor = uColor;
+}
--- /dev/null
+// Modify the vertex position according to the bounce coefficient
+attribute mediump vec3 aPosition1;
+attribute mediump vec3 aPosition2;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump vec3 uSize;
+uniform mediump float uBounceCoefficient;
+
+void main()
+{
+ gl_Position = uMvpMatrix * vec4(mix( aPosition1, aPosition2, abs(uBounceCoefficient) )*uSize, 1.0);
+}
--- /dev/null
+precision highp float;
+uniform vec3 uHSVDelta;
+uniform float uIgnoreAlpha;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+
+float rand(vec2 co)
+{
+ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
+}
+
+vec3 rgb2hsv(vec3 c)
+{
+ vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
+ vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
+ vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
+
+ float d = q.x - min(q.w, q.y);
+ float e = 1.0e-10;
+ return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
+}
+
+vec3 hsv2rgb(vec3 c)
+{
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
+ return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
+}
+
+void main()
+{
+ vec4 color = texture2D(sTexture, vTexCoord);
+ vec3 hsvColor = rgb2hsv( color.rgb );
+ // modify the hsv Value
+ hsvColor += uHSVDelta * rand(vTexCoord);
+ // if the new vale exceeds one, then decrease it
+ hsvColor -= max(hsvColor*2.0 - vec3(2.0), 0.0);
+ // if the new vale drops below zero, then increase it
+ hsvColor -= min(hsvColor*2.0, 0.0);
+ color.rgb = hsv2rgb( hsvColor );
+ // uIgnoreAlpha decide the result alpha will be 1.0 or source's alpha
+ color.a += uIgnoreAlpha;
+ gl_FragColor = color;
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform lowp vec4 uColor;
+uniform sampler2D sBackground;
+uniform sampler2D sBubbleShape;
+varying mediump float vPercentage;
+varying mediump vec2 vEffectTexCoord;
+
+void main()
+{
+ // Get the emit pisition color, and Mix with the actor color
+ mediump vec4 fragColor = texture2D(sBackground, vEffectTexCoord)*uColor;
+
+ // Apply the shape defined by the texture contained sBubbleShape
+ // And make the opacity being 0.7, and animate from 0.7 to 0 during the last 1/3 of movement
+ fragColor.a*= texture2D(sBubbleShape, vTexCoord).a * ( 2.1 - max( vPercentage*2.1, 1.4 ) );
+
+ gl_FragColor = fragColor;
+}
\ No newline at end of file
--- /dev/null
+attribute mediump float aIndex;
+attribute mediump vec2 aPosition;
+attribute highp vec2 aTexCoord;
+varying mediump vec2 vTexCoord;
+uniform mediump mat4 uMvpMatrix;
+// the gravity applied to the y direction
+uniform mediump float uGravity;
+// xy: the emit position of the bubble; zw: the destination of the bubble.
+// The bubble is moving from (xy) to (zw plus the y drop influenced by gravity).
+uniform vec4 uStartEndPosition[NUMBER_OF_BUBBLE];
+// The undergoing percentage of the bubble movement. 0.0: start from emit position, 1.0: reach the destination
+uniform float uPercentage[NUMBER_OF_BUBBLE];
+uniform vec2 uInvertedMovementArea;
+// The bubble number is restricted by the available uniform num.
+// To increase the displayed bubble, every uStartEndPosition and uPercentage uniform is applied to a small bunch of bubbles (9 here)
+// The offset defines the random offset between bubbles within the bunch.
+uniform vec2 uOffset[9];
+// This uniform is used to change the bubble size during running time
+uniform float uDynamicScale;
+varying float vPercentage;
+varying vec2 vEffectTexCoord;
+
+void main()
+{
+ vec4 position = vec4( aPosition, 0.0, 1.0 );
+ // The Z coordinate is used to record the bubble index within current mesh actor
+ int index = int(aIndex);
+ //for some i between 0 ~ NUMBER_OF_BUBBLE-1: i,i+NUMBER_OF_BUBBLE, i+NUMBER_OF_BUBBLE*2, ... (up to i+NUMBER_OF_BUBBLE*8) belongs to the same bunch.
+ int groupIdx = index / NUMBER_OF_BUBBLE;
+ // The bubbles within the same bunch applies the same uniforms uStartEndPosition[idx] & uPercentage[idx]
+ int idx = index - groupIdx*NUMBER_OF_BUBBLE;
+ float percentage = uPercentage[idx];
+ // early out if uPercentage is (zero || one) setting position to zero (zero sized triangles)
+ if( percentage <= 0.0 || percentage >= 1.0 )
+ {
+ gl_Position = vec4(0.0);
+ return;
+ }
+ vec4 startAndEnd = uStartEndPosition[idx];
+ // The final position is added up different offset for bubbles
+ startAndEnd.zw += uOffset[groupIdx];
+
+ // increase the bubble size from 0% to 100% during the first 1/5 of movement & apply the dynamic scale
+ // the new xy value containes both the new scale and new bubble position
+ position.xy *= uDynamicScale*min(percentage*5.0, 1.0);
+ position.xy += mix(startAndEnd.xy, startAndEnd.zw, percentage);
+ // The gravity is g*t*t on the y direction
+ position.y += uGravity * pow(percentage, 2.0);
+ gl_Position = uMvpMatrix * position;
+
+ // Add multiple bubble shapes in the effect
+ vTexCoord = aTexCoord;
+ vPercentage = percentage;
+ // Use the emit position color for the bubble
+ vEffectTexCoord = startAndEnd.xy * uInvertedMovementArea + vec2(0.5);
+}
\ No newline at end of file
--- /dev/null
+precision highp float;
+uniform vec3 uHSVDelta;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+
+float rand(vec2 co)
+{
+ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
+}
+
+vec3 rgb2hsv(vec3 c)
+{
+ vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
+ vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
+ vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
+
+ float d = q.x - min(q.w, q.y);
+ float e = 1.0e-10;
+ return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
+}
+
+vec3 hsv2rgb(vec3 c)
+{
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
+ return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
+}
+
+void main()
+{
+ vec4 color = texture2D(sTexture, vTexCoord);
+ vec3 hsvColor = rgb2hsv( color.rgb );
+ // modify the hsv Value
+ hsvColor += uHSVDelta * rand(vTexCoord);
+ // if the new vale exceeds one, then decrease it
+ hsvColor -= max(hsvColor*2.0 - vec3(2.0), 0.0);
+ // if the new vale drops below zero, then increase it
+ hsvColor -= min(hsvColor*2.0, 0.0);
+ color = vec4( hsv2rgb( hsvColor ), 1.0 );
+ gl_FragColor = color;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+attribute mediump vec2 aTexCoord;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+varying mediump vec2 vTexCoord;
+
+void main()
+{
+ gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy,0.0,1.0);
+ vTexCoord = aTexCoord;
+}
--- /dev/null
+INPUT mediump vec2 vPosition;
+INPUT mediump vec2 vRectSize;
+
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform mediump float blurRadius;
+
+void main()
+{
+ mediump vec2 blur = 1.0 - smoothstep( vRectSize - blurRadius * 2.0, vRectSize, abs( vPosition ) );
+ OUT_COLOR = vec4(mixColor, 1.0) * uColor;
+ OUT_COLOR.a *= blur.x * blur.y;
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+OUTPUT mediump vec2 vPosition;
+OUTPUT mediump vec2 vRectSize;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec2 extraSize;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump float blurRadius;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize + blurRadius * 2.0;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ vRectSize = visualSize / 2.0;
+ vPosition = aPosition* visualSize;
+ return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 vPosition;
+INPUT mediump vec2 vRectSize;
+INPUT mediump float vCornerRadius;
+
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;
+ OUT_COLOR = vec4(mixColor, 1.0) * uColor;
+ OUT_COLOR.a *= 1.0 - smoothstep( -1.0, 1.0, dist );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+OUTPUT mediump vec2 vPosition;
+OUTPUT mediump vec2 vRectSize;
+OUTPUT mediump float vCornerRadius;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec2 extraSize;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump float cornerRadius;
+uniform mediump float cornerRadiusPolicy;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ mediump float minSize = min( visualSize.x, visualSize.y );
+ vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);
+ vCornerRadius = min( vCornerRadius, minSize * 0.5 );
+ vRectSize = visualSize / 2.0 - vCornerRadius;
+ vPosition = aPosition* visualSize;
+ return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
\ No newline at end of file
--- /dev/null
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ OUT_COLOR = vec4(mixColor, 1.0) * uColor;
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump vec2 extraSize;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
\ No newline at end of file
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform vec4 uColor;
+
+void main()
+{
+ gl_FragColor = texture2D(sTexture, vTexCoord);
+ gl_FragColor *= uColor;
+}
--- /dev/null
+precision mediump float;
+attribute mediump vec2 aPosition;
+varying mediump vec2 vTexCoord;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump vec3 uSize;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition * uSize.xy, 0.0, 1.0);
+ vTexCoord = aPosition + vec2(0.5);
+ gl_Position = uMvpMatrix * vertexPosition;
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp vec4 uSamplerRect;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+varying mediump vec2 vTexCoord;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump vec3 uSize;
+uniform mediump vec4 uTextureRect;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ vTexCoord = aPosition + vec2(0.5);
+ vTexCoord = mix(uTextureRect.xy, uTextureRect.zw, vTexCoord);
+
+ gl_Position = vertexPosition;
+}
\ No newline at end of file
--- /dev/null
+varying float vPercentage;
+varying mediump vec2 vTexCoord;
+
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform vec4 uTextureRect;
+
+float rand(vec2 co)
+{
+ return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
+}
+
+void main()
+{
+ //Calculate the randomness
+ float offsetS = rand(vTexCoord * vPercentage) - vTexCoord.s;
+ float offsetT = rand(vec2(vTexCoord.t * vPercentage, vTexCoord.s * vPercentage)) - vTexCoord.t;
+ vec2 lookupCoord = vTexCoord + vec2(offsetS, offsetT) * vPercentage;
+ gl_FragColor = texture2D(sTexture, lookupCoord) * uColor;
+ gl_FragColor.a *= 1.0 - vPercentage;
+}
\ No newline at end of file
--- /dev/null
+attribute mediump vec2 aPosition;
+
+uniform mediump mat4 uMvpMatrix;
+uniform vec3 uSize;
+uniform vec4 uTextureRect;
+
+uniform float uPercentage;
+uniform vec3 uSaddleParam;
+uniform vec2 uTranslation;
+uniform vec2 uRotation;
+uniform float uToNext;
+
+varying float vPercentage;
+varying vec2 vTexCoord;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ vertexPosition = uMvpMatrix * vertexPosition;
+ gl_Position = vertexPosition;
+
+ vec2 texCoord = aPosition + vec2(0.5);
+ vTexCoord = texCoord;
+
+ //Calculate the distortion value given the dissolve central line
+ vec2 value = texCoord + uTranslation;
+ mat2 rotateMatrix = mat2(uRotation.s, uRotation.t, -uRotation.t, uRotation.s);
+ value = rotateMatrix * value;
+ if(uToNext == 1.0)
+ value.s = uSaddleParam[2] + value.s;
+ float delay = value.t * value.t / uSaddleParam[0] - value.s * value.s / uSaddleParam[1];
+ vPercentage = clamp(uPercentage * 2.0 - 0.5 * sin(delay * 1.571) - 0.5, 0.0, 1.0);
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+
+uniform mediump float uGlowBoundary;
+uniform mediump vec2 uOutlineParams;
+uniform lowp vec4 uOutlineColor;
+uniform lowp vec4 uShadowColor;
+uniform mediump vec2 uShadowOffset;
+uniform lowp vec4 uGlowColor;
+uniform lowp float uDoOutline;
+uniform lowp float uDoShadow;
+uniform lowp float uDoGlow;
+
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ // sample distance field
+ mediump float smoothing = 0.5;
+
+ mediump float distance = texture2D(sTexture, vTexCoord).a;
+ mediump float smoothWidth = fwidth(distance);
+ mediump float alphaFactor = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);
+ lowp vec4 color;
+
+ if (uDoShadow == 0.0)
+ {
+ mediump float alpha = uColor.a * alphaFactor;
+ lowp vec4 rgb = uColor;
+
+ if (uDoOutline > 0.0)
+ {
+ mediump float outlineWidth = uOutlineParams[1] + smoothWidth;
+ mediump float outlineBlend = smoothstep(uOutlineParams[0] - outlineWidth, uOutlineParams[0] + outlineWidth, distance);
+ alpha = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);
+ rgb = mix(uOutlineColor, uColor, outlineBlend);
+ }
+
+ if (uDoGlow > 0.0)
+ {
+ rgb = mix(uGlowColor, rgb, alphaFactor);
+ alpha = smoothstep(uGlowBoundary, smoothing, distance);
+ }
+
+ // set fragment color
+ color = vec4(rgb.rgb, alpha);
+ }
+
+ else // (uDoShadow > 0.0)
+ {
+ mediump float shadowDistance = texture2D(sTexture, vTexCoord - uShadowOffset).a;
+ mediump float inText = alphaFactor;
+ mediump float inShadow = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, shadowDistance);
+
+ // inside object, outside shadow
+ if (inText == 1.0)
+ {
+ color = uColor;
+ }
+ // inside object, outside shadow
+ else if ((inText != 0.0) && (inShadow == 0.0))
+ {
+ color = uColor;
+ color.a *= inText;
+ }
+ // outside object, completely inside shadow
+ else if ((inText == 0.0) && (inShadow == 1.0))
+ {
+ color = uShadowColor;
+ }
+ // inside object, completely inside shadow
+ else if ((inText != 0.0) && (inShadow == 1.0))
+ {
+ color = mix(uShadowColor, uColor, inText);
+ color.a = uShadowColor.a;
+ }
+ // inside object, inside shadow's border
+ else if ((inText != 0.0) && (inShadow != 0.0))
+ {
+ color = mix(uShadowColor, uColor, inText);
+ color.a *= max(inText, inShadow);
+ }
+ // inside shadow's border
+ else if (inShadow != 0.0)
+ {
+ color = uShadowColor;
+ color.a *= inShadow;
+ }
+ // outside shadow and object
+ else
+ {
+ color.a = 0.0;
+ }
+ }
+
+ gl_FragColor = color;
+}
\ No newline at end of file
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 effectColor;
+
+void main()
+{
+ gl_FragColor = effectColor;
+ gl_FragColor.a *= texture2D( sTexture, vTexCoord).a;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+varying mediump vec2 vTexCoord;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump vec3 uSize;
+uniform mediump vec3 effectOffset;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ vertexPosition.xyz += effectOffset;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ vTexCoord = aPosition + vec2(0.5);
+ gl_Position = vertexPosition;
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uEffectColor;
+
+void main()
+{
+ gl_FragColor = uEffectColor;
+ gl_FragColor.a *= texture2D( sTexture, vTexCoord).a;
+}
\ No newline at end of file
--- /dev/null
+precision highp float;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform vec2 uTexScale;
+uniform vec3 uCoefficient;
+
+void main()
+{
+ vec4 color = uCoefficient.x * texture2D( sTexture, vTexCoord + vec2(0.0, -uTexScale.y) );
+ color += uCoefficient.y * texture2D( sTexture, vTexCoord );
+ color += uCoefficient.z * texture2D( sTexture, vTexCoord + vec2(0.0, uTexScale.y) );
+ gl_FragColor = color;
+}
\ No newline at end of file
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform mediump vec2 uSampleOffsets[NUM_SAMPLES];
+uniform mediump float uSampleWeights[NUM_SAMPLES];
+
+void main()
+{
+ mediump vec4 col = texture2D(sTexture, vTexCoord + uSampleOffsets[0]) * uSampleWeights[0];
+ for (int i=1; i<NUM_SAMPLES; ++i)
+ {
+ col += texture2D(sTexture, vTexCoord + uSampleOffsets[i]) * uSampleWeights[i];
+ }
+ gl_FragColor = col;
+}
--- /dev/null
+#define TEXTURE_BASECOLOR
+
+uniform sampler2D uBaseColorSampler;
+uniform int uBaseColorTexCoordIndex;
--- /dev/null
+#define TEXTURE_EMIT
+
+uniform sampler2D uEmissiveSampler;
+uniform int uEmissiveTexCoordIndex;
+uniform vec3 uEmissiveFactor;
--- /dev/null
+#version 300 es
+precision highp float;
--- /dev/null
+#define TEXTURE_IBL
+
+uniform sampler2D ubrdfLUT;
+uniform samplerCube uDiffuseEnvSampler;
+uniform samplerCube uSpecularEnvSampler;
+uniform vec4 uScaleIBLAmbient;
+uniform highp float uMipmapLevel;
--- /dev/null
+#define TEXTURE_METALLICROUGHNESS
+
+uniform sampler2D uMetallicRoughnessSampler;
+uniform int uMetallicRoughnessTexCoordIndex;
--- /dev/null
+#define TEXTURE_NORMAL
+
+uniform sampler2D uNormalSampler;
+uniform float uNormalScale;
+uniform int uNormalTexCoordIndex;
--- /dev/null
+#define TEXTURE_OCCLUSION
+
+uniform sampler2D uOcclusionSampler;
+uniform int uOcclusionTexCoordIndex;
+uniform float uOcclusionStrength;
--- /dev/null
+uniform lowp vec3 uLightColor;
+uniform lowp vec4 uBaseColorFactor;
+uniform lowp vec2 uMetallicRoughnessFactors;
+uniform lowp int alphaMode;
+uniform lowp float alphaCutoff;
+
+in lowp vec2 vUV[2];
+in lowp mat3 vTBN;
+in lowp vec4 vColor;
+flat in int visLight;
+in highp vec3 vLightDirection;
+in highp vec3 vPositionToCamera;
+
+out vec4 FragColor;
+
+struct PBRInfo
+{
+ mediump float NdotL; // cos angle between normal and light direction
+ mediump float NdotV; // cos angle between normal and view direction
+ mediump float NdotH; // cos angle between normal and half vector
+ mediump float VdotH; // cos angle between view direction and half vector
+ mediump vec3 reflectance0; // full reflectance color (normal incidence angle)
+ mediump vec3 reflectance90; // reflectance color at grazing angle
+ lowp float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])
+};
+
+const float M_PI = 3.141592653589793;
+const float c_MinRoughness = 0.04;
+
+vec3 getNormal()
+{
+#ifdef TEXTURE_NORMAL
+ lowp vec3 n = texture( uNormalSampler, vUV[uNormalTexCoordIndex] ).rgb;
+ n = normalize( vTBN * ( ( 2.0 * n - 1.0 ) * vec3( uNormalScale, uNormalScale, 1.0 ) ) );
+#else
+ lowp vec3 n = normalize( vTBN[2].xyz );
+#endif
+ return n;
+}
+
+vec3 specularReflection( PBRInfo pbrInputs )
+{
+ return pbrInputs.reflectance0 + ( pbrInputs.reflectance90 - pbrInputs.reflectance0 ) * pow( clamp( 1.0 - pbrInputs.VdotH, 0.0, 1.0 ), 5.0 );
+}
+
+float geometricOcclusion( PBRInfo pbrInputs )
+{
+ mediump float NdotL = pbrInputs.NdotL;
+ mediump float NdotV = pbrInputs.NdotV;
+ lowp float r = pbrInputs.alphaRoughness;
+
+ lowp float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
+ lowp float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
+ return attenuationL * attenuationV;
+}
+
+float microfacetDistribution(PBRInfo pbrInputs)
+{
+ mediump float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;
+ lowp float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;
+ return roughnessSq / (M_PI * f * f);
+}
+
+vec3 linear( vec3 color )
+{
+ return pow(color,vec3(2.2));
+}
+
+void main()
+{
+ // Metallic and Roughness material properties are packed together
+ // In glTF, these factors can be specified by fixed scalar values
+ // or from a metallic-roughness map
+ lowp float metallic = uMetallicRoughnessFactors.x;
+ lowp float perceptualRoughness = uMetallicRoughnessFactors.y;
+
+ // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
+ // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
+#ifdef TEXTURE_METALLICROUGHNESS
+ lowp vec4 metrou = texture(uMetallicRoughnessSampler, vUV[uMetallicRoughnessTexCoordIndex]);
+ metallic = metrou.b * metallic;
+ perceptualRoughness = metrou.g * perceptualRoughness;
+#endif
+
+ metallic = clamp(metallic, 0.0, 1.0);
+ perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
+ // Roughness is authored as perceptual roughness; as is convention,
+ // convert to material roughness by squaring the perceptual roughness [2].
+ lowp float alphaRoughness = perceptualRoughness * perceptualRoughness;
+
+#ifdef TEXTURE_BASECOLOR
+ // The albedo may be defined from a base texture or a flat color
+ lowp vec4 baseColor = texture(uBaseColorSampler, vUV[uBaseColorTexCoordIndex]) * uBaseColorFactor;
+ baseColor = vec4(linear(baseColor.rgb), baseColor.w);
+#else
+ lowp vec4 baseColor = vColor * uBaseColorFactor;
+#endif
+
+ if( alphaMode == 0 )
+ {
+ baseColor.w = 1.0;
+ }
+ else if( alphaMode == 1 )
+ {
+ if( baseColor.w >= alphaCutoff )
+ {
+ baseColor.w = 1.0;
+ }
+ else
+ {
+ baseColor.w = 0.0;
+ }
+ }
+
+ lowp vec3 f0 = vec3(0.04);
+ lowp vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
+ diffuseColor *= ( 1.0 - metallic );
+ lowp vec3 specularColor = mix(f0, baseColor.rgb, metallic);
+
+ // Compute reflectance.
+ lowp float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
+
+ // For typical incident reflectance range (between 4% to 100%) set the grazing reflectance to 100% for typical fresnel effect.
+ // For very low reflectance range on highly diffuse objects (below 4%), incrementally reduce grazing reflecance to 0%.
+ lowp float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
+ lowp vec3 specularEnvironmentR0 = specularColor.rgb;
+ lowp vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
+
+ mediump vec3 n = getNormal(); // normal at surface point
+ mediump vec3 v = normalize(vPositionToCamera); // Vector from surface point to camera
+ mediump vec3 l = normalize(vLightDirection); // Vector from light to surface point
+ mediump vec3 h = normalize(l+v); // Half vector between both l and v
+ mediump vec3 reflection = -normalize(reflect(v, n));
+
+ mediump float NdotL = clamp(dot(n, l), 0.001, 1.0);
+ mediump float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
+ mediump float NdotH = dot(n, h);
+ mediump float LdotH = dot(l, h);
+ mediump float VdotH = dot(v, h);
+
+ PBRInfo pbrInputs = PBRInfo(
+ NdotL,
+ NdotV,
+ NdotH,
+ VdotH,
+ specularEnvironmentR0,
+ specularEnvironmentR90,
+ alphaRoughness
+ );
+
+ // Calculate the shading terms for the microfacet specular shading model
+ lowp vec3 color = vec3(0.0);
+ if( visLight == 1 )
+ {
+ lowp vec3 F = specularReflection( pbrInputs );
+ lowp float G = geometricOcclusion( pbrInputs );
+ lowp float D = microfacetDistribution( pbrInputs );
+
+ // Calculation of analytical lighting contribution
+ lowp vec3 diffuseContrib = ( 1.0 - F ) * ( diffuseColor / M_PI );
+ lowp vec3 specContrib = F * G * D / ( 4.0 * NdotL * NdotV );
+ // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
+ color = NdotL * uLightColor * (diffuseContrib + specContrib);
+ }
+
+#ifdef TEXTURE_IBL
+ lowp float lod = ( perceptualRoughness * uMipmapLevel );
+ // retrieve a scale and bias to F0. See [1], Figure 3
+ lowp vec3 brdf = linear( texture( ubrdfLUT, vec2( NdotV, 1.0 - perceptualRoughness ) ).rgb );
+ lowp vec3 diffuseLight = linear( texture( uDiffuseEnvSampler, n ).rgb );
+ lowp vec3 specularLight = linear( textureLod( uSpecularEnvSampler, reflection, lod ).rgb );
+
+ lowp vec3 diffuse = diffuseLight * diffuseColor * uScaleIBLAmbient.x;
+ lowp vec3 specular = specularLight * ( specularColor * brdf.x + brdf.y ) * uScaleIBLAmbient.y;
+ color += ( diffuse + specular );
+#endif
+
+#ifdef TEXTURE_OCCLUSION
+ lowp float ao = texture( uOcclusionSampler, vUV[uOcclusionTexCoordIndex] ).r;
+ color = mix( color, color * ao, uOcclusionStrength );
+#endif
+
+#ifdef TEXTURE_EMIT
+ lowp vec3 emissive = linear( texture( uEmissiveSampler, vUV[uEmissiveTexCoordIndex] ).rgb ) * uEmissiveFactor;
+ color += emissive;
+#endif
+
+ FragColor = vec4( pow( color,vec3( 1.0 / 2.2 ) ), baseColor.a );
+}
--- /dev/null
+in highp vec3 aPosition;
+in mediump vec2 aTexCoord0;
+in mediump vec2 aTexCoord1;
+in lowp vec3 aNormal;
+in lowp vec4 aTangent;
+in lowp vec4 aVertexColor;
+
+uniform mediump vec3 uSize;
+uniform mediump mat4 uModelMatrix;
+uniform mediump mat4 uViewMatrix;
+uniform mediump mat4 uProjection;
+uniform lowp int uLightType;
+uniform mediump vec3 uLightVector;
+uniform lowp int uIsColor;
+
+out lowp vec2 vUV[2];
+out lowp mat3 vTBN;
+out lowp vec4 vColor;
+flat out int visLight;
+out highp vec3 vLightDirection;
+out highp vec3 vPositionToCamera;
+
+void main()
+{
+ highp vec4 invY = vec4(1.0, -1.0, 1.0, 1.0);
+ highp vec4 positionW = uModelMatrix * vec4( aPosition * uSize, 1.0 );
+ highp vec4 positionV = uViewMatrix * ( invY * positionW );
+
+ vPositionToCamera = transpose( mat3( uViewMatrix ) ) * ( -vec3( positionV.xyz / positionV.w ) );
+ vPositionToCamera *= invY.xyz;
+
+ lowp vec3 bitangent = cross(aNormal, aTangent.xyz) * aTangent.w;
+ vTBN = mat3( uModelMatrix ) * mat3(aTangent.xyz, bitangent, aNormal);
+
+ vUV[0] = aTexCoord0;
+ vUV[1] = aTexCoord1;
+
+ visLight = 1;
+ if( uLightType == 1 )
+ {
+ vLightDirection = ( invY.xyz * uLightVector ) - ( positionW.xyz / positionW.w );
+ }
+ else if( uLightType == 2 )
+ {
+ vLightDirection = -( invY.xyz * uLightVector );
+ }
+ else
+ {
+ visLight = 0;
+ }
+
+ vColor = vec4( 1.0 );
+ if( uIsColor == 1 )
+ {
+ vColor = aVertexColor;
+ }
+
+ gl_Position = uProjection * positionV; // needs w for proper perspective correction
+ gl_Position = gl_Position/gl_Position.w;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump mat3 uAlignmentMatrix;
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vPosition;
+varying mediump vec2 vRectSize;
+varying mediump float vCornerRadius;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump float cornerRadius;
+uniform mediump float cornerRadiusPolicy;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ mediump float minSize = min( visualSize.x, visualSize.y );
+ vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);
+ vCornerRadius = min( vCornerRadius, minSize * 0.5 );
+ vRectSize = visualSize * 0.5 - vCornerRadius;
+ vPosition = aPosition * visualSize;
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;
+
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump mat3 uAlignmentMatrix;
+varying mediump vec2 vTexCoord;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;
+
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
\ No newline at end of file
--- /dev/null
+uniform sampler2D sTexture; // sampler1D?
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vPosition;
+varying mediump vec2 vRectSize;
+varying mediump float vCornerRadius;
+
+void main()
+{
+ mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;
+ gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor;
+ gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );
+}
--- /dev/null
+uniform sampler2D sTexture; // sampler1D?
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+varying mediump vec2 vTexCoord;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor;
+}
--- /dev/null
+uniform sampler2D sTexture; // sampler1D?
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vPosition;
+varying mediump vec2 vRectSize;
+varying mediump float vCornerRadius;
+
+void main()
+{
+ mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;
+ gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor;
+ gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );
+}
--- /dev/null
+uniform sampler2D sTexture; // sampler1D?
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+varying mediump vec2 vTexCoord;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump mat3 uAlignmentMatrix;
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vPosition;
+varying mediump vec2 vRectSize;
+varying mediump float vCornerRadius;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump float cornerRadius;
+uniform mediump float cornerRadiusPolicy;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ mediump float minSize = min( visualSize.x, visualSize.y );
+ vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);
+ vCornerRadius = min( vCornerRadius, minSize * 0.5 );
+ vRectSize = visualSize * 0.5 - vCornerRadius;
+ vPosition = aPosition * visualSize;
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+
+ vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump mat3 uAlignmentMatrix;
+varying mediump vec2 vTexCoord;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+
+ vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+
+uniform mediump mat4 uMvpMatrix;
+uniform vec3 uSize;
+uniform vec4 uTextureRect;
+
+varying vec2 vTexCoord;
+
+uniform mediump vec2 uTopLeft;
+uniform mediump vec2 uBottomRight;
+
+void main()
+{
+ mediump vec4 position = vec4(aPosition, 0.0, 1.0);
+ position.xyz *= uSize;
+ gl_Position = uMvpMatrix * position;
+
+ // The line below is doing the same as the following commented lines:
+ //
+ // vec2 imageSize = uTextureRect.zw - uTextureRect.xy;
+ // vec2 topLeft = uTextureRect.xy + uTopLeft * imageSize;
+ // vec2 bottomRight = uTextureRect.xy + uBottomRight * imageSize;
+ // vec2 texCoord = (aTexCoord - uTextureRect.xy) / imageSize;
+ // vTexCoord = topLeft + texCoord * ( bottomRight - topLeft );
+
+ vec2 texCoord = aPosition + vec2(0.5);
+ vTexCoord = uTextureRect.xy + uTopLeft * ( uTextureRect.zw - uTextureRect.xy ) + ( texCoord - uTextureRect.xy ) * ( uBottomRight - uTopLeft );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 vTexCoord;
+
+uniform sampler2D sTexture;
+uniform mediump vec4 uAtlasRect;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ mediump vec2 texCoord = clamp( mix( uAtlasRect.xy, uAtlasRect.zw, vTexCoord ), uAtlasRect.xy, uAtlasRect.zw );
+ OUT_COLOR = TEXTURE( sTexture, texCoord ) * uColor * vec4( mixColor, 1.0 );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 vTexCoord;
+
+uniform sampler2D sTexture;
+uniform mediump vec4 uAtlasRect;
+
+// WrapMode -- 0: CLAMP; 1: REPEAT; 2: REFLECT;
+uniform lowp vec2 wrapMode;
+
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+mediump float wrapCoordinate( mediump vec2 range, mediump float coordinate, lowp float wrap )
+
+{
+ mediump float coord;
+ if( wrap > 1.5 )\n // REFLECT
+ coord = 1.0-abs(fract(coordinate*0.5)*2.0 - 1.0);
+ else \n// warp == 0 or 1
+ coord = mix(coordinate, fract( coordinate ), wrap);
+ return clamp( mix(range.x, range.y, coord), range.x, range.y );
+}
+
+void main()
+{
+ mediump vec2 texCoord = vec2( wrapCoordinate( uAtlasRect.xz, vTexCoord.x, wrapMode.x ),
+ wrapCoordinate( uAtlasRect.yw, vTexCoord.y, wrapMode.y ) );
+ OUT_COLOR = TEXTURE( sTexture, texCoord ) * uColor * vec4( mixColor, 1.0 );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 vTexCoord;
+
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ OUT_COLOR = TEXTURE( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+INPUT mediump vec2 vTexCoord;
+INPUT mediump vec2 vPosition;
+INPUT mediump vec2 vRectSize;
+INPUT mediump float vCornerRadius;
+
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;
+ mediump float opacity = 1.0 - smoothstep( -1.0, 1.0, dist );
+
+ OUT_COLOR = TEXTURE( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );
+ OUT_COLOR.a *= opacity;
+ OUT_COLOR.rgb *= mix( 1.0, opacity, preMultipliedAlpha );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+OUTPUT mediump vec2 vTexCoord;
+OUTPUT mediump vec2 vPosition;
+OUTPUT mediump vec2 vRectSize;
+OUTPUT mediump float vCornerRadius;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump vec4 pixelArea;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump float cornerRadius;
+uniform mediump float cornerRadiusPolicy;
+uniform mediump vec2 extraSize;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ mediump float minSize = min( visualSize.x, visualSize.y );
+ vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);
+ vCornerRadius = min( vCornerRadius, minSize * 0.5 );
+ vRectSize = visualSize * 0.5 - vCornerRadius;
+ vPosition = aPosition* visualSize;
+ return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+ vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+OUTPUT mediump vec2 vTexCoord;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump vec4 pixelArea;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump vec2 extraSize;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+ vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );
+}
\ No newline at end of file
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vLightDirection;
+varying mediump vec3 vHalfVector;
+uniform sampler2D sDiffuse;
+uniform sampler2D sNormal;
+uniform sampler2D sGloss;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ vec4 texture = texture2D( sDiffuse, vTexCoord );
+ vec3 normal = normalize( texture2D( sNormal, vTexCoord ).xyz * 2.0 - 1.0 );
+ vec4 glossMap = texture2D( sGloss, vTexCoord );
+ vec4 visualMixColor = vec4( mixColor, 1.0 );
+
+ float lightDiffuse = max( 0.0, dot( normal, normalize( vLightDirection ) ) );
+ lightDiffuse = lightDiffuse * 0.5 + 0.5;
+
+ float shininess = pow ( max ( dot ( normalize( vHalfVector ), normal ), 0.0 ), 16.0 );
+
+ gl_FragColor = vec4( texture.rgb * uColor.rgb * visualMixColor.rgb * lightDiffuse + shininess * glossMap.rgb, texture.a * uColor.a * visualMixColor.a );
+}
--- /dev/null
+attribute highp vec3 aPosition;
+attribute highp vec2 aTexCoord;
+attribute highp vec3 aNormal;
+attribute highp vec3 aTangent;
+attribute highp vec3 aBiNormal;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vLightDirection;
+varying mediump vec3 vHalfVector;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat4 uViewMatrix;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 lightPosition;
+uniform mediump vec2 uStageOffset;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform mediump vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ float scaleFactor = min( visualSize.x, visualSize.y );
+ vec3 originFlipY =vec3(origin.x, -origin.y, 0.0);
+ vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
+ vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);
+ return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );
+}
+
+void main()
+{
+ vec4 normalisedVertexPosition = ComputeVertexPosition();
+ vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ vec4 mvVertexPosition = uModelView * normalisedVertexPosition;
+
+ vec3 tangent = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aTangent );
+ vec3 binormal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aBiNormal );
+ vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );
+
+ vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );
+ mvLightPosition = uViewMatrix * mvLightPosition;
+ vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );
+ vLightDirection.x = dot( vectorToLight, tangent );
+ vLightDirection.y = dot( vectorToLight, binormal );
+ vLightDirection.z = dot( vectorToLight, normal );
+
+ vec3 viewDirection = normalize( -mvVertexPosition.xyz );
+ vec3 halfVector = normalize( viewDirection + vectorToLight );
+ vHalfVector.x = dot( halfVector, tangent );
+ vHalfVector.y = dot( halfVector, binormal );
+ vHalfVector.z = dot( halfVector, normal );
+
+ vTexCoord = aTexCoord;
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vIllumination;
+varying mediump float vSpecular;
+uniform sampler2D sDiffuse;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ vec4 texture = texture2D( sDiffuse, vTexCoord );
+ vec4 visualMixColor = vec4( mixColor, 1.0 );
+ gl_FragColor = vec4( vIllumination.rgb * texture.rgb * uColor.rgb * visualMixColor.rgb + vSpecular * 0.3, texture.a * uColor.a * visualMixColor.a );
+}
--- /dev/null
+attribute highp vec3 aPosition;
+attribute highp vec2 aTexCoord;
+attribute highp vec3 aNormal;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vIllumination;
+varying mediump float vSpecular;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat4 uViewMatrix;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 lightPosition;
+uniform mediump vec2 uStageOffset;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform mediump vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ float scaleFactor = min( visualSize.x, visualSize.y );
+ vec3 originFlipY =vec3(origin.x, -origin.y, 0.0);
+ vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
+ vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);
+ return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );
+}
+
+void main()
+{
+ vec4 normalisedVertexPosition = ComputeVertexPosition();
+ vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ //Illumination in Model-View space - Transform attributes and uniforms
+ vec4 mvVertexPosition = uModelView * normalisedVertexPosition;
+ vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );
+
+ vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );
+ mvLightPosition = uViewMatrix * mvLightPosition;
+ vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );
+
+ vec3 viewDirection = normalize( -mvVertexPosition.xyz );
+
+ float lightDiffuse = dot( vectorToLight, normal );
+ lightDiffuse = max( 0.0,lightDiffuse );
+ vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
+
+ vec3 reflectDirection = reflect( -vectorToLight, normal );
+ vSpecular = pow( max( dot( reflectDirection, viewDirection ), 0.0 ), 4.0 );
+
+ vTexCoord = aTexCoord;
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+varying mediump vec3 vIllumination;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a ) * vec4( mixColor, 1.0 );
+}
--- /dev/null
+attribute highp vec3 aPosition;
+attribute highp vec3 aNormal;
+varying mediump vec3 vIllumination;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat4 uViewMatrix;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 lightPosition;
+uniform mediump vec2 uStageOffset;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform mediump vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ float scaleFactor = min( visualSize.x, visualSize.y );
+ vec3 originFlipY =vec3(origin.x, -origin.y, 0.0);
+ vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
+ vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);
+ return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );
+}
+
+void main()
+{
+ vec4 normalisedVertexPosition = ComputeVertexPosition();
+ vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ //Illumination in Model-View space - Transform attributes and uniforms
+ vec4 mvVertexPosition = uModelView * normalisedVertexPosition;
+ vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;
+
+ vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );
+ mvLightPosition = uViewMatrix * mvLightPosition;
+ vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );
+
+ float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
+ vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
+
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vLightDirection;
+varying mediump vec3 vHalfVector;
+uniform sampler2D sDiffuse;
+uniform sampler2D sNormal;
+uniform sampler2D sGloss;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ vec4 texture = texture2D( sDiffuse, vTexCoord );
+ vec3 normal = normalize( texture2D( sNormal, vTexCoord ).xyz * 2.0 - 1.0 );
+ vec4 glossMap = texture2D( sGloss, vTexCoord );
+
+ float lightDiffuse = max( 0.0, dot( normal, normalize(vLightDirection) ) );
+ lightDiffuse = lightDiffuse * 0.5 + 0.5;
+
+ float shininess = pow (max (dot (normalize( vHalfVector ), normal), 0.0), 16.0);
+
+ gl_FragColor = vec4( texture.rgb * uColor.rgb * lightDiffuse + shininess * glossMap.rgb, texture.a * uColor.a);
+}
--- /dev/null
+attribute highp vec3 aPosition;
+attribute highp vec2 aTexCoord;
+attribute highp vec3 aNormal;
+attribute highp vec3 aTangent;
+attribute highp vec3 aBiNormal;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vLightDirection;
+varying mediump vec3 vHalfVector;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 uLightPosition;
+
+void main()
+{
+ vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);
+ vertexPosition = uObjectMatrix * vertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);
+ vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);
+
+ vec3 tangent = normalize(uNormalMatrix * aTangent);
+ vec3 binormal = normalize(uNormalMatrix * aBiNormal);
+ vec3 normal = normalize(uNormalMatrix * aNormal);
+
+ vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );
+ vLightDirection.x = dot(vecToLight, tangent);
+ vLightDirection.y = dot(vecToLight, binormal);
+ vLightDirection.z = dot(vecToLight, normal);
+
+ vec3 viewDir = normalize(-vertPos.xyz);
+ vec3 halfVector = normalize(viewDir + vecToLight);
+ vHalfVector.x = dot(halfVector, tangent);
+ vHalfVector.y = dot(halfVector, binormal);
+ vHalfVector.z = dot(halfVector, normal);
+
+ vTexCoord = aTexCoord;
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vIllumination;
+varying mediump float vSpecular;
+uniform sampler2D sDiffuse;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ vec4 texture = texture2D( sDiffuse, vTexCoord );
+ gl_FragColor = vec4( vIllumination.rgb * texture.rgb * uColor.rgb + vSpecular * 0.3, texture.a * uColor.a);
+}
--- /dev/null
+attribute highp vec3 aPosition;
+attribute highp vec2 aTexCoord;
+attribute highp vec3 aNormal;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vIllumination;
+varying mediump float vSpecular;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 uLightPosition;
+
+void main()
+{
+ vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);
+ vertexPosition = uObjectMatrix * vertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ //Illumination in Model-View space - Transform attributes and uniforms
+ vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);
+ vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);
+ vec3 normal = normalize(uNormalMatrix * aNormal);
+
+ vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );
+ vec3 viewDir = normalize(-vertPos.xyz);
+
+ vec3 halfVector = normalize(viewDir + vecToLight);
+
+ float lightDiffuse = dot( vecToLight, normal );
+ lightDiffuse = max(0.0,lightDiffuse);
+ vIllumination = vec3(lightDiffuse * 0.5 + 0.5);
+
+ vec3 reflectDir = reflect(-vecToLight, normal);
+ vSpecular = pow( max(dot(reflectDir, viewDir), 0.0), 4.0 );
+
+ vTexCoord = aTexCoord;
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+varying mediump vec3 vIllumination;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a);
+}
--- /dev/null
+attribute highp vec3 aPosition;
+attribute highp vec2 aTexCoord;
+attribute highp vec3 aNormal;
+varying mediump vec3 vIllumination;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 uLightPosition;
+
+void main()
+{
+ vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);
+ vertexPosition = uObjectMatrix * vertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ //Illumination in Model-View space - Transform attributes and uniforms
+ vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);
+ vec3 normal = uNormalMatrix * aNormal;
+ vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);
+ vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );
+
+ float lightDiffuse = max( dot( vecToLight, normal ), 0.0 );
+ vIllumination = vec3(lightDiffuse * 0.5 + 0.5);
+
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+
+uniform sampler2D sTexture;
+uniform vec4 uColor;
+
+uniform vec2 uObjectFadeStart;
+uniform vec2 uObjectFadeEnd;
+uniform float uAlphaScale;
+uniform float uBlurTexCoordScale;
+uniform float uNumSamples;
+uniform float uRecipNumSamples;
+uniform float uRecipNumSamplesMinusOne;
+
+// inputs
+varying vec2 vModelSpaceCenterToPos;
+varying vec2 vScreenSpaceVelocityVector;
+varying float vSpeed;
+varying vec2 vTexCoord;
+
+void main()
+{
+ // calculate an alpha value that will fade the object towards its extremities, we need this to avoid an unsightly hard edge between color values of
+ // the blurred object and the unblurred background. Use smoothstep also to hide any hard edges (discontinuities) in rate of change of this alpha gradient
+ vec2 centerToPixel = abs(vModelSpaceCenterToPos);
+ vec2 fadeToEdges = smoothstep(0.0, 1.0, 1.0 - ((centerToPixel - uObjectFadeStart) / (uObjectFadeEnd - uObjectFadeStart)));
+ float fadeToEdgesScale = fadeToEdges.x * fadeToEdges.y * uAlphaScale; // apply global scaler
+ fadeToEdgesScale = mix(1.0, fadeToEdgesScale, vSpeed);// fade proportional to speed, so opaque when at rest
+
+ // scale velocity vector by user requirements
+ vec2 velocity = vScreenSpaceVelocityVector * uBlurTexCoordScale;
+
+ // standard actor texel
+ vec4 colActor = texture2D(sTexture, vTexCoord);
+
+ // blurred actor - gather texture samples from the actor texture in the direction of motion
+ vec4 col = colActor * uRecipNumSamples;
+ for(float i = 1.0; i < uNumSamples; i += 1.0)
+ {
+ float t = i * uRecipNumSamplesMinusOne;
+ col += texture2D(sTexture, vTexCoord + (velocity * t)) * uRecipNumSamples;
+ }
+ gl_FragColor = mix(colActor, col, vSpeed); // lerp blurred and non-blurred actor based on speed of motion
+ gl_FragColor.a = fadeToEdgesScale;//colActor.a * fadeToEdgesScale; // fade blurred actor to its edges based on speed of motion
+ gl_FragColor *= uColor;
+}
--- /dev/null
+precision mediump float;
+
+attribute vec2 aPosition;
+
+uniform mat4 uMvpMatrix;
+uniform mat4 uModelView;
+uniform mat4 uViewMatrix;
+uniform mat4 uProjection;
+uniform vec3 uSize;
+
+uniform mat4 uModelLastFrame;
+float timeDelta = 0.0167;
+
+uniform float uGeometryStretchFactor;
+uniform float uSpeedScalingFactor;
+
+// outputs
+varying vec2 vModelSpaceCenterToPos;
+varying vec2 vScreenSpaceVelocityVector;
+varying float vSpeed;
+varying vec2 vTexCoord;
+
+void main()
+{
+ // get view space position of vertex this frame and last frame
+ vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+
+ vec4 viewSpaceVertex = uModelView * vertexPosition;
+ vec4 viewSpaceVertexLastFrame = (uViewMatrix * uModelLastFrame) * vertexPosition;
+ float reciprocalTimeDelta = 1.0 / timeDelta;
+
+ // work out vertex's last movement in view space
+ vec3 viewSpacePosDelta = viewSpaceVertex.xyz - viewSpaceVertexLastFrame.xyz;
+
+ // get clip space position of vertex this frame and last frame
+ vec4 clipSpaceVertex = uMvpMatrix * vertexPosition;
+ vec4 clipSpaceVertexLastFrame = uProjection * viewSpaceVertexLastFrame;
+
+ // decide how much this vertex is 'trailing', i.e. at the back of the object relative to its direction of motion. We do this
+ // by assuming the objects model space origin is at its center and taking the dot product of the vector from center to vertex with the motion direction
+ float t = 0.0;
+ float posDeltaLength = length(viewSpacePosDelta);
+ if(posDeltaLength > 0.001) // avoid div by 0 if object has barely moved
+ {
+ vec4 viewSpaceCenterToPos = uModelView * vec4(vertexPosition.xy, 0.0, 0.0);
+ float centerToVertexDist = length(viewSpaceCenterToPos);
+ if(centerToVertexDist > 0.001) // avoid div by 0 if object has vertex at model space origin
+ {
+ vec3 viewSpacePosDeltaNormalised = viewSpacePosDelta / posDeltaLength;
+ vec3 viewSpaceCenterToPosNormalised = viewSpaceCenterToPos.xyz / centerToVertexDist;
+ t = (dot(viewSpacePosDeltaNormalised, viewSpaceCenterToPosNormalised) * 0.5 ) + 0.5; // scale and bias from [-1..1] to [0..1]
+ }
+ }
+ // output vertex position lerped with its last position, based on how much it is trailing,
+ // this stretches the geom back along where it has just been, giving a warping effect
+ // Note: we must take account of time delta to convert position delta into a velocity, so changes are smooth (take into account frame time correctly)
+ gl_Position = mix(clipSpaceVertexLastFrame, clipSpaceVertex, t * uGeometryStretchFactor * reciprocalTimeDelta);
+
+ // work out vertex's last movement in normalised device coordinates [-1..1] space, i.e. perspective divide
+ vec2 ndcVertex = clipSpaceVertex.xy / clipSpaceVertex.w;
+ vec2 ndcVertexLastFrame = clipSpaceVertexLastFrame.xy / clipSpaceVertexLastFrame.w;
+ // scale and bias so that a value of 1.0 corresponds to screen size (NDC is [-1..1] = 2)
+ vScreenSpaceVelocityVector = ((ndcVertex - ndcVertexLastFrame) * 0.5 * reciprocalTimeDelta);
+ vScreenSpaceVelocityVector.y = -vScreenSpaceVelocityVector.y; // TODO negated due to y being inverted in our coordinate system?
+ // calculate a scaling factor proportional to velocity, which we can use to tweak how things look
+ vSpeed = length(vScreenSpaceVelocityVector) * uSpeedScalingFactor;
+ vSpeed = clamp(vSpeed, 0.0, 1.0);
+
+ // provide fragment shader with vector from center of object to pixel (assumes the objects model space origin is at its center and verts have same z)
+ vModelSpaceCenterToPos = viewSpaceVertex.xy;
+
+ vec2 texCoord = aPosition + vec2(0.5);
+ vTexCoord = texCoord;
+}
\ No newline at end of file
--- /dev/null
+precision mediump float;
+
+uniform sampler2D sTexture;
+uniform vec4 uColor;
+
+uniform vec2 uObjectFadeStart;
+uniform vec2 uObjectFadeEnd;
+uniform float uAlphaScale;
+
+// inputs
+varying vec2 vModelSpaceCenterToPos;
+varying vec2 vScreenSpaceVelocityVector;
+varying float vSpeed;
+varying vec2 vTexCoord;
+
+void main()
+{
+ // calculate an alpha value that will fade the object towards its extremities, we need this to avoid an unsightly hard edge between color values of
+ // the stretched object and the background. Use smoothstep also to hide any hard edges (discontinuities) in rate of change of this alpha gradient
+ vec2 centerToPixel = abs( vModelSpaceCenterToPos );
+ vec2 fadeToEdges = smoothstep(0.0, 1.0, 1.0 - ((centerToPixel - uObjectFadeStart) / (uObjectFadeEnd - uObjectFadeStart)));
+ float fadeToEdgesScale = fadeToEdges.x * fadeToEdges.y * uAlphaScale; // apply global scaler
+ fadeToEdgesScale = mix(1.0, fadeToEdgesScale, vSpeed); // fade proportional to speed, so opaque when at rest
+
+ // standard actor texel
+ vec4 colActor = texture2D(sTexture, vTexCoord);
+ gl_FragColor = colActor;
+ gl_FragColor.a *= fadeToEdgesScale; // fade actor to its edges based on speed of motion
+ gl_FragColor *= uColor;
+}
\ No newline at end of file
--- /dev/null
+precision mediump float;
+
+attribute vec2 aPosition;
+
+uniform mat4 uMvpMatrix;
+uniform mat4 uModelView;
+uniform mat4 uViewMatrix;
+uniform mat4 uProjection;
+uniform vec3 uSize;
+
+uniform mat4 uModelLastFrame;
+float timeDelta = 0.0167;
+
+uniform float uGeometryStretchFactor;
+uniform float uSpeedScalingFactor;
+
+// outputs
+varying vec2 vModelSpaceCenterToPos;
+varying vec2 vScreenSpaceVelocityVector;
+varying float vSpeed;
+varying vec2 vTexCoord;
+
+void main()
+{
+ // get view space position of vertex this frame and last frame
+ vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+
+ vec4 viewSpaceVertex = uModelView * vertexPosition;
+ vec4 viewSpaceVertexLastFrame = uViewMatrix * uModelLastFrame * vertexPosition;
+
+ // work out vertex's last movement in view space
+ vec3 viewSpacePosDelta = viewSpaceVertex.xyz - viewSpaceVertexLastFrame.xyz;
+ float reciprocalTimeDelta = 1.0 / timeDelta;
+
+ // get clip space position of vertex this frame and last frame
+ vec4 clipSpaceVertex = uMvpMatrix * vertexPosition;
+ vec4 clipSpaceVertexLastFrame = uProjection * viewSpaceVertexLastFrame;
+
+ // decide how much this vertex is 'trailing', i.e. at the back of the object relative to its direction of motion. We do this
+ // by assuming the objects model space origin is at its center and taking the dot product of the vector from center to vertex with the motion direction
+ float t = 0.0;
+ float posDeltaLength = length(viewSpacePosDelta);
+ if(posDeltaLength > 0.001) // avoid div by 0 if object has barely moved
+ {
+ vec4 viewSpaceCenterToPos = uModelView * vec4(aPosition, 0.0, 0.0);
+ float centerToVertexDist = length(viewSpaceCenterToPos);
+ if(centerToVertexDist > 0.001) // avoid div by 0 if object has vertex at model space origin
+ {
+ vec3 viewSpacePosDeltaNormalised = viewSpacePosDelta / posDeltaLength;
+ vec3 viewSpaceCenterToPosNormalised = viewSpaceCenterToPos.xyz / centerToVertexDist;
+ t = (dot(viewSpacePosDeltaNormalised, viewSpaceCenterToPosNormalised) * 0.5 ) + 0.5; // scale and bias from [-1..1] to [0..1]
+ }
+ }
+
+ // output vertex position lerped with its last position, based on how much it is trailing,
+ // this stretches the geom back along where it has just been, giving a warping effect
+ // We raise t to a power in order that non-trailing vertices are effected much more than trailing ones
+ // Note: we must take account of time delta to convert position delta into a velocity, so changes are smooth (take into account frame time correctly)
+ gl_Position = mix(clipSpaceVertexLastFrame, clipSpaceVertex, t * t * t * uGeometryStretchFactor * reciprocalTimeDelta);
+
+ // work out vertex's last movement in normalised device coordinates [-1..1] space, i.e. perspective divide
+ vec2 ndcVertex = clipSpaceVertex.xy / clipSpaceVertex.w;
+ vec2 ndcVertexLastFrame = clipSpaceVertexLastFrame.xy / clipSpaceVertexLastFrame.w;
+ // scale and bias so that a value of 1.0 corresponds to screen size (NDC is [-1..1] = 2)
+ vScreenSpaceVelocityVector = ((ndcVertex - ndcVertexLastFrame) * 0.5 * reciprocalTimeDelta);
+ vScreenSpaceVelocityVector.y = -vScreenSpaceVelocityVector.y; // TODO negated due to y being inverted in our coordinate system?
+ // calculate a scaling factor proportional to velocity, which we can use to tweak how things look
+ vSpeed = length(vScreenSpaceVelocityVector) * uSpeedScalingFactor;
+ vSpeed = clamp(vSpeed, 0.0, 1.0);
+
+ // provide fragment shader with vector from center of object to pixel (assumes the objects model space origin is at its center and verts have same z)
+ vModelSpaceCenterToPos = viewSpaceVertex.xy;
+
+ vec2 texCoord = aPosition + vec2(0.5);
+ vTexCoord = texCoord;
+}
\ No newline at end of file
--- /dev/null
+attribute mediump vec2 aPosition;
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vMaskTexCoord;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump vec2 uFixed[ 3 ];
+uniform mediump vec2 uStretchTotal;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump vec2 extraSize;
+
+void main()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+
+ mediump vec2 size = visualSize.xy;
+
+ mediump vec2 fixedFactor = vec2( uFixed[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uFixed[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].y );
+ mediump vec2 stretch = floor( aPosition * 0.5 );
+ mediump vec2 fixedTotal = uFixed[ 2 ];
+
+ mediump vec4 gridPosition = vec4( fixedFactor + ( size - fixedTotal ) * stretch, 0.0, 1.0 );
+ mediump vec4 vertexPosition = gridPosition;
+ vertexPosition.xy -= size * vec2( 0.5, 0.5 );
+ vertexPosition.xy += anchorPoint*size + (visualOffset + origin)*uSize.xy;
+
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ vTexCoord = ( fixedFactor + stretch * uStretchTotal ) / ( fixedTotal + uStretchTotal );
+
+ vMaskTexCoord = gridPosition.xy / size;
+ gl_Position = vertexPosition;
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vMaskTexCoord;
+uniform sampler2D sTexture;
+uniform sampler2D sMask;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+uniform mediump float auxiliaryImageAlpha;
+
+void main()
+{
+ // Where mask image is transparent, all of background image must show through.
+ // where mask image is opaque, only mask should be shown
+ // where mask is translucent, less of background should be shown.
+ // auxiliaryImageAlpha controls how much of mask is visible
+
+ mediump vec4 color = texture2D( sTexture, vTexCoord );
+ mediump vec4 mask= texture2D( sMask, vMaskTexCoord );
+
+ mediump vec3 mixedColor = color.rgb * mix( 1.0-mask.a, 1.0, 1.0-auxiliaryImageAlpha)
+ + mask.rgb*mask.a * auxiliaryImageAlpha;
+ gl_FragColor = vec4(mixedColor,1.0) * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vMaskTexCoord;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump vec2 uNinePatchFactorsX[ FACTOR_SIZE_X ];
+uniform mediump vec2 uNinePatchFactorsY[ FACTOR_SIZE_Y ];
+
+// Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump vec2 extraSize;
+
+void main()
+{
+ mediump vec2 fixedFactor= vec2( uNinePatchFactorsX[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uNinePatchFactorsY[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].x );
+ mediump vec2 stretch= vec2( uNinePatchFactorsX[ int( ( aPosition.x ) * 0.5 ) ].y, uNinePatchFactorsY[ int( ( aPosition.y ) * 0.5 ) ].y );
+
+ mediump vec2 fixedTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].x, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].x );
+ mediump vec2 stretchTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].y, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].y );
+
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+
+ mediump vec4 gridPosition = vec4( fixedFactor + ( visualSize.xy - fixedTotal ) * stretch / stretchTotal, 0.0, 1.0 );
+ mediump vec4 vertexPosition = gridPosition;
+ vertexPosition.xy -= visualSize.xy * vec2( 0.5, 0.5 );
+ vertexPosition.xy += anchorPoint*visualSize + (visualOffset + origin)*uSize.xy;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ vTexCoord = ( fixedFactor + stretch ) / ( fixedTotal + stretchTotal );
+ vMaskTexCoord = gridPosition.xy / visualSize;
+
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+uniform vec3 uSize;
+uniform vec2 uSpineShadowParameter;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ if( gl_FrontFacing ) // display front side
+ {
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
+ }
+ else // display back side, flip the image horizontally by changing the x component of the texture coordinate
+ {
+ gl_FragColor = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) ) * uColor;
+ }
+ // display book spine, a stripe of shadowed texture
+ float pixelPos = vTexCoord.x * uSize.x;
+ if( pixelPos < uSpineShadowParameter.x )
+ {
+ float x = pixelPos - uSpineShadowParameter.x;
+ float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );
+ vec2 spineNormal = normalize(vec2(uSpineShadowParameter.y*x/uSpineShadowParameter.x, y));
+ gl_FragColor.rgb *= spineNormal.y;
+ }
+}
\ No newline at end of file
--- /dev/null
+precision mediump float;
+attribute mediump vec2 aPosition;
+uniform mediump mat4 uMvpMatrix;
+uniform vec3 uSize;
+uniform float uTextureWidth;
+varying vec2 vTexCoord;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition*uSize.xy, 0.0, 1.0);
+ gl_Position = uMvpMatrix * vertexPosition;
+ vTexCoord = aPosition + vec2(0.5);
+ vTexCoord.x /= uTextureWidth;
+}
--- /dev/null
+precision mediump float;
+
+varying mediump vec2 vTexCoord;
+
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform vec3 uSize;
+uniform vec2 uSpineShadowParameter;
+varying vec3 vNormal;
+varying vec4 vPosition;
+
+void main()
+{
+ // need to re-normalize the interpolated normal
+ vec3 normal = normalize( vNormal );
+ // display page content
+ vec4 texel;
+ // display back image of the page, flip the texture
+ if( dot(vPosition.xyz, normal) > 0.0 ) texel = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) );
+ // display front image of the page
+ else texel = texture2D( sTexture, vTexCoord );
+
+ // display book spine, a stripe of shadowed texture
+ float pixelPos = vTexCoord.x * uSize.x;
+ float spineShadowCoef = 1.0;
+ if( pixelPos < uSpineShadowParameter.x )
+ {
+ float x = pixelPos - uSpineShadowParameter.x;
+ float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );
+ spineShadowCoef = normalize( vec2( uSpineShadowParameter.y*x/uSpineShadowParameter.x, y ) ).y;
+ }
+ // calculate the lighting
+ // set the ambient color as vec3(0.4);
+ float lightColor = abs( normal.z ) * 0.6 + 0.4;
+ gl_FragColor = vec4( ( spineShadowCoef * lightColor ) * texel.rgb , texel.a ) * uColor;
+}
--- /dev/null
+/*
+ * The common parameters for all the vertices, calculate in CPU then pass into the shader as uniforms
+ *
+ * first part of the page, (outside the the line passing through original center and vertical to curve direction)
+ * no Z change, only 2D rotation and translation
+ * ([0][0],[0][1],[1][0],[1][1]) mat2 rotateMatrix
+ * ([2][0],[2][1]) vec2 translationVector
+ *
+ * ([0][2],[0][3]) vec2 originalCenter: Typically the press down position of the Pan Gesture
+ * ([1][2],[1][3]) vec2 currentCenter: Typically the current position of the Pan Gesture
+ * ([3][0],[3][1]) vec2 curveDirection: The normalized vector pointing from original center to current center
+ * ([2][2]) float vanishingPointY: The Y coordinate of the intersection of the spine
+ * and the line which goes through the original center and is vertical to the curveDirection
+ * ([2][3]) float curveEndY: The Y coordinate of intersection of the spine and the line through both original and current center
+ * ([3][2]) float curveHeight: The height of the interpolated hermite curve.
+ * ([3][3]) float currentLength: The length from the current center to the curveEnd.
+ */
+
+precision mediump float;
+
+attribute mediump vec2 aPosition;
+
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uModelView;
+
+uniform mat4 uCommonParameters;
+
+uniform vec3 uSize;
+uniform float uIsTurningBack;
+uniform float uTextureWidth;
+varying vec3 vNormal;
+varying vec4 vPosition;
+varying mediump vec2 vTexCoord;
+
+void main()
+{
+ vec4 position = vec4( aPosition*uSize.xy, 0.0, 1.0);
+ vec2 currentCenter = vec2( uCommonParameters[1][2], uCommonParameters[1][3]);
+ vec2 originalCenter = vec2( uCommonParameters[0][2], uCommonParameters[0][3]);
+ vec3 normal = vec3(0.0,0.0,1.0);
+
+ if(currentCenter.x < originalCenter.x)
+ {
+ // change the coordinate origin from the center of the page to its top-left
+ position.xy += uSize.xy * 0.5;
+ vec2 curveDirection = vec2( uCommonParameters[3]);
+ vec3 vanishingPoint = vec3(0.0, uCommonParameters[2][2], 0.0);
+ // first part of the page, (outside the the line passing through original center and vertical to curve direction)
+ //no Z change, only 2D rotation and translation
+ if( dot(curveDirection, position.xy - originalCenter) < 0.0 )
+ {
+ position.y -= vanishingPoint.y;
+ position.xy = mat2(uCommonParameters)*position.xy + vec2( uCommonParameters[2]);
+ }
+ // second part of the page, bent as a ruled surface
+ else
+ {
+ // calculate on the flat plane, between
+ // the first line passing through current vertex and vanishing point
+ // the second line passing through original center and current center
+ vec2 curveEnd = vec2( 0.0, uCommonParameters[2][3] );
+ vec2 curFlatDirection = vec2(0.0,1.0);
+ float lengthFromCurve = position.y - originalCenter.y;
+ float lengthOnCurve = position.x;
+ if(currentCenter.y != originalCenter.y)
+ {
+ curFlatDirection = normalize(position.xy - vanishingPoint.xy);
+ lengthFromCurve = (curveEnd.x*curveDirection.y-curveEnd.y*curveDirection.x-position.x*curveDirection.y+position.y*curveDirection.x)
+ / (curFlatDirection.x*curveDirection.y-curFlatDirection.y*curveDirection.x);
+ lengthOnCurve = length(position.xy+lengthFromCurve*curFlatDirection-curveEnd);
+ }
+
+ // define the control points of hermite curve, composed with two segments
+ // calculation is carried out on the 2D plane which is passing through both current and original center and vertical to the image plane
+ float currentLength = uCommonParameters[3][3];
+ float originalLength = abs(originalCenter.x/curveDirection.x);
+ float height = uCommonParameters[3][2];
+ float percentage = currentLength/originalLength;
+ //vec2 SegmentOneControlPoint0 = vec2(0.0, 0.0);
+ vec2 SegmentOneControlPoint1 = vec2((0.65*percentage - 0.15)*originalLength, (0.8 + 0.2 * percentage)*height);
+ vec2 SegmentTwoControlPoint0 = SegmentOneControlPoint1;
+ vec2 SegmentTwoControlPoint1 = vec2(currentLength, 0.0);
+ vec2 SegmentOneTangentVector0 = SegmentOneControlPoint1;
+ vec2 SegmentOneTangentVector1 = vec2(0.5*originalLength,0.0);
+ vec2 SegmentTwoTangentVector0 = SegmentOneTangentVector1;
+ vec2 SegmentTwoTangentVector1 = SegmentOneTangentVector1;
+
+ // calculate the corresponding curve point position and its tangent vector
+ // it is a linear mapping onto nonlinear curves, might cause some unwanted deformation
+ // but as there are no analytical method to calculate the curve length on arbitrary segment
+ // no efficient way to solve this nonlinear mapping, Numerical approximation would cost too much computation in shader
+ vec2 curvePoint2D;
+ vec2 tangent;
+ float t0 = lengthOnCurve / originalLength;
+ if(t0<=0.5)
+ {
+ float t = 2.0*t0;
+ float t_2 = t*t;
+ float t_3 = t*t_2;
+ curvePoint2D = (-2.0*t_3+3.0*t_2)*SegmentOneControlPoint1
+ + (t_3-2.0*t_2+t)*SegmentOneTangentVector0 + (t_3-t_2)*SegmentOneTangentVector1;
+ tangent = (-6.0*t_2+6.0*t)*SegmentOneControlPoint1
+ + (3.0*t_2-4.0*t+1.0)*SegmentOneTangentVector0 + (3.0*t_2-2.0*t)*SegmentOneTangentVector1;
+ }
+ else
+ {
+ float t = 2.0*t0-1.0;
+ float t_2 = t*t;
+ float t_3 = t*t_2;
+ curvePoint2D = (2.0*t_3-3.0*t_2+1.0)*SegmentTwoControlPoint0 + (-2.0*t_3+3.0*t_2)*SegmentTwoControlPoint1
+ + (t_3-2.0*t_2+t)*SegmentTwoTangentVector0 + (t_3-t_2)*SegmentTwoTangentVector1;
+ tangent = (6.0*t_2-6.0*t)*SegmentTwoControlPoint0 + (-6.0*t_2+6.0*t)*SegmentTwoControlPoint1
+ + (3.0*t_2-4.0*t+1.0)*SegmentTwoTangentVector0 + (3.0*t_2-2.0*t)*SegmentTwoTangentVector1;
+ // a trick to eliminate some optical illusion caused by the gradient matter of normal in per-fragment shading
+ // which is caused by linear interpolation of normal vs. nonlinear lighting
+ // will notice some artifact in the areas with dramatically normal changes, so compress the normal differences here
+ tangent.y *= min(1.0, length(position.xyz - vanishingPoint) / uSize.y );
+ }
+ vec3 curvePoint = vec3(curveEnd - curvePoint2D.x*curveDirection,max(0.0,curvePoint2D.y));
+ vec3 tangentVector = vec3(-tangent.x*curveDirection,tangent.y);
+
+ // locate the new vertex position on the line passing through both vanishing point and the calculated curve point position
+ vec3 curLiftDirection = vec3(0.0,-1.0,0.0);
+ if(currentCenter.y != originalCenter.y)
+ {
+ curLiftDirection = normalize(curvePoint - vanishingPoint);
+ tangentVector *= (curveDirection.y > 0.0) ? -1.0 : 1.0;
+ // an heuristic adjustment here, to compensate the linear parameter mapping onto the nonlinear curve
+ float Y0 = position.y - curveDirection.y * (position.x/curveDirection.x);
+ float proportion;
+ float refLength;
+ if(abs(Y0-vanishingPoint.y) > abs(curveEnd.y-vanishingPoint.y))
+ {
+ proportion = abs(curveEnd.y - Y0) / (abs(curveEnd.y-Y0)+abs(curveEnd.y - vanishingPoint.y));
+ refLength = proportion*length(originalCenter-vanishingPoint.xy) / (proportion-1.0);
+ }
+ else
+ {
+ proportion = abs(curveEnd.y - Y0) / abs(curveEnd.y - vanishingPoint.y);
+ refLength = proportion*length(originalCenter-vanishingPoint.xy);
+ }
+ float Y1 = currentCenter.y - (normalize(currentCenter-vanishingPoint.xy)).y * refLength;
+ position.y = mix(Y0, Y1, t0);
+ }
+ position.xz = curvePoint.xz - lengthFromCurve*curLiftDirection.xz;
+ // calculate the normal vector, will be used for lighting
+ normal = cross(curLiftDirection, normalize(tangentVector));
+ // the signature of Z is decided by the page turning direction:
+ // from left to right(negative); from right to left (positive)
+ position.z *= -uIsTurningBack;
+ normal.xy *= -uIsTurningBack;
+ }
+ // change the coordinate origin from the top-left of the page to its center
+ position.xy -= uSize.xy * 0.5;
+ }
+ vNormal = uNormalMatrix * normal;
+ gl_Position = uMvpMatrix * position;
+ // varying parameters for fragment shader
+ vTexCoord = aPosition + vec2(0.5);
+ vTexCoord.x /= uTextureWidth;
+ vPosition = uModelView * position;
+}
--- /dev/null
+precision mediump float;
+varying mediump vec3vIllumination;
+uniform lowpvec4uColor;
+uniform lowpvec3mixColor;
+
+void main()
+{
+ vec4 baseColor = vec4(mixColor, 1.0) * uColor;
+ gl_FragColor = vec4( vIllumination.rgb * baseColor.rgb, baseColor.a );
+}
--- /dev/null
+attribute highp vec3 aPosition;
+attribute highp vec2 aTexCoord;
+attribute highp vec3 aNormal;
+varying mediump vec3 vIllumination;
+uniform mediump vec3 uSize;
+uniform mediump vec3 uObjectDimensions;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat4 uViewMatrix;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 lightPosition;
+uniform mediump vec2 uStageOffset;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform mediump vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ float scaleFactor = min( visualSize.x / uObjectDimensions.x, visualSize.y / uObjectDimensions.y );
+ vec3 originFlipY =vec3(origin.x, -origin.y, 0.0);
+ vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
+ vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);
+
+ return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );
+}
+
+void main()
+{
+ vec4 normalisedVertexPosition = ComputeVertexPosition();
+ vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ //Illumination in Model-View space - Transform attributes and uniforms
+ vec4 mvVertexPosition = uModelView * normalisedVertexPosition;
+ vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;
+
+ vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );
+ mvLightPosition = uViewMatrix * mvLightPosition;
+ vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );
+
+ float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
+ vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
+
+ gl_Position = vertexPosition;
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform lowp vec4 uShadowColor;
+uniform sampler2D sTexture;
+
+void main()
+{
+ lowp float alpha;
+ alpha = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y)).a;
+ gl_FragColor = vec4(uShadowColor.rgb, uShadowColor.a * alpha);
+}
\ No newline at end of file
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelMatrix;
+uniform vec3 uSize;
+varying vec2 vTexCoord;
+
+uniform mediump mat4 uLightCameraProjectionMatrix;
+uniform mediump mat4 uLightCameraViewMatrix;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ gl_Position = uMvpMatrix * vertexPosition;
+ vec4 textureCoords = uLightCameraProjectionMatrix * uLightCameraViewMatrix * uModelMatrix * vertexPosition;
+ vTexCoord = 0.5 + 0.5 * (textureCoords.xy/textureCoords.w);
+}
\ No newline at end of file
--- /dev/null
+precision highp float;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform int uSpread;
+uniform vec2 uTexScale;
+
+void main()
+{
+ vec4 color = texture2D( sTexture, vTexCoord);
+ for( int i = 1; i <= uSpread; ++i )
+ {
+ vec2 offset = uTexScale * float(i);
+ color = max( texture2D( sTexture, vTexCoord + offset), color );
+ color = max( texture2D( sTexture, vTexCoord - offset), color );
+ }
+ gl_FragColor = color;
+}
\ No newline at end of file
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp float uAlpha;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
+ gl_FragColor.a *= uAlpha;
+}
--- /dev/null
+uniform lowp vec4 uColor;
+uniform lowp vec4 textColorAnimatable;
+uniform sampler2D sTexture;
+varying mediump vec2 vTexCoord;
+varying mediump vec4 vColor;
+
+void main()
+{
+ mediump vec4 color = texture2D( sTexture, vTexCoord );
+ gl_FragColor = vec4( vColor.rgb * uColor.rgb * textColorAnimatable.rgb, uColor.a * vColor.a * textColorAnimatable.a * color.r );
+}
--- /dev/null
+uniform lowp vec4 uColor;
+uniform lowp vec4 textColorAnimatable;
+uniform sampler2D sTexture;
+varying mediump vec2 vTexCoord;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * textColorAnimatable;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+attribute mediump vec2 aTexCoord;
+attribute mediump vec4 aColor;
+uniform mediump vec2 uOffset;
+uniform highp mat4 uMvpMatrix;
+varying mediump vec2 vTexCoord;
+varying mediump vec4 vColor;
+
+void main()
+{
+ mediump vec4 position = vec4( aPosition.xy + uOffset, 0.0, 1.0 );
+ gl_Position = uMvpMatrix * position;
+ vTexCoord = aTexCoord;
+ vColor = aColor;
+}
--- /dev/null
+varying mediump vec4 vColor;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ gl_FragColor = vColor * uColor;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+attribute mediump vec4 aColor;
+varying mediump vec4 vColor;
+uniform highp mat4 uMvpMatrix;
+
+void main()
+{
+ mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
+ gl_Position = uMvpMatrix * position;
+ vColor = aColor;
+}
--- /dev/null
+uniform lowp vec4 uColor;
+
+void main()
+{
+ gl_FragColor = uColor;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+
+void main()
+{
+ mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
+ gl_Position = uMvpMatrix * position;
+}
--- /dev/null
+varying highp vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ if ( vTexCoord.y > 1.0 )
+ discard;
+
+ mediump vec4 textTexture = texture2D( sTexture, vTexCoord );
+
+ gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+varying highp vec2 vTexCoord;
+uniform highp vec3 uSize;
+uniform mediump float uDelta;
+uniform mediump vec2 uTextureSize;
+uniform mediump float uGap;
+uniform mediump float uHorizontalAlign;
+uniform mediump float uVerticalAlign;
+
+uniform highp mat4 uMvpMatrix;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+void main()
+{
+ mediump vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy );
+ mediump vec2 visualSize = mix( uSize.xy * size, size, offsetSizeMode.zw );
+
+ vTexCoord.x = ( uDelta + uHorizontalAlign * ( uTextureSize.x - visualSize.x - uGap ) + floor( aPosition.x * visualSize.x ) + 0.5 - uGap * 0.5 ) / uTextureSize.x + 0.5;
+ vTexCoord.y = ( uVerticalAlign * ( uTextureSize.y - visualSize.y ) + floor( aPosition.y * visualSize.y ) + 0.5 ) / ( uTextureSize.y ) + 0.5;
+
+ mediump vec4 vertexPosition = vec4( floor( ( aPosition + anchorPoint ) * visualSize + ( visualOffset + origin ) * uSize.xy ), 0.0, 1.0 );
+
+ gl_Position = uMvpMatrix * vertexPosition;
+}
\ No newline at end of file
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump vec4 textTexture = texture2D( sTexture, vTexCoord );
+
+ gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform sampler2D sStyle;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump vec4 textTexture = texture2D( sTexture, vTexCoord );
+ mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );
+
+ // Draw the text as overlay above the style
+ gl_FragColor = ( textTexture + styleTexture * ( 1.0 - textTexture.a ) ) * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump vec4 pixelArea;
+
+varying mediump vec2 vTexCoord;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+ vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uTextColorAnimatable;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump float textTexture = texture2D( sTexture, vTexCoord ).r;
+
+ // Set the color of the text to what it is animated to.
+ gl_FragColor = uTextColorAnimatable * textTexture * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform sampler2D sMask;
+uniform lowp vec4 uTextColorAnimatable;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump vec4 textTexture = texture2D( sTexture, vTexCoord );
+ mediump float maskTexture = texture2D( sMask, vTexCoord ).r;
+
+ // Set the color of non-transparent pixel in text to what it is animated to.
+ // Markup text with multiple text colors are not animated (but can be supported later on if required).
+ // Emoji color are not animated.
+ mediump float vstep = step( 0.0001, textTexture.a );
+ textTexture.rgb = mix( textTexture.rgb, uTextColorAnimatable.rgb, vstep * maskTexture );
+
+ // Draw the text as overlay above the style
+ gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform sampler2D sStyle;
+uniform sampler2D sMask;
+uniform lowp float uHasMultipleTextColors;
+uniform lowp vec4 uTextColorAnimatable;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump vec4 textTexture = texture2D( sTexture, vTexCoord );
+ mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );
+ mediump float maskTexture = texture2D( sMask, vTexCoord ).r;
+
+ // Set the color of non-transparent pixel in text to what it is animated to.
+ // Markup text with multiple text colors are not animated (but can be supported later on if required).
+ // Emoji color are not animated.
+ mediump float vstep = step( 0.0001, textTexture.a );
+ textTexture.rgb = mix( textTexture.rgb, uTextColorAnimatable.rgb, vstep * maskTexture * ( 1.0 - uHasMultipleTextColors ) );
+
+ // Draw the text as overlay above the style
+ gl_FragColor = ( textTexture + styleTexture * ( 1.0 - textTexture.a ) ) * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform sampler2D sStyle;
+uniform lowp vec4 uTextColorAnimatable;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump float textTexture = texture2D( sTexture, vTexCoord ).r;
+ mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );
+
+ // Draw the text as overlay above the style
+ gl_FragColor = ( uTextColorAnimatable * textTexture + styleTexture * ( 1.0 - uTextColorAnimatable.a * textTexture ) ) * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+uniform lowp vec4 uColor;
+varying mediump vec2 vTexCoord;
+uniform samplerExternalOES sTexture;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+varying mediump vec2 vTexCoord;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+varying mediump vec2 sTexCoordRect;
+
+void main()
+{
+ gl_Position = uMvpMatrix * vec4(aPosition * uSize.xy, 0.0, 1.0);
+ vTexCoord = aPosition + vec2(0.5);
+}
--- /dev/null
+void main()
+{
+ gl_FragColor = vec4(0.0);
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ gl_Position = uMvpMatrix * vertexPosition;
+}
--- /dev/null
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ gl_FragColor = uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
#include <cstring> // for strcmp
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/object/type-registry-helper.h>
-#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
namespace Dali
DALI_TYPE_REGISTRATION_END()
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- varying mediump vec2 vTexCoord;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump vec3 uSize;\n
- uniform mediump vec4 uTextureRect;\n
- \n
- void main()\n
- {\n
- mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
- vertexPosition.xyz *= uSize;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
- \n
- vTexCoord = aPosition + vec2(0.5);\n
- vTexCoord = mix(uTextureRect.xy, uTextureRect.zw, vTexCoord);\n
-
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec4 uSamplerRect;
- \n
- void main()\n
- {\n
- gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
- }\n
-);
-
Actor CreateTile( const Vector4& samplerRect )
{
Actor tile = Actor::New();
void CubeTransitionEffect::OnSceneConnection( int depth )
{
Geometry geometry = VisualFactoryCache::CreateQuadGeometry();
- Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+ Shader shader = Shader::New( SHADER_CUBE_TRANSITION_EFFECT_VERT, SHADER_CUBE_TRANSITION_EFFECT_FRAG );
TextureSet textureSet = TextureSet::New();