From 67c2962f7cb1a545a6ad10b8147c8558cc6f45ca Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Wed, 13 Jan 2021 14:47:31 +0000 Subject: [PATCH] Shader compilation tool for dali-toolkit Change-Id: I3c3e193e45cc3cc61840e68f64285f0627873da8 --- .gitignore | 2 + build/tizen/CMakeLists.txt | 10 + build/tizen/shader-generator.sh | 62 ++++++ .../controls/bloom-view/bloom-view-impl.cpp | 53 +----- .../controls/bubble-effect/bubble-effect.h | 82 +------- .../controls/bubble-effect/bubble-emitter-impl.cpp | 57 +----- .../controls/bubble-effect/color-adjuster.h | 47 +---- .../controls/control/control-renderers.cpp | 34 +--- .../internal/controls/control/control-renderers.h | 10 +- .../controls/effects-view/effects-view-impl.cpp | 37 +--- .../gaussian-blur-view/gaussian-blur-view-impl.cpp | 22 +-- .../controls/model3d-view/model3d-view-impl.cpp | 190 +------------------ .../page-turn-view/page-turn-book-spine-effect.h | 52 +---- .../controls/page-turn-view/page-turn-effect.cpp | 210 +-------------------- .../controls/scrollable/bouncing-effect-actor.cpp | 30 +-- .../controls/shadow-view/shadow-view-impl.cpp | 37 +--- .../super-blur-view/super-blur-view-impl.cpp | 15 +- dali-toolkit/internal/file.list | 1 + .../graphics/shaders/alpha-discard-effect.frag | 14 ++ .../shaders/animated-gradient-visual-shader.frag | 51 +++++ .../shaders/animated-gradient-visual-shader.vert | 59 ++++++ .../shaders/arc-visual-butt-cap-shader.frag | 35 ++++ .../shaders/arc-visual-round-cap-shader.frag | 32 ++++ .../graphics/shaders/arc-visual-shader.vert | 25 +++ .../shaders/bloom-view-composite-shader.frag | 27 +++ .../shaders/bloom-view-extract-shader.frag | 13 ++ .../graphics/shaders/blur-two-images-shader.frag | 11 ++ .../graphics/shaders/blur-two-pass-shader.frag | 15 ++ .../border-visual-anti-aliasing-shader.frag | 12 ++ .../border-visual-anti-aliasing-shader.vert | 14 ++ .../graphics/shaders/border-visual-shader.frag | 8 + .../graphics/shaders/border-visual-shader.vert | 26 +++ .../shaders/bouncing-effect-mesh-shader.frag | 7 + .../shaders/bouncing-effect-mesh-shader.vert | 11 ++ .../shaders/bubble-effect-color-adjuster.frag | 44 +++++ .../internal/graphics/shaders/bubble-effect.frag | 18 ++ .../internal/graphics/shaders/bubble-effect.vert | 56 ++++++ .../internal/graphics/shaders/bubble-emitter.frag | 41 ++++ .../internal/graphics/shaders/bubble-emitter.vert | 11 ++ .../shaders/color-visual-blur-edge-shader.frag | 13 ++ .../shaders/color-visual-blur-edge-shader.vert | 29 +++ .../color-visual-rounded-corner-shader.frag | 13 ++ .../color-visual-rounded-corner-shader.vert | 34 ++++ .../graphics/shaders/color-visual-shader.frag | 7 + .../graphics/shaders/color-visual-shader.vert | 24 +++ .../graphics/shaders/control-renderers.frag | 10 + .../graphics/shaders/control-renderers.vert | 12 ++ .../graphics/shaders/cube-transition-effect.frag | 9 + .../graphics/shaders/cube-transition-effect.vert | 17 ++ .../internal/graphics/shaders/dissolve-effect.frag | 21 +++ .../internal/graphics/shaders/dissolve-effect.vert | 34 ++++ .../graphics/shaders/distance-field-effect.frag | 97 ++++++++++ .../internal/graphics/shaders/effects-view.frag | 9 + .../internal/graphics/shaders/effects-view.vert | 16 ++ .../shaders/emboss-filter-composite-shader.frag | 9 + .../graphics/shaders/emboss-filter-shader.frag | 13 ++ .../graphics/shaders/gaussian-blur-view.frag | 15 ++ .../graphics/shaders/gltf-basecolor-texture.def | 4 + .../graphics/shaders/gltf-emit-texture.def | 5 + .../graphics/shaders/gltf-gles-version-300.def | 2 + .../internal/graphics/shaders/gltf-ibl-texture.def | 7 + .../shaders/gltf-metallicroughness-texture.def | 4 + .../graphics/shaders/gltf-normal-texture.def | 5 + .../graphics/shaders/gltf-occulusion-texture.def | 5 + .../shaders/gltf-physically-based-shader.frag | 189 +++++++++++++++++++ .../shaders/gltf-physically-based-shader.vert | 60 ++++++ ...-visual-bounding-box-rounded-corner-shader.vert | 37 ++++ .../gradient-visual-bounding-box-shader.vert | 27 +++ ...adient-visual-linear-rounded-corner-shader.frag | 14 ++ .../shaders/gradient-visual-linear-shader.frag | 9 + ...adient-visual-radial-rounded-corner-shader.frag | 14 ++ .../shaders/gradient-visual-radial-shader.frag | 9 + ...nt-visual-user-space-rounded-corner-shader.vert | 38 ++++ .../shaders/gradient-visual-user-space-shader.vert | 28 +++ .../graphics/shaders/image-region-effect.vert | 28 +++ .../shaders/image-visual-atlas-clamp-shader.frag | 13 ++ .../image-visual-atlas-various-wrap-shader.frag | 28 +++ .../shaders/image-visual-no-atlas-shader.frag | 11 ++ .../image-visual-rounded-corner-shader.frag | 19 ++ .../image-visual-rounded-corner-shader.vert | 37 ++++ .../graphics/shaders/image-visual-shader.vert | 27 +++ .../shaders/mesh-visual-normal-map-shader.frag | 25 +++ .../shaders/mesh-visual-normal-map-shader.vert | 62 ++++++ .../graphics/shaders/mesh-visual-shader.frag | 15 ++ .../graphics/shaders/mesh-visual-shader.vert | 58 ++++++ .../shaders/mesh-visual-simple-shader.frag | 10 + .../shaders/mesh-visual-simple-shader.vert | 48 +++++ .../shaders/model3d-view-nrmmap-shader.frag | 22 +++ .../shaders/model3d-view-nrmmap-shader.vert | 42 +++++ .../graphics/shaders/model3d-view-shader.frag | 12 ++ .../graphics/shaders/model3d-view-shader.vert | 39 ++++ .../shaders/model3d-view-simple-shader.frag | 8 + .../shaders/model3d-view-simple-shader.vert | 28 +++ .../graphics/shaders/motion-blur-effect.frag | 45 +++++ .../graphics/shaders/motion-blur-effect.vert | 75 ++++++++ .../graphics/shaders/motion-stretch-effect.frag | 30 +++ .../graphics/shaders/motion-stretch-effect.vert | 77 ++++++++ .../graphics/shaders/npatch-visual-3x3-shader.vert | 39 ++++ .../shaders/npatch-visual-mask-shader.frag | 23 +++ .../graphics/shaders/npatch-visual-shader.frag | 10 + .../graphics/shaders/npatch-visual-shader.vert | 38 ++++ .../shaders/page-turn-book-spine-effect.frag | 27 +++ .../shaders/page-turn-book-spine-effect.vert | 14 ++ .../graphics/shaders/page-turn-effect.frag | 36 ++++ .../graphics/shaders/page-turn-effect.vert | 163 ++++++++++++++++ .../graphics/shaders/primitive-visual-shader.frag | 10 + .../graphics/shaders/primitive-visual-shader.vert | 51 +++++ .../shaders/shadow-view-render-shader.frag | 10 + .../shaders/shadow-view-render-shader.vert | 17 ++ .../graphics/shaders/spread-filter-shader.frag | 17 ++ .../internal/graphics/shaders/super-blur-view.frag | 10 + .../graphics/shaders/text-atlas-l8-shader.frag | 11 ++ .../graphics/shaders/text-atlas-rgba-shader.frag | 9 + .../graphics/shaders/text-atlas-shader.vert | 15 ++ .../shaders/text-controller-background-shader.frag | 7 + .../shaders/text-controller-background-shader.vert | 11 ++ .../graphics/shaders/text-decorator-shader.frag | 6 + .../graphics/shaders/text-decorator-shader.vert | 8 + .../graphics/shaders/text-scroller-shader.frag | 14 ++ .../graphics/shaders/text-scroller-shader.vert | 30 +++ .../text-visual-multi-color-text-shader.frag | 11 ++ ...-visual-multi-color-text-with-style-shader.frag | 14 ++ .../graphics/shaders/text-visual-shader.vert | 26 +++ .../text-visual-single-color-text-shader.frag | 13 ++ ...visual-single-color-text-with-emoji-shader.frag | 21 +++ ...gle-color-text-with-style-and-emoji-shader.frag | 24 +++ ...visual-single-color-text-with-style-shader.frag | 15 ++ .../graphics/shaders/video-view-texture.frag | 8 + .../graphics/shaders/video-view-texture.vert | 11 ++ .../internal/graphics/shaders/video-view.frag | 4 + .../internal/graphics/shaders/video-view.vert | 10 + .../graphics/shaders/wireframe-visual-shader.frag | 7 + .../graphics/shaders/wireframe-visual-shader.vert | 22 +++ .../cube-transition-effect-impl.cpp | 37 +--- 134 files changed, 3013 insertions(+), 865 deletions(-) create mode 100755 build/tizen/shader-generator.sh create mode 100644 dali-toolkit/internal/graphics/shaders/alpha-discard-effect.frag create mode 100644 dali-toolkit/internal/graphics/shaders/animated-gradient-visual-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/animated-gradient-visual-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/arc-visual-butt-cap-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/arc-visual-round-cap-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/arc-visual-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/bloom-view-composite-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/bloom-view-extract-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/blur-two-images-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/blur-two-pass-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/border-visual-anti-aliasing-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/border-visual-anti-aliasing-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/border-visual-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/border-visual-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/bouncing-effect-mesh-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/bouncing-effect-mesh-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/bubble-effect-color-adjuster.frag create mode 100644 dali-toolkit/internal/graphics/shaders/bubble-effect.frag create mode 100644 dali-toolkit/internal/graphics/shaders/bubble-effect.vert create mode 100644 dali-toolkit/internal/graphics/shaders/bubble-emitter.frag create mode 100644 dali-toolkit/internal/graphics/shaders/bubble-emitter.vert create mode 100644 dali-toolkit/internal/graphics/shaders/color-visual-blur-edge-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/color-visual-blur-edge-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/color-visual-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/color-visual-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/control-renderers.frag create mode 100644 dali-toolkit/internal/graphics/shaders/control-renderers.vert create mode 100644 dali-toolkit/internal/graphics/shaders/cube-transition-effect.frag create mode 100644 dali-toolkit/internal/graphics/shaders/cube-transition-effect.vert create mode 100644 dali-toolkit/internal/graphics/shaders/dissolve-effect.frag create mode 100644 dali-toolkit/internal/graphics/shaders/dissolve-effect.vert create mode 100644 dali-toolkit/internal/graphics/shaders/distance-field-effect.frag create mode 100644 dali-toolkit/internal/graphics/shaders/effects-view.frag create mode 100644 dali-toolkit/internal/graphics/shaders/effects-view.vert create mode 100644 dali-toolkit/internal/graphics/shaders/emboss-filter-composite-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/emboss-filter-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/gaussian-blur-view.frag create mode 100644 dali-toolkit/internal/graphics/shaders/gltf-basecolor-texture.def create mode 100644 dali-toolkit/internal/graphics/shaders/gltf-emit-texture.def create mode 100644 dali-toolkit/internal/graphics/shaders/gltf-gles-version-300.def create mode 100644 dali-toolkit/internal/graphics/shaders/gltf-ibl-texture.def create mode 100644 dali-toolkit/internal/graphics/shaders/gltf-metallicroughness-texture.def create mode 100644 dali-toolkit/internal/graphics/shaders/gltf-normal-texture.def create mode 100644 dali-toolkit/internal/graphics/shaders/gltf-occulusion-texture.def create mode 100644 dali-toolkit/internal/graphics/shaders/gltf-physically-based-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/gltf-physically-based-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/gradient-visual-bounding-box-rounded-corner-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/gradient-visual-bounding-box-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/gradient-visual-linear-rounded-corner-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/gradient-visual-linear-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/gradient-visual-radial-rounded-corner-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/gradient-visual-radial-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/gradient-visual-user-space-rounded-corner-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/gradient-visual-user-space-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/image-region-effect.vert create mode 100644 dali-toolkit/internal/graphics/shaders/image-visual-atlas-clamp-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/image-visual-atlas-various-wrap-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/image-visual-no-atlas-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/image-visual-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/mesh-visual-normal-map-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/mesh-visual-normal-map-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/mesh-visual-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/mesh-visual-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/mesh-visual-simple-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/mesh-visual-simple-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/model3d-view-nrmmap-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/model3d-view-nrmmap-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/model3d-view-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/model3d-view-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/model3d-view-simple-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/model3d-view-simple-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/motion-blur-effect.frag create mode 100644 dali-toolkit/internal/graphics/shaders/motion-blur-effect.vert create mode 100644 dali-toolkit/internal/graphics/shaders/motion-stretch-effect.frag create mode 100644 dali-toolkit/internal/graphics/shaders/motion-stretch-effect.vert create mode 100644 dali-toolkit/internal/graphics/shaders/npatch-visual-3x3-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/npatch-visual-mask-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/npatch-visual-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/npatch-visual-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/page-turn-book-spine-effect.frag create mode 100644 dali-toolkit/internal/graphics/shaders/page-turn-book-spine-effect.vert create mode 100644 dali-toolkit/internal/graphics/shaders/page-turn-effect.frag create mode 100644 dali-toolkit/internal/graphics/shaders/page-turn-effect.vert create mode 100644 dali-toolkit/internal/graphics/shaders/primitive-visual-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/primitive-visual-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/shadow-view-render-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/shadow-view-render-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/spread-filter-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/super-blur-view.frag create mode 100644 dali-toolkit/internal/graphics/shaders/text-atlas-l8-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/text-atlas-rgba-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/text-atlas-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/text-controller-background-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/text-controller-background-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/text-decorator-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/text-decorator-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/text-scroller-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/text-scroller-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/text-visual-multi-color-text-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/text-visual-multi-color-text-with-style-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/text-visual-shader.vert create mode 100644 dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-with-emoji-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-with-style-and-emoji-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-with-style-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/video-view-texture.frag create mode 100644 dali-toolkit/internal/graphics/shaders/video-view-texture.vert create mode 100644 dali-toolkit/internal/graphics/shaders/video-view.frag create mode 100644 dali-toolkit/internal/graphics/shaders/video-view.vert create mode 100644 dali-toolkit/internal/graphics/shaders/wireframe-visual-shader.frag create mode 100644 dali-toolkit/internal/graphics/shaders/wireframe-visual-shader.vert diff --git a/.gitignore b/.gitignore index b28e3c5..aa38ad0 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ build/tizen/CMakeDoxygenDefaults.cmake core .clangd/ compile_commands.json +dali-toolkit/internal/graphics/generated/* +dali-toolkit/internal/graphics/builtin-shader-extern-gen.h diff --git a/build/tizen/CMakeLists.txt b/build/tizen/CMakeLists.txt index 63352ba..840ff92 100644 --- a/build/tizen/CMakeLists.txt +++ b/build/tizen/CMakeLists.txt @@ -283,6 +283,16 @@ IF(DEFINED STATIC) 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}" diff --git a/build/tizen/shader-generator.sh b/build/tizen/shader-generator.sh new file mode 100755 index 0000000..7b6b2fc --- /dev/null +++ b/build/tizen/shader-generator.sh @@ -0,0 +1,62 @@ +#!/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 " >> $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 + diff --git a/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp b/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp index ed35267..d54dcd3 100644 --- a/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp +++ b/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp @@ -33,6 +33,7 @@ // INTERNAL INCLUDES #include #include +#include #include #include #include @@ -85,54 +86,6 @@ const char* const BLOOM_SATURATION_PROPERTY_NAME = "uBloomSaturation"; 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 @@ -386,7 +339,7 @@ void BloomView::AllocateResources() ////////////////////////////////////////////////////// // 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 @@ -395,7 +348,7 @@ void BloomView::AllocateResources() 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() ); diff --git a/dali-toolkit/internal/controls/bubble-effect/bubble-effect.h b/dali-toolkit/internal/controls/bubble-effect/bubble-effect.h index 65b485f..4f4a3e5 100644 --- a/dali-toolkit/internal/controls/bubble-effect/bubble-effect.h +++ b/dali-toolkit/internal/controls/bubble-effect/bubble-effect.h @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include namespace Dali { @@ -38,87 +39,10 @@ namespace Internal */ 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; } diff --git a/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp b/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp index 5ee9047..b1e28e7 100644 --- a/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp +++ b/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp @@ -27,6 +27,7 @@ // INTERNAL INCLUDES #include #include +#include namespace { @@ -59,60 +60,6 @@ float RandomRange(float f0, float f1, unsigned int& seed) 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 @@ -265,7 +212,7 @@ void BubbleEmitter::SetBackground( Texture bgTexture, const Vector3& hsvDelta ) //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 ); diff --git a/dali-toolkit/internal/controls/bubble-effect/color-adjuster.h b/dali-toolkit/internal/controls/bubble-effect/color-adjuster.h index bbf81a9..ffcce3a 100644 --- a/dali-toolkit/internal/controls/bubble-effect/color-adjuster.h +++ b/dali-toolkit/internal/controls/bubble-effect/color-adjuster.h @@ -24,8 +24,7 @@ // INTERNAL INCLUDES #include - -#define DALI_COMPOSE_SHADER(STR) #STR +#include namespace Dali { @@ -51,50 +50,8 @@ inline void SetColorAdjusterProperties( Actor& actor, const Vector3& hsvDelta, b */ 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; diff --git a/dali-toolkit/internal/controls/control/control-renderers.cpp b/dali-toolkit/internal/controls/control/control-renderers.cpp index ea6e2e4..e864690 100644 --- a/dali-toolkit/internal/controls/control/control-renderers.cpp +++ b/dali-toolkit/internal/controls/control/control-renderers.cpp @@ -24,36 +24,6 @@ namespace Toolkit 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(); @@ -118,7 +88,7 @@ Geometry CreateGridGeometry( Uint16Pair gridSize ) 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 ); @@ -153,7 +123,7 @@ Dali::Renderer CreateRenderer( const char* vertexSrc, const char* 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 ); diff --git a/dali-toolkit/internal/controls/control/control-renderers.h b/dali-toolkit/internal/controls/control/control-renderers.h index 320528c..de14bb6 100644 --- a/dali-toolkit/internal/controls/control/control-renderers.h +++ b/dali-toolkit/internal/controls/control/control-renderers.h @@ -18,6 +18,7 @@ */ #include +#include namespace Dali { @@ -26,9 +27,8 @@ namespace Toolkit 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. @@ -36,7 +36,7 @@ extern const char* const BASIC_FRAGMENT_SOURCE; * @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. @@ -45,7 +45,7 @@ Dali::Renderer CreateRenderer( const char* vertexSrc, const char* fragmentSrc ); * @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. diff --git a/dali-toolkit/internal/controls/effects-view/effects-view-impl.cpp b/dali-toolkit/internal/controls/effects-view/effects-view-impl.cpp index f23d985..bd12e33 100644 --- a/dali-toolkit/internal/controls/effects-view/effects-view-impl.cpp +++ b/dali-toolkit/internal/controls/effects-view/effects-view-impl.cpp @@ -32,6 +32,7 @@ // INTERNAL INCLUDES #include #include +#include #include #include #include @@ -66,39 +67,6 @@ const float ARBITRARY_FIELD_OF_VIEW = Math::PI / 4.0f; 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 }; @@ -299,7 +267,8 @@ void EffectsView::OnSceneConnection( int depth ) 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 ); diff --git a/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp b/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp index 93fb35b..304c799 100644 --- a/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp +++ b/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp @@ -37,6 +37,7 @@ #include #include #include +#include // TODO: // pixel format / size - set from JSON @@ -102,24 +103,6 @@ const float GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_HEIGHT_SCALE = 0.5f; 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 // INTERNAL INCLUDES +#include #include #include @@ -93,185 +94,6 @@ DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, Model3dView, "lightPosition", V 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; @@ -459,7 +281,7 @@ void Model3dView::OnInitialize() { //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 ) { @@ -572,21 +394,21 @@ void Model3dView::CreateMaterial() { 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(); diff --git a/dali-toolkit/internal/controls/page-turn-view/page-turn-book-spine-effect.h b/dali-toolkit/internal/controls/page-turn-view/page-turn-book-spine-effect.h index 100c2c8..023e527 100644 --- a/dali-toolkit/internal/controls/page-turn-view/page-turn-book-spine-effect.h +++ b/dali-toolkit/internal/controls/page-turn-view/page-turn-book-spine-effect.h @@ -20,8 +20,7 @@ // INTERNAL INCLUDES #include - -#define DALI_COMPOSE_SHADER(STR) #STR +#include namespace Dali { @@ -52,57 +51,12 @@ namespace Internal **/ 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; diff --git a/dali-toolkit/internal/controls/page-turn-view/page-turn-effect.cpp b/dali-toolkit/internal/controls/page-turn-view/page-turn-effect.cpp index 15a48da..175d6d2 100644 --- a/dali-toolkit/internal/controls/page-turn-view/page-turn-effect.cpp +++ b/dali-toolkit/internal/controls/page-turn-view/page-turn-effect.cpp @@ -24,13 +24,13 @@ // INTERNAL INCLUDES #include #include +#include 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" ); @@ -124,216 +124,12 @@ void Dali::Toolkit::Internal::PageTurnApplyInternalConstraint( Actor& actor, flo 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; diff --git a/dali-toolkit/internal/controls/scrollable/bouncing-effect-actor.cpp b/dali-toolkit/internal/controls/scrollable/bouncing-effect-actor.cpp index a7db0d2..be63772 100644 --- a/dali-toolkit/internal/controls/scrollable/bouncing-effect-actor.cpp +++ b/dali-toolkit/internal/controls/scrollable/bouncing-effect-actor.cpp @@ -26,6 +26,9 @@ #include #include +// INTERNAL INCLUDES +#include + namespace Dali { @@ -47,31 +50,6 @@ const float LAYER_HEIGHTS[5] = 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 ) @@ -123,7 +101,7 @@ 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 ); diff --git a/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp b/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp index 37f7f53..3a86588 100644 --- a/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp +++ b/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp @@ -31,6 +31,7 @@ // INTERNAL INCLUDES #include +#include #include #include #include @@ -88,38 +89,6 @@ const char* const SHADER_SHADOW_COLOR_PROPERTY_NAME = "uShadowColor"; 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 ) @@ -159,7 +128,9 @@ void ShadowView::SetShadowPlaneBackground(Actor shadowPlaneBackground) 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 ); diff --git a/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp b/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp index 769a7fc..4cd42a4 100644 --- a/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp +++ b/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp @@ -32,6 +32,7 @@ // INTERNAL_INCLUDES #include #include +#include #include #include #include @@ -52,18 +53,6 @@ const float GAUSSIAN_BLUR_DOWNSAMPLE_WIDTH_SCALE = 0.5f; 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. @@ -314,7 +303,7 @@ void SuperBlurView::OnSceneConnection( int depth ) for(unsigned int i=0; i= 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 diff --git a/dali-toolkit/internal/graphics/shaders/bubble-emitter.frag b/dali-toolkit/internal/graphics/shaders/bubble-emitter.frag new file mode 100644 index 0000000..06690f8 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/bubble-emitter.frag @@ -0,0 +1,41 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/bubble-emitter.vert b/dali-toolkit/internal/graphics/shaders/bubble-emitter.vert new file mode 100644 index 0000000..f7bd577 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/bubble-emitter.vert @@ -0,0 +1,11 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-blur-edge-shader.frag b/dali-toolkit/internal/graphics/shaders/color-visual-blur-edge-shader.frag new file mode 100644 index 0000000..f2025a7 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/color-visual-blur-edge-shader.frag @@ -0,0 +1,13 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-blur-edge-shader.vert b/dali-toolkit/internal/graphics/shaders/color-visual-blur-edge-shader.vert new file mode 100644 index 0000000..65849eb --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/color-visual-blur-edge-shader.vert @@ -0,0 +1,29 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.frag b/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.frag new file mode 100644 index 0000000..d68e66f --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.frag @@ -0,0 +1,13 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.vert b/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.vert new file mode 100644 index 0000000..f4bc1ad --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.vert @@ -0,0 +1,34 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag new file mode 100644 index 0000000..fef045b --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag @@ -0,0 +1,7 @@ +uniform lowp vec4 uColor; +uniform lowp vec3 mixColor; + +void main() +{ + OUT_COLOR = vec4(mixColor, 1.0) * uColor; +} \ No newline at end of file diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/color-visual-shader.vert new file mode 100644 index 0000000..993d9d4 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/color-visual-shader.vert @@ -0,0 +1,24 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/control-renderers.frag b/dali-toolkit/internal/graphics/shaders/control-renderers.frag new file mode 100644 index 0000000..e29e6a1 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/control-renderers.frag @@ -0,0 +1,10 @@ +precision mediump float; +varying mediump vec2 vTexCoord; +uniform sampler2D sTexture; +uniform vec4 uColor; + +void main() +{ + gl_FragColor = texture2D(sTexture, vTexCoord); + gl_FragColor *= uColor; +} diff --git a/dali-toolkit/internal/graphics/shaders/control-renderers.vert b/dali-toolkit/internal/graphics/shaders/control-renderers.vert new file mode 100644 index 0000000..e7e930f --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/control-renderers.vert @@ -0,0 +1,12 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/cube-transition-effect.frag b/dali-toolkit/internal/graphics/shaders/cube-transition-effect.frag new file mode 100644 index 0000000..b8b19ac --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/cube-transition-effect.frag @@ -0,0 +1,9 @@ +varying mediump vec2 vTexCoord; +uniform sampler2D sTexture; +uniform lowp vec4 uColor; +uniform lowp vec4 uSamplerRect; + +void main() +{ + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor; +} diff --git a/dali-toolkit/internal/graphics/shaders/cube-transition-effect.vert b/dali-toolkit/internal/graphics/shaders/cube-transition-effect.vert new file mode 100644 index 0000000..fccd035 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/cube-transition-effect.vert @@ -0,0 +1,17 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/dissolve-effect.frag b/dali-toolkit/internal/graphics/shaders/dissolve-effect.frag new file mode 100644 index 0000000..e28a074 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/dissolve-effect.frag @@ -0,0 +1,21 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/dissolve-effect.vert b/dali-toolkit/internal/graphics/shaders/dissolve-effect.vert new file mode 100644 index 0000000..be8c3df --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/dissolve-effect.vert @@ -0,0 +1,34 @@ +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); +} diff --git a/dali-toolkit/internal/graphics/shaders/distance-field-effect.frag b/dali-toolkit/internal/graphics/shaders/distance-field-effect.frag new file mode 100644 index 0000000..82c294d --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/distance-field-effect.frag @@ -0,0 +1,97 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/effects-view.frag b/dali-toolkit/internal/graphics/shaders/effects-view.frag new file mode 100644 index 0000000..9c66b3b --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/effects-view.frag @@ -0,0 +1,9 @@ +varying mediump vec2 vTexCoord; +uniform sampler2D sTexture; +uniform lowp vec4 effectColor; + +void main() +{ + gl_FragColor = effectColor; + gl_FragColor.a *= texture2D( sTexture, vTexCoord).a; +} diff --git a/dali-toolkit/internal/graphics/shaders/effects-view.vert b/dali-toolkit/internal/graphics/shaders/effects-view.vert new file mode 100644 index 0000000..e8b7984 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/effects-view.vert @@ -0,0 +1,16 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/emboss-filter-composite-shader.frag b/dali-toolkit/internal/graphics/shaders/emboss-filter-composite-shader.frag new file mode 100644 index 0000000..1ef9fc1 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/emboss-filter-composite-shader.frag @@ -0,0 +1,9 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/emboss-filter-shader.frag b/dali-toolkit/internal/graphics/shaders/emboss-filter-shader.frag new file mode 100644 index 0000000..2a6761a --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/emboss-filter-shader.frag @@ -0,0 +1,13 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/gaussian-blur-view.frag b/dali-toolkit/internal/graphics/shaders/gaussian-blur-view.frag new file mode 100644 index 0000000..6613b0f --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/gaussian-blur-view.frag @@ -0,0 +1,15 @@ +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= 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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/gltf-physically-based-shader.vert b/dali-toolkit/internal/graphics/shaders/gltf-physically-based-shader.vert new file mode 100644 index 0000000..6628865 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/gltf-physically-based-shader.vert @@ -0,0 +1,60 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-bounding-box-rounded-corner-shader.vert b/dali-toolkit/internal/graphics/shaders/gradient-visual-bounding-box-rounded-corner-shader.vert new file mode 100644 index 0000000..79724e7 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-bounding-box-rounded-corner-shader.vert @@ -0,0 +1,37 @@ +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(); +} diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-bounding-box-shader.vert b/dali-toolkit/internal/graphics/shaders/gradient-visual-bounding-box-shader.vert new file mode 100644 index 0000000..018e260 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-bounding-box-shader.vert @@ -0,0 +1,27 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-linear-rounded-corner-shader.frag b/dali-toolkit/internal/graphics/shaders/gradient-visual-linear-rounded-corner-shader.frag new file mode 100644 index 0000000..61984eb --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-linear-rounded-corner-shader.frag @@ -0,0 +1,14 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-linear-shader.frag b/dali-toolkit/internal/graphics/shaders/gradient-visual-linear-shader.frag new file mode 100644 index 0000000..1ec04b2 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-linear-shader.frag @@ -0,0 +1,9 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-radial-rounded-corner-shader.frag b/dali-toolkit/internal/graphics/shaders/gradient-visual-radial-rounded-corner-shader.frag new file mode 100644 index 0000000..0ae8163 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-radial-rounded-corner-shader.frag @@ -0,0 +1,14 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-radial-shader.frag b/dali-toolkit/internal/graphics/shaders/gradient-visual-radial-shader.frag new file mode 100644 index 0000000..8d37383 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-radial-shader.frag @@ -0,0 +1,9 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-user-space-rounded-corner-shader.vert b/dali-toolkit/internal/graphics/shaders/gradient-visual-user-space-rounded-corner-shader.vert new file mode 100644 index 0000000..38f05fb --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-user-space-rounded-corner-shader.vert @@ -0,0 +1,38 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-user-space-shader.vert b/dali-toolkit/internal/graphics/shaders/gradient-visual-user-space-shader.vert new file mode 100644 index 0000000..ca1eab6 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-user-space-shader.vert @@ -0,0 +1,28 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/image-region-effect.vert b/dali-toolkit/internal/graphics/shaders/image-region-effect.vert new file mode 100644 index 0000000..5997336 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/image-region-effect.vert @@ -0,0 +1,28 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-atlas-clamp-shader.frag b/dali-toolkit/internal/graphics/shaders/image-visual-atlas-clamp-shader.frag new file mode 100644 index 0000000..0d87f9d --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/image-visual-atlas-clamp-shader.frag @@ -0,0 +1,13 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-atlas-various-wrap-shader.frag b/dali-toolkit/internal/graphics/shaders/image-visual-atlas-various-wrap-shader.frag new file mode 100644 index 0000000..eeb8a0c --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/image-visual-atlas-various-wrap-shader.frag @@ -0,0 +1,28 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-no-atlas-shader.frag b/dali-toolkit/internal/graphics/shaders/image-visual-no-atlas-shader.frag new file mode 100644 index 0000000..ffc960c --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/image-visual-no-atlas-shader.frag @@ -0,0 +1,11 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.frag b/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.frag new file mode 100644 index 0000000..1e3a1a7 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.frag @@ -0,0 +1,19 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.vert b/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.vert new file mode 100644 index 0000000..d4b129e --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.vert @@ -0,0 +1,37 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/image-visual-shader.vert new file mode 100644 index 0000000..fe0c35c --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/image-visual-shader.vert @@ -0,0 +1,27 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/mesh-visual-normal-map-shader.frag b/dali-toolkit/internal/graphics/shaders/mesh-visual-normal-map-shader.frag new file mode 100644 index 0000000..8c355ec --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/mesh-visual-normal-map-shader.frag @@ -0,0 +1,25 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/mesh-visual-normal-map-shader.vert b/dali-toolkit/internal/graphics/shaders/mesh-visual-normal-map-shader.vert new file mode 100644 index 0000000..c25a1bb --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/mesh-visual-normal-map-shader.vert @@ -0,0 +1,62 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/mesh-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/mesh-visual-shader.frag new file mode 100644 index 0000000..77f8649 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/mesh-visual-shader.frag @@ -0,0 +1,15 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/mesh-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/mesh-visual-shader.vert new file mode 100644 index 0000000..05b90ce --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/mesh-visual-shader.vert @@ -0,0 +1,58 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/mesh-visual-simple-shader.frag b/dali-toolkit/internal/graphics/shaders/mesh-visual-simple-shader.frag new file mode 100644 index 0000000..52b1e47 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/mesh-visual-simple-shader.frag @@ -0,0 +1,10 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/mesh-visual-simple-shader.vert b/dali-toolkit/internal/graphics/shaders/mesh-visual-simple-shader.vert new file mode 100644 index 0000000..2a4b704 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/mesh-visual-simple-shader.vert @@ -0,0 +1,48 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/model3d-view-nrmmap-shader.frag b/dali-toolkit/internal/graphics/shaders/model3d-view-nrmmap-shader.frag new file mode 100644 index 0000000..b2db8e9 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/model3d-view-nrmmap-shader.frag @@ -0,0 +1,22 @@ +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); +} diff --git a/dali-toolkit/internal/graphics/shaders/model3d-view-nrmmap-shader.vert b/dali-toolkit/internal/graphics/shaders/model3d-view-nrmmap-shader.vert new file mode 100644 index 0000000..3e00350 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/model3d-view-nrmmap-shader.vert @@ -0,0 +1,42 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/model3d-view-shader.frag b/dali-toolkit/internal/graphics/shaders/model3d-view-shader.frag new file mode 100644 index 0000000..0c48098 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/model3d-view-shader.frag @@ -0,0 +1,12 @@ +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); +} diff --git a/dali-toolkit/internal/graphics/shaders/model3d-view-shader.vert b/dali-toolkit/internal/graphics/shaders/model3d-view-shader.vert new file mode 100644 index 0000000..7987a18 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/model3d-view-shader.vert @@ -0,0 +1,39 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/model3d-view-simple-shader.frag b/dali-toolkit/internal/graphics/shaders/model3d-view-simple-shader.frag new file mode 100644 index 0000000..d7be96f --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/model3d-view-simple-shader.frag @@ -0,0 +1,8 @@ +precision mediump float; +varying mediump vec3 vIllumination; +uniform lowp vec4 uColor; + +void main() +{ + gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a); +} diff --git a/dali-toolkit/internal/graphics/shaders/model3d-view-simple-shader.vert b/dali-toolkit/internal/graphics/shaders/model3d-view-simple-shader.vert new file mode 100644 index 0000000..a94619e --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/model3d-view-simple-shader.vert @@ -0,0 +1,28 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/motion-blur-effect.frag b/dali-toolkit/internal/graphics/shaders/motion-blur-effect.frag new file mode 100644 index 0000000..b2c0857 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/motion-blur-effect.frag @@ -0,0 +1,45 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/motion-blur-effect.vert b/dali-toolkit/internal/graphics/shaders/motion-blur-effect.vert new file mode 100644 index 0000000..ed3ca94 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/motion-blur-effect.vert @@ -0,0 +1,75 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/motion-stretch-effect.frag b/dali-toolkit/internal/graphics/shaders/motion-stretch-effect.frag new file mode 100644 index 0000000..8754a4f --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/motion-stretch-effect.frag @@ -0,0 +1,30 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/motion-stretch-effect.vert b/dali-toolkit/internal/graphics/shaders/motion-stretch-effect.vert new file mode 100644 index 0000000..3ac7364 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/motion-stretch-effect.vert @@ -0,0 +1,77 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/npatch-visual-3x3-shader.vert b/dali-toolkit/internal/graphics/shaders/npatch-visual-3x3-shader.vert new file mode 100644 index 0000000..1586312 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/npatch-visual-3x3-shader.vert @@ -0,0 +1,39 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/npatch-visual-mask-shader.frag b/dali-toolkit/internal/graphics/shaders/npatch-visual-mask-shader.frag new file mode 100644 index 0000000..6b85462 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/npatch-visual-mask-shader.frag @@ -0,0 +1,23 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/npatch-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/npatch-visual-shader.frag new file mode 100644 index 0000000..acfd7f5 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/npatch-visual-shader.frag @@ -0,0 +1,10 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/npatch-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/npatch-visual-shader.vert new file mode 100644 index 0000000..07f645b --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/npatch-visual-shader.vert @@ -0,0 +1,38 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/page-turn-book-spine-effect.frag b/dali-toolkit/internal/graphics/shaders/page-turn-book-spine-effect.frag new file mode 100644 index 0000000..c4544aa --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/page-turn-book-spine-effect.frag @@ -0,0 +1,27 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/page-turn-book-spine-effect.vert b/dali-toolkit/internal/graphics/shaders/page-turn-book-spine-effect.vert new file mode 100644 index 0000000..900aeb9 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/page-turn-book-spine-effect.vert @@ -0,0 +1,14 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/page-turn-effect.frag b/dali-toolkit/internal/graphics/shaders/page-turn-effect.frag new file mode 100644 index 0000000..8fa6e77 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/page-turn-effect.frag @@ -0,0 +1,36 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/page-turn-effect.vert b/dali-toolkit/internal/graphics/shaders/page-turn-effect.vert new file mode 100644 index 0000000..9705061 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/page-turn-effect.vert @@ -0,0 +1,163 @@ +/* + * 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; +} diff --git a/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.frag new file mode 100644 index 0000000..610b774 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.frag @@ -0,0 +1,10 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.vert new file mode 100644 index 0000000..6605bc6 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.vert @@ -0,0 +1,51 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/shadow-view-render-shader.frag b/dali-toolkit/internal/graphics/shaders/shadow-view-render-shader.frag new file mode 100644 index 0000000..d193acf --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/shadow-view-render-shader.frag @@ -0,0 +1,10 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/shadow-view-render-shader.vert b/dali-toolkit/internal/graphics/shaders/shadow-view-render-shader.vert new file mode 100644 index 0000000..4b38884 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/shadow-view-render-shader.vert @@ -0,0 +1,17 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/spread-filter-shader.frag b/dali-toolkit/internal/graphics/shaders/spread-filter-shader.frag new file mode 100644 index 0000000..ac82763 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/spread-filter-shader.frag @@ -0,0 +1,17 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/super-blur-view.frag b/dali-toolkit/internal/graphics/shaders/super-blur-view.frag new file mode 100644 index 0000000..aad41e1 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/super-blur-view.frag @@ -0,0 +1,10 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/text-atlas-l8-shader.frag b/dali-toolkit/internal/graphics/shaders/text-atlas-l8-shader.frag new file mode 100644 index 0000000..e42de21 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-atlas-l8-shader.frag @@ -0,0 +1,11 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/text-atlas-rgba-shader.frag b/dali-toolkit/internal/graphics/shaders/text-atlas-rgba-shader.frag new file mode 100644 index 0000000..966ee90 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-atlas-rgba-shader.frag @@ -0,0 +1,9 @@ +uniform lowp vec4 uColor; +uniform lowp vec4 textColorAnimatable; +uniform sampler2D sTexture; +varying mediump vec2 vTexCoord; + +void main() +{ + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * textColorAnimatable; +} diff --git a/dali-toolkit/internal/graphics/shaders/text-atlas-shader.vert b/dali-toolkit/internal/graphics/shaders/text-atlas-shader.vert new file mode 100644 index 0000000..388f0c2 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-atlas-shader.vert @@ -0,0 +1,15 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/text-controller-background-shader.frag b/dali-toolkit/internal/graphics/shaders/text-controller-background-shader.frag new file mode 100644 index 0000000..c935d22 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-controller-background-shader.frag @@ -0,0 +1,7 @@ +varying mediump vec4 vColor; +uniform lowp vec4 uColor; + +void main() +{ + gl_FragColor = vColor * uColor; +} diff --git a/dali-toolkit/internal/graphics/shaders/text-controller-background-shader.vert b/dali-toolkit/internal/graphics/shaders/text-controller-background-shader.vert new file mode 100644 index 0000000..9ce403c --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-controller-background-shader.vert @@ -0,0 +1,11 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/text-decorator-shader.frag b/dali-toolkit/internal/graphics/shaders/text-decorator-shader.frag new file mode 100644 index 0000000..7402dde --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-decorator-shader.frag @@ -0,0 +1,6 @@ +uniform lowp vec4 uColor; + +void main() +{ + gl_FragColor = uColor; +} diff --git a/dali-toolkit/internal/graphics/shaders/text-decorator-shader.vert b/dali-toolkit/internal/graphics/shaders/text-decorator-shader.vert new file mode 100644 index 0000000..6afdfca --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-decorator-shader.vert @@ -0,0 +1,8 @@ +attribute mediump vec2 aPosition; +uniform highp mat4 uMvpMatrix; + +void main() +{ + mediump vec4 position = vec4( aPosition, 0.0, 1.0 ); + gl_Position = uMvpMatrix * position; +} diff --git a/dali-toolkit/internal/graphics/shaders/text-scroller-shader.frag b/dali-toolkit/internal/graphics/shaders/text-scroller-shader.frag new file mode 100644 index 0000000..25b85a3 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-scroller-shader.frag @@ -0,0 +1,14 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/text-scroller-shader.vert b/dali-toolkit/internal/graphics/shaders/text-scroller-shader.vert new file mode 100644 index 0000000..6c2cd05 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-scroller-shader.vert @@ -0,0 +1,30 @@ +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 diff --git a/dali-toolkit/internal/graphics/shaders/text-visual-multi-color-text-shader.frag b/dali-toolkit/internal/graphics/shaders/text-visual-multi-color-text-shader.frag new file mode 100644 index 0000000..e9e1069 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-visual-multi-color-text-shader.frag @@ -0,0 +1,11 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/text-visual-multi-color-text-with-style-shader.frag b/dali-toolkit/internal/graphics/shaders/text-visual-multi-color-text-with-style-shader.frag new file mode 100644 index 0000000..d8506cb --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-visual-multi-color-text-with-style-shader.frag @@ -0,0 +1,14 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/text-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/text-visual-shader.vert new file mode 100644 index 0000000..893d075 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-visual-shader.vert @@ -0,0 +1,26 @@ +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) ); +} diff --git a/dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-shader.frag b/dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-shader.frag new file mode 100644 index 0000000..ab44460 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-shader.frag @@ -0,0 +1,13 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-with-emoji-shader.frag b/dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-with-emoji-shader.frag new file mode 100644 index 0000000..544f0be --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-with-emoji-shader.frag @@ -0,0 +1,21 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-with-style-and-emoji-shader.frag b/dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-with-style-and-emoji-shader.frag new file mode 100644 index 0000000..b892a17 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-with-style-and-emoji-shader.frag @@ -0,0 +1,24 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-with-style-shader.frag b/dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-with-style-shader.frag new file mode 100644 index 0000000..f5d8b1c --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/text-visual-single-color-text-with-style-shader.frag @@ -0,0 +1,15 @@ +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 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/video-view-texture.frag b/dali-toolkit/internal/graphics/shaders/video-view-texture.frag new file mode 100644 index 0000000..306f12e --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/video-view-texture.frag @@ -0,0 +1,8 @@ +uniform lowp vec4 uColor; +varying mediump vec2 vTexCoord; +uniform samplerExternalOES sTexture; + +void main() +{ + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor; +} diff --git a/dali-toolkit/internal/graphics/shaders/video-view-texture.vert b/dali-toolkit/internal/graphics/shaders/video-view-texture.vert new file mode 100644 index 0000000..79cbb23 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/video-view-texture.vert @@ -0,0 +1,11 @@ +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); +} diff --git a/dali-toolkit/internal/graphics/shaders/video-view.frag b/dali-toolkit/internal/graphics/shaders/video-view.frag new file mode 100644 index 0000000..8045c0d --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/video-view.frag @@ -0,0 +1,4 @@ +void main() +{ + gl_FragColor = vec4(0.0); +} diff --git a/dali-toolkit/internal/graphics/shaders/video-view.vert b/dali-toolkit/internal/graphics/shaders/video-view.vert new file mode 100644 index 0000000..3f824dd --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/video-view.vert @@ -0,0 +1,10 @@ +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; +} diff --git a/dali-toolkit/internal/graphics/shaders/wireframe-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/wireframe-visual-shader.frag new file mode 100644 index 0000000..78d8759 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/wireframe-visual-shader.frag @@ -0,0 +1,7 @@ +uniform lowp vec4 uColor; +uniform lowp vec3 mixColor; + +void main() +{ + gl_FragColor = uColor * vec4( mixColor, 1.0 ); +} diff --git a/dali-toolkit/internal/graphics/shaders/wireframe-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/wireframe-visual-shader.vert new file mode 100644 index 0000000..5e0bfb0 --- /dev/null +++ b/dali-toolkit/internal/graphics/shaders/wireframe-visual-shader.vert @@ -0,0 +1,22 @@ +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(); +} diff --git a/dali-toolkit/internal/transition-effects/cube-transition-effect-impl.cpp b/dali-toolkit/internal/transition-effects/cube-transition-effect-impl.cpp index 29fd9e8..bd52a8b 100644 --- a/dali-toolkit/internal/transition-effects/cube-transition-effect-impl.cpp +++ b/dali-toolkit/internal/transition-effects/cube-transition-effect-impl.cpp @@ -22,10 +22,11 @@ #include // for strcmp #include #include -#include #include // INTERNAL INCLUDES +#include +#include #include namespace Dali @@ -47,38 +48,6 @@ DALI_SIGNAL_REGISTRATION( Toolkit, CubeTransitionEffect, "transitionCompleted", 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(); @@ -247,7 +216,7 @@ void CubeTransitionEffect::Initialize() 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(); -- 2.7.4