Commit 422d91612187d1a575b3ed00f7d33cb2d19e02ed
1 parent
39b38842
Convert shaders in dali-demo to use shader compilation tool
Change-Id: Ieee1546e6f20ad0f5fc29c239d7571e463bdcf6f
Showing
119 changed files
with
2043 additions
and
2172 deletions
build/tizen/examples/CMakeLists.txt
| ... | ... | @@ -21,6 +21,15 @@ IF (NOT "${ENABLE_SCENE_LOADER}" ) |
| 21 | 21 | ENDIF() |
| 22 | 22 | |
| 23 | 23 | FOREACH(EXAMPLE ${SUBDIRS}) |
| 24 | + # Generate source files for shaders | |
| 25 | + SET(SHADER_SOURCE_DIR "${EXAMPLES_SRC_DIR}/${EXAMPLE}/shaders/") | |
| 26 | + SET(SHADER_GENERATED_DIR "${EXAMPLES_SRC_DIR}/${EXAMPLE}/generated/") | |
| 27 | + SET(PARENT_CMAKE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../") | |
| 28 | + IF (EXISTS ${SHADER_SOURCE_DIR}) | |
| 29 | + EXECUTE_PROCESS( COMMAND bash -c "${PARENT_CMAKE_SOURCE_DIR}/shader-generator.sh ${SHADER_SOURCE_DIR} ${SHADER_GENERATED_DIR} --skip") | |
| 30 | + SET_PROPERTY( DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES | |
| 31 | + "${SHADER_GENERATED_DIR}" ) | |
| 32 | + ENDIF() | |
| 24 | 33 | FILE(GLOB SRCS "${EXAMPLES_SRC_DIR}/${EXAMPLE}/*.cpp") |
| 25 | 34 | SET(SRCS ${SRCS} "${ROOT_SRC_DIR}/shared/resources-location.cpp") |
| 26 | 35 | IF(SHARED) | ... | ... |
build/tizen/shader-generator.sh
0 → 100755
| 1 | +#!/bin/bash | |
| 2 | + | |
| 3 | +# Set Colors | |
| 4 | +Red='\033[0;31m' # Red | |
| 5 | +Yellow='\033[0;33m' # Yellow | |
| 6 | +Blue='\033[0;34m' # Blue | |
| 7 | +Clear='\033[0m' # Text Reset | |
| 8 | + | |
| 9 | +######################################################################################### | |
| 10 | + | |
| 11 | +Usage() | |
| 12 | +{ | |
| 13 | + echo -e "${Yellow}Usage: $(basename ${BASH_SOURCE[0]}) [indir] [outdir] [OPTIONS]" | |
| 14 | + echo | |
| 15 | + echo -e " ${Blue}Mandatory parameters:${Clear}" | |
| 16 | + echo -e " indir The input directory where the original shader files are located" | |
| 17 | + echo -e " outdir The output directory where the header files for the shaders should be generated" | |
| 18 | + echo -e " ${Red}NOTE: All the above parameters must be provided${Clear}" | |
| 19 | + echo | |
| 20 | + echo -e " ${Blue}Options:${Clear}" | |
| 21 | + echo -e " -s|--skip Skip the generation of header and cpp files that include all the generated shader header files" | |
| 22 | + echo -e " -h|--help Help" | |
| 23 | +} | |
| 24 | + | |
| 25 | +if [ "$1" = "-h" ] || [ "$1" = "--help" ] | |
| 26 | +then | |
| 27 | + Usage | |
| 28 | + exit 0 | |
| 29 | +elif [ "$#" -lt 2 ] | |
| 30 | +then | |
| 31 | + echo -e "${Red}ERROR:${Clear} Mandatory parameters are not provided" | |
| 32 | + echo | |
| 33 | + Usage | |
| 34 | + exit 1 | |
| 35 | +fi | |
| 36 | + | |
| 37 | +######################################################################################### | |
| 38 | + | |
| 39 | +indir=$1 | |
| 40 | +outdir=$2 | |
| 41 | +skip="" | |
| 42 | + | |
| 43 | +for option in $* | |
| 44 | +do | |
| 45 | + if [ "$option" = "-s" ] || [ "$option" = "--skip" ] | |
| 46 | + then | |
| 47 | + skip="--skip" | |
| 48 | + continue | |
| 49 | + elif [[ $option == -* ]] | |
| 50 | + then | |
| 51 | + echo -e "${Red}Invalid Option: ${Blue}$option${Clear}" | |
| 52 | + echo | |
| 53 | + Usage | |
| 54 | + exit 1 | |
| 55 | + fi | |
| 56 | +done | |
| 57 | + | |
| 58 | +######################################################################################### | |
| 59 | + | |
| 60 | +mkdir -p $outdir | |
| 61 | + | |
| 62 | +if [ ! -e $indir ] ; then | |
| 63 | + echo "Error: The folder \""$indir"\" does not exist!" | |
| 64 | + exit 1 | |
| 65 | +fi | |
| 66 | + | |
| 67 | +cd $indir | |
| 68 | +all_shaders=$(ls -1 *.{vert,frag,def} 2>/dev/null) | |
| 69 | +cd $OLDPWD | |
| 70 | + | |
| 71 | +# Generate one header file per shader which is defined as a const std::string_view | |
| 72 | +for name in $all_shaders ; do | |
| 73 | + echo "Generating header files for $name..." | |
| 74 | + varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;') | |
| 75 | + | |
| 76 | + newname=$(echo ${name} | sed -e 's/\./-/;')".h" | |
| 77 | + echo Writing $newname | |
| 78 | + | |
| 79 | + shader_fullpath=$(echo ${indir})$name | |
| 80 | + | |
| 81 | + header_name="${varname}_GEN_H" | |
| 82 | + echo "const std::string_view" "$varname""{" > $outdir/$newname | |
| 83 | + cat $shader_fullpath | sed -e 's/^..*$/"&\\n"/' >> $outdir/$newname | |
| 84 | + echo "};" >> $outdir/$newname | |
| 85 | +done | |
| 86 | + | |
| 87 | +if [ "$skip" != "--skip" ]; then | |
| 88 | + # Generate one cpp file that includes all the previously generated string_views for shaders | |
| 89 | + echo "Generating cpp file..." | |
| 90 | + echo -e "#include \"../builtin-shader-extern-gen.h\"\n" > $outdir/builtin-shader-gen.cpp | |
| 91 | + | |
| 92 | + varnames= | |
| 93 | + for name in $all_shaders ; do | |
| 94 | + varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;') | |
| 95 | + newname=$(echo ${name} | sed -e 's/\./-/;')".h" | |
| 96 | + varnames="${varnames} $varname" | |
| 97 | + echo "#include \"$newname\"" >> $outdir/builtin-shader-gen.cpp | |
| 98 | + done | |
| 99 | + | |
| 100 | + # Generate one header file that defines all the shader string_views as extern variables | |
| 101 | + echo "Generating extern header file ( for external use )..." | |
| 102 | + echo "#ifndef GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H" > $outdir/../builtin-shader-extern-gen.h | |
| 103 | + echo -e "#define GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H\n" >> $outdir/../builtin-shader-extern-gen.h | |
| 104 | + | |
| 105 | + echo "#include <string_view>" >> $outdir/../builtin-shader-extern-gen.h | |
| 106 | + echo "" >> $outdir/../builtin-shader-extern-gen.h | |
| 107 | + | |
| 108 | + for name in $all_shaders ; do | |
| 109 | + varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;') | |
| 110 | + newname=$(echo ${name} | sed -e 's/\./-/;')".h" | |
| 111 | + echo "extern const std::string_view $varname;" >> $outdir/../builtin-shader-extern-gen.h | |
| 112 | + done | |
| 113 | + cat >> $outdir/../builtin-shader-extern-gen.h << EOF | |
| 114 | + | |
| 115 | +#endif // GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H | |
| 116 | +EOF | |
| 117 | +fi | |
| 118 | + | ... | ... |
examples/animated-shapes/animated-shapes-example.cpp
| ... | ... | @@ -18,6 +18,8 @@ |
| 18 | 18 | #include <dali-toolkit/dali-toolkit.h> |
| 19 | 19 | #include <dali/dali.h> |
| 20 | 20 | #include "shared/view.h" |
| 21 | +#include "generated/animated-shapes-vert.h" | |
| 22 | +#include "generated/animated-shapes-frag.h" | |
| 21 | 23 | |
| 22 | 24 | #include <sstream> |
| 23 | 25 | |
| ... | ... | @@ -28,50 +30,16 @@ namespace |
| 28 | 30 | { |
| 29 | 31 | const char* APPLICATION_TITLE("Animated Shapes"); |
| 30 | 32 | |
| 31 | -// clang-format off | |
| 32 | -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER | |
| 33 | -( | |
| 34 | - attribute mediump vec3 aCoefficient; | |
| 35 | - uniform mediump mat4 uMvpMatrix; | |
| 36 | - uniform mediump vec3 uPosition[MAX_POINT_COUNT]; | |
| 37 | - varying lowp vec2 vCoefficient; | |
| 38 | - void main() | |
| 39 | - { | |
| 40 | - int vertexId = int(aCoefficient.z); | |
| 41 | - gl_Position = uMvpMatrix * vec4(uPosition[vertexId], 1.0); | |
| 42 | - | |
| 43 | - vCoefficient = aCoefficient.xy; | |
| 44 | - } | |
| 45 | -); | |
| 46 | - | |
| 47 | -// Fragment shader. | |
| 48 | -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER | |
| 49 | -( | |
| 50 | - uniform lowp vec4 uColor; | |
| 51 | - varying lowp vec2 vCoefficient; | |
| 52 | - void main() | |
| 53 | - { | |
| 54 | - lowp float C = (vCoefficient.x*vCoefficient.x-vCoefficient.y); | |
| 55 | - lowp float Cdx = dFdx(C); | |
| 56 | - lowp float Cdy = dFdy(C); | |
| 57 | - | |
| 58 | - lowp float distance = float(C / sqrt(Cdx*Cdx + Cdy*Cdy)); | |
| 59 | - lowp float alpha = 0.5 - distance; | |
| 60 | - gl_FragColor = vec4( uColor.rgb, uColor.a * alpha ); | |
| 61 | - } | |
| 62 | -); | |
| 63 | -// clang-format on | |
| 64 | - | |
| 65 | 33 | Shader CreateShader(unsigned int pointCount) |
| 66 | 34 | { |
| 67 | 35 | std::ostringstream vertexShader; |
| 68 | 36 | vertexShader << "#define MAX_POINT_COUNT " << pointCount << "\n" |
| 69 | - << VERTEX_SHADER; | |
| 37 | + << SHADER_ANIMATED_SHAPES_VERT; | |
| 70 | 38 | |
| 71 | 39 | std::ostringstream fragmentShader; |
| 72 | 40 | fragmentShader << "#extension GL_OES_standard_derivatives : enable " |
| 73 | 41 | << "\n" |
| 74 | - << FRAGMENT_SHADER; | |
| 42 | + << SHADER_ANIMATED_SHAPES_FRAG; | |
| 75 | 43 | |
| 76 | 44 | Shader shader = Shader::New(vertexShader.str(), fragmentShader.str()); |
| 77 | 45 | for(unsigned int i(0); i < pointCount; ++i) | ... | ... |
examples/animated-shapes/shaders/animated-shapes.frag
0 → 100644
| 1 | +uniform lowp vec4 uColor; | |
| 2 | +varying lowp vec2 vCoefficient; | |
| 3 | + | |
| 4 | +void main() | |
| 5 | +{ | |
| 6 | + lowp float C = (vCoefficient.x*vCoefficient.x-vCoefficient.y); | |
| 7 | + lowp float Cdx = dFdx(C); | |
| 8 | + lowp float Cdy = dFdy(C); | |
| 9 | + | |
| 10 | + lowp float distance = float(C / sqrt(Cdx*Cdx + Cdy*Cdy)); | |
| 11 | + lowp float alpha = 0.5 - distance; | |
| 12 | + gl_FragColor = vec4( uColor.rgb, uColor.a * alpha ); | |
| 13 | +} | ... | ... |
examples/animated-shapes/shaders/animated-shapes.vert
0 → 100644
| 1 | +attribute mediump vec3 aCoefficient; | |
| 2 | +uniform mediump mat4 uMvpMatrix; | |
| 3 | +uniform mediump vec3 uPosition[MAX_POINT_COUNT]; | |
| 4 | +varying lowp vec2 vCoefficient; | |
| 5 | + | |
| 6 | +void main() | |
| 7 | +{ | |
| 8 | + int vertexId = int(aCoefficient.z); | |
| 9 | + gl_Position = uMvpMatrix * vec4(uPosition[vertexId], 1.0); | |
| 10 | + | |
| 11 | + vCoefficient = aCoefficient.xy; | |
| 12 | +} | ... | ... |
examples/benchmark/benchmark.cpp
| ... | ... | @@ -20,6 +20,8 @@ |
| 20 | 20 | |
| 21 | 21 | // INTERNAL INCLUDES |
| 22 | 22 | #include "shared/utility.h" |
| 23 | +#include "generated/benchmark-vert.h" | |
| 24 | +#include "generated/benchmark-frag.h" | |
| 23 | 25 | |
| 24 | 26 | using namespace Dali; |
| 25 | 27 | using namespace Dali::Toolkit; |
| ... | ... | @@ -149,33 +151,6 @@ struct VertexWithTexture |
| 149 | 151 | Vector2 texCoord; |
| 150 | 152 | }; |
| 151 | 153 | |
| 152 | -// clang-format off | |
| 153 | -const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( | |
| 154 | - attribute mediump vec2 aPosition;\n | |
| 155 | - attribute mediump vec2 aTexCoord;\n | |
| 156 | - uniform mediump mat4 uMvpMatrix;\n | |
| 157 | - uniform mediump vec3 uSize;\n | |
| 158 | - varying mediump vec2 vTexCoord;\n | |
| 159 | - void main()\n | |
| 160 | - {\n | |
| 161 | - vec4 position = vec4(aPosition,0.0,1.0)*vec4(uSize,1.0);\n | |
| 162 | - gl_Position = uMvpMatrix * position;\n | |
| 163 | - vTexCoord = aTexCoord;\n | |
| 164 | - }\n | |
| 165 | -); | |
| 166 | - | |
| 167 | -const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( | |
| 168 | - uniform lowp vec4 uColor;\n | |
| 169 | - uniform sampler2D sTexture;\n | |
| 170 | - varying mediump vec2 vTexCoord;\n | |
| 171 | - | |
| 172 | - void main()\n | |
| 173 | - {\n | |
| 174 | - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n | |
| 175 | - }\n | |
| 176 | -); | |
| 177 | -// clang-format on | |
| 178 | - | |
| 179 | 154 | bool gUseMesh(false); |
| 180 | 155 | bool gNinePatch(false); |
| 181 | 156 | unsigned int gRowsPerPage(25); |
| ... | ... | @@ -282,7 +257,7 @@ public: |
| 282 | 257 | |
| 283 | 258 | //Create all the renderers |
| 284 | 259 | std::vector<Renderer> renderers(numImages); |
| 285 | - Shader shader = Shader::New(VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE); | |
| 260 | + Shader shader = Shader::New(SHADER_BENCHMARK_VERT, SHADER_BENCHMARK_FRAG); | |
| 286 | 261 | Geometry geometry = DemoHelper::CreateTexturedQuad(); |
| 287 | 262 | for(unsigned int i(0); i < numImages; ++i) |
| 288 | 263 | { | ... | ... |
examples/benchmark/shaders/benchmark.frag
0 → 100644
examples/benchmark/shaders/benchmark.vert
0 → 100644
| 1 | +attribute mediump vec2 aPosition; | |
| 2 | +attribute mediump vec2 aTexCoord; | |
| 3 | +uniform mediump mat4 uMvpMatrix; | |
| 4 | +uniform mediump vec3 uSize; | |
| 5 | +varying mediump vec2 vTexCoord; | |
| 6 | + | |
| 7 | +void main() | |
| 8 | +{ | |
| 9 | + vec4 position = vec4(aPosition,0.0,1.0)*vec4(uSize,1.0); | |
| 10 | + gl_Position = uMvpMatrix * position; | |
| 11 | + vTexCoord = aTexCoord; | |
| 12 | +} | ... | ... |
examples/bezier-curve/bezier-curve-example.cpp
| ... | ... | @@ -19,6 +19,8 @@ |
| 19 | 19 | #include <dali-toolkit/devel-api/controls/table-view/table-view.h> |
| 20 | 20 | #include <dali/dali.h> |
| 21 | 21 | #include "shared/view.h" |
| 22 | +#include "generated/bezier-curve-vert.h" | |
| 23 | +#include "generated/bezier-curve-frag.h" | |
| 22 | 24 | |
| 23 | 25 | #include <sstream> |
| 24 | 26 | |
| ... | ... | @@ -42,28 +44,6 @@ const float ANIM_RIGHT_FACTOR(0.8f); |
| 42 | 44 | const int AXIS_LABEL_POINT_SIZE(7); |
| 43 | 45 | const float AXIS_LINE_SIZE(1.0f); |
| 44 | 46 | |
| 45 | -// clang-format off | |
| 46 | -const char* CURVE_VERTEX_SHADER = DALI_COMPOSE_SHADER | |
| 47 | - ( | |
| 48 | - attribute mediump vec2 aPosition; | |
| 49 | - uniform mediump mat4 uMvpMatrix; | |
| 50 | - uniform vec3 uSize; | |
| 51 | - void main() | |
| 52 | - { | |
| 53 | - gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy, 0.0, 1.0); | |
| 54 | - } | |
| 55 | - ); | |
| 56 | - | |
| 57 | -const char* CURVE_FRAGMENT_SHADER = DALI_COMPOSE_SHADER | |
| 58 | - ( | |
| 59 | - uniform lowp vec4 uColor; | |
| 60 | - void main() | |
| 61 | - { | |
| 62 | - gl_FragColor = vec4(0.0,0.0,0.0,1.0); | |
| 63 | - } | |
| 64 | - ); | |
| 65 | -// clang-format on | |
| 66 | - | |
| 67 | 47 | inline float Clamp(float v, float min, float max) |
| 68 | 48 | { |
| 69 | 49 | if(v < min) return min; |
| ... | ... | @@ -294,7 +274,7 @@ public: |
| 294 | 274 | mCurve.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); |
| 295 | 275 | mCurve.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); |
| 296 | 276 | |
| 297 | - Shader shader = Shader::New(CURVE_VERTEX_SHADER, CURVE_FRAGMENT_SHADER); | |
| 277 | + Shader shader = Shader::New(SHADER_BEZIER_CURVE_VERT, SHADER_BEZIER_CURVE_FRAG); | |
| 298 | 278 | |
| 299 | 279 | Property::Map curveVertexFormat; |
| 300 | 280 | curveVertexFormat["aPosition"] = Property::VECTOR2; |
| ... | ... | @@ -338,7 +318,7 @@ public: |
| 338 | 318 | line.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); |
| 339 | 319 | line.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); |
| 340 | 320 | |
| 341 | - Shader shader = Shader::New(CURVE_VERTEX_SHADER, CURVE_FRAGMENT_SHADER); | |
| 321 | + Shader shader = Shader::New(SHADER_BEZIER_CURVE_VERT, SHADER_BEZIER_CURVE_FRAG); | |
| 342 | 322 | Geometry geometry = Geometry::New(); |
| 343 | 323 | geometry.AddVertexBuffer(vertexBuffer); |
| 344 | 324 | geometry.SetType(Geometry::LINE_STRIP); | ... | ... |
examples/bezier-curve/shaders/bezier-curve.frag
0 → 100644
examples/bezier-curve/shaders/bezier-curve.vert
0 → 100644
examples/color-transition/color-transition-controller.cpp
| ... | ... | @@ -18,6 +18,8 @@ |
| 18 | 18 | #include "utils.h" |
| 19 | 19 | #include "dali/dali.h" |
| 20 | 20 | #include "dali-toolkit/dali-toolkit.h" |
| 21 | +#include "generated/color-transition-controller-composite-vert.h" | |
| 22 | +#include "generated/color-transition-controller-composite-frag.h" | |
| 21 | 23 | |
| 22 | 24 | using namespace Dali; |
| 23 | 25 | using namespace Dali::Toolkit; |
| ... | ... | @@ -27,65 +29,6 @@ namespace |
| 27 | 29 | |
| 28 | 30 | const Vector4 BG_COLOR = Vector4(0.f, 0.f, 0.f, 0.f); |
| 29 | 31 | |
| 30 | -const char* const COMPOSITE_VSH = DALI_COMPOSE_SHADER( | |
| 31 | -precision mediump float; | |
| 32 | - | |
| 33 | -// <DALI> | |
| 34 | -uniform mat4 uMvpMatrix; | |
| 35 | -uniform vec3 uSize; | |
| 36 | -// </DALI> | |
| 37 | - | |
| 38 | -uniform float uFlow; | |
| 39 | -uniform vec4 uUvTransform; // rotation, scale (initial, target)) | |
| 40 | - | |
| 41 | -attribute vec2 aPosition; | |
| 42 | - | |
| 43 | -varying vec2 vUv; | |
| 44 | -varying vec2 vUvFlow; | |
| 45 | - | |
| 46 | -void main() | |
| 47 | -{ | |
| 48 | - vec4 position = uMvpMatrix * vec4(aPosition * uSize.xy, 0., 1.); | |
| 49 | - | |
| 50 | - gl_Position = position; | |
| 51 | - | |
| 52 | - vec2 uv = position.xy / (position.ww * 2.); | |
| 53 | - vUv = uv + vec2(.5); | |
| 54 | - | |
| 55 | - float alpha = uFlow * .5 + .5; | |
| 56 | - vec2 uvRotationScale = mix(uUvTransform.xy, uUvTransform.zw, alpha); | |
| 57 | - float c = cos(uvRotationScale.x) * uvRotationScale.y; | |
| 58 | - float s = sin(uvRotationScale.x) * uvRotationScale.y; | |
| 59 | - vec4 uvMatrix = vec4(c, -s, s, c); | |
| 60 | - uv = vec2(dot(uvMatrix.xy, uv), dot(uvMatrix.zw, uv)); | |
| 61 | - | |
| 62 | - // N.B. +y is down which is well aligned with the inverted y of the off-screen render, | |
| 63 | - // however we need to flip the y of the uvs for the flow map. | |
| 64 | - vUvFlow = vec2(uv.x + .5, .5 - uv.y); | |
| 65 | -}); | |
| 66 | - | |
| 67 | -const char* const COMPOSITE_FSH = DALI_COMPOSE_SHADER( | |
| 68 | -precision mediump float; | |
| 69 | - | |
| 70 | -const float kStepsilon = 1e-2; | |
| 71 | - | |
| 72 | -uniform sampler2D sColor; | |
| 73 | -uniform sampler2D sFlowMap; | |
| 74 | - | |
| 75 | -uniform float uFlow; | |
| 76 | -uniform vec3 uRgb[2]; | |
| 77 | - | |
| 78 | -varying vec2 vUv; | |
| 79 | -varying vec2 vUvFlow; | |
| 80 | - | |
| 81 | -void main() | |
| 82 | -{ | |
| 83 | - vec4 colorAlpha = texture2D(sColor, vUv); | |
| 84 | - float flow = smoothstep(.5 - kStepsilon, .5 + kStepsilon, clamp(uFlow + texture2D(sFlowMap, vUvFlow).r, 0., 1.)); | |
| 85 | - | |
| 86 | - gl_FragColor = vec4(mix(colorAlpha.rgb, mix(uRgb[0], uRgb[1], flow), colorAlpha.a), 1.); | |
| 87 | -}); | |
| 88 | - | |
| 89 | 32 | } // nonamespace |
| 90 | 33 | |
| 91 | 34 | ColorTransitionController::ColorTransitionController(WeakHandle<RenderTaskList> window, Actor content, RenderTaskList tasks, Vector3 initialColor) |
| ... | ... | @@ -129,7 +72,7 @@ ColorTransitionController::ColorTransitionController(WeakHandle<RenderTaskList> |
| 129 | 72 | flowSampler.SetWrapMode(WrapMode::REPEAT, WrapMode::REPEAT); |
| 130 | 73 | tsComposite.SetSampler(1, flowSampler); |
| 131 | 74 | |
| 132 | - auto shdComposite = Shader::New(COMPOSITE_VSH, COMPOSITE_FSH); | |
| 75 | + auto shdComposite = Shader::New(SHADER_COLOR_TRANSITION_CONTROLLER_COMPOSITE_VERT, SHADER_COLOR_TRANSITION_CONTROLLER_COMPOSITE_FRAG); | |
| 133 | 76 | |
| 134 | 77 | auto compositeRenderer = CreateRenderer(tsComposite, geomComposite, shdComposite); |
| 135 | 78 | composite.AddRenderer(compositeRenderer); | ... | ... |
examples/color-transition/shaders/color-transition-controller-composite.frag
0 → 100644
| 1 | +precision mediump float; | |
| 2 | + | |
| 3 | +const float kStepsilon = 1e-2; | |
| 4 | + | |
| 5 | +uniform sampler2D sColor; | |
| 6 | +uniform sampler2D sFlowMap; | |
| 7 | + | |
| 8 | +uniform float uFlow; | |
| 9 | +uniform vec3 uRgb[2]; | |
| 10 | + | |
| 11 | +varying vec2 vUv; | |
| 12 | +varying vec2 vUvFlow; | |
| 13 | + | |
| 14 | +void main() | |
| 15 | +{ | |
| 16 | + vec4 colorAlpha = texture2D(sColor, vUv); | |
| 17 | + float flow = smoothstep(.5 - kStepsilon, .5 + kStepsilon, clamp(uFlow + texture2D(sFlowMap, vUvFlow).r, 0., 1.)); | |
| 18 | + | |
| 19 | + gl_FragColor = vec4(mix(colorAlpha.rgb, mix(uRgb[0], uRgb[1], flow), colorAlpha.a), 1.); | |
| 20 | +} | ... | ... |
examples/color-transition/shaders/color-transition-controller-composite.vert
0 → 100644
| 1 | +precision mediump float; | |
| 2 | + | |
| 3 | +// <DALI> | |
| 4 | +uniform mat4 uMvpMatrix; | |
| 5 | +uniform vec3 uSize; | |
| 6 | +// </DALI> | |
| 7 | + | |
| 8 | +uniform float uFlow; | |
| 9 | +uniform vec4 uUvTransform; // rotation, scale (initial, target)) | |
| 10 | + | |
| 11 | +attribute vec2 aPosition; | |
| 12 | + | |
| 13 | +varying vec2 vUv; | |
| 14 | +varying vec2 vUvFlow; | |
| 15 | + | |
| 16 | +void main() | |
| 17 | +{ | |
| 18 | + vec4 position = uMvpMatrix * vec4(aPosition * uSize.xy, 0., 1.); | |
| 19 | + | |
| 20 | + gl_Position = position; | |
| 21 | + | |
| 22 | + vec2 uv = position.xy / (position.ww * 2.); | |
| 23 | + vUv = uv + vec2(.5); | |
| 24 | + | |
| 25 | + float alpha = uFlow * .5 + .5; | |
| 26 | + vec2 uvRotationScale = mix(uUvTransform.xy, uUvTransform.zw, alpha); | |
| 27 | + float c = cos(uvRotationScale.x) * uvRotationScale.y; | |
| 28 | + float s = sin(uvRotationScale.x) * uvRotationScale.y; | |
| 29 | + vec4 uvMatrix = vec4(c, -s, s, c); | |
| 30 | + uv = vec2(dot(uvMatrix.xy, uv), dot(uvMatrix.zw, uv)); | |
| 31 | + | |
| 32 | + // N.B. +y is down which is well aligned with the inverted y of the off-screen render, | |
| 33 | + // however we need to flip the y of the uvs for the flow map. | |
| 34 | + vUvFlow = vec2(uv.x + .5, .5 - uv.y); | |
| 35 | +} | ... | ... |
examples/compressed-texture-formats/compressed-texture-formats-example.cpp
| ... | ... | @@ -22,6 +22,8 @@ |
| 22 | 22 | |
| 23 | 23 | // INTERNAL INCLUDES |
| 24 | 24 | #include "shared/utility.h" |
| 25 | +#include "generated/compressed-texture-formats-example-vert.h" | |
| 26 | +#include "generated/compressed-texture-formats-example-frag.h" | |
| 25 | 27 | |
| 26 | 28 | using namespace Dali; |
| 27 | 29 | using Dali::Toolkit::TextLabel; |
| ... | ... | @@ -32,33 +34,6 @@ const char* IMAGE_FILENAME_ETC = DEMO_IMAGE_DIR "tx-etc1.ktx"; |
| 32 | 34 | const char* IMAGE_FILENAME_ASTC_LINEAR = DEMO_IMAGE_DIR "tx-astc-4x4-linear.ktx"; |
| 33 | 35 | const char* IMAGE_FILENAME_ASTC_LINEAR_NATIVE = DEMO_IMAGE_DIR "tx-astc-4x4-linear-native.astc"; |
| 34 | 36 | |
| 35 | -// clang-format off | |
| 36 | -static const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( | |
| 37 | - attribute mediump vec2 aPosition;\n | |
| 38 | - attribute mediump vec2 aTexCoord;\n | |
| 39 | - uniform mediump mat4 uMvpMatrix;\n | |
| 40 | - uniform mediump vec3 uSize;\n | |
| 41 | - varying mediump vec2 vTexCoord;\n | |
| 42 | - void main()\n | |
| 43 | - {\n | |
| 44 | - vec4 position = vec4(aPosition,0.0,1.0)*vec4(uSize,1.0);\n | |
| 45 | - gl_Position = uMvpMatrix * position;\n | |
| 46 | - vTexCoord = aTexCoord;\n | |
| 47 | - }\n | |
| 48 | -); | |
| 49 | - | |
| 50 | -static const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( | |
| 51 | - uniform lowp vec4 uColor;\n | |
| 52 | - uniform sampler2D sTexture;\n | |
| 53 | - varying mediump vec2 vTexCoord;\n | |
| 54 | - | |
| 55 | - void main()\n | |
| 56 | - {\n | |
| 57 | - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n | |
| 58 | - }\n | |
| 59 | -); | |
| 60 | -// clang-format on | |
| 61 | - | |
| 62 | 37 | /** |
| 63 | 38 | * @brief Create a renderer to render an image and adds it to an actor |
| 64 | 39 | * @param[in] imagePath The path where the image file is located |
| ... | ... | @@ -148,7 +123,7 @@ public: |
| 148 | 123 | |
| 149 | 124 | //Create the geometry and the shader renderers will use |
| 150 | 125 | Geometry geometry = DemoHelper::CreateTexturedQuad(); |
| 151 | - Shader shader = Shader::New(VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE); | |
| 126 | + Shader shader = Shader::New(SHADER_COMPRESSED_TEXTURE_FORMATS_EXAMPLE_VERT, SHADER_COMPRESSED_TEXTURE_FORMATS_EXAMPLE_FRAG); | |
| 152 | 127 | |
| 153 | 128 | // Add images. |
| 154 | 129 | Actor actor = Actor::New(); | ... | ... |
examples/compressed-texture-formats/shaders/compressed-texture-formats-example.frag
0 → 100644
examples/compressed-texture-formats/shaders/compressed-texture-formats-example.vert
0 → 100644
| 1 | +attribute mediump vec2 aPosition; | |
| 2 | +attribute mediump vec2 aTexCoord; | |
| 3 | +uniform mediump mat4 uMvpMatrix; | |
| 4 | +uniform mediump vec3 uSize; | |
| 5 | +varying mediump vec2 vTexCoord; | |
| 6 | + | |
| 7 | +void main() | |
| 8 | +{ | |
| 9 | + vec4 position = vec4(aPosition,0.0,1.0)*vec4(uSize,1.0); | |
| 10 | + gl_Position = uMvpMatrix * position; | |
| 11 | + vTexCoord = aTexCoord; | |
| 12 | +} | ... | ... |
examples/contact-cards/clipped-image.cpp
| ... | ... | @@ -21,6 +21,10 @@ |
| 21 | 21 | // EXTERNAL INCLUDES |
| 22 | 22 | #include <dali-toolkit/dali-toolkit.h> |
| 23 | 23 | |
| 24 | +// INTERNAL INCLUDES | |
| 25 | +#include "generated/clipped-image-vert.h" | |
| 26 | +#include "generated/clipped-image-frag.h" | |
| 27 | + | |
| 24 | 28 | namespace ClippedImage |
| 25 | 29 | { |
| 26 | 30 | using namespace Dali; |
| ... | ... | @@ -31,39 +35,6 @@ namespace |
| 31 | 35 | const char* const DELTA_PROPERTY_NAME("uDelta"); ///< Name of uniform used to mix the Circle and Quad geometries. |
| 32 | 36 | |
| 33 | 37 | /** |
| 34 | - * @brief This vertex-shader mixes in the quad and circle geometry depending on the value of uDelta. | |
| 35 | - * | |
| 36 | - * uDelta is used to mix in the Circle and the Quad positions. | |
| 37 | - * If uDelta is 0.0f, then the circle position is adopted and if it is 1.0f, then the quad position is adopted. | |
| 38 | - */ | |
| 39 | -// clang-format off | |
| 40 | -const char * VERTEX_SHADER = DALI_COMPOSE_SHADER( | |
| 41 | - attribute mediump vec2 aPositionCircle;\n | |
| 42 | - attribute mediump vec2 aPositionQuad;\n | |
| 43 | - uniform mediump float uDelta; | |
| 44 | - uniform mediump mat4 uMvpMatrix;\n | |
| 45 | - uniform mediump vec3 uSize;\n | |
| 46 | - \n | |
| 47 | - void main()\n | |
| 48 | - {\n | |
| 49 | - mediump vec4 vertexPosition = vec4(mix(aPositionCircle,aPositionQuad,uDelta), 0.0, 1.0);\n | |
| 50 | - vertexPosition.xyz *= uSize;\n | |
| 51 | - gl_Position = uMvpMatrix * vertexPosition;\n | |
| 52 | - }\n | |
| 53 | -); | |
| 54 | - | |
| 55 | -/** | |
| 56 | - * @brief This fragment-shader does not output anything. It's for a control which is just going to clip as specified in the vertex shader. | |
| 57 | - */ | |
| 58 | -const char * FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 59 | - void main()\n | |
| 60 | - {\n | |
| 61 | - gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n | |
| 62 | - }\n | |
| 63 | -); | |
| 64 | -// clang-format on | |
| 65 | - | |
| 66 | -/** | |
| 67 | 38 | * @brief Creates the shader required for the clipped image |
| 68 | 39 | * @return A reference to a static handle to a shader object (only created when first called). |
| 69 | 40 | */ |
| ... | ... | @@ -77,7 +48,7 @@ Shader& CreateShader() |
| 77 | 48 | |
| 78 | 49 | if(!shader) |
| 79 | 50 | { |
| 80 | - shader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); | |
| 51 | + shader = Shader::New(SHADER_CLIPPED_IMAGE_VERT, SHADER_CLIPPED_IMAGE_FRAG); | |
| 81 | 52 | } |
| 82 | 53 | |
| 83 | 54 | return shader; | ... | ... |
examples/contact-cards/shaders/clipped-image.frag
0 → 100644
examples/contact-cards/shaders/clipped-image.vert
0 → 100644
| 1 | +// This vertex-shader mixes in the quad and circle geometry depending on the value of uDelta. | |
| 2 | +// | |
| 3 | +// uDelta is used to mix in the Circle and the Quad positions. | |
| 4 | +// If uDelta is 0.0f, then the circle position is adopted and if it is 1.0f, then the quad position is adopted. | |
| 5 | + | |
| 6 | +attribute mediump vec2 aPositionCircle; | |
| 7 | +attribute mediump vec2 aPositionQuad; | |
| 8 | +uniform mediump float uDelta; | |
| 9 | +uniform mediump mat4 uMvpMatrix; | |
| 10 | +uniform mediump vec3 uSize; | |
| 11 | + | |
| 12 | +void main() | |
| 13 | +{ | |
| 14 | + mediump vec4 vertexPosition = vec4(mix(aPositionCircle,aPositionQuad,uDelta), 0.0, 1.0); | |
| 15 | + vertexPosition.xyz *= uSize; | |
| 16 | + gl_Position = uMvpMatrix * vertexPosition; | |
| 17 | +} | ... | ... |
examples/deferred-shading/deferred-shading.cpp
| ... | ... | @@ -21,6 +21,11 @@ |
| 21 | 21 | #include "dali/public-api/actors/actor.h" |
| 22 | 22 | #include "dali/public-api/rendering/renderer.h" |
| 23 | 23 | |
| 24 | +#include "generated/deferred-shading-mainpass-vert.h" | |
| 25 | +#include "generated/deferred-shading-mainpass-frag.h" | |
| 26 | +#include "generated/deferred-shading-prepass-vert.h" | |
| 27 | +#include "generated/deferred-shading-prepass-frag.h" | |
| 28 | + | |
| 24 | 29 | using namespace Dali; |
| 25 | 30 | |
| 26 | 31 | namespace |
| ... | ... | @@ -38,181 +43,6 @@ namespace |
| 38 | 43 | |
| 39 | 44 | #define DEFINE_MAX_LIGHTS "const int kMaxLights = " QUOTE(MAX_LIGHTS) ";" |
| 40 | 45 | |
| 41 | -#define DEFINE(x) "#define " DALI_COMPOSE_SHADER(x) DALI_COMPOSE_SHADER(\n) | |
| 42 | - | |
| 43 | -// clang-format off | |
| 44 | - | |
| 45 | -//============================================================================= | |
| 46 | -// PRE-PASS | |
| 47 | -//============================================================================= | |
| 48 | -const char* const PREPASS_VSH = DALI_COMPOSE_SHADER(#version 300 es\n | |
| 49 | -precision mediump float;) | |
| 50 | - DALI_COMPOSE_SHADER( | |
| 51 | - | |
| 52 | -// DALI uniforms | |
| 53 | -uniform mat4 uMvpMatrix; | |
| 54 | -uniform mat3 uNormalMatrix; | |
| 55 | -uniform vec3 uSize; | |
| 56 | - | |
| 57 | -uniform vec3 uDepth_InvDepth_Near;\n) | |
| 58 | - DEFINE(DEPTH uDepth_InvDepth_Near.x) | |
| 59 | - DEFINE(INV_DEPTH uDepth_InvDepth_Near.y) | |
| 60 | - DEFINE(NEAR uDepth_InvDepth_Near.z) | |
| 61 | - DALI_COMPOSE_SHADER( | |
| 62 | - | |
| 63 | -in vec3 aPosition; | |
| 64 | -in vec3 aNormal; | |
| 65 | - | |
| 66 | -out vec4 vPosition; | |
| 67 | -out vec3 vNormal; | |
| 68 | - | |
| 69 | -vec4 Map(vec4 v) // projection space -> texture | |
| 70 | -{ | |
| 71 | - return vec4(v.xyz / (2.f * v.w) + vec3(.5f), (v.w - NEAR) * INV_DEPTH); | |
| 72 | -} | |
| 73 | - | |
| 74 | -void main() | |
| 75 | -{ | |
| 76 | - vec4 position = uMvpMatrix * vec4(aPosition * uSize, 1.f); | |
| 77 | - vPosition = Map(position); | |
| 78 | - gl_Position = position; | |
| 79 | - | |
| 80 | - vNormal = normalize(uNormalMatrix * aNormal); | |
| 81 | -}); | |
| 82 | - | |
| 83 | -//============================================================================= | |
| 84 | -const char* const PREPASS_FSH = DALI_COMPOSE_SHADER(#version 300 es\n | |
| 85 | -precision mediump float; | |
| 86 | - | |
| 87 | -// DALI uniform | |
| 88 | -uniform vec4 uColor; | |
| 89 | - | |
| 90 | -in vec4 vPosition; | |
| 91 | -in vec3 vNormal; | |
| 92 | - | |
| 93 | -// These are our outputs. | |
| 94 | -layout(location = 0) out vec3 oNormal; | |
| 95 | -layout(location = 1) out vec4 oPosition; | |
| 96 | -layout(location = 2) out vec3 oColor; | |
| 97 | - | |
| 98 | -void main() | |
| 99 | -{ | |
| 100 | - oColor = uColor.rgb; | |
| 101 | - oPosition = vPosition; | |
| 102 | - oNormal = normalize(vNormal) * .5f + .5f; | |
| 103 | -}); | |
| 104 | - | |
| 105 | -//============================================================================= | |
| 106 | -// MAIN (LIGHTING) PASS | |
| 107 | -//============================================================================= | |
| 108 | -const char* const MAINPASS_VSH = DALI_COMPOSE_SHADER(#version 300 es\n | |
| 109 | -precision mediump float; | |
| 110 | - | |
| 111 | -// DALI uniforms | |
| 112 | -uniform mat4 uMvpMatrix; | |
| 113 | -uniform vec3 uSize; | |
| 114 | - | |
| 115 | -in vec3 aPosition; | |
| 116 | -in vec2 aTexCoord; | |
| 117 | - | |
| 118 | -out vec2 vUv; | |
| 119 | - | |
| 120 | -void main() | |
| 121 | -{ | |
| 122 | - vec4 position = uMvpMatrix * vec4(aPosition * uSize, 1.f); | |
| 123 | - vUv = aTexCoord; | |
| 124 | - | |
| 125 | - gl_Position = position; | |
| 126 | -}); | |
| 127 | - | |
| 128 | -//============================================================================= | |
| 129 | -const char* const MAINPASS_FSH = DALI_COMPOSE_SHADER(#version 300 es\n | |
| 130 | -precision mediump float;\n) | |
| 131 | - DEFINE_MAX_LIGHTS | |
| 132 | - DALI_COMPOSE_SHADER( | |
| 133 | - | |
| 134 | -const float kAttenuationConst = .05f; | |
| 135 | -const float kAttenuationLinear = .1f; | |
| 136 | -const float kAttenuationQuadratic = .15f; | |
| 137 | - | |
| 138 | -// G-buffer | |
| 139 | -uniform sampler2D uTextureNormal; | |
| 140 | -uniform sampler2D uTexturePosition; | |
| 141 | -uniform sampler2D uTextureColor; | |
| 142 | - | |
| 143 | -uniform mat4 uInvProjection; | |
| 144 | - | |
| 145 | -uniform vec3 uDepth_InvDepth_Near;\n) | |
| 146 | - DEFINE(DEPTH uDepth_InvDepth_Near.x) | |
| 147 | - DEFINE(INV_DEPTH uDepth_InvDepth_Near.y) | |
| 148 | - DEFINE(NEAR uDepth_InvDepth_Near.z) | |
| 149 | - DALI_COMPOSE_SHADER( | |
| 150 | - | |
| 151 | -// Light source uniforms | |
| 152 | -struct Light | |
| 153 | -{ | |
| 154 | - vec3 position; // view space | |
| 155 | - float radius; | |
| 156 | - vec3 color; | |
| 157 | -}; | |
| 158 | - | |
| 159 | -uniform Light uLights[kMaxLights]; | |
| 160 | - | |
| 161 | -in vec2 vUv; | |
| 162 | - | |
| 163 | -out vec4 oColor; | |
| 164 | - | |
| 165 | -vec4 Unmap(vec4 m) // texture -> projection | |
| 166 | -{ | |
| 167 | - m.w = m.w * DEPTH + NEAR; | |
| 168 | - m.xyz = (m.xyz - vec3(.5)) * (2.f * m.w); | |
| 169 | - return m; | |
| 170 | -} | |
| 171 | - | |
| 172 | -vec3 CalculateLighting(vec3 pos, vec3 normal) | |
| 173 | -{ | |
| 174 | - vec3 viewDir = normalize(pos); | |
| 175 | - vec3 viewDirRefl = -reflect(viewDir, normal); | |
| 176 | - | |
| 177 | - vec3 light = vec3(0.04f); // fake ambient term | |
| 178 | - for (int i = 0; i < kMaxLights; ++i) | |
| 179 | - { | |
| 180 | - vec3 rel = pos - uLights[i].position; | |
| 181 | - float distance = length(rel); | |
| 182 | - rel /= distance; | |
| 183 | - | |
| 184 | - float a = uLights[i].radius / (kAttenuationConst + kAttenuationLinear * distance + | |
| 185 | - kAttenuationQuadratic * distance * distance); // attenuation | |
| 186 | - | |
| 187 | - float l = max(0.f, dot(normal, rel)); // lambertian | |
| 188 | - float s = pow(max(0.f, dot(viewDirRefl, rel)), 256.f); // specular | |
| 189 | - | |
| 190 | - light += (uLights[i].color * (l + s)) * a; | |
| 191 | - } | |
| 192 | - | |
| 193 | - return light; | |
| 194 | -} | |
| 195 | - | |
| 196 | -void main() | |
| 197 | -{ | |
| 198 | - vec3 normSample = texture(uTextureNormal, vUv).xyz; | |
| 199 | - if (dot(normSample, normSample) == 0.f) | |
| 200 | - { | |
| 201 | - discard; // if we didn't write this texel, don't bother lighting it. | |
| 202 | - } | |
| 203 | - | |
| 204 | - vec3 normal = normalize(normSample - .5f); | |
| 205 | - | |
| 206 | - vec4 posSample = texture(uTexturePosition, vUv); | |
| 207 | - vec3 pos = (uInvProjection * Unmap(posSample)).xyz; | |
| 208 | - | |
| 209 | - vec3 color = texture(uTextureColor, vUv).rgb; | |
| 210 | - vec3 finalColor = color * CalculateLighting(pos, normal); | |
| 211 | - | |
| 212 | - oColor = vec4(finalColor, 1.f); | |
| 213 | -}); | |
| 214 | -// clang-format on | |
| 215 | - | |
| 216 | 46 | //============================================================================= |
| 217 | 47 | // PRNG for floats. |
| 218 | 48 | struct FloatRand |
| ... | ... | @@ -542,7 +372,7 @@ private: |
| 542 | 372 | Geometry mesh = CreateOctahedron(false); |
| 543 | 373 | |
| 544 | 374 | // Create main actors |
| 545 | - Shader preShader = Shader::New(PREPASS_VSH, PREPASS_FSH); | |
| 375 | + Shader preShader = Shader::New(SHADER_DEFERRED_SHADING_PREPASS_VERT, SHADER_DEFERRED_SHADING_PREPASS_FRAG); | |
| 546 | 376 | TextureSet noTexturesThanks = TextureSet::New(); |
| 547 | 377 | Renderer meshRenderer = CreateRenderer(noTexturesThanks, mesh, preShader, OPTION_DEPTH_TEST | OPTION_DEPTH_WRITE); |
| 548 | 378 | meshRenderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK); |
| ... | ... | @@ -631,7 +461,7 @@ private: |
| 631 | 461 | finalImageTextures.SetSampler(1, sampler); |
| 632 | 462 | finalImageTextures.SetSampler(2, sampler); |
| 633 | 463 | |
| 634 | - Shader shdMain = Shader::New(MAINPASS_VSH, MAINPASS_FSH); | |
| 464 | + Shader shdMain = Shader::New(SHADER_DEFERRED_SHADING_MAINPASS_VERT, SHADER_DEFERRED_SHADING_MAINPASS_FRAG); | |
| 635 | 465 | Geometry finalImageGeom = CreateTexturedQuadGeometry(true); |
| 636 | 466 | Renderer finalImageRenderer = CreateRenderer(finalImageTextures, finalImageGeom, shdMain); |
| 637 | 467 | RegisterDepthProperties(depth, zNear, finalImageRenderer); | ... | ... |
examples/deferred-shading/shaders/deferred-shading-mainpass.frag
0 → 100644
| 1 | +#version 300 es | |
| 2 | + | |
| 3 | +precision mediump float; | |
| 4 | + | |
| 5 | +const int kMaxLights = 32; | |
| 6 | + | |
| 7 | +const float kAttenuationConst = .05f; | |
| 8 | +const float kAttenuationLinear = .1f; | |
| 9 | +const float kAttenuationQuadratic = .15f; | |
| 10 | + | |
| 11 | +// G-buffer | |
| 12 | +uniform sampler2D uTextureNormal; | |
| 13 | +uniform sampler2D uTexturePosition; | |
| 14 | +uniform sampler2D uTextureColor; | |
| 15 | + | |
| 16 | +uniform mat4 uInvProjection; | |
| 17 | +uniform vec3 uDepth_InvDepth_Near; | |
| 18 | + | |
| 19 | +#define DEPTH uDepth_InvDepth_Near.x | |
| 20 | +#define INV_DEPTH uDepth_InvDepth_Near.y | |
| 21 | +#define NEAR uDepth_InvDepth_Near.z | |
| 22 | + | |
| 23 | +// Light source uniforms | |
| 24 | +struct Light | |
| 25 | +{ | |
| 26 | + vec3 position; // view space | |
| 27 | + float radius; | |
| 28 | + vec3 color; | |
| 29 | +}; | |
| 30 | + | |
| 31 | +uniform Light uLights[kMaxLights]; | |
| 32 | + | |
| 33 | +in vec2 vUv; | |
| 34 | +out vec4 oColor; | |
| 35 | + | |
| 36 | +vec4 Unmap(vec4 m) // texture -> projection | |
| 37 | +{ | |
| 38 | + m.w = m.w * DEPTH + NEAR; | |
| 39 | + m.xyz = (m.xyz - vec3(.5)) * (2.f * m.w); | |
| 40 | + return m; | |
| 41 | +} | |
| 42 | + | |
| 43 | +vec3 CalculateLighting(vec3 pos, vec3 normal) | |
| 44 | +{ | |
| 45 | + vec3 viewDir = normalize(pos); | |
| 46 | + vec3 viewDirRefl = -reflect(viewDir, normal); | |
| 47 | + | |
| 48 | + vec3 light = vec3(0.04f); // fake ambient term | |
| 49 | + for (int i = 0; i < kMaxLights; ++i) | |
| 50 | + { | |
| 51 | + vec3 rel = pos - uLights[i].position; | |
| 52 | + float distance = length(rel); | |
| 53 | + rel /= distance; | |
| 54 | + | |
| 55 | + float a = uLights[i].radius / (kAttenuationConst + kAttenuationLinear * distance + | |
| 56 | + kAttenuationQuadratic * distance * distance); // attenuation | |
| 57 | + | |
| 58 | + float l = max(0.f, dot(normal, rel)); // lambertian | |
| 59 | + float s = pow(max(0.f, dot(viewDirRefl, rel)), 256.f); // specular | |
| 60 | + | |
| 61 | + light += (uLights[i].color * (l + s)) * a; | |
| 62 | + } | |
| 63 | + | |
| 64 | + return light; | |
| 65 | +} | |
| 66 | + | |
| 67 | +void main() | |
| 68 | +{ | |
| 69 | + vec3 normSample = texture(uTextureNormal, vUv).xyz; | |
| 70 | + if (dot(normSample, normSample) == 0.f) | |
| 71 | + { | |
| 72 | + discard; // if we didn't write this texel, don't bother lighting it. | |
| 73 | + } | |
| 74 | + | |
| 75 | + vec3 normal = normalize(normSample - .5f); | |
| 76 | + | |
| 77 | + vec4 posSample = texture(uTexturePosition, vUv); | |
| 78 | + vec3 pos = (uInvProjection * Unmap(posSample)).xyz; | |
| 79 | + | |
| 80 | + vec3 color = texture(uTextureColor, vUv).rgb; | |
| 81 | + vec3 finalColor = color * CalculateLighting(pos, normal); | |
| 82 | + | |
| 83 | + oColor = vec4(finalColor, 1.f); | |
| 84 | +} | ... | ... |
examples/deferred-shading/shaders/deferred-shading-mainpass.vert
0 → 100644
| 1 | +#version 300 es | |
| 2 | +precision mediump float; | |
| 3 | + | |
| 4 | +// DALI uniforms | |
| 5 | +uniform mat4 uMvpMatrix; | |
| 6 | +uniform vec3 uSize; | |
| 7 | + | |
| 8 | +in vec3 aPosition; | |
| 9 | +in vec2 aTexCoord; | |
| 10 | + | |
| 11 | +out vec2 vUv; | |
| 12 | + | |
| 13 | +void main() | |
| 14 | +{ | |
| 15 | + vec4 position = uMvpMatrix * vec4(aPosition * uSize, 1.f); | |
| 16 | + vUv = aTexCoord; | |
| 17 | + | |
| 18 | + gl_Position = position; | |
| 19 | +} | ... | ... |
examples/deferred-shading/shaders/deferred-shading-prepass.frag
0 → 100644
| 1 | +#version 300 es | |
| 2 | +precision mediump float; | |
| 3 | + | |
| 4 | +// DALI uniform | |
| 5 | +uniform vec4 uColor; | |
| 6 | + | |
| 7 | +in vec4 vPosition; | |
| 8 | +in vec3 vNormal; | |
| 9 | + | |
| 10 | +// These are our outputs. | |
| 11 | +layout(location = 0) out vec3 oNormal; | |
| 12 | +layout(location = 1) out vec4 oPosition; | |
| 13 | +layout(location = 2) out vec3 oColor; | |
| 14 | + | |
| 15 | +void main() | |
| 16 | +{ | |
| 17 | + oColor = uColor.rgb; | |
| 18 | + oPosition = vPosition; | |
| 19 | + oNormal = normalize(vNormal) * .5f + .5f; | |
| 20 | +} | ... | ... |
examples/deferred-shading/shaders/deferred-shading-prepass.vert
0 → 100644
| 1 | +#version 300 es | |
| 2 | + | |
| 3 | +precision mediump float; | |
| 4 | + | |
| 5 | +// DALI uniforms | |
| 6 | +uniform mat4 uMvpMatrix; | |
| 7 | +uniform mat3 uNormalMatrix; | |
| 8 | +uniform vec3 uSize; | |
| 9 | + | |
| 10 | +uniform vec3 uDepth_InvDepth_Near; | |
| 11 | + | |
| 12 | +#define DEPTH uDepth_InvDepth_Near.x | |
| 13 | +#define INV_DEPTH uDepth_InvDepth_Near.y | |
| 14 | +#define NEAR uDepth_InvDepth_Near.z | |
| 15 | + | |
| 16 | +in vec3 aPosition; | |
| 17 | +in vec3 aNormal; | |
| 18 | + | |
| 19 | +out vec4 vPosition; | |
| 20 | +out vec3 vNormal; | |
| 21 | + | |
| 22 | +vec4 Map(vec4 v) // projection space -> texture | |
| 23 | +{ | |
| 24 | + return vec4(v.xyz / (2.f * v.w) + vec3(.5f), (v.w - NEAR) * INV_DEPTH); | |
| 25 | +} | |
| 26 | + | |
| 27 | +void main() | |
| 28 | +{ | |
| 29 | + vec4 position = uMvpMatrix * vec4(aPosition * uSize, 1.f); | |
| 30 | + vPosition = Map(position); | |
| 31 | + gl_Position = position; | |
| 32 | + | |
| 33 | + vNormal = normalize(uNormalMatrix * aNormal); | |
| 34 | +} | ... | ... |
examples/fpp-game/game-renderer.cpp
| ... | ... | @@ -19,37 +19,10 @@ |
| 19 | 19 | #include "game-model.h" |
| 20 | 20 | #include "game-texture.h" |
| 21 | 21 | |
| 22 | -#include <dali/dali.h> | |
| 23 | - | |
| 24 | -namespace | |
| 25 | -{ | |
| 26 | -// clang-format off | |
| 22 | +#include "generated/game-renderer-vert.h" | |
| 23 | +#include "generated/game-renderer-frag.h" | |
| 27 | 24 | |
| 28 | -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( | |
| 29 | - attribute highp vec3 aPosition;\n | |
| 30 | - attribute highp vec3 aNormal;\n | |
| 31 | - attribute highp vec2 aTexCoord;\n | |
| 32 | - uniform highp mat4 uMvpMatrix;\n | |
| 33 | - varying highp vec2 vTexCoord;\n | |
| 34 | - void main()\n | |
| 35 | - {\n | |
| 36 | - gl_Position = uMvpMatrix * vec4(aPosition, 1.0 );\n | |
| 37 | - vTexCoord = aTexCoord;\n | |
| 38 | - vTexCoord.y = 1.0 - vTexCoord.y;\n | |
| 39 | - }\n | |
| 40 | -) | |
| 41 | - ; | |
| 42 | -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 43 | - uniform sampler2D sTexture;\n | |
| 44 | - varying highp vec2 vTexCoord;\n | |
| 45 | - void main()\n | |
| 46 | - {\n | |
| 47 | - gl_FragColor = texture2D( sTexture, vTexCoord ) * vec4(1.2, 1.2, 1.2, 1.0);\n | |
| 48 | - }\n | |
| 49 | -); | |
| 50 | -// clang-format on | |
| 51 | - | |
| 52 | -} // namespace | |
| 25 | +#include <dali/dali.h> | |
| 53 | 26 | |
| 54 | 27 | GameRenderer::GameRenderer() |
| 55 | 28 | : mModel(NULL), |
| ... | ... | @@ -77,7 +50,7 @@ void GameRenderer::Setup() |
| 77 | 50 | { |
| 78 | 51 | if(!mRenderer && mModel) |
| 79 | 52 | { |
| 80 | - Dali::Shader shader = Dali::Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); | |
| 53 | + Dali::Shader shader = Dali::Shader::New(SHADER_GAME_RENDERER_VERT, SHADER_GAME_RENDERER_FRAG); | |
| 81 | 54 | mRenderer = Dali::Renderer::New(mModel->GetGeometry(), shader); |
| 82 | 55 | mRenderer.SetProperty(Dali::Renderer::Property::DEPTH_WRITE_MODE, Dali::DepthWriteMode::ON); |
| 83 | 56 | mRenderer.SetProperty(Dali::Renderer::Property::DEPTH_FUNCTION, Dali::DepthFunction::LESS_EQUAL); | ... | ... |
examples/fpp-game/shaders/game-renderer.frag
0 → 100644
examples/fpp-game/shaders/game-renderer.vert
0 → 100644
| 1 | +attribute highp vec3 aPosition; | |
| 2 | +attribute highp vec3 aNormal; | |
| 3 | +attribute highp vec2 aTexCoord; | |
| 4 | +uniform highp mat4 uMvpMatrix; | |
| 5 | +varying highp vec2 vTexCoord; | |
| 6 | + | |
| 7 | +void main() | |
| 8 | +{ | |
| 9 | + gl_Position = uMvpMatrix * vec4(aPosition, 1.0 ); | |
| 10 | + vTexCoord = aTexCoord; | |
| 11 | + vTexCoord.y = 1.0 - vTexCoord.y; | |
| 12 | +} | ... | ... |
examples/image-view-url/image-view-url-example.cpp
| ... | ... | @@ -19,6 +19,7 @@ |
| 19 | 19 | #include <dali-toolkit/devel-api/image-loader/texture-manager.h> |
| 20 | 20 | |
| 21 | 21 | #include "shared/view.h" |
| 22 | +#include "generated/image-view-url-frag.h" | |
| 22 | 23 | |
| 23 | 24 | using namespace Dali; |
| 24 | 25 | |
| ... | ... | @@ -31,22 +32,6 @@ const char* const TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); |
| 31 | 32 | const char* const BUTTON_ICON(DEMO_IMAGE_DIR "icon-change.png"); |
| 32 | 33 | const char* const BUTTON_ICON_SELECTED(DEMO_IMAGE_DIR "icon-change-selected.png"); |
| 33 | 34 | |
| 34 | -const char* FILTER_FRAGMENT_SOURCE = | |
| 35 | - { | |
| 36 | - "precision highp float;\n" | |
| 37 | - "varying mediump vec2 vTexCoord;\n" | |
| 38 | - "uniform sampler2D sTexture;\n" | |
| 39 | - "uniform mediump float uDelta;\n" | |
| 40 | - "void main()\n" | |
| 41 | - "{\n" | |
| 42 | - " vec4 color = vec4(0.0);\n" | |
| 43 | - " vec2 texCoord = vTexCoord * 2. - 1.;\n" | |
| 44 | - " mat2 rotation = mat2(cos(uDelta), -sin(uDelta), sin(uDelta), cos(uDelta));" | |
| 45 | - " texCoord = (rotation * texCoord) * .5 + .5;\n" | |
| 46 | - " color += texture2D( sTexture, texCoord );\n" | |
| 47 | - " gl_FragColor = color;\n" | |
| 48 | - "}\n"}; | |
| 49 | - | |
| 50 | 35 | const char* DELTA_UNIFORM_NAME = "uDelta"; |
| 51 | 36 | |
| 52 | 37 | const Vector2 TARGET_SIZE(800.f, 800.f); |
| ... | ... | @@ -119,7 +104,7 @@ private: |
| 119 | 104 | mActorForInput.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); |
| 120 | 105 | mActorForInput.SetProperty(Actor::Property::SIZE, TARGET_SIZE); |
| 121 | 106 | Property::Map customShader; |
| 122 | - customShader[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = FILTER_FRAGMENT_SOURCE; | |
| 107 | + customShader[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = SHADER_IMAGE_VIEW_URL_FRAG.data(); | |
| 123 | 108 | Property::Map visualMap; |
| 124 | 109 | visualMap.Insert(Toolkit::Visual::Property::SHADER, customShader); |
| 125 | 110 | mActorForInput.SetProperty(Toolkit::ImageView::Property::IMAGE, visualMap); | ... | ... |
examples/image-view-url/shaders/image-view-url.frag
0 → 100644
| 1 | +precision highp float; | |
| 2 | +varying mediump vec2 vTexCoord; | |
| 3 | +uniform sampler2D sTexture; | |
| 4 | +uniform mediump float uDelta; | |
| 5 | + | |
| 6 | +void main() | |
| 7 | +{ | |
| 8 | + vec4 color = vec4(0.0); | |
| 9 | + vec2 texCoord = vTexCoord * 2. - 1.; | |
| 10 | + mat2 rotation = mat2(cos(uDelta), -sin(uDelta), sin(uDelta), cos(uDelta)); | |
| 11 | + texCoord = (rotation * texCoord) * .5 + .5; | |
| 12 | + color += texture2D( sTexture, texCoord ); | |
| 13 | + gl_FragColor = color; | |
| 14 | +} | |
| 0 | 15 | \ No newline at end of file | ... | ... |
examples/line-mesh/line-mesh-example.cpp
| ... | ... | @@ -22,6 +22,8 @@ |
| 22 | 22 | |
| 23 | 23 | // INTERNAL INCLUDES |
| 24 | 24 | #include "shared/view.h" |
| 25 | +#include "generated/line-mesh-vert.h" | |
| 26 | +#include "generated/line-mesh-frag.h" | |
| 25 | 27 | |
| 26 | 28 | #include <sstream> |
| 27 | 29 | |
| ... | ... | @@ -29,36 +31,6 @@ using namespace Dali; |
| 29 | 31 | |
| 30 | 32 | namespace |
| 31 | 33 | { |
| 32 | -#define MAKE_SHADER(A) #A | |
| 33 | - | |
| 34 | -const char* VERTEX_SHADER = MAKE_SHADER( | |
| 35 | - attribute mediump vec2 aPosition1; | |
| 36 | - attribute mediump vec2 aPosition2; | |
| 37 | - attribute lowp vec3 aColor; | |
| 38 | - uniform mediump mat4 uMvpMatrix; | |
| 39 | - uniform mediump vec3 uSize; | |
| 40 | - uniform mediump float uMorphAmount; | |
| 41 | - | |
| 42 | - varying lowp vec3 vColor; | |
| 43 | - | |
| 44 | - void main() { | |
| 45 | - mediump vec2 morphPosition = mix(aPosition1, aPosition2, uMorphAmount); | |
| 46 | - mediump vec4 vertexPosition = vec4(morphPosition, 0.0, 1.0); | |
| 47 | - vColor = aColor; | |
| 48 | - vertexPosition.xyz *= uSize; | |
| 49 | - vertexPosition = uMvpMatrix * vertexPosition; | |
| 50 | - gl_Position = vertexPosition; | |
| 51 | - }); | |
| 52 | - | |
| 53 | -const char* FRAGMENT_SHADER = MAKE_SHADER( | |
| 54 | - uniform lowp vec4 uColor; | |
| 55 | - uniform sampler2D sTexture; | |
| 56 | - | |
| 57 | - varying lowp vec3 vColor; | |
| 58 | - | |
| 59 | - void main() { | |
| 60 | - gl_FragColor = uColor * vec4(vColor, 1.0); | |
| 61 | - }); | |
| 62 | 34 | |
| 63 | 35 | const unsigned short INDEX_LINES[] = {0, 1, 1, 2, 2, 3, 3, 4, 4, 0}; |
| 64 | 36 | const unsigned short INDEX_LOOP[] = {0, 1, 2, 3, 4}; |
| ... | ... | @@ -177,7 +149,7 @@ public: |
| 177 | 149 | mMeshActor.Reset(); |
| 178 | 150 | } |
| 179 | 151 | |
| 180 | - mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); | |
| 152 | + mShader = Shader::New(SHADER_LINE_MESH_VERT, SHADER_LINE_MESH_FRAG); | |
| 181 | 153 | mGeometry = CreateGeometry(); |
| 182 | 154 | mRenderer = Renderer::New(mGeometry, mShader); |
| 183 | 155 | ... | ... |
examples/line-mesh/shaders/line-mesh.frag
0 → 100644
examples/line-mesh/shaders/line-mesh.vert
0 → 100644
| 1 | +attribute mediump vec2 aPosition1; | |
| 2 | +attribute mediump vec2 aPosition2; | |
| 3 | +attribute lowp vec3 aColor; | |
| 4 | +uniform mediump mat4 uMvpMatrix; | |
| 5 | +uniform mediump vec3 uSize; | |
| 6 | +uniform mediump float uMorphAmount; | |
| 7 | + | |
| 8 | +varying lowp vec3 vColor; | |
| 9 | + | |
| 10 | +void main() | |
| 11 | +{ | |
| 12 | + mediump vec2 morphPosition = mix(aPosition1, aPosition2, uMorphAmount); | |
| 13 | + mediump vec4 vertexPosition = vec4(morphPosition, 0.0, 1.0); | |
| 14 | + vColor = aColor; | |
| 15 | + vertexPosition.xyz *= uSize; | |
| 16 | + vertexPosition = uMvpMatrix * vertexPosition; | |
| 17 | + gl_Position = vertexPosition; | |
| 18 | +} | ... | ... |
examples/mesh-morph/mesh-morph-example.cpp
| ... | ... | @@ -21,37 +21,13 @@ |
| 21 | 21 | |
| 22 | 22 | // INTERNAL INCLUDES |
| 23 | 23 | #include "shared/view.h" |
| 24 | +#include "generated/mesh-morph-vert.h" | |
| 25 | +#include "generated/mesh-morph-frag.h" | |
| 24 | 26 | |
| 25 | 27 | using namespace Dali; |
| 26 | 28 | |
| 27 | 29 | namespace |
| 28 | 30 | { |
| 29 | -#define MAKE_SHADER(A) #A | |
| 30 | - | |
| 31 | -const char* VERTEX_SHADER = MAKE_SHADER( | |
| 32 | - attribute mediump vec2 aInitPos; | |
| 33 | - attribute mediump vec2 aFinalPos; | |
| 34 | - attribute mediump vec3 aColor; | |
| 35 | - uniform mediump mat4 uMvpMatrix; | |
| 36 | - uniform mediump vec3 uSize; | |
| 37 | - uniform mediump float uDelta; | |
| 38 | - uniform lowp vec4 uColor; | |
| 39 | - varying lowp vec4 vColor; | |
| 40 | - | |
| 41 | - void main() { | |
| 42 | - mediump vec4 vertexPosition = vec4(mix(aInitPos, aFinalPos, uDelta), 0.0, 1.0); | |
| 43 | - vertexPosition.xyz *= uSize; | |
| 44 | - vertexPosition = uMvpMatrix * vertexPosition; | |
| 45 | - gl_Position = vertexPosition; | |
| 46 | - vColor = vec4(aColor, 0.) * uColor; | |
| 47 | - }); | |
| 48 | - | |
| 49 | -const char* FRAGMENT_SHADER = MAKE_SHADER( | |
| 50 | - varying lowp vec4 vColor; | |
| 51 | - | |
| 52 | - void main() { | |
| 53 | - gl_FragColor = vColor; | |
| 54 | - }); | |
| 55 | 31 | |
| 56 | 32 | Geometry CreateGeometry() |
| 57 | 33 | { |
| ... | ... | @@ -288,7 +264,7 @@ public: |
| 288 | 264 | |
| 289 | 265 | // The Init signal is received once (only) during the Application lifetime |
| 290 | 266 | |
| 291 | - mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); | |
| 267 | + mShader = Shader::New(SHADER_MESH_MORPH_VERT, SHADER_MESH_MORPH_FRAG); | |
| 292 | 268 | mGeometry = CreateGeometry(); |
| 293 | 269 | mRenderer = Renderer::New(mGeometry, mShader); |
| 294 | 270 | ... | ... |
examples/mesh-morph/shaders/mesh-morph.frag
0 → 100644
examples/mesh-morph/shaders/mesh-morph.vert
0 → 100644
| 1 | +attribute mediump vec2 aInitPos; | |
| 2 | +attribute mediump vec2 aFinalPos; | |
| 3 | +attribute mediump vec3 aColor; | |
| 4 | +uniform mediump mat4 uMvpMatrix; | |
| 5 | +uniform mediump vec3 uSize; | |
| 6 | +uniform mediump float uDelta; | |
| 7 | +uniform lowp vec4 uColor; | |
| 8 | +varying lowp vec4 vColor; | |
| 9 | + | |
| 10 | +void main() | |
| 11 | +{ | |
| 12 | + mediump vec4 vertexPosition = vec4(mix(aInitPos, aFinalPos, uDelta), 0.0, 1.0); | |
| 13 | + vertexPosition.xyz *= uSize; | |
| 14 | + vertexPosition = uMvpMatrix * vertexPosition; | |
| 15 | + gl_Position = vertexPosition; | |
| 16 | + vColor = vec4(aColor, 0.) * uColor; | |
| 17 | +} | ... | ... |
examples/metaball-explosion/metaball-explosion-example.cpp
| ... | ... | @@ -28,6 +28,9 @@ |
| 28 | 28 | |
| 29 | 29 | // INTERNAL INCLUDES |
| 30 | 30 | #include "shared/utility.h" // DemoHelper::LoadTexture |
| 31 | +#include "generated/metaball-vert.h" | |
| 32 | +#include "generated/metaball-frag.h" | |
| 33 | +#include "generated/metaball-refraction-frag.h" | |
| 31 | 34 | |
| 32 | 35 | using namespace Dali; |
| 33 | 36 | |
| ... | ... | @@ -40,127 +43,6 @@ const char* const BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-2.jpg"); |
| 40 | 43 | constexpr uint32_t METABALL_NUMBER = 6; |
| 41 | 44 | |
| 42 | 45 | /** |
| 43 | - * Vertex shader code for metaball | |
| 44 | - */ | |
| 45 | -// clang-format off | |
| 46 | -const char* const METABALL_VERTEX_SHADER = DALI_COMPOSE_SHADER ( | |
| 47 | - attribute mediump vec2 aPosition;\n | |
| 48 | - attribute mediump vec2 aTexture;\n | |
| 49 | - uniform mediump mat4 uMvpMatrix;\n | |
| 50 | - uniform mediump vec3 uSize;\n | |
| 51 | - uniform lowp vec4 uColor;\n | |
| 52 | - varying mediump vec2 vTexCoord;\n | |
| 53 | - | |
| 54 | - void main()\n | |
| 55 | - {\n | |
| 56 | - vTexCoord = aTexture;\n | |
| 57 | - mediump vec4 vertexPosition = vec4(aPosition.x, aPosition.y, 0.0, 1.0);\n | |
| 58 | - gl_Position = uMvpMatrix * vertexPosition;\n | |
| 59 | - }\n | |
| 60 | -); | |
| 61 | - | |
| 62 | -/** | |
| 63 | - * Fragment shader code for metaball | |
| 64 | - */ | |
| 65 | -const char* const METABALL_FRAG_SHADER = DALI_COMPOSE_SHADER ( | |
| 66 | - precision mediump float;\n | |
| 67 | - varying vec2 vTexCoord;\n | |
| 68 | - uniform vec2 uPositionMetaball;\n | |
| 69 | - uniform vec2 uPositionVar;\n | |
| 70 | - uniform vec2 uGravityVector;\n | |
| 71 | - uniform float uRadius;\n | |
| 72 | - uniform float uRadiusVar;\n | |
| 73 | - void main()\n | |
| 74 | - {\n | |
| 75 | - vec2 adjustedCoords = vTexCoord * 2.0 - 1.0;\n | |
| 76 | - vec2 finalMetaballPosition = uPositionMetaball + uGravityVector + uPositionVar;\n | |
| 77 | - \n | |
| 78 | - float finalRadius = uRadius + uRadiusVar;\n | |
| 79 | - vec2 distanceVec = adjustedCoords - finalMetaballPosition;\n | |
| 80 | - float result = dot(distanceVec, distanceVec);\n | |
| 81 | - float color = inversesqrt(result) * finalRadius;\n | |
| 82 | - \n | |
| 83 | - gl_FragColor = vec4(color,color,color,1.0);\n | |
| 84 | - }\n | |
| 85 | -); | |
| 86 | - | |
| 87 | -/** | |
| 88 | - * Fragment shader code for metaball and background composition with refraction effect | |
| 89 | - */ | |
| 90 | -const char* const REFRACTION_FRAG_SHADER = DALI_COMPOSE_SHADER ( | |
| 91 | - precision highp float;\n | |
| 92 | - varying vec2 vTexCoord;\n | |
| 93 | - uniform sampler2D sTexture;\n | |
| 94 | - uniform sampler2D sEffect;\n | |
| 95 | - uniform vec2 uPositionMetaball;\n | |
| 96 | - void main()\n | |
| 97 | - {\n | |
| 98 | - vec2 zoomCoords;\n | |
| 99 | - vec3 normal = vec3(0.0,0.0,1.0);\n | |
| 100 | - vec2 fakePos = vec2(0.0,0.0);\n | |
| 101 | - vec3 color = vec3(1.0, 1.0, 1.0); | |
| 102 | - float ambient = 0.2; | |
| 103 | - \n | |
| 104 | - vec4 metaColor = texture2D(sEffect, vTexCoord);\n | |
| 105 | - \n | |
| 106 | - vec2 adjustedCoords = vTexCoord.xy * vec2(2.0) - vec2(1.0);\n | |
| 107 | - fakePos = adjustedCoords.xy - vec2(uPositionMetaball.x, -uPositionMetaball.y); | |
| 108 | - float len = length(fakePos) + 0.01;\n | |
| 109 | - vec3 colorPos = vec3(0,0,1); | |
| 110 | - \n | |
| 111 | - if (metaColor.r > 0.85)\n | |
| 112 | - {\n | |
| 113 | - zoomCoords = ((vTexCoord - 0.5) * 0.9);\n | |
| 114 | - zoomCoords = zoomCoords + 0.5;\n | |
| 115 | - \n | |
| 116 | - float interpNormal = mix(0.7, 1.0, (metaColor.r - 0.85) * 4.);\n | |
| 117 | - normal.xyz = vec3(fakePos.x * (1.0 - interpNormal) / len, fakePos.y * (1.0 - interpNormal) / len, interpNormal);\n | |
| 118 | - normal.xyz = normalize(normal.xyz);\n | |
| 119 | - color = vec3(0.65, 1.0, 0);\n | |
| 120 | - colorPos = vec3(fakePos.x,fakePos.y,0); | |
| 121 | - }\n | |
| 122 | - else if (metaColor.r > 0.75)\n | |
| 123 | - {\n | |
| 124 | - float interpolation = mix(0.9, 1.15, (0.85 - metaColor.r) * 10.0);\n | |
| 125 | - zoomCoords = ((vTexCoord - 0.5) * interpolation);\n | |
| 126 | - zoomCoords = zoomCoords + 0.5;\n | |
| 127 | - \n | |
| 128 | - float interpNormal = mix(0.7, 0.0, (0.85 - metaColor.r) * 10.0);\n | |
| 129 | - normal.xyz = vec3(fakePos.x * (1.0 - interpNormal) / len, fakePos.y * (1.0 - interpNormal) / len, interpNormal);\n | |
| 130 | - normal.xyz = normalize(normal.xyz);\n | |
| 131 | - color = vec3(0.65, 1.0, 0);\n | |
| 132 | - colorPos = vec3(fakePos.x,fakePos.y,0); | |
| 133 | - }\n | |
| 134 | - else\n | |
| 135 | - {\n | |
| 136 | - zoomCoords = vTexCoord;\n | |
| 137 | - normal = vec3(0,0,0);\n | |
| 138 | - ambient = 0.5;\n | |
| 139 | - }\n | |
| 140 | - \n | |
| 141 | - vec3 lightPosition = vec3(-750.0,-1000.0,2000.0);\n | |
| 142 | - vec3 vertex = vec3(adjustedCoords.x,adjustedCoords.y,0.0);\n | |
| 143 | - \n | |
| 144 | - vec3 vecToLight = normalize( lightPosition - vertex );\n | |
| 145 | - \n | |
| 146 | - float lightDiffuse = dot( vecToLight, normal );\n | |
| 147 | - lightDiffuse = max(0.0,lightDiffuse);\n | |
| 148 | - lightDiffuse = lightDiffuse * 0.5 + 0.5; | |
| 149 | - \n | |
| 150 | - vec3 vertexToEye = vec3(0,0,1) - vertex;\n | |
| 151 | - vertexToEye = normalize(vertexToEye); | |
| 152 | - vec3 lightReflect = normalize(reflect(-vecToLight, normal));\n | |
| 153 | - float specularFactor = max(0.0,dot(vertexToEye, lightReflect));\n | |
| 154 | - specularFactor = pow(specularFactor, 32.0) * 0.7; | |
| 155 | - \n | |
| 156 | - vec4 texColor = texture2D(sTexture, zoomCoords);\n | |
| 157 | - gl_FragColor.rgb = texColor.rgb * ambient + color.rgb * texColor.rgb * lightDiffuse + vec3(specularFactor);\n | |
| 158 | - gl_FragColor.a = 1.0; | |
| 159 | - }\n | |
| 160 | - ); | |
| 161 | -// clang-format on | |
| 162 | - | |
| 163 | -/** | |
| 164 | 46 | * Metadata for each ball |
| 165 | 47 | */ |
| 166 | 48 | struct MetaballInfo |
| ... | ... | @@ -429,7 +311,7 @@ Geometry MetaballExplosionController::CreateGeometry(bool aspectMappedTexture) |
| 429 | 311 | void MetaballExplosionController::CreateMetaballActors() |
| 430 | 312 | { |
| 431 | 313 | // Create the shader for the metaballs, tell DALi that shader modifies geometry so we dont need to set a meaningless size |
| 432 | - Shader shader = Shader::New(METABALL_VERTEX_SHADER, METABALL_FRAG_SHADER, Shader::Hint::MODIFIES_GEOMETRY); | |
| 314 | + Shader shader = Shader::New(SHADER_METABALL_VERT, SHADER_METABALL_FRAG, Shader::Hint::MODIFIES_GEOMETRY); | |
| 433 | 315 | |
| 434 | 316 | Geometry metaballGeom = CreateGeometry(); |
| 435 | 317 | // Reuse same renderer for each actor |
| ... | ... | @@ -493,7 +375,7 @@ void MetaballExplosionController::CreateMetaballImage() |
| 493 | 375 | void MetaballExplosionController::CreateComposition() |
| 494 | 376 | { |
| 495 | 377 | //Create new shader |
| 496 | - Shader shader = Shader::New(METABALL_VERTEX_SHADER, REFRACTION_FRAG_SHADER); | |
| 378 | + Shader shader = Shader::New(SHADER_METABALL_VERT, SHADER_METABALL_REFRACTION_FRAG); | |
| 497 | 379 | |
| 498 | 380 | // Create new texture set |
| 499 | 381 | auto textureSet = TextureSet::New(); | ... | ... |
examples/metaball-explosion/shaders/metaball-refraction.frag
0 → 100644
| 1 | +//Fragment shader code for metaball and background composition with refraction effect | |
| 2 | + | |
| 3 | +precision highp float; | |
| 4 | +varying vec2 vTexCoord; | |
| 5 | +uniform sampler2D sTexture; | |
| 6 | +uniform sampler2D sEffect; | |
| 7 | +uniform vec2 uPositionMetaball; | |
| 8 | +void main() | |
| 9 | +{ | |
| 10 | + vec2 zoomCoords; | |
| 11 | + vec3 normal = vec3(0.0,0.0,1.0); | |
| 12 | + vec2 fakePos = vec2(0.0,0.0); | |
| 13 | + vec3 color = vec3(1.0, 1.0, 1.0); | |
| 14 | + float ambient = 0.2; | |
| 15 | + | |
| 16 | + vec4 metaColor = texture2D(sEffect, vTexCoord); | |
| 17 | + | |
| 18 | + vec2 adjustedCoords = vTexCoord.xy * vec2(2.0) - vec2(1.0); | |
| 19 | + fakePos = adjustedCoords.xy - vec2(uPositionMetaball.x, -uPositionMetaball.y); | |
| 20 | + float len = length(fakePos) + 0.01; | |
| 21 | + vec3 colorPos = vec3(0,0,1); | |
| 22 | + | |
| 23 | + if (metaColor.r > 0.85) | |
| 24 | + { | |
| 25 | + zoomCoords = ((vTexCoord - 0.5) * 0.9); | |
| 26 | + zoomCoords = zoomCoords + 0.5; | |
| 27 | + | |
| 28 | + float interpNormal = mix(0.7, 1.0, (metaColor.r - 0.85) * 4.); | |
| 29 | + normal.xyz = vec3(fakePos.x * (1.0 - interpNormal) / len, fakePos.y * (1.0 - interpNormal) / len, interpNormal); | |
| 30 | + normal.xyz = normalize(normal.xyz); | |
| 31 | + color = vec3(0.65, 1.0, 0); | |
| 32 | + colorPos = vec3(fakePos.x,fakePos.y,0); | |
| 33 | + } | |
| 34 | + else if (metaColor.r > 0.75) | |
| 35 | + { | |
| 36 | + float interpolation = mix(0.9, 1.15, (0.85 - metaColor.r) * 10.0); | |
| 37 | + zoomCoords = ((vTexCoord - 0.5) * interpolation); | |
| 38 | + zoomCoords = zoomCoords + 0.5; | |
| 39 | + | |
| 40 | + float interpNormal = mix(0.7, 0.0, (0.85 - metaColor.r) * 10.0); | |
| 41 | + normal.xyz = vec3(fakePos.x * (1.0 - interpNormal) / len, fakePos.y * (1.0 - interpNormal) / len, interpNormal); | |
| 42 | + normal.xyz = normalize(normal.xyz); | |
| 43 | + color = vec3(0.65, 1.0, 0); | |
| 44 | + colorPos = vec3(fakePos.x,fakePos.y,0); | |
| 45 | + } | |
| 46 | + else | |
| 47 | + { | |
| 48 | + zoomCoords = vTexCoord; | |
| 49 | + normal = vec3(0,0,0); | |
| 50 | + ambient = 0.5; | |
| 51 | + } | |
| 52 | + | |
| 53 | + vec3 lightPosition = vec3(-750.0,-1000.0,2000.0); | |
| 54 | + vec3 vertex = vec3(adjustedCoords.x,adjustedCoords.y,0.0); | |
| 55 | + | |
| 56 | + vec3 vecToLight = normalize( lightPosition - vertex ); | |
| 57 | + | |
| 58 | + float lightDiffuse = dot( vecToLight, normal ); | |
| 59 | + lightDiffuse = max(0.0,lightDiffuse); | |
| 60 | + lightDiffuse = lightDiffuse * 0.5 + 0.5; | |
| 61 | + | |
| 62 | + vec3 vertexToEye = vec3(0,0,1) - vertex; | |
| 63 | + vertexToEye = normalize(vertexToEye); | |
| 64 | + vec3 lightReflect = normalize(reflect(-vecToLight, normal)); | |
| 65 | + float specularFactor = max(0.0,dot(vertexToEye, lightReflect)); | |
| 66 | + specularFactor = pow(specularFactor, 32.0) * 0.7; | |
| 67 | + | |
| 68 | + vec4 texColor = texture2D(sTexture, zoomCoords); | |
| 69 | + gl_FragColor.rgb = texColor.rgb * ambient + color.rgb * texColor.rgb * lightDiffuse + vec3(specularFactor); | |
| 70 | + gl_FragColor.a = 1.0; | |
| 71 | +} | ... | ... |
examples/metaball-explosion/shaders/metaball.frag
0 → 100644
| 1 | +// Fragment shader code for metaball | |
| 2 | + | |
| 3 | +precision mediump float; | |
| 4 | +varying vec2 vTexCoord; | |
| 5 | +uniform vec2 uPositionMetaball; | |
| 6 | +uniform vec2 uPositionVar; | |
| 7 | +uniform vec2 uGravityVector; | |
| 8 | +uniform float uRadius; | |
| 9 | +uniform float uRadiusVar; | |
| 10 | + | |
| 11 | +void main() | |
| 12 | +{ | |
| 13 | + vec2 adjustedCoords = vTexCoord * 2.0 - 1.0; | |
| 14 | + vec2 finalMetaballPosition = uPositionMetaball + uGravityVector + uPositionVar; | |
| 15 | + | |
| 16 | + float finalRadius = uRadius + uRadiusVar; | |
| 17 | + vec2 distanceVec = adjustedCoords - finalMetaballPosition; | |
| 18 | + float result = dot(distanceVec, distanceVec); | |
| 19 | + float color = inversesqrt(result) * finalRadius; | |
| 20 | + | |
| 21 | + gl_FragColor = vec4(color,color,color,1.0); | |
| 22 | +} | ... | ... |
examples/metaball-explosion/shaders/metaball.vert
0 → 100644
| 1 | +//Vertex shader code for metaball | |
| 2 | + | |
| 3 | +attribute mediump vec2 aPosition; | |
| 4 | +attribute mediump vec2 aTexture; | |
| 5 | +uniform mediump mat4 uMvpMatrix; | |
| 6 | +uniform mediump vec3 uSize; | |
| 7 | +uniform lowp vec4 uColor; | |
| 8 | +varying mediump vec2 vTexCoord; | |
| 9 | + | |
| 10 | +void main() | |
| 11 | +{ | |
| 12 | + vTexCoord = aTexture; | |
| 13 | + mediump vec4 vertexPosition = vec4(aPosition.x, aPosition.y, 0.0, 1.0); | |
| 14 | + gl_Position = uMvpMatrix * vertexPosition; | |
| 15 | +} | ... | ... |
examples/metaball-refrac/metaball-refrac-example.cpp
| ... | ... | @@ -27,6 +27,10 @@ |
| 27 | 27 | |
| 28 | 28 | // INTERNAL INCLUDES |
| 29 | 29 | #include "shared/utility.h" // DemoHelper::LoadTexture |
| 30 | +#include "generated/metaball-vert.h" | |
| 31 | +#include "generated/metaball-frag.h" | |
| 32 | +#include "generated/metaball-refraction-frag.h" | |
| 33 | +#include "generated/fragment-frag.h" | |
| 30 | 34 | |
| 31 | 35 | using namespace Dali; |
| 32 | 36 | |
| ... | ... | @@ -39,117 +43,6 @@ const float GRAVITY_Y(-0.09); |
| 39 | 43 | // number of metaballs |
| 40 | 44 | constexpr uint32_t METABALL_NUMBER = 6; |
| 41 | 45 | |
| 42 | -// clang-format off | |
| 43 | - | |
| 44 | -/** | |
| 45 | - * Vertex shader for metaballs | |
| 46 | - */ | |
| 47 | -const char* const METABALL_VERTEX_SHADER = DALI_COMPOSE_SHADER ( | |
| 48 | - attribute mediump vec2 aPosition;\n | |
| 49 | - attribute mediump vec2 aTexture;\n | |
| 50 | - uniform mediump mat4 uMvpMatrix;\n | |
| 51 | - uniform mediump vec3 uSize;\n | |
| 52 | - uniform lowp vec4 uColor;\n | |
| 53 | - varying mediump vec2 vTexCoord;\n | |
| 54 | - | |
| 55 | - void main()\n | |
| 56 | - {\n | |
| 57 | - mediump vec4 vertexPosition = vec4(aPosition.x, aPosition.y, 0.0, 1.0);\n | |
| 58 | - vertexPosition = uMvpMatrix * vertexPosition;\n | |
| 59 | - gl_Position = vertexPosition;\n | |
| 60 | - vTexCoord = aTexture;\n | |
| 61 | - }\n | |
| 62 | -); | |
| 63 | - | |
| 64 | -/** | |
| 65 | - * Fragment shader for metaballs | |
| 66 | - */ | |
| 67 | -const char* const METABALL_FRAG_SHADER = DALI_COMPOSE_SHADER ( | |
| 68 | - precision mediump float;\n | |
| 69 | - varying vec2 vTexCoord;\n | |
| 70 | - uniform vec2 uPositionMetaball;\n | |
| 71 | - uniform vec2 uPositionVar;\n | |
| 72 | - uniform vec2 uGravityVector;\n | |
| 73 | - uniform float uRadius;\n | |
| 74 | - uniform float uRadiusVar;\n | |
| 75 | - uniform float uAspect;\n | |
| 76 | - void main()\n | |
| 77 | - {\n | |
| 78 | - vec2 adjustedCoords = vTexCoord * 2.0 - 1.0;\n | |
| 79 | - vec2 finalMetaballPosition = uPositionMetaball + uGravityVector + uPositionVar;\n | |
| 80 | - | |
| 81 | - float distance = (adjustedCoords.x - finalMetaballPosition.x) * (adjustedCoords.x - finalMetaballPosition.x) + | |
| 82 | - (adjustedCoords.y - finalMetaballPosition.y) * (adjustedCoords.y - finalMetaballPosition.y);\n | |
| 83 | - float finalRadius = uRadius + uRadiusVar;\n | |
| 84 | - float color = finalRadius / sqrt( distance );\n | |
| 85 | - vec2 bordercolor = vec2(0.0,0.0);\n | |
| 86 | - if (vTexCoord.x < 0.1)\n | |
| 87 | - {\n | |
| 88 | - bordercolor.x = (0.1 - vTexCoord.x) * 0.8;\n | |
| 89 | - }\n | |
| 90 | - if (vTexCoord.x > 0.9)\n | |
| 91 | - {\n | |
| 92 | - bordercolor.x = (vTexCoord.x - 0.9) * 0.8;\n | |
| 93 | - }\n | |
| 94 | - if (vTexCoord.y < 0.1)\n | |
| 95 | - {\n | |
| 96 | - bordercolor.y = (0.1 - vTexCoord.y) * 0.8;\n | |
| 97 | - }\n | |
| 98 | - if (vTexCoord.y > (0.9 * uAspect))\n | |
| 99 | - {\n | |
| 100 | - bordercolor.y = (vTexCoord.y - (0.9 * uAspect)) * 0.8;\n | |
| 101 | - }\n | |
| 102 | - float border = (bordercolor.x + bordercolor.y) * 0.5;\n | |
| 103 | - gl_FragColor = vec4(color + border,color + border,color + border,1.0);\n | |
| 104 | - }\n | |
| 105 | -); | |
| 106 | - | |
| 107 | -/** | |
| 108 | - * Fragment shader code for metaball and background composition with refraction effect | |
| 109 | - */ | |
| 110 | -const char* const REFRACTION_FRAG_SHADER = DALI_COMPOSE_SHADER ( | |
| 111 | - precision mediump float;\n | |
| 112 | - varying vec2 vTexCoord;\n | |
| 113 | - uniform sampler2D sTexture;\n | |
| 114 | - uniform sampler2D sEffect;\n | |
| 115 | - void main()\n | |
| 116 | - {\n | |
| 117 | - vec4 metaColor = texture2D(sEffect, vTexCoord);\n | |
| 118 | - vec2 zoomCoords;\n | |
| 119 | - float bright = 1.0;\n | |
| 120 | - if (metaColor.r > 0.85)\n | |
| 121 | - {\n | |
| 122 | - zoomCoords = ((vTexCoord - 0.5) * 0.95) + 0.5;\n | |
| 123 | - }\n | |
| 124 | - else if (metaColor.r > 0.78)\n | |
| 125 | - {\n | |
| 126 | - float interpolation = mix(0.95, 1.05, (0.85 - metaColor.r) * 50.0);\n | |
| 127 | - zoomCoords = ((vTexCoord - 0.5) * interpolation) + 0.5;\n | |
| 128 | - bright = 1.2;\n | |
| 129 | - }\n | |
| 130 | - else\n | |
| 131 | - {\n | |
| 132 | - zoomCoords = vTexCoord;\n | |
| 133 | - }\n | |
| 134 | - | |
| 135 | - gl_FragColor = texture2D(sTexture, zoomCoords) * bright;\n | |
| 136 | - }\n | |
| 137 | - ); | |
| 138 | - | |
| 139 | -/** | |
| 140 | - * Fragment shader code when there's no effect | |
| 141 | - */ | |
| 142 | -const char* const FRAG_SHADER = DALI_COMPOSE_SHADER ( | |
| 143 | - precision mediump float;\n | |
| 144 | - varying vec2 vTexCoord;\n | |
| 145 | - uniform sampler2D sTexture;\n | |
| 146 | - void main()\n | |
| 147 | - {\n | |
| 148 | - gl_FragColor = texture2D(sTexture, vTexCoord);\n | |
| 149 | - }\n | |
| 150 | -); | |
| 151 | -// clang-format on | |
| 152 | - | |
| 153 | 46 | /** |
| 154 | 47 | * Metadata for each ball |
| 155 | 48 | */ |
| ... | ... | @@ -405,7 +298,7 @@ void MetaballRefracController::CreateMetaballActors() |
| 405 | 298 | const float aspect = mScreenSize.y / mScreenSize.x; |
| 406 | 299 | |
| 407 | 300 | // Create the renderer for the metaballs |
| 408 | - Shader shader = Shader::New(METABALL_VERTEX_SHADER, METABALL_FRAG_SHADER, Shader::Hint::MODIFIES_GEOMETRY); | |
| 301 | + Shader shader = Shader::New(SHADER_METABALL_VERT, SHADER_METABALL_FRAG, Shader::Hint::MODIFIES_GEOMETRY); | |
| 409 | 302 | Geometry metaballGeometry = CreateGeometry(); |
| 410 | 303 | Renderer renderer = Renderer::New(metaballGeometry, shader); |
| 411 | 304 | renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); |
| ... | ... | @@ -471,7 +364,7 @@ void MetaballRefracController::CreateMetaballImage() |
| 471 | 364 | void MetaballRefracController::CreateComposition() |
| 472 | 365 | { |
| 473 | 366 | // Create Refraction shader and renderer |
| 474 | - mShaderRefraction = Shader::New(METABALL_VERTEX_SHADER, REFRACTION_FRAG_SHADER); | |
| 367 | + mShaderRefraction = Shader::New(SHADER_METABALL_VERT, SHADER_METABALL_REFRACTION_FRAG); | |
| 475 | 368 | |
| 476 | 369 | // Create new texture set |
| 477 | 370 | mTextureSetRefraction = TextureSet::New(); |
| ... | ... | @@ -479,7 +372,7 @@ void MetaballRefracController::CreateComposition() |
| 479 | 372 | mTextureSetRefraction.SetTexture(1u, mMetaballFBO.GetColorTexture()); |
| 480 | 373 | |
| 481 | 374 | // Create normal shader |
| 482 | - mShaderNormal = Shader::New(METABALL_VERTEX_SHADER, FRAG_SHADER); | |
| 375 | + mShaderNormal = Shader::New(SHADER_METABALL_VERT, SHADER_FRAGMENT_FRAG); | |
| 483 | 376 | |
| 484 | 377 | // Create new texture set |
| 485 | 378 | mTextureSetNormal = TextureSet::New(); | ... | ... |
examples/metaball-refrac/shaders/fragment.frag
0 → 100644
examples/metaball-refrac/shaders/metaball-refraction.frag
0 → 100644
| 1 | +// Fragment shader code for metaball and background composition with refraction effect | |
| 2 | + | |
| 3 | +precision mediump float; | |
| 4 | +varying vec2 vTexCoord; | |
| 5 | +uniform sampler2D sTexture; | |
| 6 | +uniform sampler2D sEffect; | |
| 7 | + | |
| 8 | +void main() | |
| 9 | +{ | |
| 10 | + vec4 metaColor = texture2D(sEffect, vTexCoord); | |
| 11 | + vec2 zoomCoords; | |
| 12 | + float bright = 1.0; | |
| 13 | + if (metaColor.r > 0.85) | |
| 14 | + { | |
| 15 | + zoomCoords = ((vTexCoord - 0.5) * 0.95) + 0.5; | |
| 16 | + } | |
| 17 | + else if (metaColor.r > 0.78) | |
| 18 | + { | |
| 19 | + float interpolation = mix(0.95, 1.05, (0.85 - metaColor.r) * 50.0); | |
| 20 | + zoomCoords = ((vTexCoord - 0.5) * interpolation) + 0.5; | |
| 21 | + bright = 1.2; | |
| 22 | + } | |
| 23 | + else | |
| 24 | + { | |
| 25 | + zoomCoords = vTexCoord; | |
| 26 | + } | |
| 27 | + | |
| 28 | + gl_FragColor = texture2D(sTexture, zoomCoords) * bright; | |
| 29 | +} | ... | ... |
examples/metaball-refrac/shaders/metaball.frag
0 → 100644
| 1 | +// Fragment shader for metaballs | |
| 2 | + | |
| 3 | +precision mediump float; | |
| 4 | +varying vec2 vTexCoord; | |
| 5 | +uniform vec2 uPositionMetaball; | |
| 6 | +uniform vec2 uPositionVar; | |
| 7 | +uniform vec2 uGravityVector; | |
| 8 | +uniform float uRadius; | |
| 9 | +uniform float uRadiusVar; | |
| 10 | +uniform float uAspect; | |
| 11 | + | |
| 12 | +void main() | |
| 13 | +{ | |
| 14 | + vec2 adjustedCoords = vTexCoord * 2.0 - 1.0; | |
| 15 | + vec2 finalMetaballPosition = uPositionMetaball + uGravityVector + uPositionVar; | |
| 16 | + | |
| 17 | + float distance = (adjustedCoords.x - finalMetaballPosition.x) * (adjustedCoords.x - finalMetaballPosition.x) + | |
| 18 | + (adjustedCoords.y - finalMetaballPosition.y) * (adjustedCoords.y - finalMetaballPosition.y); | |
| 19 | + float finalRadius = uRadius + uRadiusVar; | |
| 20 | + float color = finalRadius / sqrt( distance ); | |
| 21 | + vec2 bordercolor = vec2(0.0,0.0); | |
| 22 | + if (vTexCoord.x < 0.1) | |
| 23 | + { | |
| 24 | + bordercolor.x = (0.1 - vTexCoord.x) * 0.8; | |
| 25 | + } | |
| 26 | + if (vTexCoord.x > 0.9) | |
| 27 | + { | |
| 28 | + bordercolor.x = (vTexCoord.x - 0.9) * 0.8; | |
| 29 | + } | |
| 30 | + if (vTexCoord.y < 0.1) | |
| 31 | + { | |
| 32 | + bordercolor.y = (0.1 - vTexCoord.y) * 0.8; | |
| 33 | + } | |
| 34 | + if (vTexCoord.y > (0.9 * uAspect)) | |
| 35 | + { | |
| 36 | + bordercolor.y = (vTexCoord.y - (0.9 * uAspect)) * 0.8; | |
| 37 | + } | |
| 38 | + float border = (bordercolor.x + bordercolor.y) * 0.5; | |
| 39 | + gl_FragColor = vec4(color + border,color + border,color + border,1.0); | |
| 40 | +} | ... | ... |
examples/metaball-refrac/shaders/metaball.vert
0 → 100644
| 1 | +// Vertex shader for metaballs | |
| 2 | + | |
| 3 | +attribute mediump vec2 aPosition; | |
| 4 | +attribute mediump vec2 aTexture; | |
| 5 | +uniform mediump mat4 uMvpMatrix; | |
| 6 | +uniform mediump vec3 uSize; | |
| 7 | +uniform lowp vec4 uColor; | |
| 8 | +varying mediump vec2 vTexCoord; | |
| 9 | + | |
| 10 | +void main() | |
| 11 | +{ | |
| 12 | + mediump vec4 vertexPosition = vec4(aPosition.x, aPosition.y, 0.0, 1.0); | |
| 13 | + vertexPosition = uMvpMatrix * vertexPosition; | |
| 14 | + gl_Position = vertexPosition; | |
| 15 | + vTexCoord = aTexture; | |
| 16 | +} | ... | ... |
examples/native-image-source/native-image-source-example.cpp
| ... | ... | @@ -22,6 +22,8 @@ |
| 22 | 22 | |
| 23 | 23 | // INTERNAL INCLUDES |
| 24 | 24 | #include "shared/utility.h" |
| 25 | +#include "generated/native-image-source-texture-vert.h" | |
| 26 | +#include "generated/native-image-source-texture-frag.h" | |
| 25 | 27 | |
| 26 | 28 | using namespace Dali; |
| 27 | 29 | using namespace Toolkit; |
| ... | ... | @@ -43,33 +45,6 @@ Shader CreateShader(NativeImageInterface& nativeImage) |
| 43 | 45 | { |
| 44 | 46 | static const char* DEFAULT_SAMPLER_TYPENAME = "sampler2D"; |
| 45 | 47 | |
| 46 | - // clang-format off | |
| 47 | - static const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( | |
| 48 | - attribute mediump vec2 aPosition;\n | |
| 49 | - attribute mediump vec2 aTexCoord;\n | |
| 50 | - uniform mediump mat4 uMvpMatrix;\n | |
| 51 | - uniform mediump vec3 uSize;\n | |
| 52 | - varying mediump vec2 vTexCoord;\n | |
| 53 | - void main()\n | |
| 54 | - {\n | |
| 55 | - vec4 position = vec4(aPosition,0.0,1.0)*vec4(uSize,1.0);\n | |
| 56 | - gl_Position = uMvpMatrix * position;\n | |
| 57 | - vTexCoord = aTexCoord;\n | |
| 58 | - }\n | |
| 59 | - ); | |
| 60 | - | |
| 61 | - static const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( | |
| 62 | - uniform lowp vec4 uColor;\n | |
| 63 | - uniform sampler2D sTexture;\n | |
| 64 | - varying mediump vec2 vTexCoord;\n | |
| 65 | - | |
| 66 | - void main()\n | |
| 67 | - {\n | |
| 68 | - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n | |
| 69 | - }\n | |
| 70 | - ); | |
| 71 | - // clang-format on | |
| 72 | - | |
| 73 | 48 | std::string fragmentShader; |
| 74 | 49 | |
| 75 | 50 | //Get custom fragment shader prefix |
| ... | ... | @@ -77,11 +52,11 @@ Shader CreateShader(NativeImageInterface& nativeImage) |
| 77 | 52 | if(fragmentPrefix) |
| 78 | 53 | { |
| 79 | 54 | fragmentShader = fragmentPrefix; |
| 80 | - fragmentShader += FRAGMENT_SHADER_TEXTURE; | |
| 55 | + fragmentShader += SHADER_NATIVE_IMAGE_SOURCE_TEXTURE_FRAG.data(); | |
| 81 | 56 | } |
| 82 | 57 | else |
| 83 | 58 | { |
| 84 | - fragmentShader = FRAGMENT_SHADER_TEXTURE; | |
| 59 | + fragmentShader = SHADER_NATIVE_IMAGE_SOURCE_TEXTURE_FRAG.data(); | |
| 85 | 60 | } |
| 86 | 61 | |
| 87 | 62 | //Get custom sampler type name |
| ... | ... | @@ -91,7 +66,7 @@ Shader CreateShader(NativeImageInterface& nativeImage) |
| 91 | 66 | fragmentShader.replace(fragmentShader.find(DEFAULT_SAMPLER_TYPENAME), strlen(DEFAULT_SAMPLER_TYPENAME), customSamplerTypename); |
| 92 | 67 | } |
| 93 | 68 | |
| 94 | - return Shader::New(VERTEX_SHADER_TEXTURE, fragmentShader); | |
| 69 | + return Shader::New(SHADER_NATIVE_IMAGE_SOURCE_TEXTURE_VERT, fragmentShader); | |
| 95 | 70 | } |
| 96 | 71 | |
| 97 | 72 | } // namespace | ... | ... |
examples/native-image-source/shaders/native-image-source-texture.frag
0 → 100644
examples/native-image-source/shaders/native-image-source-texture.vert
0 → 100644
| 1 | +attribute mediump vec2 aPosition; | |
| 2 | +attribute mediump vec2 aTexCoord; | |
| 3 | +uniform mediump mat4 uMvpMatrix; | |
| 4 | +uniform mediump vec3 uSize; | |
| 5 | +varying mediump vec2 vTexCoord; | |
| 6 | + | |
| 7 | +void main() | |
| 8 | +{ | |
| 9 | + vec4 position = vec4(aPosition,0.0,1.0)*vec4(uSize,1.0); | |
| 10 | + gl_Position = uMvpMatrix * position; | |
| 11 | + vTexCoord = aTexCoord; | |
| 12 | +} | ... | ... |
examples/particles/particle-view.cpp
| ... | ... | @@ -18,6 +18,11 @@ |
| 18 | 18 | #include "utils.h" |
| 19 | 19 | #include "dali/public-api/animation/constraints.h" |
| 20 | 20 | |
| 21 | +#include "generated/particle-view-vert.h" | |
| 22 | +#include "generated/particle-view-frag.h" | |
| 23 | +#include "generated/particle-view-simple-vert.h" | |
| 24 | +#include "generated/particle-view-simple-frag.h" | |
| 25 | + | |
| 21 | 26 | //#define ENABLE_DEBUG_VOLUME |
| 22 | 27 | |
| 23 | 28 | #define USE_GLSL_VERSION(version) "#version " #version "\n" |
| ... | ... | @@ -29,195 +34,6 @@ namespace |
| 29 | 34 | |
| 30 | 35 | const uint32_t POPULATION_GRANULARITY = 128; |
| 31 | 36 | |
| 32 | -///@brief Shader for billboarded particles, where the vertices of the particles | |
| 33 | -/// are supplied as vec3 position (particle position) + vec2 sub-position. | |
| 34 | -const char* const PARTICLES_VSH = USE_GLSL_VERSION(300 es) | |
| 35 | -DALI_COMPOSE_SHADER( | |
| 36 | - precision lowp float; | |
| 37 | - uniform mat4 uModelView; // DALi | |
| 38 | - uniform mat4 uProjection; // DALi | |
| 39 | - uniform vec3 uSize; // DALi | |
| 40 | - uniform vec4 uColor; // DALi | |
| 41 | - | |
| 42 | - uniform vec3 uSecondaryColor; | |
| 43 | - uniform vec2 uDepthRange; // x is zNear, y is 1.f / (zFar - zNear) | |
| 44 | - uniform float uTwinkleFrequency; | |
| 45 | - uniform float uTwinkleSizeScale; | |
| 46 | - uniform float uTwinkleOpacityWeight; | |
| 47 | - uniform float uTime; | |
| 48 | - uniform float uFocalLength; | |
| 49 | - uniform float uAperture; | |
| 50 | - uniform float uPopulation; | |
| 51 | - | |
| 52 | - struct Scatter | |
| 53 | - { | |
| 54 | - float radiusSqr; | |
| 55 | - float amount; | |
| 56 | - vec3 ray; | |
| 57 | - }; | |
| 58 | - | |
| 59 | - const int SCATTER_VARS = 6; // Must match ParticleView::mScatterProps' size. | |
| 60 | - uniform Scatter uScatter[SCATTER_VARS]; | |
| 61 | - | |
| 62 | - const int POPULATION_GRANULARITY = 128; | |
| 63 | - uniform float uOrderLookUp[POPULATION_GRANULARITY]; | |
| 64 | - | |
| 65 | - in vec3 aPosition; | |
| 66 | - in float aSeed; | |
| 67 | - in vec4 aPath; | |
| 68 | - in vec2 aSubPosition; | |
| 69 | - in float aSize; | |
| 70 | - | |
| 71 | - flat out float vDepth; | |
| 72 | - flat out float vFocalDistance; | |
| 73 | - out vec2 vUvUnit; | |
| 74 | - flat out float vOpacity; | |
| 75 | - flat out vec3 vColor; // ignore alpha | |
| 76 | - | |
| 77 | - float bezier(vec3 control, float alpha) | |
| 78 | - { | |
| 79 | - return mix(mix(control.x, control.y, alpha), mix(control.y, control.z, alpha), alpha); | |
| 80 | - } | |
| 81 | - | |
| 82 | - void main() { | |
| 83 | - // Get random order from the look-up table, based on particle ID. | |
| 84 | - int particleId = gl_VertexID / 6; | |
| 85 | - float order = uOrderLookUp[particleId & (POPULATION_GRANULARITY - 1)]; | |
| 86 | - | |
| 87 | - // Get twinkle scalar | |
| 88 | - float twinkle = sin(uTime * floor(uTwinkleFrequency * aSeed) + fract(aSeed * 1.17137)); | |
| 89 | - | |
| 90 | - // Add Motion | |
| 91 | - float s = sin(uTime + aSeed) * .5f + .5f; // different phase for all | |
| 92 | - // NOTE: you'd think that taking the bezier() calls apart would save 4 mix() calls, since | |
| 93 | - // the mix()es (of xy / yz / zw / wx) are all calculated twice. It turns out that the MALI | |
| 94 | - // compiler is already doing this; leaving it as is for readability. | |
| 95 | - float bx0 = bezier(aPath.xyz, s); | |
| 96 | - float bx1 = bezier(aPath.zwx, s); | |
| 97 | - float by0 = bezier(aPath.yzw, s); | |
| 98 | - float by1 = bezier(aPath.wxy, s); | |
| 99 | - vec3 motion = vec3(mix(bx0, bx1, s), mix(by0, by1, s), 0.f); | |
| 100 | - | |
| 101 | - // Model to view position | |
| 102 | - vec3 position3 = aPosition * uSize + motion; | |
| 103 | - | |
| 104 | - vec4 position = uModelView * vec4(position3, 1.f); | |
| 105 | - | |
| 106 | - // Add scatter - calculated in view space, using view ray | |
| 107 | - vec3 normalizedPos = position.xyz / uSize; | |
| 108 | - for (int i = 0; i < SCATTER_VARS; ++i) | |
| 109 | - { | |
| 110 | - vec2 scatterDist = (normalizedPos - uScatter[i].ray * dot(uScatter[i].ray, normalizedPos)).xy; | |
| 111 | - | |
| 112 | - // NOTE: replacing the division with a multiplication (by inverse) oddly results in more instructions (MALI). | |
| 113 | - float scatter = max(0.f, uScatter[i].radiusSqr - dot(scatterDist, scatterDist)) * | |
| 114 | - uScatter[i].amount / aSize; | |
| 115 | - position.xy += scatter * normalize(scatterDist) * uSize.xy; | |
| 116 | - } | |
| 117 | - | |
| 118 | - // Calculate normalised depth and distance from focal plane | |
| 119 | - float depth = (position.z - uDepthRange.x) * uDepthRange.y; | |
| 120 | - vDepth = depth; | |
| 121 | - | |
| 122 | - float focalDist = (uFocalLength - depth) * uAperture; | |
| 123 | - focalDist *= focalDist; | |
| 124 | - vFocalDistance = max(focalDist, 1e-6f); // NOTE: was clamp(..., 1.f); side effect: out of focus particles get squashed at higher aperture values. | |
| 125 | - | |
| 126 | - // Calculate expiring scale - for size and opacity. | |
| 127 | - float expiringScale = smoothstep(order + 1.f, order, uPopulation); | |
| 128 | - | |
| 129 | - // Calculate billboard position and size | |
| 130 | - vec2 subPosition = aSubPosition * aSize * | |
| 131 | - (1.f + twinkle * aSeed * uTwinkleSizeScale) * | |
| 132 | - expiringScale; | |
| 133 | - | |
| 134 | - // Insist on hacking the size? Do it here... | |
| 135 | - float sizeHack = depth + .5f; | |
| 136 | - // NOTE: sizeHack *= sizeHack looked slightly better. | |
| 137 | - subPosition *= sizeHack; | |
| 138 | - | |
| 139 | - vec3 subPositionView = vec3(subPosition, 0.); | |
| 140 | - | |
| 141 | - // Add billboards to view position. | |
| 142 | - position += vec4(subPositionView, 0.f); | |
| 143 | - | |
| 144 | - // subPosition doubles as normalized (-1..1) UV. | |
| 145 | - vUvUnit = aSubPosition; | |
| 146 | - | |
| 147 | - // Vary opacity (actor alpha) by time as well as expiring scale. | |
| 148 | - vOpacity = uColor.a * expiringScale * | |
| 149 | - (1.0f + aSeed + twinkle * uTwinkleOpacityWeight) / (2.0f + uTwinkleOpacityWeight); | |
| 150 | - | |
| 151 | - // Randomize RGB using seed. | |
| 152 | - vec3 mixColor = vec3(fract(aSeed), fract(aSeed * 16.f), fract(aSeed * 256.f)); | |
| 153 | - vColor = mix(uColor.rgb, uSecondaryColor, mixColor); | |
| 154 | - | |
| 155 | - gl_Position = uProjection * position; | |
| 156 | - }); | |
| 157 | - | |
| 158 | -///@brief Fragment shader for particles, which simulates depth of field | |
| 159 | -/// using a combination of procedural texturing, alpha testing and alpha | |
| 160 | -/// blending. | |
| 161 | -const char* const PARTICLES_FSH = USE_GLSL_VERSION(300 es) | |
| 162 | -DALI_COMPOSE_SHADER( | |
| 163 | - precision lowp float; | |
| 164 | - uniform float uAlphaTestRefValue; | |
| 165 | - uniform vec2 uFadeRange; // near, far | |
| 166 | - in vec2 vUvUnit; | |
| 167 | - flat in float vDepth; | |
| 168 | - flat in float vFocalDistance; | |
| 169 | - flat in float vOpacity; | |
| 170 | - flat in vec3 vColor; | |
| 171 | - out vec4 oFragColor; | |
| 172 | - | |
| 173 | - const float REF_VALUE_THRESHOLD = 1. / 64.; | |
| 174 | - | |
| 175 | - void main() { | |
| 176 | - // Softened disc pattern from normalized UVs | |
| 177 | - float value = 1.f - dot(vUvUnit, vUvUnit); | |
| 178 | - | |
| 179 | - // Decrease area of particles 'in-focus'. | |
| 180 | - float refValue = (1.f - vFocalDistance) * .5f; | |
| 181 | - float threshold = REF_VALUE_THRESHOLD * (1.f + vDepth); | |
| 182 | - float alpha = pow(value, vFocalDistance) * smoothstep(refValue - threshold, refValue + threshold, value); | |
| 183 | - if (alpha < uAlphaTestRefValue) | |
| 184 | - { | |
| 185 | - discard; | |
| 186 | - } | |
| 187 | - | |
| 188 | - // Apply opacity | |
| 189 | - alpha *= vOpacity; | |
| 190 | - alpha *= alpha; | |
| 191 | - | |
| 192 | - // Fade particles out as they get close to the near and far clipping planes | |
| 193 | - alpha *= smoothstep(.0f, uFadeRange.x, vDepth) * smoothstep(1.f, uFadeRange.y, vDepth); | |
| 194 | - | |
| 195 | - oFragColor = vec4(vColor, alpha); | |
| 196 | - }); | |
| 197 | - | |
| 198 | -///@brief Shader for simple textured geometry. | |
| 199 | -const char* const SIMPLE_VSH = USE_GLSL_VERSION(300 es) | |
| 200 | -DALI_COMPOSE_SHADER( | |
| 201 | - precision mediump float; | |
| 202 | - uniform mat4 uMvpMatrix;//by DALi | |
| 203 | - uniform vec3 uSize; // by DALi | |
| 204 | - in vec3 aPosition; | |
| 205 | - void main() { | |
| 206 | - gl_Position = uMvpMatrix * vec4(aPosition * uSize, 1.f); | |
| 207 | - }); | |
| 208 | - | |
| 209 | -///@brief Shader for an unlit, unfogged, textured mesh. | |
| 210 | -const char* const SIMPLE_FSH = USE_GLSL_VERSION(300 es) | |
| 211 | -DALI_COMPOSE_SHADER( | |
| 212 | - precision mediump float; | |
| 213 | - uniform vec4 uColor; | |
| 214 | - out vec4 oFragColor; | |
| 215 | - | |
| 216 | - void main() { | |
| 217 | - oFragColor = uColor; | |
| 218 | - }); | |
| 219 | - | |
| 220 | - | |
| 221 | 37 | uint32_t GetSkipValue(uint32_t count, uint32_t prime) |
| 222 | 38 | { |
| 223 | 39 | uint32_t skip = 0; |
| ... | ... | @@ -243,7 +59,7 @@ ParticleView::ParticleView(const ParticleField& field, Dali::Actor world, Dali:: |
| 243 | 59 | } |
| 244 | 60 | |
| 245 | 61 | // create shader |
| 246 | - Shader particleShader = Shader::New(PARTICLES_VSH, PARTICLES_FSH, Shader::Hint::MODIFIES_GEOMETRY); | |
| 62 | + Shader particleShader = Shader::New(SHADER_PARTICLE_VIEW_VERT, SHADER_PARTICLE_VIEW_FRAG, Shader::Hint::MODIFIES_GEOMETRY); | |
| 247 | 63 | |
| 248 | 64 | float zNear = camera.GetNearClippingPlane(); |
| 249 | 65 | float zFar = camera.GetFarClippingPlane(); |
| ... | ... | @@ -318,7 +134,7 @@ ParticleView::ParticleView(const ParticleField& field, Dali::Actor world, Dali:: |
| 318 | 134 | |
| 319 | 135 | #ifdef ENABLE_DEBUG_VOLUME |
| 320 | 136 | Geometry cubeGeom = CreateCuboidWireframeGeometry(); |
| 321 | - renderer = CreateRenderer(renderer.GetTextures(), cubeGeom, Shader::New(SIMPLE_VSH, SIMPLE_FSH)); | |
| 137 | + renderer = CreateRenderer(renderer.GetTextures(), cubeGeom, Shader::New(SHADER_PARTICLE_VIEW_SIMPLE_VERT, SHADER_PARTICLE_VIEW_SIMPLE_FRAG)); | |
| 322 | 138 | masterParticles.AddRenderer(renderer); |
| 323 | 139 | #endif |
| 324 | 140 | ... | ... |
examples/particles/shaders/particle-view-simple.frag
0 → 100644
examples/particles/shaders/particle-view-simple.vert
0 → 100644
examples/particles/shaders/particle-view.frag
0 → 100644
| 1 | +// Fragment shader for particles, which simulates depth of field using | |
| 2 | +// a combination of procedural texturing, alpha testing and alpha blending. | |
| 3 | + | |
| 4 | +#version 300 es | |
| 5 | + | |
| 6 | +precision lowp float; | |
| 7 | +uniform float uAlphaTestRefValue; | |
| 8 | +uniform vec2 uFadeRange; // near, far | |
| 9 | +in vec2 vUvUnit; | |
| 10 | +flat in float vDepth; | |
| 11 | +flat in float vFocalDistance; | |
| 12 | +flat in float vOpacity; | |
| 13 | +flat in vec3 vColor; | |
| 14 | +out vec4 oFragColor; | |
| 15 | + | |
| 16 | +const float REF_VALUE_THRESHOLD = 1. / 64.; | |
| 17 | + | |
| 18 | +void main() | |
| 19 | +{ | |
| 20 | + // Softened disc pattern from normalized UVs | |
| 21 | + float value = 1.f - dot(vUvUnit, vUvUnit); | |
| 22 | + | |
| 23 | + // Decrease area of particles 'in-focus'. | |
| 24 | + float refValue = (1.f - vFocalDistance) * .5f; | |
| 25 | + float threshold = REF_VALUE_THRESHOLD * (1.f + vDepth); | |
| 26 | + float alpha = pow(value, vFocalDistance) * smoothstep(refValue - threshold, refValue + threshold, value); | |
| 27 | + if (alpha < uAlphaTestRefValue) | |
| 28 | + { | |
| 29 | + discard; | |
| 30 | + } | |
| 31 | + | |
| 32 | + // Apply opacity | |
| 33 | + alpha *= vOpacity; | |
| 34 | + alpha *= alpha; | |
| 35 | + | |
| 36 | + // Fade particles out as they get close to the near and far clipping planes | |
| 37 | + alpha *= smoothstep(.0f, uFadeRange.x, vDepth) * smoothstep(1.f, uFadeRange.y, vDepth); | |
| 38 | + | |
| 39 | + oFragColor = vec4(vColor, alpha); | |
| 40 | +} | ... | ... |
examples/particles/shaders/particle-view.vert
0 → 100644
| 1 | +// Shader for billboarded particles, where the vertices of the particles | |
| 2 | +// are supplied as vec3 position (particle position) + vec2 sub-position. | |
| 3 | + | |
| 4 | +#version 300 es | |
| 5 | + | |
| 6 | +precision lowp float; | |
| 7 | +uniform mat4 uModelView; // DALi | |
| 8 | +uniform mat4 uProjection; // DALi | |
| 9 | +uniform vec3 uSize; // DALi | |
| 10 | +uniform vec4 uColor; // DALi | |
| 11 | + | |
| 12 | +uniform vec3 uSecondaryColor; | |
| 13 | +uniform vec2 uDepthRange; // x is zNear, y is 1.f / (zFar - zNear) | |
| 14 | +uniform float uTwinkleFrequency; | |
| 15 | +uniform float uTwinkleSizeScale; | |
| 16 | +uniform float uTwinkleOpacityWeight; | |
| 17 | +uniform float uTime; | |
| 18 | +uniform float uFocalLength; | |
| 19 | +uniform float uAperture; | |
| 20 | +uniform float uPopulation; | |
| 21 | + | |
| 22 | +struct Scatter | |
| 23 | +{ | |
| 24 | + float radiusSqr; | |
| 25 | + float amount; | |
| 26 | + vec3 ray; | |
| 27 | +}; | |
| 28 | + | |
| 29 | +const int SCATTER_VARS = 6; // Must match ParticleView::mScatterProps' size. | |
| 30 | +uniform Scatter uScatter[SCATTER_VARS]; | |
| 31 | + | |
| 32 | +const int POPULATION_GRANULARITY = 128; | |
| 33 | +uniform float uOrderLookUp[POPULATION_GRANULARITY]; | |
| 34 | + | |
| 35 | +in vec3 aPosition; | |
| 36 | +in float aSeed; | |
| 37 | +in vec4 aPath; | |
| 38 | +in vec2 aSubPosition; | |
| 39 | +in float aSize; | |
| 40 | + | |
| 41 | +flat out float vDepth; | |
| 42 | +flat out float vFocalDistance; | |
| 43 | +out vec2 vUvUnit; | |
| 44 | +flat out float vOpacity; | |
| 45 | +flat out vec3 vColor; // ignore alpha | |
| 46 | + | |
| 47 | +float bezier(vec3 control, float alpha) | |
| 48 | +{ | |
| 49 | + return mix(mix(control.x, control.y, alpha), mix(control.y, control.z, alpha), alpha); | |
| 50 | +} | |
| 51 | + | |
| 52 | +void main() { | |
| 53 | + // Get random order from the look-up table, based on particle ID. | |
| 54 | + int particleId = gl_VertexID / 6; | |
| 55 | + float order = uOrderLookUp[particleId & (POPULATION_GRANULARITY - 1)]; | |
| 56 | + | |
| 57 | + // Get twinkle scalar | |
| 58 | + float twinkle = sin(uTime * floor(uTwinkleFrequency * aSeed) + fract(aSeed * 1.17137)); | |
| 59 | + | |
| 60 | + // Add Motion | |
| 61 | + float s = sin(uTime + aSeed) * .5f + .5f; // different phase for all | |
| 62 | + // NOTE: you'd think that taking the bezier() calls apart would save 4 mix() calls, since | |
| 63 | + // the mix()es (of xy / yz / zw / wx) are all calculated twice. It turns out that the MALI | |
| 64 | + // compiler is already doing this; leaving it as is for readability. | |
| 65 | + float bx0 = bezier(aPath.xyz, s); | |
| 66 | + float bx1 = bezier(aPath.zwx, s); | |
| 67 | + float by0 = bezier(aPath.yzw, s); | |
| 68 | + float by1 = bezier(aPath.wxy, s); | |
| 69 | + vec3 motion = vec3(mix(bx0, bx1, s), mix(by0, by1, s), 0.f); | |
| 70 | + | |
| 71 | + // Model to view position | |
| 72 | + vec3 position3 = aPosition * uSize + motion; | |
| 73 | + | |
| 74 | + vec4 position = uModelView * vec4(position3, 1.f); | |
| 75 | + | |
| 76 | + // Add scatter - calculated in view space, using view ray | |
| 77 | + vec3 normalizedPos = position.xyz / uSize; | |
| 78 | + for (int i = 0; i < SCATTER_VARS; ++i) | |
| 79 | + { | |
| 80 | + vec2 scatterDist = (normalizedPos - uScatter[i].ray * dot(uScatter[i].ray, normalizedPos)).xy; | |
| 81 | + | |
| 82 | + // NOTE: replacing the division with a multiplication (by inverse) oddly results in more instructions (MALI). | |
| 83 | + float scatter = max(0.f, uScatter[i].radiusSqr - dot(scatterDist, scatterDist)) * | |
| 84 | + uScatter[i].amount / aSize; | |
| 85 | + position.xy += scatter * normalize(scatterDist) * uSize.xy; | |
| 86 | + } | |
| 87 | + | |
| 88 | + // Calculate normalised depth and distance from focal plane | |
| 89 | + float depth = (position.z - uDepthRange.x) * uDepthRange.y; | |
| 90 | + vDepth = depth; | |
| 91 | + | |
| 92 | + float focalDist = (uFocalLength - depth) * uAperture; | |
| 93 | + focalDist *= focalDist; | |
| 94 | + vFocalDistance = max(focalDist, 1e-6f); // NOTE: was clamp(..., 1.f); side effect: out of focus particles get squashed at higher aperture values. | |
| 95 | + | |
| 96 | + // Calculate expiring scale - for size and opacity. | |
| 97 | + float expiringScale = smoothstep(order + 1.f, order, uPopulation); | |
| 98 | + | |
| 99 | + // Calculate billboard position and size | |
| 100 | + vec2 subPosition = aSubPosition * aSize * | |
| 101 | + (1.f + twinkle * aSeed * uTwinkleSizeScale) * | |
| 102 | + expiringScale; | |
| 103 | + | |
| 104 | + // Insist on hacking the size? Do it here... | |
| 105 | + float sizeHack = depth + .5f; | |
| 106 | + // NOTE: sizeHack *= sizeHack looked slightly better. | |
| 107 | + subPosition *= sizeHack; | |
| 108 | + | |
| 109 | + vec3 subPositionView = vec3(subPosition, 0.); | |
| 110 | + | |
| 111 | + // Add billboards to view position. | |
| 112 | + position += vec4(subPositionView, 0.f); | |
| 113 | + | |
| 114 | + // subPosition doubles as normalized (-1..1) UV. | |
| 115 | + vUvUnit = aSubPosition; | |
| 116 | + | |
| 117 | + // Vary opacity (actor alpha) by time as well as expiring scale. | |
| 118 | + vOpacity = uColor.a * expiringScale * | |
| 119 | + (1.0f + aSeed + twinkle * uTwinkleOpacityWeight) / (2.0f + uTwinkleOpacityWeight); | |
| 120 | + | |
| 121 | + // Randomize RGB using seed. | |
| 122 | + vec3 mixColor = vec3(fract(aSeed), fract(aSeed * 16.f), fract(aSeed * 256.f)); | |
| 123 | + vColor = mix(uColor.rgb, uSecondaryColor, mixColor); | |
| 124 | + | |
| 125 | + gl_Position = uProjection * position; | |
| 126 | +} | ... | ... |
examples/perf-scroll/perf-scroll.cpp
| ... | ... | @@ -18,6 +18,8 @@ |
| 18 | 18 | #include <dali-toolkit/dali-toolkit.h> |
| 19 | 19 | #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h> |
| 20 | 20 | #include "shared/utility.h" |
| 21 | +#include "generated/perf-scroll-vert.h" | |
| 22 | +#include "generated/perf-scroll-frag.h" | |
| 21 | 23 | |
| 22 | 24 | using namespace Dali; |
| 23 | 25 | using namespace Dali::Toolkit; |
| ... | ... | @@ -147,35 +149,6 @@ struct VertexWithTexture |
| 147 | 149 | Vector2 texCoord; |
| 148 | 150 | }; |
| 149 | 151 | |
| 150 | -// clang-format off | |
| 151 | - | |
| 152 | -const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( | |
| 153 | - attribute mediump vec2 aPosition;\n | |
| 154 | - attribute mediump vec2 aTexCoord;\n | |
| 155 | - uniform mediump mat4 uMvpMatrix;\n | |
| 156 | - uniform mediump vec3 uSize;\n | |
| 157 | - varying mediump vec2 vTexCoord;\n | |
| 158 | - void main()\n | |
| 159 | - {\n | |
| 160 | - vec4 position = vec4(aPosition,0.0,1.0)*vec4(uSize,1.0);\n | |
| 161 | - gl_Position = uMvpMatrix * position;\n | |
| 162 | - vTexCoord = aTexCoord;\n | |
| 163 | - }\n | |
| 164 | -); | |
| 165 | - | |
| 166 | -const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( | |
| 167 | - uniform lowp vec4 uColor;\n | |
| 168 | - uniform sampler2D sTexture;\n | |
| 169 | - varying mediump vec2 vTexCoord;\n | |
| 170 | - | |
| 171 | - void main()\n | |
| 172 | - {\n | |
| 173 | - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n | |
| 174 | - }\n | |
| 175 | -); | |
| 176 | - | |
| 177 | -// clang-format on | |
| 178 | - | |
| 179 | 152 | bool gUseMesh(false); |
| 180 | 153 | bool gNinePatch(false); |
| 181 | 154 | unsigned int gRowsPerPage(15); |
| ... | ... | @@ -294,7 +267,7 @@ public: |
| 294 | 267 | |
| 295 | 268 | //Create all the renderers |
| 296 | 269 | std::vector<Renderer> renderers(numImages); |
| 297 | - Shader shader = Shader::New(VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE); | |
| 270 | + Shader shader = Shader::New(SHADER_PERF_SCROLL_VERT, SHADER_PERF_SCROLL_FRAG); | |
| 298 | 271 | Geometry geometry = DemoHelper::CreateTexturedQuad(); |
| 299 | 272 | for(unsigned int i(0); i < numImages; ++i) |
| 300 | 273 | { | ... | ... |
examples/perf-scroll/shaders/perf-scroll.frag
0 → 100644
examples/perf-scroll/shaders/perf-scroll.vert
0 → 100644
| 1 | +attribute mediump vec2 aPosition; | |
| 2 | +attribute mediump vec2 aTexCoord; | |
| 3 | +uniform mediump mat4 uMvpMatrix; | |
| 4 | +uniform mediump vec3 uSize; | |
| 5 | +varying mediump vec2 vTexCoord; | |
| 6 | + | |
| 7 | +void main() | |
| 8 | +{ | |
| 9 | + vec4 position = vec4(aPosition,0.0,1.0)*vec4(uSize,1.0); | |
| 10 | + gl_Position = uMvpMatrix * position; | |
| 11 | + vTexCoord = aTexCoord; | |
| 12 | +} | ... | ... |
examples/point-mesh/point-mesh-example.cpp
| ... | ... | @@ -21,6 +21,8 @@ |
| 21 | 21 | // INTERNAL INCLUDES |
| 22 | 22 | #include "shared/utility.h" |
| 23 | 23 | #include "shared/view.h" |
| 24 | +#include "generated/point-mesh-vert.h" | |
| 25 | +#include "generated/point-mesh-frag.h" | |
| 24 | 26 | |
| 25 | 27 | using namespace Dali; |
| 26 | 28 | |
| ... | ... | @@ -29,49 +31,6 @@ namespace |
| 29 | 31 | const char* MATERIAL_SAMPLE(DEMO_IMAGE_DIR "gallery-small-48.jpg"); |
| 30 | 32 | const char* MATERIAL_SAMPLE2(DEMO_IMAGE_DIR "gallery-medium-19.jpg"); |
| 31 | 33 | |
| 32 | -#define MAKE_SHADER(A) #A | |
| 33 | - | |
| 34 | -const char* VERTEX_SHADER = MAKE_SHADER( | |
| 35 | - attribute mediump vec2 aPosition; | |
| 36 | - attribute highp float aHue; | |
| 37 | - varying mediump vec2 vTexCoord; | |
| 38 | - uniform mediump mat4 uMvpMatrix; | |
| 39 | - uniform mediump vec3 uSize; | |
| 40 | - uniform mediump float uPointSize; | |
| 41 | - uniform lowp vec4 uFadeColor; | |
| 42 | - varying mediump vec3 vVertexColor; | |
| 43 | - varying mediump float vHue; | |
| 44 | - | |
| 45 | - vec3 hsv2rgb(vec3 c) { | |
| 46 | - vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | |
| 47 | - vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); | |
| 48 | - return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); | |
| 49 | - } | |
| 50 | - | |
| 51 | - void main() { | |
| 52 | - mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | |
| 53 | - vertexPosition.xyz *= (uSize - uPointSize); | |
| 54 | - vertexPosition = uMvpMatrix * vertexPosition; | |
| 55 | - vVertexColor = hsv2rgb(vec3(aHue, 0.7, 1.0)); | |
| 56 | - vHue = aHue; | |
| 57 | - gl_PointSize = uPointSize; | |
| 58 | - gl_Position = vertexPosition; | |
| 59 | - }); | |
| 60 | - | |
| 61 | -const char* FRAGMENT_SHADER = MAKE_SHADER( | |
| 62 | - varying mediump vec3 vVertexColor; | |
| 63 | - varying mediump float vHue; | |
| 64 | - uniform lowp vec4 uColor; | |
| 65 | - uniform sampler2D sTexture1; | |
| 66 | - uniform sampler2D sTexture2; | |
| 67 | - uniform lowp vec4 uFadeColor; | |
| 68 | - | |
| 69 | - void main() { | |
| 70 | - mediump vec4 texCol1 = texture2D(sTexture1, gl_PointCoord); | |
| 71 | - mediump vec4 texCol2 = texture2D(sTexture2, gl_PointCoord); | |
| 72 | - gl_FragColor = vec4(vVertexColor, 1.0) * ((texCol1 * vHue) + (texCol2 * (1.0 - vHue))); | |
| 73 | - }); | |
| 74 | - | |
| 75 | 34 | Geometry CreateGeometry() |
| 76 | 35 | { |
| 77 | 36 | // Create vertices |
| ... | ... | @@ -150,7 +109,7 @@ public: |
| 150 | 109 | Texture texture0 = DemoHelper::LoadTexture(MATERIAL_SAMPLE); |
| 151 | 110 | Texture texture1 = DemoHelper::LoadTexture(MATERIAL_SAMPLE2); |
| 152 | 111 | |
| 153 | - Shader shader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); | |
| 112 | + Shader shader = Shader::New(SHADER_POINT_MESH_VERT, SHADER_POINT_MESH_FRAG); | |
| 154 | 113 | |
| 155 | 114 | TextureSet textureSet = TextureSet::New(); |
| 156 | 115 | textureSet.SetTexture(0u, texture0); | ... | ... |
examples/point-mesh/shaders/point-mesh.frag
0 → 100644
| 1 | +varying mediump vec3 vVertexColor; | |
| 2 | +varying mediump float vHue; | |
| 3 | +uniform lowp vec4 uColor; | |
| 4 | +uniform sampler2D sTexture1; | |
| 5 | +uniform sampler2D sTexture2; | |
| 6 | +uniform lowp vec4 uFadeColor; | |
| 7 | + | |
| 8 | +void main() | |
| 9 | +{ | |
| 10 | + mediump vec4 texCol1 = texture2D(sTexture1, gl_PointCoord); | |
| 11 | + mediump vec4 texCol2 = texture2D(sTexture2, gl_PointCoord); | |
| 12 | + gl_FragColor = vec4(vVertexColor, 1.0) * ((texCol1 * vHue) + (texCol2 * (1.0 - vHue))); | |
| 13 | +} | ... | ... |
examples/point-mesh/shaders/point-mesh.vert
0 → 100644
| 1 | +attribute mediump vec2 aPosition; | |
| 2 | +attribute highp float aHue; | |
| 3 | +varying mediump vec2 vTexCoord; | |
| 4 | +uniform mediump mat4 uMvpMatrix; | |
| 5 | +uniform mediump vec3 uSize; | |
| 6 | +uniform mediump float uPointSize; | |
| 7 | +uniform lowp vec4 uFadeColor; | |
| 8 | +varying mediump vec3 vVertexColor; | |
| 9 | +varying mediump float vHue; | |
| 10 | + | |
| 11 | +vec3 hsv2rgb(vec3 c) | |
| 12 | +{ | |
| 13 | + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | |
| 14 | + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); | |
| 15 | + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); | |
| 16 | +} | |
| 17 | + | |
| 18 | +void main() | |
| 19 | +{ | |
| 20 | + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | |
| 21 | + vertexPosition.xyz *= (uSize - uPointSize); | |
| 22 | + vertexPosition = uMvpMatrix * vertexPosition; | |
| 23 | + vVertexColor = hsv2rgb(vec3(aHue, 0.7, 1.0)); | |
| 24 | + vHue = aHue; | |
| 25 | + gl_PointSize = uPointSize; | |
| 26 | + gl_Position = vertexPosition; | |
| 27 | +} | ... | ... |
examples/reflection-demo/reflection-example.cpp
| ... | ... | @@ -22,146 +22,17 @@ |
| 22 | 22 | #include <map> |
| 23 | 23 | |
| 24 | 24 | #include "gltf-scene.h" |
| 25 | +#include "generated/reflection-vert.h" | |
| 26 | +#include "generated/reflection-frag.h" | |
| 27 | +#include "generated/reflection-simple-frag.h" | |
| 28 | +#include "generated/reflection-textured-frag.h" | |
| 29 | +#include "generated/reflection-plasma-frag.h" | |
| 30 | +#include "generated/reflection-tex-frag.h" | |
| 25 | 31 | |
| 26 | 32 | using namespace Dali; |
| 27 | 33 | |
| 28 | 34 | namespace |
| 29 | 35 | { |
| 30 | -// clang-format off | |
| 31 | - | |
| 32 | -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( | |
| 33 | - attribute mediump vec3 aPosition;\n | |
| 34 | - attribute mediump vec3 aNormal;\n | |
| 35 | - attribute mediump vec2 aTexCoord;\n | |
| 36 | - uniform mediump mat4 uMvpMatrix;\n | |
| 37 | - uniform mediump mat3 uNormalMatrix;\n | |
| 38 | - uniform mediump vec3 uSize;\n | |
| 39 | - \n | |
| 40 | - varying mediump vec2 vTexCoord; \n | |
| 41 | - varying mediump vec3 vNormal; \n | |
| 42 | - varying mediump vec3 vPosition; \n | |
| 43 | - void main()\n | |
| 44 | -{\n | |
| 45 | - mediump vec4 vertexPosition = vec4(aPosition, 1.0);\n | |
| 46 | - vertexPosition.xyz *= uSize;\n | |
| 47 | - vTexCoord = aTexCoord;\n | |
| 48 | - vNormal = normalize(uNormalMatrix * aNormal);\n | |
| 49 | - vPosition = aPosition; \n | |
| 50 | - gl_Position = uMvpMatrix * vertexPosition;\n | |
| 51 | -}\n | |
| 52 | -); | |
| 53 | - | |
| 54 | -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 55 | - uniform lowp vec4 uColor;\n | |
| 56 | - uniform sampler2D sTexture; \n | |
| 57 | - varying mediump vec3 vNormal;\n | |
| 58 | - varying mediump vec3 vPosition; \n | |
| 59 | - varying mediump vec2 vTexCoord; \n | |
| 60 | - \n | |
| 61 | - void main()\n | |
| 62 | -{\n | |
| 63 | - gl_FragColor = texture2D(sTexture, vTexCoord) * 50.0;\n | |
| 64 | -}\n | |
| 65 | -); | |
| 66 | - | |
| 67 | -const char* FRAGMENT_SIMPLE_SHADER = DALI_COMPOSE_SHADER( | |
| 68 | - uniform lowp vec4 uColor;\n | |
| 69 | - uniform sampler2D sTexture; \n | |
| 70 | - varying mediump vec3 vNormal;\n | |
| 71 | - varying mediump vec3 vPosition; \n | |
| 72 | - varying mediump vec2 vTexCoord; \n | |
| 73 | - \n | |
| 74 | - void main()\n | |
| 75 | -{\n | |
| 76 | - gl_FragColor = texture2D(sTexture, vTexCoord) * 2.0;\n | |
| 77 | -}\n | |
| 78 | -); | |
| 79 | - | |
| 80 | -const char* TEXTURED_FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 81 | - uniform lowp vec4 uColor;\n | |
| 82 | - uniform sampler2D sTexture; \n | |
| 83 | - uniform mediump vec2 uScreenSize;\n | |
| 84 | - | |
| 85 | - uniform mediump vec3 eyePos;\n | |
| 86 | - uniform mediump vec3 lightDir;\n | |
| 87 | - | |
| 88 | - varying mediump vec3 vNormal;\n | |
| 89 | - varying mediump vec3 vPosition; \n | |
| 90 | - varying mediump vec2 vTexCoord; \n | |
| 91 | - \n | |
| 92 | - void main()\n | |
| 93 | -{\n | |
| 94 | - mediump vec3 n = normalize( vNormal );\n | |
| 95 | - mediump vec3 l = normalize( lightDir );\n | |
| 96 | - mediump vec3 e = normalize( eyePos );\n | |
| 97 | - mediump float intensity = max(dot(n,l), 0.0);\n | |
| 98 | - gl_FragColor = texture2D(sTexture, vTexCoord) * intensity;\n | |
| 99 | -}\n | |
| 100 | -); | |
| 101 | - | |
| 102 | -const char* PLASMA_FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 103 | - precision mediump float;\n | |
| 104 | - uniform sampler2D sTexture; \n | |
| 105 | - | |
| 106 | - uniform float uTime; | |
| 107 | - uniform float uKFactor; | |
| 108 | - uniform mediump vec3 eyePos;\n | |
| 109 | - uniform mediump vec3 lightDir;\n | |
| 110 | - varying mediump vec3 vNormal;\n | |
| 111 | - varying mediump vec3 vPosition; \n | |
| 112 | - varying mediump vec2 vTexCoord; \n | |
| 113 | - \n | |
| 114 | - void main()\n | |
| 115 | -{\n | |
| 116 | - mediump vec3 n = normalize( vNormal );\n | |
| 117 | - mediump vec3 l = normalize( lightDir );\n | |
| 118 | - mediump vec3 e = normalize( eyePos );\n | |
| 119 | - mediump float intensity = max(dot(n,l), 0.0);\n | |
| 120 | -\n | |
| 121 | - const mediump float PI = 3.1415926535897932384626433832795;\n | |
| 122 | - mediump float v = 0.0;\n | |
| 123 | - mediump vec2 c = vTexCoord * uKFactor - uKFactor/2.0;\n | |
| 124 | - v += sin((c.x+uTime));\n | |
| 125 | - v += sin((c.y+uTime)/2.0);\n | |
| 126 | - v += sin((c.x+c.y+uTime)/2.0);\n | |
| 127 | - c += uKFactor/2.0 * vec2(sin(uTime/3.0), cos(uTime/2.0));\n | |
| 128 | - v += sin(sqrt(c.x*c.x+c.y*c.y+1.0)+uTime);\n | |
| 129 | - v = v/2.0;\n | |
| 130 | - mediump vec3 col = vec3(1, sin(PI*v), cos(PI*v));\n | |
| 131 | - gl_FragColor = (texture2D(sTexture, vTexCoord)) * (((col.r+col.g+col.b)/3.0)+1.0+intensity);\n | |
| 132 | -}\n | |
| 133 | -); | |
| 134 | - | |
| 135 | -const char* TEX_FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 136 | - uniform lowp vec4 uColor;\n | |
| 137 | - uniform sampler2D sTexture0; \n | |
| 138 | - uniform sampler2D sTexture1; \n | |
| 139 | - uniform mediump vec3 eyePos;\n | |
| 140 | - uniform mediump vec3 lightDir;\n | |
| 141 | - uniform mediump vec2 uScreenSize;\n | |
| 142 | - varying mediump vec3 vNormal;\n | |
| 143 | - varying mediump vec3 vPosition; \n | |
| 144 | - varying mediump vec2 vTexCoord; \n | |
| 145 | - \n | |
| 146 | - | |
| 147 | - mediump float rand(mediump vec2 co){\n | |
| 148 | - return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);\n | |
| 149 | - }\n | |
| 150 | - \n | |
| 151 | - void main()\n | |
| 152 | -{\n | |
| 153 | - mediump vec2 tx = (gl_FragCoord.xy / uScreenSize.xy);\n | |
| 154 | - mediump vec3 n = normalize( vNormal );\n | |
| 155 | - mediump vec3 l = normalize( lightDir );\n | |
| 156 | - mediump vec3 e = normalize( eyePos );\n | |
| 157 | - mediump float factor = gl_FragCoord.y / uScreenSize.y;\n | |
| 158 | - mediump float intensity = max(dot(n,l), 0.0);\n | |
| 159 | - mediump vec2 uv = tx;\n | |
| 160 | - gl_FragColor = ((texture2D(sTexture0, vTexCoord) * factor ) + \n | |
| 161 | - (texture2D(sTexture1, uv))) * intensity;\n | |
| 162 | -}\n | |
| 163 | -); | |
| 164 | -// clang-format on | |
| 165 | 36 | |
| 166 | 37 | struct Model |
| 167 | 38 | { |
| ... | ... | @@ -335,11 +206,11 @@ void CreateModelsFromGLTF(glTF* gltf, ModelContainer& models) |
| 335 | 206 | // change shader to use texture if material indicates that |
| 336 | 207 | if(mesh->material != 0xffffffff && gltf->GetMaterials()[mesh->material].pbrMetallicRoughness.enabled) |
| 337 | 208 | { |
| 338 | - models.emplace_back(CreateModel(*gltf, mesh, VERTEX_SHADER, TEXTURED_FRAGMENT_SHADER)); | |
| 209 | + models.emplace_back(CreateModel(*gltf, mesh, SHADER_REFLECTION_VERT.data(), SHADER_REFLECTION_TEXTURED_FRAG.data())); | |
| 339 | 210 | } |
| 340 | 211 | else |
| 341 | 212 | { |
| 342 | - models.emplace_back(CreateModel(*gltf, mesh, VERTEX_SHADER, FRAGMENT_SHADER)); | |
| 213 | + models.emplace_back(CreateModel(*gltf, mesh, SHADER_REFLECTION_VERT.data(), SHADER_REFLECTION_FRAG.data())); | |
| 343 | 214 | } |
| 344 | 215 | } |
| 345 | 216 | } |
| ... | ... | @@ -500,13 +371,13 @@ private: |
| 500 | 371 | auto planeActor = mLayer3D.FindChildByName("Plane"); |
| 501 | 372 | auto solarActor = mLayer3D.FindChildByName("solar_root"); |
| 502 | 373 | auto backgroundActor = mLayer3D.FindChildByName("background"); |
| 503 | - ReplaceShader(backgroundActor, VERTEX_SHADER, FRAGMENT_SIMPLE_SHADER); | |
| 374 | + ReplaceShader(backgroundActor, SHADER_REFLECTION_VERT.data(), SHADER_REFLECTION_SIMPLE_FRAG.data()); | |
| 504 | 375 | mCenterActor = mLayer3D.FindChildByName("center"); |
| 505 | 376 | mCenterHorizActor = mLayer3D.FindChildByName("center2"); |
| 506 | 377 | |
| 507 | 378 | // Prepare Sun |
| 508 | 379 | auto sun = mLayer3D.FindChildByName("sun"); |
| 509 | - ReplaceShader(sun, VERTEX_SHADER, PLASMA_FRAGMENT_SHADER); | |
| 380 | + ReplaceShader(sun, SHADER_REFLECTION_VERT.data(), SHADER_REFLECTION_PLASMA_FRAG.data()); | |
| 510 | 381 | mSunTimeUniformIndex = sun.RegisterProperty("uTime", 0.0f); |
| 511 | 382 | mSunKFactorUniformIndex = sun.RegisterProperty("uKFactor", 0.0f); |
| 512 | 383 | |
| ... | ... | @@ -515,7 +386,7 @@ private: |
| 515 | 386 | |
| 516 | 387 | // Milkyway |
| 517 | 388 | auto milkyway = mLayer3D.FindChildByName("milkyway"); |
| 518 | - ReplaceShader(milkyway, VERTEX_SHADER, FRAGMENT_SHADER); | |
| 389 | + ReplaceShader(milkyway, SHADER_REFLECTION_VERT.data(), SHADER_REFLECTION_FRAG.data()); | |
| 519 | 390 | |
| 520 | 391 | auto renderTaskSourceActor = mLayer3D.FindChildByName("RenderTaskSource"); |
| 521 | 392 | |
| ... | ... | @@ -544,7 +415,7 @@ private: |
| 544 | 415 | /** |
| 545 | 416 | * Change shader to textured |
| 546 | 417 | */ |
| 547 | - Shader texShader = CreateShader(VERTEX_SHADER, TEX_FRAGMENT_SHADER); | |
| 418 | + Shader texShader = CreateShader(SHADER_REFLECTION_VERT.data(), SHADER_REFLECTION_TEX_FRAG.data()); | |
| 548 | 419 | planeActor.RegisterProperty("uScreenSize", Vector2(windowWidth, windowHeight)); |
| 549 | 420 | auto renderer = planeActor.GetRendererAt(0); |
| 550 | 421 | auto textureSet = renderer.GetTextures(); | ... | ... |
examples/reflection-demo/shaders/reflection-plasma.frag
0 → 100644
| 1 | +precision mediump float; | |
| 2 | +uniform sampler2D sTexture; | |
| 3 | + | |
| 4 | +uniform float uTime; | |
| 5 | +uniform float uKFactor; | |
| 6 | +uniform mediump vec3 eyePos; | |
| 7 | +uniform mediump vec3 lightDir; | |
| 8 | +varying mediump vec3 vNormal; | |
| 9 | +varying mediump vec3 vPosition; | |
| 10 | +varying mediump vec2 vTexCoord; | |
| 11 | + | |
| 12 | +void main() | |
| 13 | +{ | |
| 14 | + mediump vec3 n = normalize( vNormal ); | |
| 15 | + mediump vec3 l = normalize( lightDir ); | |
| 16 | + mediump vec3 e = normalize( eyePos ); | |
| 17 | + mediump float intensity = max(dot(n,l), 0.0); | |
| 18 | + | |
| 19 | + const mediump float PI = 3.1415926535897932384626433832795; | |
| 20 | + mediump float v = 0.0; | |
| 21 | + mediump vec2 c = vTexCoord * uKFactor - uKFactor/2.0; | |
| 22 | + v += sin((c.x+uTime)); | |
| 23 | + v += sin((c.y+uTime)/2.0); | |
| 24 | + v += sin((c.x+c.y+uTime)/2.0); | |
| 25 | + c += uKFactor/2.0 * vec2(sin(uTime/3.0), cos(uTime/2.0)); | |
| 26 | + v += sin(sqrt(c.x*c.x+c.y*c.y+1.0)+uTime); | |
| 27 | + v = v/2.0; | |
| 28 | + mediump vec3 col = vec3(1, sin(PI*v), cos(PI*v)); | |
| 29 | + gl_FragColor = (texture2D(sTexture, vTexCoord)) * (((col.r+col.g+col.b)/3.0)+1.0+intensity); | |
| 30 | +} | ... | ... |
examples/reflection-demo/shaders/reflection-simple.frag
0 → 100644
examples/reflection-demo/shaders/reflection-tex.frag
0 → 100644
| 1 | +uniform lowp vec4 uColor; | |
| 2 | +uniform sampler2D sTexture0; | |
| 3 | +uniform sampler2D sTexture1; | |
| 4 | +uniform mediump vec3 eyePos; | |
| 5 | +uniform mediump vec3 lightDir; | |
| 6 | +uniform mediump vec2 uScreenSize; | |
| 7 | +varying mediump vec3 vNormal; | |
| 8 | +varying mediump vec3 vPosition; | |
| 9 | +varying mediump vec2 vTexCoord; | |
| 10 | + | |
| 11 | +mediump float rand(mediump vec2 co) | |
| 12 | +{ | |
| 13 | + return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); | |
| 14 | +} | |
| 15 | + | |
| 16 | +void main() | |
| 17 | +{ | |
| 18 | + mediump vec2 tx = (gl_FragCoord.xy / uScreenSize.xy); | |
| 19 | + mediump vec3 n = normalize( vNormal ); | |
| 20 | + mediump vec3 l = normalize( lightDir ); | |
| 21 | + mediump vec3 e = normalize( eyePos ); | |
| 22 | + mediump float factor = gl_FragCoord.y / uScreenSize.y; | |
| 23 | + mediump float intensity = max(dot(n,l), 0.0); | |
| 24 | + mediump vec2 uv = tx; | |
| 25 | + gl_FragColor = ((texture2D(sTexture0, vTexCoord) * factor ) + | |
| 26 | + (texture2D(sTexture1, uv))) * intensity; | |
| 27 | +} | ... | ... |
examples/reflection-demo/shaders/reflection-textured.frag
0 → 100644
| 1 | +uniform lowp vec4 uColor; | |
| 2 | +uniform sampler2D sTexture; | |
| 3 | +uniform mediump vec2 uScreenSize; | |
| 4 | + | |
| 5 | +uniform mediump vec3 eyePos; | |
| 6 | +uniform mediump vec3 lightDir; | |
| 7 | + | |
| 8 | +varying mediump vec3 vNormal; | |
| 9 | +varying mediump vec3 vPosition; | |
| 10 | +varying mediump vec2 vTexCoord; | |
| 11 | + | |
| 12 | +void main() | |
| 13 | +{ | |
| 14 | + mediump vec3 n = normalize( vNormal ); | |
| 15 | + mediump vec3 l = normalize( lightDir ); | |
| 16 | + mediump vec3 e = normalize( eyePos ); | |
| 17 | + mediump float intensity = max(dot(n,l), 0.0); | |
| 18 | + gl_FragColor = texture2D(sTexture, vTexCoord) * intensity; | |
| 19 | +} | ... | ... |
examples/reflection-demo/shaders/reflection.frag
0 → 100644
examples/reflection-demo/shaders/reflection.vert
0 → 100644
| 1 | +attribute mediump vec3 aPosition; | |
| 2 | +attribute mediump vec3 aNormal; | |
| 3 | +attribute mediump vec2 aTexCoord; | |
| 4 | +uniform mediump mat4 uMvpMatrix; | |
| 5 | +uniform mediump mat3 uNormalMatrix; | |
| 6 | +uniform mediump vec3 uSize; | |
| 7 | + | |
| 8 | +varying mediump vec2 vTexCoord; | |
| 9 | +varying mediump vec3 vNormal; | |
| 10 | +varying mediump vec3 vPosition; | |
| 11 | + | |
| 12 | +void main() | |
| 13 | +{ | |
| 14 | + mediump vec4 vertexPosition = vec4(aPosition, 1.0); | |
| 15 | + vertexPosition.xyz *= uSize; | |
| 16 | + vTexCoord = aTexCoord; | |
| 17 | + vNormal = normalize(uNormalMatrix * aNormal); | |
| 18 | + vPosition = aPosition; | |
| 19 | + gl_Position = uMvpMatrix * vertexPosition; | |
| 20 | +} | |
| 0 | 21 | \ No newline at end of file | ... | ... |
examples/refraction-effect/refraction-effect-example.cpp
| ... | ... | @@ -28,6 +28,10 @@ |
| 28 | 28 | // INTERNAL INCLUDES |
| 29 | 29 | #include "shared/utility.h" |
| 30 | 30 | #include "shared/view.h" |
| 31 | +#include "generated/refraction-effect-flat-vert.h" | |
| 32 | +#include "generated/refraction-effect-flat-frag.h" | |
| 33 | +#include "generated/refraction-effect-refraction-vert.h" | |
| 34 | +#include "generated/refraction-effect-refraction-frag.h" | |
| 31 | 35 | |
| 32 | 36 | using namespace Dali; |
| 33 | 37 | |
| ... | ... | @@ -94,117 +98,6 @@ struct Vertex |
| 94 | 98 | } |
| 95 | 99 | }; |
| 96 | 100 | |
| 97 | -/************************************************************************************************ | |
| 98 | - *** The shader source is used when the MeshActor is not touched*** | |
| 99 | - ************************************************************************************************/ | |
| 100 | -// clang-format off | |
| 101 | -const char* VERTEX_SHADER_FLAT = DALI_COMPOSE_SHADER( | |
| 102 | -attribute mediump vec3 aPosition;\n | |
| 103 | -attribute mediump vec3 aNormal;\n | |
| 104 | -attribute highp vec2 aTexCoord;\n | |
| 105 | -uniform mediump mat4 uMvpMatrix;\n | |
| 106 | -varying mediump vec2 vTexCoord;\n | |
| 107 | -void main()\n | |
| 108 | -{\n | |
| 109 | - gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n | |
| 110 | - vTexCoord = aTexCoord.xy;\n | |
| 111 | -}\n | |
| 112 | -); | |
| 113 | - | |
| 114 | -const char* FRAGMENT_SHADER_FLAT = DALI_COMPOSE_SHADER( | |
| 115 | -uniform lowp vec4 uColor;\n | |
| 116 | -uniform sampler2D sTexture;\n | |
| 117 | -varying mediump vec2 vTexCoord;\n | |
| 118 | -void main()\n | |
| 119 | -{\n | |
| 120 | - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n | |
| 121 | -}\n | |
| 122 | -); | |
| 123 | - | |
| 124 | -/************************************************************ | |
| 125 | - ** Custom refraction effect shader*************************** | |
| 126 | - ************************************************************/ | |
| 127 | -const char* VERTEX_SHADER_REFRACTION = DALI_COMPOSE_SHADER( | |
| 128 | -attribute mediump vec3 aPosition;\n | |
| 129 | -attribute mediump vec3 aNormal;\n | |
| 130 | -attribute highp vec2 aTexCoord;\n | |
| 131 | -uniform mediump mat4 uMvpMatrix;\n | |
| 132 | -varying mediump vec4 vVertex;\n | |
| 133 | -varying mediump vec3 vNormal;\n | |
| 134 | -varying mediump vec2 vTexCoord;\n | |
| 135 | -varying mediump vec2 vTextureOffset;\n | |
| 136 | -void main()\n | |
| 137 | -{\n | |
| 138 | - gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n | |
| 139 | - vTexCoord = aTexCoord.xy;\n | |
| 140 | - | |
| 141 | - vNormal = aNormal;\n | |
| 142 | - vVertex = vec4( aPosition, 1.0 );\n | |
| 143 | - float length = max(0.01, length(aNormal.xy)) * 40.0;\n | |
| 144 | - vTextureOffset = aNormal.xy / length;\n | |
| 145 | -}\n | |
| 146 | -); | |
| 147 | - | |
| 148 | -const char* FRAGMENT_SHADER_REFRACTION = DALI_COMPOSE_SHADER( | |
| 149 | -precision mediump float;\n | |
| 150 | -uniform mediump float uEffectStrength;\n | |
| 151 | -uniform mediump vec3 uLightPosition;\n | |
| 152 | -uniform mediump vec2 uLightXYOffset;\n | |
| 153 | -uniform mediump vec2 uLightSpinOffset;\n | |
| 154 | -uniform mediump float uLightIntensity;\n | |
| 155 | -uniform lowp vec4 uColor;\n | |
| 156 | -uniform sampler2D sTexture;\n | |
| 157 | -varying mediump vec4 vVertex;\n | |
| 158 | -varying mediump vec3 vNormal;\n | |
| 159 | -varying mediump vec2 vTexCoord;\n | |
| 160 | -varying mediump vec2 vTextureOffset;\n | |
| 161 | - | |
| 162 | -vec3 rgb2hsl(vec3 rgb)\n | |
| 163 | -{\n | |
| 164 | - float epsilon = 1.0e-10;\n | |
| 165 | - vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n | |
| 166 | - vec4 P = mix(vec4(rgb.bg, K.wz), vec4(rgb.gb, K.xy), step(rgb.b, rgb.g));\n | |
| 167 | - vec4 Q = mix(vec4(P.xyw, rgb.r), vec4(rgb.r, P.yzx), step(P.x, rgb.r));\n | |
| 168 | - \n | |
| 169 | - // RGB -> HCV | |
| 170 | - float value = Q.x;\n | |
| 171 | - float chroma = Q.x - min(Q.w, Q.y);\n | |
| 172 | - float hue = abs(Q.z + (Q.w-Q.y) / (6.0*chroma+epsilon));\n | |
| 173 | - // HCV -> HSL | |
| 174 | - float lightness = value - chroma*0.5;\n | |
| 175 | - return vec3( hue, chroma/max( 1.0-abs(lightness*2.0-1.0), 1.0e-1 ), lightness );\n | |
| 176 | -}\n | |
| 177 | - | |
| 178 | -vec3 hsl2rgb( vec3 hsl )\n | |
| 179 | -{\n | |
| 180 | - // pure hue->RGB | |
| 181 | - vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n | |
| 182 | - vec3 p = abs(fract(hsl.xxx + K.xyz) * 6.0 - K.www);\n | |
| 183 | - vec3 RGB = clamp(p - K.xxx, 0.0, 1.0);\n | |
| 184 | - \n | |
| 185 | - float chroma = ( 1.0 - abs( hsl.z*2.0-1.0 ) ) * hsl.y;\n | |
| 186 | - return ( RGB - 0.5 ) * chroma + hsl.z;\n | |
| 187 | -}\n | |
| 188 | - | |
| 189 | -void main()\n | |
| 190 | -{\n | |
| 191 | - vec3 normal = normalize( vNormal);\n | |
| 192 | - | |
| 193 | - vec3 lightPosition = uLightPosition + vec3(uLightXYOffset+uLightSpinOffset, 0.0);\n | |
| 194 | - mediump vec3 vecToLight = normalize( (lightPosition - vVertex.xyz) * 0.01 );\n | |
| 195 | - mediump float spotEffect = pow( max(0.05, vecToLight.z ) - 0.05, 8.0);\n | |
| 196 | - | |
| 197 | - spotEffect = spotEffect * uEffectStrength;\n | |
| 198 | - mediump float lightDiffuse = ( ( dot( vecToLight, normal )-0.75 ) *uLightIntensity ) * spotEffect;\n | |
| 199 | - | |
| 200 | - lowp vec4 color = texture2D( sTexture, vTexCoord + vTextureOffset * spotEffect );\n | |
| 201 | - vec3 lightedColor = hsl2rgb( rgb2hsl(color.rgb) + vec3(0.0,0.0,lightDiffuse) );\n | |
| 202 | - | |
| 203 | - gl_FragColor = vec4( lightedColor, color.a ) * uColor;\n | |
| 204 | -}\n | |
| 205 | -); | |
| 206 | -// clang-format on | |
| 207 | - | |
| 208 | 101 | } // namespace |
| 209 | 102 | |
| 210 | 103 | /*************************************************/ |
| ... | ... | @@ -281,7 +174,7 @@ private: |
| 281 | 174 | DemoHelper::DEFAULT_MODE_SWITCH_PADDING); |
| 282 | 175 | |
| 283 | 176 | // shader used when the screen is not touched, render a flat surface |
| 284 | - mShaderFlat = Shader::New(VERTEX_SHADER_FLAT, FRAGMENT_SHADER_FLAT); | |
| 177 | + mShaderFlat = Shader::New(SHADER_REFRACTION_EFFECT_FLAT_VERT, SHADER_REFRACTION_EFFECT_FLAT_FRAG); | |
| 285 | 178 | mGeometry = CreateGeometry(MESH_FILES[mCurrentMeshId]); |
| 286 | 179 | |
| 287 | 180 | Texture texture = DemoHelper::LoadWindowFillingTexture(window.GetSize(), TEXTURE_IMAGES[mCurrentTextureId]); |
| ... | ... | @@ -301,7 +194,7 @@ private: |
| 301 | 194 | mContent.TouchedSignal().Connect(this, &RefractionEffectExample::OnTouch); |
| 302 | 195 | |
| 303 | 196 | // shader used when the finger is touching the screen. render refraction effect |
| 304 | - mShaderRefraction = Shader::New(VERTEX_SHADER_REFRACTION, FRAGMENT_SHADER_REFRACTION); | |
| 197 | + mShaderRefraction = Shader::New(SHADER_REFRACTION_EFFECT_REFRACTION_VERT, SHADER_REFRACTION_EFFECT_REFRACTION_FRAG); | |
| 305 | 198 | |
| 306 | 199 | // register uniforms |
| 307 | 200 | mLightXYOffsetIndex = mMeshActor.RegisterProperty("uLightXYOffset", Vector2::ZERO); | ... | ... |
examples/refraction-effect/shaders/refraction-effect-flat.frag
0 → 100644
examples/refraction-effect/shaders/refraction-effect-flat.vert
0 → 100644
| 1 | +// The shader source is used when the MeshActor is not touched | |
| 2 | + | |
| 3 | +attribute mediump vec3 aPosition; | |
| 4 | +attribute mediump vec3 aNormal; | |
| 5 | +attribute highp vec2 aTexCoord; | |
| 6 | +uniform mediump mat4 uMvpMatrix; | |
| 7 | +varying mediump vec2 vTexCoord; | |
| 8 | + | |
| 9 | +void main() | |
| 10 | +{ | |
| 11 | + gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 ); | |
| 12 | + vTexCoord = aTexCoord.xy; | |
| 13 | +} | ... | ... |
examples/refraction-effect/shaders/refraction-effect-refraction.frag
0 → 100644
| 1 | +precision mediump float; | |
| 2 | +uniform mediump float uEffectStrength; | |
| 3 | +uniform mediump vec3 uLightPosition; | |
| 4 | +uniform mediump vec2 uLightXYOffset; | |
| 5 | +uniform mediump vec2 uLightSpinOffset; | |
| 6 | +uniform mediump float uLightIntensity; | |
| 7 | +uniform lowp vec4 uColor; | |
| 8 | +uniform sampler2D sTexture; | |
| 9 | +varying mediump vec4 vVertex; | |
| 10 | +varying mediump vec3 vNormal; | |
| 11 | +varying mediump vec2 vTexCoord; | |
| 12 | +varying mediump vec2 vTextureOffset; | |
| 13 | + | |
| 14 | +vec3 rgb2hsl(vec3 rgb) | |
| 15 | +{ | |
| 16 | + float epsilon = 1.0e-10; | |
| 17 | + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); | |
| 18 | + vec4 P = mix(vec4(rgb.bg, K.wz), vec4(rgb.gb, K.xy), step(rgb.b, rgb.g)); | |
| 19 | + vec4 Q = mix(vec4(P.xyw, rgb.r), vec4(rgb.r, P.yzx), step(P.x, rgb.r)); | |
| 20 | + | |
| 21 | + // RGB -> HCV | |
| 22 | + float value = Q.x; | |
| 23 | + float chroma = Q.x - min(Q.w, Q.y); | |
| 24 | + float hue = abs(Q.z + (Q.w-Q.y) / (6.0*chroma+epsilon)); | |
| 25 | + // HCV -> HSL | |
| 26 | + float lightness = value - chroma*0.5; | |
| 27 | + return vec3( hue, chroma/max( 1.0-abs(lightness*2.0-1.0), 1.0e-1 ), lightness ); | |
| 28 | +} | |
| 29 | + | |
| 30 | +vec3 hsl2rgb( vec3 hsl ) | |
| 31 | +{ | |
| 32 | + // pure hue->RGB | |
| 33 | + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | |
| 34 | + vec3 p = abs(fract(hsl.xxx + K.xyz) * 6.0 - K.www); | |
| 35 | + vec3 RGB = clamp(p - K.xxx, 0.0, 1.0); | |
| 36 | + | |
| 37 | + float chroma = ( 1.0 - abs( hsl.z*2.0-1.0 ) ) * hsl.y; | |
| 38 | + return ( RGB - 0.5 ) * chroma + hsl.z; | |
| 39 | +} | |
| 40 | + | |
| 41 | +void main() | |
| 42 | +{ | |
| 43 | + vec3 normal = normalize( vNormal); | |
| 44 | + | |
| 45 | + vec3 lightPosition = uLightPosition + vec3(uLightXYOffset+uLightSpinOffset, 0.0); | |
| 46 | + mediump vec3 vecToLight = normalize( (lightPosition - vVertex.xyz) * 0.01 ); | |
| 47 | + mediump float spotEffect = pow( max(0.05, vecToLight.z ) - 0.05, 8.0); | |
| 48 | + | |
| 49 | + spotEffect = spotEffect * uEffectStrength; | |
| 50 | + mediump float lightDiffuse = ( ( dot( vecToLight, normal )-0.75 ) *uLightIntensity ) * spotEffect; | |
| 51 | + | |
| 52 | + lowp vec4 color = texture2D( sTexture, vTexCoord + vTextureOffset * spotEffect ); | |
| 53 | + vec3 lightedColor = hsl2rgb( rgb2hsl(color.rgb) + vec3(0.0,0.0,lightDiffuse) ); | |
| 54 | + | |
| 55 | + gl_FragColor = vec4( lightedColor, color.a ) * uColor; | |
| 56 | +} | ... | ... |
examples/refraction-effect/shaders/refraction-effect-refraction.vert
0 → 100644
| 1 | +attribute mediump vec3 aPosition; | |
| 2 | +attribute mediump vec3 aNormal; | |
| 3 | +attribute highp vec2 aTexCoord; | |
| 4 | +uniform mediump mat4 uMvpMatrix; | |
| 5 | +varying mediump vec4 vVertex; | |
| 6 | +varying mediump vec3 vNormal; | |
| 7 | +varying mediump vec2 vTexCoord; | |
| 8 | +varying mediump vec2 vTextureOffset; | |
| 9 | + | |
| 10 | +void main() | |
| 11 | +{ | |
| 12 | + gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 ); | |
| 13 | + vTexCoord = aTexCoord.xy; | |
| 14 | + | |
| 15 | + vNormal = aNormal; | |
| 16 | + vVertex = vec4( aPosition, 1.0 ); | |
| 17 | + float length = max(0.01, length(aNormal.xy)) * 40.0; | |
| 18 | + vTextureOffset = aNormal.xy / length; | |
| 19 | +} | ... | ... |
examples/renderer-stencil/renderer-stencil-example.cpp
| ... | ... | @@ -16,12 +16,16 @@ |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | // EXTERNAL INCLUDES |
| 19 | +#include <dali/public-api/rendering/shader.h> | |
| 19 | 20 | #include <dali-toolkit/dali-toolkit.h> |
| 20 | 21 | |
| 21 | 22 | // INTERNAL INCLUDES |
| 22 | -#include "renderer-stencil-shaders.h" | |
| 23 | 23 | #include "shared/utility.h" |
| 24 | 24 | #include "shared/view.h" |
| 25 | +#include "generated/render-stencil-vert.h" | |
| 26 | +#include "generated/render-stencil-frag.h" | |
| 27 | +#include "generated/render-stencil-textured-vert.h" | |
| 28 | +#include "generated/render-stencil-textured-frag.h" | |
| 25 | 29 | |
| 26 | 30 | using namespace Dali; |
| 27 | 31 | |
| ... | ... | @@ -57,6 +61,14 @@ const Vector4 REFLECTION_COLOR(0.6f, 0.6f, 0.6f, 0.6f); ///< Note that alpha is |
| 57 | 61 | // We need to control the draw order as we are controlling both the stencil and depth buffer per renderer. |
| 58 | 62 | const int DEPTH_INDEX_GRANULARITY(10000); ///< This value is the gap in depth-index in-between each renderer. |
| 59 | 63 | |
| 64 | +// Shader uniforms: | |
| 65 | +const char* const COLOR_UNIFORM_NAME("uColor"); | |
| 66 | +const char* const OBJECT_DIMENSIONS_UNIFORM_NAME("uObjectDimensions"); | |
| 67 | +const char* const LIGHT_POSITION_UNIFORM_NAME = "uLightPosition"; | |
| 68 | +const char* const POSITION("aPosition"); | |
| 69 | +const char* const NORMAL("aNormal"); | |
| 70 | +const char* const TEXTURE("aTexCoord"); | |
| 71 | + | |
| 60 | 72 | } // Anonymous namespace |
| 61 | 73 | |
| 62 | 74 | /** |
| ... | ... | @@ -477,11 +489,11 @@ private: |
| 477 | 489 | |
| 478 | 490 | if(textured) |
| 479 | 491 | { |
| 480 | - shader = Shader::New(VERTEX_SHADER_TEXTURED, FRAGMENT_SHADER_TEXTURED); | |
| 492 | + shader = Shader::New(SHADER_RENDER_STENCIL_TEXTURED_VERT, SHADER_RENDER_STENCIL_TEXTURED_FRAG); | |
| 481 | 493 | } |
| 482 | 494 | else |
| 483 | 495 | { |
| 484 | - shader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); | |
| 496 | + shader = Shader::New(SHADER_RENDER_STENCIL_VERT, SHADER_RENDER_STENCIL_FRAG); | |
| 485 | 497 | } |
| 486 | 498 | |
| 487 | 499 | // Here we modify the light position based on half the window size as a pre-calculation step. | ... | ... |
examples/renderer-stencil/renderer-stencil-shaders.h deleted
| 1 | -#ifndef DALI_DEMO_RENDERER_STENCIL_SHADERS_H | |
| 2 | -#define DALI_DEMO_RENDERER_STENCIL_SHADERS_H | |
| 3 | - | |
| 4 | -/* | |
| 5 | - * Copyright (c) 2020 Samsung Electronics Co., Ltd. | |
| 6 | - * | |
| 7 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 | - * you may not use this file except in compliance with the License. | |
| 9 | - * You may obtain a copy of the License at | |
| 10 | - * | |
| 11 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
| 12 | - * | |
| 13 | - * Unless required by applicable law or agreed to in writing, software | |
| 14 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
| 15 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 16 | - * See the License for the specific language governing permissions and | |
| 17 | - * limitations under the License. | |
| 18 | - */ | |
| 19 | - | |
| 20 | -// EXTERNAL INCLUDES | |
| 21 | -#include <dali/public-api/rendering/shader.h> | |
| 22 | - | |
| 23 | -// Shader uniforms: | |
| 24 | -const char* const COLOR_UNIFORM_NAME("uColor"); | |
| 25 | -const char* const OBJECT_DIMENSIONS_UNIFORM_NAME("uObjectDimensions"); | |
| 26 | -const char* const LIGHT_POSITION_UNIFORM_NAME = "uLightPosition"; | |
| 27 | -const char* const POSITION("aPosition"); | |
| 28 | -const char* const NORMAL("aNormal"); | |
| 29 | -const char* const TEXTURE("aTexCoord"); | |
| 30 | - | |
| 31 | -// clang-format off | |
| 32 | - | |
| 33 | -// Shader for basic, per-vertex lighting (vertex): | |
| 34 | -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( | |
| 35 | - attribute mediump vec3 aPosition; | |
| 36 | - attribute highp vec3 aNormal; | |
| 37 | - attribute highp vec2 aTexCoord; | |
| 38 | - | |
| 39 | - varying mediump vec2 vTexCoord; | |
| 40 | - uniform mediump mat4 uMvpMatrix; | |
| 41 | - uniform mediump vec3 uSize; | |
| 42 | - uniform mediump vec3 uObjectDimensions; | |
| 43 | - varying mediump vec3 vIllumination; | |
| 44 | - uniform mediump mat4 uModelView; | |
| 45 | - uniform mediump mat4 uViewMatrix; | |
| 46 | - uniform mediump mat3 uNormalMatrix; | |
| 47 | - uniform mediump vec3 uLightPosition; | |
| 48 | - | |
| 49 | - void main() | |
| 50 | - { | |
| 51 | - mediump vec4 vertexPosition = vec4( aPosition * uObjectDimensions, 1.0 ); | |
| 52 | - vertexPosition = uMvpMatrix * vertexPosition; | |
| 53 | - | |
| 54 | - vec4 mvVertexPosition = uModelView * vertexPosition; | |
| 55 | - | |
| 56 | - vec3 vectorToLight = normalize( mat3( uViewMatrix ) * uLightPosition - mvVertexPosition.xyz ); | |
| 57 | - | |
| 58 | - vec3 normal = uNormalMatrix * aNormal; | |
| 59 | - float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 ); | |
| 60 | - vIllumination = vec3( lightDiffuse * 0.5 + 0.5 ); | |
| 61 | - | |
| 62 | - gl_Position = vertexPosition; | |
| 63 | - } | |
| 64 | -); | |
| 65 | - | |
| 66 | -// Fragment shader. | |
| 67 | -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 68 | - varying mediump vec2 vTexCoord; | |
| 69 | - varying mediump vec3 vIllumination; | |
| 70 | - uniform lowp vec4 uColor; | |
| 71 | - uniform sampler2D sTexture; | |
| 72 | - | |
| 73 | - void main() | |
| 74 | - { | |
| 75 | - gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a ); | |
| 76 | - } | |
| 77 | -); | |
| 78 | - | |
| 79 | -// Shader for basic, per-vertex lighting with texture (vertex): | |
| 80 | -const char* VERTEX_SHADER_TEXTURED = DALI_COMPOSE_SHADER( | |
| 81 | - attribute mediump vec3 aPosition; | |
| 82 | - attribute highp vec3 aNormal; | |
| 83 | - attribute highp vec2 aTexCoord; | |
| 84 | - | |
| 85 | - varying mediump vec2 vTexCoord; | |
| 86 | - uniform mediump mat4 uMvpMatrix; | |
| 87 | - uniform mediump vec3 uSize; | |
| 88 | - uniform mediump vec3 uObjectDimensions; | |
| 89 | - varying mediump vec3 vIllumination; | |
| 90 | - uniform mediump mat4 uModelView; | |
| 91 | - uniform mediump mat4 uViewMatrix; | |
| 92 | - uniform mediump mat3 uNormalMatrix; | |
| 93 | - uniform mediump vec3 uLightPosition; | |
| 94 | - | |
| 95 | - void main() | |
| 96 | - { | |
| 97 | - mediump vec4 vertexPosition = vec4( aPosition * uObjectDimensions, 1.0 ); | |
| 98 | - vertexPosition = uMvpMatrix * vertexPosition; | |
| 99 | - | |
| 100 | - vec4 mvVertexPosition = uModelView * vertexPosition; | |
| 101 | - | |
| 102 | - vec3 vectorToLight = normalize( mat3( uViewMatrix ) * uLightPosition - mvVertexPosition.xyz ); | |
| 103 | - | |
| 104 | - vec3 normal = uNormalMatrix * aNormal; | |
| 105 | - float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 ); | |
| 106 | - vIllumination = vec3( lightDiffuse * 0.5 + 0.5 ); | |
| 107 | - | |
| 108 | - vTexCoord = aTexCoord; | |
| 109 | - gl_Position = vertexPosition; | |
| 110 | - } | |
| 111 | -); | |
| 112 | - | |
| 113 | -// Fragment shader. | |
| 114 | -const char* FRAGMENT_SHADER_TEXTURED = DALI_COMPOSE_SHADER( | |
| 115 | - varying mediump vec2 vTexCoord; | |
| 116 | - varying mediump vec3 vIllumination; | |
| 117 | - uniform lowp vec4 uColor; | |
| 118 | - uniform sampler2D sTexture; | |
| 119 | - | |
| 120 | - void main() | |
| 121 | - { | |
| 122 | - gl_FragColor = vec4( texture2D( sTexture, vTexCoord ).rgb * vIllumination.rgb * uColor.rgb, uColor.a ); | |
| 123 | - } | |
| 124 | -); | |
| 125 | - | |
| 126 | -// clang-format on | |
| 127 | - | |
| 128 | -#endif // DALI_DEMO_RENDERER_STENCIL_SHADERS_H |
examples/renderer-stencil/shaders/render-stencil-textured.frag
0 → 100644
examples/renderer-stencil/shaders/render-stencil-textured.vert
0 → 100644
| 1 | +// Shader for basic, per-vertex lighting with texture (vertex): | |
| 2 | + | |
| 3 | +attribute mediump vec3 aPosition; | |
| 4 | +attribute highp vec3 aNormal; | |
| 5 | +attribute highp vec2 aTexCoord; | |
| 6 | + | |
| 7 | +varying mediump vec2 vTexCoord; | |
| 8 | +uniform mediump mat4 uMvpMatrix; | |
| 9 | +uniform mediump vec3 uSize; | |
| 10 | +uniform mediump vec3 uObjectDimensions; | |
| 11 | +varying mediump vec3 vIllumination; | |
| 12 | +uniform mediump mat4 uModelView; | |
| 13 | +uniform mediump mat4 uViewMatrix; | |
| 14 | +uniform mediump mat3 uNormalMatrix; | |
| 15 | +uniform mediump vec3 uLightPosition; | |
| 16 | + | |
| 17 | +void main() | |
| 18 | +{ | |
| 19 | + mediump vec4 vertexPosition = vec4( aPosition * uObjectDimensions, 1.0 ); | |
| 20 | + vertexPosition = uMvpMatrix * vertexPosition; | |
| 21 | + | |
| 22 | + vec4 mvVertexPosition = uModelView * vertexPosition; | |
| 23 | + | |
| 24 | + vec3 vectorToLight = normalize( mat3( uViewMatrix ) * uLightPosition - mvVertexPosition.xyz ); | |
| 25 | + | |
| 26 | + vec3 normal = uNormalMatrix * aNormal; | |
| 27 | + float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 ); | |
| 28 | + vIllumination = vec3( lightDiffuse * 0.5 + 0.5 ); | |
| 29 | + | |
| 30 | + vTexCoord = aTexCoord; | |
| 31 | + gl_Position = vertexPosition; | |
| 32 | +} | ... | ... |
examples/renderer-stencil/shaders/render-stencil.frag
0 → 100644
examples/renderer-stencil/shaders/render-stencil.vert
0 → 100644
| 1 | +// Shader for basic, per-vertex lighting (vertex): | |
| 2 | + | |
| 3 | +attribute mediump vec3 aPosition; | |
| 4 | +attribute highp vec3 aNormal; | |
| 5 | +attribute highp vec2 aTexCoord; | |
| 6 | + | |
| 7 | +varying mediump vec2 vTexCoord; | |
| 8 | +uniform mediump mat4 uMvpMatrix; | |
| 9 | +uniform mediump vec3 uSize; | |
| 10 | +uniform mediump vec3 uObjectDimensions; | |
| 11 | +varying mediump vec3 vIllumination; | |
| 12 | +uniform mediump mat4 uModelView; | |
| 13 | +uniform mediump mat4 uViewMatrix; | |
| 14 | +uniform mediump mat3 uNormalMatrix; | |
| 15 | +uniform mediump vec3 uLightPosition; | |
| 16 | + | |
| 17 | +void main() | |
| 18 | +{ | |
| 19 | + mediump vec4 vertexPosition = vec4( aPosition * uObjectDimensions, 1.0 ); | |
| 20 | + vertexPosition = uMvpMatrix * vertexPosition; | |
| 21 | + | |
| 22 | + vec4 mvVertexPosition = uModelView * vertexPosition; | |
| 23 | + | |
| 24 | + vec3 vectorToLight = normalize( mat3( uViewMatrix ) * uLightPosition - mvVertexPosition.xyz ); | |
| 25 | + | |
| 26 | + vec3 normal = uNormalMatrix * aNormal; | |
| 27 | + float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 ); | |
| 28 | + vIllumination = vec3( lightDiffuse * 0.5 + 0.5 ); | |
| 29 | + | |
| 30 | + gl_Position = vertexPosition; | |
| 31 | +} | ... | ... |
examples/rendering-basic-light/rendering-basic-light-example.cpp
| ... | ... | @@ -18,6 +18,9 @@ |
| 18 | 18 | #include <dali-toolkit/dali-toolkit.h> |
| 19 | 19 | #include <dali/dali.h> |
| 20 | 20 | |
| 21 | +#include "generated/rendering-basic-light-vert.h" | |
| 22 | +#include "generated/rendering-basic-light-frag.h" | |
| 23 | + | |
| 21 | 24 | using namespace Dali; |
| 22 | 25 | using namespace Toolkit; |
| 23 | 26 | |
| ... | ... | @@ -66,75 +69,6 @@ Material material[] = |
| 66 | 69 | |
| 67 | 70 | int MaterialID = 0; |
| 68 | 71 | |
| 69 | -// clang-format off | |
| 70 | - | |
| 71 | -/* | |
| 72 | - * Vertex shader | |
| 73 | - */ | |
| 74 | -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( | |
| 75 | -attribute mediump vec3 aPosition;\n // DALi shader builtin | |
| 76 | -attribute mediump vec3 aNormal;\n // DALi shader builtin | |
| 77 | -uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 78 | -uniform mediump vec3 uSize;\n // DALi shader builtin | |
| 79 | -uniform mediump mat4 uModelView;\n // DALi shader builtin | |
| 80 | -uniform mediump mat3 uNormalMatrix;\n // DALi shader builtin | |
| 81 | -\n | |
| 82 | -varying mediump vec3 vNormal;\n | |
| 83 | -varying mediump vec3 vFragPos;\n | |
| 84 | -\n | |
| 85 | -void main()\n | |
| 86 | -{\n | |
| 87 | - mediump vec4 vertexPosition = vec4(aPosition, 1.0);\n | |
| 88 | - vertexPosition.xyz *= uSize;\n | |
| 89 | - vFragPos = vec3(uModelView * vertexPosition);\n | |
| 90 | - vNormal = uNormalMatrix * aNormal;\n | |
| 91 | - \n | |
| 92 | - gl_Position = uMvpMatrix * vertexPosition;\n | |
| 93 | -}\n | |
| 94 | -); | |
| 95 | - | |
| 96 | -/* | |
| 97 | - * Fragment shader | |
| 98 | - */ | |
| 99 | -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 100 | -varying mediump vec3 vNormal;\n | |
| 101 | -varying mediump vec3 vFragPos;\n | |
| 102 | -uniform mediump vec3 viewPos;\n // custom uniform | |
| 103 | -\n | |
| 104 | -struct Material {\n | |
| 105 | - mediump vec3 ambient;\n | |
| 106 | - mediump vec3 diffuse;\n | |
| 107 | - mediump vec3 specular;\n | |
| 108 | - mediump float shininess;\n | |
| 109 | -};\n | |
| 110 | -struct Light {\n | |
| 111 | - mediump vec3 position;\n | |
| 112 | - mediump vec3 color;\n | |
| 113 | -};\n | |
| 114 | -uniform Material material;\n // custom uniform | |
| 115 | -uniform Light light;\n // custom uniform | |
| 116 | -\n | |
| 117 | -void main()\n | |
| 118 | -{\n | |
| 119 | -\n // Ambient | |
| 120 | - mediump vec3 ambient = material.ambient * light.color;\n | |
| 121 | -\n // Diffuse | |
| 122 | - mediump vec3 norm = normalize(vNormal);\n | |
| 123 | - mediump vec3 lightDir = normalize(light.position - vFragPos);\n | |
| 124 | - mediump float diff = max(dot(norm, lightDir), 0.0);\n | |
| 125 | - mediump vec3 diffuse = material.diffuse * diff * light.color;\n | |
| 126 | - \n | |
| 127 | -\n // Specular | |
| 128 | - mediump vec3 viewDir = normalize(viewPos - vFragPos);\n | |
| 129 | - mediump vec3 reflectDir = reflect(-lightDir, norm); \n | |
| 130 | - mediump float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);\n | |
| 131 | - mediump vec3 specular = material.specular * spec * light.color; \n | |
| 132 | - mediump vec3 result = (ambient + diffuse + specular);\n | |
| 133 | - gl_FragColor = vec4(result, 1.0);\n | |
| 134 | -}\n | |
| 135 | -); | |
| 136 | -// clang-format on | |
| 137 | - | |
| 138 | 72 | } // namespace |
| 139 | 73 | |
| 140 | 74 | // This example shows per-pixel lighting of materials with different ambient, diffuse, specular and shininess parameters |
| ... | ... | @@ -323,14 +257,14 @@ public: |
| 323 | 257 | } |
| 324 | 258 | |
| 325 | 259 | /** |
| 326 | - * Creates a shader using inlined variable VERTEX_SHADER and FRAGMENT_SHADER | |
| 260 | + * Creates a shader using inlined variable SHADER_RENDERING_BASIC_LIGHT_VERT and SHADER_RENDERING_BASIC_LIGHT_FRAG | |
| 327 | 261 | * |
| 328 | 262 | * Shaders are very basic and all they do is transforming vertices and interpolating |
| 329 | 263 | * input per-vertex color. |
| 330 | 264 | */ |
| 331 | 265 | void CreateCubeShader() |
| 332 | 266 | { |
| 333 | - mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); | |
| 267 | + mShader = Shader::New(SHADER_RENDERING_BASIC_LIGHT_VERT, SHADER_RENDERING_BASIC_LIGHT_FRAG); | |
| 334 | 268 | |
| 335 | 269 | float scale = 120.0f; |
| 336 | 270 | mShader.RegisterProperty("light.position", Vector3(1.2 * scale, scale, 2.0 * scale)); | ... | ... |
examples/rendering-basic-light/shaders/rendering-basic-light.frag
0 → 100644
| 1 | +varying mediump vec3 vNormal; | |
| 2 | +varying mediump vec3 vFragPos; | |
| 3 | +uniform mediump vec3 viewPos; // custom uniform | |
| 4 | + | |
| 5 | +struct Material | |
| 6 | +{ | |
| 7 | + mediump vec3 ambient; | |
| 8 | + mediump vec3 diffuse; | |
| 9 | + mediump vec3 specular; | |
| 10 | + mediump float shininess; | |
| 11 | +}; | |
| 12 | + | |
| 13 | +struct Light | |
| 14 | +{ | |
| 15 | + mediump vec3 position; | |
| 16 | + mediump vec3 color; | |
| 17 | +}; | |
| 18 | + | |
| 19 | +uniform Material material; // custom uniform | |
| 20 | +uniform Light light; // custom uniform | |
| 21 | + | |
| 22 | +void main() | |
| 23 | +{ | |
| 24 | + // Ambient | |
| 25 | + mediump vec3 ambient = material.ambient * light.color; | |
| 26 | + // Diffuse | |
| 27 | + mediump vec3 norm = normalize(vNormal); | |
| 28 | + mediump vec3 lightDir = normalize(light.position - vFragPos); | |
| 29 | + mediump float diff = max(dot(norm, lightDir), 0.0); | |
| 30 | + mediump vec3 diffuse = material.diffuse * diff * light.color; | |
| 31 | + | |
| 32 | + // Specular | |
| 33 | + mediump vec3 viewDir = normalize(viewPos - vFragPos); | |
| 34 | + mediump vec3 reflectDir = reflect(-lightDir, norm); | |
| 35 | + mediump float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess); | |
| 36 | + mediump vec3 specular = material.specular * spec * light.color; | |
| 37 | + mediump vec3 result = (ambient + diffuse + specular); | |
| 38 | + gl_FragColor = vec4(result, 1.0); | |
| 39 | +} | ... | ... |
examples/rendering-basic-light/shaders/rendering-basic-light.vert
0 → 100644
| 1 | +attribute mediump vec3 aPosition; // DALi shader builtin | |
| 2 | +attribute mediump vec3 aNormal; // DALi shader builtin | |
| 3 | +uniform mediump mat4 uMvpMatrix; // DALi shader builtin | |
| 4 | +uniform mediump vec3 uSize; // DALi shader builtin | |
| 5 | +uniform mediump mat4 uModelView; // DALi shader builtin | |
| 6 | +uniform mediump mat3 uNormalMatrix; // DALi shader builtin | |
| 7 | + | |
| 8 | +varying mediump vec3 vNormal; | |
| 9 | +varying mediump vec3 vFragPos; | |
| 10 | + | |
| 11 | +void main() | |
| 12 | +{ | |
| 13 | + mediump vec4 vertexPosition = vec4(aPosition, 1.0); | |
| 14 | + vertexPosition.xyz *= uSize; | |
| 15 | + vFragPos = vec3(uModelView * vertexPosition); | |
| 16 | + vNormal = uNormalMatrix * aNormal; | |
| 17 | + | |
| 18 | + gl_Position = uMvpMatrix * vertexPosition; | |
| 19 | +} | ... | ... |
examples/rendering-basic-pbr/model-skybox.cpp
| ... | ... | @@ -25,47 +25,8 @@ |
| 25 | 25 | |
| 26 | 26 | // INTERNAL INCLUDES |
| 27 | 27 | #include "obj-loader.h" |
| 28 | - | |
| 29 | -namespace | |
| 30 | -{ | |
| 31 | -// clang-format off | |
| 32 | - | |
| 33 | -/* | |
| 34 | - * Vertex shader for a skybox | |
| 35 | - */ | |
| 36 | -const char* VERTEX_SHADER_SKYBOX = DALI_COMPOSE_SHADER( | |
| 37 | -attribute mediump vec3 aPosition;\n // DALi shader builtin | |
| 38 | -uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 39 | -\n | |
| 40 | -varying mediump vec3 vTexCoord;\n | |
| 41 | -void main()\n | |
| 42 | -{\n | |
| 43 | - vTexCoord = aPosition;\n | |
| 44 | - | |
| 45 | - mediump vec4 vertexPosition = vec4(aPosition, 1.0);\n | |
| 46 | - vec4 clipSpacePosition = uMvpMatrix * vertexPosition;\n | |
| 47 | - gl_Position = clipSpacePosition.xyww;\n // Writes 1.0, the maximum depth value, into the depth buffer. | |
| 48 | - // This is an optimization to avoid running the fragment shader | |
| 49 | - // for the pixels hidden by the scene's objects. | |
| 50 | -}\n | |
| 51 | -); | |
| 52 | - | |
| 53 | -/* | |
| 54 | - * Fragment shader for a skybox | |
| 55 | - */ | |
| 56 | -const char* FRAGMENT_SHADER_SKYBOX = DALI_COMPOSE_SHADER( | |
| 57 | -uniform samplerCube uSkyBoxTexture;\n | |
| 58 | -\n | |
| 59 | -varying mediump vec3 vTexCoord;\n | |
| 60 | -void main()\n | |
| 61 | -{\n | |
| 62 | - mediump vec4 texColor = textureCube( uSkyBoxTexture, vTexCoord, 0.0);\n | |
| 63 | - gl_FragColor = texColor;\n | |
| 64 | -}\n | |
| 65 | -); | |
| 66 | -// clang-format on | |
| 67 | - | |
| 68 | -} // namespace | |
| 28 | +#include "generated/skybox-vert.h" | |
| 29 | +#include "generated/skybox-frag.h" | |
| 69 | 30 | |
| 70 | 31 | ModelSkybox::ModelSkybox() |
| 71 | 32 | { |
| ... | ... | @@ -78,7 +39,7 @@ ModelSkybox::~ModelSkybox() |
| 78 | 39 | void ModelSkybox::Init(const Vector3& size) |
| 79 | 40 | { |
| 80 | 41 | Geometry geometry = CreateGeometry(); |
| 81 | - Shader shader = Shader::New(VERTEX_SHADER_SKYBOX, FRAGMENT_SHADER_SKYBOX); | |
| 42 | + Shader shader = Shader::New(SHADER_SKYBOX_VERT, SHADER_SKYBOX_FRAG); | |
| 82 | 43 | |
| 83 | 44 | Renderer renderer = Renderer::New(geometry, shader); |
| 84 | 45 | ... | ... |
examples/rendering-basic-pbr/shaders/skybox.frag
0 → 100644
examples/rendering-basic-pbr/shaders/skybox.vert
0 → 100644
| 1 | +attribute mediump vec3 aPosition; // DALi shader builtin | |
| 2 | +uniform mediump mat4 uMvpMatrix; // DALi shader builtin | |
| 3 | + | |
| 4 | +varying mediump vec3 vTexCoord; | |
| 5 | +void main() | |
| 6 | +{ | |
| 7 | + vTexCoord = aPosition; | |
| 8 | + | |
| 9 | + mediump vec4 vertexPosition = vec4(aPosition, 1.0); | |
| 10 | + vec4 clipSpacePosition = uMvpMatrix * vertexPosition; | |
| 11 | + gl_Position = clipSpacePosition.xyww; // Writes 1.0, the maximum depth value, into the depth buffer. | |
| 12 | + // This is an optimization to avoid running the fragment shader | |
| 13 | + // for the pixels hidden by the scene's objects. | |
| 14 | +} | ... | ... |
examples/rendering-cube/rendering-cube.cpp
| ... | ... | @@ -18,48 +18,12 @@ |
| 18 | 18 | #include <dali-toolkit/dali-toolkit.h> |
| 19 | 19 | #include <dali/dali.h> |
| 20 | 20 | |
| 21 | +#include "generated/rendering-cube-vert.h" | |
| 22 | +#include "generated/rendering-cube-frag.h" | |
| 23 | + | |
| 21 | 24 | using namespace Dali; |
| 22 | 25 | using namespace Toolkit; |
| 23 | 26 | |
| 24 | -namespace | |
| 25 | -{ | |
| 26 | -// clang-format off | |
| 27 | - | |
| 28 | -/* | |
| 29 | - * Vertex shader | |
| 30 | - */ | |
| 31 | -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( | |
| 32 | -attribute mediump vec3 aPosition;\n // DALi shader builtin | |
| 33 | -attribute mediump vec3 aColor;\n // DALi shader builtin | |
| 34 | -uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 35 | -uniform mediump vec3 uSize;\n // DALi shader builtin | |
| 36 | -\n | |
| 37 | -varying mediump vec4 vColor;\n | |
| 38 | -\n | |
| 39 | -void main()\n | |
| 40 | -{\n | |
| 41 | - mediump vec4 vertexPosition = vec4(aPosition, 1.0);\n | |
| 42 | - vertexPosition.xyz *= uSize;\n | |
| 43 | - vColor = vec4( aColor, 1.0 );\n | |
| 44 | - gl_Position = uMvpMatrix * vertexPosition;\n | |
| 45 | -}\n | |
| 46 | -); | |
| 47 | - | |
| 48 | -/* | |
| 49 | - * Fragment shader | |
| 50 | - */ | |
| 51 | -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 52 | -varying mediump vec4 vColor;\n | |
| 53 | -\n | |
| 54 | -void main()\n | |
| 55 | -{\n | |
| 56 | - gl_FragColor = vColor;\n | |
| 57 | -}\n | |
| 58 | -); | |
| 59 | -// clang-format on | |
| 60 | - | |
| 61 | -} // namespace | |
| 62 | - | |
| 63 | 27 | // This example shows how to create a cube with colors on each side |
| 64 | 28 | // |
| 65 | 29 | class DrawCubeController : public ConnectionTracker |
| ... | ... | @@ -204,14 +168,14 @@ public: |
| 204 | 168 | } |
| 205 | 169 | |
| 206 | 170 | /** |
| 207 | - * Creates a shader using inlined variable VERTEX_SHADER and FRAGMENT_SHADER | |
| 171 | + * Creates a shader using inlined variable SHADER_RENDERING_CUBE_VERT and SHADER_RENDERING_CUBE_FRAG | |
| 208 | 172 | * |
| 209 | 173 | * Shaders are very basic and all they do is transforming vertices and interpolating |
| 210 | 174 | * input per-vertex color. |
| 211 | 175 | */ |
| 212 | 176 | void CreateCubeShader() |
| 213 | 177 | { |
| 214 | - mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); | |
| 178 | + mShader = Shader::New(SHADER_RENDERING_CUBE_VERT, SHADER_RENDERING_CUBE_FRAG); | |
| 215 | 179 | } |
| 216 | 180 | |
| 217 | 181 | /** | ... | ... |
examples/rendering-cube/shaders/rendering-cube.frag
0 → 100644
examples/rendering-cube/shaders/rendering-cube.vert
0 → 100644
| 1 | +attribute mediump vec3 aPosition; // DALi shader builtin | |
| 2 | +attribute mediump vec3 aColor; // DALi shader builtin | |
| 3 | +uniform mediump mat4 uMvpMatrix; // DALi shader builtin | |
| 4 | +uniform mediump vec3 uSize; // DALi shader builtin | |
| 5 | + | |
| 6 | +varying mediump vec4 vColor; | |
| 7 | + | |
| 8 | +void main() | |
| 9 | +{ | |
| 10 | + mediump vec4 vertexPosition = vec4(aPosition, 1.0); | |
| 11 | + vertexPosition.xyz *= uSize; | |
| 12 | + vColor = vec4( aColor, 1.0 ); | |
| 13 | + gl_Position = uMvpMatrix * vertexPosition; | |
| 14 | +} | ... | ... |
examples/rendering-line/rendering-line.cpp
| ... | ... | @@ -18,44 +18,12 @@ |
| 18 | 18 | #include <dali-toolkit/dali-toolkit.h> |
| 19 | 19 | #include <dali/dali.h> |
| 20 | 20 | |
| 21 | +#include "generated/rendering-line-vert.h" | |
| 22 | +#include "generated/rendering-line-frag.h" | |
| 23 | + | |
| 21 | 24 | using namespace Dali; |
| 22 | 25 | using namespace Toolkit; |
| 23 | 26 | |
| 24 | -namespace | |
| 25 | -{ | |
| 26 | -// clang-format off | |
| 27 | - | |
| 28 | -/* | |
| 29 | - * Vertex shader | |
| 30 | - */ | |
| 31 | -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( | |
| 32 | -attribute mediump vec2 aPosition;\n // DALi shader builtin | |
| 33 | -uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 34 | -uniform mediump vec3 uSize;\n // DALi shader builtin | |
| 35 | -\n | |
| 36 | -void main()\n | |
| 37 | -{\n | |
| 38 | - mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n | |
| 39 | - vertexPosition.xyz *= uSize;\n | |
| 40 | - gl_Position = uMvpMatrix * vertexPosition;\n | |
| 41 | -}\n | |
| 42 | -); | |
| 43 | - | |
| 44 | -/* | |
| 45 | - * Fragment shader | |
| 46 | - */ | |
| 47 | -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 48 | -uniform mediump vec4 uColor;\n | |
| 49 | -\n | |
| 50 | -void main()\n | |
| 51 | -{\n | |
| 52 | - gl_FragColor = uColor;\n | |
| 53 | -}\n | |
| 54 | -); | |
| 55 | -// clang-format on | |
| 56 | - | |
| 57 | -} // namespace | |
| 58 | - | |
| 59 | 27 | // This example shows how to draw a line in actor's color |
| 60 | 28 | // |
| 61 | 29 | class DrawLineController : public ConnectionTracker |
| ... | ... | @@ -143,13 +111,13 @@ public: |
| 143 | 111 | } |
| 144 | 112 | |
| 145 | 113 | /** |
| 146 | - * Creates a shader using inlined variable VERTEX_SHADER and FRAGMENT_SHADER | |
| 114 | + * Creates a shader using inlined variable SHADER_RENDERING_LINE_VERT and SHADER_RENDERING_LINE_FRAG | |
| 147 | 115 | * |
| 148 | 116 | * Shaders are very basic and all they do is transforming vertices and applying actor's colour. |
| 149 | 117 | */ |
| 150 | 118 | void CreateLineShader() |
| 151 | 119 | { |
| 152 | - mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); | |
| 120 | + mShader = Shader::New(SHADER_RENDERING_LINE_VERT, SHADER_RENDERING_LINE_FRAG); | |
| 153 | 121 | } |
| 154 | 122 | |
| 155 | 123 | /** | ... | ... |
examples/rendering-line/shaders/rendering-line.frag
0 → 100644
examples/rendering-line/shaders/rendering-line.vert
0 → 100644
| 1 | +attribute mediump vec2 aPosition; // DALi shader builtin | |
| 2 | +uniform mediump mat4 uMvpMatrix; // DALi shader builtin | |
| 3 | +uniform mediump vec3 uSize; // DALi shader builtin | |
| 4 | + | |
| 5 | +void main() | |
| 6 | +{ | |
| 7 | + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | |
| 8 | + vertexPosition.xyz *= uSize; | |
| 9 | + gl_Position = uMvpMatrix * vertexPosition; | |
| 10 | +} | ... | ... |
examples/rendering-radial-progress/radial-progress.cpp
| ... | ... | @@ -18,6 +18,11 @@ |
| 18 | 18 | #include <dali-toolkit/dali-toolkit.h> |
| 19 | 19 | #include <dali/dali.h> |
| 20 | 20 | |
| 21 | +#include "generated/radial-progress-basic-vert.h" | |
| 22 | +#include "generated/radial-progress-basic-frag.h" | |
| 23 | +#include "generated/radial-progress-textured-vert.h" | |
| 24 | +#include "generated/radial-progress-textured-frag.h" | |
| 25 | + | |
| 21 | 26 | using namespace Dali; |
| 22 | 27 | |
| 23 | 28 | namespace // unnamed namespace |
| ... | ... | @@ -30,77 +35,6 @@ const int NUMBER_OF_SIDES(64); // number of sides of the polygon used as a |
| 30 | 35 | const float INITIAL_DELAY(2.0f); // initial delay before showing the circle |
| 31 | 36 | const float PROGRESS_DURATION(0.5f); // number of seconds to fully show the circle |
| 32 | 37 | |
| 33 | -// clang-format off | |
| 34 | - | |
| 35 | -/* | |
| 36 | - * Vertex shader for textured quad | |
| 37 | - */ | |
| 38 | -const char* VERTEX_SHADER_TEXTURED = DALI_COMPOSE_SHADER( | |
| 39 | -attribute mediump vec2 aPosition;\n | |
| 40 | -uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 41 | -uniform mediump vec3 uSize;\n // DALi shader builtin | |
| 42 | -\n | |
| 43 | -varying mediump vec2 vTexCoord;\n | |
| 44 | -void main()\n | |
| 45 | -{\n | |
| 46 | - mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n | |
| 47 | - vertexPosition.xyz *= uSize;\n | |
| 48 | - vTexCoord = vec2(1.0, 1.0)*(aPosition + vec2(0.5) );\n | |
| 49 | - gl_Position = uMvpMatrix * vertexPosition;\n | |
| 50 | -}\n | |
| 51 | -); | |
| 52 | - | |
| 53 | -/* | |
| 54 | - * Fragment shaderfor textured quad | |
| 55 | - */ | |
| 56 | -const char* FRAGMENT_SHADER_TEXTURED = DALI_COMPOSE_SHADER( | |
| 57 | -uniform sampler2D uTexture;\n | |
| 58 | -\n | |
| 59 | -varying mediump vec2 vTexCoord;\n | |
| 60 | -void main()\n | |
| 61 | -{\n | |
| 62 | - mediump vec4 texColor = texture2D( uTexture, vTexCoord );\n | |
| 63 | - gl_FragColor = texColor;\n | |
| 64 | -}\n | |
| 65 | -); | |
| 66 | - | |
| 67 | -/* | |
| 68 | - * Vertex shader for polygon | |
| 69 | - */ | |
| 70 | -const char* VERTEX_SHADER_BASIC = DALI_COMPOSE_SHADER( | |
| 71 | -attribute mediump vec3 aPosition;\n | |
| 72 | -uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 73 | -uniform mediump vec3 uSize;\n // DALi shader builtin | |
| 74 | -uniform mediump float uProgress;\n | |
| 75 | -\n | |
| 76 | -varying mediump vec2 vTexCoord;\n | |
| 77 | -void main()\n | |
| 78 | -{\n | |
| 79 | - mediump vec4 vertexPosition = vec4(aPosition.x, aPosition.y, 0.0, 1.0);\n | |
| 80 | -\n | |
| 81 | - float index = aPosition.z;\n | |
| 82 | - if( uProgress < index )\n | |
| 83 | - {\n | |
| 84 | - vertexPosition = vec4(0.0, 0.0, 0.0, 1.0);\n | |
| 85 | - }\n | |
| 86 | -\n | |
| 87 | - vertexPosition.xyz *= uSize;\n | |
| 88 | - gl_Position = uMvpMatrix * vertexPosition;\n | |
| 89 | -}\n | |
| 90 | -); | |
| 91 | - | |
| 92 | -/* | |
| 93 | - * Fragment shader for polygon | |
| 94 | - */ | |
| 95 | -const char* FRAGMENT_SHADER_BASIC = DALI_COMPOSE_SHADER( | |
| 96 | - | |
| 97 | -void main()\n | |
| 98 | -{\n | |
| 99 | - gl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 );\n | |
| 100 | -}\n | |
| 101 | -); | |
| 102 | -// clang-format on | |
| 103 | - | |
| 104 | 38 | } // unnamed namespace |
| 105 | 39 | |
| 106 | 40 | // This example shows how to render a radial progress indicator |
| ... | ... | @@ -195,7 +129,7 @@ public: |
| 195 | 129 | geometry.AddVertexBuffer(vertexBuffer); |
| 196 | 130 | geometry.SetType(Geometry::TRIANGLE_FAN); |
| 197 | 131 | |
| 198 | - Shader shader = Shader::New(VERTEX_SHADER_BASIC, FRAGMENT_SHADER_BASIC); | |
| 132 | + Shader shader = Shader::New(SHADER_RADIAL_PROGRESS_BASIC_VERT, SHADER_RADIAL_PROGRESS_BASIC_FRAG); | |
| 199 | 133 | Renderer renderer = Renderer::New(geometry, shader); |
| 200 | 134 | |
| 201 | 135 | // Setting stencil data. We don't want to render to the color buffer so |
| ... | ... | @@ -233,7 +167,7 @@ public: |
| 233 | 167 | { |
| 234 | 168 | // Create shader & geometry needed by Renderer |
| 235 | 169 | |
| 236 | - Shader shader = Shader::New(VERTEX_SHADER_TEXTURED, FRAGMENT_SHADER_TEXTURED); | |
| 170 | + Shader shader = Shader::New(SHADER_RADIAL_PROGRESS_TEXTURED_VERT, SHADER_RADIAL_PROGRESS_TEXTURED_FRAG); | |
| 237 | 171 | |
| 238 | 172 | Property::Map vertexFormat; |
| 239 | 173 | vertexFormat["aPosition"] = Property::VECTOR2; | ... | ... |
examples/rendering-radial-progress/shaders/radial-progress-basic.frag
0 → 100644
examples/rendering-radial-progress/shaders/radial-progress-basic.vert
0 → 100644
| 1 | +// Vertex shader for polygon | |
| 2 | + | |
| 3 | +attribute mediump vec3 aPosition; | |
| 4 | +uniform mediump mat4 uMvpMatrix; // DALi shader builtin | |
| 5 | +uniform mediump vec3 uSize; // DALi shader builtin | |
| 6 | +uniform mediump float uProgress; | |
| 7 | + | |
| 8 | +varying mediump vec2 vTexCoord; | |
| 9 | + | |
| 10 | +void main() | |
| 11 | +{ | |
| 12 | + mediump vec4 vertexPosition = vec4(aPosition.x, aPosition.y, 0.0, 1.0); | |
| 13 | + | |
| 14 | + float index = aPosition.z; | |
| 15 | + if( uProgress < index ) | |
| 16 | + { | |
| 17 | + vertexPosition = vec4(0.0, 0.0, 0.0, 1.0); | |
| 18 | + } | |
| 19 | + | |
| 20 | + vertexPosition.xyz *= uSize; | |
| 21 | + gl_Position = uMvpMatrix * vertexPosition; | |
| 22 | +} | ... | ... |
examples/rendering-radial-progress/shaders/radial-progress-textured.frag
0 → 100644
examples/rendering-radial-progress/shaders/radial-progress-textured.vert
0 → 100644
| 1 | +// Vertex shader for textured quad | |
| 2 | + | |
| 3 | +attribute mediump vec2 aPosition; | |
| 4 | +uniform mediump mat4 uMvpMatrix; // DALi shader builtin | |
| 5 | +uniform mediump vec3 uSize; // DALi shader builtin | |
| 6 | + | |
| 7 | +varying mediump vec2 vTexCoord; | |
| 8 | + | |
| 9 | +void main() | |
| 10 | +{ | |
| 11 | + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | |
| 12 | + vertexPosition.xyz *= uSize; | |
| 13 | + vTexCoord = vec2(1.0, 1.0)*(aPosition + vec2(0.5) ); | |
| 14 | + gl_Position = uMvpMatrix * vertexPosition; | |
| 15 | +} | ... | ... |
examples/rendering-skybox/rendering-skybox.cpp
| ... | ... | @@ -19,82 +19,16 @@ |
| 19 | 19 | #include <dali/dali.h> |
| 20 | 20 | |
| 21 | 21 | #include "look-camera.h" |
| 22 | +#include "generated/rendering-skybox-vert.h" | |
| 23 | +#include "generated/rendering-skybox-frag.h" | |
| 24 | +#include "generated/rendering-skybox-cube-vert.h" | |
| 25 | +#include "generated/rendering-skybox-cube-frag.h" | |
| 22 | 26 | |
| 23 | 27 | using namespace Dali; |
| 24 | 28 | using namespace Toolkit; |
| 25 | 29 | |
| 26 | 30 | namespace |
| 27 | 31 | { |
| 28 | -// clang-format off | |
| 29 | -/* | |
| 30 | - * Vertex shader for a textured cube | |
| 31 | - */ | |
| 32 | -const char* VERTEX_SHADER_CUBE = DALI_COMPOSE_SHADER( | |
| 33 | -attribute mediump vec3 aPosition;\n // DALi shader builtin | |
| 34 | -attribute mediump vec2 aTexCoord;\n // DALi shader builtin | |
| 35 | -uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 36 | -uniform mediump vec3 uSize;\n // DALi shader builtin | |
| 37 | -\n | |
| 38 | -varying mediump vec2 vTexCoord;\n | |
| 39 | -void main()\n | |
| 40 | -{\n | |
| 41 | - mediump vec4 vertexPosition = vec4(aPosition, 1.0);\n | |
| 42 | - vertexPosition.xyz *= uSize;\n | |
| 43 | - vTexCoord = aTexCoord;\n | |
| 44 | - gl_Position = uMvpMatrix * vertexPosition;\n | |
| 45 | -}\n | |
| 46 | -); | |
| 47 | - | |
| 48 | -/* | |
| 49 | - * Fragment shader for a textured cube | |
| 50 | - */ | |
| 51 | -const char* FRAGMENT_SHADER_CUBE = DALI_COMPOSE_SHADER( | |
| 52 | -uniform sampler2D uTexture;\n | |
| 53 | -\n | |
| 54 | -varying mediump vec2 vTexCoord;\n | |
| 55 | -void main()\n | |
| 56 | -{\n | |
| 57 | - mediump vec4 texColor = texture2D( uTexture, vTexCoord );\n | |
| 58 | - gl_FragColor = texColor;\n | |
| 59 | -}\n | |
| 60 | -); | |
| 61 | - | |
| 62 | -/* | |
| 63 | - * Vertex shader for a skybox | |
| 64 | - */ | |
| 65 | -const char* VERTEX_SHADER_SKYBOX = DALI_COMPOSE_SHADER( | |
| 66 | -attribute mediump vec3 aPosition;\n // DALi shader builtin | |
| 67 | -uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 68 | -\n | |
| 69 | -varying mediump vec3 vTexCoord;\n | |
| 70 | -void main()\n | |
| 71 | -{\n | |
| 72 | - vTexCoord.x = aPosition.x;\n | |
| 73 | - vTexCoord.y = -aPosition.y;\n // convert to GL coords | |
| 74 | - vTexCoord.z = aPosition.z;\n | |
| 75 | - | |
| 76 | - mediump vec4 vertexPosition = vec4(aPosition, 1.0);\n | |
| 77 | - vec4 clipSpacePosition = uMvpMatrix * vertexPosition;\n | |
| 78 | - gl_Position = clipSpacePosition.xyww;\n // Writes 1.0, the maximum depth value, into the depth buffer. | |
| 79 | - // This is an optimization to avoid running the fragment shader | |
| 80 | - // for the pixels hidden by the scene's objects. | |
| 81 | -}\n | |
| 82 | -); | |
| 83 | - | |
| 84 | -/* | |
| 85 | - * Fragment shader for a skybox | |
| 86 | - */ | |
| 87 | -const char* FRAGMENT_SHADER_SKYBOX = DALI_COMPOSE_SHADER( | |
| 88 | -uniform samplerCube uSkyBoxTexture;\n | |
| 89 | -\n | |
| 90 | -varying mediump vec3 vTexCoord;\n | |
| 91 | -void main()\n | |
| 92 | -{\n | |
| 93 | - mediump vec4 texColor = textureCube( uSkyBoxTexture, vTexCoord );\n | |
| 94 | - gl_FragColor = texColor;\n | |
| 95 | -}\n | |
| 96 | -); | |
| 97 | -// clang-format on | |
| 98 | 32 | |
| 99 | 33 | const float CAMERA_DEFAULT_FOV(60.0f); |
| 100 | 34 | const float CAMERA_DEFAULT_NEAR(0.1f); |
| ... | ... | @@ -215,8 +149,8 @@ public: |
| 215 | 149 | */ |
| 216 | 150 | void CreateShaders() |
| 217 | 151 | { |
| 218 | - mShaderCube = Shader::New(VERTEX_SHADER_CUBE, FRAGMENT_SHADER_CUBE); | |
| 219 | - mShaderSkybox = Shader::New(VERTEX_SHADER_SKYBOX, FRAGMENT_SHADER_SKYBOX); | |
| 152 | + mShaderCube = Shader::New(SHADER_RENDERING_SKYBOX_CUBE_VERT, SHADER_RENDERING_SKYBOX_CUBE_FRAG); | |
| 153 | + mShaderSkybox = Shader::New(SHADER_RENDERING_SKYBOX_CUBE_VERT, SHADER_RENDERING_SKYBOX_CUBE_FRAG); | |
| 220 | 154 | } |
| 221 | 155 | |
| 222 | 156 | /** | ... | ... |
examples/rendering-skybox/shaders/rendering-skybox-cube.frag
0 → 100644
examples/rendering-skybox/shaders/rendering-skybox-cube.vert
0 → 100644
| 1 | +// Vertex shader for a textured cube | |
| 2 | + | |
| 3 | +attribute mediump vec3 aPosition; // DALi shader builtin | |
| 4 | +attribute mediump vec2 aTexCoord; // DALi shader builtin | |
| 5 | +uniform mediump mat4 uMvpMatrix; // DALi shader builtin | |
| 6 | +uniform mediump vec3 uSize; // DALi shader builtin | |
| 7 | + | |
| 8 | +varying mediump vec2 vTexCoord; | |
| 9 | + | |
| 10 | +void main() | |
| 11 | +{ | |
| 12 | + mediump vec4 vertexPosition = vec4(aPosition, 1.0); | |
| 13 | + vertexPosition.xyz *= uSize; | |
| 14 | + vTexCoord = aTexCoord; | |
| 15 | + gl_Position = uMvpMatrix * vertexPosition; | |
| 16 | +} | ... | ... |
examples/rendering-skybox/shaders/rendering-skybox.frag
0 → 100644
examples/rendering-skybox/shaders/rendering-skybox.vert
0 → 100644
| 1 | +// Vertex shader for a skybox | |
| 2 | + | |
| 3 | +attribute mediump vec3 aPosition; // DALi shader builtin | |
| 4 | +uniform mediump mat4 uMvpMatrix; // DALi shader builtin | |
| 5 | + | |
| 6 | +varying mediump vec3 vTexCoord; | |
| 7 | + | |
| 8 | +void main() | |
| 9 | +{ | |
| 10 | + vTexCoord.x = aPosition.x; | |
| 11 | + vTexCoord.y = -aPosition.y; // convert to GL coords | |
| 12 | + vTexCoord.z = aPosition.z; | |
| 13 | + | |
| 14 | + mediump vec4 vertexPosition = vec4(aPosition, 1.0); | |
| 15 | + vec4 clipSpacePosition = uMvpMatrix * vertexPosition; | |
| 16 | + gl_Position = clipSpacePosition.xyww; // Writes 1.0, the maximum depth value, into the depth buffer. | |
| 17 | + // This is an optimization to avoid running the fragment shader | |
| 18 | + // for the pixels hidden by the scene's objects. | |
| 19 | +} | ... | ... |
examples/rendering-textured-cube/rendering-textured-cube.cpp
| ... | ... | @@ -18,46 +18,14 @@ |
| 18 | 18 | #include <dali-toolkit/dali-toolkit.h> |
| 19 | 19 | #include <dali/dali.h> |
| 20 | 20 | |
| 21 | +#include "generated/rendering-textured-cube-vert.h" | |
| 22 | +#include "generated/rendering-textured-cube-frag.h" | |
| 23 | + | |
| 21 | 24 | using namespace Dali; |
| 22 | 25 | using namespace Toolkit; |
| 23 | 26 | |
| 24 | 27 | namespace |
| 25 | 28 | { |
| 26 | -// clang-format off | |
| 27 | - | |
| 28 | -/* | |
| 29 | - * Vertex shader | |
| 30 | - */ | |
| 31 | -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( | |
| 32 | -attribute mediump vec3 aPosition;\n // DALi shader builtin | |
| 33 | -attribute mediump vec2 aTexCoord;\n // DALi shader builtin | |
| 34 | -uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 35 | -uniform mediump vec3 uSize;\n // DALi shader builtin | |
| 36 | -\n | |
| 37 | -varying mediump vec2 vTexCoord;\n | |
| 38 | -void main()\n | |
| 39 | -{\n | |
| 40 | - mediump vec4 vertexPosition = vec4(aPosition, 1.0);\n | |
| 41 | - vertexPosition.xyz *= uSize;\n | |
| 42 | - vTexCoord = aTexCoord;\n | |
| 43 | - gl_Position = uMvpMatrix * vertexPosition;\n | |
| 44 | -}\n | |
| 45 | -); | |
| 46 | - | |
| 47 | -/* | |
| 48 | - * Fragment shader | |
| 49 | - */ | |
| 50 | -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 51 | -uniform sampler2D uTexture;\n | |
| 52 | -\n | |
| 53 | -varying mediump vec2 vTexCoord;\n | |
| 54 | -void main()\n | |
| 55 | -{\n | |
| 56 | - mediump vec4 texColor = texture2D( uTexture, vTexCoord );\n | |
| 57 | - gl_FragColor = texColor;\n | |
| 58 | -}\n | |
| 59 | -); | |
| 60 | -// clang-format on | |
| 61 | 29 | |
| 62 | 30 | const char* TEXTURE_URL = DEMO_IMAGE_DIR "wood.png"; |
| 63 | 31 | |
| ... | ... | @@ -204,14 +172,14 @@ public: |
| 204 | 172 | } |
| 205 | 173 | |
| 206 | 174 | /** |
| 207 | - * Creates a shader using inlined variable VERTEX_SHADER and FRAGMENT_SHADER | |
| 175 | + * Creates a shader using SHADER_RENDERING_TEXTURED_CUBE_VERT and SHADER_RENDERING_TEXTURED_CUBE_FRAG | |
| 208 | 176 | * |
| 209 | 177 | * Shaders are very basic and all they do is transforming vertices and sampling |
| 210 | 178 | * a texture. |
| 211 | 179 | */ |
| 212 | 180 | void CreateCubeShader() |
| 213 | 181 | { |
| 214 | - mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); | |
| 182 | + mShader = Shader::New(SHADER_RENDERING_TEXTURED_CUBE_VERT, SHADER_RENDERING_TEXTURED_CUBE_FRAG); | |
| 215 | 183 | } |
| 216 | 184 | |
| 217 | 185 | /** | ... | ... |
examples/rendering-textured-cube/shaders/rendering-textured-cube.frag
0 → 100644
examples/rendering-textured-cube/shaders/rendering-textured-cube.vert
0 → 100644
| 1 | +attribute mediump vec3 aPosition; // DALi shader builtin | |
| 2 | +attribute mediump vec2 aTexCoord; // DALi shader builtin | |
| 3 | +uniform mediump mat4 uMvpMatrix; // DALi shader builtin | |
| 4 | +uniform mediump vec3 uSize; // DALi shader builtin | |
| 5 | + | |
| 6 | +varying mediump vec2 vTexCoord; | |
| 7 | + | |
| 8 | +void main() | |
| 9 | +{ | |
| 10 | + mediump vec4 vertexPosition = vec4(aPosition, 1.0); | |
| 11 | + vertexPosition.xyz *= uSize; | |
| 12 | + vTexCoord = aTexCoord; | |
| 13 | + gl_Position = uMvpMatrix * vertexPosition; | |
| 14 | +} | ... | ... |
examples/rendering-triangle/rendering-triangle.cpp
| ... | ... | @@ -18,44 +18,12 @@ |
| 18 | 18 | #include <dali-toolkit/dali-toolkit.h> |
| 19 | 19 | #include <dali/dali.h> |
| 20 | 20 | |
| 21 | +#include "generated/rendering-triangle-vert.h" | |
| 22 | +#include "generated/rendering-triangle-frag.h" | |
| 23 | + | |
| 21 | 24 | using namespace Dali; |
| 22 | 25 | using namespace Toolkit; |
| 23 | 26 | |
| 24 | -namespace | |
| 25 | -{ | |
| 26 | -// clang-format off | |
| 27 | - | |
| 28 | -/* | |
| 29 | - * Vertex shader | |
| 30 | - */ | |
| 31 | -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( | |
| 32 | -attribute mediump vec2 aPosition;\n // DALi shader builtin | |
| 33 | -uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 34 | -uniform mediump vec3 uSize;\n // DALi shader builtin | |
| 35 | -\n | |
| 36 | -void main()\n | |
| 37 | -{\n | |
| 38 | - mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n | |
| 39 | - vertexPosition.xyz *= uSize;\n | |
| 40 | - gl_Position = uMvpMatrix * vertexPosition;\n | |
| 41 | -}\n | |
| 42 | -); | |
| 43 | - | |
| 44 | -/* | |
| 45 | - * Fragment shader | |
| 46 | - */ | |
| 47 | -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 48 | -uniform mediump vec4 uColor;\n | |
| 49 | -\n | |
| 50 | -void main()\n | |
| 51 | -{\n | |
| 52 | - gl_FragColor = uColor;\n | |
| 53 | -}\n | |
| 54 | -); | |
| 55 | -// clang-format on | |
| 56 | - | |
| 57 | -} // namespace | |
| 58 | - | |
| 59 | 27 | // This example shows how to draw a triangle in actor's color |
| 60 | 28 | // |
| 61 | 29 | class DrawTriangleController : public ConnectionTracker |
| ... | ... | @@ -150,7 +118,7 @@ public: |
| 150 | 118 | */ |
| 151 | 119 | void CreateTriangleShader() |
| 152 | 120 | { |
| 153 | - mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); | |
| 121 | + mShader = Shader::New(SHADER_RENDERING_TRIANGLE_VERT, SHADER_RENDERING_TRIANGLE_FRAG); | |
| 154 | 122 | } |
| 155 | 123 | |
| 156 | 124 | /** | ... | ... |
examples/rendering-triangle/shaders/rendering-triangle.frag
0 → 100644
examples/rendering-triangle/shaders/rendering-triangle.vert
0 → 100644
| 1 | +attribute mediump vec2 aPosition; // DALi shader builtin | |
| 2 | +uniform mediump mat4 uMvpMatrix; // DALi shader builtin | |
| 3 | +uniform mediump vec3 uSize; // DALi shader builtin | |
| 4 | + | |
| 5 | +void main() | |
| 6 | +{ | |
| 7 | + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | |
| 8 | + vertexPosition.xyz *= uSize; | |
| 9 | + gl_Position = uMvpMatrix * vertexPosition; | |
| 10 | +} | ... | ... |
examples/simple-text-renderer/shaders/simple-text-renderer.frag
0 → 100644
examples/simple-text-renderer/shaders/simple-text-renderer.vert
0 → 100644
| 1 | +#version 300 es | |
| 2 | + | |
| 3 | +precision mediump float; | |
| 4 | + | |
| 5 | +in vec2 aPosition; | |
| 6 | +in vec2 aTexCoord; | |
| 7 | + | |
| 8 | +out vec2 vUV; | |
| 9 | + | |
| 10 | +uniform vec3 uSize; | |
| 11 | +uniform mat4 uMvpMatrix; | |
| 12 | + | |
| 13 | +void main() | |
| 14 | +{ | |
| 15 | + vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | |
| 16 | + vertexPosition.xyz *= uSize; | |
| 17 | + gl_Position = uMvpMatrix * vertexPosition; | |
| 18 | + | |
| 19 | + vUV = aTexCoord; | |
| 20 | +} | ... | ... |
examples/simple-text-renderer/simple-text-renderer-example.cpp
| ... | ... | @@ -26,6 +26,10 @@ |
| 26 | 26 | #include <dali/devel-api/adaptor-framework/image-loading.h> |
| 27 | 27 | #include <dali/devel-api/adaptor-framework/pixel-buffer.h> |
| 28 | 28 | |
| 29 | +// INTERNAL INCLUDES | |
| 30 | +#include "generated/simple-text-renderer-vert.h" | |
| 31 | +#include "generated/simple-text-renderer-frag.h" | |
| 32 | + | |
| 29 | 33 | using namespace std; |
| 30 | 34 | using namespace Dali; |
| 31 | 35 | using namespace Dali::Toolkit; |
| ... | ... | @@ -35,44 +39,6 @@ namespace |
| 35 | 39 | const std::string IMAGE1 = DEMO_IMAGE_DIR "application-icon-1.png"; |
| 36 | 40 | const std::string IMAGE2 = DEMO_IMAGE_DIR "application-icon-6.png"; |
| 37 | 41 | |
| 38 | -#define MAKE_SHADER(A) #A | |
| 39 | - | |
| 40 | -const std::string VERSION_3_ES = "#version 300 es\n"; | |
| 41 | - | |
| 42 | -const char* VERTEX_SHADER = MAKE_SHADER( | |
| 43 | - precision mediump float; | |
| 44 | - | |
| 45 | - in vec2 aPosition; | |
| 46 | - in vec2 aTexCoord; | |
| 47 | - | |
| 48 | - out vec2 vUV; | |
| 49 | - | |
| 50 | - uniform vec3 uSize; | |
| 51 | - uniform mat4 uMvpMatrix; | |
| 52 | - | |
| 53 | - void main() { | |
| 54 | - vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | |
| 55 | - vertexPosition.xyz *= uSize; | |
| 56 | - gl_Position = uMvpMatrix * vertexPosition; | |
| 57 | - | |
| 58 | - vUV = aTexCoord; | |
| 59 | - }); | |
| 60 | - | |
| 61 | -const char* FRAGMENT_SHADER = MAKE_SHADER( | |
| 62 | - precision mediump float; | |
| 63 | - | |
| 64 | - in vec2 vUV; | |
| 65 | - | |
| 66 | - out vec4 FragColor; | |
| 67 | - | |
| 68 | - uniform sampler2D sAlbedo; | |
| 69 | - uniform vec4 uColor; | |
| 70 | - | |
| 71 | - void main() { | |
| 72 | - vec4 color = texture(sAlbedo, vUV); | |
| 73 | - FragColor = vec4(color.rgb, uColor.a * color.a); | |
| 74 | - }); | |
| 75 | - | |
| 76 | 42 | Renderer CreateRenderer() |
| 77 | 43 | { |
| 78 | 44 | // Create the geometry. |
| ... | ... | @@ -100,7 +66,7 @@ Renderer CreateRenderer() |
| 100 | 66 | geometry.SetType(Geometry::TRIANGLE_STRIP); |
| 101 | 67 | |
| 102 | 68 | // Create the shader |
| 103 | - Shader shader = Shader::New(VERSION_3_ES + VERTEX_SHADER, VERSION_3_ES + FRAGMENT_SHADER); | |
| 69 | + Shader shader = Shader::New(SHADER_SIMPLE_TEXT_RENDERER_VERT, SHADER_SIMPLE_TEXT_RENDERER_FRAG); | |
| 104 | 70 | |
| 105 | 71 | // Create the renderer |
| 106 | 72 | ... | ... |
examples/sparkle/shaders/sparkle-effect.frag
0 → 100644
examples/sparkle/shaders/sparkle-effect.vert
0 → 100644
| 1 | +precision highp float; | |
| 2 | + | |
| 3 | +attribute vec2 aTexCoord; | |
| 4 | +uniform mat4 uMvpMatrix; | |
| 5 | +varying vec2 vTexCoord; | |
| 6 | + | |
| 7 | +attribute vec2 aParticlePath0; | |
| 8 | +attribute vec2 aParticlePath1; | |
| 9 | +attribute vec2 aParticlePath2; | |
| 10 | +attribute vec2 aParticlePath3; | |
| 11 | +attribute vec2 aParticlePath4; | |
| 12 | +attribute vec2 aParticlePath5; | |
| 13 | + | |
| 14 | +uniform float uPercentage; | |
| 15 | +uniform float uPercentageMarked; | |
| 16 | +uniform vec3 uParticleColors[NUM_COLOR]; | |
| 17 | +uniform float uOpacity[NUM_PARTICLE]; | |
| 18 | +uniform vec2 uTapIndices; | |
| 19 | +uniform float uTapOffset[MAXIMUM_ANIMATION_COUNT]; | |
| 20 | +uniform vec2 uTapPoint[MAXIMUM_ANIMATION_COUNT]; | |
| 21 | +uniform float uAcceleration; | |
| 22 | +uniform float uRadius; | |
| 23 | +uniform float uScale; | |
| 24 | +uniform float uBreak; | |
| 25 | + | |
| 26 | +varying lowp vec4 vColor; | |
| 27 | + | |
| 28 | +void main() | |
| 29 | +{ | |
| 30 | + // we store the particle index inside texCoord attribute | |
| 31 | + float idx = abs(aTexCoord.y)-1.0; | |
| 32 | + | |
| 33 | + // early out if the particle is invisible | |
| 34 | + if(uOpacity[int(idx)]<1e-5) | |
| 35 | + { | |
| 36 | + gl_Position = vec4(0.0); | |
| 37 | + vColor = vec4(0.0); | |
| 38 | + return; | |
| 39 | + } | |
| 40 | + | |
| 41 | + // As the movement along the b-curve has nonuniform speed with a uniform increasing parameter 'uPercentage' | |
| 42 | + // we give different particles the different 'percentage' to make them looks more random | |
| 43 | + float increment = idx / float(NUM_PARTICLE)*5.0; | |
| 44 | + float percentage = mod(uPercentage +uAcceleration+increment, 1.0); | |
| 45 | + | |
| 46 | + vec2 p0; vec2 p1; vec2 p2; vec2 p3; | |
| 47 | + // calculate the particle position by using the cubic b-curve equation | |
| 48 | + if(percentage<0.5) // particle on the first b-curve | |
| 49 | + { | |
| 50 | + p0 = aParticlePath0; | |
| 51 | + p1 = aParticlePath1; | |
| 52 | + p2 = aParticlePath2; | |
| 53 | + p3 = aParticlePath3; | |
| 54 | + } | |
| 55 | + else | |
| 56 | + { | |
| 57 | + p0 = aParticlePath3; | |
| 58 | + p1 = aParticlePath4; | |
| 59 | + p2 = aParticlePath5; | |
| 60 | + p3 = aParticlePath0; | |
| 61 | + } | |
| 62 | + float t = mod( percentage*2.0, 1.0); | |
| 63 | + vec2 position = (1.0-t)*(1.0-t)*(1.0-t)*p0 + 3.0*(1.0-t)*(1.0-t)*t*p1+3.0*(1.0-t)*t*t*p2 + t*t*t*p3; | |
| 64 | + | |
| 65 | + vec2 referencePoint = mix(p0,p3,0.5); | |
| 66 | + float maxAnimationCount = float(MAXIMUM_ANIMATION_COUNT); | |
| 67 | + | |
| 68 | + for( float i=uTapIndices.x; i<uTapIndices.y; i+=1.0 ) | |
| 69 | + { | |
| 70 | + int id = int( mod(i+0.5,maxAnimationCount ) ); | |
| 71 | + vec2 edgePoint = normalize(referencePoint-uTapPoint[id])*uRadius+vec2(uRadius); | |
| 72 | + position = mix( position, edgePoint, uTapOffset[id] ) ; | |
| 73 | + } | |
| 74 | + | |
| 75 | + position = mix( position, vec2( 250.0,250.0 ),uBreak*(1.0-uOpacity[int(idx)]) ) ; | |
| 76 | + | |
| 77 | + // vertex position on the mesh: (sign(aTexCoord.x), sign(aTexCoord.y))*PARTICLE_HALF_SIZE | |
| 78 | + gl_Position = uMvpMatrix * vec4( position.x+sign(aTexCoord.x)*PARTICLE_HALF_SIZE/uScale, | |
| 79 | + position.y+sign(aTexCoord.y)*PARTICLE_HALF_SIZE/uScale, | |
| 80 | + 0.0, 1.0 ); | |
| 81 | + | |
| 82 | + // we store the color index inside texCoord attribute | |
| 83 | + float colorIndex = abs(aTexCoord.x); | |
| 84 | + vColor.rgb = uParticleColors[int(colorIndex)-1]; | |
| 85 | + vColor.a = fract(colorIndex) * uOpacity[int(idx)]; | |
| 86 | + | |
| 87 | + // produce a 'seemingly' random fade in/out | |
| 88 | + percentage = mod(uPercentage+increment+0.15, 1.0); | |
| 89 | + float ramdomOpacity = (min(percentage, 0.25)-0.15+0.9-max(percentage,0.9))*10.0; | |
| 90 | + vColor.a *=ramdomOpacity; | |
| 91 | + | |
| 92 | + vTexCoord = clamp(aTexCoord, 0.0, 1.0); | |
| 93 | +} | ... | ... |
examples/sparkle/sparkle-effect.h
| ... | ... | @@ -21,6 +21,9 @@ |
| 21 | 21 | #include <dali-toolkit/dali-toolkit.h> |
| 22 | 22 | #include <dali/dali.h> |
| 23 | 23 | |
| 24 | +#include "generated/sparkle-effect-vert.h" | |
| 25 | +#include "generated/sparkle-effect-frag.h" | |
| 26 | + | |
| 24 | 27 | using namespace Dali; |
| 25 | 28 | using Dali::Toolkit::ImageView; |
| 26 | 29 | |
| ... | ... | @@ -230,126 +233,14 @@ struct Vertex |
| 230 | 233 | */ |
| 231 | 234 | Shader New() |
| 232 | 235 | { |
| 233 | - // clang-format off | |
| 234 | - std::string vertexShader = DALI_COMPOSE_SHADER( | |
| 235 | - precision highp float;\n | |
| 236 | - \n | |
| 237 | - attribute vec2 aTexCoord;\n | |
| 238 | - uniform mat4 uMvpMatrix;\n | |
| 239 | - varying vec2 vTexCoord;\n | |
| 240 | - \n | |
| 241 | - attribute vec2 aParticlePath0;\n | |
| 242 | - attribute vec2 aParticlePath1;\n | |
| 243 | - attribute vec2 aParticlePath2;\n | |
| 244 | - attribute vec2 aParticlePath3;\n | |
| 245 | - attribute vec2 aParticlePath4;\n | |
| 246 | - attribute vec2 aParticlePath5;\n | |
| 247 | - \n | |
| 248 | - uniform float uPercentage;\n | |
| 249 | - uniform float uPercentageMarked;\n | |
| 250 | - uniform vec3 uParticleColors[NUM_COLOR];\n | |
| 251 | - uniform float uOpacity[NUM_PARTICLE];\n | |
| 252 | - uniform vec2 uTapIndices; | |
| 253 | - uniform float uTapOffset[MAXIMUM_ANIMATION_COUNT];\n | |
| 254 | - uniform vec2 uTapPoint[MAXIMUM_ANIMATION_COUNT];\n | |
| 255 | - uniform float uAcceleration;\n | |
| 256 | - uniform float uRadius;\n | |
| 257 | - uniform float uScale;\n | |
| 258 | - uniform float uBreak;\n | |
| 259 | - \n | |
| 260 | - varying lowp vec4 vColor;\n | |
| 261 | - \n | |
| 262 | - void main()\n | |
| 263 | - {\n | |
| 264 | - // we store the particle index inside texCoord attribute | |
| 265 | - float idx = abs(aTexCoord.y)-1.0;\n | |
| 266 | - \n | |
| 267 | - // early out if the particle is invisible | |
| 268 | - if(uOpacity[int(idx)]<1e-5)\n | |
| 269 | - {\n | |
| 270 | - gl_Position = vec4(0.0);\n | |
| 271 | - vColor = vec4(0.0);\n | |
| 272 | - return;\n | |
| 273 | - }\n | |
| 274 | - \n | |
| 275 | - // As the movement along the b-curve has nonuniform speed with a uniform increasing parameter 'uPercentage' | |
| 276 | - // we give different particles the different 'percentage' to make them looks more random | |
| 277 | - float increment = idx / float(NUM_PARTICLE)*5.0; | |
| 278 | - float percentage = mod(uPercentage +uAcceleration+increment, 1.0); | |
| 279 | - \n | |
| 280 | - vec2 p0; vec2 p1; vec2 p2; vec2 p3; | |
| 281 | - // calculate the particle position by using the cubic b-curve equation | |
| 282 | - if(percentage<0.5)\n // particle on the first b-curve | |
| 283 | - {\n | |
| 284 | - p0 = aParticlePath0;\n | |
| 285 | - p1 = aParticlePath1;\n | |
| 286 | - p2 = aParticlePath2;\n | |
| 287 | - p3 = aParticlePath3;\n | |
| 288 | - }\n | |
| 289 | - else\n | |
| 290 | - {\n | |
| 291 | - p0 = aParticlePath3;\n | |
| 292 | - p1 = aParticlePath4;\n | |
| 293 | - p2 = aParticlePath5;\n | |
| 294 | - p3 = aParticlePath0;\n | |
| 295 | - }\n | |
| 296 | - float t = mod( percentage*2.0, 1.0);\n | |
| 297 | - vec2 position = (1.0-t)*(1.0-t)*(1.0-t)*p0 + 3.0*(1.0-t)*(1.0-t)*t*p1+3.0*(1.0-t)*t*t*p2 + t*t*t*p3;\n | |
| 298 | - \n | |
| 299 | - vec2 referencePoint = mix(p0,p3,0.5);\n | |
| 300 | - float maxAnimationCount = float(MAXIMUM_ANIMATION_COUNT);\n | |
| 301 | - \n | |
| 302 | - for( float i=uTapIndices.x; i<uTapIndices.y; i+=1.0 )\n | |
| 303 | - { | |
| 304 | - int id = int( mod(i+0.5,maxAnimationCount ) );\n | |
| 305 | - vec2 edgePoint = normalize(referencePoint-uTapPoint[id])*uRadius+vec2(uRadius);\n | |
| 306 | - position = mix( position, edgePoint, uTapOffset[id] ) ;\n | |
| 307 | - }\n | |
| 308 | - \n | |
| 309 | - position = mix( position, vec2( 250.0,250.0 ),uBreak*(1.0-uOpacity[int(idx)]) ) ; | |
| 310 | - \n | |
| 311 | - // vertex position on the mesh: (sign(aTexCoord.x), sign(aTexCoord.y))*PARTICLE_HALF_SIZE | |
| 312 | - gl_Position = uMvpMatrix * vec4( position.x+sign(aTexCoord.x)*PARTICLE_HALF_SIZE/uScale, | |
| 313 | - position.y+sign(aTexCoord.y)*PARTICLE_HALF_SIZE/uScale, | |
| 314 | - 0.0, 1.0 );\n | |
| 315 | - \n | |
| 316 | - // we store the color index inside texCoord attribute | |
| 317 | - float colorIndex = abs(aTexCoord.x); | |
| 318 | - vColor.rgb = uParticleColors[int(colorIndex)-1];\n | |
| 319 | - vColor.a = fract(colorIndex) * uOpacity[int(idx)];\n | |
| 320 | - \n | |
| 321 | - // produce a 'seemingly' random fade in/out | |
| 322 | - percentage = mod(uPercentage+increment+0.15, 1.0);\n | |
| 323 | - float ramdomOpacity = (min(percentage, 0.25)-0.15+0.9-max(percentage,0.9))*10.0;\n | |
| 324 | - vColor.a *=ramdomOpacity;\n | |
| 325 | - \n | |
| 326 | - vTexCoord = clamp(aTexCoord, 0.0, 1.0);\n | |
| 327 | - }\n | |
| 328 | - ); | |
| 329 | - | |
| 330 | - std::string fragmentShader = DALI_COMPOSE_SHADER( | |
| 331 | - precision highp float;\n | |
| 332 | - uniform sampler2D sTexture;\n | |
| 333 | - varying vec2 vTexCoord;\n | |
| 334 | - \n | |
| 335 | - varying lowp vec4 vColor;\n | |
| 336 | - \n | |
| 337 | - void main()\n | |
| 338 | - {\n | |
| 339 | - gl_FragColor = vColor;\n | |
| 340 | - gl_FragColor.a *= texture2D(sTexture, vTexCoord).a;\n | |
| 341 | - }\n | |
| 342 | - ); | |
| 343 | - // clang-format on | |
| 344 | - | |
| 345 | 236 | std::ostringstream vertexShaderStringStream; |
| 346 | 237 | vertexShaderStringStream << "#define NUM_COLOR " << NUM_COLOR << "\n" |
| 347 | 238 | << "#define NUM_PARTICLE " << NUM_PARTICLE << "\n" |
| 348 | 239 | << "#define PARTICLE_HALF_SIZE " << PARTICLE_SIZE * ACTOR_SCALE / 2.f << "\n" |
| 349 | 240 | << "#define MAXIMUM_ANIMATION_COUNT " << MAXIMUM_ANIMATION_COUNT << "\n" |
| 350 | - << vertexShader; | |
| 241 | + << SHADER_SPARKLE_EFFECT_VERT; | |
| 351 | 242 | |
| 352 | - Shader handle = Shader::New(vertexShaderStringStream.str(), fragmentShader); | |
| 243 | + Shader handle = Shader::New(vertexShaderStringStream.str(), SHADER_SPARKLE_EFFECT_FRAG); | |
| 353 | 244 | |
| 354 | 245 | // set the particle colors |
| 355 | 246 | std::ostringstream oss; | ... | ... |
examples/styling/image-channel-control-impl.cpp
| ... | ... | @@ -19,6 +19,8 @@ |
| 19 | 19 | #include <dali-toolkit/devel-api/controls/control-devel.h> |
| 20 | 20 | #include <dali-toolkit/devel-api/visual-factory/visual-factory.h> |
| 21 | 21 | |
| 22 | +#include "generated/image-channel-control-frag.h" | |
| 23 | + | |
| 22 | 24 | #include <cstdio> |
| 23 | 25 | |
| 24 | 26 | using namespace Dali; // Needed for macros |
| ... | ... | @@ -29,21 +31,6 @@ namespace Internal |
| 29 | 31 | { |
| 30 | 32 | namespace |
| 31 | 33 | { |
| 32 | -// clang-format off | |
| 33 | - | |
| 34 | -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 35 | - varying mediump vec2 vTexCoord;\n | |
| 36 | - uniform sampler2D sTexture;\n | |
| 37 | - uniform mediump vec4 uColor;\n | |
| 38 | - uniform mediump vec3 mixColor;\n | |
| 39 | - uniform mediump vec3 uChannels;\n | |
| 40 | - \n | |
| 41 | - void main()\n | |
| 42 | - {\n | |
| 43 | - gl_FragColor = texture2D( sTexture, vTexCoord ) * vec4(mixColor,1.0) * uColor * vec4(uChannels, 1.0) ;\n | |
| 44 | - }\n | |
| 45 | -); | |
| 46 | -// clang-format on | |
| 47 | 34 | |
| 48 | 35 | Dali::BaseHandle Create() |
| 49 | 36 | { |
| ... | ... | @@ -95,7 +82,7 @@ void ImageChannelControl::SetImage(const std::string& url) |
| 95 | 82 | |
| 96 | 83 | Property::Map properties; |
| 97 | 84 | Property::Map shader; |
| 98 | - shader[Dali::Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = FRAGMENT_SHADER; | |
| 85 | + shader[Dali::Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = SHADER_IMAGE_CHANNEL_CONTROL_FRAG.data(); | |
| 99 | 86 | properties[Dali::Toolkit::Visual::Property::TYPE] = Dali::Toolkit::Visual::IMAGE; |
| 100 | 87 | properties[Dali::Toolkit::Visual::Property::SHADER] = shader; |
| 101 | 88 | properties[Dali::Toolkit::ImageVisual::Property::URL] = url; | ... | ... |
examples/styling/shaders/image-channel-control.frag
0 → 100644
| 1 | +varying mediump vec2 vTexCoord; | |
| 2 | +uniform sampler2D sTexture; | |
| 3 | +uniform mediump vec4 uColor; | |
| 4 | +uniform mediump vec3 mixColor; | |
| 5 | +uniform mediump vec3 uChannels; | |
| 6 | + | |
| 7 | +void main() | |
| 8 | +{ | |
| 9 | + gl_FragColor = texture2D( sTexture, vTexCoord ) * vec4(mixColor,1.0) * uColor * vec4(uChannels, 1.0) ; | |
| 10 | +} | ... | ... |
examples/textured-mesh/shaders/textured-mesh.frag
0 → 100644
examples/textured-mesh/shaders/textured-mesh.vert
0 → 100644
| 1 | +attribute mediump vec2 aPosition; | |
| 2 | +attribute highp vec2 aTexCoord; | |
| 3 | +varying mediump vec2 vTexCoord; | |
| 4 | +uniform mediump mat4 uMvpMatrix; | |
| 5 | +uniform mediump vec3 uSize; | |
| 6 | +uniform lowp vec4 uFadeColor; | |
| 7 | + | |
| 8 | +void main() | |
| 9 | +{ | |
| 10 | + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | |
| 11 | + vertexPosition.xyz *= uSize; | |
| 12 | + vertexPosition = uMvpMatrix * vertexPosition; | |
| 13 | + vTexCoord = aTexCoord; | |
| 14 | + gl_Position = vertexPosition; | |
| 15 | +} | ... | ... |
examples/textured-mesh/textured-mesh-example.cpp
| ... | ... | @@ -21,6 +21,8 @@ |
| 21 | 21 | // INTERNAL INCLUDES |
| 22 | 22 | #include "shared/utility.h" |
| 23 | 23 | #include "shared/view.h" |
| 24 | +#include "generated/textured-mesh-vert.h" | |
| 25 | +#include "generated/textured-mesh-frag.h" | |
| 24 | 26 | |
| 25 | 27 | using namespace Dali; |
| 26 | 28 | |
| ... | ... | @@ -29,34 +31,6 @@ namespace |
| 29 | 31 | const char* MATERIAL_SAMPLE(DEMO_IMAGE_DIR "gallery-small-48.jpg"); |
| 30 | 32 | const char* MATERIAL_SAMPLE2(DEMO_IMAGE_DIR "gallery-medium-19.jpg"); |
| 31 | 33 | |
| 32 | -#define MAKE_SHADER(A) #A | |
| 33 | - | |
| 34 | -const char* VERTEX_SHADER = MAKE_SHADER( | |
| 35 | - attribute mediump vec2 aPosition; | |
| 36 | - attribute highp vec2 aTexCoord; | |
| 37 | - varying mediump vec2 vTexCoord; | |
| 38 | - uniform mediump mat4 uMvpMatrix; | |
| 39 | - uniform mediump vec3 uSize; | |
| 40 | - uniform lowp vec4 uFadeColor; | |
| 41 | - | |
| 42 | - void main() { | |
| 43 | - mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | |
| 44 | - vertexPosition.xyz *= uSize; | |
| 45 | - vertexPosition = uMvpMatrix * vertexPosition; | |
| 46 | - vTexCoord = aTexCoord; | |
| 47 | - gl_Position = vertexPosition; | |
| 48 | - }); | |
| 49 | - | |
| 50 | -const char* FRAGMENT_SHADER = MAKE_SHADER( | |
| 51 | - varying mediump vec2 vTexCoord; | |
| 52 | - uniform lowp vec4 uColor; | |
| 53 | - uniform sampler2D sTexture; | |
| 54 | - uniform lowp vec4 uFadeColor; | |
| 55 | - | |
| 56 | - void main() { | |
| 57 | - gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * uFadeColor; | |
| 58 | - }); | |
| 59 | - | |
| 60 | 34 | /** |
| 61 | 35 | * Sinusoidal curve starting at zero with 2 cycles |
| 62 | 36 | */ |
| ... | ... | @@ -107,7 +81,7 @@ public: |
| 107 | 81 | Texture texture1 = DemoHelper::LoadTexture(MATERIAL_SAMPLE); |
| 108 | 82 | Texture texture2 = DemoHelper::LoadTexture(MATERIAL_SAMPLE2); |
| 109 | 83 | |
| 110 | - mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); | |
| 84 | + mShader = Shader::New(SHADER_TEXTURED_MESH_VERT, SHADER_TEXTURED_MESH_FRAG); | |
| 111 | 85 | mTextureSet1 = TextureSet::New(); |
| 112 | 86 | mTextureSet1.SetTexture(0u, texture1); |
| 113 | 87 | ... | ... |
examples/waves/shaders/waves.frag
0 → 100644
| 1 | +precision highp float; | |
| 2 | + | |
| 3 | +uniform vec4 uColor; // DALi | |
| 4 | +uniform sampler2D uNormalMap; // DALi | |
| 5 | + | |
| 6 | +uniform vec3 uInvLightDir; | |
| 7 | +uniform vec3 uLightColorSqr; | |
| 8 | +uniform vec3 uAmbientColor; | |
| 9 | + | |
| 10 | +uniform float uNormalMapWeight; | |
| 11 | +uniform float uSpecularity; | |
| 12 | + | |
| 13 | +varying vec2 vUv; | |
| 14 | +varying vec3 vNormal; | |
| 15 | +varying vec3 vViewPos; | |
| 16 | +varying float vHeight; | |
| 17 | + | |
| 18 | +float Rand(vec2 co) | |
| 19 | +{ | |
| 20 | + return fract(sin(dot(co.xy, vec2(12.98981, 78.2331))) * 43758.5453); | |
| 21 | +} | |
| 22 | + | |
| 23 | +float Sum(vec3 v) | |
| 24 | +{ | |
| 25 | + return v.x + v.y + v.z; | |
| 26 | +} | |
| 27 | + | |
| 28 | +void main() | |
| 29 | +{ | |
| 30 | + vec3 viewPos = normalize(vViewPos); | |
| 31 | + vec2 uv2 = vUv + vViewPos.xy / vViewPos.z * vHeight + vec2(.5, 0.); | |
| 32 | + | |
| 33 | + vec3 perturbNormal = texture2D(uNormalMap, vUv).rgb * 2. - 1.; | |
| 34 | + vec3 perturbNormal2 = texture2D(uNormalMap, uv2).rgb * 2. - 1.; | |
| 35 | + vec3 normal = normalize(vNormal + perturbNormal * uNormalMapWeight); | |
| 36 | + vec3 normal2 = normalize(vNormal + perturbNormal2 * uNormalMapWeight); | |
| 37 | + | |
| 38 | + vec3 color = uAmbientColor; | |
| 39 | + float d = max(0., dot(normal, -uInvLightDir)); | |
| 40 | + color += uColor.rgb * d; | |
| 41 | + | |
| 42 | + vec3 reflected = reflect(uInvLightDir, normal); | |
| 43 | + d = max(0., dot(reflected, viewPos)); | |
| 44 | + color += pow(d, uSpecularity) * uLightColorSqr; | |
| 45 | + | |
| 46 | + reflected = reflect(uInvLightDir, normal2); | |
| 47 | + d = max(0., dot(reflected, viewPos)); | |
| 48 | + color += pow(d, uSpecularity) * uLightColorSqr; | |
| 49 | + | |
| 50 | + gl_FragColor = vec4(color, 1.); | |
| 51 | +} | ... | ... |
examples/waves/shaders/waves.vert
0 → 100644
| 1 | +#define FMA(a, b, c) ((a) * (b) + (c)) // fused multiply-add | |
| 2 | + | |
| 3 | +precision highp float; | |
| 4 | + | |
| 5 | +const float kTile = 1.; | |
| 6 | + | |
| 7 | +const float kPi = 3.1415926535; | |
| 8 | +const float kEpsilon = 1. / 32.; | |
| 9 | + | |
| 10 | +// DALI uniforms | |
| 11 | +uniform vec3 uSize; | |
| 12 | +uniform mat4 uModelView; | |
| 13 | +uniform mat4 uProjection; | |
| 14 | +uniform mat3 uNormalMatrix; | |
| 15 | + | |
| 16 | +// our uniforms | |
| 17 | +uniform float uTime; | |
| 18 | +uniform vec2 uScrollScale; | |
| 19 | +uniform float uWaveRate; | |
| 20 | +uniform float uWaveAmplitude; | |
| 21 | +uniform float uParallaxAmount; | |
| 22 | + | |
| 23 | +attribute vec2 aPosition; | |
| 24 | +attribute vec2 aTexCoord; | |
| 25 | + | |
| 26 | +varying vec2 vUv; | |
| 27 | +varying vec3 vViewPos; | |
| 28 | +varying vec3 vNormal; | |
| 29 | +varying float vHeight; | |
| 30 | + | |
| 31 | +float CubicHermite(float B, float C, float t) | |
| 32 | +{ | |
| 33 | + float dCB = (C - B) * .5; | |
| 34 | + float A = B - dCB; | |
| 35 | + float D = B + dCB; | |
| 36 | + vec3 p = vec3(D + .5 * (((B - C) * 3.) - A), A - 2.5 * B + 2. * C - D, | |
| 37 | + .5 * (C - A)); | |
| 38 | + return FMA(FMA(FMA(p.x, t, p.y), t, p.z), t, B); | |
| 39 | +} | |
| 40 | + | |
| 41 | +float Hash(float n) | |
| 42 | +{ | |
| 43 | + return fract(sin(n) * 43751.5453123); | |
| 44 | +} | |
| 45 | + | |
| 46 | +float HeightAtTile(vec2 pos) | |
| 47 | +{ | |
| 48 | + float rate = Hash(Hash(pos.x) * Hash(pos.y)); | |
| 49 | + | |
| 50 | + return (sin(uTime * rate * uWaveRate) * .5 + .5) * uWaveAmplitude; | |
| 51 | +} | |
| 52 | + | |
| 53 | +float CalculateHeight(vec2 position) | |
| 54 | +{ | |
| 55 | + vec2 tile = floor(position); | |
| 56 | + position = fract(position); | |
| 57 | + | |
| 58 | + vec2 cp = vec2( | |
| 59 | + CubicHermite( | |
| 60 | + HeightAtTile(tile + vec2( kTile * -0.5, kTile * -0.5)), | |
| 61 | + HeightAtTile(tile + vec2( kTile * +0.5, kTile * -0.5)), | |
| 62 | + position.x), | |
| 63 | + CubicHermite( | |
| 64 | + HeightAtTile(tile + vec2( kTile * -0.5, kTile * +0.5)), | |
| 65 | + HeightAtTile(tile + vec2( kTile * +0.5, kTile * +0.5)), | |
| 66 | + position.x) | |
| 67 | + ); | |
| 68 | + | |
| 69 | + return CubicHermite(cp.x, cp.y, position.y); | |
| 70 | +} | |
| 71 | + | |
| 72 | +vec3 CalculateNormal(vec2 position) | |
| 73 | +{ | |
| 74 | + vec3 normal = vec3( | |
| 75 | + CalculateHeight(vec2(position.x - kEpsilon, position.y)) - | |
| 76 | + CalculateHeight(vec2(position.x + kEpsilon, position.y)), | |
| 77 | + .25, | |
| 78 | + CalculateHeight(vec2(position.x, position.y - kEpsilon)) - | |
| 79 | + CalculateHeight(vec2(position.x, position.y + kEpsilon)) | |
| 80 | + ); | |
| 81 | + return normal; | |
| 82 | +} | |
| 83 | + | |
| 84 | +void main() | |
| 85 | +{ | |
| 86 | + vUv = aTexCoord; | |
| 87 | + | |
| 88 | + vec2 scrollPosition = aPosition * uScrollScale + vec2(0., uTime * -kPi); | |
| 89 | + vNormal = uNormalMatrix * CalculateNormal(scrollPosition); | |
| 90 | + | |
| 91 | + float h = CalculateHeight(scrollPosition); | |
| 92 | + vHeight = h * uParallaxAmount; | |
| 93 | + vec3 position = vec3(aPosition.x, h, aPosition.y); | |
| 94 | + | |
| 95 | + vec4 viewPosition = uModelView * vec4(position * uSize, 1.); | |
| 96 | + vViewPos = -viewPosition.xyz; | |
| 97 | + | |
| 98 | + gl_Position = uProjection * viewPosition; | |
| 99 | +} | ... | ... |
examples/waves/waves-example.cpp
| ... | ... | @@ -32,165 +32,14 @@ |
| 32 | 32 | #include <iostream> |
| 33 | 33 | #include <numeric> |
| 34 | 34 | |
| 35 | +#include "generated/waves-vert.h" | |
| 36 | +#include "generated/waves-frag.h" | |
| 37 | + | |
| 35 | 38 | using namespace Dali; |
| 36 | 39 | |
| 37 | 40 | namespace |
| 38 | 41 | { |
| 39 | 42 | |
| 40 | -constexpr std::string_view WAVES_VSH = | |
| 41 | - "#define FMA(a, b, c) ((a) * (b) + (c))\n" // fused multiply-add | |
| 42 | -DALI_COMPOSE_SHADER( | |
| 43 | - precision highp float; | |
| 44 | - | |
| 45 | - const float kTile = 1.; | |
| 46 | - | |
| 47 | - const float kPi = 3.1415926535; | |
| 48 | - const float kEpsilon = 1. / 32.; | |
| 49 | - | |
| 50 | - // DALI uniforms | |
| 51 | - uniform vec3 uSize; | |
| 52 | - uniform mat4 uModelView; | |
| 53 | - uniform mat4 uProjection; | |
| 54 | - uniform mat3 uNormalMatrix; | |
| 55 | - | |
| 56 | - // our uniforms | |
| 57 | - uniform float uTime; | |
| 58 | - uniform vec2 uScrollScale; | |
| 59 | - uniform float uWaveRate; | |
| 60 | - uniform float uWaveAmplitude; | |
| 61 | - uniform float uParallaxAmount; | |
| 62 | - | |
| 63 | - attribute vec2 aPosition; | |
| 64 | - attribute vec2 aTexCoord; | |
| 65 | - | |
| 66 | - varying vec2 vUv; | |
| 67 | - varying vec3 vViewPos; | |
| 68 | - varying vec3 vNormal; | |
| 69 | - varying float vHeight; | |
| 70 | - | |
| 71 | - float CubicHermite(float B, float C, float t) | |
| 72 | - { | |
| 73 | - float dCB = (C - B) * .5; | |
| 74 | - float A = B - dCB; | |
| 75 | - float D = B + dCB; | |
| 76 | - vec3 p = vec3(D + .5 * (((B - C) * 3.) - A), A - 2.5 * B + 2. * C - D, | |
| 77 | - .5 * (C - A)); | |
| 78 | - return FMA(FMA(FMA(p.x, t, p.y), t, p.z), t, B); | |
| 79 | - } | |
| 80 | - | |
| 81 | - float Hash(float n) | |
| 82 | - { | |
| 83 | - return fract(sin(n) * 43751.5453123); | |
| 84 | - } | |
| 85 | - | |
| 86 | - float HeightAtTile(vec2 pos) | |
| 87 | - { | |
| 88 | - float rate = Hash(Hash(pos.x) * Hash(pos.y)); | |
| 89 | - | |
| 90 | - return (sin(uTime * rate * uWaveRate) * .5 + .5) * uWaveAmplitude; | |
| 91 | - } | |
| 92 | - | |
| 93 | - float CalculateHeight(vec2 position) | |
| 94 | - { | |
| 95 | - vec2 tile = floor(position); | |
| 96 | - position = fract(position); | |
| 97 | - | |
| 98 | - vec2 cp = vec2( | |
| 99 | - CubicHermite( | |
| 100 | - HeightAtTile(tile + vec2( kTile * -0.5, kTile * -0.5)), | |
| 101 | - HeightAtTile(tile + vec2( kTile * +0.5, kTile * -0.5)), | |
| 102 | - position.x), | |
| 103 | - CubicHermite( | |
| 104 | - HeightAtTile(tile + vec2( kTile * -0.5, kTile * +0.5)), | |
| 105 | - HeightAtTile(tile + vec2( kTile * +0.5, kTile * +0.5)), | |
| 106 | - position.x) | |
| 107 | - ); | |
| 108 | - | |
| 109 | - return CubicHermite(cp.x, cp.y, position.y); | |
| 110 | - } | |
| 111 | - | |
| 112 | - vec3 CalculateNormal(vec2 position) | |
| 113 | - { | |
| 114 | - vec3 normal = vec3( | |
| 115 | - CalculateHeight(vec2(position.x - kEpsilon, position.y)) - | |
| 116 | - CalculateHeight(vec2(position.x + kEpsilon, position.y)), | |
| 117 | - .25, | |
| 118 | - CalculateHeight(vec2(position.x, position.y - kEpsilon)) - | |
| 119 | - CalculateHeight(vec2(position.x, position.y + kEpsilon)) | |
| 120 | - ); | |
| 121 | - return normal; | |
| 122 | - } | |
| 123 | - | |
| 124 | - void main() | |
| 125 | - { | |
| 126 | - vUv = aTexCoord; | |
| 127 | - | |
| 128 | - vec2 scrollPosition = aPosition * uScrollScale + vec2(0., uTime * -kPi); | |
| 129 | - vNormal = uNormalMatrix * CalculateNormal(scrollPosition); | |
| 130 | - | |
| 131 | - float h = CalculateHeight(scrollPosition); | |
| 132 | - vHeight = h * uParallaxAmount; | |
| 133 | - vec3 position = vec3(aPosition.x, h, aPosition.y); | |
| 134 | - | |
| 135 | - vec4 viewPosition = uModelView * vec4(position * uSize, 1.); | |
| 136 | - vViewPos = -viewPosition.xyz; | |
| 137 | - | |
| 138 | - gl_Position = uProjection * viewPosition; | |
| 139 | - }); | |
| 140 | - | |
| 141 | -constexpr std::string_view WAVES_FSH = DALI_COMPOSE_SHADER( | |
| 142 | - precision highp float; | |
| 143 | - | |
| 144 | - uniform vec4 uColor; // DALi | |
| 145 | - uniform sampler2D uNormalMap; // DALi | |
| 146 | - | |
| 147 | - uniform vec3 uInvLightDir; | |
| 148 | - uniform vec3 uLightColorSqr; | |
| 149 | - uniform vec3 uAmbientColor; | |
| 150 | - | |
| 151 | - uniform float uNormalMapWeight; | |
| 152 | - uniform float uSpecularity; | |
| 153 | - | |
| 154 | - varying vec2 vUv; | |
| 155 | - varying vec3 vNormal; | |
| 156 | - varying vec3 vViewPos; | |
| 157 | - varying float vHeight; | |
| 158 | - | |
| 159 | - float Rand(vec2 co) | |
| 160 | - { | |
| 161 | - return fract(sin(dot(co.xy, vec2(12.98981, 78.2331))) * 43758.5453); | |
| 162 | - } | |
| 163 | - | |
| 164 | - float Sum(vec3 v) | |
| 165 | - { | |
| 166 | - return v.x + v.y + v.z; | |
| 167 | - } | |
| 168 | - | |
| 169 | - void main() | |
| 170 | - { | |
| 171 | - vec3 viewPos = normalize(vViewPos); | |
| 172 | - vec2 uv2 = vUv + vViewPos.xy / vViewPos.z * vHeight + vec2(.5, 0.); | |
| 173 | - | |
| 174 | - vec3 perturbNormal = texture2D(uNormalMap, vUv).rgb * 2. - 1.; | |
| 175 | - vec3 perturbNormal2 = texture2D(uNormalMap, uv2).rgb * 2. - 1.; | |
| 176 | - vec3 normal = normalize(vNormal + perturbNormal * uNormalMapWeight); | |
| 177 | - vec3 normal2 = normalize(vNormal + perturbNormal2 * uNormalMapWeight); | |
| 178 | - | |
| 179 | - vec3 color = uAmbientColor; | |
| 180 | - float d = max(0., dot(normal, -uInvLightDir)); | |
| 181 | - color += uColor.rgb * d; | |
| 182 | - | |
| 183 | - vec3 reflected = reflect(uInvLightDir, normal); | |
| 184 | - d = max(0., dot(reflected, viewPos)); | |
| 185 | - color += pow(d, uSpecularity) * uLightColorSqr; | |
| 186 | - | |
| 187 | - reflected = reflect(uInvLightDir, normal2); | |
| 188 | - d = max(0., dot(reflected, viewPos)); | |
| 189 | - color += pow(d, uSpecularity) * uLightColorSqr; | |
| 190 | - | |
| 191 | - gl_FragColor = vec4(color, 1.); | |
| 192 | - }); | |
| 193 | - | |
| 194 | 43 | const float TIME_STEP = 0.0952664626; |
| 195 | 44 | |
| 196 | 45 | const std::string UNIFORM_LIGHT_COLOR_SQR = "uLightColorSqr"; |
| ... | ... | @@ -423,7 +272,7 @@ private: |
| 423 | 272 | specularity = mWaveShader.GetProperty(mUSpecularity).Get<float>(); |
| 424 | 273 | } |
| 425 | 274 | |
| 426 | - Shader shader = Shader::New(WAVES_VSH.data(), WAVES_FSH.data(), Shader::Hint::MODIFIES_GEOMETRY); | |
| 275 | + Shader shader = Shader::New(SHADER_WAVES_VERT, SHADER_WAVES_FRAG, Shader::Hint::MODIFIES_GEOMETRY); | |
| 427 | 276 | mULightColorSqr = shader.RegisterProperty(UNIFORM_LIGHT_COLOR_SQR, lightColorSqr); |
| 428 | 277 | mUAmbientColor = shader.RegisterProperty(UNIFORM_AMBIENT_COLOR, ambientColor); |
| 429 | 278 | mUInvLightDir = shader.RegisterProperty(UNIFORM_INV_LIGHT_DIR, invLightDir); | ... | ... |