core
.clangd/
compile_commands.json
+dali-toolkit/internal/graphics/generated/*
+dali-toolkit/internal/graphics/builtin-shader-extern-gen.h
+dali-scene-loader/internal/graphics/generated/*
+dali-scene-loader/internal/graphics/builtin-shader-extern-gen.h
#!/bin/bash
-TEMP=`getopt -o dhsSmf --long debug,help,failnorerun,serial,tct,modules -n 'execute.sh' -- "$@"`
+TEMP=`getopt -o dhsSmfq --long debug,help,failnorerun,quiet,serial,tct,modules -n 'execute.sh' -- "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
function usage
{
- echo -e "Usage: execute.sh [-d][-s|-S|-r] [module|testcase]"
+ echo -e "Usage: execute.sh [-d][-s|-S|-r][-q] [module|testcase]"
echo -e " execute.sh\t\tExecute test cases from all modules in parallel"
echo -e " execute.sh -f \tExecute test cases from all modules in parallel without rerunning failed test cases"
echo -e " execute.sh -d <testcase>\tDebug testcase"
echo -e " execute.sh [module]\tExecute test cases from the given module in parallel"
echo -e " execute.sh -s [module]\t\tExecute test cases in serial using Testkit-Lite"
echo -e " execute.sh -S [module]\t\tExecute test cases in serial"
+ echo -e " execute.sh -q|--quiet ...\tExecute test cases, but don't write output"
echo -e " execute.sh <testcase>\tFind and execute the given test case"
exit 2
}
opt_modules=0
opt_debug=0
opt_noFailedRerun="";
+opt_quiet="";
while true ; do
case "$1" in
-h|--help) usage ;;
-s|--tct) opt_tct=1 ; shift ;;
-f|--nofailedrerun) opt_noFailedRerun="-f" ; shift ;;
-S|--serial) opt_serial="-s" ; shift ;;
+ -q|--quiet) opt_quiet="-q" ; shift ;;
-m|--modules) opt_modules=1 ; shift ;;
--) shift; break;;
*) echo "Internal error $1!" ; exit 1 ;;
EOF
}
+function output_start
+{
+ start=`date +"%Y-%m-%d_%H_%M_%S"`
+ cat > tct-${1}-core-tests.xml <<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<?xml-stylesheet type="text/xsl" href="./style/testresult.xsl"?>
+<test_definition>
+<environment build_id="" device_id="localhost" device_model="" device_name="N/A" host="Ubuntu" manufacturer="" resolution="N/A" screen_size="N/A"><other /></environment>
+<summary test_plan_name="Empty test_plan_name"><start_at>$start</start_at><end_at>$start</end_at></summary>
+ <suite category="Core APIs" name="tct-$1-core-tests">
+ <set name="default" set_debug_msg="automated-tests.auto.suite_1_set_1.dlog">
+EOF
+}
+
+
+function output_end
+{
+ cat >> tct-${1}-core-tests.xml <<EOF
+ </set>
+ </suite>
+</test_definition>
+EOF
+}
+
+
if [ $opt_modules == 1 ] ; then
modules= get_modules
echo $modules
do
echo -e "$ASCII_BOLD"
echo -e "Executing $mod$ASCII_RESET"
- dbus-launch build/src/$mod/tct-$mod-core $opt_serial $opt_noFailedRerun
+ output_start $mod
+ dbus-launch build/src/$mod/tct-$mod-core $opt_serial $opt_noFailedRerun $opt_quiet
+ output_end $mod
done
summary_end
summary_start
module=$1
shift;
- dbus-launch build/src/$module/tct-$module-core $opt_serial $opt_noFailedRerun $*
+ output_start ${module}
+ dbus-launch build/src/$module/tct-$module-core $opt_serial $opt_noFailedRerun $opt_quiet $*
+ output_end ${module}
summary_end
else
-#include <string.h>
-#include <getopt.h>
-#include <stdlib.h>
#include <test-harness.h>
#include "tct-dali-scene-loader-internal-core.h"
int main(int argc, char * const argv[])
{
- int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT;
-
- const char* optString = "sf";
- bool optRerunFailed(true);
- bool optRunSerially(false);
-
- int nextOpt = 0;
- do
- {
- nextOpt = getopt( argc, argv, optString );
- switch(nextOpt)
- {
- case 'f':
- optRerunFailed = false;
- break;
- case 's':
- optRunSerially = true;
- break;
- case '?':
- TestHarness::Usage(argv[0]);
- exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT);
- break;
- }
- } while( nextOpt != -1 );
-
- if( optind == argc ) // no testcase name in argument list
- {
- if( optRunSerially )
- {
- result = TestHarness::RunAll( argv[0], tc_array );
- }
- else
- {
- result = TestHarness::RunAllInParallel( argv[0], tc_array, optRerunFailed );
- }
- }
- else
- {
- // optind is index of next argument - interpret as testcase name
- result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]);
- }
- return result;
+ return TestHarness::RunTests(argc, argv, tc_array);
}
-#include <string.h>
-#include <getopt.h>
-#include <stdlib.h>
#include <test-harness.h>
#include "tct-dali-scene-loader-core.h"
int main(int argc, char * const argv[])
{
- int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT;
-
- const char* optString = "sf";
- bool optRerunFailed(true);
- bool optRunSerially(false);
-
- int nextOpt = 0;
- do
- {
- nextOpt = getopt( argc, argv, optString );
- switch(nextOpt)
- {
- case 'f':
- optRerunFailed = false;
- break;
- case 's':
- optRunSerially = true;
- break;
- case '?':
- TestHarness::Usage(argv[0]);
- exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT);
- break;
- }
- } while( nextOpt != -1 );
-
- if( optind == argc ) // no testcase name in argument list
- {
- if( optRunSerially )
- {
- result = TestHarness::RunAll( argv[0], tc_array );
- }
- else
- {
- result = TestHarness::RunAllInParallel( argv[0], tc_array, optRerunFailed );
- }
- }
- else
- {
- // optind is index of next argument - interpret as testcase name
- result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]);
- }
- return result;
+ return TestHarness::RunTests(argc, argv, tc_array);
}
-#include <string.h>
-#include <getopt.h>
-#include <stdlib.h>
#include <test-harness.h>
#include "tct-dali-toolkit-internal-core.h"
int main(int argc, char * const argv[])
{
- int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT;
-
- const char* optString = "sf";
- bool optRerunFailed(true);
- bool optRunSerially(false);
-
- int nextOpt = 0;
- do
- {
- nextOpt = getopt( argc, argv, optString );
- switch(nextOpt)
- {
- case 'f':
- optRerunFailed = false;
- break;
- case 's':
- optRunSerially = true;
- break;
- case '?':
- TestHarness::Usage(argv[0]);
- exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT);
- break;
- }
- } while( nextOpt != -1 );
-
- if( optind == argc ) // no testcase name in argument list
- {
- if( optRunSerially )
- {
- result = TestHarness::RunAll( argv[0], tc_array );
- }
- else
- {
- result = TestHarness::RunAllInParallel( argv[0], tc_array, optRerunFailed );
- }
- }
- else
- {
- // optind is index of next argument - interpret as testcase name
- result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]);
- }
- return result;
+ return TestHarness::RunTests(argc, argv, tc_array);
}
-#include <string.h>
-#include <getopt.h>
-#include <stdlib.h>
#include <test-harness.h>
#include "tct-dali-toolkit-styling-core.h"
int main(int argc, char * const argv[])
{
- int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT;
-
- const char* optString = "sf";
- bool optRerunFailed(true);
- bool optRunSerially(false);
-
- int nextOpt = 0;
- do
- {
- nextOpt = getopt( argc, argv, optString );
- switch(nextOpt)
- {
- case 'f':
- optRerunFailed = false;
- break;
- case 's':
- optRunSerially = true;
- break;
- case '?':
- TestHarness::Usage(argv[0]);
- exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT);
- break;
- }
- } while( nextOpt != -1 );
-
- if( optind == argc ) // no testcase name in argument list
- {
- if( optRunSerially )
- {
- result = TestHarness::RunAll( argv[0], tc_array );
- }
- else
- {
- result = TestHarness::RunAllInParallel( argv[0], tc_array, optRerunFailed );
- }
- }
- else
- {
- // optind is index of next argument - interpret as testcase name
- result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]);
- }
- return result;
+ return TestHarness::RunTests(argc, argv, tc_array);
}
-#include <string.h>
-#include <getopt.h>
-#include <stdlib.h>
#include <test-harness.h>
#include "tct-dali-toolkit-third-party-core.h"
int main(int argc, char * const argv[])
{
- int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT;
-
- const char* optString = "sf";
- bool optRerunFailed(true);
- bool optRunSerially(false);
-
- int nextOpt = 0;
- do
- {
- nextOpt = getopt( argc, argv, optString );
- switch(nextOpt)
- {
- case 'f':
- optRerunFailed = false;
- break;
- case 's':
- optRunSerially = true;
- break;
- case '?':
- TestHarness::Usage(argv[0]);
- exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT);
- break;
- }
- } while( nextOpt != -1 );
-
- if( optind == argc ) // no testcase name in argument list
- {
- if( optRunSerially )
- {
- result = TestHarness::RunAll( argv[0], tc_array );
- }
- else
- {
- result = TestHarness::RunAllInParallel( argv[0], tc_array, optRerunFailed );
- }
- }
- else
- {
- // optind is index of next argument - interpret as testcase name
- result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]);
- }
- return result;
+ return TestHarness::RunTests(argc, argv, tc_array);
}
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
mCore = Dali::Integration::Core::New(mRenderController,
mPlatformAbstraction,
- mGlAbstraction,
- mGlSyncAbstraction,
- mGlContextHelperAbstraction,
+ mGraphicsController,
Integration::RenderToFrameBuffer::FALSE,
Integration::DepthBufferAvailable::TRUE,
Integration::StencilBufferAvailable::TRUE,
return mRenderController;
}
+TestGraphicsController& TestApplication::GetGraphicsController()
+{
+ return mGraphicsController;
+}
+
TestGlAbstraction& TestApplication::GetGlAbstraction()
{
- return mGlAbstraction;
+ return static_cast<TestGlAbstraction&>(mGraphicsController.GetGlAbstraction());
}
TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
{
- return mGlSyncAbstraction;
+ return static_cast<TestGlSyncAbstraction&>(mGraphicsController.GetGlSyncAbstraction());
}
TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
{
- return mGlContextHelperAbstraction;
+ return static_cast<TestGlContextHelperAbstraction&>(mGraphicsController.GetGlContextHelperAbstraction());
}
void TestApplication::ProcessEvent(const Integration::Event& event)
void TestApplication::ResetContext()
{
mCore->ContextDestroyed();
- mGlAbstraction.Initialize();
+ mGraphicsController.Initialize();
mCore->ContextCreated();
}
#define DALI_TEST_APPLICATION_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/integration-api/resource-policies.h>
#include <dali/integration-api/scene.h>
#include <dali/integration-api/trace.h>
+
#include <dali/public-api/common/dali-common.h>
#include <test-platform-abstraction.h>
-#include "test-gl-abstraction.h"
-#include "test-gl-context-helper-abstraction.h"
-#include "test-gl-sync-abstraction.h"
+#include "test-graphics-controller.h"
#include "test-render-controller.h"
namespace Dali
void CreateScene();
void InitializeCore();
~TestApplication() override;
- static void LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message);
- static void LogContext(bool start, const char* tag);
- Dali::Integration::Core& GetCore();
- TestPlatformAbstraction& GetPlatform();
- TestRenderController& GetRenderController();
+ static void LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message);
+ static void LogContext(bool start, const char* tag);
+ Dali::Integration::Core& GetCore();
+ TestPlatformAbstraction& GetPlatform();
+ TestRenderController& GetRenderController();
+ TestGraphicsController& GetGraphicsController();
+
TestGlAbstraction& GetGlAbstraction();
TestGlSyncAbstraction& GetGlSyncAbstraction();
TestGlContextHelperAbstraction& GetGlContextHelperAbstraction();
- void ProcessEvent(const Integration::Event& event);
- void SendNotification();
- bool Render(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL, const char* location = NULL);
- bool PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects);
- bool RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect);
- uint32_t GetUpdateStatus();
- bool UpdateOnly(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL);
- bool RenderOnly();
- void ResetContext();
- bool GetRenderNeedsUpdate();
- bool GetRenderNeedsPostRender();
- uint32_t Wait(uint32_t durationToWait);
- static void EnableLogging(bool enabled)
+
+ void ProcessEvent(const Integration::Event& event);
+ void SendNotification();
+ bool Render(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL, const char* location = NULL);
+ bool PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects);
+ bool RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect);
+ uint32_t GetUpdateStatus();
+ bool UpdateOnly(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL);
+ bool RenderOnly();
+ void ResetContext();
+ bool GetRenderNeedsUpdate();
+ bool GetRenderNeedsPostRender();
+ uint32_t Wait(uint32_t durationToWait);
+ static void EnableLogging(bool enabled)
{
mLoggingEnabled = enabled;
}
void DoUpdate(uint32_t intervalMilliseconds, const char* location = NULL);
protected:
- TestPlatformAbstraction mPlatformAbstraction;
- TestRenderController mRenderController;
- TestGlAbstraction mGlAbstraction;
- TestGlSyncAbstraction mGlSyncAbstraction;
- TestGlContextHelperAbstraction mGlContextHelperAbstraction;
+ TestPlatformAbstraction mPlatformAbstraction;
+ TestRenderController mRenderController;
+ TestGraphicsController mGraphicsController;
Integration::UpdateStatus mStatus;
Integration::RenderStatus mRenderStatus;
--- /dev/null
+#ifndef TEST_GRAPHICS_CONTROLLER_H
+#define TEST_GRAPHICS_CONTROLLER_H
+
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali/graphics-api/graphics-controller.h>
+#include "test-gl-abstraction.h"
+#include "test-gl-context-helper-abstraction.h"
+#include "test-gl-sync-abstraction.h"
+
+namespace Dali
+{
+class TestGraphicsController : public Dali::Graphics::Controller
+{
+public:
+ TestGraphicsController() = default;
+ virtual ~TestGraphicsController() = default;
+
+ void Initialize()
+ {
+ mGlAbstraction.Initialize();
+ }
+
+ Integration::GlAbstraction& GetGlAbstraction() override
+ {
+ return mGlAbstraction;
+ }
+
+ Integration::GlSyncAbstraction& GetGlSyncAbstraction() override
+ {
+ return mGlSyncAbstraction;
+ }
+
+ Integration::GlContextHelperAbstraction& GetGlContextHelperAbstraction() override
+ {
+ return mGlContextHelperAbstraction;
+ }
+
+private:
+ TestGlAbstraction mGlAbstraction;
+ TestGlSyncAbstraction mGlSyncAbstraction;
+ TestGlContextHelperAbstraction mGlContextHelperAbstraction;
+};
+
+} // namespace Dali
+
+#endif //TEST_GRAPHICS_CONTROLLER_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <sys/wait.h>
#include <testcase.h>
-#include <time.h>
+#include <getopt.h>
#include <unistd.h>
-
+#include <algorithm>
#include <chrono>
+#include <cstdlib>
#include <cstring>
+#include <ctime>
+#include <fstream>
#include <map>
+#include <sstream>
#include <vector>
+using std::chrono::steady_clock;
+using std::chrono::system_clock;
+
namespace TestHarness
{
typedef std::map<int32_t, TestCase> RunningTestCases;
return slash;
}
-void SuppressLogOutput()
+std::vector<std::string> Split(const std::string& aString, char delimiter)
{
- // Close stdout and stderr to suppress the log output
- close(STDOUT_FILENO); // File descriptor number for stdout is 1
- close(STDERR_FILENO); // File descriptor number for stderr is 2
+ std::vector<std::string> tokens;
+ std::string token;
+ std::istringstream tokenStream(aString);
+ while(std::getline(tokenStream, token, delimiter))
+ {
+ tokens.push_back(token);
+ }
+ return tokens;
+}
- // The POSIX specification requires that /dev/null must be provided,
- // The open function always chooses the lowest unused file descriptor
- // It is sufficient for stdout to be writable.
- open("/dev/null", O_WRONLY); // Redirect file descriptor number 1 (i.e. stdout) to /dev/null
- // When stderr is opened it must be both readable and writable.
- open("/dev/null", O_RDWR); // Redirect file descriptor number 2 (i.e. stderr) to /dev/null
+std::string Join(const std::vector<std::string>& tokens, char delimiter)
+{
+ std::ostringstream oss;
+
+ unsigned int delimiterCount = 0;
+ for(auto& token : tokens)
+ {
+ oss << token;
+ if(delimiterCount < tokens.size() - 1)
+ {
+ oss << delimiter;
+ }
+ ++delimiterCount;
+ }
+ return oss.str();
+}
+
+std::string ChildOutputFilename(int pid)
+{
+ std::ostringstream os;
+ os << "/tmp/tct-child." << pid;
+ return os.str();
+}
+
+std::string TestModuleFilename(const char* processName)
+{
+ auto pathComponents = Split(processName, '/');
+ auto aModule = pathComponents.back();
+ aModule += "-tests.xml";
+ return aModule;
+}
+
+std::string TestModuleName(const char* processName)
+{
+ auto pathComponents = Split(processName, '/');
+ auto aModule = pathComponents.back();
+ auto moduleComponents = Split(aModule, '-');
+
+ moduleComponents[1][0] = std::toupper(moduleComponents[1][0]);
+ moduleComponents[2][0] = std::toupper(moduleComponents[2][0]);
+
+ std::ostringstream oss;
+ for(unsigned int i = 1; i < moduleComponents.size() - 1; ++i) // [0]=tct, [n-1]=core
+ {
+ oss << moduleComponents[i];
+
+ if(i > 1 && i < moduleComponents.size() - 2) // skip first and last delimiter
+ {
+ oss << '-';
+ }
+ }
+
+ return oss.str();
+}
+
+std::string ReadAndEscape(std::string filename)
+{
+ std::ostringstream os;
+ std::ifstream ifs;
+ ifs.open(filename, std::ifstream::in);
+ while(ifs.good())
+ {
+ std::string line;
+ std::getline(ifs, line);
+ for(auto c : line)
+ {
+ switch(c)
+ {
+ case '<':
+ os << "<";
+ break;
+ case '>':
+ os << ">";
+ break;
+ case '&':
+ os << "&";
+ break;
+ default:
+ os << c;
+ break;
+ }
+ }
+ os << "\\"
+ << "n";
+ }
+ ifs.close();
+ return os.str();
+}
+
+void OutputTestResult(
+ std::ofstream& ofs,
+ const char* pathToExecutable,
+ std::string testSuiteName,
+ TestCase& testCase,
+ std::string startTime,
+ std::string endTime)
+{
+ std::string outputFilename = ChildOutputFilename(testCase.childPid);
+ std::string testOutput = ReadAndEscape(outputFilename);
+
+ ofs << "<testcase component=\"CoreAPI/" << testSuiteName << "/default\" execution_type=\"auto\" id=\""
+ << testCase.name << "\" purpose=\"\" result=\"" << (testCase.result == 0 ? "PASS" : "FAIL") << "\">" << std::endl
+ << "<description><test_script_entry test_script_expected_result=\"0\">"
+ << pathToExecutable << testCase.name << "</test_script_entry>" << std::endl
+ << "</description>"
+ << "<result_info><actual_result>" << (testCase.result == 0 ? "PASS" : "FAIL") << "</actual_result>" << std::endl
+ << "<start>" << startTime << "</start>"
+ << "<end>" << endTime << "</end>"
+ << "<stdout><![CDATA[]]></stdout>"
+ << "<stderr><![CDATA[" << testOutput << "]]></stderr></result_info></testcase>" << std::endl;
+
+ unlink(outputFilename.c_str());
+}
+
+void OutputTestResults(const char* processName, RunningTestCases& children)
+{
+ std::ofstream ofs;
+ std::string filename = TestModuleFilename(processName);
+ std::string moduleName = TestModuleName(processName);
+ ofs.open(filename, std::ofstream::out | std::ofstream::app);
+
+ // Sort completed cases by original test case id
+ std::vector<TestCase> childTestCases;
+ childTestCases.reserve(children.size());
+ for(auto& element : children) childTestCases.push_back(element.second);
+ std::sort(childTestCases.begin(), childTestCases.end(), [](const TestCase& a, const TestCase& b) {
+ return a.testCase < b.testCase;
+ });
+
+ const int BUFSIZE = 256;
+ char buffer[BUFSIZE];
+ for(auto& testCase : childTestCases)
+ {
+ auto tt = system_clock::to_time_t(testCase.startSystemTime);
+ strftime(buffer, BUFSIZE, "%c", localtime(&tt));
+ std::string startTime(buffer);
+ OutputTestResult(ofs, processName, moduleName, testCase, startTime, startTime);
+ }
+
+ ofs.close();
+}
+
+void OutputStatistics(const char* processName, int32_t numPasses, int32_t numFailures)
+{
+ FILE* fp = fopen("summary.xml", "a");
+ if(fp != NULL)
+ {
+ fprintf(fp,
+ " <suite name=\"%s-tests\">\n"
+ " <total_case>%d</total_case>\n"
+ " <pass_case>%d</pass_case>\n"
+ " <pass_rate>%5.2f</pass_rate>\n"
+ " <fail_case>%d</fail_case>\n"
+ " <fail_rate>%5.2f</fail_rate>\n"
+ " <block_case>0</block_case>\n"
+ " <block_rate>0.00</block_rate>\n"
+ " <na_case>0</na_case>\n"
+ " <na_rate>0.00</na_rate>\n"
+ " </suite>\n",
+ basename(processName),
+ numPasses + numFailures,
+ numPasses,
+ (float)numPasses * 100.0f / (numPasses + numFailures),
+ numFailures,
+ (float)numFailures * 100.0f / (numPasses + numFailures));
+ fclose(fp);
+ }
}
int32_t RunTestCase(struct ::testcase_s& testCase)
return result;
}
-int32_t RunTestCaseInChildProcess(struct ::testcase_s& testCase, bool suppressOutput)
+int32_t RunTestCaseRedirectOutput(TestCase& testCase, bool suppressOutput)
+{
+ // Executing in child process
+ // Close stdout and stderr to suppress the log output
+ close(STDOUT_FILENO); // File descriptor number for stdout is 1
+
+ // The POSIX specification requires that /dev/null must be provided,
+ // The open function always chooses the lowest unused file descriptor
+ // It is sufficient for stdout to be writable.
+ open("/dev/null", O_WRONLY); // Redirect file descriptor number 1 (i.e. stdout) to /dev/null
+
+ fflush(stderr);
+ close(STDERR_FILENO);
+ if(suppressOutput)
+ {
+ stderr = fopen("/dev/null", "w+"); // Redirect fd 2 to /dev/null
+ }
+ else
+ {
+ // When stderr is opened it must be both readable and writable.
+ std::string childOutputFilename = ChildOutputFilename(getpid());
+ stderr = fopen(childOutputFilename.c_str(), "w+");
+ }
+
+ int32_t status = RunTestCase(*testCase.tctPtr);
+
+ fflush(stderr);
+ fclose(stderr);
+
+ return status;
+}
+
+int32_t RunTestCaseInChildProcess(TestCase& testCase, bool redirect)
{
int32_t testResult = EXIT_STATUS_TESTCASE_FAILED;
int32_t pid = fork();
if(pid == 0) // Child process
{
- if(suppressOutput)
+ if(redirect)
{
- SuppressLogOutput();
+ int status = RunTestCaseRedirectOutput(testCase, false);
+ exit(status);
}
else
{
- printf("\n");
- for(int32_t i = 0; i < 80; ++i) printf("#");
- printf("\nTC: %s\n", testCase.name);
- fflush(stdout);
+ int status = RunTestCase(*testCase.tctPtr);
+ exit(status);
}
-
- int32_t status = RunTestCase(testCase);
-
- if(!suppressOutput)
- {
- fflush(stdout);
- fflush(stderr);
- fclose(stdout);
- fclose(stderr);
- }
- exit(status);
}
else if(pid == -1)
{
}
else // Parent process
{
- int32_t status = 0;
- int32_t childPid = waitpid(pid, &status, 0);
+ int32_t status = 0;
+ int32_t childPid = waitpid(pid, &status, 0);
+ testCase.childPid = childPid;
if(childPid == -1)
{
perror("waitpid");
return testResult;
}
-void OutputStatistics(const char* processName, int32_t numPasses, int32_t numFailures)
+int32_t RunAll(const char* processName, ::testcase tc_array[], bool quiet)
{
- FILE* fp = fopen("summary.xml", "a");
- if(fp != NULL)
+ int32_t numFailures = 0;
+ int32_t numPasses = 0;
+ std::ofstream ofs;
+ std::string filename = TestModuleFilename(processName);
+ std::string moduleName = TestModuleName(processName);
+ ofs.open(filename, std::ofstream::out | std::ofstream::app);
+ const int BUFSIZE = 256;
+ char buffer[BUFSIZE];
+
+ // Run test cases in child process( to handle signals ), but run serially.
+ for(uint32_t i = 0; tc_array[i].name; i++)
{
- fprintf(fp,
- " <suite name=\"%s\">\n"
- " <total_case>%d</total_case>\n"
- " <pass_case>%d</pass_case>\n"
- " <pass_rate>%5.2f</pass_rate>\n"
- " <fail_case>%d</fail_case>\n"
- " <fail_rate>%5.2f</fail_rate>\n"
- " <block_case>0</block_case>\n"
- " <block_rate>0.00</block_rate>\n"
- " <na_case>0</na_case>\n"
- " <na_rate>0.00</na_rate>\n"
- " </suite>\n",
- basename(processName),
- numPasses + numFailures,
- numPasses,
- (float)numPasses / (numPasses + numFailures),
- numFailures,
- (float)numFailures / (numPasses + numFailures));
- fclose(fp);
- }
-}
+ auto tt = system_clock::to_time_t(system_clock::now());
+ strftime(buffer, BUFSIZE, "%c", localtime(&tt));
+ std::string startTime(buffer);
-int32_t RunAll(const char* processName, ::testcase tc_array[])
-{
- int32_t numFailures = 0;
- int32_t numPasses = 0;
+ TestCase testCase(i, &tc_array[i]);
+ testCase.result = RunTestCaseInChildProcess(testCase, quiet);
- // Run test cases in child process( to kill output/handle signals ), but run serially.
- for(uint32_t i = 0; tc_array[i].name; i++)
- {
- int32_t result = RunTestCaseInChildProcess(tc_array[i], false);
- if(result == 0)
+ tt = system_clock::to_time_t(system_clock::now());
+ strftime(buffer, BUFSIZE, "%c", localtime(&tt));
+ std::string endTime(buffer);
+
+ if(testCase.result == 0)
{
numPasses++;
}
{
numFailures++;
}
+ if(!quiet)
+ {
+ OutputTestResult(ofs, processName, moduleName, testCase, startTime, endTime);
+ }
}
+ ofs.close();
OutputStatistics(processName, numPasses, numFailures);
}
// Constantly runs up to MAX_NUM_CHILDREN processes
-int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool reRunFailed)
+int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool reRunFailed, bool quiet)
{
int32_t numFailures = 0;
int32_t numPasses = 0;
int32_t pid = fork();
if(pid == 0) // Child process
{
- SuppressLogOutput();
- exit(RunTestCase(tc_array[nextTestCase]));
+ TestCase testCase(nextTestCase, &tc_array[nextTestCase]);
+ int status = RunTestCaseRedirectOutput(testCase, quiet);
+ exit(status);
}
else if(pid == -1)
{
else // Parent process
{
TestCase tc(nextTestCase, tc_array[nextTestCase].name);
- tc.startTime = std::chrono::steady_clock::now();
+ tc.startTime = steady_clock::now();
+ tc.startSystemTime = system_clock::now();
+ tc.childPid = pid;
children[pid] = tc;
nextTestCase++;
{
if(WIFEXITED(status))
{
- int32_t testResult = WEXITSTATUS(status);
- if(testResult)
+ auto& testCase = children[childPid];
+ testCase.result = WEXITSTATUS(status);
+ if(testCase.result)
{
- printf("Test case %s failed: %d\n", children[childPid].testCaseName, testResult);
- failedTestCases.push_back(children[childPid].testCase);
+ printf("Test case %s failed: %d\n", testCase.name, testCase.result);
+ failedTestCases.push_back(testCase.testCase);
numFailures++;
}
else
RunningTestCases::iterator iter = children.find(childPid);
if(iter != children.end())
{
- printf("Test case %s exited with signal %s\n", iter->second.testCaseName, strsignal(status));
+ printf("Test case %s exited with signal %s\n", iter->second.name, strsignal(status));
+ iter->second.result = 1;
failedTestCases.push_back(iter->second.testCase);
}
else
}
}
+ if(!quiet)
+ {
+ OutputTestResults(processName, children);
+ }
+
OutputStatistics(processName, numPasses, numFailures);
if(reRunFailed)
printf("=");
}
printf("\n");
- RunTestCaseInChildProcess(tc_array[failedTestCases[i]], false);
+ int index = failedTestCases[i];
+ TestCase testCase(index, &tc_array[index]);
+ RunTestCaseInChildProcess(testCase, false);
}
}
" %s <testcase name>\t\t Execute a test case\n"
" %s \t\t Execute all test cases in parallel\n"
" %s -r\t\t Execute all test cases in parallel, rerunning failed test cases\n"
- " %s -s\t\t Execute all test cases serially\n",
+ " %s -s\t\t Execute all test cases serially\n"
+ " %s -q\t\t Run without output\n",
+ program,
program,
program,
program,
program);
}
+int RunTests(int argc, char* const argv[], ::testcase tc_array[])
+{
+ int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT;
+ const char* optString = "sfq";
+ bool optRerunFailed(true);
+ bool optRunSerially(false);
+ bool optQuiet(false);
+
+ int nextOpt = 0;
+ do
+ {
+ nextOpt = getopt(argc, argv, optString);
+ switch(nextOpt)
+ {
+ case 'f':
+ optRerunFailed = false;
+ break;
+ case 's':
+ optRunSerially = true;
+ break;
+ case 'q':
+ optQuiet = true;
+ break;
+ case '?':
+ TestHarness::Usage(argv[0]);
+ exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT);
+ break;
+ }
+ } while(nextOpt != -1);
+
+ if(optind == argc) // no testcase name in argument list
+ {
+ if(optRunSerially)
+ {
+ result = TestHarness::RunAll(argv[0], tc_array, optQuiet);
+ }
+ else
+ {
+ result = TestHarness::RunAllInParallel(argv[0], tc_array, optRerunFailed, optQuiet);
+ }
+ }
+ else
+ {
+ // optind is index of next argument - interpret as testcase name
+ result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]);
+ }
+ return result;
+}
+
} // namespace TestHarness
struct TestCase
{
int32_t testCase;
- const char* testCaseName;
+ const char* name;
std::chrono::steady_clock::time_point startTime;
+ std::chrono::system_clock::time_point startSystemTime;
+ int32_t result;
+ pid_t childPid{0};
+ testcase* tctPtr;
+ TestCase(int32_t index, testcase* testCase)
+ : testCase(index),
+ name(testCase->name),
+ startTime(),
+ startSystemTime(),
+ result(0),
+ childPid(0),
+ tctPtr(testCase)
+ {
+ }
TestCase()
: testCase(0),
- testCaseName(NULL),
- startTime()
+ name(NULL),
+ startTime(),
+ startSystemTime(),
+ result(0),
+ childPid(0),
+ tctPtr(nullptr)
{
}
TestCase(int32_t tc, const char* name)
: testCase(tc),
- testCaseName(name),
- startTime()
+ name(name),
+ startTime(),
+ startSystemTime(),
+ result(0),
+ childPid(0),
+ tctPtr(nullptr)
{
}
TestCase(const TestCase& rhs)
: testCase(rhs.testCase),
- testCaseName(rhs.testCaseName),
- startTime(rhs.startTime)
+ name(rhs.name),
+ startTime(rhs.startTime),
+ startSystemTime(rhs.startSystemTime),
+ result(rhs.result),
+ childPid(rhs.childPid),
+ tctPtr(rhs.tctPtr)
{
}
TestCase& operator=(const TestCase& rhs)
{
- testCase = rhs.testCase;
- testCaseName = rhs.testCaseName;
- startTime = rhs.startTime;
+ testCase = rhs.testCase;
+ name = rhs.name;
+ startTime = rhs.startTime;
+ startSystemTime = rhs.startSystemTime;
+ result = rhs.result;
+ childPid = rhs.childPid;
+ tctPtr = rhs.tctPtr;
return *this;
}
};
*/
void Usage(const char* program);
+/**
+ * Main function.
+ * @param[in] argc Argument count
+ * @param[in] argv Argument vector
+ * @param[in] tc_array Array of test cases
+ */
+int RunTests(int argc, char* const argv[], ::testcase tc_array[]);
+
} // namespace TestHarness
#endif
, mDefaultTextEncodingName()
, mDefaultFontSize( 16 )
, mEvaluating( false )
+ , mScrollPosition( 0, 0 )
+ , mScrollSize( 500, 500 )
+ , mContentSize( 500, 500 )
{
gInstanceCount++;
gInstance = this;
mDefaultFontSize = defaultFontSize;
}
+ void ScrollBy( int dx, int dy )
+ {
+ mScrollPosition += Dali::Vector2( dx, dy );
+ if ( mScrollPosition.y + mScrollSize.height > mContentSize.height )
+ {
+ gInstance->mScrollEdgeReachedSignal.Emit( Dali::WebEnginePlugin::ScrollEdge::BOTTOM );
+ }
+ }
+
+ void SetScrollPosition( int x, int y )
+ {
+ mScrollPosition.x = x;
+ mScrollPosition.y = y;
+ }
+
+ void GetScrollPosition( int& x, int& y ) const
+ {
+ x = mScrollPosition.x;
+ y = mScrollPosition.y;
+ }
+
+ void GetScrollSize( int& w, int& h ) const
+ {
+ w = mScrollSize.width;
+ h = mScrollSize.height;
+ }
+
+ void GetContentSize( int& w, int& h ) const
+ {
+ w = mContentSize.width;
+ h = mContentSize.height;
+ }
+
Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal()
{
return mPageLoadStartedSignal;
return mPageLoadErrorSignal;
}
+ Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal()
+ {
+ return mScrollEdgeReachedSignal;
+ }
+
std::string mUrl;
std::vector< std::string > mHistory;
size_t mCurrentPlusOnePos;
Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType mPageLoadErrorSignal;
std::vector< std::function< void( const std::string& ) > > mResultCallbacks;
bool mEvaluating;
+
+ Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
+ Dali::Vector2 mScrollPosition;
+ Dali::Vector2 mScrollSize;
+ Dali::Vector2 mContentSize;
};
inline WebEngine& GetImplementation( Dali::WebEngine& webEngine )
Internal::Adaptor::GetImplementation( *this ).SetDefaultFontSize( defaultFontSize );
}
+void WebEngine::ScrollBy( int dx, int dy )
+{
+ Internal::Adaptor::GetImplementation( *this ).ScrollBy( dx, dy );
+}
+
+void WebEngine::SetScrollPosition( int x, int y )
+{
+ Internal::Adaptor::GetImplementation( *this ).SetScrollPosition( x, y );
+}
+
+void WebEngine::GetScrollPosition( int& x, int& y ) const
+{
+ Internal::Adaptor::GetImplementation( *this ).GetScrollPosition( x, y );
+}
+
+void WebEngine::GetScrollSize( int& w, int& h ) const
+{
+ Internal::Adaptor::GetImplementation( *this ).GetScrollSize( w, h );
+}
+
+void WebEngine::GetContentSize( int& w, int& h ) const
+{
+ Internal::Adaptor::GetImplementation( *this ).GetContentSize( w, h );
+}
+
void WebEngine::SetSize( int width, int height )
{
}
return Internal::Adaptor::GetImplementation( *this ).PageLoadErrorSignal();
}
+Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& WebEngine::ScrollEdgeReachedSignal()
+{
+ return Internal::Adaptor::GetImplementation( *this ).ScrollEdgeReachedSignal();
+}
+
} // namespace Dali;
-#include <string.h>
-#include <getopt.h>
-#include <stdlib.h>
#include <test-harness.h>
#include "tct-dali-toolkit-core.h"
int main(int argc, char * const argv[])
{
- int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT;
-
- const char* optString = "sf";
- bool optRerunFailed(true);
- bool optRunSerially(false);
-
- int nextOpt = 0;
- do
- {
- nextOpt = getopt( argc, argv, optString );
- switch(nextOpt)
- {
- case 'f':
- optRerunFailed = false;
- break;
- case 's':
- optRunSerially = true;
- break;
- case '?':
- TestHarness::Usage(argv[0]);
- exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT);
- break;
- }
- } while( nextOpt != -1 );
-
- if( optind == argc ) // no testcase name in argument list
- {
- if( optRunSerially )
- {
- result = TestHarness::RunAll( argv[0], tc_array );
- }
- else
- {
- result = TestHarness::RunAllInParallel( argv[0], tc_array, optRerunFailed );
- }
- }
- else
- {
- // optind is index of next argument - interpret as testcase name
- result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]);
- }
- return result;
+ return TestHarness::RunTests(argc, argv, tc_array);
}
application.SendNotification();
application.Render();
+ // Check resource status
+ Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
+ DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
+
+ // The broken image should be shown.
DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
static int gPageLoadStartedCallbackCalled = 0;
static int gPageLoadFinishedCallbackCalled = 0;
+static int gScrollEdgeReachedCallbackCalled = 0;
static int gEvaluateJavaScriptCallbackCalled = 0;
static bool gTouched = false;
gPageLoadFinishedCallbackCalled++;
}
+static void OnScrollEdgeReached( WebView view, Dali::WebEnginePlugin::ScrollEdge edge )
+{
+ gScrollEdgeReachedCallbackCalled++;
+}
+
static void OnPageLoadError( WebView view, const std::string& url, WebView::LoadErrorCode errorCode )
{
}
END_TEST;
}
+int UtcDaliWebViewProperty9(void)
+{
+ // SCROLL_POSITION
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+
+ // Check default value
+ Dali::Vector2 output = Dali::Vector2::ONE;
+ view.GetProperty( WebView::Property::SCROLL_POSITION ).Get( output );
+ DALI_TEST_CHECK( output.x == 0 && output.y == 0 );
+
+ // Check Set/GetProperty
+ Dali::Vector2 testValue = Dali::Vector2( 100, 100 );
+ view.SetProperty( WebView::Property::SCROLL_POSITION, testValue );
+ view.GetProperty( WebView::Property::SCROLL_POSITION ).Get( output );
+ DALI_TEST_EQUALS( output, testValue, TEST_LOCATION );
+
+ // Check default value of scroll size
+ output = Dali::Vector2::ONE;
+ view.GetProperty( WebView::Property::SCROLL_SIZE ).Get( output );
+ DALI_TEST_CHECK( output.x == 500 && output.y == 500 );
+
+ // Check default value of content size
+ output = Dali::Vector2::ONE;
+ view.GetProperty( WebView::Property::CONTENT_SIZE ).Get( output );
+ DALI_TEST_CHECK( output.x == 500 && output.y == 500 );
+
+ END_TEST;
+}
+
+int UtcDaliWebViewScrollBy(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+
+ // load url.
+ ConnectionTracker* testTracker = new ConnectionTracker();
+ view.ScrollEdgeReachedSignal().Connect( &OnScrollEdgeReached );
+ bool signal1 = false;
+ view.ConnectSignal( testTracker, "scrollEdgeReached", CallbackFunctor(&signal1) );
+ DALI_TEST_EQUALS( gScrollEdgeReachedCallbackCalled, 0, TEST_LOCATION );
+
+ view.LoadUrl( TEST_URL1 );
+ Test::EmitGlobalTimerSignal();
+
+ // set scroll position.
+ Dali::Vector2 output = Dali::Vector2::ONE;
+ Dali::Vector2 testValue = Dali::Vector2( 100, 100 );
+ view.SetProperty( WebView::Property::SCROLL_POSITION, testValue );
+ view.GetProperty( WebView::Property::SCROLL_POSITION ).Get( output );
+ DALI_TEST_EQUALS( output, testValue, TEST_LOCATION );
+
+ // scroll by and trigger scrollEdgeReached event.
+ view.ScrollBy( 50, 50 );
+ view.GetProperty( WebView::Property::SCROLL_POSITION ).Get( output );
+ DALI_TEST_CHECK( output.x == 150 && output.y == 150 );
+ DALI_TEST_EQUALS( gScrollEdgeReachedCallbackCalled, 1, TEST_LOCATION );
+ DALI_TEST_CHECK( signal1 );
+
+ END_TEST;
+}
+
int UtcDaliWebViewEvaluteJavaScript(void)
{
ToolkitTestApplication application;
+++ /dev/null
-scripts/tcbuild.sh
\ No newline at end of file
--- /dev/null
+#!/bin/bash
+
+#---------- DEBUG_BEGIN ----------
+#ARG="-d" # debug-on flag, might be set as $1
+# keyprompt "introductory message" -- wait until any key pressed
+function keyprompt { echo -ne "\n\e[1;31m$1 -- " && read -n 1 && echo -e "\n\e[0m"; }
+# d_bp -- breakpoint at which user need to press any key to proceed
+function d_bp { if [[ "$ARG" == "-d" ]]; then keyprompt "d >> Press any key"; fi }
+# d_showVar VARNAME -- print bash variable name
+function d_showVar { if [ "$ARG" == "-d" -a -n "$1" ]; then echo "d >> ${1} = ${!1}"; fi }
+# d_print "message" -- print a debug message
+function d_print { if [ "$ARG" == "-d" -a -n "$1" ]; then echo -e "d >> $1"; fi }
+#---------- DEBUG_END ----------
+
+PROJECT_DIR="$(cd "$(dirname $0)" && pwd)"
+d_showVar PROJECT_DIR
+
+function gbs_profile {
+perl -e "
+use Config::Tiny;
+my \$Config = Config::Tiny->read( \"\$ENV{HOME}/.gbs.conf\" );
+my \$profile = \$Config->{general}->{profile};
+\$profile =~ s/profile.//;
+print \$profile;"
+}
+
+PROFILE=`gbs_profile`
+RPM_DIR="$HOME/GBS-ROOT/local/repos/$PROFILE/armv7l/RPMS"
+d_showVar RPM_DIR
+
+function add_module {
+ # argument check
+ if [ -z "$1" ]; then echo "Usage: `basename $0` addmod <module_name> [module_lib_name]"; exit 1; fi
+
+ MODULE_NAME=$1
+ d_showVar MODULE_NAME
+ MODULE_NAME_C=$(echo $MODULE_NAME | sed -e 's/-\([a-z]\)/\U\1/' -e 's/^\([a-z]\)/\U\1/')
+ d_showVar MODULE_NAME_C
+ MODULE_NAME_U=$(echo $MODULE_NAME | sed -e 's/-/_/')
+ d_showVar MODULE_NAME_U
+# MODULE_LIBNAME=${2:-capi-$MODULE_NAME}
+ MODULE_LIBNAME=$1
+ d_showVar MODULE_LIBNAME
+
+ echo "Adding $MODULE_NAME module to project..."
+ d_bp
+ cd $PROJECT_DIR
+ # prepare .spec file
+ echo "-- Generating packaging/core-$MODULE_NAME-tests.spec file"
+ if [ ! -d packaging ]; then mkdir packaging; fi
+ sed -e "s:\[MODULE_NAME\]:$MODULE_NAME:g" -e "s:\[MODULE_LIBNAME\]:$MODULE_LIBNAME:g" \
+ templates/core-\[module_name\]-tests.spec > packaging/core-$MODULE_NAME-tests.spec
+ # prepare src directory
+ mkdir src/$MODULE_NAME
+ echo "-- Generating src/$MODULE_NAME/CMakeLists.txt file"
+ sed -e "s:%{MODULE_NAME}:$MODULE_NAME:g" -e "s:%{MODULE_LIBNAME}:$MODULE_LIBNAME:g" \
+ templates/src-directory/CMakeLists.txt > src/$MODULE_NAME/CMakeLists.txt
+ echo "-- Generating src/$MODULE_NAME/tct-$MODULE_NAME-core.c file"
+ sed -e "s:%{MODULE_NAME}:$MODULE_NAME:g" \
+ templates/src-directory/tct-\[module_name\]-core.c > src/$MODULE_NAME/tct-$MODULE_NAME-core.c
+ echo "-- Generating src/$MODULE_NAME/utc-$MODULE_NAME.c file"
+ sed -e "s:%{MODULE_NAME_U}:$MODULE_NAME_U:g" -e "s:%{MODULE_NAME_C}:$MODULE_NAME_C:g" \
+ templates/src-directory/utc-\[module_name\].c > src/$MODULE_NAME/utc-$MODULE_NAME.c
+ echo "Task finished successfully"
+}
+
+function rm_module {
+ # argument check
+ if [ -z "$1" ]; then echo "Usage: `basename $0` rmmod <module_name>"; exit 1; fi
+
+ MODULE_NAME=$1
+ d_showVar MODULE_NAME
+
+ echo "Removing $MODULE_NAME module from project..."
+ d_bp
+ echo "---- Updating /opt/tct/packages/package_list.xml"
+ scripts/tcpackageslistsgen.sh $MODULE_NAME /opt/tct/packages/package_list.xml 1
+ if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
+ # echo "---- Updating test plans"
+ # scripts/tcpackageslistsgen.sh $MODULE_NAME /opt/tct/manager/plan/*.xml 1
+ # if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
+
+ cd $PROJECT_DIR
+ echo "-- Removing packaging/core-$MODULE_NAME-tests.spec file"
+ rm packaging/core-$MODULE_NAME-tests.spec
+ echo "-- Removing src/$MODULE_NAME directory"
+ rm -r src/$MODULE_NAME
+ echo "Task finished successfully"
+}
+
+function build {
+ if [ -n "$1" ]; then
+ (cd src/$1; ../../scripts/tcheadgen.sh tct-$1-core.h)
+ if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
+ cp packaging/core-$1-tests.spec ../packaging
+ cp .gitignore-without-autogenerated-files .gitignore
+ gbs build -A armv7l --spec core-$1-tests.spec --include-all --keep-packs | \
+ tee build.log | stdbuf -o0 sed -e 's/error:/\x1b[1;91m&\x1b[0m/' \
+ -e 's/warning:/\x1b[93m&\x1b[0m/'
+ rm ../packaging/core-$1-tests.spec
+ cp .gitignore-with-autogenerated-files .gitignore
+ else
+ echo "Build requires a module name"
+ exit 1
+ fi
+}
+
+function inst {
+ if [ -z "$1" ]
+ then
+ for mod in `ls -1 src/ | grep -v CMakeLists`
+ do
+
+ if [ $mod != 'common' ] && [ $mod != 'manual' ]; then
+
+ PKG_NAME="core-$mod-tests"
+ d_showVar PKG_NAME
+ VER=$(cat packaging/$PKG_NAME.spec | awk '/^Version:/ { print $2; exit; }')
+ d_showVar VER
+ PKG_VNAME="$PKG_NAME-$VER"
+ d_showVar PKG_VNAME
+ PKG_FNAME="$PKG_VNAME-0.armv7l.rpm"
+ d_showVar PKG_FNAME
+
+ if [ -f "$RPM_DIR/$PKG_FNAME" ]
+ then
+ inst $mod
+ echo ""
+ fi
+ fi
+ done
+ else
+ cd $PROJECT_DIR
+ # setting variables
+ MOD_NAME="$1"
+ d_showVar MOD_NAME
+ PKG_NAME="core-$MOD_NAME-tests"
+ d_showVar PKG_NAME
+ VER=$(cat packaging/$PKG_NAME.spec | awk '/^Version:/ { print $2; exit; }')
+ d_showVar VER
+ PKG_VNAME="$PKG_NAME-$VER"
+ d_showVar PKG_VNAME
+ PKG_FNAME="$PKG_VNAME-0.armv7l.rpm"
+ d_showVar PKG_FNAME
+ TCT_DIR="opt/tct-$MOD_NAME-core-tests"
+ d_showVar TCT_DIR
+
+ echo "Deploying $MOD_NAME suite to tct-mgr..."
+ d_bp
+ # prepare tct directory and files
+ echo "-- Preparing suite .zip file..."
+ echo "---- Creating /tmp/$TCT_DIR directory"
+ rm -r /tmp/opt > /dev/null 2>&1
+ mkdir -p /tmp/$TCT_DIR
+ # README
+ echo "---- Copying /tmp/$TCT_DIR"
+ cp templates/tct-package/README /tmp/$TCT_DIR
+ # rpm
+ echo "---- Copying /tmp/$TCT_DIR package"
+ cp $RPM_DIR/$PKG_FNAME /tmp/$TCT_DIR
+ if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
+ # inst.sh
+ echo "---- Generating /tmp/$TCT_DIR/inst.sh file"
+ sed -e "s:%{PKG_NAME}:\"$PKG_NAME\":g" -e "s:%{PKG_FULLNAME}:\"$PKG_FNAME\":g" \
+ -e "s:%{PKG_DIR}:\"/opt/usr/media/tct/$TCT_DIR\":g" \
+ templates/tct-package/inst.sh > /tmp/$TCT_DIR/inst.sh
+ chmod a+x /tmp/$TCT_DIR/inst.sh
+ # tests.xml
+ echo "---- Generating /tmp/$TCT_DIR"
+ scripts/tctestsgen.sh $MOD_NAME /tmp/$TCT_DIR target
+ if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
+ # zip
+ echo "---- Preparing /tmp/tct/packages/tct-$MOD_NAME-core-tests-2.2.1-1.zip file"
+ # clear old zips
+ rm -r /tmp/tct/packages > /dev/null 2>&1
+ mkdir -p /tmp/tct/packages
+ # create new zip
+ ( cd /tmp; zip -r /tmp/tct/packages/tct-$MOD_NAME-core-tests-2.2.1-1.zip opt > /dev/null 2>&1; )
+ # deployment
+ echo "-- Suite deployment..."
+ echo "---- Copying /opt/tct/packages/tct-$MOD_NAME-core-tests-2.2.1-1.zip"
+ cp /tmp/tct/packages/tct-$MOD_NAME-core-tests-2.2.1-1.zip /opt/tct/packages/
+ echo "---- Updating /opt/tct/packages/package_list.xml"
+ scripts/tcpackageslistsgen.sh $MOD_NAME /opt/tct/packages/package_list.xml 0
+ if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
+ # echo "---- Updating test plans"
+ # for file in `grep -r tct-$MOD_NAME-core-tests /opt/tct/manager/plan/ | cut -d: -f1 | uniq`
+ # do
+ # scripts/tcpackageslistsgen.sh $MOD_NAME $file
+ # done
+ # scripts/tcpackageslistsgen.sh $MOD_NAME /opt/tct/manager/plan/Full_test.xml
+ # if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
+ echo "Task finished successfully"
+ fi
+}
+
+if [ -z "$1" ]; then
+ # usage note
+ echo "Usage: `basename $0` <addmod|rmmod|build|install> <module_name> [module_lib_name]"
+ exit 1
+elif [ "addmod" == "$1" ]; then
+ # add new module
+ add_module $2 $3
+elif [ "rmmod" == "$1" ]; then
+ # remove module
+ rm_module $2
+elif [ "build" == "$1" ]; then
+ # build the binary
+ build $2
+elif [ "install" == "$1" ]; then
+ # install
+ inst $2
+else
+ echo "Invalid subcommand: $1"
+fi
SET(LIBTYPE STATIC)
ENDIF()
+# Generate source files for shaders
+SET(SHADER_SOURCE_DIR "${ROOT_SRC_DIR}/dali-toolkit/internal/graphics/shaders/")
+SET(SHADER_GENERATED_DIR "${ROOT_SRC_DIR}/dali-toolkit/internal/graphics/generated")
+EXECUTE_PROCESS( COMMAND bash -c "${CMAKE_CURRENT_SOURCE_DIR}/shader-generator.sh ${SHADER_SOURCE_DIR} ${SHADER_GENERATED_DIR}" )
+
+SET(GENERATED_SHADER_DIR ${ROOT_SRC_DIR}/dali-toolkit/internal/graphics/)
+SET_PROPERTY(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
+ "${GENERATED_SHADER_DIR}/generated/"
+ "${GENERATED_SHADER_DIR}/builtin-shader-extern-gen.h")
+
IF( WIN32 OR APPLE )
SET( DALICORE_LDFLAGS
"${DALICORE_LDFLAGS}"
target_link_libraries(${name} log)
endif()
+# Generate source files for shaders
+SET(SHADER_SOURCE_DIR "${scene_loader_dir}/internal/graphics/shaders/")
+SET(SHADER_GENERATED_DIR "${scene_loader_dir}/internal/graphics/generated")
+EXECUTE_PROCESS( COMMAND bash -c "${repo_root_dir}/build/tizen/shader-generator.sh ${SHADER_SOURCE_DIR} ${SHADER_GENERATED_DIR}" )
+
+SET(GENERATED_SHADER_DIR ${scene_loader_dir}/internal/graphics/)
+SET_PROPERTY(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
+ "${GENERATED_SHADER_DIR}/generated/"
+ "${GENERATED_SHADER_DIR}/builtin-shader-extern-gen.h")
+
IF( INSTALL_CMAKE_MODULES )
SET_TARGET_PROPERTIES( ${name}
PROPERTIES
--- /dev/null
+#!/bin/bash
+
+indir=$1
+outdir=$2
+
+mkdir -p $outdir
+
+if [ ! -e $indir ] ; then
+ echo "Error! "$indir" not found!"
+ exit 0
+fi
+
+cd $indir
+all_shaders=$(ls -1 *.{vert,frag,def})
+cd $OLDPWD
+
+# Generate one header file per shader which is defined as a const std::string_view
+for name in $all_shaders ; do
+ echo "Generating header files for $name..."
+ varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;')
+
+ newname=$(echo ${name} | sed -e 's/\./-/;')".h"
+ echo Writing $newname
+
+ shader_fullpath=$(echo ${indir})$name
+
+ header_name="${varname}_GEN_H"
+ echo "const std::string_view" "$varname""{" > $outdir/$newname
+ cat $shader_fullpath | sed -e 's/^..*$/"&\\n"/' >> $outdir/$newname
+ echo "};" >> $outdir/$newname
+done
+
+# Generate one cpp file that includes all the previously generated string_views for shaders
+echo "Generating cpp file..."
+echo -e "#include \"../builtin-shader-extern-gen.h\"\n" > $outdir/builtin-shader-gen.cpp
+
+varnames=
+for name in $all_shaders ; do
+ varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;')
+ newname=$(echo ${name} | sed -e 's/\./-/;')".h"
+ varnames="${varnames} $varname"
+ echo "#include \"$newname\"" >> $outdir/builtin-shader-gen.cpp
+done
+
+# Generate one header file that defines all the shader string_views as extern variables
+echo "Generating extern header file ( for external use )..."
+echo "#ifndef GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H" > $outdir/../builtin-shader-extern-gen.h
+echo -e "#define GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H\n" >> $outdir/../builtin-shader-extern-gen.h
+
+echo "#include <string_view>" >> $outdir/../builtin-shader-extern-gen.h
+echo "" >> $outdir/../builtin-shader-extern-gen.h
+
+for name in $all_shaders ; do
+ varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;')
+ newname=$(echo ${name} | sed -e 's/\./-/;')".h"
+ echo "extern const std::string_view $varname;" >> $outdir/../builtin-shader-extern-gen.h
+done
+cat >> $outdir/../builtin-shader-extern-gen.h << EOF
+
+#endif // GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H
+EOF
+
--- /dev/null
+#version 300 es
+
+precision mediump float;
+flat in float vColor;
+out vec4 FragColor;
+
+void main()
+{
+ vec3 rgb = vec3(fract(vColor), fract(vColor * 0.00390625), fract(vColor * 0.00390625 * 0.00390625));
+ FragColor = vec4(rgb, 1.);
+}
\ No newline at end of file
--- /dev/null
+#version 300 es
+
+precision mediump float;
+uniform mat4 uMvpMatrix;
+in vec3 aPosition;
+in float aColor;
+flat out float vColor;
+
+void main()
+{
+ vColor = aColor;
+ gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
+}
\ No newline at end of file
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "dali-scene-loader/public-api/blend-shape-details.h"
#include "dali-scene-loader/public-api/utils.h"
#include "dali-scene-loader/public-api/skinning-details.h"
+#include "dali-scene-loader/internal/graphics/builtin-shader-extern-gen.h"
//#define DEBUG_SCENE_DEFINITION
//#define DEBUG_JOINTS
#ifdef DEBUG_JOINTS
-const char* JOINT_DEBUG_VSH = "#version 300 es\n"
-DALI_COMPOSE_SHADER(
- precision mediump float;
- uniform mat4 uMvpMatrix;
- in vec3 aPosition;
- in float aColor;
- flat out float vColor;
- void main() {
- vColor = aColor;
- gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
- });
-
-const char* JOINT_DEBUG_FSH = "#version 300 es\n"
-DALI_COMPOSE_SHADER(
- precision mediump float;
- flat in float vColor;
- out vec4 FragColor;
- void main() {
- vec3 rgb = vec3(fract(vColor), fract(vColor * 0.00390625), fract(vColor * 0.00390625 * 0.00390625));
- FragColor = vec4(rgb, 1.);
- });
Shader sJointDebugShader;
int sNumScenes = 0;
{
if (0 == sNumScenes)
{
- sJointDebugShader = Shader::New(JOINT_DEBUG_VSH, JOINT_DEBUG_FSH);
+ sJointDebugShader = Shader::New(SHADER_SCENE_LOADER_JOINT_DEBUG_VERT, SHADER_SCENE_LOADER_JOINT_DEBUG_FRAG);
}
++sNumScenes;
}
Dali::Toolkit::GetImpl(*this).Resume();
}
+void WebView::ScrollBy( int deltaX, int deltaY )
+{
+ Dali::Toolkit::GetImpl( *this ).ScrollBy( deltaX, deltaY );
+}
+
bool WebView::CanGoForward()
{
return Dali::Toolkit::GetImpl(*this).CanGoForward();
return Dali::Toolkit::GetImpl(*this).PageLoadErrorSignal();
}
+WebView::WebViewScrollEdgeReachedSignalType& WebView::ScrollEdgeReachedSignal()
+{
+ return Dali::Toolkit::GetImpl( *this ).ScrollEdgeReachedSignal();
+}
+
WebView::WebView(Internal::WebView& implementation)
: Control(implementation)
{
#include <functional>
// INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
#include <dali-toolkit/public-api/controls/control.h>
namespace Dali
* @details Name "defaultFontSize", type Property::INT.
* @note Default is 16.
*/
- DEFAULT_FONT_SIZE
+ DEFAULT_FONT_SIZE,
+
+ /**
+ * @brief The current position of scroll.
+ * @details Name "scrollPosition", type Property::VECTOR2.
+ */
+ SCROLL_POSITION,
+
+ /**
+ * @brief The current position of scroll.
+ * @details Name "scrollSize", type Property::VECTOR2. Read-only.
+ */
+ SCROLL_SIZE,
+
+ /**
+ * @brief The current position of scroll.
+ * @details Name "contentSize", type Property::VECTOR2. Read-only.
+ */
+ CONTENT_SIZE,
};
};
*/
typedef Signal<void(WebView, const std::string&, LoadErrorCode)> WebViewPageLoadErrorSignalType;
+ /**
+ * @brief WebView signal type related with scroll edge reached.
+ */
+ typedef Signal<void(WebView, Dali::WebEnginePlugin::ScrollEdge)> WebViewScrollEdgeReachedSignalType;
+
public:
/**
* @brief Creates an initialized WebView.
void Resume();
/**
+ * @brief Scrolls the webpage of view by deltaX and deltaY.
+ * @param[in] deltaX The delta x of scroll
+ * @param[in] deltaY The delta y of scroll
+ */
+ void ScrollBy( int deltaX, int deltaY );
+
+ /**
* @brief Returns whether forward is possible.
*
* @return True if forward is possible, false otherwise
*/
WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
+ /**
+ * @brief Connects to this signal to be notified when scroll edge is reached.
+ *
+ * @return A signal object to connect with.
+ */
+ WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
+
public: // Not intended for application developers
/// @cond internal
/**
${devel_api_src_dir}/image-loader/image-atlas.cpp
${devel_api_src_dir}/image-loader/texture-manager.cpp
${devel_api_src_dir}/layouting/flex-node.cpp
+ ${devel_api_src_dir}/shader-effects/alpha-discard-effect.cpp
+ ${devel_api_src_dir}/shader-effects/dissolve-effect.cpp
+ ${devel_api_src_dir}/shader-effects/distance-field-effect.cpp
+ ${devel_api_src_dir}/shader-effects/image-region-effect.cpp
+ ${devel_api_src_dir}/shader-effects/motion-blur-effect.cpp
+ ${devel_api_src_dir}/shader-effects/motion-stretch-effect.cpp
${devel_api_src_dir}/styling/style-manager-devel.cpp
${devel_api_src_dir}/text/bitmap-font.cpp
${devel_api_src_dir}/text/text-utils-devel.cpp
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/shader-effects/alpha-discard-effect.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+
+Property::Map CreateAlphaDiscardEffect()
+{
+ Property::Map map;
+
+ Property::Map customShader;
+ customShader[Visual::Shader::Property::FRAGMENT_SHADER] = SHADER_ALPHA_DISCARD_EFFECT_FRAG.data();
+
+ map[Toolkit::Visual::Property::SHADER] = customShader;
+ return map;
+}
+
+} // namespace Toolkit
+} // namespace Dali
#define DALI_TOOLKIT_ALPHA_DISCARD_EFFECT_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/object/property-map.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
namespace Dali
{
*
* @return A property map of the required shaders.
*/
-inline Property::Map CreateAlphaDiscardEffect()
-{
- const char* ALPHA_DISCARD_FRAGMENT_SHADER_SOURCE =
- "varying mediump vec2 vTexCoord; \n"
- " \n"
- "uniform sampler2D sTexture; \n"
- "uniform lowp vec4 uColor; \n"
- "void main() \n"
- "{ \n"
- " mediump vec4 color = texture2D( sTexture, vTexCoord ); \n"
- " if(color.a <= 0.0001) \n"
- " { \n"
- " discard; \n"
- " } \n"
- " gl_FragColor = color * uColor; \n"
- "} \n";
-
- Property::Map map;
-
- Property::Map customShader;
- customShader[Visual::Shader::Property::FRAGMENT_SHADER] = ALPHA_DISCARD_FRAGMENT_SHADER_SOURCE;
-
- map[Toolkit::Visual::Property::SHADER] = customShader;
- return map;
-}
+DALI_TOOLKIT_API Property::Map CreateAlphaDiscardEffect();
} // namespace Toolkit
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/shader-effects/dissolve-effect.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/rendering/shader.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+void DissolveEffectSetCentralLine( Actor& actor, const Vector2& position, const Vector2& displacement, float initialProgress )
+{
+ // the line passes through 'position' and has the direction of 'displacement'
+ float coefA, coefB, coefC; //line equation: Ax+By+C=0;
+ coefA = displacement.y;
+ coefB = -displacement.x;
+ coefC = -displacement.y * position.x + displacement.x * position.y;
+
+ float inversedAABB = 1.f / (coefA * coefA + coefB * coefB);
+ float inversedSqrtAABB = sqrtf(inversedAABB);
+ float saddleA;
+
+ //saddle surface(Hyperbolic paraboloid)function, used to calculate the dissolve starting time
+ //z = y*y/a/a - x*x/b/b
+ //with our selection of parameters(a and b), this value for any texture coordinate is between -1.0 and 1.0
+
+ Vector3 saddleParam; // [0]: a*a, [1]: b*b, [2] b
+ Vector2 translation;
+ Vector2 rotation;
+ float toNext = -1.f;
+ if(displacement.x > 0.f || (EqualsZero(displacement.x) && displacement.y > 0.f))
+ {
+ toNext = 1.f;
+ }
+
+ if((displacement.y * displacement.x < 0.0f))
+ {
+ //distance from (0,0) to the line
+ float distanceTopLeft = fabsf(coefC) * inversedSqrtAABB;
+ //distance from (1, 1 ) to the line
+ float distanceBottomRight = fabsf(coefA + coefB + coefC) * inversedSqrtAABB;
+ saddleA = std::max(distanceTopLeft, distanceBottomRight);
+
+ //foot of a perpendicular: (1,0) to the line
+ float footX1 = (coefB * coefB - coefA * coefC) * inversedAABB;
+ float footY1 = (-coefA * coefB - coefB * coefC) * inversedAABB;
+ //foot of a perpendicular: (0,1) to the line
+ float footX2 = (-coefA * coefB - coefA * coefC) * inversedAABB;
+ float footY2 = (coefA * coefA - coefB * coefC) * inversedAABB;
+ saddleParam[1] = (footX1 - footX2) * (footX1 - footX2) + (footY1 - footY2) * (footY1 - footY2);
+ translation = Vector2(-footX2, -footY2);
+ }
+ else
+ {
+ //distance from(1,0) to the line
+ float distanceTopRight = fabsf(coefA + coefC) * inversedSqrtAABB;
+ //distance from(0,1) to the line
+ float distanceBottomLeft = fabsf(coefB + coefC) * inversedSqrtAABB;
+ saddleA = std::max(distanceTopRight, distanceBottomLeft);
+ //foot of a perpendicular: (0,0) to the line
+ float footX3 = (-coefA * coefC) * inversedAABB;
+ float footY3 = (-coefB * coefC) * inversedAABB;
+ //foot of a perpendicular: (1.0,1.0) to the line
+ float footX4 = (coefB * coefB - coefA * coefB - coefA * coefC) * inversedAABB;
+ float footY4 = (-coefA * coefB + coefA * coefA - coefB * coefC) * inversedAABB;
+ saddleParam[1] = (footX3 - footX4) * (footX3 - footX4) + (footY3 - footY4) * (footY3 - footY4);
+ translation = Vector2(-footX3, -footY3);
+ }
+
+ saddleParam[2] = sqrtf(saddleParam[1]);
+ saddleParam[0] = saddleA * saddleA;
+ rotation = Vector2(-displacement.x, displacement.y);
+ rotation.Normalize();
+
+ actor.RegisterProperty("uSaddleParam", saddleParam);
+ actor.RegisterProperty("uTranslation", translation);
+ actor.RegisterProperty("uRotation", rotation);
+ actor.RegisterProperty("uToNext", toNext);
+ actor.RegisterProperty("uPercentage", initialProgress, Dali::Property::ANIMATABLE);
+}
+
+Property::Map CreateDissolveEffect( bool useHighPrecision )
+{
+ const char* prefixHighPrecision("precision highp float;\n");
+ const char* prefixMediumPrecision("precision mediump float;\n");
+
+ const char* vertexShader = SHADER_DISSOLVE_EFFECT_VERT.data();
+ const char* fragmentShader = SHADER_DISSOLVE_EFFECT_FRAG.data();
+
+ Property::Map map;
+
+ Property::Map customShader;
+
+ std::string vertexShaderString;
+ std::string fragmentShaderString;
+ if(useHighPrecision)
+ {
+ vertexShaderString.reserve(strlen(prefixHighPrecision) + strlen(vertexShader));
+ vertexShaderString.append(prefixHighPrecision);
+
+ fragmentShaderString.reserve(strlen(prefixHighPrecision) + strlen(fragmentShader));
+ fragmentShaderString.append(prefixHighPrecision);
+ }
+ else
+ {
+ vertexShaderString.reserve(strlen(prefixMediumPrecision) + strlen(vertexShader));
+ vertexShaderString.append(prefixMediumPrecision);
+
+ fragmentShaderString.reserve(strlen(prefixMediumPrecision) + strlen(fragmentShader));
+ fragmentShaderString.append(prefixMediumPrecision);
+ }
+
+ vertexShaderString.append(vertexShader);
+ fragmentShaderString.append(fragmentShader);
+
+ customShader[Visual::Shader::Property::VERTEX_SHADER] = vertexShaderString;
+ customShader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShaderString;
+
+ customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 20;
+ customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 20;
+
+ customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
+
+ map[Toolkit::Visual::Property::SHADER] = customShader;
+ return map;
+}
+
+} // namespace Toolkit
+
+} // namespace Dali
#define DALI_TOOLKIT_SHADER_EFFECT_DISSOLVE_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// EXTERNAL INCLUDES
-#include <dali/public-api/rendering/shader.h>
#include <string.h>
+#include <dali/public-api/actors/actor.h>
+#include <dali/public-api/math/vector2.h>
+#include <dali/public-api/object/property-map.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
#include <dali-toolkit/public-api/visuals/visual-properties.h>
namespace Dali
* @param[in] displacement The direction of the central line
* @param[in] initialProgress The normalised initial progress of the shader
*/
-inline void DissolveEffectSetCentralLine(Actor& actor, const Vector2& position, const Vector2& displacement, float initialProgress)
-{
- // the line passes through 'position' and has the direction of 'displacement'
- float coefA, coefB, coefC; //line equation: Ax+By+C=0;
- coefA = displacement.y;
- coefB = -displacement.x;
- coefC = -displacement.y * position.x + displacement.x * position.y;
-
- float inversedAABB = 1.f / (coefA * coefA + coefB * coefB);
- float inversedSqrtAABB = sqrtf(inversedAABB);
- float saddleA;
-
- //saddle surface(Hyperbolic paraboloid)function, used to calculate the dissolve starting time
- //z = y*y/a/a - x*x/b/b
- //with our selection of parameters(a and b), this value for any texture coordinate is between -1.0 and 1.0
-
- Vector3 saddleParam; // [0]: a*a, [1]: b*b, [2] b
- Vector2 translation;
- Vector2 rotation;
- float toNext = -1.f;
- if(displacement.x > 0.f || (EqualsZero(displacement.x) && displacement.y > 0.f))
- {
- toNext = 1.f;
- }
-
- if((displacement.y * displacement.x < 0.0f))
- {
- //distance from (0,0) to the line
- float distanceTopLeft = fabsf(coefC) * inversedSqrtAABB;
- //distance from (1, 1 ) to the line
- float distanceBottomRight = fabsf(coefA + coefB + coefC) * inversedSqrtAABB;
- saddleA = std::max(distanceTopLeft, distanceBottomRight);
+DALI_TOOLKIT_API void DissolveEffectSetCentralLine( Actor& actor, const Vector2& position, const Vector2& displacement, float initialProgress );
- //foot of a perpendicular: (1,0) to the line
- float footX1 = (coefB * coefB - coefA * coefC) * inversedAABB;
- float footY1 = (-coefA * coefB - coefB * coefC) * inversedAABB;
- //foot of a perpendicular: (0,1) to the line
- float footX2 = (-coefA * coefB - coefA * coefC) * inversedAABB;
- float footY2 = (coefA * coefA - coefB * coefC) * inversedAABB;
- saddleParam[1] = (footX1 - footX2) * (footX1 - footX2) + (footY1 - footY2) * (footY1 - footY2);
- translation = Vector2(-footX2, -footY2);
- }
- else
- {
- //distance from(1,0) to the line
- float distanceTopRight = fabsf(coefA + coefC) * inversedSqrtAABB;
- //distance from(0,1) to the line
- float distanceBottomLeft = fabsf(coefB + coefC) * inversedSqrtAABB;
- saddleA = std::max(distanceTopRight, distanceBottomLeft);
- //foot of a perpendicular: (0,0) to the line
- float footX3 = (-coefA * coefC) * inversedAABB;
- float footY3 = (-coefB * coefC) * inversedAABB;
- //foot of a perpendicular: (1.0,1.0) to the line
- float footX4 = (coefB * coefB - coefA * coefB - coefA * coefC) * inversedAABB;
- float footY4 = (-coefA * coefB + coefA * coefA - coefB * coefC) * inversedAABB;
- saddleParam[1] = (footX3 - footX4) * (footX3 - footX4) + (footY3 - footY4) * (footY3 - footY4);
- translation = Vector2(-footX3, -footY3);
- }
-
- saddleParam[2] = sqrtf(saddleParam[1]);
- saddleParam[0] = saddleA * saddleA;
- rotation = Vector2(-displacement.x, displacement.y);
- rotation.Normalize();
-
- actor.RegisterProperty("uSaddleParam", saddleParam);
- actor.RegisterProperty("uTranslation", translation);
- actor.RegisterProperty("uRotation", rotation);
- actor.RegisterProperty("uToNext", toNext);
- actor.RegisterProperty("uPercentage", initialProgress, Dali::Property::ANIMATABLE);
-}
/**
* @brief Create a new Dissolve effect
*
* @return The newly created Property::Map with the dissolve effect
*/
-inline Property::Map CreateDissolveEffect(bool useHighPrecision = true)
-{
- const char* prefixHighPrecision("precision highp float;\n");
- const char* prefixMediumPrecision("precision mediump float;\n");
-
- const char* vertexShader(
- "attribute mediump vec2 aPosition;\n"
- "\n"
- "uniform mediump mat4 uMvpMatrix;\n"
- "uniform vec3 uSize;\n"
- "uniform vec4 uTextureRect;"
- "\n"
- "uniform float uPercentage;\n"
- "uniform vec3 uSaddleParam;\n"
- "uniform vec2 uTranslation;\n"
- "uniform vec2 uRotation; \n"
- "uniform float uToNext;\n"
- "\n"
- "varying float vPercentage;\n"
- "varying vec2 vTexCoord;\n"
- "\n"
- "void main()\n"
- "{\n"
- " mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n"
- " vertexPosition.xyz *= uSize;\n"
- " vertexPosition = uMvpMatrix * vertexPosition;\n"
- " gl_Position = vertexPosition;\n"
- "\n"
- " vec2 texCoord = aPosition + vec2(0.5);\n"
- " vTexCoord = texCoord;\n"
- "\n"
- " //Calculate the distortion value given the dissolve central line\n"
- " vec2 value = texCoord + uTranslation;\n"
- " mat2 rotateMatrix = mat2(uRotation.s, uRotation.t, -uRotation.t, uRotation.s);\n"
- " value = rotateMatrix * value;\n"
- " if(uToNext == 1.0)\n"
- " value.s = uSaddleParam[2] + value.s;\n"
- " float delay = value.t * value.t / uSaddleParam[0] - value.s * value.s / uSaddleParam[1];\n"
- " vPercentage = clamp(uPercentage * 2.0 - 0.5 * sin(delay * 1.571) - 0.5, 0.0, 1.0);\n"
- "}\n");
-
- const char* fragmentShader(
- "varying float vPercentage;\n"
- "varying mediump vec2 vTexCoord;\n"
- "\n"
- "uniform sampler2D sTexture;\n"
- "uniform lowp vec4 uColor;\n"
- "uniform vec4 uTextureRect;\n"
- "float rand(vec2 co)\n"
- "{\n"
- " return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);\n"
- "}\n"
- "void main()\n"
- "{\n"
- " //Calculate the randomness\n"
- " float offsetS = rand(vTexCoord * vPercentage) - vTexCoord.s;\n"
- " float offsetT = rand(vec2(vTexCoord.t * vPercentage, vTexCoord.s * vPercentage)) - vTexCoord.t;\n"
- " vec2 lookupCoord = vTexCoord + vec2(offsetS, offsetT) * vPercentage;\n"
- " gl_FragColor = texture2D(sTexture, lookupCoord) * uColor;\n"
- " gl_FragColor.a *= 1.0 - vPercentage;\n"
- "}\n");
-
- Property::Map map;
-
- Property::Map customShader;
-
- std::string vertexShaderString;
- std::string fragmentShaderString;
- if(useHighPrecision)
- {
- vertexShaderString.reserve(strlen(prefixHighPrecision) + strlen(vertexShader));
- vertexShaderString.append(prefixHighPrecision);
-
- fragmentShaderString.reserve(strlen(prefixHighPrecision) + strlen(fragmentShader));
- fragmentShaderString.append(prefixHighPrecision);
- }
- else
- {
- vertexShaderString.reserve(strlen(prefixMediumPrecision) + strlen(vertexShader));
- vertexShaderString.append(prefixMediumPrecision);
-
- fragmentShaderString.reserve(strlen(prefixMediumPrecision) + strlen(fragmentShader));
- fragmentShaderString.append(prefixMediumPrecision);
- }
-
- vertexShaderString.append(vertexShader);
- fragmentShaderString.append(fragmentShader);
-
- customShader[Visual::Shader::Property::VERTEX_SHADER] = vertexShaderString;
- customShader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShaderString;
-
- customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 20;
- customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 20;
-
- customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
-
- map[Toolkit::Visual::Property::SHADER] = customShader;
- return map;
-}
+DALI_TOOLKIT_API Property::Map CreateDissolveEffect( bool useHighPrecision = true);
} // namespace Toolkit
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/shader-effects/distance-field-effect.h>
+
+// EXTERNAL INCLUDES
+#include <string.h>
+#include <dali/public-api/rendering/shader.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+Dali::Property::Map CreateDistanceFieldEffect()
+{
+ const char* fragmentShaderPrefix("#extension GL_OES_standard_derivatives : enable\n");
+
+ const char* fragmentShader = SHADER_DISTANCE_FIELD_EFFECT_FRAG.data();
+
+ Property::Map map;
+
+ Property::Map customShader;
+
+ std::string fragmentShaderString;
+ fragmentShaderString.reserve(strlen(fragmentShaderPrefix) + strlen(fragmentShader));
+ fragmentShaderString.append(fragmentShaderPrefix);
+ fragmentShaderString.append(fragmentShader);
+
+ customShader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShaderString;
+ customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
+
+ map[Toolkit::Visual::Property::SHADER] = customShader;
+ return map;
+}
+
+} // namespace Toolkit
+
+} // namespace Dali
#define DALI_TOOLKIT_SHADER_EFFECT_DISTANCEFIELD_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
*/
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
+
// EXTERNAL INCLUDES
#include <dali/public-api/object/property-map.h>
-#include <string.h>
-
-// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/visuals/visual-properties.h>
namespace Dali
{
*
* @return The newly created Property::Map with the distance field effect
*/
-inline Dali::Property::Map CreateDistanceFieldEffect()
-{
- const char* fragmentShaderPrefix("#extension GL_OES_standard_derivatives : enable\n");
-
- const char* fragmentShader(
- "varying mediump vec2 vTexCoord;\n"
- "\n"
- "uniform mediump float uGlowBoundary;\n"
- "uniform mediump vec2 uOutlineParams;\n"
- "uniform lowp vec4 uOutlineColor;\n"
- "uniform lowp vec4 uShadowColor;\n"
- "uniform mediump vec2 uShadowOffset;\n"
- "uniform lowp vec4 uGlowColor;\n"
- "uniform lowp float uDoOutline;\n"
- "uniform lowp float uDoShadow;\n"
- "uniform lowp float uDoGlow;\n"
- "\n"
- "uniform sampler2D sTexture;\n"
- "uniform lowp vec4 uColor;\n"
- "\n"
- "void main()\n"
- "{\n"
- " // sample distance field\n"
- " mediump float smoothing = 0.5;\n"
- " \n"
- " mediump float distance = texture2D(sTexture, vTexCoord).a;\n"
- " mediump float smoothWidth = fwidth(distance);\n"
- " mediump float alphaFactor = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);\n"
- " lowp vec4 color;\n"
- " if (uDoShadow == 0.0)\n"
- " {\n"
- " mediump float alpha = uColor.a * alphaFactor;\n"
- " lowp vec4 rgb = uColor;\n"
- "\n"
- " if (uDoOutline > 0.0)\n"
- " {\n"
- " mediump float outlineWidth = uOutlineParams[1] + smoothWidth;\n"
- " mediump float outlineBlend = smoothstep(uOutlineParams[0] - outlineWidth, uOutlineParams[0] + outlineWidth, distance);\n"
- " alpha = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);\n"
- " rgb = mix(uOutlineColor, uColor, outlineBlend);\n"
- " }\n"
- "\n"
- " if (uDoGlow > 0.0)\n"
- " {\n"
- " rgb = mix(uGlowColor, rgb, alphaFactor);\n"
- " alpha = smoothstep(uGlowBoundary, smoothing, distance);\n"
- " }\n"
- "\n"
- " // set fragment color\n"
- " color = vec4(rgb.rgb, alpha);\n"
- " }\n"
- "\n"
- " else // (uDoShadow > 0.0)\n"
- " {\n"
- " mediump float shadowDistance = texture2D(sTexture, vTexCoord - uShadowOffset).a;\n"
- " mediump float inText = alphaFactor;\n"
- " mediump float inShadow = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, shadowDistance);\n"
- "\n"
- " // inside object, outside shadow\n"
- " if (inText == 1.0)\n"
- " {\n"
- " color = uColor;\n"
- " }\n"
- " // inside object, outside shadow\n"
- " else if ((inText != 0.0) && (inShadow == 0.0))\n"
- " {\n"
- " color = uColor;\n"
- " color.a *= inText;\n"
- " }\n"
- " // outside object, completely inside shadow\n"
- " else if ((inText == 0.0) && (inShadow == 1.0))\n"
- " {\n"
- " color = uShadowColor;\n"
- " }\n"
- " // inside object, completely inside shadow\n"
- " else if ((inText != 0.0) && (inShadow == 1.0))\n"
- " {\n"
- " color = mix(uShadowColor, uColor, inText);\n"
- " color.a = uShadowColor.a;\n"
- " }\n"
- " // inside object, inside shadow's border\n"
- " else if ((inText != 0.0) && (inShadow != 0.0))\n"
- " {\n"
- " color = mix(uShadowColor, uColor, inText);\n"
- " color.a *= max(inText, inShadow);\n"
- " }\n"
- " // inside shadow's border\n"
- " else if (inShadow != 0.0)\n"
- " {\n"
- " color = uShadowColor;\n"
- " color.a *= inShadow;\n"
- " }\n"
- " // outside shadow and object\n"
- " else \n"
- " {\n"
- " color.a = 0.0;\n"
- " }\n"
- "\n"
- " }\n"
- "\n"
- " gl_FragColor = color;\n"
- "\n"
- "}\n");
-
- Property::Map map;
-
- Property::Map customShader;
-
- std::string fragmentShaderString;
- fragmentShaderString.reserve(strlen(fragmentShaderPrefix) + strlen(fragmentShader));
- fragmentShaderString.append(fragmentShaderPrefix);
- fragmentShaderString.append(fragmentShader);
-
- customShader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShaderString;
- customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
-
- map[Toolkit::Visual::Property::SHADER] = customShader;
- return map;
-}
+DALI_TOOLKIT_API Dali::Property::Map CreateDistanceFieldEffect();
} // namespace Toolkit
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/shader-effects/image-region-effect.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+
+Property::Map CreateImageRegionEffect()
+{
+ Property::Map map;
+
+ Property::Map customShader;
+ customShader[Visual::Shader::Property::VERTEX_SHADER] = SHADER_IMAGE_REGION_EFFECT_VERT.data();
+
+ map[Toolkit::Visual::Property::SHADER] = customShader;
+ return map;
+}
+
+} // Toolkit
+
+} // Dali
#define DALI_TOOLKIT_IMAGE_REGION_EFFECT_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/object/property-map.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
namespace Dali
{
*
* @return A property map of the required shader
*/
-inline Property::Map CreateImageRegionEffect()
-{
- std::string vertexShader(
- "attribute mediump vec2 aPosition;\n"
- "\n"
- "uniform mediump mat4 uMvpMatrix;\n"
- "uniform vec3 uSize;\n"
- "uniform vec4 uTextureRect;"
- "\n"
- "varying vec2 vTexCoord;\n"
-
- "uniform mediump vec2 uTopLeft;\n"
- "uniform mediump vec2 uBottomRight;\n"
- "void main()\n"
- "{\n"
- " mediump vec4 position = vec4(aPosition, 0.0, 1.0);\n"
- " position.xyz *= uSize;\n"
- " gl_Position = uMvpMatrix * position;\n"
- // The line below is doing the same as the following commented lines:
- //" vec2 imageSize = uTextureRect.zw - uTextureRect.xy;\n"
- //" vec2 topLeft = uTextureRect.xy + uTopLeft * imageSize;\n"
- //" vec2 bottomRight = uTextureRect.xy + uBottomRight * imageSize;\n"
- //" vec2 texCoord = (aTexCoord - uTextureRect.xy) / imageSize;\n"
- //" vTexCoord = topLeft + texCoord * ( bottomRight - topLeft );\n"
-
- " vec2 texCoord = aPosition + vec2(0.5);\n"
- " vTexCoord = uTextureRect.xy + uTopLeft * ( uTextureRect.zw - uTextureRect.xy ) + ( texCoord - uTextureRect.xy ) * ( uBottomRight - uTopLeft );\n"
- "}\n");
-
- Property::Map map;
-
- Property::Map customShader;
- customShader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
-
- map[Toolkit::Visual::Property::SHADER] = customShader;
- return map;
-}
+DALI_TOOLKIT_API Property::Map CreateImageRegionEffect();
} // namespace Toolkit
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/shader-effects/motion-blur-effect.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/animation/constraints.h>
+#include <dali/public-api/rendering/shader.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+
+void SetMotionBlurProperties( Actor& actor, unsigned int numBlurSamples )
+{
+ actor.RegisterProperty("uBlurTexCoordScale", 0.125f);
+ actor.RegisterProperty("uGeometryStretchFactor", 0.05f);
+ actor.RegisterProperty("uSpeedScalingFactor", 0.5f);
+ actor.RegisterProperty("uObjectFadeStart", Vector2(0.25f, 0.25f));
+ actor.RegisterProperty("uObjectFadeEnd", Vector2(0.5f, 0.5f));
+ actor.RegisterProperty("uAlphaScale", 0.75f);
+ actor.RegisterProperty("uNumSamples", static_cast<float>(numBlurSamples));
+ actor.RegisterProperty("uRecipNumSamples", 1.0f / static_cast<float>(numBlurSamples));
+ actor.RegisterProperty("uRecipNumSamplesMinusOne", 1.0f / static_cast<float>(numBlurSamples - 1.0f));
+ Property::Index uModelProperty = actor.RegisterProperty("uModelLastFrame", Matrix::IDENTITY);
+
+ Constraint constraint = Constraint::New<Matrix>(actor, uModelProperty, EqualToConstraint());
+ constraint.AddSource(Source(actor, Actor::Property::WORLD_MATRIX));
+ constraint.Apply();
+}
+
+
+Property::Map CreateMotionBlurEffect()
+{
+ Property::Map map;
+
+ Property::Map customShader;
+ customShader[Visual::Shader::Property::VERTEX_SHADER] = SHADER_MOTION_BLUR_EFFECT_VERT.data();
+ customShader[Visual::Shader::Property::FRAGMENT_SHADER] = SHADER_MOTION_BLUR_EFFECT_FRAG.data();
+
+ customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 10;
+ customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 10;
+
+ customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
+
+ map[Toolkit::Visual::Property::SHADER] = customShader;
+ return map;
+}
+
+} // Toolkit
+} // Dali
#define DALI_TOOLKIT_SHADER_EFFECT_MOTION_BLUR_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// EXTERNAL INCLUDES
#include <dali/public-api/actors/actor.h>
-#include <dali/public-api/animation/constraint.h>
#include <dali/public-api/object/property-map.h>
-#include <dali/public-api/rendering/shader.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
namespace Dali
{
* @param[in] actor The actor that registers the uniform properties
* @param[in] numBlurSamples Number of samples used by the shader
*/
-inline void SetMotionBlurProperties(Actor& actor, unsigned int numBlurSamples = 8)
-{
- actor.RegisterProperty("uBlurTexCoordScale", 0.125f);
- actor.RegisterProperty("uGeometryStretchFactor", 0.05f);
- actor.RegisterProperty("uSpeedScalingFactor", 0.5f);
- actor.RegisterProperty("uObjectFadeStart", Vector2(0.25f, 0.25f));
- actor.RegisterProperty("uObjectFadeEnd", Vector2(0.5f, 0.5f));
- actor.RegisterProperty("uAlphaScale", 0.75f);
- actor.RegisterProperty("uNumSamples", static_cast<float>(numBlurSamples));
- actor.RegisterProperty("uRecipNumSamples", 1.0f / static_cast<float>(numBlurSamples));
- actor.RegisterProperty("uRecipNumSamplesMinusOne", 1.0f / static_cast<float>(numBlurSamples - 1.0f));
- Property::Index uModelProperty = actor.RegisterProperty("uModelLastFrame", Matrix::IDENTITY);
-
- Constraint constraint = Constraint::New<Matrix>(actor, uModelProperty, EqualToConstraint());
- constraint.AddSource(Source(actor, Actor::Property::WORLD_MATRIX));
- constraint.Apply();
-}
+DALI_TOOLKIT_API void SetMotionBlurProperties( Actor& actor, unsigned int numBlurSamples = 8 );
/**
* @brief Create a new MotionBlurEffect
*
* @return The newly created Property::Map with the motion blur effect
*/
-inline Property::Map CreateMotionBlurEffect()
-{
- std::string vertexSource;
- vertexSource =
- "precision mediump float;\n"
-
- "attribute vec2 aPosition;\n"
-
- "uniform mat4 uMvpMatrix;\n"
- "uniform mat4 uModelView;\n"
- "uniform mat4 uViewMatrix;\n"
- "uniform mat4 uProjection;\n"
- "uniform vec3 uSize;\n"
-
- "uniform mat4 uModelLastFrame;\n"
- "float timeDelta = 0.0167;\n"
-
- "uniform float uGeometryStretchFactor;\n"
- "uniform float uSpeedScalingFactor;\n"
-
- // outputs
- "varying vec2 vModelSpaceCenterToPos;\n"
- "varying vec2 vScreenSpaceVelocityVector;\n"
- "varying float vSpeed;\n"
- "varying vec2 vTexCoord;\n"
-
- "void main()\n"
- "{\n"
- // get view space position of vertex this frame and last frame
- " vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n"
- " vertexPosition.xyz *= uSize;\n"
-
- " vec4 viewSpaceVertex = uModelView * vertexPosition;\n"
- " vec4 viewSpaceVertexLastFrame = (uViewMatrix * uModelLastFrame) * vertexPosition;\n"
- " float reciprocalTimeDelta = 1.0 / timeDelta;\n"
-
- // work out vertex's last movement in view space
- " vec3 viewSpacePosDelta = viewSpaceVertex.xyz - viewSpaceVertexLastFrame.xyz;\n"
-
- // get clip space position of vertex this frame and last frame
- " vec4 clipSpaceVertex = uMvpMatrix * vertexPosition;\n"
- " vec4 clipSpaceVertexLastFrame = uProjection * viewSpaceVertexLastFrame;\n"
-
- // decide how much this vertex is 'trailing', i.e. at the back of the object relative to its direction of motion. We do this
- // by assuming the objects model space origin is at its center and taking the dot product of the vector from center to vertex with the motion direction
- " float t = 0.0;\n"
- " float posDeltaLength = length(viewSpacePosDelta);\n"
- " if(posDeltaLength > 0.001)\n" // avoid div by 0 if object has barely moved
- " {\n"
- " vec4 viewSpaceCenterToPos = uModelView * vec4(vertexPosition.xy, 0.0, 0.0);\n"
- " float centerToVertexDist = length(viewSpaceCenterToPos);\n"
- " if(centerToVertexDist > 0.001)\n" // avoid div by 0 if object has vertex at model space origin
- " {\n"
- " vec3 viewSpacePosDeltaNormalised = viewSpacePosDelta / posDeltaLength;\n"
- " vec3 viewSpaceCenterToPosNormalised = viewSpaceCenterToPos.xyz / centerToVertexDist;\n"
- " t = (dot(viewSpacePosDeltaNormalised, viewSpaceCenterToPosNormalised) * 0.5 ) + 0.5;\n" // scale and bias from [-1..1] to [0..1]
- " }\n"
- " }\n"
- // output vertex position lerped with its last position, based on how much it is trailing,
- // this stretches the geom back along where it has just been, giving a warping effect
- // Note: we must take account of time delta to convert position delta into a velocity, so changes are smooth (take into account frame time correctly)
- " gl_Position = mix(clipSpaceVertexLastFrame, clipSpaceVertex, t * uGeometryStretchFactor * reciprocalTimeDelta);\n"
-
- // work out vertex's last movement in normalised device coordinates [-1..1] space, i.e. perspective divide
- " vec2 ndcVertex = clipSpaceVertex.xy / clipSpaceVertex.w;\n"
- " vec2 ndcVertexLastFrame = clipSpaceVertexLastFrame.xy / clipSpaceVertexLastFrame.w;\n"
- // scale and bias so that a value of 1.0 corresponds to screen size (NDC is [-1..1] = 2)
- " vScreenSpaceVelocityVector = ((ndcVertex - ndcVertexLastFrame) * 0.5 * reciprocalTimeDelta);\n"
- " vScreenSpaceVelocityVector.y = -vScreenSpaceVelocityVector.y;\n" // TODO negated due to y being inverted in our coordinate system?
- // calculate a scaling factor proportional to velocity, which we can use to tweak how things look
- " vSpeed = length(vScreenSpaceVelocityVector) * uSpeedScalingFactor;\n"
- " vSpeed = clamp(vSpeed, 0.0, 1.0);\n"
-
- // provide fragment shader with vector from center of object to pixel (assumes the objects model space origin is at its center and verts have same z)
- " vModelSpaceCenterToPos = viewSpaceVertex.xy;\n"
-
- " vec2 texCoord = aPosition + vec2(0.5);"
- " vTexCoord = texCoord;\n"
- "}\n";
-
- std::string fragmentSource;
- fragmentSource =
- "precision mediump float;\n"
-
- "uniform sampler2D sTexture;\n"
- "uniform vec4 uColor;\n"
-
- "uniform vec2 uObjectFadeStart;\n"
- "uniform vec2 uObjectFadeEnd;\n"
- "uniform float uAlphaScale;\n"
- "uniform float uBlurTexCoordScale;\n"
- "uniform float uNumSamples;\n"
- "uniform float uRecipNumSamples;\n"
- "uniform float uRecipNumSamplesMinusOne;\n"
- // inputs
- "varying vec2 vModelSpaceCenterToPos;\n"
- "varying vec2 vScreenSpaceVelocityVector;\n"
- "varying float vSpeed;\n"
- "varying vec2 vTexCoord;\n"
-
- "void main()\n"
- "{\n"
- // calculate an alpha value that will fade the object towards its extremities, we need this to avoid an unsightly hard edge between color values of
- // the blurred object and the unblurred background. Use smoothstep also to hide any hard edges (discontinuities) in rate of change of this alpha gradient
- " vec2 centerToPixel = abs(vModelSpaceCenterToPos);\n"
- " vec2 fadeToEdges = smoothstep(0.0, 1.0, 1.0 - ((centerToPixel - uObjectFadeStart) / (uObjectFadeEnd - uObjectFadeStart)));\n"
- " float fadeToEdgesScale = fadeToEdges.x * fadeToEdges.y * uAlphaScale;\n" // apply global scaler
- " fadeToEdgesScale = mix(1.0, fadeToEdgesScale, vSpeed);\n" // fade proportional to speed, so opaque when at rest
-
- // scale velocity vector by user requirements
- " vec2 velocity = vScreenSpaceVelocityVector * uBlurTexCoordScale;\n"
-
- // standard actor texel
- " vec4 colActor = texture2D(sTexture, vTexCoord);\n"
-
- // blurred actor - gather texture samples from the actor texture in the direction of motion
- " vec4 col = colActor * uRecipNumSamples;\n"
- " for(float i = 1.0; i < uNumSamples; i += 1.0)\n"
- " {\n"
- " float t = i * uRecipNumSamplesMinusOne;\n"
- " col += texture2D(sTexture, vTexCoord + (velocity * t)) * uRecipNumSamples;\n"
- " }\n"
- " gl_FragColor = mix(colActor, col, vSpeed);\n" // lerp blurred and non-blurred actor based on speed of motion
- " gl_FragColor.a = fadeToEdgesScale;//colActor.a * fadeToEdgesScale;\n" // fade blurred actor to its edges based on speed of motion
- " gl_FragColor *= uColor;\n"
- "}\n";
-
- Property::Map map;
-
- Property::Map customShader;
- customShader[Visual::Shader::Property::VERTEX_SHADER] = vertexSource;
- customShader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentSource;
-
- customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 10;
- customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 10;
-
- customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
-
- map[Toolkit::Visual::Property::SHADER] = customShader;
- return map;
-}
+DALI_TOOLKIT_API Property::Map CreateMotionBlurEffect();
} // namespace Toolkit
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/shader-effects/motion-stretch-effect.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/actors/actor.h>
+#include <dali/public-api/animation/constraints.h>
+#include <dali/public-api/object/property-map.h>
+#include <dali/public-api/rendering/shader.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+
+void SetMotionStretchProperties( Actor& actor )
+{
+ actor.RegisterProperty("uGeometryStretchFactor", 0.5f);
+ actor.RegisterProperty("uSpeedScalingFactor", 0.5f);
+ actor.RegisterProperty("uObjectFadeStart", Vector2(0.25f, 0.25f));
+ actor.RegisterProperty("uObjectFadeEnd", Vector2(0.5f, 0.5f));
+ actor.RegisterProperty("uAlphaScale", 0.75f);
+ Property::Index uModelProperty = actor.RegisterProperty("uModelLastFrame", Matrix::IDENTITY);
+
+ Constraint constraint = Constraint::New<Matrix>(actor, uModelProperty, EqualToConstraint());
+ constraint.AddSource(Source(actor, Actor::Property::WORLD_MATRIX));
+ constraint.Apply();
+}
+
+Property::Map CreateMotionStretchEffect()
+{
+ Property::Map map;
+
+ Property::Map customShader;
+ customShader[Visual::Shader::Property::VERTEX_SHADER] = SHADER_MOTION_STRETCH_EFFECT_VERT.data();
+ customShader[Visual::Shader::Property::FRAGMENT_SHADER] = SHADER_MOTION_STRETCH_EFFECT_FRAG.data();
+
+ customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 10;
+ customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 10;
+
+ customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
+
+ map[Toolkit::Visual::Property::SHADER] = customShader;
+ return map;
+}
+
+
+} // Toolkit
+} // Dali
#define DALI_TOOLKIT_SHADER_EFFECT_MOTION_STRETCH_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// EXTERNAL INCLUDES
#include <dali/public-api/actors/actor.h>
-#include <dali/public-api/animation/constraint.h>
#include <dali/public-api/object/property-map.h>
-#include <dali/public-api/rendering/shader.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
namespace Dali
{
/**
* @brief Set the properties for the motion stretch
*/
-inline void SetMotionStretchProperties(Actor& actor)
-{
- actor.RegisterProperty("uGeometryStretchFactor", 0.5f);
- actor.RegisterProperty("uSpeedScalingFactor", 0.5f);
- actor.RegisterProperty("uObjectFadeStart", Vector2(0.25f, 0.25f));
- actor.RegisterProperty("uObjectFadeEnd", Vector2(0.5f, 0.5f));
- actor.RegisterProperty("uAlphaScale", 0.75f);
- Property::Index uModelProperty = actor.RegisterProperty("uModelLastFrame", Matrix::IDENTITY);
-
- Constraint constraint = Constraint::New<Matrix>(actor, uModelProperty, EqualToConstraint());
- constraint.AddSource(Source(actor, Actor::Property::WORLD_MATRIX));
- constraint.Apply();
-}
+DALI_TOOLKIT_API void SetMotionStretchProperties( Actor& actor );
/**
* @brief Creates a new MotionStretchEffect
*
* @return The newly created Property::Map with the motion stretch effect
*/
-inline Property::Map CreateMotionStretchEffect()
-{
- std::string vertexSource;
- vertexSource =
- "precision mediump float;\n"
-
- "attribute vec2 aPosition;\n"
-
- "uniform mat4 uMvpMatrix;\n"
- "uniform mat4 uModelView;\n"
- "uniform mat4 uViewMatrix;\n"
- "uniform mat4 uProjection;\n"
- "uniform vec3 uSize;\n"
-
- "uniform mat4 uModelLastFrame;\n"
- "float timeDelta = 0.0167;\n"
-
- "uniform float uGeometryStretchFactor;\n"
- "uniform float uSpeedScalingFactor;\n"
-
- // outputs
- "varying vec2 vModelSpaceCenterToPos;\n"
- "varying vec2 vScreenSpaceVelocityVector;\n"
- "varying float vSpeed;\n"
- "varying vec2 vTexCoord;\n"
-
- "void main()\n"
- "{\n"
- // get view space position of vertex this frame and last frame
- " vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n"
- " vertexPosition.xyz *= uSize;\n"
-
- " vec4 viewSpaceVertex = uModelView * vertexPosition;\n"
- " vec4 viewSpaceVertexLastFrame = uViewMatrix * uModelLastFrame * vertexPosition;\n"
-
- // work out vertex's last movement in view space
- " vec3 viewSpacePosDelta = viewSpaceVertex.xyz - viewSpaceVertexLastFrame.xyz;\n"
- " float reciprocalTimeDelta = 1.0 / timeDelta;\n"
-
- // get clip space position of vertex this frame and last frame
- " vec4 clipSpaceVertex = uMvpMatrix * vertexPosition;\n"
- " vec4 clipSpaceVertexLastFrame = uProjection * viewSpaceVertexLastFrame;\n"
-
- // decide how much this vertex is 'trailing', i.e. at the back of the object relative to its direction of motion. We do this
- // by assuming the objects model space origin is at its center and taking the dot product of the vector from center to vertex with the motion direction
- " float t = 0.0;\n"
- " float posDeltaLength = length(viewSpacePosDelta);\n"
- " if(posDeltaLength > 0.001)\n" // avoid div by 0 if object has barely moved
- " {\n"
- " vec4 viewSpaceCenterToPos = uModelView * vec4(aPosition, 0.0, 0.0);\n"
- " float centerToVertexDist = length(viewSpaceCenterToPos);\n"
- " if(centerToVertexDist > 0.001)\n" // avoid div by 0 if object has vertex at model space origin
- " {\n"
- " vec3 viewSpacePosDeltaNormalised = viewSpacePosDelta / posDeltaLength;\n"
- " vec3 viewSpaceCenterToPosNormalised = viewSpaceCenterToPos.xyz / centerToVertexDist;\n"
- " t = (dot(viewSpacePosDeltaNormalised, viewSpaceCenterToPosNormalised) * 0.5 ) + 0.5;\n" // scale and bias from [-1..1] to [0..1]
- " }\n"
- " }\n"
- // output vertex position lerped with its last position, based on how much it is trailing,
- // this stretches the geom back along where it has just been, giving a warping effect
- // We raise t to a power in order that non-trailing vertices are effected much more than trailing ones
- // Note: we must take account of time delta to convert position delta into a velocity, so changes are smooth (take into account frame time correctly)
- " gl_Position = mix(clipSpaceVertexLastFrame, clipSpaceVertex, t * t * t * uGeometryStretchFactor * reciprocalTimeDelta);\n"
-
- // work out vertex's last movement in normalised device coordinates [-1..1] space, i.e. perspective divide
- " vec2 ndcVertex = clipSpaceVertex.xy / clipSpaceVertex.w;\n"
- " vec2 ndcVertexLastFrame = clipSpaceVertexLastFrame.xy / clipSpaceVertexLastFrame.w;\n"
- // scale and bias so that a value of 1.0 corresponds to screen size (NDC is [-1..1] = 2)
- " vScreenSpaceVelocityVector = ((ndcVertex - ndcVertexLastFrame) * 0.5 * reciprocalTimeDelta);\n"
- " vScreenSpaceVelocityVector.y = -vScreenSpaceVelocityVector.y;\n" // TODO negated due to y being inverted in our coordinate system?
- // calculate a scaling factor proportional to velocity, which we can use to tweak how things look
- " vSpeed = length(vScreenSpaceVelocityVector) * uSpeedScalingFactor;\n"
- " vSpeed = clamp(vSpeed, 0.0, 1.0);\n"
-
- // provide fragment shader with vector from center of object to pixel (assumes the objects model space origin is at its center and verts have same z)
- " vModelSpaceCenterToPos = viewSpaceVertex.xy;\n"
-
- " vec2 texCoord = aPosition + vec2(0.5);"
- " vTexCoord = texCoord;\n"
- "}\n";
-
- std::string fragmentSource;
- fragmentSource =
- "precision mediump float;\n"
-
- "uniform sampler2D sTexture;\n"
- "uniform vec4 uColor;\n"
-
- "uniform vec2 uObjectFadeStart;\n"
- "uniform vec2 uObjectFadeEnd;\n"
- "uniform float uAlphaScale;\n"
-
- // inputs
- "varying vec2 vModelSpaceCenterToPos;\n"
- "varying vec2 vScreenSpaceVelocityVector;\n"
- "varying float vSpeed;\n"
- "varying vec2 vTexCoord;\n"
-
- "void main()\n"
- "{\n"
- // calculate an alpha value that will fade the object towards its extremities, we need this to avoid an unsightly hard edge between color values of
- // the stretched object and the background. Use smoothstep also to hide any hard edges (discontinuities) in rate of change of this alpha gradient
- " vec2 centerToPixel = abs( vModelSpaceCenterToPos );\n"
- " vec2 fadeToEdges = smoothstep(0.0, 1.0, 1.0 - ((centerToPixel - uObjectFadeStart) / (uObjectFadeEnd - uObjectFadeStart)));\n"
- " float fadeToEdgesScale = fadeToEdges.x * fadeToEdges.y * uAlphaScale;\n" // apply global scaler
- " fadeToEdgesScale = mix(1.0, fadeToEdgesScale, vSpeed);\n" // fade proportional to speed, so opaque when at rest
-
- // standard actor texel
- " vec4 colActor = texture2D(sTexture, vTexCoord);\n"
- " gl_FragColor = colActor;\n"
- " gl_FragColor.a *= fadeToEdgesScale;\n" // fade actor to its edges based on speed of motion
- " gl_FragColor *= uColor;\n"
- "}";
-
- Property::Map map;
-
- Property::Map customShader;
- customShader[Visual::Shader::Property::VERTEX_SHADER] = vertexSource;
- customShader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentSource;
-
- customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 10;
- customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 10;
-
- customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
-
- map[Toolkit::Visual::Property::SHADER] = customShader;
- return map;
-}
+DALI_TOOLKIT_API Property::Map CreateMotionStretchEffect();
} // namespace Toolkit
// INTERNAL INCLUDES
#include <dali-toolkit/devel-api/controls/gaussian-blur-view/gaussian-blur-view.h>
#include <dali-toolkit/devel-api/controls/bloom-view/bloom-view.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.h>
#include <dali-toolkit/internal/controls/control/control-renderers.h>
#include <dali-toolkit/internal/controls/control/control-data-impl.h>
const char* const IMAGE_INTENSITY_PROPERTY_NAME = "uImageIntensity";
const char* const IMAGE_SATURATION_PROPERTY_NAME = "uImageSaturation";
-///////////////////////////////////////////////////////
-//
-// Bloom shaders
-//
-
-const char* const BLOOM_EXTRACT_FRAGMENT_SOURCE =
- "varying mediump vec2 vTexCoord;\n"
- "uniform sampler2D sTexture;\n"
- "uniform lowp vec4 uColor;\n"
- "uniform mediump float uBloomThreshold;\n"
- "uniform mediump float uRecipOneMinusBloomThreshold;\n"
- "void main()\n"
- "{\n"
- " mediump vec4 col;\n"
- " col = texture2D(sTexture, vTexCoord);\n"
- " col = (col - uBloomThreshold) * uRecipOneMinusBloomThreshold;\n" // remove intensities lower than the thresold and remap intensities above the threshold to [0..1]
- " gl_FragColor = clamp(col, 0.0, 1.0);\n"
- "}\n";
-
-const char* const COMPOSITE_FRAGMENT_SOURCE =
- "precision mediump float;\n"
- "varying mediump vec2 vTexCoord;\n"
- "uniform sampler2D sTexture;\n"
- "uniform sampler2D sEffect;\n"
- "uniform lowp vec4 uColor;\n"
- "uniform float uBloomIntensity;\n"
- "uniform float uImageIntensity;\n"
- "uniform float uBloomSaturation;\n"
- "uniform float uImageSaturation;\n"
-
- "vec4 ChangeSaturation(vec4 col, float sat)\n"
- "{\n"
- " float grey = dot(col.rgb, vec3(0.3, 0.6, 0.1));\n"
- " return mix(vec4(grey, grey, grey, 1.0), col, sat);\n"
- "}\n"
-
- "void main()\n"
- "{\n"
- " mediump vec4 image;\n"
- " mediump vec4 bloom;\n"
- " image = texture2D(sTexture, vTexCoord);\n"
- " bloom = texture2D(sEffect, vTexCoord);\n"
- " image = ChangeSaturation(image, uImageSaturation) * uImageIntensity;\n"
- " bloom = ChangeSaturation(bloom, uBloomSaturation) * uBloomIntensity;\n"
- " image *= 1.0 - clamp(bloom, 0.0, 1.0);\n" // darken base where bloom is strong, to prevent excessive burn-out of result
- " gl_FragColor = image + bloom;\n"
- "}\n";
-
} // namespace
//////////////////////////////////////////////////////
// Point actors and render tasks at new render targets
- Renderer bloomRenderer = CreateRenderer( BASIC_VERTEX_SOURCE, BLOOM_EXTRACT_FRAGMENT_SOURCE );
+ Renderer bloomRenderer = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_BLOOM_VIEW_EXTRACT_SHADER_FRAG );
SetRendererTexture( bloomRenderer, mRenderTargetForRenderingChildren );
mBloomExtractActor.AddRenderer( bloomRenderer );
mBloomExtractActor.SetProperty( Actor::Property::SIZE, Vector2( mDownsampledWidth, mDownsampledHeight ) ); // size needs to match render target
mGaussianBlurView.SetUserImageAndOutputRenderTarget( mBloomExtractTarget.GetColorTexture(), blurExtractTarget );
// use the completed blur in the first buffer and composite with the original child actors render
- Renderer compositeRenderer = CreateRenderer( BASIC_VERTEX_SOURCE, COMPOSITE_FRAGMENT_SOURCE );
+ Renderer compositeRenderer = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_BLOOM_VIEW_COMPOSITE_SHADER_FRAG );
SetRendererTexture( compositeRenderer, mRenderTargetForRenderingChildren );
TextureSet textureSet = compositeRenderer.GetTextures();
textureSet.SetTexture( 0u, mRenderTargetForRenderingChildren.GetColorTexture() );
// EXTERNAL INCLUDES
#include <sstream>
#include <dali/public-api/rendering/shader.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
*/
inline Shader CreateBubbleShader( unsigned int numBubble )
{
- const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute mediump float aIndex;\n
- attribute mediump vec2 aPosition;\n
- attribute highp vec2 aTexCoord;\n
- varying mediump vec2 vTexCoord;\n
- uniform mediump mat4 uMvpMatrix;\n
- // the gravity applied to the y direction
- uniform mediump float uGravity;\n
- // xy: the emit position of the bubble; zw: the destination of the bubble.
- // The bubble is moving from (xy) to (zw plus the y drop influenced by gravity).
- uniform vec4 uStartEndPosition[NUMBER_OF_BUBBLE];\n
- // The undergoing percentage of the bubble movement. 0.0: start from emit position, 1.0: reach the destination
- uniform float uPercentage[NUMBER_OF_BUBBLE];\n
- uniform vec2 uInvertedMovementArea;\n
- // The bubble number is restricted by the available uniform num.
- // To increase the displayed bubble, every uStartEndPosition and uPercentage uniform is applied to a small bunch of bubbles (9 here)
- // The offset defines the random offset between bubbles within the bunch.
- uniform vec2 uOffset[9];\n
- // This uniform is used to change the bubble size during running time
- uniform float uDynamicScale;\n
- varying float vPercentage;\n
- varying vec2 vEffectTexCoord;\n
- void main()\n
- {\n
- vec4 position = vec4( aPosition, 0.0, 1.0 );\n
- // The Z coordinate is used to record the bubble index within current mesh actor
- int index = int(aIndex); \n
- //for some i between 0 ~ NUMBER_OF_BUBBLE-1: i,i+NUMBER_OF_BUBBLE, i+NUMBER_OF_BUBBLE*2, ... (up to i+NUMBER_OF_BUBBLE*8) belongs to the same bunch.
- int groupIdx = index / NUMBER_OF_BUBBLE;\n
- // The bubbles within the same bunch applies the same uniforms uStartEndPosition[idx] & uPercentage[idx]
- int idx = index - groupIdx*NUMBER_OF_BUBBLE;\n
- float percentage = uPercentage[idx];
- // early out if uPercentage is (zero || one) setting position to zero (zero sized triangles)
- if( percentage <= 0.0 || percentage >= 1.0 )\n
- {\n
- gl_Position = vec4(0.0);\n
- return;\n
- }\n
- vec4 startAndEnd = uStartEndPosition[idx];\n
- // The final position is added up different offset for bubbles
- startAndEnd.zw += uOffset[groupIdx];\n
- \n
- // increase the bubble size from 0% to 100% during the first 1/5 of movement & apply the dynamic scale
- // the new xy value containes both the new scale and new bubble position
- position.xy *= uDynamicScale*min(percentage*5.0, 1.0);\n
- position.xy += mix(startAndEnd.xy, startAndEnd.zw, percentage);\n
- // The gravity is g*t*t on the y direction
- position.y += uGravity * pow(percentage, 2.0);\n
- gl_Position = uMvpMatrix * position;\n
- \n
- // Add multiple bubble shapes in the effect
- vTexCoord = aTexCoord;\n
- vPercentage = percentage;\n
- // Use the emit position color for the bubble
- vEffectTexCoord = startAndEnd.xy * uInvertedMovementArea + vec2(0.5);\n
- }\n
- );
-
- const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform lowp vec4 uColor;\n
- uniform sampler2D sBackground;\n
- uniform sampler2D sBubbleShape;\n
- varying mediump float vPercentage;\n
- varying mediump vec2 vEffectTexCoord;\n
- \n
- void main()\n
- {\n
- // Get the emit pisition color, and Mix with the actor color
- mediump vec4 fragColor = texture2D(sBackground, vEffectTexCoord)*uColor;\n
- // Apply the shape defined by the texture contained sBubbleShape
- // And make the opacity being 0.7, and animate from 0.7 to 0 during the last 1/3 of movement
- fragColor.a *= texture2D(sBubbleShape, vTexCoord).a * ( 2.1 - max( vPercentage*2.1, 1.4 ) );\n
- gl_FragColor = fragColor;\n
- }\n
- );
-
std::ostringstream vertexShaderStringStream;
vertexShaderStringStream << "#define NUMBER_OF_BUBBLE "<< numBubble << "\n"
- << VERTEX_SHADER;
- Shader shader = Shader::New( vertexShaderStringStream.str(), FRAGMENT_SHADER );
+ << SHADER_BUBBLE_EFFECT_VERT;
+ Shader shader = Shader::New( vertexShaderStringStream.str(), SHADER_BUBBLE_EFFECT_FRAG );
return shader;
}
// INTERNAL INCLUDES
#include <dali-toolkit/internal/controls/bubble-effect/bubble-effect.h>
#include <dali-toolkit/internal/controls/bubble-effect/bubble-renderer.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace
{
return f0 + (rand_r( &seed ) & 0xfff) * (f1-f0) * (1.0f/4095.0f);
}
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- attribute mediump vec2 aTexCoord;\n
- uniform mediump vec3 uSize;\n
- uniform mediump mat4 uMvpMatrix;\n
- varying mediump vec2 vTexCoord;\n
- \n
-
- void main()\n
- {\n
- gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy,0.0,1.0);
- vTexCoord = aTexCoord;\n
- }\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- precision highp float;\n
- uniform vec3 uHSVDelta;\n
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- float rand(vec2 co) \n
- {\n
- return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); \n}
- \n
- vec3 rgb2hsv(vec3 c)\n
- {\n
- vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n
- vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n
- vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n
- \n
- float d = q.x - min(q.w, q.y);\n
- float e = 1.0e-10;\n
- return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n
- }\n
- vec3 hsv2rgb(vec3 c)\n
- {\n
- vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n
- vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n
- return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n
- }\n
- void main() {\n
- vec4 color = texture2D(sTexture, vTexCoord); \n
- vec3 hsvColor = rgb2hsv( color.rgb );\n
- // modify the hsv Value
- hsvColor += uHSVDelta * rand(vTexCoord); \n
- // if the new vale exceeds one, then decrease it
- hsvColor -= max(hsvColor*2.0 - vec3(2.0), 0.0);\n
- // if the new vale drops below zero, then increase it
- hsvColor -= min(hsvColor*2.0, 0.0);\n
- color = vec4( hsv2rgb( hsvColor ), 1.0 ); \n
- gl_FragColor = color; \n
- }\n
- );
-
Dali::Geometry CreateTexturedQuad()
{
struct Vertex
//Create renderer
Dali::Geometry geometry = CreateTexturedQuad();
- Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+ Shader shader = Shader::New( SHADER_BUBBLE_EMITTER_VERT, SHADER_BUBBLE_EMITTER_FRAG );
Renderer renderer = Renderer::New( geometry, shader );
TextureSet textureSet = TextureSet::New();
textureSet.SetTexture(0u, bgTexture );
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/visuals/visual-properties.h>
-
-#define DALI_COMPOSE_SHADER(STR) #STR
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
*/
inline Property::Map CreateColorAdjuster()
{
- std::string fragmentShader = DALI_COMPOSE_SHADER(
- precision highp float;\n
- uniform vec3 uHSVDelta;\n
- uniform float uIgnoreAlpha;\n
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- float rand(vec2 co) \n
- {\n
- return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); \n}
- \n
- vec3 rgb2hsv(vec3 c)\n
- {\n
- vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n
- vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n
- vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n
- \n
- float d = q.x - min(q.w, q.y);\n
- float e = 1.0e-10;\n
- return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n
- }\n
- vec3 hsv2rgb(vec3 c)\n
- {\n
- vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n
- vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n
- return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n
- }\n
- void main() {\n
- vec4 color = texture2D(sTexture, vTexCoord); \n
- vec3 hsvColor = rgb2hsv( color.rgb );\n
- // modify the hsv Value
- hsvColor += uHSVDelta * rand(vTexCoord); \n
- // if the new vale exceeds one, then decrease it
- hsvColor -= max(hsvColor*2.0 - vec3(2.0), 0.0);\n
- // if the new vale drops below zero, then increase it
- hsvColor -= min(hsvColor*2.0, 0.0);\n
- color.rgb = hsv2rgb( hsvColor ); \n
- // uIgnoreAlpha decide the result alpha will be 1.0 or source's alpha
- color.a += uIgnoreAlpha;\n
- gl_FragColor = color; \n
- }\n
- );
-
Property::Map customShader;
- customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = fragmentShader;
+ customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = SHADER_BUBBLE_EFFECT_COLOR_ADJUSTER_FRAG.data();
Property::Map map;
map[ Toolkit::Visual::Property::SHADER ] = customShader;
namespace Internal
{
-#define DALI_COMPOSE_SHADER(STR) #STR
-
-const char * const BASIC_VERTEX_SOURCE = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- attribute mediump vec2 aPosition;\n
- varying mediump vec2 vTexCoord;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump vec3 uSize;\n
- \n
- void main()\n
- {\n
- mediump vec4 vertexPosition = vec4(aPosition * uSize.xy, 0.0, 1.0);\n
- vTexCoord = aPosition + vec2(0.5);
- gl_Position = uMvpMatrix * vertexPosition;\n
- }\n
-);
-
-const char * const BASIC_FRAGMENT_SOURCE = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform vec4 uColor;\n
- \n
- void main()\n
- {\n
- gl_FragColor = texture2D(sTexture, vTexCoord);\n
- gl_FragColor *= uColor;
- }\n
-);
-
Geometry CreateGridGeometry( Uint16Pair gridSize )
{
uint16_t gridWidth = gridSize.GetWidth();
return geometry;
}
-Dali::Renderer CreateRenderer( const char* vertexSrc, const char* fragmentSrc )
+Dali::Renderer CreateRenderer( std::string_view vertexSrc, std::string_view fragmentSrc )
{
Dali::Shader shader = Dali::Shader::New( vertexSrc, fragmentSrc );
return renderer;
}
-Dali::Renderer CreateRenderer( const char* vertexSrc, const char* fragmentSrc, Dali::Shader::Hint::Value hints, Uint16Pair gridSize )
+Dali::Renderer CreateRenderer( std::string_view vertexSrc, std::string_view fragmentSrc, Dali::Shader::Hint::Value hints, Uint16Pair gridSize )
{
Dali::Shader shader = Dali::Shader::New( vertexSrc, fragmentSrc, hints );
*/
#include <dali/dali.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
namespace Internal
{
-extern const char* const BASIC_VERTEX_SOURCE;
-
-extern const char* const BASIC_FRAGMENT_SOURCE;
+#define BASIC_VERTEX_SOURCE SHADER_CONTROL_RENDERERS_VERT
+#define BASIC_FRAGMENT_SOURCE SHADER_CONTROL_RENDERERS_FRAG
/**
* Helper method for rendering an image with custom shader.
* @param[in] fragmentSrc The custom fragment shader.
* @return A newly created renderer.
*/
-Dali::Renderer CreateRenderer( const char* vertexSrc, const char* fragmentSrc );
+Dali::Renderer CreateRenderer( std::string_view vertexSrc, std::string_view fragmentSrc );
/**
* Helper method for rendering an image with custom shader.
* @param[in] gridSize The number of grid sub-divisions required.
* @return A newly created renderer.
*/
-Dali::Renderer CreateRenderer( const char* vertexSrc, const char* fragmentSrc, Dali::Shader::Hint::Value hints, Dali::Uint16Pair gridSize );
+Dali::Renderer CreateRenderer( std::string_view vertexSrc, std::string_view fragmentSrc, Dali::Shader::Hint::Value hints, Dali::Uint16Pair gridSize );
/**
* Helper method for setting the first texture passed to a renderer.
// INTERNAL INCLUDES
#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/filters/blur-two-pass-filter.h>
#include <dali-toolkit/internal/filters/emboss-filter.h>
#include <dali-toolkit/internal/filters/spread-filter.h>
const Vector4 EFFECTS_VIEW_DEFAULT_BACKGROUND_COLOR( 0.0f, 0.0f, 0.0f, 0.0 );
const bool EFFECTS_VIEW_REFRESH_ON_DEMAND(false);
-#define DALI_COMPOSE_SHADER(STR) #STR
-
-const char* EFFECTS_VIEW_VERTEX_SOURCE = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- varying mediump vec2 vTexCoord;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump vec3 uSize;\n
- uniform mediump vec3 effectOffset;\n
- \n
- void main()\n
- {\n
- mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
- vertexPosition.xyz *= uSize;\n
- vertexPosition.xyz += effectOffset;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
- \n
- vTexCoord = aPosition + vec2(0.5);\n
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* EFFECTS_VIEW_FRAGMENT_SOURCE = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 effectColor;\n
- \n
- void main()\n
- {\n
- gl_FragColor = effectColor;\n
- gl_FragColor.a *= texture2D( sTexture, vTexCoord).a;\n
- }\n
-);
-
const float BLUR_KERNEL0[] = { 12.0f/16.0f,
2.0f/16.0f, 2.0f/16.0f };
Actor self( Self() );
// Create renderers
- mRendererPostFilter = CreateRenderer( EFFECTS_VIEW_VERTEX_SOURCE, EFFECTS_VIEW_FRAGMENT_SOURCE );
+ mRendererPostFilter = CreateRenderer( SHADER_EFFECTS_VIEW_VERT,
+ SHADER_EFFECTS_VIEW_FRAG );
mRendererPostFilter.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, DepthIndex::CONTENT );
self.AddRenderer( mRendererPostFilter );
#include <dali-toolkit/public-api/visuals/visual-properties.h>
#include <dali-toolkit/internal/controls/control/control-renderers.h>
#include <dali-toolkit/internal/controls/control/control-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
// TODO:
// pixel format / size - set from JSON
const float ARBITRARY_FIELD_OF_VIEW = Math::PI / 4.0f;
-const char* const GAUSSIAN_BLUR_FRAGMENT_SOURCE = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
- uniform mediump vec2 uSampleOffsets[NUM_SAMPLES];\n
- uniform mediump float uSampleWeights[NUM_SAMPLES];\n
-
- void main()\n
- {\n
- mediump vec4 col = texture2D(sTexture, vTexCoord + uSampleOffsets[0]) * uSampleWeights[0];\n
- for (int i=1; i<NUM_SAMPLES; ++i)\n
- {\n
- col += texture2D(sTexture, vTexCoord + uSampleOffsets[i]) * uSampleWeights[i];\n
- }\n
- gl_FragColor = col;\n
- }\n
-);
-
} // namespace
std::ostringstream fragmentStringStream;
fragmentStringStream << "#define NUM_SAMPLES " << mNumSamples << "\n";
- fragmentStringStream << GAUSSIAN_BLUR_FRAGMENT_SOURCE;
+ fragmentStringStream << SHADER_GAUSSIAN_BLUR_VIEW_FRAG;
std::string fragmentSource(fragmentStringStream.str());
//////////////////////////////////////////////////////
// Create an actor for performing a horizontal blur on the texture
mHorizBlurActor = Actor::New();
mHorizBlurActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER );
+
Renderer renderer = CreateRenderer( BASIC_VERTEX_SOURCE, fragmentSource.c_str() );
mHorizBlurActor.AddRenderer( renderer );
#include <dali/devel-api/adaptor-framework/image-loading.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/controls/model3d-view/obj-loader.h>
#include <dali-toolkit/internal/controls/control/control-data-impl.h>
DALI_TYPE_REGISTRATION_END()
-
-#define MAKE_SHADER(A)#A
-
-// Diffuse illumination shader
-
-const char* SIMPLE_VERTEX_SHADER = MAKE_SHADER(
- attribute highp vec3 aPosition;\n
- attribute highp vec2 aTexCoord;\n
- attribute highp vec3 aNormal;\n
- varying mediump vec3 vIllumination;\n
- uniform mediump vec3 uSize;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump mat4 uModelView;\n
- uniform mediump mat3 uNormalMatrix;
- uniform mediump mat4 uObjectMatrix;\n
- uniform mediump vec3 uLightPosition;\n
-
- void main()\n
- {\n
- vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);\n
- vertexPosition = uObjectMatrix * vertexPosition;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
-
- //Illumination in Model-View space - Transform attributes and uniforms\n
- vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);\n
- vec3 normal = uNormalMatrix * aNormal;\n
- vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);\n
- vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );\n
-
- float lightDiffuse = max( dot( vecToLight, normal ), 0.0 );\n
- vIllumination = vec3(lightDiffuse * 0.5 + 0.5);\n
-
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* SIMPLE_FRAGMENT_SHADER = MAKE_SHADER(
- precision mediump float;\n
- varying mediump vec3 vIllumination;\n
- uniform lowp vec4 uColor;\n
-
- void main()\n
- {\n
- gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a);\n
- }\n
-);
-
-// Diffuse and specular illumination shader with albedo texture
-
-const char* VERTEX_SHADER = MAKE_SHADER(
- attribute highp vec3 aPosition;\n
- attribute highp vec2 aTexCoord;\n
- attribute highp vec3 aNormal;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec3 vIllumination;\n
- varying mediump float vSpecular;\n
- uniform mediump vec3 uSize;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump mat4 uModelView;
- uniform mediump mat3 uNormalMatrix;
- uniform mediump mat4 uObjectMatrix;\n
- uniform mediump vec3 uLightPosition;\n
-
- void main()
- {\n
- vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);\n
- vertexPosition = uObjectMatrix * vertexPosition;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
-
- //Illumination in Model-View space - Transform attributes and uniforms\n
- vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);\n
- vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);\n
- vec3 normal = normalize(uNormalMatrix * aNormal);\n
-
- vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );\n
- vec3 viewDir = normalize(-vertPos.xyz);
-
- vec3 halfVector = normalize(viewDir + vecToLight);
-
- float lightDiffuse = dot( vecToLight, normal );\n
- lightDiffuse = max(0.0,lightDiffuse);\n
- vIllumination = vec3(lightDiffuse * 0.5 + 0.5);\n
-
- vec3 reflectDir = reflect(-vecToLight, normal);
- vSpecular = pow( max(dot(reflectDir, viewDir), 0.0), 4.0 );
-
- vTexCoord = aTexCoord;\n
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* FRAGMENT_SHADER = MAKE_SHADER(
- precision mediump float;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec3 vIllumination;\n
- varying mediump float vSpecular;\n
- uniform sampler2D sDiffuse;\n
- uniform lowp vec4 uColor;\n
-
- void main()\n
- {\n
- vec4 texture = texture2D( sDiffuse, vTexCoord );\n
- gl_FragColor = vec4( vIllumination.rgb * texture.rgb * uColor.rgb + vSpecular * 0.3, texture.a * uColor.a);\n
- }\n
-);
-
-// Diffuse and specular illumination shader with albedo texture, normal map and gloss map shader
-
-const char* NRMMAP_VERTEX_SHADER = MAKE_SHADER(
- attribute highp vec3 aPosition;\n
- attribute highp vec2 aTexCoord;\n
- attribute highp vec3 aNormal;\n
- attribute highp vec3 aTangent;\n
- attribute highp vec3 aBiNormal;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec3 vLightDirection;\n
- varying mediump vec3 vHalfVector;\n
- uniform mediump vec3 uSize;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump mat4 uModelView;
- uniform mediump mat3 uNormalMatrix;
- uniform mediump mat4 uObjectMatrix;\n
- uniform mediump vec3 uLightPosition;\n
-
- void main()
- {\n
- vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);\n
- vertexPosition = uObjectMatrix * vertexPosition;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
-
- vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);\n
- vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);\n
-
- vec3 tangent = normalize(uNormalMatrix * aTangent);
- vec3 binormal = normalize(uNormalMatrix * aBiNormal);
- vec3 normal = normalize(uNormalMatrix * aNormal);
-
- vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );\n
- vLightDirection.x = dot(vecToLight, tangent);
- vLightDirection.y = dot(vecToLight, binormal);
- vLightDirection.z = dot(vecToLight, normal);
-
- vec3 viewDir = normalize(-vertPos.xyz);
- vec3 halfVector = normalize(viewDir + vecToLight);
- vHalfVector.x = dot(halfVector, tangent);
- vHalfVector.y = dot(halfVector, binormal);
- vHalfVector.z = dot(halfVector, normal);
-
- vTexCoord = aTexCoord;\n
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* NRMMAP_FRAGMENT_SHADER = MAKE_SHADER(
- precision mediump float;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec3 vLightDirection;\n
- varying mediump vec3 vHalfVector;\n
- uniform sampler2D sDiffuse;\n
- uniform sampler2D sNormal;\n
- uniform sampler2D sGloss;\n
- uniform lowp vec4 uColor;\n
-
- void main()\n
- {\n
- vec4 texture = texture2D( sDiffuse, vTexCoord );\n
- vec3 normal = normalize( texture2D( sNormal, vTexCoord ).xyz * 2.0 - 1.0 );\n
- vec4 glossMap = texture2D( sGloss, vTexCoord );\n
-
- float lightDiffuse = max( 0.0, dot( normal, normalize(vLightDirection) ) );\n
- lightDiffuse = lightDiffuse * 0.5 + 0.5;\n
-
- float shininess = pow (max (dot (normalize( vHalfVector ), normal), 0.0), 16.0) ;
-
- gl_FragColor = vec4( texture.rgb * uColor.rgb * lightDiffuse + shininess * glossMap.rgb, texture.a * uColor.a);\n
- }\n
-);
-
-
} // anonymous namespace
using namespace Dali;
{
//Create empty versions of the geometry and material so we always have a Renderer
Geometry mesh = Geometry::New();
- Shader shader = Shader::New( SIMPLE_VERTEX_SHADER, SIMPLE_FRAGMENT_SHADER );
+ Shader shader = Shader::New( SHADER_MODEL3D_VIEW_SIMPLE_SHADER_VERT, SHADER_MODEL3D_VIEW_SIMPLE_SHADER_FRAG );
mRenderer = Renderer::New( mesh, shader );
DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) {
{
if( (mTexture2Url != "") && (mTexture1Url != "") && (mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP) )
{
- mShader = Shader::New( NRMMAP_VERTEX_SHADER, NRMMAP_FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_MODEL3D_VIEW_NRMMAP_SHADER_VERT, SHADER_MODEL3D_VIEW_NRMMAP_SHADER_FRAG );
}
else if( mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_TEXTURE ||
mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP )
{
- mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_MODEL3D_VIEW_SHADER_VERT, SHADER_MODEL3D_VIEW_SHADER_FRAG );
}
else
{
- mShader = Shader::New( SIMPLE_VERTEX_SHADER, SIMPLE_FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_MODEL3D_VIEW_SIMPLE_SHADER_VERT, SHADER_MODEL3D_VIEW_SIMPLE_SHADER_FRAG );
}
}
else
{
- mShader = Shader::New( SIMPLE_VERTEX_SHADER, SIMPLE_FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_MODEL3D_VIEW_SIMPLE_SHADER_VERT, SHADER_MODEL3D_VIEW_SIMPLE_SHADER_FRAG );
}
mTextureSet = TextureSet::New();
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/visuals/visual-properties.h>
-
-#define DALI_COMPOSE_SHADER(STR) #STR
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
**/
inline Property::Map CreatePageTurnBookSpineEffect()
{
- const char* vertexSource = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- attribute mediump vec2 aPosition;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform vec3 uSize;\n
- uniform float uTextureWidth;\n
- varying vec2 vTexCoord;\n
- void main()\n
- {\n
- mediump vec4 vertexPosition = vec4(aPosition*uSize.xy, 0.0, 1.0);\n
- gl_Position = uMvpMatrix * vertexPosition;\n
- vTexCoord = aPosition + vec2(0.5);\n
- vTexCoord.x /= uTextureWidth;
- }\n);
-
- // the simplified version of the fragment shader of page turn effect
- const char* fragmentSource = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- varying mediump vec2 vTexCoord;\n
- uniform vec3 uSize;\n
- uniform vec2 uSpineShadowParameter;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
-
- void main()\n
- {\n
- if( gl_FrontFacing )\n // display front side
- {\n
- gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
- }\n
- else\n // display back side, flip the image horizontally by changing the x component of the texture coordinate
- {\n
- gl_FragColor = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) ) * uColor;\n
- }\n
- // display book spine, a stripe of shadowed texture
- float pixelPos = vTexCoord.x * uSize.x;\n
- if( pixelPos < uSpineShadowParameter.x )\n
- {\n
- float x = pixelPos - uSpineShadowParameter.x;\n
- float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );\n
- vec2 spineNormal = normalize(vec2(uSpineShadowParameter.y*x/uSpineShadowParameter.x, y));\n
- gl_FragColor.rgb *= spineNormal.y; \n
- }\n
- } );
-
Property::Map map;
Property::Map customShader;
- customShader[ Toolkit::Visual::Shader::Property::VERTEX_SHADER ] = vertexSource;
- customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = fragmentSource;
+ customShader[ Toolkit::Visual::Shader::Property::VERTEX_SHADER ] = SHADER_PAGE_TURN_BOOK_SPINE_EFFECT_VERT.data();
+ customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = SHADER_PAGE_TURN_BOOK_SPINE_EFFECT_FRAG.data();
map[ Toolkit::Visual::Property::SHADER ] = customShader;
return map;
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/visuals/visual-properties.h>
#include <dali-toolkit/internal/controls/page-turn-view/page-turn-effect.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
using namespace Dali;
using namespace Dali::Toolkit;
namespace
{
-#define DALI_COMPOSE_SHADER(STR) #STR
const char * const PROPERTY_COMMON_PARAMETERS( "uCommonParameters" );
const char * const PROPERTY_ORIGINAL_CENTER( "originalCenter" );
const char * const PROPERTY_CURRENT_CENTER( "currentCenter" );
Property::Map Dali::Toolkit::Internal::CreatePageTurnEffect()
{
- const char* vertexShader = DALI_COMPOSE_SHADER(
- /*
- * The common parameters for all the vertices, calculate in CPU then pass into the shader as uniforms
- *
- * first part of the page, (outside the the line passing through original center and vertical to curve direction)
- * no Z change, only 2D rotation and translation
- * ([0][0],[0][1],[1][0],[1][1]) mat2 rotateMatrix
- * ([2][0],[2][1]) vec2 translationVector
- *
- * ([0][2],[0][3]) vec2 originalCenter: Typically the press down position of the Pan Gesture
- * ([1][2],[1][3]) vec2 currentCenter: Typically the current position of the Pan Gesture
- * ([3][0],[3][1]) vec2 curveDirection: The normalized vector pointing from original center to current center
- * ([2][2]) float vanishingPointY: The Y coordinate of the intersection of the spine
- * and the line which goes through the original center and is vertical to the curveDirection
- * ([2][3]) float curveEndY: The Y coordinate of intersection of the spine and the line through both original and current center
- * ([3][2]) float curveHeight: The height of the interpolated hermite curve.
- * ([3][3]) float currentLength: The length from the current center to the curveEnd.
- */
- precision mediump float;\n
- \n
- attribute mediump vec2 aPosition;\n
- \n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump mat3 uNormalMatrix;\n
- uniform mediump mat4 uModelView;\n
- \n
- uniform mat4 uCommonParameters;\n
- \n
- uniform vec3 uSize;\n
- uniform float uIsTurningBack;\n
- uniform float uTextureWidth;\n
- varying vec3 vNormal;\n
- varying vec4 vPosition;\n
- varying mediump vec2 vTexCoord;\n
- \n
- void main()\n
- {\n
- vec4 position = vec4( aPosition*uSize.xy, 0.0, 1.0);\n
- vec2 currentCenter = vec2( uCommonParameters[1][2], uCommonParameters[1][3]);\n
- vec2 originalCenter = vec2( uCommonParameters[0][2], uCommonParameters[0][3]);\n
- vec3 normal = vec3(0.0,0.0,1.0);\n
- \n
- if(currentCenter.x < originalCenter.x)\n
- {\n
- // change the coordinate origin from the center of the page to its top-left
- position.xy += uSize.xy * 0.5;\n
- vec2 curveDirection = vec2( uCommonParameters[3]);\n
- vec3 vanishingPoint = vec3(0.0, uCommonParameters[2][2], 0.0);\n
- // first part of the page, (outside the the line passing through original center and vertical to curve direction)
- //no Z change, only 2D rotation and translation
- if( dot(curveDirection, position.xy - originalCenter) < 0.0 )
- {\n
- position.y -= vanishingPoint.y;\n
- position.xy = mat2(uCommonParameters)*position.xy + vec2( uCommonParameters[2]);\n
- }\n
- // second part of the page, bent as a ruled surface
- else\n
- {\n
- // calculate on the flat plane, between
- // the first line passing through current vertex and vanishing point
- // the second line passing through original center and current center
- vec2 curveEnd = vec2( 0.0, uCommonParameters[2][3] );\n
- vec2 curFlatDirection = vec2(0.0,1.0);\n
- float lengthFromCurve = position.y - originalCenter.y;\n
- float lengthOnCurve = position.x;\n
- if(currentCenter.y != originalCenter.y)\n
- {\n
- curFlatDirection = normalize(position.xy - vanishingPoint.xy);\n
- lengthFromCurve = (curveEnd.x*curveDirection.y-curveEnd.y*curveDirection.x-position.x*curveDirection.y+position.y*curveDirection.x)
- / (curFlatDirection.x*curveDirection.y-curFlatDirection.y*curveDirection.x);\n
- lengthOnCurve = length(position.xy+lengthFromCurve*curFlatDirection-curveEnd);\n
- }\n
- \n
- // define the control points of hermite curve, composed with two segments
- // calculation is carried out on the 2D plane which is passing through both current and original center and vertical to the image plane
- float currentLength = uCommonParameters[3][3];\n
- float originalLength = abs(originalCenter.x/curveDirection.x);\n
- float height = uCommonParameters[3][2];\n
- float percentage = currentLength/originalLength;\n
- //vec2 SegmentOneControlPoint0 = vec2(0.0, 0.0);
- vec2 SegmentOneControlPoint1 = vec2((0.65*percentage - 0.15)*originalLength, (0.8 + 0.2 * percentage)*height); \n
- vec2 SegmentTwoControlPoint0 = SegmentOneControlPoint1;\n
- vec2 SegmentTwoControlPoint1 = vec2(currentLength, 0.0); \n
- vec2 SegmentOneTangentVector0 = SegmentOneControlPoint1;\n
- vec2 SegmentOneTangentVector1 = vec2(0.5*originalLength,0.0);\n
- vec2 SegmentTwoTangentVector0 = SegmentOneTangentVector1;\n
- vec2 SegmentTwoTangentVector1 = SegmentOneTangentVector1;\n
- \n
- // calculate the corresponding curve point position and its tangent vector
- // it is a linear mapping onto nonlinear curves, might cause some unwanted deformation
- // but as there are no analytical method to calculate the curve length on arbitrary segment
- // no efficient way to solve this nonlinear mapping, Numerical approximation would cost too much computation in shader
- vec2 curvePoint2D;\n
- vec2 tangent;\n
- float t0 = lengthOnCurve / originalLength;\n
- if(t0<=0.5)\n
- {\n
- float t = 2.0*t0;\n
- float t_2 = t*t;\n
- float t_3 = t*t_2;\n
- curvePoint2D = (-2.0*t_3+3.0*t_2)*SegmentOneControlPoint1
- + (t_3-2.0*t_2+t)*SegmentOneTangentVector0 + (t_3-t_2)*SegmentOneTangentVector1;\n
- tangent = (-6.0*t_2+6.0*t)*SegmentOneControlPoint1
- + (3.0*t_2-4.0*t+1.0)*SegmentOneTangentVector0 + (3.0*t_2-2.0*t)*SegmentOneTangentVector1;\n
- }\n
- else\n
- {\n
- float t = 2.0*t0-1.0;\n
- float t_2 = t*t;\n
- float t_3 = t*t_2;\n
- curvePoint2D = (2.0*t_3-3.0*t_2+1.0)*SegmentTwoControlPoint0 + (-2.0*t_3+3.0*t_2)*SegmentTwoControlPoint1
- + (t_3-2.0*t_2+t)*SegmentTwoTangentVector0 + (t_3-t_2)*SegmentTwoTangentVector1;\n
- tangent = (6.0*t_2-6.0*t)*SegmentTwoControlPoint0 + (-6.0*t_2+6.0*t)*SegmentTwoControlPoint1
- + (3.0*t_2-4.0*t+1.0)*SegmentTwoTangentVector0 + (3.0*t_2-2.0*t)*SegmentTwoTangentVector1;\n
- // a trick to eliminate some optical illusion caused by the gradient matter of normal in per-fragment shading
- // which is caused by linear interpolation of normal vs. nonlinear lighting
- // will notice some artifact in the areas with dramatically normal changes, so compress the normal differences here
- tangent.y *= min(1.0, length(position.xyz - vanishingPoint) / uSize.y ); \n
- }\n
- vec3 curvePoint = vec3(curveEnd - curvePoint2D.x*curveDirection,max(0.0,curvePoint2D.y));\n
- vec3 tangentVector = vec3(-tangent.x*curveDirection,tangent.y);\n
- \n
- // locate the new vertex position on the line passing through both vanishing point and the calculated curve point position
- vec3 curLiftDirection = vec3(0.0,-1.0,0.0);\n
- if(currentCenter.y != originalCenter.y)\n
- {\n
- curLiftDirection = normalize(curvePoint - vanishingPoint);\n
- tangentVector *= (curveDirection.y > 0.0) ? -1.0 : 1.0;\n
- // an heuristic adjustment here, to compensate the linear parameter mapping onto the nonlinear curve
- float Y0 = position.y - curveDirection.y * (position.x/curveDirection.x); \n
- float proportion;
- float refLength;\n
- if(abs(Y0-vanishingPoint.y) > abs(curveEnd.y-vanishingPoint.y)) \n
- {\n
- proportion = abs(curveEnd.y - Y0) / (abs(curveEnd.y-Y0)+abs(curveEnd.y - vanishingPoint.y)); \n
- refLength = proportion*length(originalCenter-vanishingPoint.xy) / (proportion-1.0); \n
- }\n
- else\n
- {\n
- proportion = abs(curveEnd.y - Y0) / abs(curveEnd.y - vanishingPoint.y);\n
- refLength = proportion*length(originalCenter-vanishingPoint.xy); \n
- }\n
- float Y1 = currentCenter.y - (normalize(currentCenter-vanishingPoint.xy)).y * refLength; \n
- position.y = mix(Y0, Y1, t0); \n
- }\n
- position.xz = curvePoint.xz - lengthFromCurve*curLiftDirection.xz;\n
- // calculate the normal vector, will be used for lighting
- normal = cross(curLiftDirection, normalize(tangentVector));\n
- // the signature of Z is decided by the page turning direction:
- // from left to right(negative); from right to left (positive)
- position.z *= -uIsTurningBack;\n
- normal.xy *= -uIsTurningBack;\n
- }\n
- // change the coordinate origin from the top-left of the page to its center
- position.xy -= uSize.xy * 0.5; \n
- }\n
- vNormal = uNormalMatrix * normal;\n
- gl_Position = uMvpMatrix * position;
- // varying parameters for fragment shader
- vTexCoord = aPosition + vec2(0.5);\n
- vTexCoord.x /= uTextureWidth;
- vPosition = uModelView * position;\n
- }\n
- );
-
- const char* fragmentShader = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- \n
- varying mediump vec2 vTexCoord;\n
- \n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
- uniform vec3 uSize;\n
- uniform vec2 uSpineShadowParameter;\n
- varying vec3 vNormal;\n
- varying vec4 vPosition;\n
- \n
- void main()\n
- {\n
- // need to re-normalize the interpolated normal
- vec3 normal = normalize( vNormal );\n
- // display page content
- vec4 texel;
- // display back image of the page, flip the texture
- if( dot(vPosition.xyz, normal) > 0.0 ) texel = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) );\n
- // display front image of the page
- else texel = texture2D( sTexture, vTexCoord );\n
-
- // display book spine, a stripe of shadowed texture
- float pixelPos = vTexCoord.x * uSize.x; \n
- float spineShadowCoef = 1.0; \n
- if( pixelPos < uSpineShadowParameter.x ) \n
- {\n
- float x = pixelPos - uSpineShadowParameter.x;\n
- float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );\n
- spineShadowCoef = normalize( vec2( uSpineShadowParameter.y*x/uSpineShadowParameter.x, y ) ).y;\n
- }\n
- // calculate the lighting
- // set the ambient color as vec3(0.4);
- float lightColor = abs( normal.z ) * 0.6 + 0.4;\n
- gl_FragColor = vec4( ( spineShadowCoef * lightColor ) * texel.rgb , texel.a ) * uColor;\n
- }
- );
-
Property::Map map;
Property::Map customShader;
- customShader[ Toolkit::Visual::Shader::Property::VERTEX_SHADER ] = vertexShader;
- customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = fragmentShader;
+ customShader[ Toolkit::Visual::Shader::Property::VERTEX_SHADER ] = SHADER_PAGE_TURN_EFFECT_VERT.data();
+ customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = SHADER_PAGE_TURN_EFFECT_FRAG.data();
customShader[ Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_X ] = 20;
customShader[ Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_Y ] = 20;
// CLASS HEADER
#include <dali-toolkit/internal/controls/scene3d-view/gltf-loader.h>
-#include <dali-toolkit/internal/controls/scene3d-view/gltf-shader.h>
// EXTERNAL INCLUDES
#include <dali/integration-api/debug.h>
#include <dali/devel-api/adaptor-framework/image-loading.h>
#include <dali/devel-api/adaptor-framework/file-stream.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
bool isEmissiveTexture = false;
std::string VERTEX_SHADER, FRAGMENT_SHADER;
- VERTEX_SHADER = GLES_VERSION_300;
- VERTEX_SHADER += PHYSICALLY_BASED_VERTEX_SHADER;
- FRAGMENT_SHADER = GLES_VERSION_300;
+ VERTEX_SHADER = SHADER_GLTF_GLES_VERSION_300_DEF.data();
+ VERTEX_SHADER += SHADER_GLTF_PHYSICALLY_BASED_SHADER_VERT.data();
+ FRAGMENT_SHADER = SHADER_GLTF_GLES_VERSION_300_DEF.data();
bool useIBL = ( scene3dView.GetLightType() >= Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT );
if( isMaterial )
{
MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx];
- if( SetTextureAndSampler( textureSet, materialInfo.baseColorTexture.index, FRAGMENT_SHADER, DEFINE_BASECOLOR_TEXTURE, addIdx ) )
+ if( SetTextureAndSampler( textureSet, materialInfo.baseColorTexture.index, FRAGMENT_SHADER, SHADER_GLTF_BASECOLOR_TEXTURE_DEF.data(), addIdx ) )
{
shaderTypeIndex += static_cast<int32_t>( ShaderType::BASECOLOR_SHADER );
isBaseColorTexture = true;
}
- if( SetTextureAndSampler( textureSet, materialInfo.metallicRoughnessTexture.index, FRAGMENT_SHADER, DEFINE_METALLICROUGHNESS_TEXTURE, addIdx ) )
+ if( SetTextureAndSampler( textureSet, materialInfo.metallicRoughnessTexture.index, FRAGMENT_SHADER, SHADER_GLTF_METALLICROUGHNESS_TEXTURE_DEF.data(), addIdx ) )
{
shaderTypeIndex += static_cast<int32_t>( ShaderType::METALLICROUGHNESS_SHADER );
isMetallicRoughnessTexture = true;
}
- if( SetTextureAndSampler( textureSet, materialInfo.normalTexture.index, FRAGMENT_SHADER, DEFINE_NORMAL_TEXTURE, addIdx ) )
+ if( SetTextureAndSampler( textureSet, materialInfo.normalTexture.index, FRAGMENT_SHADER, SHADER_GLTF_NORMAL_TEXTURE_DEF.data(), addIdx ) )
{
shaderTypeIndex += static_cast<int32_t>( ShaderType::NORMAL_SHADER );
isNormalTexture = true;
}
- if( SetTextureAndSampler( textureSet, materialInfo.occlusionTexture.index, FRAGMENT_SHADER, DEFINE_OCCLUSION_TEXTURE, addIdx ) )
+ if( SetTextureAndSampler( textureSet, materialInfo.occlusionTexture.index, FRAGMENT_SHADER, SHADER_GLTF_OCCULUSION_TEXTURE_DEF.data(), addIdx ) )
{
shaderTypeIndex += static_cast<int32_t>( ShaderType::OCCLUSION_SHADER );
isOcclusionTexture = true;
}
- if( SetTextureAndSampler( textureSet, materialInfo.emissiveTexture.index, FRAGMENT_SHADER, DEFINE_EMIT_TEXTURE, addIdx ) )
+ if( SetTextureAndSampler( textureSet, materialInfo.emissiveTexture.index, FRAGMENT_SHADER, SHADER_GLTF_EMIT_TEXTURE_DEF.data(), addIdx ) )
{
shaderTypeIndex += static_cast<int32_t>( ShaderType::EMIT_SHADER );
isEmissiveTexture = true;
if( useIBL )
{
shaderTypeIndex += static_cast<int32_t>( ShaderType::IBL_SHADER );
- FRAGMENT_SHADER += DEFINE_IBL_TEXTURE;
+ FRAGMENT_SHADER += SHADER_GLTF_IBL_TEXTURE_DEF.data();
Sampler sampler = Sampler::New();
sampler.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
}
}
- FRAGMENT_SHADER += PHYSICALLY_BASED_FRAGMENT_SHADER;
+ FRAGMENT_SHADER += SHADER_GLTF_PHYSICALLY_BASED_SHADER_FRAG.data();
if( !mShaderCache[shaderTypeIndex] )
{
mShaderCache[shaderTypeIndex] = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+++ /dev/null
-#ifndef DALI_TOOLKIT_INTERNAL_GLTF_SHADER_H
-#define DALI_TOOLKIT_INTERNAL_GLTF_SHADER_H
-
-/*
- * Belows Vertex Shader and Fragment Shader code are based off glTF WebGL PBR.
- * https://github.com/KhronosGroup/glTF-WebGL-PBR/
- *
- * Copyright (c) 2016-2017 Mohamad Moneimne and Contributors
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-namespace Internal
-{
-
-const char* GLES_VERSION_300 = {
- "#version 300 es\n\n"
- "precision highp float;\n\n"
-};
-
-const char* DEFINE_BASECOLOR_TEXTURE = {
- "#define TEXTURE_BASECOLOR\n\n"
- "uniform sampler2D uBaseColorSampler;\n"
- "uniform int uBaseColorTexCoordIndex;\n\n"
-};
-
-const char* DEFINE_METALLICROUGHNESS_TEXTURE = {
- "#define TEXTURE_METALLICROUGHNESS\n\n"
- "uniform sampler2D uMetallicRoughnessSampler;\n"
- "uniform int uMetallicRoughnessTexCoordIndex;\n\n"
-};
-
-const char* DEFINE_NORMAL_TEXTURE = {
- "#define TEXTURE_NORMAL\n\n"
- "uniform sampler2D uNormalSampler;\n"
- "uniform float uNormalScale;\n"
- "uniform int uNormalTexCoordIndex;\n\n"
-};
-
-const char* DEFINE_OCCLUSION_TEXTURE = {
- "#define TEXTURE_OCCLUSION\n\n"
- "uniform sampler2D uOcclusionSampler;\n"
- "uniform int uOcclusionTexCoordIndex;\n"
- "uniform float uOcclusionStrength;\n\n"
-};
-
-const char* DEFINE_EMIT_TEXTURE = {
- "#define TEXTURE_EMIT\n\n"
- "uniform sampler2D uEmissiveSampler;\n"
- "uniform int uEmissiveTexCoordIndex;\n"
- "uniform vec3 uEmissiveFactor;\n\n"
-};
-
-const char* DEFINE_IBL_TEXTURE = {
- "#define TEXTURE_IBL\n\n"
- "uniform sampler2D ubrdfLUT;\n"
- "uniform samplerCube uDiffuseEnvSampler;\n"
- "uniform samplerCube uSpecularEnvSampler;\n"
- "uniform vec4 uScaleIBLAmbient;\n"
- "uniform highp float uMipmapLevel;\n"
-};
-
-const char* PHYSICALLY_BASED_VERTEX_SHADER = {
- "in highp vec3 aPosition;\n"
- "in mediump vec2 aTexCoord0;\n"
- "in mediump vec2 aTexCoord1;\n"
- "in lowp vec3 aNormal;\n"
- "in lowp vec4 aTangent;\n"
- "in lowp vec4 aVertexColor;\n"
-
- "uniform mediump vec3 uSize;\n"
- "uniform mediump mat4 uModelMatrix;\n"
- "uniform mediump mat4 uViewMatrix;\n"
- "uniform mediump mat4 uProjection;\n"
- "uniform lowp int uLightType;\n"
- "uniform mediump vec3 uLightVector;\n"
- "uniform lowp int uIsColor;\n"
-
- "out lowp vec2 vUV[2];\n"
- "out lowp mat3 vTBN;\n"
- "out lowp vec4 vColor;\n"
- "flat out int visLight;\n"
- "out highp vec3 vLightDirection;\n"
- "out highp vec3 vPositionToCamera;\n"
-
- "void main()\n"
- "{\n"
- " highp vec4 invY = vec4(1.0, -1.0, 1.0, 1.0);\n"
- " highp vec4 positionW = uModelMatrix * vec4( aPosition * uSize, 1.0 );\n"
- " highp vec4 positionV = uViewMatrix * ( invY * positionW );\n"
-
- " vPositionToCamera = transpose( mat3( uViewMatrix ) ) * ( -vec3( positionV.xyz / positionV.w ) );\n"
- " vPositionToCamera *= invY.xyz;\n"
-
- " lowp vec3 bitangent = cross(aNormal, aTangent.xyz) * aTangent.w;\n"
- " vTBN = mat3( uModelMatrix ) * mat3(aTangent.xyz, bitangent, aNormal);\n"
-
- " vUV[0] = aTexCoord0;\n"
- " vUV[1] = aTexCoord1;\n"
-
- " visLight = 1;\n"
- " if( uLightType == 1 )\n"
- " {\n"
- " vLightDirection = ( invY.xyz * uLightVector ) - ( positionW.xyz / positionW.w );\n"
- " }\n"
- " else if( uLightType == 2 )\n"
- " {\n"
- " vLightDirection = -( invY.xyz * uLightVector );\n"
- " }\n"
- " else\n"
- " {\n"
- " visLight = 0;\n"
- " }\n"
-
- " vColor = vec4( 1.0 );\n"
- " if( uIsColor == 1 )\n"
- " {\n"
- " vColor = aVertexColor;\n"
- " }\n"
-
- " gl_Position = uProjection * positionV;\n" // needs w for proper perspective correction
- " gl_Position = gl_Position/gl_Position.w;\n"
- "}\n"
-};
-
-const char* PHYSICALLY_BASED_FRAGMENT_SHADER = {
- "uniform lowp vec3 uLightColor;\n"
- "uniform lowp vec4 uBaseColorFactor;\n"
- "uniform lowp vec2 uMetallicRoughnessFactors;\n"
- "uniform lowp int alphaMode;\n"
- "uniform lowp float alphaCutoff;\n"
-
- "in lowp vec2 vUV[2];\n"
- "in lowp mat3 vTBN;\n"
- "in lowp vec4 vColor;\n"
- "flat in int visLight;\n"
- "in highp vec3 vLightDirection;\n"
- "in highp vec3 vPositionToCamera;\n"
-
- "out vec4 FragColor;"
-
- "struct PBRInfo\n"
- "{\n"
- " mediump float NdotL;\n" // cos angle between normal and light direction
- " mediump float NdotV;\n" // cos angle between normal and view direction
- " mediump float NdotH;\n" // cos angle between normal and half vector
- " mediump float VdotH;\n" // cos angle between view direction and half vector
- " mediump vec3 reflectance0;\n" // full reflectance color (normal incidence angle)
- " mediump vec3 reflectance90;\n" // reflectance color at grazing angle
- " lowp float alphaRoughness;\n" // roughness mapped to a more linear change in the roughness (proposed by [2])
- "};\n"
-
- "const float M_PI = 3.141592653589793;\n"
- "const float c_MinRoughness = 0.04;\n"
-
- "vec3 getNormal()\n"
- "{\n"
- "#ifdef TEXTURE_NORMAL\n"
- " lowp vec3 n = texture( uNormalSampler, vUV[uNormalTexCoordIndex] ).rgb;\n"
- " n = normalize( vTBN * ( ( 2.0 * n - 1.0 ) * vec3( uNormalScale, uNormalScale, 1.0 ) ) );\n"
- "#else\n"
- " lowp vec3 n = normalize( vTBN[2].xyz );\n"
- "#endif\n"
- " return n;\n"
- "}\n"
-
- "vec3 specularReflection( PBRInfo pbrInputs )\n"
- "{\n"
- " return pbrInputs.reflectance0 + ( pbrInputs.reflectance90 - pbrInputs.reflectance0 ) * pow( clamp( 1.0 - pbrInputs.VdotH, 0.0, 1.0 ), 5.0 );\n"
- "}\n"
-
- "float geometricOcclusion( PBRInfo pbrInputs )\n"
- "{\n"
- " mediump float NdotL = pbrInputs.NdotL;\n"
- " mediump float NdotV = pbrInputs.NdotV;\n"
- " lowp float r = pbrInputs.alphaRoughness;\n"
-
- " lowp float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n"
- " lowp float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n"
- " return attenuationL * attenuationV;\n"
- "}\n"
-
- "float microfacetDistribution(PBRInfo pbrInputs)\n"
- "{\n"
- " mediump float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;\n"
- " lowp float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;\n"
- " return roughnessSq / (M_PI * f * f);\n"
- "}\n"
-
- "vec3 linear( vec3 color )\n"
- "{\n"
- " return pow(color,vec3(2.2));\n"
- "}\n"
-
- "void main()\n"
- "{\n"
- // Metallic and Roughness material properties are packed together
- // In glTF, these factors can be specified by fixed scalar values
- // or from a metallic-roughness map
- " lowp float metallic = uMetallicRoughnessFactors.x;\n"
- " lowp float perceptualRoughness = uMetallicRoughnessFactors.y;\n"
-
- // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
- // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
- "#ifdef TEXTURE_METALLICROUGHNESS\n"
- " lowp vec4 metrou = texture(uMetallicRoughnessSampler, vUV[uMetallicRoughnessTexCoordIndex]);\n"
- " metallic = metrou.b * metallic;\n"
- " perceptualRoughness = metrou.g * perceptualRoughness;\n"
- "#endif\n"
-
- " metallic = clamp(metallic, 0.0, 1.0);\n"
- " perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n"
- // Roughness is authored as perceptual roughness; as is convention,
- // convert to material roughness by squaring the perceptual roughness [2].
- " lowp float alphaRoughness = perceptualRoughness * perceptualRoughness;\n"
-
- "#ifdef TEXTURE_BASECOLOR\n"
- // The albedo may be defined from a base texture or a flat color
- " lowp vec4 baseColor = texture(uBaseColorSampler, vUV[uBaseColorTexCoordIndex]) * uBaseColorFactor;\n"
- " baseColor = vec4(linear(baseColor.rgb), baseColor.w);\n"
- "#else\n"
- " lowp vec4 baseColor = vColor * uBaseColorFactor;\n"
- "#endif\n"
-
- " if( alphaMode == 0 )\n"
- " {\n"
- " baseColor.w = 1.0;\n"
- " }\n"
- " else if( alphaMode == 1 )\n"
- " {\n"
- " if( baseColor.w >= alphaCutoff )"
- " {\n"
- " baseColor.w = 1.0;\n"
- " }\n"
- " else\n"
- " {\n"
- " baseColor.w = 0.0;\n"
- " }\n"
- " }\n"
-
- " lowp vec3 f0 = vec3(0.04);\n"
- " lowp vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);\n"
- " diffuseColor *= ( 1.0 - metallic );\n"
- " lowp vec3 specularColor = mix(f0, baseColor.rgb, metallic);\n"
-
- // Compute reflectance.
- " lowp float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n"
-
- // For typical incident reflectance range (between 4% to 100%) set the grazing reflectance to 100% for typical fresnel effect.
- // For very low reflectance range on highly diffuse objects (below 4%), incrementally reduce grazing reflecance to 0%.
- " lowp float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n"
- " lowp vec3 specularEnvironmentR0 = specularColor.rgb;\n"
- " lowp vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;\n"
-
- " mediump vec3 n = getNormal();\n" // normal at surface point
- " mediump vec3 v = normalize(vPositionToCamera);\n" // Vector from surface point to camera
- " mediump vec3 l = normalize(vLightDirection);\n" // Vector from light to surface point
- " mediump vec3 h = normalize(l+v);\n" // Half vector between both l and v
- " mediump vec3 reflection = -normalize(reflect(v, n));\n"
-
- " mediump float NdotL = clamp(dot(n, l), 0.001, 1.0);\n"
- " mediump float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n"
- " mediump float NdotH = dot(n, h);\n"
- " mediump float LdotH = dot(l, h);\n"
- " mediump float VdotH = dot(v, h);\n"
-
- " PBRInfo pbrInputs = PBRInfo(\n"
- " NdotL,\n"
- " NdotV,\n"
- " NdotH,\n"
- " VdotH,\n"
- " specularEnvironmentR0,\n"
- " specularEnvironmentR90,\n"
- " alphaRoughness\n"
- " );\n"
-
- // Calculate the shading terms for the microfacet specular shading model
- " lowp vec3 color = vec3(0.0);\n"
- " if( visLight == 1 )\n"
- " {\n"
- " lowp vec3 F = specularReflection( pbrInputs );\n"
- " lowp float G = geometricOcclusion( pbrInputs );\n"
- " lowp float D = microfacetDistribution( pbrInputs );\n"
-
- // Calculation of analytical lighting contribution
- " lowp vec3 diffuseContrib = ( 1.0 - F ) * ( diffuseColor / M_PI );\n"
- " lowp vec3 specContrib = F * G * D / ( 4.0 * NdotL * NdotV );\n"
- // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
- " color = NdotL * uLightColor * (diffuseContrib + specContrib);\n"
- " }\n"
-
- "#ifdef TEXTURE_IBL\n"
- " lowp float lod = ( perceptualRoughness * uMipmapLevel );\n"
- // retrieve a scale and bias to F0. See [1], Figure 3
- " lowp vec3 brdf = linear( texture( ubrdfLUT, vec2( NdotV, 1.0 - perceptualRoughness ) ).rgb );\n"
- " lowp vec3 diffuseLight = linear( texture( uDiffuseEnvSampler, n ).rgb );\n"
- " lowp vec3 specularLight = linear( textureLod( uSpecularEnvSampler, reflection, lod ).rgb );\n"
-
- " lowp vec3 diffuse = diffuseLight * diffuseColor * uScaleIBLAmbient.x;\n"
- " lowp vec3 specular = specularLight * ( specularColor * brdf.x + brdf.y ) * uScaleIBLAmbient.y;\n"
- " color += ( diffuse + specular );\n"
- "#endif\n"
-
- "#ifdef TEXTURE_OCCLUSION\n"
- " lowp float ao = texture( uOcclusionSampler, vUV[uOcclusionTexCoordIndex] ).r;\n"
- " color = mix( color, color * ao, uOcclusionStrength );\n"
- "#endif\n"
-
- "#ifdef TEXTURE_EMIT\n"
- " lowp vec3 emissive = linear( texture( uEmissiveSampler, vUV[uEmissiveTexCoordIndex] ).rgb ) * uEmissiveFactor;\n"
- " color += emissive;\n"
- "#endif\n"
-
- " FragColor = vec4( pow( color,vec3( 1.0 / 2.2 ) ), baseColor.a );\n"
- "}\n"
-};
-
-} // namespace internal
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // DALI_TOOLKIT_INTERNAL_GLTF_SHADER_H
\ No newline at end of file
#include <dali/public-api/rendering/shader.h>
#include <dali/public-api/rendering/texture-set.h>
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
namespace Dali
{
26.f / 130.f
};
-#define MAKE_SHADER(A)#A
-
-// Modify the vertex position according to the bounce coefficient;
-const char* MESH_VERTEX_SHADER = MAKE_SHADER(
-attribute mediump vec3 aPosition1;\n
-attribute mediump vec3 aPosition2;\n
-uniform mediump mat4 uMvpMatrix;\n
-uniform mediump vec3 uSize;
-uniform mediump float uBounceCoefficient;\n
-\n
-void main()\n
-{\n
- gl_Position = uMvpMatrix * vec4(mix( aPosition1, aPosition2, abs(uBounceCoefficient) )*uSize, 1.0);\n
-}
-);
-
-// use the actor color to paint every layer
-const char* MESH_FRAGMENT_SHADER = MAKE_SHADER(
-uniform lowp vec4 uColor;\n
-void main()\n
-{\n
- gl_FragColor = uColor;\n
-}\n
-);
-
} // namespace Anon
Actor CreateBouncingEffectActor( Property::Index& bouncePropertyIndex )
meshGeometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) );
// Create the shader
- Shader shader = Shader::New( MESH_VERTEX_SHADER, MESH_FRAGMENT_SHADER );
+ Shader shader = Shader::New( SHADER_BOUNCING_EFFECT_MESH_SHADER_VERT, SHADER_BOUNCING_EFFECT_MESH_SHADER_FRAG );
// Create renderer
Renderer renderer = Renderer::New( meshGeometry, shader );
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/controls/control/control-renderers.h>
#include <dali-toolkit/internal/controls/shadow-view/shadow-view-impl.h>
#include <dali-toolkit/internal/filters/blur-two-pass-filter.h>
const char* const BLUR_STRENGTH_PROPERTY_NAME = "BlurStrengthProperty";
const char* const SHADOW_COLOR_PROPERTY_NAME = "ShadowColorProperty";
-const char* const RENDER_SHADOW_VERTEX_SOURCE =
-
- " attribute mediump vec2 aPosition;\n"
- " uniform mediump mat4 uMvpMatrix;\n"
- " uniform mediump mat4 uModelMatrix;\n"
- " uniform vec3 uSize;\n"
- " varying vec2 vTexCoord;\n"
-
- " uniform mediump mat4 uLightCameraProjectionMatrix;\n"
- " uniform mediump mat4 uLightCameraViewMatrix;\n"
- "\n"
- "void main()\n"
- "{\n"
- " mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n"
- " vertexPosition.xyz *= uSize;\n"
- " gl_Position = uMvpMatrix * vertexPosition;\n"
- " vec4 textureCoords = uLightCameraProjectionMatrix * uLightCameraViewMatrix * uModelMatrix * vertexPosition;\n"
- " vTexCoord = 0.5 + 0.5 * (textureCoords.xy/textureCoords.w);\n"
- "}\n";
-
-const char* const RENDER_SHADOW_FRAGMENT_SOURCE =
- "varying mediump vec2 vTexCoord;\n"
- "uniform lowp vec4 uShadowColor;\n"
- "uniform sampler2D sTexture;\n"
-
- "void main()\n"
- "{\n"
- " lowp float alpha;\n"
- " alpha = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y)).a;\n"
- " gl_FragColor = vec4(uShadowColor.rgb, uShadowColor.a * alpha);\n"
- "}\n";
-
} // namespace
ShadowView::ShadowView( float downsampleWidthScale, float downsampleHeightScale )
mShadowPlane.SetProperty( Actor::Property::NAME, "SHADOW_PLANE" );
mShadowPlane.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
mShadowPlane.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
- Renderer shadowRenderer = CreateRenderer( RENDER_SHADOW_VERTEX_SOURCE, RENDER_SHADOW_FRAGMENT_SOURCE, Shader::Hint::OUTPUT_IS_TRANSPARENT, Uint16Pair(20,20) );
+ Renderer shadowRenderer = CreateRenderer( SHADER_SHADOW_VIEW_RENDER_SHADER_VERT, SHADER_SHADOW_VIEW_RENDER_SHADER_FRAG,
+ Shader::Hint::OUTPUT_IS_TRANSPARENT,
+ Uint16Pair(20,20) );
TextureSet textureSet = shadowRenderer.GetTextures();
textureSet.SetTexture( 0u, mOutputFrameBuffer.GetColorTexture() );
mShadowPlane.AddRenderer( shadowRenderer );
// INTERNAL_INCLUDES
#include <dali-toolkit/public-api/image-loader/sync-image-loader.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/controls/control/control-renderers.h>
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
#include <dali-toolkit/internal/visuals/visual-factory-impl.h>
const float GAUSSIAN_BLUR_DOWNSAMPLE_HEIGHT_SCALE = 0.5f;
const char* ALPHA_UNIFORM_NAME( "uAlpha" );
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
- uniform lowp float uAlpha;\n
- \n
- void main()\n
- {\n
- gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
- gl_FragColor.a *= uAlpha;
- }\n
-);
/**
* The constraint is used to blend the group of blurred images continuously with a unified blur strength property value which ranges from zero to one.
for(unsigned int i=0; i<mBlurLevels+1;i++)
{
- mRenderers[i] = CreateRenderer( BASIC_VERTEX_SOURCE, FRAGMENT_SHADER );
+ mRenderers[i] = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_SUPER_BLUR_VIEW_FRAG );
mRenderers[i].SetProperty( Dali::Renderer::Property::DEPTH_INDEX, (int)i );
self.AddRenderer( mRenderers[i] );
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali/integration-api/adaptor-framework/adaptor.h>
#include <dali-toolkit/internal/controls/control/control-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
const char* const DEFAULT_SAMPLER_TYPE_NAME( "sampler2D" );
const char* const CUSTOM_SAMPLER_TYPE_NAME( "samplerExternalOES" );
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- uniform highp mat4 uMvpMatrix;\n
- uniform highp vec3 uSize;\n
- \n
- void main()\n
- {\n
- mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
- vertexPosition.xyz *= uSize;\n
- gl_Position = uMvpMatrix * vertexPosition;\n
- }\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- \n
- void main()\n
- {\n
- gl_FragColor = vec4(0.0);\n
- }\n
-);
-
-const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- varying mediump vec2 vTexCoord;\n
- uniform highp mat4 uMvpMatrix;\n
- uniform highp vec3 uSize;\n
- varying mediump vec2 sTexCoordRect;\n
- void main()\n
- {\n
- gl_Position = uMvpMatrix * vec4(aPosition * uSize.xy, 0.0, 1.0);\n
- vTexCoord = aPosition + vec2(0.5);\n
- }\n
-);
-
-const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
- uniform lowp vec4 uColor;\n
- varying mediump vec2 vTexCoord;\n
- uniform samplerExternalOES sTexture;\n
- void main()\n
- {\n
- gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
- }\n
-);
-
} // anonymous namepsace
VideoView::VideoView( Dali::VideoSyncMode syncMode )
{
// For underlay rendering mode, video display area have to be transparent.
Geometry geometry = VisualFactoryCache::CreateQuadGeometry();
- Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+ Shader shader = Shader::New( SHADER_VIDEO_VIEW_VERT, SHADER_VIDEO_VIEW_FRAG );
mOverlayRenderer = Renderer::New( geometry, shader );
mOverlayRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
}
if( !vertexShaderValue || !checkShader )
{
- vertexShader = VERTEX_SHADER_TEXTURE;
+ vertexShader = SHADER_VIDEO_VIEW_TEXTURE_VERT.data();
}
Property::Value* fragmentShaderValue = mEffectPropertyMap.Find( CUSTOM_FRAGMENT_SHADER );
if( !fragmentShaderValue || !checkShader )
{
- fragmentShader += FRAGMENT_SHADER_TEXTURE;
+ fragmentShader += SHADER_VIDEO_VIEW_TEXTURE_FRAG.data();
}
}
else
{
- vertexShader = VERTEX_SHADER_TEXTURE;
- fragmentShader += FRAGMENT_SHADER_TEXTURE;
+ vertexShader = SHADER_VIDEO_VIEW_TEXTURE_VERT.data();
+ fragmentShader += SHADER_VIDEO_VIEW_TEXTURE_FRAG.data();
}
return Dali::Shader::New( vertexShader, fragmentShader );
DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "loadImagesAutomatically", BOOLEAN, LOAD_IMAGES_AUTOMATICALLY )
DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "defaultTextEncodingName", STRING, DEFAULT_TEXT_ENCODING_NAME )
DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "defaultFontSize", INTEGER, DEFAULT_FONT_SIZE )
+DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "scrollPosition", VECTOR2, SCROLL_POSITION )
+DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "scrollSize", VECTOR2, SCROLL_SIZE )
+DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "contentSize", VECTOR2, CONTENT_SIZE )
DALI_SIGNAL_REGISTRATION( Toolkit, WebView, "pageLoadStarted", PAGE_LOAD_STARTED_SIGNAL )
DALI_SIGNAL_REGISTRATION( Toolkit, WebView, "pageLoadFinished", PAGE_LOAD_FINISHED_SIGNAL )
DALI_SIGNAL_REGISTRATION( Toolkit, WebView, "pageLoadError", PAGE_LOAD_ERROR_SIGNAL )
+DALI_SIGNAL_REGISTRATION( Toolkit, WebView, "scrollEdgeReached", SCROLL_EDGE_REACHED_SIGNAL )
DALI_TYPE_REGISTRATION_END()
mWebEngine.PageLoadStartedSignal().Connect( this, &WebView::OnPageLoadStarted );
mWebEngine.PageLoadFinishedSignal().Connect( this, &WebView::OnPageLoadFinished );
mWebEngine.PageLoadErrorSignal().Connect( this, &WebView::OnPageLoadError );
+ mWebEngine.ScrollEdgeReachedSignal().Connect( this, &WebView::OnScrollEdgeReached );
}
}
}
}
+void WebView::ScrollBy( int deltaX, int deltaY )
+{
+ if ( mWebEngine )
+ {
+ mWebEngine.ScrollBy( deltaX, deltaY );
+ }
+}
+
bool WebView::CanGoForward()
{
return mWebEngine ? mWebEngine.CanGoForward() : false;
return mPageLoadErrorSignal;
}
+Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& WebView::ScrollEdgeReachedSignal()
+{
+ return mScrollEdgeReachedSignal;
+}
+
void WebView::OnPageLoadStarted( const std::string& url )
{
if( !mPageLoadStartedSignal.Empty() )
}
}
+void WebView::OnScrollEdgeReached( Dali::WebEnginePlugin::ScrollEdge edge )
+{
+ if( !mScrollEdgeReachedSignal.Empty() )
+ {
+ Dali::Toolkit::WebView handle( GetOwner() );
+ mScrollEdgeReachedSignal.Emit( handle, edge );
+ }
+}
+
bool WebView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
{
Dali::BaseHandle handle( object );
webView.PageLoadErrorSignal().Connect( tracker, functor );
connected = true;
}
+ else if( 0 == strcmp( signalName.c_str(), SCROLL_EDGE_REACHED_SIGNAL ) )
+ {
+ webView.ScrollEdgeReachedSignal().Connect( tracker, functor );
+ connected = true;
+ }
return connected;
}
}
break;
}
+ case Toolkit::WebView::Property::SCROLL_POSITION:
+ {
+ Vector2 input;
+ if ( value.Get( input ) )
+ {
+ impl.SetScrollPosition( input.x, input.y );
+ }
+ break;
+ }
}
}
}
value = impl.GetDefaultFontSize();
break;
}
+ case Toolkit::WebView::Property::SCROLL_POSITION:
+ {
+ int x, y;
+ impl.GetScrollPosition( x, y );
+ value = Vector2( x, y );
+ break;
+ }
+ case Toolkit::WebView::Property::SCROLL_SIZE:
+ {
+ int width, height;
+ impl.GetScrollSize( width, height );
+ value = Vector2( width, height );
+ break;
+ }
+ case Toolkit::WebView::Property::CONTENT_SIZE:
+ {
+ int width, height;
+ impl.GetContentSize( width, height );
+ value = Vector2( width, height );
+ break;
+ }
default:
break;
}
EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
}
+void WebView::SetScrollPosition( int x, int y )
+{
+ if( mWebEngine )
+ {
+ mWebEngine.SetScrollPosition( x, y );
+ }
+}
+
+void WebView::GetScrollPosition( int& x, int& y ) const
+{
+ if( mWebEngine )
+ {
+ mWebEngine.GetScrollPosition( x, y );
+ }
+}
+
+void WebView::GetScrollSize( int& width, int& height ) const
+{
+ if( mWebEngine )
+ {
+ mWebEngine.GetScrollSize( width, height );
+ }
+}
+
+void WebView::GetContentSize( int& width, int& height ) const
+{
+ if( mWebEngine )
+ {
+ mWebEngine.GetContentSize( width, height );
+ }
+}
+
Toolkit::WebView::CacheModel::Type WebView::GetCacheModel() const
{
return mWebEngine ? static_cast< Toolkit::WebView::CacheModel::Type >( mWebEngine.GetCacheModel() ) : Toolkit::WebView::CacheModel::DOCUMENT_VIEWER;
void Resume();
/**
+ * @copydoc Dali::Toolkit::WebView::ScrollBy()
+ */
+ void ScrollBy( int deltaX, int deltaY );
+
+ /**
* @copydoc Dali::Toolkit::WebView::CanGoForward()
*/
bool CanGoForward();
*/
Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
+ /**
+ * @copydoc Dali::Toolkit::WebView::ScrollEdgeReachedSignal()
+ */
+ Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
+
public: // Properties
/**
WebView& operator=( const WebView& webView );
/**
+ * @brief Sets an absolute scroll of the given view.
+ * @param[in] x The coordinate x of scroll
+ * @param[in] y The coordinate y of scroll
+ */
+ void SetScrollPosition( int x, int y );
+
+ /**
+ * @brief Gets the current scroll position of the given view.
+ * @param[out] x The coordinate x of scroll
+ * @param[out] y The coordinate y of scroll
+ */
+ void GetScrollPosition( int& x, int& y ) const;
+
+ /**
+ * @brief Gets the possible scroll size of the given view.
+ * @param[out] width The width of scroll size
+ * @param[out] height The height of scroll size
+ */
+ void GetScrollSize( int& width, int& height ) const;
+
+ /**
+ * @brief Gets the last known content's size.
+ * @param[out] width The width of content's size
+ * @param[out] height The height of content's size
+ */
+ void GetContentSize( int& width, int& height ) const;
+
+ /**
* @brief Get cache model option. The default isToolkit::WebView::CacheModel::DOCUMENT_VIEWER.
* @see Toolkit::WebView::CacheModel::Type
*/
*/
void OnPageLoadError( const std::string& url, int errorCode );
+ /**
+ * @brief Callback function to be called when scroll edge is reached.
+ * @param[in] e The scroll edge reached.
+ */
+ void OnScrollEdgeReached( Dali::WebEnginePlugin::ScrollEdge edge );
+
private:
std::string mUrl;
Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadStartedSignal;
Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadFinishedSignal;
Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType mPageLoadErrorSignal;
+ Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
};
} // namespace Internal
${toolkit_src_dir}/transition-effects/cube-transition-wave-effect-impl.cpp
${toolkit_src_dir}/text/xhtml-entities.cpp
${toolkit_src_dir}/drag-drop-detector/drag-and-drop-detector-impl.cpp
+ ${toolkit_src_dir}/graphics/generated/builtin-shader-gen.cpp
)
SET( SOURCES ${SOURCES}
// INTERNAL INCLUDES
#include <dali-toolkit/internal/controls/control/control-renderers.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
1.0f/16.0f, 1.0f/16.0f, 1.0f/16.0f, 0.5f/16.0f,
0.5f/16.0f, 0.5f/16.0f, 0.5f/16.0f };
-const char* BLUR_TWO_PASS_FRAGMENT_SOURCE =
-{
- "precision highp float;\n"
- "varying mediump vec2 vTexCoord;\n"
- "uniform sampler2D sTexture;\n"
- "uniform vec2 uSampleOffsets[NUM_SAMPLES];\n"
- "uniform float uSampleWeights[NUM_SAMPLES];\n"
- "void main()\n"
- "{\n"
- " vec4 color = vec4(0.0);\n"
- " for( int i = 0; i < NUM_SAMPLES; ++i )\n"
- " {\n"
- " color += texture2D( sTexture, vTexCoord + uSampleOffsets[i] ) * uSampleWeights[i];\n"
- " }\n"
- " gl_FragColor = color;\n"
- "}\n"
-};
-
std::string GetOffsetUniformName( int index )
{
std::ostringstream oss;
return oss.str();
}
-const char* BLEND_TWO_IMAGES_FRAGMENT_SOURCE =
-{
- "precision highp float;\n"
- "uniform float uBlurStrength;\n "
- "uniform sampler2D sTexture;\n"
- "uniform sampler2D sEffect;\n"
- "varying mediump vec2 vTexCoord;\n"
- "void main()\n"
- "{\n"
- " gl_FragColor = texture2D( sTexture, vTexCoord ) * uBlurStrength"
- " + texture2D( sEffect, vTexCoord )*(1.0-uBlurStrength); \n"
- "}\n"
-};
-
const char* const BLUR_STRENGTH_UNIFORM_NAME( "uBlurStrength" );
const char* const EFFECT_IMAGE_NAME( "sEffect" );
// Set up blur-two-pass custom shader
std::ostringstream sstream;
sstream << "#define NUM_SAMPLES " << kernelSize << "\n";
- sstream << BLUR_TWO_PASS_FRAGMENT_SOURCE;
+ sstream << SHADER_BLUR_TWO_PASS_SHADER_FRAG;
std::string fragmentSource( sstream.str() );
// create actor to render input with applied emboss effect
mBlurredFrameBuffer.AttachColorTexture( blurredTexture );
// create an actor to blend the blurred image and the input image with the given blur strength
- Renderer rendererForBlending = CreateRenderer( BASIC_VERTEX_SOURCE, BLEND_TWO_IMAGES_FRAGMENT_SOURCE );
+ Renderer rendererForBlending = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_BLUR_TWO_IMAGES_SHADER_FRAG );
TextureSet textureSetForBlending = rendererForBlending.GetTextures();
textureSetForBlending.SetTexture( 0u, blurredTexture );
textureSetForBlending.SetTexture( 1u, mInputTexture );
// INTERNAL INCLUDES
#include <dali-toolkit/internal/controls/control/control-renderers.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
namespace
{
-const char* EMBOSS_FRAGMENT_SOURCE =
-{
- "precision highp float;\n"
- "varying mediump vec2 vTexCoord;\n"
- "uniform sampler2D sTexture;\n"
- "uniform vec2 uTexScale;\n"
- "uniform vec3 uCoefficient;\n"
- "\n"
- "void main()\n"
- "{\n"
- " vec4 color = uCoefficient.x * texture2D( sTexture, vTexCoord + vec2(0.0, -uTexScale.y) );\n"
- " color += uCoefficient.y * texture2D( sTexture, vTexCoord );\n"
- " color += uCoefficient.z * texture2D( sTexture, vTexCoord + vec2(0.0, uTexScale.y) );\n"
- " gl_FragColor = color;\n"
- "}\n"
-};
-
-const char* const COMPOSITE_FRAGMENT_SOURCE =
-{
- "varying mediump vec2 vTexCoord;\n"
- "uniform sampler2D sTexture;\n"
- "uniform lowp vec4 uEffectColor;\n"
- "void main()\n"
- "{\n"
- " gl_FragColor = uEffectColor;\n"
- " gl_FragColor.a *= texture2D( sTexture, vTexCoord).a;\n"
- "}\n"
-};
-
const char* const TEX_SCALE_UNIFORM_NAME( "uTexScale" );
const char* const COEFFICIENT_UNIFORM_NAME( "uCoefficient" );
const char* const COLOR_UNIFORM_NAME( "uEffectColor" );
mActorForInput1.RegisterProperty( TEX_SCALE_UNIFORM_NAME, textureScale );
mActorForInput1.RegisterProperty( COEFFICIENT_UNIFORM_NAME, Vector3( 2.f, -1.f, -1.f ) );
// set EMBOSS custom shader
- Renderer renderer1 = CreateRenderer( BASIC_VERTEX_SOURCE, EMBOSS_FRAGMENT_SOURCE );
+ Renderer renderer1 = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_EMBOSS_FILTER_SHADER_FRAG );
SetRendererTexture( renderer1, mInputTexture );
mActorForInput1.AddRenderer( renderer1 );
mRootActor.Add( mActorForInput1 );
mActorForInput2.RegisterProperty( TEX_SCALE_UNIFORM_NAME, textureScale );
mActorForInput2.RegisterProperty( COEFFICIENT_UNIFORM_NAME, Vector3( -1.f, -1.f, 2.f ) );
// set EMBOSS custom shader
- Renderer renderer2 = CreateRenderer( BASIC_VERTEX_SOURCE, EMBOSS_FRAGMENT_SOURCE );
+ Renderer renderer2 = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_EMBOSS_FILTER_SHADER_FRAG );
SetRendererTexture( renderer2, mInputTexture );
mActorForInput2.AddRenderer( renderer2 );
mRootActor.Add( mActorForInput2 );
mRootActor.Add( mActorForComposite );
- mRendererForEmboss1 = CreateRenderer( BASIC_VERTEX_SOURCE, COMPOSITE_FRAGMENT_SOURCE );
+ mRendererForEmboss1 = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_EMBOSS_FILTER_COMPOSITE_SHADER_FRAG );
SetRendererTexture( mRendererForEmboss1, mFrameBufferForEmboss1 );
mRendererForEmboss1.RegisterProperty( COLOR_UNIFORM_NAME, Color::BLACK );
mActorForComposite.AddRenderer( mRendererForEmboss1 );
- mRendererForEmboss2 = CreateRenderer( BASIC_VERTEX_SOURCE, COMPOSITE_FRAGMENT_SOURCE );
+ mRendererForEmboss2 = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_EMBOSS_FILTER_COMPOSITE_SHADER_FRAG );
SetRendererTexture( mRendererForEmboss2, mFrameBufferForEmboss2 );
mRendererForEmboss2.RegisterProperty( COLOR_UNIFORM_NAME, Color::WHITE );
mActorForComposite.AddRenderer( mRendererForEmboss2 );
// INTERNAL INCLUDES
#include <dali-toolkit/internal/controls/control/control-renderers.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
namespace
{
-const char* const SPREAD_FRAGMENT_SOURCE =
-{
- "precision highp float;\n"
- "varying mediump vec2 vTexCoord;\n"
- "uniform sampler2D sTexture;\n"
- "uniform int uSpread;\n"
- "uniform vec2 uTexScale;\n"
- "void main()\n"
- "{\n"
- " vec4 color = texture2D( sTexture, vTexCoord);\n"
- " for( int i = 1; i <= uSpread; ++i )\n"
- " {\n"
- " vec2 offset = uTexScale * float(i);\n"
- " color = max( texture2D( sTexture, vTexCoord + offset), color );\n"
- " color = max( texture2D( sTexture, vTexCoord - offset), color );\n"
- " }\n"
- " gl_FragColor = color;\n"
- "}\n"
-};
-
const char* const SPREAD_UNIFORM_NAME( "uSpread" );
const char* const TEX_SCALE_UNIFORM_NAME( "uTexScale" );
mActorForInput.RegisterProperty( SPREAD_UNIFORM_NAME, mSpread );
mActorForInput.RegisterProperty( TEX_SCALE_UNIFORM_NAME, Vector2( 1.0f / mTargetSize.width, 0.0f ) );
- Renderer rendererForInput = CreateRenderer( BASIC_VERTEX_SOURCE, SPREAD_FRAGMENT_SOURCE );
+ Renderer rendererForInput = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_SPREAD_FILTER_SHADER_FRAG );
SetRendererTexture( rendererForInput, mInputTexture );
mActorForInput.AddRenderer( rendererForInput );
// register properties as shader uniforms
mActorForHorz.RegisterProperty( SPREAD_UNIFORM_NAME, mSpread );
mActorForHorz.RegisterProperty( TEX_SCALE_UNIFORM_NAME, Vector2( 0.0f, 1.0f / mTargetSize.height ) );
- Renderer rendererForHorz = CreateRenderer( BASIC_VERTEX_SOURCE, SPREAD_FRAGMENT_SOURCE );
+ Renderer rendererForHorz = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_SPREAD_FILTER_SHADER_FRAG );
SetRendererTexture( rendererForHorz, textureForHorz );
mActorForHorz.AddRenderer( rendererForHorz );
--- /dev/null
+varying mediump vec2 vTexCoord;
+
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ mediump vec4 color = texture2D( sTexture, vTexCoord );
+ if(color.a <= 0.0001)
+ {
+ discard;
+ }
+ gl_FragColor = color * uColor;
+}
--- /dev/null
+precision mediump float;
+
+uniform mediump vec4 start_color;
+uniform mediump vec4 end_color;
+uniform mediump float gradient_offset;
+
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vStart;
+varying mediump vec2 vEnd;
+
+float get_position(vec2 x, vec2 s, vec2 e)
+{
+ vec2 df = e - s;
+ vec2 dx = x - s;
+
+#ifdef GRADIENT_TYPE_LINEAR
+ return dot(dx,df)/dot(df,df);
+#endif
+/* GradientType::LINEAR */
+
+#ifdef GRADIENT_TYPE_RADIAL
+ return sqrt(dot(dx,dx)/dot(df,df));
+#endif
+/* GradientType::RADIAL */
+}
+
+float recalculate(float r)
+{
+#ifdef SPREAD_TYPE_REFLECT
+ return 1.0 - abs(mod(r, 2.0) - 1.0);
+#endif
+/* SpreadType::REFLECT */
+
+#ifdef SPREAD_TYPE_REPEAT
+ return fract(r);
+#endif
+/* SpreadType::REPEAT*/
+
+#ifdef SPREAD_TYPE_CLAMP
+ return clamp(r, 0.0, 1.0);
+#endif
+/* SpreadType::CLAMP */
+}
+
+void main()
+{
+ float r = get_position( vTexCoord, vStart, vEnd );
+ r = recalculate( r + gradient_offset );
+ vec4 color = mix( start_color, end_color, r );
+ gl_FragColor = color;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+uniform mediump vec2 start_point;
+uniform mediump vec2 end_point;
+uniform mediump vec2 rotate_center;
+uniform mediump float rotate_angle;
+
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vStart;
+varying mediump vec2 vEnd;
+
+vec2 rotate(vec2 x, vec2 c, float a)
+{
+ vec2 d = x - c;
+ vec2 r = vec2(d.x * cos(a) - d.y * sin(a), d.x * sin(a) + d.y * cos(a));
+
+#ifdef UNIT_TYPE_BOUNDING_BOX
+ return r + c;
+#endif
+
+ /* UnitType::OBJECT_BOUNDING_BOX */
+#ifdef UNIT_TYPE_USER
+ return (r + c) / uSize.x;
+#endif
+ /* UnitType::USER_SPACE*/
+}
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix( uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy );
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ vStart = rotate( start_point, rotate_center, rotate_angle );
+ vEnd = rotate( end_point, rotate_center, rotate_angle );
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+
+#ifdef UNIT_TYPE_BOUNDING_BOX
+ vTexCoord = vec2(aPosition.x, -aPosition.y);
+#endif
+/* UnitType::OBJECT_BOUNDING_BOX */
+
+#ifdef UNIT_TYPE_USER
+ vTexCoord = vec2(aPosition.x, -aPosition.y * uSize.y / uSize.x);
+#endif
+/* UnitType::USER_SPACE*/
+}
--- /dev/null
+INPUT mediump vec2 vPosition;
+
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform mediump float thickness;
+uniform mediump float radius;
+uniform mediump float startAngle;
+uniform mediump float sweepAngle;
+
+const mediump float M_PI_OVER_2 = 1.57079632679;
+const mediump float M_PI = 3.14159265359;
+const mediump float M_PI_2 = 6.28318530718;
+
+mediump float GetOpacity()
+{
+ mediump float start = radians( mod( startAngle, 360.0 ) );
+ mediump float angle = mod( atan( vPosition.y, vPosition.x ) + M_PI_OVER_2 - start, M_PI_2 );
+ mediump float dist = length( vPosition );
+ if( angle <= radians( sweepAngle ) )
+ {
+ return smoothstep( -1.0, 1.0, thickness / 2.0 - ( abs( dist - radius ) ) );
+ }
+ mediump float end = radians( mod( startAngle + sweepAngle, 360.0 ) );
+ mediump vec2 q0 = vec2( dist * cos( start - M_PI_OVER_2 ), dist * sin( start - M_PI_OVER_2 ) );
+ mediump vec2 q1 = vec2( dist * cos( end - M_PI_OVER_2 ), dist * sin( end - M_PI_OVER_2 ) );
+ mediump float opacity = 1.0 - smoothstep( 0.0, 2.0, min( length( vPosition - q0 ), length( vPosition - q1 ) ) );
+ opacity *= step( 0.0, thickness / 2.0 - abs( dist - radius ) );
+ return opacity;
+}
+
+void main()
+{
+ OUT_COLOR = vec4( mixColor, 1.0 ) * uColor;
+ OUT_COLOR.a *= GetOpacity();
+}
--- /dev/null
+INPUT mediump vec2 vPosition;
+
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform mediump float thickness;
+uniform mediump float radius;
+uniform mediump float startAngle;
+uniform mediump float sweepAngle;
+
+const mediump float M_PI_OVER_2 = 1.57079632679;
+const mediump float M_PI_2 = 6.28318530718;
+
+mediump float GetOpacity()
+{
+ mediump float start = radians( mod( startAngle, 360.0 ) );
+ mediump float angle = mod( atan( vPosition.y, vPosition.x ) + M_PI_OVER_2 - start, M_PI_2 );
+ mediump float dist = length( vPosition );
+ if( angle <= radians( sweepAngle ) )
+ {
+ return smoothstep( -1.0, 1.0, thickness / 2.0 - ( abs( dist - radius ) ) );
+ }
+ mediump float end = radians( mod( startAngle + sweepAngle, 360.0 ) );
+ mediump vec2 q0 = vec2( radius * cos( start - M_PI_OVER_2 ), radius * sin( start - M_PI_OVER_2 ) );
+ mediump vec2 q1 = vec2( radius * cos( end - M_PI_OVER_2 ), radius * sin( end - M_PI_OVER_2 ) );
+ return smoothstep( -1.0, 1.0, thickness / 2.0 - min( length( vPosition - q0 ), length( vPosition - q1 ) ) );
+}
+
+void main()
+{
+ OUT_COLOR = vec4( mixColor, 1.0 ) * uColor;
+ OUT_COLOR.a *= GetOpacity();
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+OUTPUT mediump vec2 vPosition;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ vPosition = aPosition* visualSize;
+ return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
\ No newline at end of file
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform sampler2D sEffect;
+uniform lowp vec4 uColor;
+uniform float uBloomIntensity;
+uniform float uImageIntensity;
+uniform float uBloomSaturation;
+uniform float uImageSaturation;
+
+vec4 ChangeSaturation(vec4 col, float sat)
+{
+ float grey = dot(col.rgb, vec3(0.3, 0.6, 0.1));
+ return mix(vec4(grey, grey, grey, 1.0), col, sat);
+}
+
+void main()
+{
+ mediump vec4 image;
+ mediump vec4 bloom;
+ image = texture2D(sTexture, vTexCoord);
+ bloom = texture2D(sEffect, vTexCoord);
+ image = ChangeSaturation(image, uImageSaturation) * uImageIntensity;
+ bloom = ChangeSaturation(bloom, uBloomSaturation) * uBloomIntensity;
+ image *= 1.0 - clamp(bloom, 0.0, 1.0); // darken base where bloom is strong, to prevent excessive burn-out of result
+ gl_FragColor = image + bloom;
+}
\ No newline at end of file
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform mediump float uBloomThreshold;
+uniform mediump float uRecipOneMinusBloomThreshold;
+
+void main()
+{
+ mediump vec4 col;
+ col = texture2D(sTexture, vTexCoord);
+ col = (col - uBloomThreshold) * uRecipOneMinusBloomThreshold; // remove intensities lower than the thresold and remap intensities above the threshold to [0..1]
+ gl_FragColor = clamp(col, 0.0, 1.0);
+}
\ No newline at end of file
--- /dev/null
+precision highp float;
+uniform float uBlurStrength;
+uniform sampler2D sTexture;
+uniform sampler2D sEffect;
+varying mediump vec2 vTexCoord;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uBlurStrength
+ + texture2D( sEffect, vTexCoord )*(1.0-uBlurStrength);
+}
\ No newline at end of file
--- /dev/null
+precision highp float;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform vec2 uSampleOffsets[NUM_SAMPLES];
+uniform float uSampleWeights[NUM_SAMPLES];
+
+void main()
+{
+ vec4 color = vec4(0.0);
+ for( int i = 0; i < NUM_SAMPLES; ++i )
+ {
+ color += texture2D( sTexture, vTexCoord + uSampleOffsets[i] ) * uSampleWeights[i];
+ }
+ gl_FragColor = color;
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump float vAlpha;
+
+uniform lowp vec4 uColor;
+uniform lowp vec4 borderColor;
+uniform lowp vec3 mixColor;
+uniform mediump float borderSize;
+
+void main()
+{
+ OUT_COLOR = vec4(mixColor, 1.0) * borderColor * uColor;
+ OUT_COLOR.a *= smoothstep(0.0, 1.5, vAlpha) * smoothstep( borderSize + 1.5, borderSize, vAlpha );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+INPUT mediump vec2 aDrift;
+OUTPUT mediump float vAlpha;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump float borderSize;
+
+void main()
+{
+ vec2 position = aPosition*(uSize.xy+vec2(0.75)) + aDrift*(borderSize+1.5);
+ gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);
+ vAlpha = min( abs(aDrift.x), abs(aDrift.y) )*(borderSize+1.5);
+}
\ No newline at end of file
--- /dev/null
+uniform lowp vec4 uColor;
+uniform lowp vec4 borderColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ OUT_COLOR = vec4(mixColor, 1.0) * borderColor * uColor;
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+INPUT mediump vec2 aDrift;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump float borderSize;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec2 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy;
+}
+
+void main()
+{
+ vec2 position = ComputeVertexPosition() + aDrift*borderSize;
+ gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);
+}
\ No newline at end of file
--- /dev/null
+// Use the actor color to paint every layer
+uniform lowp vec4 uColor;
+
+void main()
+{
+ gl_FragColor = uColor;
+}
--- /dev/null
+// Modify the vertex position according to the bounce coefficient
+attribute mediump vec3 aPosition1;
+attribute mediump vec3 aPosition2;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump vec3 uSize;
+uniform mediump float uBounceCoefficient;
+
+void main()
+{
+ gl_Position = uMvpMatrix * vec4(mix( aPosition1, aPosition2, abs(uBounceCoefficient) )*uSize, 1.0);
+}
--- /dev/null
+precision highp float;
+uniform vec3 uHSVDelta;
+uniform float uIgnoreAlpha;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+
+float rand(vec2 co)
+{
+ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
+}
+
+vec3 rgb2hsv(vec3 c)
+{
+ vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
+ vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
+ vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
+
+ float d = q.x - min(q.w, q.y);
+ float e = 1.0e-10;
+ return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
+}
+
+vec3 hsv2rgb(vec3 c)
+{
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
+ return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
+}
+
+void main()
+{
+ vec4 color = texture2D(sTexture, vTexCoord);
+ vec3 hsvColor = rgb2hsv( color.rgb );
+ // modify the hsv Value
+ hsvColor += uHSVDelta * rand(vTexCoord);
+ // if the new vale exceeds one, then decrease it
+ hsvColor -= max(hsvColor*2.0 - vec3(2.0), 0.0);
+ // if the new vale drops below zero, then increase it
+ hsvColor -= min(hsvColor*2.0, 0.0);
+ color.rgb = hsv2rgb( hsvColor );
+ // uIgnoreAlpha decide the result alpha will be 1.0 or source's alpha
+ color.a += uIgnoreAlpha;
+ gl_FragColor = color;
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform lowp vec4 uColor;
+uniform sampler2D sBackground;
+uniform sampler2D sBubbleShape;
+varying mediump float vPercentage;
+varying mediump vec2 vEffectTexCoord;
+
+void main()
+{
+ // Get the emit pisition color, and Mix with the actor color
+ mediump vec4 fragColor = texture2D(sBackground, vEffectTexCoord)*uColor;
+
+ // Apply the shape defined by the texture contained sBubbleShape
+ // And make the opacity being 0.7, and animate from 0.7 to 0 during the last 1/3 of movement
+ fragColor.a*= texture2D(sBubbleShape, vTexCoord).a * ( 2.1 - max( vPercentage*2.1, 1.4 ) );
+
+ gl_FragColor = fragColor;
+}
\ No newline at end of file
--- /dev/null
+attribute mediump float aIndex;
+attribute mediump vec2 aPosition;
+attribute highp vec2 aTexCoord;
+varying mediump vec2 vTexCoord;
+uniform mediump mat4 uMvpMatrix;
+// the gravity applied to the y direction
+uniform mediump float uGravity;
+// xy: the emit position of the bubble; zw: the destination of the bubble.
+// The bubble is moving from (xy) to (zw plus the y drop influenced by gravity).
+uniform vec4 uStartEndPosition[NUMBER_OF_BUBBLE];
+// The undergoing percentage of the bubble movement. 0.0: start from emit position, 1.0: reach the destination
+uniform float uPercentage[NUMBER_OF_BUBBLE];
+uniform vec2 uInvertedMovementArea;
+// The bubble number is restricted by the available uniform num.
+// To increase the displayed bubble, every uStartEndPosition and uPercentage uniform is applied to a small bunch of bubbles (9 here)
+// The offset defines the random offset between bubbles within the bunch.
+uniform vec2 uOffset[9];
+// This uniform is used to change the bubble size during running time
+uniform float uDynamicScale;
+varying float vPercentage;
+varying vec2 vEffectTexCoord;
+
+void main()
+{
+ vec4 position = vec4( aPosition, 0.0, 1.0 );
+ // The Z coordinate is used to record the bubble index within current mesh actor
+ int index = int(aIndex);
+ //for some i between 0 ~ NUMBER_OF_BUBBLE-1: i,i+NUMBER_OF_BUBBLE, i+NUMBER_OF_BUBBLE*2, ... (up to i+NUMBER_OF_BUBBLE*8) belongs to the same bunch.
+ int groupIdx = index / NUMBER_OF_BUBBLE;
+ // The bubbles within the same bunch applies the same uniforms uStartEndPosition[idx] & uPercentage[idx]
+ int idx = index - groupIdx*NUMBER_OF_BUBBLE;
+ float percentage = uPercentage[idx];
+ // early out if uPercentage is (zero || one) setting position to zero (zero sized triangles)
+ if( percentage <= 0.0 || percentage >= 1.0 )
+ {
+ gl_Position = vec4(0.0);
+ return;
+ }
+ vec4 startAndEnd = uStartEndPosition[idx];
+ // The final position is added up different offset for bubbles
+ startAndEnd.zw += uOffset[groupIdx];
+
+ // increase the bubble size from 0% to 100% during the first 1/5 of movement & apply the dynamic scale
+ // the new xy value containes both the new scale and new bubble position
+ position.xy *= uDynamicScale*min(percentage*5.0, 1.0);
+ position.xy += mix(startAndEnd.xy, startAndEnd.zw, percentage);
+ // The gravity is g*t*t on the y direction
+ position.y += uGravity * pow(percentage, 2.0);
+ gl_Position = uMvpMatrix * position;
+
+ // Add multiple bubble shapes in the effect
+ vTexCoord = aTexCoord;
+ vPercentage = percentage;
+ // Use the emit position color for the bubble
+ vEffectTexCoord = startAndEnd.xy * uInvertedMovementArea + vec2(0.5);
+}
\ No newline at end of file
--- /dev/null
+precision highp float;
+uniform vec3 uHSVDelta;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+
+float rand(vec2 co)
+{
+ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
+}
+
+vec3 rgb2hsv(vec3 c)
+{
+ vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
+ vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
+ vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
+
+ float d = q.x - min(q.w, q.y);
+ float e = 1.0e-10;
+ return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
+}
+
+vec3 hsv2rgb(vec3 c)
+{
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
+ return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
+}
+
+void main()
+{
+ vec4 color = texture2D(sTexture, vTexCoord);
+ vec3 hsvColor = rgb2hsv( color.rgb );
+ // modify the hsv Value
+ hsvColor += uHSVDelta * rand(vTexCoord);
+ // if the new vale exceeds one, then decrease it
+ hsvColor -= max(hsvColor*2.0 - vec3(2.0), 0.0);
+ // if the new vale drops below zero, then increase it
+ hsvColor -= min(hsvColor*2.0, 0.0);
+ color = vec4( hsv2rgb( hsvColor ), 1.0 );
+ gl_FragColor = color;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+attribute mediump vec2 aTexCoord;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+varying mediump vec2 vTexCoord;
+
+void main()
+{
+ gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy,0.0,1.0);
+ vTexCoord = aTexCoord;
+}
--- /dev/null
+INPUT mediump vec2 vPosition;
+INPUT mediump vec2 vRectSize;
+
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform mediump float blurRadius;
+
+void main()
+{
+ mediump vec2 blur = 1.0 - smoothstep( vRectSize - blurRadius * 2.0, vRectSize, abs( vPosition ) );
+ OUT_COLOR = vec4(mixColor, 1.0) * uColor;
+ OUT_COLOR.a *= blur.x * blur.y;
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+OUTPUT mediump vec2 vPosition;
+OUTPUT mediump vec2 vRectSize;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec2 extraSize;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump float blurRadius;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize + blurRadius * 2.0;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ vRectSize = visualSize / 2.0;
+ vPosition = aPosition* visualSize;
+ return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 vPosition;
+INPUT mediump vec2 vRectSize;
+INPUT mediump float vCornerRadius;
+
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;
+ OUT_COLOR = vec4(mixColor, 1.0) * uColor;
+ OUT_COLOR.a *= 1.0 - smoothstep( -1.0, 1.0, dist );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+OUTPUT mediump vec2 vPosition;
+OUTPUT mediump vec2 vRectSize;
+OUTPUT mediump float vCornerRadius;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec2 extraSize;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump float cornerRadius;
+uniform mediump float cornerRadiusPolicy;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ mediump float minSize = min( visualSize.x, visualSize.y );
+ vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);
+ vCornerRadius = min( vCornerRadius, minSize * 0.5 );
+ vRectSize = visualSize / 2.0 - vCornerRadius;
+ vPosition = aPosition* visualSize;
+ return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
\ No newline at end of file
--- /dev/null
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ OUT_COLOR = vec4(mixColor, 1.0) * uColor;
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump vec2 extraSize;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
\ No newline at end of file
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform vec4 uColor;
+
+void main()
+{
+ gl_FragColor = texture2D(sTexture, vTexCoord);
+ gl_FragColor *= uColor;
+}
--- /dev/null
+precision mediump float;
+attribute mediump vec2 aPosition;
+varying mediump vec2 vTexCoord;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump vec3 uSize;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition * uSize.xy, 0.0, 1.0);
+ vTexCoord = aPosition + vec2(0.5);
+ gl_Position = uMvpMatrix * vertexPosition;
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp vec4 uSamplerRect;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+varying mediump vec2 vTexCoord;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump vec3 uSize;
+uniform mediump vec4 uTextureRect;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ vTexCoord = aPosition + vec2(0.5);
+ vTexCoord = mix(uTextureRect.xy, uTextureRect.zw, vTexCoord);
+
+ gl_Position = vertexPosition;
+}
\ No newline at end of file
--- /dev/null
+varying float vPercentage;
+varying mediump vec2 vTexCoord;
+
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform vec4 uTextureRect;
+
+float rand(vec2 co)
+{
+ return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
+}
+
+void main()
+{
+ //Calculate the randomness
+ float offsetS = rand(vTexCoord * vPercentage) - vTexCoord.s;
+ float offsetT = rand(vec2(vTexCoord.t * vPercentage, vTexCoord.s * vPercentage)) - vTexCoord.t;
+ vec2 lookupCoord = vTexCoord + vec2(offsetS, offsetT) * vPercentage;
+ gl_FragColor = texture2D(sTexture, lookupCoord) * uColor;
+ gl_FragColor.a *= 1.0 - vPercentage;
+}
\ No newline at end of file
--- /dev/null
+attribute mediump vec2 aPosition;
+
+uniform mediump mat4 uMvpMatrix;
+uniform vec3 uSize;
+uniform vec4 uTextureRect;
+
+uniform float uPercentage;
+uniform vec3 uSaddleParam;
+uniform vec2 uTranslation;
+uniform vec2 uRotation;
+uniform float uToNext;
+
+varying float vPercentage;
+varying vec2 vTexCoord;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ vertexPosition = uMvpMatrix * vertexPosition;
+ gl_Position = vertexPosition;
+
+ vec2 texCoord = aPosition + vec2(0.5);
+ vTexCoord = texCoord;
+
+ //Calculate the distortion value given the dissolve central line
+ vec2 value = texCoord + uTranslation;
+ mat2 rotateMatrix = mat2(uRotation.s, uRotation.t, -uRotation.t, uRotation.s);
+ value = rotateMatrix * value;
+ if(uToNext == 1.0)
+ value.s = uSaddleParam[2] + value.s;
+ float delay = value.t * value.t / uSaddleParam[0] - value.s * value.s / uSaddleParam[1];
+ vPercentage = clamp(uPercentage * 2.0 - 0.5 * sin(delay * 1.571) - 0.5, 0.0, 1.0);
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+
+uniform mediump float uGlowBoundary;
+uniform mediump vec2 uOutlineParams;
+uniform lowp vec4 uOutlineColor;
+uniform lowp vec4 uShadowColor;
+uniform mediump vec2 uShadowOffset;
+uniform lowp vec4 uGlowColor;
+uniform lowp float uDoOutline;
+uniform lowp float uDoShadow;
+uniform lowp float uDoGlow;
+
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ // sample distance field
+ mediump float smoothing = 0.5;
+
+ mediump float distance = texture2D(sTexture, vTexCoord).a;
+ mediump float smoothWidth = fwidth(distance);
+ mediump float alphaFactor = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);
+ lowp vec4 color;
+
+ if (uDoShadow == 0.0)
+ {
+ mediump float alpha = uColor.a * alphaFactor;
+ lowp vec4 rgb = uColor;
+
+ if (uDoOutline > 0.0)
+ {
+ mediump float outlineWidth = uOutlineParams[1] + smoothWidth;
+ mediump float outlineBlend = smoothstep(uOutlineParams[0] - outlineWidth, uOutlineParams[0] + outlineWidth, distance);
+ alpha = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);
+ rgb = mix(uOutlineColor, uColor, outlineBlend);
+ }
+
+ if (uDoGlow > 0.0)
+ {
+ rgb = mix(uGlowColor, rgb, alphaFactor);
+ alpha = smoothstep(uGlowBoundary, smoothing, distance);
+ }
+
+ // set fragment color
+ color = vec4(rgb.rgb, alpha);
+ }
+
+ else // (uDoShadow > 0.0)
+ {
+ mediump float shadowDistance = texture2D(sTexture, vTexCoord - uShadowOffset).a;
+ mediump float inText = alphaFactor;
+ mediump float inShadow = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, shadowDistance);
+
+ // inside object, outside shadow
+ if (inText == 1.0)
+ {
+ color = uColor;
+ }
+ // inside object, outside shadow
+ else if ((inText != 0.0) && (inShadow == 0.0))
+ {
+ color = uColor;
+ color.a *= inText;
+ }
+ // outside object, completely inside shadow
+ else if ((inText == 0.0) && (inShadow == 1.0))
+ {
+ color = uShadowColor;
+ }
+ // inside object, completely inside shadow
+ else if ((inText != 0.0) && (inShadow == 1.0))
+ {
+ color = mix(uShadowColor, uColor, inText);
+ color.a = uShadowColor.a;
+ }
+ // inside object, inside shadow's border
+ else if ((inText != 0.0) && (inShadow != 0.0))
+ {
+ color = mix(uShadowColor, uColor, inText);
+ color.a *= max(inText, inShadow);
+ }
+ // inside shadow's border
+ else if (inShadow != 0.0)
+ {
+ color = uShadowColor;
+ color.a *= inShadow;
+ }
+ // outside shadow and object
+ else
+ {
+ color.a = 0.0;
+ }
+ }
+
+ gl_FragColor = color;
+}
\ No newline at end of file
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 effectColor;
+
+void main()
+{
+ gl_FragColor = effectColor;
+ gl_FragColor.a *= texture2D( sTexture, vTexCoord).a;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+varying mediump vec2 vTexCoord;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump vec3 uSize;
+uniform mediump vec3 effectOffset;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ vertexPosition.xyz += effectOffset;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ vTexCoord = aPosition + vec2(0.5);
+ gl_Position = vertexPosition;
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uEffectColor;
+
+void main()
+{
+ gl_FragColor = uEffectColor;
+ gl_FragColor.a *= texture2D( sTexture, vTexCoord).a;
+}
\ No newline at end of file
--- /dev/null
+precision highp float;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform vec2 uTexScale;
+uniform vec3 uCoefficient;
+
+void main()
+{
+ vec4 color = uCoefficient.x * texture2D( sTexture, vTexCoord + vec2(0.0, -uTexScale.y) );
+ color += uCoefficient.y * texture2D( sTexture, vTexCoord );
+ color += uCoefficient.z * texture2D( sTexture, vTexCoord + vec2(0.0, uTexScale.y) );
+ gl_FragColor = color;
+}
\ No newline at end of file
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform mediump vec2 uSampleOffsets[NUM_SAMPLES];
+uniform mediump float uSampleWeights[NUM_SAMPLES];
+
+void main()
+{
+ mediump vec4 col = texture2D(sTexture, vTexCoord + uSampleOffsets[0]) * uSampleWeights[0];
+ for (int i=1; i<NUM_SAMPLES; ++i)
+ {
+ col += texture2D(sTexture, vTexCoord + uSampleOffsets[i]) * uSampleWeights[i];
+ }
+ gl_FragColor = col;
+}
--- /dev/null
+#define TEXTURE_BASECOLOR
+
+uniform sampler2D uBaseColorSampler;
+uniform int uBaseColorTexCoordIndex;
--- /dev/null
+#define TEXTURE_EMIT
+
+uniform sampler2D uEmissiveSampler;
+uniform int uEmissiveTexCoordIndex;
+uniform vec3 uEmissiveFactor;
--- /dev/null
+#version 300 es
+precision highp float;
--- /dev/null
+#define TEXTURE_IBL
+
+uniform sampler2D ubrdfLUT;
+uniform samplerCube uDiffuseEnvSampler;
+uniform samplerCube uSpecularEnvSampler;
+uniform vec4 uScaleIBLAmbient;
+uniform highp float uMipmapLevel;
--- /dev/null
+#define TEXTURE_METALLICROUGHNESS
+
+uniform sampler2D uMetallicRoughnessSampler;
+uniform int uMetallicRoughnessTexCoordIndex;
--- /dev/null
+#define TEXTURE_NORMAL
+
+uniform sampler2D uNormalSampler;
+uniform float uNormalScale;
+uniform int uNormalTexCoordIndex;
--- /dev/null
+#define TEXTURE_OCCLUSION
+
+uniform sampler2D uOcclusionSampler;
+uniform int uOcclusionTexCoordIndex;
+uniform float uOcclusionStrength;
--- /dev/null
+uniform lowp vec3 uLightColor;
+uniform lowp vec4 uBaseColorFactor;
+uniform lowp vec2 uMetallicRoughnessFactors;
+uniform lowp int alphaMode;
+uniform lowp float alphaCutoff;
+
+in lowp vec2 vUV[2];
+in lowp mat3 vTBN;
+in lowp vec4 vColor;
+flat in int visLight;
+in highp vec3 vLightDirection;
+in highp vec3 vPositionToCamera;
+
+out vec4 FragColor;
+
+struct PBRInfo
+{
+ mediump float NdotL; // cos angle between normal and light direction
+ mediump float NdotV; // cos angle between normal and view direction
+ mediump float NdotH; // cos angle between normal and half vector
+ mediump float VdotH; // cos angle between view direction and half vector
+ mediump vec3 reflectance0; // full reflectance color (normal incidence angle)
+ mediump vec3 reflectance90; // reflectance color at grazing angle
+ lowp float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])
+};
+
+const float M_PI = 3.141592653589793;
+const float c_MinRoughness = 0.04;
+
+vec3 getNormal()
+{
+#ifdef TEXTURE_NORMAL
+ lowp vec3 n = texture( uNormalSampler, vUV[uNormalTexCoordIndex] ).rgb;
+ n = normalize( vTBN * ( ( 2.0 * n - 1.0 ) * vec3( uNormalScale, uNormalScale, 1.0 ) ) );
+#else
+ lowp vec3 n = normalize( vTBN[2].xyz );
+#endif
+ return n;
+}
+
+vec3 specularReflection( PBRInfo pbrInputs )
+{
+ return pbrInputs.reflectance0 + ( pbrInputs.reflectance90 - pbrInputs.reflectance0 ) * pow( clamp( 1.0 - pbrInputs.VdotH, 0.0, 1.0 ), 5.0 );
+}
+
+float geometricOcclusion( PBRInfo pbrInputs )
+{
+ mediump float NdotL = pbrInputs.NdotL;
+ mediump float NdotV = pbrInputs.NdotV;
+ lowp float r = pbrInputs.alphaRoughness;
+
+ lowp float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
+ lowp float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
+ return attenuationL * attenuationV;
+}
+
+float microfacetDistribution(PBRInfo pbrInputs)
+{
+ mediump float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;
+ lowp float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;
+ return roughnessSq / (M_PI * f * f);
+}
+
+vec3 linear( vec3 color )
+{
+ return pow(color,vec3(2.2));
+}
+
+void main()
+{
+ // Metallic and Roughness material properties are packed together
+ // In glTF, these factors can be specified by fixed scalar values
+ // or from a metallic-roughness map
+ lowp float metallic = uMetallicRoughnessFactors.x;
+ lowp float perceptualRoughness = uMetallicRoughnessFactors.y;
+
+ // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
+ // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
+#ifdef TEXTURE_METALLICROUGHNESS
+ lowp vec4 metrou = texture(uMetallicRoughnessSampler, vUV[uMetallicRoughnessTexCoordIndex]);
+ metallic = metrou.b * metallic;
+ perceptualRoughness = metrou.g * perceptualRoughness;
+#endif
+
+ metallic = clamp(metallic, 0.0, 1.0);
+ perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
+ // Roughness is authored as perceptual roughness; as is convention,
+ // convert to material roughness by squaring the perceptual roughness [2].
+ lowp float alphaRoughness = perceptualRoughness * perceptualRoughness;
+
+#ifdef TEXTURE_BASECOLOR
+ // The albedo may be defined from a base texture or a flat color
+ lowp vec4 baseColor = texture(uBaseColorSampler, vUV[uBaseColorTexCoordIndex]) * uBaseColorFactor;
+ baseColor = vec4(linear(baseColor.rgb), baseColor.w);
+#else
+ lowp vec4 baseColor = vColor * uBaseColorFactor;
+#endif
+
+ if( alphaMode == 0 )
+ {
+ baseColor.w = 1.0;
+ }
+ else if( alphaMode == 1 )
+ {
+ if( baseColor.w >= alphaCutoff )
+ {
+ baseColor.w = 1.0;
+ }
+ else
+ {
+ baseColor.w = 0.0;
+ }
+ }
+
+ lowp vec3 f0 = vec3(0.04);
+ lowp vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
+ diffuseColor *= ( 1.0 - metallic );
+ lowp vec3 specularColor = mix(f0, baseColor.rgb, metallic);
+
+ // Compute reflectance.
+ lowp float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
+
+ // For typical incident reflectance range (between 4% to 100%) set the grazing reflectance to 100% for typical fresnel effect.
+ // For very low reflectance range on highly diffuse objects (below 4%), incrementally reduce grazing reflecance to 0%.
+ lowp float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
+ lowp vec3 specularEnvironmentR0 = specularColor.rgb;
+ lowp vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
+
+ mediump vec3 n = getNormal(); // normal at surface point
+ mediump vec3 v = normalize(vPositionToCamera); // Vector from surface point to camera
+ mediump vec3 l = normalize(vLightDirection); // Vector from light to surface point
+ mediump vec3 h = normalize(l+v); // Half vector between both l and v
+ mediump vec3 reflection = -normalize(reflect(v, n));
+
+ mediump float NdotL = clamp(dot(n, l), 0.001, 1.0);
+ mediump float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
+ mediump float NdotH = dot(n, h);
+ mediump float LdotH = dot(l, h);
+ mediump float VdotH = dot(v, h);
+
+ PBRInfo pbrInputs = PBRInfo(
+ NdotL,
+ NdotV,
+ NdotH,
+ VdotH,
+ specularEnvironmentR0,
+ specularEnvironmentR90,
+ alphaRoughness
+ );
+
+ // Calculate the shading terms for the microfacet specular shading model
+ lowp vec3 color = vec3(0.0);
+ if( visLight == 1 )
+ {
+ lowp vec3 F = specularReflection( pbrInputs );
+ lowp float G = geometricOcclusion( pbrInputs );
+ lowp float D = microfacetDistribution( pbrInputs );
+
+ // Calculation of analytical lighting contribution
+ lowp vec3 diffuseContrib = ( 1.0 - F ) * ( diffuseColor / M_PI );
+ lowp vec3 specContrib = F * G * D / ( 4.0 * NdotL * NdotV );
+ // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
+ color = NdotL * uLightColor * (diffuseContrib + specContrib);
+ }
+
+#ifdef TEXTURE_IBL
+ lowp float lod = ( perceptualRoughness * uMipmapLevel );
+ // retrieve a scale and bias to F0. See [1], Figure 3
+ lowp vec3 brdf = linear( texture( ubrdfLUT, vec2( NdotV, 1.0 - perceptualRoughness ) ).rgb );
+ lowp vec3 diffuseLight = linear( texture( uDiffuseEnvSampler, n ).rgb );
+ lowp vec3 specularLight = linear( textureLod( uSpecularEnvSampler, reflection, lod ).rgb );
+
+ lowp vec3 diffuse = diffuseLight * diffuseColor * uScaleIBLAmbient.x;
+ lowp vec3 specular = specularLight * ( specularColor * brdf.x + brdf.y ) * uScaleIBLAmbient.y;
+ color += ( diffuse + specular );
+#endif
+
+#ifdef TEXTURE_OCCLUSION
+ lowp float ao = texture( uOcclusionSampler, vUV[uOcclusionTexCoordIndex] ).r;
+ color = mix( color, color * ao, uOcclusionStrength );
+#endif
+
+#ifdef TEXTURE_EMIT
+ lowp vec3 emissive = linear( texture( uEmissiveSampler, vUV[uEmissiveTexCoordIndex] ).rgb ) * uEmissiveFactor;
+ color += emissive;
+#endif
+
+ FragColor = vec4( pow( color,vec3( 1.0 / 2.2 ) ), baseColor.a );
+}
--- /dev/null
+in highp vec3 aPosition;
+in mediump vec2 aTexCoord0;
+in mediump vec2 aTexCoord1;
+in lowp vec3 aNormal;
+in lowp vec4 aTangent;
+in lowp vec4 aVertexColor;
+
+uniform mediump vec3 uSize;
+uniform mediump mat4 uModelMatrix;
+uniform mediump mat4 uViewMatrix;
+uniform mediump mat4 uProjection;
+uniform lowp int uLightType;
+uniform mediump vec3 uLightVector;
+uniform lowp int uIsColor;
+
+out lowp vec2 vUV[2];
+out lowp mat3 vTBN;
+out lowp vec4 vColor;
+flat out int visLight;
+out highp vec3 vLightDirection;
+out highp vec3 vPositionToCamera;
+
+void main()
+{
+ highp vec4 invY = vec4(1.0, -1.0, 1.0, 1.0);
+ highp vec4 positionW = uModelMatrix * vec4( aPosition * uSize, 1.0 );
+ highp vec4 positionV = uViewMatrix * ( invY * positionW );
+
+ vPositionToCamera = transpose( mat3( uViewMatrix ) ) * ( -vec3( positionV.xyz / positionV.w ) );
+ vPositionToCamera *= invY.xyz;
+
+ lowp vec3 bitangent = cross(aNormal, aTangent.xyz) * aTangent.w;
+ vTBN = mat3( uModelMatrix ) * mat3(aTangent.xyz, bitangent, aNormal);
+
+ vUV[0] = aTexCoord0;
+ vUV[1] = aTexCoord1;
+
+ visLight = 1;
+ if( uLightType == 1 )
+ {
+ vLightDirection = ( invY.xyz * uLightVector ) - ( positionW.xyz / positionW.w );
+ }
+ else if( uLightType == 2 )
+ {
+ vLightDirection = -( invY.xyz * uLightVector );
+ }
+ else
+ {
+ visLight = 0;
+ }
+
+ vColor = vec4( 1.0 );
+ if( uIsColor == 1 )
+ {
+ vColor = aVertexColor;
+ }
+
+ gl_Position = uProjection * positionV; // needs w for proper perspective correction
+ gl_Position = gl_Position/gl_Position.w;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump mat3 uAlignmentMatrix;
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vPosition;
+varying mediump vec2 vRectSize;
+varying mediump float vCornerRadius;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump float cornerRadius;
+uniform mediump float cornerRadiusPolicy;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ mediump float minSize = min( visualSize.x, visualSize.y );
+ vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);
+ vCornerRadius = min( vCornerRadius, minSize * 0.5 );
+ vRectSize = visualSize * 0.5 - vCornerRadius;
+ vPosition = aPosition * visualSize;
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;
+
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump mat3 uAlignmentMatrix;
+varying mediump vec2 vTexCoord;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;
+
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
\ No newline at end of file
--- /dev/null
+uniform sampler2D sTexture; // sampler1D?
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vPosition;
+varying mediump vec2 vRectSize;
+varying mediump float vCornerRadius;
+
+void main()
+{
+ mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;
+ gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor;
+ gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );
+}
--- /dev/null
+uniform sampler2D sTexture; // sampler1D?
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+varying mediump vec2 vTexCoord;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor;
+}
--- /dev/null
+uniform sampler2D sTexture; // sampler1D?
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vPosition;
+varying mediump vec2 vRectSize;
+varying mediump float vCornerRadius;
+
+void main()
+{
+ mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;
+ gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor;
+ gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );
+}
--- /dev/null
+uniform sampler2D sTexture; // sampler1D?
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+varying mediump vec2 vTexCoord;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump mat3 uAlignmentMatrix;
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vPosition;
+varying mediump vec2 vRectSize;
+varying mediump float vCornerRadius;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump float cornerRadius;
+uniform mediump float cornerRadiusPolicy;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ mediump float minSize = min( visualSize.x, visualSize.y );
+ vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);
+ vCornerRadius = min( vCornerRadius, minSize * 0.5 );
+ vRectSize = visualSize * 0.5 - vCornerRadius;
+ vPosition = aPosition * visualSize;
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+
+ vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump mat3 uAlignmentMatrix;
+varying mediump vec2 vTexCoord;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+
+ vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+
+uniform mediump mat4 uMvpMatrix;
+uniform vec3 uSize;
+uniform vec4 uTextureRect;
+
+varying vec2 vTexCoord;
+
+uniform mediump vec2 uTopLeft;
+uniform mediump vec2 uBottomRight;
+
+void main()
+{
+ mediump vec4 position = vec4(aPosition, 0.0, 1.0);
+ position.xyz *= uSize;
+ gl_Position = uMvpMatrix * position;
+
+ // The line below is doing the same as the following commented lines:
+ //
+ // vec2 imageSize = uTextureRect.zw - uTextureRect.xy;
+ // vec2 topLeft = uTextureRect.xy + uTopLeft * imageSize;
+ // vec2 bottomRight = uTextureRect.xy + uBottomRight * imageSize;
+ // vec2 texCoord = (aTexCoord - uTextureRect.xy) / imageSize;
+ // vTexCoord = topLeft + texCoord * ( bottomRight - topLeft );
+
+ vec2 texCoord = aPosition + vec2(0.5);
+ vTexCoord = uTextureRect.xy + uTopLeft * ( uTextureRect.zw - uTextureRect.xy ) + ( texCoord - uTextureRect.xy ) * ( uBottomRight - uTopLeft );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 vTexCoord;
+
+uniform sampler2D sTexture;
+uniform mediump vec4 uAtlasRect;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ mediump vec2 texCoord = clamp( mix( uAtlasRect.xy, uAtlasRect.zw, vTexCoord ), uAtlasRect.xy, uAtlasRect.zw );
+ OUT_COLOR = TEXTURE( sTexture, texCoord ) * uColor * vec4( mixColor, 1.0 );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 vTexCoord;
+
+uniform sampler2D sTexture;
+uniform mediump vec4 uAtlasRect;
+
+// WrapMode -- 0: CLAMP; 1: REPEAT; 2: REFLECT;
+uniform lowp vec2 wrapMode;
+
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+mediump float wrapCoordinate( mediump vec2 range, mediump float coordinate, lowp float wrap )
+
+{
+ mediump float coord;
+ if( wrap > 1.5 )\n // REFLECT
+ coord = 1.0-abs(fract(coordinate*0.5)*2.0 - 1.0);
+ else \n// warp == 0 or 1
+ coord = mix(coordinate, fract( coordinate ), wrap);
+ return clamp( mix(range.x, range.y, coord), range.x, range.y );
+}
+
+void main()
+{
+ mediump vec2 texCoord = vec2( wrapCoordinate( uAtlasRect.xz, vTexCoord.x, wrapMode.x ),
+ wrapCoordinate( uAtlasRect.yw, vTexCoord.y, wrapMode.y ) );
+ OUT_COLOR = TEXTURE( sTexture, texCoord ) * uColor * vec4( mixColor, 1.0 );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 vTexCoord;
+
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ OUT_COLOR = TEXTURE( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+INPUT mediump vec2 vTexCoord;
+INPUT mediump vec2 vPosition;
+INPUT mediump vec2 vRectSize;
+INPUT mediump float vCornerRadius;
+
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;
+ mediump float opacity = 1.0 - smoothstep( -1.0, 1.0, dist );
+
+ OUT_COLOR = TEXTURE( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );
+ OUT_COLOR.a *= opacity;
+ OUT_COLOR.rgb *= mix( 1.0, opacity, preMultipliedAlpha );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+OUTPUT mediump vec2 vTexCoord;
+OUTPUT mediump vec2 vPosition;
+OUTPUT mediump vec2 vRectSize;
+OUTPUT mediump float vCornerRadius;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump vec4 pixelArea;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump float cornerRadius;
+uniform mediump float cornerRadiusPolicy;
+uniform mediump vec2 extraSize;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ mediump float minSize = min( visualSize.x, visualSize.y );
+ vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);
+ vCornerRadius = min( vCornerRadius, minSize * 0.5 );
+ vRectSize = visualSize * 0.5 - vCornerRadius;
+ vPosition = aPosition* visualSize;
+ return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+ vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );
+}
\ No newline at end of file
--- /dev/null
+INPUT mediump vec2 aPosition;
+OUTPUT mediump vec2 vTexCoord;
+
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump vec4 pixelArea;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump vec2 extraSize;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+ vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );
+}
\ No newline at end of file
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vLightDirection;
+varying mediump vec3 vHalfVector;
+uniform sampler2D sDiffuse;
+uniform sampler2D sNormal;
+uniform sampler2D sGloss;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ vec4 texture = texture2D( sDiffuse, vTexCoord );
+ vec3 normal = normalize( texture2D( sNormal, vTexCoord ).xyz * 2.0 - 1.0 );
+ vec4 glossMap = texture2D( sGloss, vTexCoord );
+ vec4 visualMixColor = vec4( mixColor, 1.0 );
+
+ float lightDiffuse = max( 0.0, dot( normal, normalize( vLightDirection ) ) );
+ lightDiffuse = lightDiffuse * 0.5 + 0.5;
+
+ float shininess = pow ( max ( dot ( normalize( vHalfVector ), normal ), 0.0 ), 16.0 );
+
+ gl_FragColor = vec4( texture.rgb * uColor.rgb * visualMixColor.rgb * lightDiffuse + shininess * glossMap.rgb, texture.a * uColor.a * visualMixColor.a );
+}
--- /dev/null
+attribute highp vec3 aPosition;
+attribute highp vec2 aTexCoord;
+attribute highp vec3 aNormal;
+attribute highp vec3 aTangent;
+attribute highp vec3 aBiNormal;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vLightDirection;
+varying mediump vec3 vHalfVector;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat4 uViewMatrix;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 lightPosition;
+uniform mediump vec2 uStageOffset;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform mediump vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ float scaleFactor = min( visualSize.x, visualSize.y );
+ vec3 originFlipY =vec3(origin.x, -origin.y, 0.0);
+ vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
+ vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);
+ return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );
+}
+
+void main()
+{
+ vec4 normalisedVertexPosition = ComputeVertexPosition();
+ vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ vec4 mvVertexPosition = uModelView * normalisedVertexPosition;
+
+ vec3 tangent = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aTangent );
+ vec3 binormal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aBiNormal );
+ vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );
+
+ vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );
+ mvLightPosition = uViewMatrix * mvLightPosition;
+ vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );
+ vLightDirection.x = dot( vectorToLight, tangent );
+ vLightDirection.y = dot( vectorToLight, binormal );
+ vLightDirection.z = dot( vectorToLight, normal );
+
+ vec3 viewDirection = normalize( -mvVertexPosition.xyz );
+ vec3 halfVector = normalize( viewDirection + vectorToLight );
+ vHalfVector.x = dot( halfVector, tangent );
+ vHalfVector.y = dot( halfVector, binormal );
+ vHalfVector.z = dot( halfVector, normal );
+
+ vTexCoord = aTexCoord;
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vIllumination;
+varying mediump float vSpecular;
+uniform sampler2D sDiffuse;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ vec4 texture = texture2D( sDiffuse, vTexCoord );
+ vec4 visualMixColor = vec4( mixColor, 1.0 );
+ gl_FragColor = vec4( vIllumination.rgb * texture.rgb * uColor.rgb * visualMixColor.rgb + vSpecular * 0.3, texture.a * uColor.a * visualMixColor.a );
+}
--- /dev/null
+attribute highp vec3 aPosition;
+attribute highp vec2 aTexCoord;
+attribute highp vec3 aNormal;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vIllumination;
+varying mediump float vSpecular;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat4 uViewMatrix;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 lightPosition;
+uniform mediump vec2 uStageOffset;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform mediump vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ float scaleFactor = min( visualSize.x, visualSize.y );
+ vec3 originFlipY =vec3(origin.x, -origin.y, 0.0);
+ vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
+ vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);
+ return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );
+}
+
+void main()
+{
+ vec4 normalisedVertexPosition = ComputeVertexPosition();
+ vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ //Illumination in Model-View space - Transform attributes and uniforms
+ vec4 mvVertexPosition = uModelView * normalisedVertexPosition;
+ vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );
+
+ vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );
+ mvLightPosition = uViewMatrix * mvLightPosition;
+ vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );
+
+ vec3 viewDirection = normalize( -mvVertexPosition.xyz );
+
+ float lightDiffuse = dot( vectorToLight, normal );
+ lightDiffuse = max( 0.0,lightDiffuse );
+ vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
+
+ vec3 reflectDirection = reflect( -vectorToLight, normal );
+ vSpecular = pow( max( dot( reflectDirection, viewDirection ), 0.0 ), 4.0 );
+
+ vTexCoord = aTexCoord;
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+varying mediump vec3 vIllumination;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a ) * vec4( mixColor, 1.0 );
+}
--- /dev/null
+attribute highp vec3 aPosition;
+attribute highp vec3 aNormal;
+varying mediump vec3 vIllumination;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat4 uViewMatrix;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 lightPosition;
+uniform mediump vec2 uStageOffset;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform mediump vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ float scaleFactor = min( visualSize.x, visualSize.y );
+ vec3 originFlipY =vec3(origin.x, -origin.y, 0.0);
+ vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
+ vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);
+ return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );
+}
+
+void main()
+{
+ vec4 normalisedVertexPosition = ComputeVertexPosition();
+ vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ //Illumination in Model-View space - Transform attributes and uniforms
+ vec4 mvVertexPosition = uModelView * normalisedVertexPosition;
+ vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;
+
+ vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );
+ mvLightPosition = uViewMatrix * mvLightPosition;
+ vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );
+
+ float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
+ vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
+
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vLightDirection;
+varying mediump vec3 vHalfVector;
+uniform sampler2D sDiffuse;
+uniform sampler2D sNormal;
+uniform sampler2D sGloss;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ vec4 texture = texture2D( sDiffuse, vTexCoord );
+ vec3 normal = normalize( texture2D( sNormal, vTexCoord ).xyz * 2.0 - 1.0 );
+ vec4 glossMap = texture2D( sGloss, vTexCoord );
+
+ float lightDiffuse = max( 0.0, dot( normal, normalize(vLightDirection) ) );
+ lightDiffuse = lightDiffuse * 0.5 + 0.5;
+
+ float shininess = pow (max (dot (normalize( vHalfVector ), normal), 0.0), 16.0);
+
+ gl_FragColor = vec4( texture.rgb * uColor.rgb * lightDiffuse + shininess * glossMap.rgb, texture.a * uColor.a);
+}
--- /dev/null
+attribute highp vec3 aPosition;
+attribute highp vec2 aTexCoord;
+attribute highp vec3 aNormal;
+attribute highp vec3 aTangent;
+attribute highp vec3 aBiNormal;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vLightDirection;
+varying mediump vec3 vHalfVector;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 uLightPosition;
+
+void main()
+{
+ vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);
+ vertexPosition = uObjectMatrix * vertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);
+ vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);
+
+ vec3 tangent = normalize(uNormalMatrix * aTangent);
+ vec3 binormal = normalize(uNormalMatrix * aBiNormal);
+ vec3 normal = normalize(uNormalMatrix * aNormal);
+
+ vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );
+ vLightDirection.x = dot(vecToLight, tangent);
+ vLightDirection.y = dot(vecToLight, binormal);
+ vLightDirection.z = dot(vecToLight, normal);
+
+ vec3 viewDir = normalize(-vertPos.xyz);
+ vec3 halfVector = normalize(viewDir + vecToLight);
+ vHalfVector.x = dot(halfVector, tangent);
+ vHalfVector.y = dot(halfVector, binormal);
+ vHalfVector.z = dot(halfVector, normal);
+
+ vTexCoord = aTexCoord;
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vIllumination;
+varying mediump float vSpecular;
+uniform sampler2D sDiffuse;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ vec4 texture = texture2D( sDiffuse, vTexCoord );
+ gl_FragColor = vec4( vIllumination.rgb * texture.rgb * uColor.rgb + vSpecular * 0.3, texture.a * uColor.a);
+}
--- /dev/null
+attribute highp vec3 aPosition;
+attribute highp vec2 aTexCoord;
+attribute highp vec3 aNormal;
+varying mediump vec2 vTexCoord;
+varying mediump vec3 vIllumination;
+varying mediump float vSpecular;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 uLightPosition;
+
+void main()
+{
+ vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);
+ vertexPosition = uObjectMatrix * vertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ //Illumination in Model-View space - Transform attributes and uniforms
+ vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);
+ vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);
+ vec3 normal = normalize(uNormalMatrix * aNormal);
+
+ vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );
+ vec3 viewDir = normalize(-vertPos.xyz);
+
+ vec3 halfVector = normalize(viewDir + vecToLight);
+
+ float lightDiffuse = dot( vecToLight, normal );
+ lightDiffuse = max(0.0,lightDiffuse);
+ vIllumination = vec3(lightDiffuse * 0.5 + 0.5);
+
+ vec3 reflectDir = reflect(-vecToLight, normal);
+ vSpecular = pow( max(dot(reflectDir, viewDir), 0.0), 4.0 );
+
+ vTexCoord = aTexCoord;
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+varying mediump vec3 vIllumination;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a);
+}
--- /dev/null
+attribute highp vec3 aPosition;
+attribute highp vec2 aTexCoord;
+attribute highp vec3 aNormal;
+varying mediump vec3 vIllumination;
+uniform mediump vec3 uSize;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 uLightPosition;
+
+void main()
+{
+ vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);
+ vertexPosition = uObjectMatrix * vertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ //Illumination in Model-View space - Transform attributes and uniforms
+ vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);
+ vec3 normal = uNormalMatrix * aNormal;
+ vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);
+ vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );
+
+ float lightDiffuse = max( dot( vecToLight, normal ), 0.0 );
+ vIllumination = vec3(lightDiffuse * 0.5 + 0.5);
+
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+
+uniform sampler2D sTexture;
+uniform vec4 uColor;
+
+uniform vec2 uObjectFadeStart;
+uniform vec2 uObjectFadeEnd;
+uniform float uAlphaScale;
+uniform float uBlurTexCoordScale;
+uniform float uNumSamples;
+uniform float uRecipNumSamples;
+uniform float uRecipNumSamplesMinusOne;
+
+// inputs
+varying vec2 vModelSpaceCenterToPos;
+varying vec2 vScreenSpaceVelocityVector;
+varying float vSpeed;
+varying vec2 vTexCoord;
+
+void main()
+{
+ // calculate an alpha value that will fade the object towards its extremities, we need this to avoid an unsightly hard edge between color values of
+ // the blurred object and the unblurred background. Use smoothstep also to hide any hard edges (discontinuities) in rate of change of this alpha gradient
+ vec2 centerToPixel = abs(vModelSpaceCenterToPos);
+ vec2 fadeToEdges = smoothstep(0.0, 1.0, 1.0 - ((centerToPixel - uObjectFadeStart) / (uObjectFadeEnd - uObjectFadeStart)));
+ float fadeToEdgesScale = fadeToEdges.x * fadeToEdges.y * uAlphaScale; // apply global scaler
+ fadeToEdgesScale = mix(1.0, fadeToEdgesScale, vSpeed);// fade proportional to speed, so opaque when at rest
+
+ // scale velocity vector by user requirements
+ vec2 velocity = vScreenSpaceVelocityVector * uBlurTexCoordScale;
+
+ // standard actor texel
+ vec4 colActor = texture2D(sTexture, vTexCoord);
+
+ // blurred actor - gather texture samples from the actor texture in the direction of motion
+ vec4 col = colActor * uRecipNumSamples;
+ for(float i = 1.0; i < uNumSamples; i += 1.0)
+ {
+ float t = i * uRecipNumSamplesMinusOne;
+ col += texture2D(sTexture, vTexCoord + (velocity * t)) * uRecipNumSamples;
+ }
+ gl_FragColor = mix(colActor, col, vSpeed); // lerp blurred and non-blurred actor based on speed of motion
+ gl_FragColor.a = fadeToEdgesScale;//colActor.a * fadeToEdgesScale; // fade blurred actor to its edges based on speed of motion
+ gl_FragColor *= uColor;
+}
--- /dev/null
+precision mediump float;
+
+attribute vec2 aPosition;
+
+uniform mat4 uMvpMatrix;
+uniform mat4 uModelView;
+uniform mat4 uViewMatrix;
+uniform mat4 uProjection;
+uniform vec3 uSize;
+
+uniform mat4 uModelLastFrame;
+float timeDelta = 0.0167;
+
+uniform float uGeometryStretchFactor;
+uniform float uSpeedScalingFactor;
+
+// outputs
+varying vec2 vModelSpaceCenterToPos;
+varying vec2 vScreenSpaceVelocityVector;
+varying float vSpeed;
+varying vec2 vTexCoord;
+
+void main()
+{
+ // get view space position of vertex this frame and last frame
+ vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+
+ vec4 viewSpaceVertex = uModelView * vertexPosition;
+ vec4 viewSpaceVertexLastFrame = (uViewMatrix * uModelLastFrame) * vertexPosition;
+ float reciprocalTimeDelta = 1.0 / timeDelta;
+
+ // work out vertex's last movement in view space
+ vec3 viewSpacePosDelta = viewSpaceVertex.xyz - viewSpaceVertexLastFrame.xyz;
+
+ // get clip space position of vertex this frame and last frame
+ vec4 clipSpaceVertex = uMvpMatrix * vertexPosition;
+ vec4 clipSpaceVertexLastFrame = uProjection * viewSpaceVertexLastFrame;
+
+ // decide how much this vertex is 'trailing', i.e. at the back of the object relative to its direction of motion. We do this
+ // by assuming the objects model space origin is at its center and taking the dot product of the vector from center to vertex with the motion direction
+ float t = 0.0;
+ float posDeltaLength = length(viewSpacePosDelta);
+ if(posDeltaLength > 0.001) // avoid div by 0 if object has barely moved
+ {
+ vec4 viewSpaceCenterToPos = uModelView * vec4(vertexPosition.xy, 0.0, 0.0);
+ float centerToVertexDist = length(viewSpaceCenterToPos);
+ if(centerToVertexDist > 0.001) // avoid div by 0 if object has vertex at model space origin
+ {
+ vec3 viewSpacePosDeltaNormalised = viewSpacePosDelta / posDeltaLength;
+ vec3 viewSpaceCenterToPosNormalised = viewSpaceCenterToPos.xyz / centerToVertexDist;
+ t = (dot(viewSpacePosDeltaNormalised, viewSpaceCenterToPosNormalised) * 0.5 ) + 0.5; // scale and bias from [-1..1] to [0..1]
+ }
+ }
+ // output vertex position lerped with its last position, based on how much it is trailing,
+ // this stretches the geom back along where it has just been, giving a warping effect
+ // Note: we must take account of time delta to convert position delta into a velocity, so changes are smooth (take into account frame time correctly)
+ gl_Position = mix(clipSpaceVertexLastFrame, clipSpaceVertex, t * uGeometryStretchFactor * reciprocalTimeDelta);
+
+ // work out vertex's last movement in normalised device coordinates [-1..1] space, i.e. perspective divide
+ vec2 ndcVertex = clipSpaceVertex.xy / clipSpaceVertex.w;
+ vec2 ndcVertexLastFrame = clipSpaceVertexLastFrame.xy / clipSpaceVertexLastFrame.w;
+ // scale and bias so that a value of 1.0 corresponds to screen size (NDC is [-1..1] = 2)
+ vScreenSpaceVelocityVector = ((ndcVertex - ndcVertexLastFrame) * 0.5 * reciprocalTimeDelta);
+ vScreenSpaceVelocityVector.y = -vScreenSpaceVelocityVector.y; // TODO negated due to y being inverted in our coordinate system?
+ // calculate a scaling factor proportional to velocity, which we can use to tweak how things look
+ vSpeed = length(vScreenSpaceVelocityVector) * uSpeedScalingFactor;
+ vSpeed = clamp(vSpeed, 0.0, 1.0);
+
+ // provide fragment shader with vector from center of object to pixel (assumes the objects model space origin is at its center and verts have same z)
+ vModelSpaceCenterToPos = viewSpaceVertex.xy;
+
+ vec2 texCoord = aPosition + vec2(0.5);
+ vTexCoord = texCoord;
+}
\ No newline at end of file
--- /dev/null
+precision mediump float;
+
+uniform sampler2D sTexture;
+uniform vec4 uColor;
+
+uniform vec2 uObjectFadeStart;
+uniform vec2 uObjectFadeEnd;
+uniform float uAlphaScale;
+
+// inputs
+varying vec2 vModelSpaceCenterToPos;
+varying vec2 vScreenSpaceVelocityVector;
+varying float vSpeed;
+varying vec2 vTexCoord;
+
+void main()
+{
+ // calculate an alpha value that will fade the object towards its extremities, we need this to avoid an unsightly hard edge between color values of
+ // the stretched object and the background. Use smoothstep also to hide any hard edges (discontinuities) in rate of change of this alpha gradient
+ vec2 centerToPixel = abs( vModelSpaceCenterToPos );
+ vec2 fadeToEdges = smoothstep(0.0, 1.0, 1.0 - ((centerToPixel - uObjectFadeStart) / (uObjectFadeEnd - uObjectFadeStart)));
+ float fadeToEdgesScale = fadeToEdges.x * fadeToEdges.y * uAlphaScale; // apply global scaler
+ fadeToEdgesScale = mix(1.0, fadeToEdgesScale, vSpeed); // fade proportional to speed, so opaque when at rest
+
+ // standard actor texel
+ vec4 colActor = texture2D(sTexture, vTexCoord);
+ gl_FragColor = colActor;
+ gl_FragColor.a *= fadeToEdgesScale; // fade actor to its edges based on speed of motion
+ gl_FragColor *= uColor;
+}
\ No newline at end of file
--- /dev/null
+precision mediump float;
+
+attribute vec2 aPosition;
+
+uniform mat4 uMvpMatrix;
+uniform mat4 uModelView;
+uniform mat4 uViewMatrix;
+uniform mat4 uProjection;
+uniform vec3 uSize;
+
+uniform mat4 uModelLastFrame;
+float timeDelta = 0.0167;
+
+uniform float uGeometryStretchFactor;
+uniform float uSpeedScalingFactor;
+
+// outputs
+varying vec2 vModelSpaceCenterToPos;
+varying vec2 vScreenSpaceVelocityVector;
+varying float vSpeed;
+varying vec2 vTexCoord;
+
+void main()
+{
+ // get view space position of vertex this frame and last frame
+ vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+
+ vec4 viewSpaceVertex = uModelView * vertexPosition;
+ vec4 viewSpaceVertexLastFrame = uViewMatrix * uModelLastFrame * vertexPosition;
+
+ // work out vertex's last movement in view space
+ vec3 viewSpacePosDelta = viewSpaceVertex.xyz - viewSpaceVertexLastFrame.xyz;
+ float reciprocalTimeDelta = 1.0 / timeDelta;
+
+ // get clip space position of vertex this frame and last frame
+ vec4 clipSpaceVertex = uMvpMatrix * vertexPosition;
+ vec4 clipSpaceVertexLastFrame = uProjection * viewSpaceVertexLastFrame;
+
+ // decide how much this vertex is 'trailing', i.e. at the back of the object relative to its direction of motion. We do this
+ // by assuming the objects model space origin is at its center and taking the dot product of the vector from center to vertex with the motion direction
+ float t = 0.0;
+ float posDeltaLength = length(viewSpacePosDelta);
+ if(posDeltaLength > 0.001) // avoid div by 0 if object has barely moved
+ {
+ vec4 viewSpaceCenterToPos = uModelView * vec4(aPosition, 0.0, 0.0);
+ float centerToVertexDist = length(viewSpaceCenterToPos);
+ if(centerToVertexDist > 0.001) // avoid div by 0 if object has vertex at model space origin
+ {
+ vec3 viewSpacePosDeltaNormalised = viewSpacePosDelta / posDeltaLength;
+ vec3 viewSpaceCenterToPosNormalised = viewSpaceCenterToPos.xyz / centerToVertexDist;
+ t = (dot(viewSpacePosDeltaNormalised, viewSpaceCenterToPosNormalised) * 0.5 ) + 0.5; // scale and bias from [-1..1] to [0..1]
+ }
+ }
+
+ // output vertex position lerped with its last position, based on how much it is trailing,
+ // this stretches the geom back along where it has just been, giving a warping effect
+ // We raise t to a power in order that non-trailing vertices are effected much more than trailing ones
+ // Note: we must take account of time delta to convert position delta into a velocity, so changes are smooth (take into account frame time correctly)
+ gl_Position = mix(clipSpaceVertexLastFrame, clipSpaceVertex, t * t * t * uGeometryStretchFactor * reciprocalTimeDelta);
+
+ // work out vertex's last movement in normalised device coordinates [-1..1] space, i.e. perspective divide
+ vec2 ndcVertex = clipSpaceVertex.xy / clipSpaceVertex.w;
+ vec2 ndcVertexLastFrame = clipSpaceVertexLastFrame.xy / clipSpaceVertexLastFrame.w;
+ // scale and bias so that a value of 1.0 corresponds to screen size (NDC is [-1..1] = 2)
+ vScreenSpaceVelocityVector = ((ndcVertex - ndcVertexLastFrame) * 0.5 * reciprocalTimeDelta);
+ vScreenSpaceVelocityVector.y = -vScreenSpaceVelocityVector.y; // TODO negated due to y being inverted in our coordinate system?
+ // calculate a scaling factor proportional to velocity, which we can use to tweak how things look
+ vSpeed = length(vScreenSpaceVelocityVector) * uSpeedScalingFactor;
+ vSpeed = clamp(vSpeed, 0.0, 1.0);
+
+ // provide fragment shader with vector from center of object to pixel (assumes the objects model space origin is at its center and verts have same z)
+ vModelSpaceCenterToPos = viewSpaceVertex.xy;
+
+ vec2 texCoord = aPosition + vec2(0.5);
+ vTexCoord = texCoord;
+}
\ No newline at end of file
--- /dev/null
+attribute mediump vec2 aPosition;
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vMaskTexCoord;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump vec2 uFixed[ 3 ];
+uniform mediump vec2 uStretchTotal;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump vec2 extraSize;
+
+void main()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+
+ mediump vec2 size = visualSize.xy;
+
+ mediump vec2 fixedFactor = vec2( uFixed[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uFixed[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].y );
+ mediump vec2 stretch = floor( aPosition * 0.5 );
+ mediump vec2 fixedTotal = uFixed[ 2 ];
+
+ mediump vec4 gridPosition = vec4( fixedFactor + ( size - fixedTotal ) * stretch, 0.0, 1.0 );
+ mediump vec4 vertexPosition = gridPosition;
+ vertexPosition.xy -= size * vec2( 0.5, 0.5 );
+ vertexPosition.xy += anchorPoint*size + (visualOffset + origin)*uSize.xy;
+
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ vTexCoord = ( fixedFactor + stretch * uStretchTotal ) / ( fixedTotal + uStretchTotal );
+
+ vMaskTexCoord = gridPosition.xy / size;
+ gl_Position = vertexPosition;
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vMaskTexCoord;
+uniform sampler2D sTexture;
+uniform sampler2D sMask;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+uniform mediump float auxiliaryImageAlpha;
+
+void main()
+{
+ // Where mask image is transparent, all of background image must show through.
+ // where mask image is opaque, only mask should be shown
+ // where mask is translucent, less of background should be shown.
+ // auxiliaryImageAlpha controls how much of mask is visible
+
+ mediump vec4 color = texture2D( sTexture, vTexCoord );
+ mediump vec4 mask= texture2D( sMask, vMaskTexCoord );
+
+ mediump vec3 mixedColor = color.rgb * mix( 1.0-mask.a, 1.0, 1.0-auxiliaryImageAlpha)
+ + mask.rgb*mask.a * auxiliaryImageAlpha;
+ gl_FragColor = vec4(mixedColor,1.0) * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+uniform lowp float preMultipliedAlpha;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+varying mediump vec2 vTexCoord;
+varying mediump vec2 vMaskTexCoord;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump vec2 uNinePatchFactorsX[ FACTOR_SIZE_X ];
+uniform mediump vec2 uNinePatchFactorsY[ FACTOR_SIZE_Y ];
+
+// Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+uniform mediump vec2 extraSize;
+
+void main()
+{
+ mediump vec2 fixedFactor= vec2( uNinePatchFactorsX[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uNinePatchFactorsY[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].x );
+ mediump vec2 stretch= vec2( uNinePatchFactorsX[ int( ( aPosition.x ) * 0.5 ) ].y, uNinePatchFactorsY[ int( ( aPosition.y ) * 0.5 ) ].y );
+
+ mediump vec2 fixedTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].x, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].x );
+ mediump vec2 stretchTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].y, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].y );
+
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+
+ mediump vec4 gridPosition = vec4( fixedFactor + ( visualSize.xy - fixedTotal ) * stretch / stretchTotal, 0.0, 1.0 );
+ mediump vec4 vertexPosition = gridPosition;
+ vertexPosition.xy -= visualSize.xy * vec2( 0.5, 0.5 );
+ vertexPosition.xy += anchorPoint*visualSize + (visualOffset + origin)*uSize.xy;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ vTexCoord = ( fixedFactor + stretch ) / ( fixedTotal + stretchTotal );
+ vMaskTexCoord = gridPosition.xy / visualSize;
+
+ gl_Position = vertexPosition;
+}
--- /dev/null
+precision mediump float;
+varying mediump vec2 vTexCoord;
+uniform vec3 uSize;
+uniform vec2 uSpineShadowParameter;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ if( gl_FrontFacing ) // display front side
+ {
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
+ }
+ else // display back side, flip the image horizontally by changing the x component of the texture coordinate
+ {
+ gl_FragColor = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) ) * uColor;
+ }
+ // display book spine, a stripe of shadowed texture
+ float pixelPos = vTexCoord.x * uSize.x;
+ if( pixelPos < uSpineShadowParameter.x )
+ {
+ float x = pixelPos - uSpineShadowParameter.x;
+ float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );
+ vec2 spineNormal = normalize(vec2(uSpineShadowParameter.y*x/uSpineShadowParameter.x, y));
+ gl_FragColor.rgb *= spineNormal.y;
+ }
+}
\ No newline at end of file
--- /dev/null
+precision mediump float;
+attribute mediump vec2 aPosition;
+uniform mediump mat4 uMvpMatrix;
+uniform vec3 uSize;
+uniform float uTextureWidth;
+varying vec2 vTexCoord;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition*uSize.xy, 0.0, 1.0);
+ gl_Position = uMvpMatrix * vertexPosition;
+ vTexCoord = aPosition + vec2(0.5);
+ vTexCoord.x /= uTextureWidth;
+}
--- /dev/null
+precision mediump float;
+
+varying mediump vec2 vTexCoord;
+
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform vec3 uSize;
+uniform vec2 uSpineShadowParameter;
+varying vec3 vNormal;
+varying vec4 vPosition;
+
+void main()
+{
+ // need to re-normalize the interpolated normal
+ vec3 normal = normalize( vNormal );
+ // display page content
+ vec4 texel;
+ // display back image of the page, flip the texture
+ if( dot(vPosition.xyz, normal) > 0.0 ) texel = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) );
+ // display front image of the page
+ else texel = texture2D( sTexture, vTexCoord );
+
+ // display book spine, a stripe of shadowed texture
+ float pixelPos = vTexCoord.x * uSize.x;
+ float spineShadowCoef = 1.0;
+ if( pixelPos < uSpineShadowParameter.x )
+ {
+ float x = pixelPos - uSpineShadowParameter.x;
+ float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );
+ spineShadowCoef = normalize( vec2( uSpineShadowParameter.y*x/uSpineShadowParameter.x, y ) ).y;
+ }
+ // calculate the lighting
+ // set the ambient color as vec3(0.4);
+ float lightColor = abs( normal.z ) * 0.6 + 0.4;
+ gl_FragColor = vec4( ( spineShadowCoef * lightColor ) * texel.rgb , texel.a ) * uColor;
+}
--- /dev/null
+/*
+ * The common parameters for all the vertices, calculate in CPU then pass into the shader as uniforms
+ *
+ * first part of the page, (outside the the line passing through original center and vertical to curve direction)
+ * no Z change, only 2D rotation and translation
+ * ([0][0],[0][1],[1][0],[1][1]) mat2 rotateMatrix
+ * ([2][0],[2][1]) vec2 translationVector
+ *
+ * ([0][2],[0][3]) vec2 originalCenter: Typically the press down position of the Pan Gesture
+ * ([1][2],[1][3]) vec2 currentCenter: Typically the current position of the Pan Gesture
+ * ([3][0],[3][1]) vec2 curveDirection: The normalized vector pointing from original center to current center
+ * ([2][2]) float vanishingPointY: The Y coordinate of the intersection of the spine
+ * and the line which goes through the original center and is vertical to the curveDirection
+ * ([2][3]) float curveEndY: The Y coordinate of intersection of the spine and the line through both original and current center
+ * ([3][2]) float curveHeight: The height of the interpolated hermite curve.
+ * ([3][3]) float currentLength: The length from the current center to the curveEnd.
+ */
+
+precision mediump float;
+
+attribute mediump vec2 aPosition;
+
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uModelView;
+
+uniform mat4 uCommonParameters;
+
+uniform vec3 uSize;
+uniform float uIsTurningBack;
+uniform float uTextureWidth;
+varying vec3 vNormal;
+varying vec4 vPosition;
+varying mediump vec2 vTexCoord;
+
+void main()
+{
+ vec4 position = vec4( aPosition*uSize.xy, 0.0, 1.0);
+ vec2 currentCenter = vec2( uCommonParameters[1][2], uCommonParameters[1][3]);
+ vec2 originalCenter = vec2( uCommonParameters[0][2], uCommonParameters[0][3]);
+ vec3 normal = vec3(0.0,0.0,1.0);
+
+ if(currentCenter.x < originalCenter.x)
+ {
+ // change the coordinate origin from the center of the page to its top-left
+ position.xy += uSize.xy * 0.5;
+ vec2 curveDirection = vec2( uCommonParameters[3]);
+ vec3 vanishingPoint = vec3(0.0, uCommonParameters[2][2], 0.0);
+ // first part of the page, (outside the the line passing through original center and vertical to curve direction)
+ //no Z change, only 2D rotation and translation
+ if( dot(curveDirection, position.xy - originalCenter) < 0.0 )
+ {
+ position.y -= vanishingPoint.y;
+ position.xy = mat2(uCommonParameters)*position.xy + vec2( uCommonParameters[2]);
+ }
+ // second part of the page, bent as a ruled surface
+ else
+ {
+ // calculate on the flat plane, between
+ // the first line passing through current vertex and vanishing point
+ // the second line passing through original center and current center
+ vec2 curveEnd = vec2( 0.0, uCommonParameters[2][3] );
+ vec2 curFlatDirection = vec2(0.0,1.0);
+ float lengthFromCurve = position.y - originalCenter.y;
+ float lengthOnCurve = position.x;
+ if(currentCenter.y != originalCenter.y)
+ {
+ curFlatDirection = normalize(position.xy - vanishingPoint.xy);
+ lengthFromCurve = (curveEnd.x*curveDirection.y-curveEnd.y*curveDirection.x-position.x*curveDirection.y+position.y*curveDirection.x)
+ / (curFlatDirection.x*curveDirection.y-curFlatDirection.y*curveDirection.x);
+ lengthOnCurve = length(position.xy+lengthFromCurve*curFlatDirection-curveEnd);
+ }
+
+ // define the control points of hermite curve, composed with two segments
+ // calculation is carried out on the 2D plane which is passing through both current and original center and vertical to the image plane
+ float currentLength = uCommonParameters[3][3];
+ float originalLength = abs(originalCenter.x/curveDirection.x);
+ float height = uCommonParameters[3][2];
+ float percentage = currentLength/originalLength;
+ //vec2 SegmentOneControlPoint0 = vec2(0.0, 0.0);
+ vec2 SegmentOneControlPoint1 = vec2((0.65*percentage - 0.15)*originalLength, (0.8 + 0.2 * percentage)*height);
+ vec2 SegmentTwoControlPoint0 = SegmentOneControlPoint1;
+ vec2 SegmentTwoControlPoint1 = vec2(currentLength, 0.0);
+ vec2 SegmentOneTangentVector0 = SegmentOneControlPoint1;
+ vec2 SegmentOneTangentVector1 = vec2(0.5*originalLength,0.0);
+ vec2 SegmentTwoTangentVector0 = SegmentOneTangentVector1;
+ vec2 SegmentTwoTangentVector1 = SegmentOneTangentVector1;
+
+ // calculate the corresponding curve point position and its tangent vector
+ // it is a linear mapping onto nonlinear curves, might cause some unwanted deformation
+ // but as there are no analytical method to calculate the curve length on arbitrary segment
+ // no efficient way to solve this nonlinear mapping, Numerical approximation would cost too much computation in shader
+ vec2 curvePoint2D;
+ vec2 tangent;
+ float t0 = lengthOnCurve / originalLength;
+ if(t0<=0.5)
+ {
+ float t = 2.0*t0;
+ float t_2 = t*t;
+ float t_3 = t*t_2;
+ curvePoint2D = (-2.0*t_3+3.0*t_2)*SegmentOneControlPoint1
+ + (t_3-2.0*t_2+t)*SegmentOneTangentVector0 + (t_3-t_2)*SegmentOneTangentVector1;
+ tangent = (-6.0*t_2+6.0*t)*SegmentOneControlPoint1
+ + (3.0*t_2-4.0*t+1.0)*SegmentOneTangentVector0 + (3.0*t_2-2.0*t)*SegmentOneTangentVector1;
+ }
+ else
+ {
+ float t = 2.0*t0-1.0;
+ float t_2 = t*t;
+ float t_3 = t*t_2;
+ curvePoint2D = (2.0*t_3-3.0*t_2+1.0)*SegmentTwoControlPoint0 + (-2.0*t_3+3.0*t_2)*SegmentTwoControlPoint1
+ + (t_3-2.0*t_2+t)*SegmentTwoTangentVector0 + (t_3-t_2)*SegmentTwoTangentVector1;
+ tangent = (6.0*t_2-6.0*t)*SegmentTwoControlPoint0 + (-6.0*t_2+6.0*t)*SegmentTwoControlPoint1
+ + (3.0*t_2-4.0*t+1.0)*SegmentTwoTangentVector0 + (3.0*t_2-2.0*t)*SegmentTwoTangentVector1;
+ // a trick to eliminate some optical illusion caused by the gradient matter of normal in per-fragment shading
+ // which is caused by linear interpolation of normal vs. nonlinear lighting
+ // will notice some artifact in the areas with dramatically normal changes, so compress the normal differences here
+ tangent.y *= min(1.0, length(position.xyz - vanishingPoint) / uSize.y );
+ }
+ vec3 curvePoint = vec3(curveEnd - curvePoint2D.x*curveDirection,max(0.0,curvePoint2D.y));
+ vec3 tangentVector = vec3(-tangent.x*curveDirection,tangent.y);
+
+ // locate the new vertex position on the line passing through both vanishing point and the calculated curve point position
+ vec3 curLiftDirection = vec3(0.0,-1.0,0.0);
+ if(currentCenter.y != originalCenter.y)
+ {
+ curLiftDirection = normalize(curvePoint - vanishingPoint);
+ tangentVector *= (curveDirection.y > 0.0) ? -1.0 : 1.0;
+ // an heuristic adjustment here, to compensate the linear parameter mapping onto the nonlinear curve
+ float Y0 = position.y - curveDirection.y * (position.x/curveDirection.x);
+ float proportion;
+ float refLength;
+ if(abs(Y0-vanishingPoint.y) > abs(curveEnd.y-vanishingPoint.y))
+ {
+ proportion = abs(curveEnd.y - Y0) / (abs(curveEnd.y-Y0)+abs(curveEnd.y - vanishingPoint.y));
+ refLength = proportion*length(originalCenter-vanishingPoint.xy) / (proportion-1.0);
+ }
+ else
+ {
+ proportion = abs(curveEnd.y - Y0) / abs(curveEnd.y - vanishingPoint.y);
+ refLength = proportion*length(originalCenter-vanishingPoint.xy);
+ }
+ float Y1 = currentCenter.y - (normalize(currentCenter-vanishingPoint.xy)).y * refLength;
+ position.y = mix(Y0, Y1, t0);
+ }
+ position.xz = curvePoint.xz - lengthFromCurve*curLiftDirection.xz;
+ // calculate the normal vector, will be used for lighting
+ normal = cross(curLiftDirection, normalize(tangentVector));
+ // the signature of Z is decided by the page turning direction:
+ // from left to right(negative); from right to left (positive)
+ position.z *= -uIsTurningBack;
+ normal.xy *= -uIsTurningBack;
+ }
+ // change the coordinate origin from the top-left of the page to its center
+ position.xy -= uSize.xy * 0.5;
+ }
+ vNormal = uNormalMatrix * normal;
+ gl_Position = uMvpMatrix * position;
+ // varying parameters for fragment shader
+ vTexCoord = aPosition + vec2(0.5);
+ vTexCoord.x /= uTextureWidth;
+ vPosition = uModelView * position;
+}
--- /dev/null
+//Very simple fragment shader that merely applies the vertex shading to the color at each fragment.
+
+precision mediump float;
+varying mediump vec3 vIllumination;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ vec4 baseColor = vec4(mixColor, 1.0) * uColor;
+ gl_FragColor = vec4( vIllumination.rgb * baseColor.rgb, baseColor.a );
+}
--- /dev/null
+//A simple shader that applies diffuse lighting to a mono-coloured object.
+
+attribute highp vec3 aPosition;
+attribute highp vec2 aTexCoord;
+attribute highp vec3 aNormal;
+varying mediump vec3 vIllumination;
+uniform mediump vec3 uSize;
+uniform mediump vec3 uObjectDimensions;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelView;
+uniform mediump mat4 uViewMatrix;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uObjectMatrix;
+uniform mediump vec3 lightPosition;
+uniform mediump vec2 uStageOffset;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform mediump vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ float scaleFactor = min( visualSize.x / uObjectDimensions.x, visualSize.y / uObjectDimensions.y );
+ vec3 originFlipY =vec3(origin.x, -origin.y, 0.0);
+ vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
+ vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);
+
+ return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );
+}
+
+void main()
+{
+ vec4 normalisedVertexPosition = ComputeVertexPosition();
+ vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;
+ vertexPosition = uMvpMatrix * vertexPosition;
+
+ //Illumination in Model-View space - Transform attributes and uniforms
+ vec4 mvVertexPosition = uModelView * normalisedVertexPosition;
+ vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;
+
+ vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );
+ mvLightPosition = uViewMatrix * mvLightPosition;
+ vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );
+
+ float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
+ vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
+
+ gl_Position = vertexPosition;
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform lowp vec4 uShadowColor;
+uniform sampler2D sTexture;
+
+void main()
+{
+ lowp float alpha;
+ alpha = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y)).a;
+ gl_FragColor = vec4(uShadowColor.rgb, uShadowColor.a * alpha);
+}
\ No newline at end of file
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat4 uModelMatrix;
+uniform vec3 uSize;
+varying vec2 vTexCoord;
+
+uniform mediump mat4 uLightCameraProjectionMatrix;
+uniform mediump mat4 uLightCameraViewMatrix;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ gl_Position = uMvpMatrix * vertexPosition;
+ vec4 textureCoords = uLightCameraProjectionMatrix * uLightCameraViewMatrix * uModelMatrix * vertexPosition;
+ vTexCoord = 0.5 + 0.5 * (textureCoords.xy/textureCoords.w);
+}
\ No newline at end of file
--- /dev/null
+precision highp float;
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform int uSpread;
+uniform vec2 uTexScale;
+
+void main()
+{
+ vec4 color = texture2D( sTexture, vTexCoord);
+ for( int i = 1; i <= uSpread; ++i )
+ {
+ vec2 offset = uTexScale * float(i);
+ color = max( texture2D( sTexture, vTexCoord + offset), color );
+ color = max( texture2D( sTexture, vTexCoord - offset), color );
+ }
+ gl_FragColor = color;
+}
\ No newline at end of file
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp float uAlpha;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
+ gl_FragColor.a *= uAlpha;
+}
--- /dev/null
+uniform lowp vec4 uColor;
+uniform lowp vec4 textColorAnimatable;
+uniform sampler2D sTexture;
+varying mediump vec2 vTexCoord;
+varying mediump vec4 vColor;
+
+void main()
+{
+ mediump vec4 color = texture2D( sTexture, vTexCoord );
+ gl_FragColor = vec4( vColor.rgb * uColor.rgb * textColorAnimatable.rgb, uColor.a * vColor.a * textColorAnimatable.a * color.r );
+}
--- /dev/null
+uniform lowp vec4 uColor;
+uniform lowp vec4 textColorAnimatable;
+uniform sampler2D sTexture;
+varying mediump vec2 vTexCoord;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * textColorAnimatable;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+attribute mediump vec2 aTexCoord;
+attribute mediump vec4 aColor;
+uniform mediump vec2 uOffset;
+uniform highp mat4 uMvpMatrix;
+varying mediump vec2 vTexCoord;
+varying mediump vec4 vColor;
+
+void main()
+{
+ mediump vec4 position = vec4( aPosition.xy + uOffset, 0.0, 1.0 );
+ gl_Position = uMvpMatrix * position;
+ vTexCoord = aTexCoord;
+ vColor = aColor;
+}
--- /dev/null
+varying mediump vec4 vColor;
+uniform lowp vec4 uColor;
+
+void main()
+{
+ gl_FragColor = vColor * uColor;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+attribute mediump vec4 aColor;
+varying mediump vec4 vColor;
+uniform highp mat4 uMvpMatrix;
+
+void main()
+{
+ mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
+ gl_Position = uMvpMatrix * position;
+ vColor = aColor;
+}
--- /dev/null
+uniform lowp vec4 uColor;
+
+void main()
+{
+ gl_FragColor = uColor;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+
+void main()
+{
+ mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
+ gl_Position = uMvpMatrix * position;
+}
--- /dev/null
+varying highp vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ if ( vTexCoord.y > 1.0 )
+ discard;
+
+ mediump vec4 textTexture = texture2D( sTexture, vTexCoord );
+
+ gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+varying highp vec2 vTexCoord;
+uniform highp vec3 uSize;
+uniform mediump float uDelta;
+uniform mediump vec2 uTextureSize;
+uniform mediump float uGap;
+uniform mediump float uHorizontalAlign;
+uniform mediump float uVerticalAlign;
+
+uniform highp mat4 uMvpMatrix;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+void main()
+{
+ mediump vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy );
+ mediump vec2 visualSize = mix( uSize.xy * size, size, offsetSizeMode.zw );
+
+ vTexCoord.x = ( uDelta + uHorizontalAlign * ( uTextureSize.x - visualSize.x - uGap ) + floor( aPosition.x * visualSize.x ) + 0.5 - uGap * 0.5 ) / uTextureSize.x + 0.5;
+ vTexCoord.y = ( uVerticalAlign * ( uTextureSize.y - visualSize.y ) + floor( aPosition.y * visualSize.y ) + 0.5 ) / ( uTextureSize.y ) + 0.5;
+
+ mediump vec4 vertexPosition = vec4( floor( ( aPosition + anchorPoint ) * visualSize + ( visualOffset + origin ) * uSize.xy ), 0.0, 1.0 );
+
+ gl_Position = uMvpMatrix * vertexPosition;
+}
\ No newline at end of file
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump vec4 textTexture = texture2D( sTexture, vTexCoord );
+
+ gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform sampler2D sStyle;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump vec4 textTexture = texture2D( sTexture, vTexCoord );
+ mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );
+
+ // Draw the text as overlay above the style
+ gl_FragColor = ( textTexture + styleTexture * ( 1.0 - textTexture.a ) ) * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+uniform mediump vec4 pixelArea;
+
+varying mediump vec2 vTexCoord;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+ vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform lowp vec4 uTextColorAnimatable;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump float textTexture = texture2D( sTexture, vTexCoord ).r;
+
+ // Set the color of the text to what it is animated to.
+ gl_FragColor = uTextColorAnimatable * textTexture * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform sampler2D sMask;
+uniform lowp vec4 uTextColorAnimatable;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump vec4 textTexture = texture2D( sTexture, vTexCoord );
+ mediump float maskTexture = texture2D( sMask, vTexCoord ).r;
+
+ // Set the color of non-transparent pixel in text to what it is animated to.
+ // Markup text with multiple text colors are not animated (but can be supported later on if required).
+ // Emoji color are not animated.
+ mediump float vstep = step( 0.0001, textTexture.a );
+ textTexture.rgb = mix( textTexture.rgb, uTextColorAnimatable.rgb, vstep * maskTexture );
+
+ // Draw the text as overlay above the style
+ gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform sampler2D sStyle;
+uniform sampler2D sMask;
+uniform lowp float uHasMultipleTextColors;
+uniform lowp vec4 uTextColorAnimatable;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump vec4 textTexture = texture2D( sTexture, vTexCoord );
+ mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );
+ mediump float maskTexture = texture2D( sMask, vTexCoord ).r;
+
+ // Set the color of non-transparent pixel in text to what it is animated to.
+ // Markup text with multiple text colors are not animated (but can be supported later on if required).
+ // Emoji color are not animated.
+ mediump float vstep = step( 0.0001, textTexture.a );
+ textTexture.rgb = mix( textTexture.rgb, uTextColorAnimatable.rgb, vstep * maskTexture * ( 1.0 - uHasMultipleTextColors ) );
+
+ // Draw the text as overlay above the style
+ gl_FragColor = ( textTexture + styleTexture * ( 1.0 - textTexture.a ) ) * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+varying mediump vec2 vTexCoord;
+uniform sampler2D sTexture;
+uniform sampler2D sStyle;
+uniform lowp vec4 uTextColorAnimatable;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ mediump float textTexture = texture2D( sTexture, vTexCoord ).r;
+ mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );
+
+ // Draw the text as overlay above the style
+ gl_FragColor = ( uTextColorAnimatable * textTexture + styleTexture * ( 1.0 - uTextColorAnimatable.a * textTexture ) ) * uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+uniform lowp vec4 uColor;
+varying mediump vec2 vTexCoord;
+uniform samplerExternalOES sTexture;
+
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+varying mediump vec2 vTexCoord;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+varying mediump vec2 sTexCoordRect;
+
+void main()
+{
+ gl_Position = uMvpMatrix * vec4(aPosition * uSize.xy, 0.0, 1.0);
+ vTexCoord = aPosition + vec2(0.5);
+}
--- /dev/null
+void main()
+{
+ gl_FragColor = vec4(0.0);
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+ vertexPosition.xyz *= uSize;
+ gl_Position = uMvpMatrix * vertexPosition;
+}
--- /dev/null
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
+
+void main()
+{
+ gl_FragColor = uColor * vec4( mixColor, 1.0 );
+}
--- /dev/null
+attribute mediump vec2 aPosition;
+uniform highp mat4 uMvpMatrix;
+uniform highp vec3 uSize;
+
+//Visual size and offset
+uniform mediump vec2 offset;
+uniform highp vec2 size;
+uniform mediump vec4 offsetSizeMode;
+uniform mediump vec2 origin;
+uniform mediump vec2 anchorPoint;
+
+vec4 ComputeVertexPosition()
+{
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
+}
+
+void main()
+{
+ gl_Position = uMvpMatrix * ComputeVertexPosition();
+}
#include <dali-toolkit/public-api/controls/image-view/image-view.h>
#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
#include <dali-toolkit/internal/controls/image-view/image-view-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#ifdef DEBUG_ENABLED
#define DECORATOR_DEBUG
#endif
-#define MAKE_SHADER(A)#A
-
-namespace
-{
-const char* VERTEX_SHADER = MAKE_SHADER(
-attribute mediump vec2 aPosition;
-uniform highp mat4 uMvpMatrix;
-
-void main()
-{
- mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
- gl_Position = uMvpMatrix * position;
-}
-);
-
-const char* FRAGMENT_SHADER = MAKE_SHADER(
-uniform lowp vec4 uColor;
-
-void main()
-{
- gl_FragColor = uColor;
-}
-);
-}
-
namespace Dali
{
namespace Internal
mHidePrimaryCursorAndGrabHandle( false )
{
mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
- mHighlightShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+ mHighlightShader = Shader::New( SHADER_TEXT_DECORATOR_SHADER_VERT, SHADER_TEXT_DECORATOR_SHADER_FRAG );
SetupGestures();
}
#include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
#include <dali-toolkit/internal/text/rendering/atlas/atlas-mesh-factory.h>
#include <dali-toolkit/internal/text/text-view.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
using namespace Dali;
using namespace Dali::Toolkit;
Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_RENDERING");
#endif
-#define MAKE_SHADER(A)#A
-
-const char* VERTEX_SHADER = MAKE_SHADER(
-attribute mediump vec2 aPosition;
-attribute mediump vec2 aTexCoord;
-attribute mediump vec4 aColor;
-uniform mediump vec2 uOffset;
-uniform highp mat4 uMvpMatrix;
-varying mediump vec2 vTexCoord;
-varying mediump vec4 vColor;
-
-void main()
-{
- mediump vec4 position = vec4( aPosition.xy + uOffset, 0.0, 1.0 );
- gl_Position = uMvpMatrix * position;
- vTexCoord = aTexCoord;
- vColor = aColor;
-}
-);
-
-const char* FRAGMENT_SHADER_L8 = MAKE_SHADER(
-uniform lowp vec4 uColor;
-uniform lowp vec4 textColorAnimatable;
-uniform sampler2D sTexture;
-varying mediump vec2 vTexCoord;
-varying mediump vec4 vColor;
-
-void main()
-{
- mediump vec4 color = texture2D( sTexture, vTexCoord );
- gl_FragColor = vec4( vColor.rgb * uColor.rgb * textColorAnimatable.rgb, uColor.a * vColor.a * textColorAnimatable.a * color.r );
-}
-);
-
-const char* FRAGMENT_SHADER_RGBA = MAKE_SHADER(
-uniform lowp vec4 uColor;
-uniform lowp vec4 textColorAnimatable;
-uniform sampler2D sTexture;
-varying mediump vec2 vTexCoord;
-
-void main()
-{
- gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * textColorAnimatable;
-}
-);
-
const float ZERO( 0.0f );
const float HALF( 0.5f );
const float ONE( 1.0f );
// The glyph is an emoji and is not a shadow.
if( !mShaderRgba )
{
- mShaderRgba = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_RGBA );
+ mShaderRgba = Shader::New( SHADER_TEXT_ATLAS_SHADER_VERT, SHADER_TEXT_ATLAS_RGBA_SHADER_FRAG );
}
shader = mShaderRgba;
}
// The glyph is text or a shadow.
if( !mShaderL8 )
{
- mShaderL8 = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_L8 );
+ mShaderL8 = Shader::New( SHADER_TEXT_ATLAS_SHADER_VERT, SHADER_TEXT_ATLAS_L8_SHADER_FRAG );
}
shader = mShaderL8;
}
#include <dali-toolkit/internal/text/text-controller-impl-event-handler.h>
#include <dali-toolkit/internal/text/text-run-container.h>
#include <dali-toolkit/internal/text/text-selection-handle-controller.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
using namespace Dali;
Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
#endif
-#define MAKE_SHADER(A)#A
-
-const char* VERTEX_SHADER_BACKGROUND = MAKE_SHADER(
-attribute mediump vec2 aPosition;
-attribute mediump vec4 aColor;
-varying mediump vec4 vColor;
-uniform highp mat4 uMvpMatrix;
-
-void main()
-{
- mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
- gl_Position = uMvpMatrix * position;
- vColor = aColor;
-}
-);
-
-const char* FRAGMENT_SHADER_BACKGROUND = MAKE_SHADER(
-varying mediump vec4 vColor;
-uniform lowp vec4 uColor;
-
-void main()
-{
- gl_FragColor = vColor * uColor;
-}
-);
-
struct BackgroundVertex
{
Vector2 mPosition; ///< Vertex posiiton
if( !mShaderBackground )
{
- mShaderBackground = Shader::New( VERTEX_SHADER_BACKGROUND, FRAGMENT_SHADER_BACKGROUND );
+ mShaderBackground = Shader::New( SHADER_TEXT_CONTROLLER_BACKGROUND_SHADER_VERT, SHADER_TEXT_CONTROLLER_BACKGROUND_SHADER_FRAG );
}
Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, mShaderBackground );
// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/text-scroller-interface.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
const int MINIMUM_SCROLL_SPEED = 1; // Speed should be set by Property system.
-const char* VERTEX_SHADER_SCROLL = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- varying highp vec2 vTexCoord;\n
- uniform highp vec3 uSize;\n
- uniform mediump float uDelta;\n
- uniform mediump vec2 uTextureSize;\n
- uniform mediump float uGap;\n
- uniform mediump float uHorizontalAlign;\n
- uniform mediump float uVerticalAlign;\n
- \n
- uniform highp mat4 uMvpMatrix;\n
- \n
- //Visual size and offset
- uniform mediump vec2 offset;\n
- uniform highp vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
-
- void main()\n
- {\n
- mediump vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy );\n
- mediump vec2 visualSize = mix( uSize.xy * size, size, offsetSizeMode.zw );\n
- \n
- vTexCoord.x = ( uDelta + uHorizontalAlign * ( uTextureSize.x - visualSize.x - uGap ) + floor( aPosition.x * visualSize.x ) + 0.5 - uGap * 0.5 ) / uTextureSize.x + 0.5;\n
- vTexCoord.y = ( uVerticalAlign * ( uTextureSize.y - visualSize.y ) + floor( aPosition.y * visualSize.y ) + 0.5 ) / ( uTextureSize.y ) + 0.5;\n
- \n
- mediump vec4 vertexPosition = vec4( floor( ( aPosition + anchorPoint ) * visualSize + ( visualOffset + origin ) * uSize.xy ), 0.0, 1.0 );\n
- \n
- gl_Position = uMvpMatrix * vertexPosition;\n
- }\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- varying highp vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- \n
- void main()\n
- {\n
- if ( vTexCoord.y > 1.0 )\n
- discard;\n
- \n
- mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n
- \n
- gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 );
- }\n
-);
-
/**
* @brief How the text should be aligned horizontally when scrolling the text.
*
mTextureSet = mRenderer.GetTextures();
// Set the shader and texture for scrolling
- Shader shader = Shader::New( VERTEX_SHADER_SCROLL, FRAGMENT_SHADER, Shader::Hint::NONE );
+ Shader shader = Shader::New( SHADER_TEXT_SCROLLER_SHADER_VERT, SHADER_TEXT_SCROLLER_SHADER_FRAG, Shader::Hint::NONE );
mRenderer.SetShader( shader );
mRenderer.SetTextures( textureSet );
#include <cstring> // for strcmp
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/object/type-registry-helper.h>
-#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
namespace Dali
DALI_TYPE_REGISTRATION_END()
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- varying mediump vec2 vTexCoord;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump vec3 uSize;\n
- uniform mediump vec4 uTextureRect;\n
- \n
- void main()\n
- {\n
- mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
- vertexPosition.xyz *= uSize;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
- \n
- vTexCoord = aPosition + vec2(0.5);\n
- vTexCoord = mix(uTextureRect.xy, uTextureRect.zw, vTexCoord);\n
-
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec4 uSamplerRect;
- \n
- void main()\n
- {\n
- gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
- }\n
-);
-
Actor CreateTile( const Vector4& samplerRect )
{
Actor tile = Actor::New();
void CubeTransitionEffect::OnSceneConnection( int depth )
{
Geometry geometry = VisualFactoryCache::CreateQuadGeometry();
- Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+ Shader shader = Shader::New( SHADER_CUBE_TRANSITION_EFFECT_VERT, SHADER_CUBE_TRANSITION_EFFECT_FRAG );
TextureSet textureSet = TextureSet::New();
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
const Toolkit::DevelAnimatedGradientVisual::AnimationParameter::MotionType::Type DEFAULT_ANIMATION_MOTION_TYPE = Toolkit::DevelAnimatedGradientVisual::AnimationParameter::MotionType::LOOP;
const Toolkit::DevelAnimatedGradientVisual::AnimationParameter::EasingType::Type DEFAULT_ANIMATION_EASING_TYPE = Toolkit::DevelAnimatedGradientVisual::AnimationParameter::EasingType::LINEAR;
-const char* const BASIC_VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;
- uniform highp mat4 uMvpMatrix;
- uniform highp vec3 uSize;
-
- uniform mediump vec2 start_point;
- uniform mediump vec2 end_point;
- uniform mediump vec2 rotate_center;
- uniform mediump float rotate_angle;
-
- varying mediump vec2 vTexCoord;
- varying mediump vec2 vStart;
- varying mediump vec2 vEnd;
-
- vec2 rotate(vec2 x, vec2 c, float a)
- {
- vec2 d = x - c;
- vec2 r = vec2(d.x * cos(a) - d.y * sin(a), d.x * sin(a) + d.y * cos(a));
-
-\n #ifdef UNIT_TYPE_BOUNDING_BOX \n return r + c; \n #endif \n /* UnitType::OBJECT_BOUNDING_BOX */
-\n #ifdef UNIT_TYPE_USER \n return (r + c) / uSize.x; \n #endif \n /* UnitType::USER_SPACE */
- }
-
- //Visual size and offset
- uniform mediump vec2 offset;
- uniform highp vec2 size;
- uniform mediump vec4 offsetSizeMode;
- uniform mediump vec2 origin;
- uniform mediump vec2 anchorPoint;
-
- vec4 ComputeVertexPosition()
- {
- vec2 visualSize = mix( uSize.xy*size, size, offsetSizeMode.zw );
- vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy );
- return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
- }
-
- void main()
- {
- vStart = rotate( start_point, rotate_center, rotate_angle );
- vEnd = rotate( end_point, rotate_center, rotate_angle );
- gl_Position = uMvpMatrix * ComputeVertexPosition();
-
-\n #ifdef UNIT_TYPE_BOUNDING_BOX \n vTexCoord = vec2(aPosition.x, -aPosition.y); \n #endif \n /* UnitType::OBJECT_BOUNDING_BOX */
-\n #ifdef UNIT_TYPE_USER \n vTexCoord = vec2(aPosition.x, -aPosition.y * uSize.y / uSize.x); \n #endif \n /* UnitType::USER_SPACE */
- }
-);
-
-const char* const BASIC_FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- precision mediump float;
-
- uniform mediump vec4 start_color;
- uniform mediump vec4 end_color;
- uniform mediump float gradient_offset;
-
- varying mediump vec2 vTexCoord;
- varying mediump vec2 vStart;
- varying mediump vec2 vEnd;
-
- float get_position(vec2 x, vec2 s, vec2 e)
- {
- vec2 df = e - s;
- vec2 dx = x - s;
-
-\n #ifdef GRADIENT_TYPE_LINEAR \n return dot(dx,df)/dot(df,df); \n #endif \n /* GradientType::LINEAR */
-\n #ifdef GRADIENT_TYPE_RADIAL \n return sqrt(dot(dx,dx)/dot(df,df)); \n #endif \n /* GradientType::RADIAL */
- }
- float recalculate(float r)
- {
-\n #ifdef SPREAD_TYPE_REFLECT \n return 1.0 - abs(mod(r, 2.0) - 1.0); \n #endif \n /* SpreadType::REFLECT */
-\n #ifdef SPREAD_TYPE_REPEAT \n return fract(r); \n #endif \n /* SpreadType::REPEAT */
-\n #ifdef SPREAD_TYPE_CLAMP \n return clamp(r, 0.0, 1.0); \n #endif \n /* SpreadType::CLAMP */
- }
-
- void main()
- {
- float r = get_position( vTexCoord, vStart, vEnd );
- r = recalculate( r + gradient_offset );
- vec4 color = mix( start_color, end_color, r );
- gl_FragColor = color;
- }
-);
-
Property::Value GetStartValue( const Property::Map& map, Property::Index index, const char* const name )
{
// Get start value of animation parameter
std::string frag;
vert = "#define " + tagUnit + "\n"
- + BASIC_VERTEX_SHADER;
+ + SHADER_ANIMATED_GRADIENT_VISUAL_SHADER_VERT.data();
frag = "#define " + tagGrad + "\n"
+ "#define " + tagSpread + "\n"
- + BASIC_FRAGMENT_SHADER;
+ + SHADER_ANIMATED_GRADIENT_VISUAL_SHADER_FRAG.data();
shader = Shader::New( vert, frag );
return shader;
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
DALI_ENUM_TO_STRING_WITH_SCOPE( DevelArcVisual::Cap, ROUND )
DALI_ENUM_TO_STRING_TABLE_END( CAP )
-const char* VERTEX_SHADER =
- "INPUT mediump vec2 aPosition;\n"
- "OUTPUT mediump vec2 vPosition;\n"
-
- "uniform highp mat4 uMvpMatrix;\n"
- "uniform highp vec3 uSize;\n"
-
- "//Visual size and offset\n"
- "uniform mediump vec2 offset;\n"
- "uniform highp vec2 size;\n"
- "uniform mediump vec4 offsetSizeMode;\n"
- "uniform mediump vec2 origin;\n"
- "uniform mediump vec2 anchorPoint;\n"
-
- "vec4 ComputeVertexPosition()\n"
- "{\n"
- " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n"
- " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
- " vPosition = aPosition* visualSize;\n"
- " return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n"
- "}\n"
-
- "void main()\n"
- "{\n"
- " gl_Position = uMvpMatrix * ComputeVertexPosition();\n"
- "}\n";
-
-const char* FRAGMENT_SHADER_BUTT_CAP =
- "INPUT mediump vec2 vPosition;\n"
-
- "uniform lowp vec4 uColor;\n"
- "uniform lowp vec3 mixColor;\n"
- "uniform mediump float thickness;\n"
- "uniform mediump float radius;\n"
- "uniform mediump float startAngle;\n"
- "uniform mediump float sweepAngle;\n"
-
- "const mediump float M_PI_OVER_2 = 1.57079632679;\n"
- "const mediump float M_PI = 3.14159265359;\n"
- "const mediump float M_PI_2 = 6.28318530718;\n"
-
- "mediump float GetOpacity()\n"
- "{\n"
- " mediump float start = radians( mod( startAngle, 360.0 ) );\n"
- " mediump float angle = mod( atan( vPosition.y, vPosition.x ) + M_PI_OVER_2 - start, M_PI_2 );\n"
- " mediump float dist = length( vPosition );\n"
- " if( angle <= radians( sweepAngle ) )\n"
- " {\n"
- " return smoothstep( -1.0, 1.0, thickness / 2.0 - ( abs( dist - radius ) ) );\n"
- " }\n"
- " mediump float end = radians( mod( startAngle + sweepAngle, 360.0 ) );\n"
- " mediump vec2 q0 = vec2( dist * cos( start - M_PI_OVER_2 ), dist * sin( start - M_PI_OVER_2 ) );\n"
- " mediump vec2 q1 = vec2( dist * cos( end - M_PI_OVER_2 ), dist * sin( end - M_PI_OVER_2 ) );\n"
- " mediump float opacity = 1.0 - smoothstep( 0.0, 2.0, min( length( vPosition - q0 ), length( vPosition - q1 ) ) );\n"
- " opacity *= step( 0.0, thickness / 2.0 - abs( dist - radius ) );\n"
- " return opacity;\n"
- "}\n"
-
- "void main()\n"
- "{\n"
- " OUT_COLOR = vec4( mixColor, 1.0 ) * uColor;\n"
- " OUT_COLOR.a *= GetOpacity();\n"
- "}\n";
-
-const char* FRAGMENT_SHADER_ROUND_CAP =
- "INPUT mediump vec2 vPosition;\n"
-
- "uniform lowp vec4 uColor;\n"
- "uniform lowp vec3 mixColor;\n"
- "uniform mediump float thickness;\n"
- "uniform mediump float radius;\n"
- "uniform mediump float startAngle;\n"
- "uniform mediump float sweepAngle;\n"
-
- "const mediump float M_PI_OVER_2 = 1.57079632679;\n"
- "const mediump float M_PI_2 = 6.28318530718;\n"
-
- "mediump float GetOpacity()\n"
- "{\n"
- " mediump float start = radians( mod( startAngle, 360.0 ) );\n"
- " mediump float angle = mod( atan( vPosition.y, vPosition.x ) + M_PI_OVER_2 - start, M_PI_2 );\n"
- " mediump float dist = length( vPosition );\n"
- " if( angle <= radians( sweepAngle ) )\n"
- " {\n"
- " return smoothstep( -1.0, 1.0, thickness / 2.0 - ( abs( dist - radius ) ) );\n"
- " }\n"
- " mediump float end = radians( mod( startAngle + sweepAngle, 360.0 ) );\n"
- " mediump vec2 q0 = vec2( radius * cos( start - M_PI_OVER_2 ), radius * sin( start - M_PI_OVER_2 ) );\n"
- " mediump vec2 q1 = vec2( radius * cos( end - M_PI_OVER_2 ), radius * sin( end - M_PI_OVER_2 ) );\n"
- " return smoothstep( -1.0, 1.0, thickness / 2.0 - min( length( vPosition - q0 ), length( vPosition - q1 ) ) );\n"
- "}\n"
-
- "void main()\n"
- "{\n"
- " OUT_COLOR = vec4( mixColor, 1.0 ) * uColor;\n"
- " OUT_COLOR.a *= GetOpacity();\n"
- "}\n";
-
}
ArcVisualPtr ArcVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
shader = mFactoryCache.GetShader( VisualFactoryCache::ARC_BUTT_CAP_SHADER );
if( !shader )
{
- shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_BUTT_CAP );
+ shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_ARC_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_ARC_VISUAL_BUTT_CAP_SHADER_FRAG.data() );
mFactoryCache.SaveShader( VisualFactoryCache::ARC_BUTT_CAP_SHADER, shader );
}
}
shader = mFactoryCache.GetShader( VisualFactoryCache::ARC_ROUND_CAP_SHADER );
if( !shader )
{
- shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ROUND_CAP );
+ shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_ARC_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_ARC_VISUAL_ROUND_CAP_SHADER_FRAG.data() );
mFactoryCache.SaveShader( VisualFactoryCache::ARC_ROUND_CAP_SHADER, shader );
}
}
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
const char * const POSITION_ATTRIBUTE_NAME("aPosition");
const char * const DRIFT_ATTRIBUTE_NAME("aDrift");
const char * const INDEX_NAME("indices");
-
-const char* VERTEX_SHADER =
- "INPUT mediump vec2 aPosition;\n"
- "INPUT mediump vec2 aDrift;\n"
-
- "uniform highp mat4 uMvpMatrix;\n"
- "uniform highp vec3 uSize;\n"
- "uniform mediump float borderSize;\n"
-
- "//Visual size and offset\n"
- "uniform mediump vec2 offset;\n"
- "uniform highp vec2 size;\n"
- "uniform mediump vec4 offsetSizeMode;\n"
- "uniform mediump vec2 origin;\n"
- "uniform mediump vec2 anchorPoint;\n"
-
- "vec2 ComputeVertexPosition()\n"
- "{\n"
- " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n"
- " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
- " return (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy;\n"
- "}\n"
-
- "void main()\n"
- "{\n"
- " vec2 position = ComputeVertexPosition() + aDrift*borderSize;\n"
- " gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);\n"
- "}\n";
-
-const char* FRAGMENT_SHADER =
- "uniform lowp vec4 uColor;\n"
- "uniform lowp vec4 borderColor;\n"
- "uniform lowp vec3 mixColor;\n"
-
- "void main()\n"
- "{\n"
- " OUT_COLOR = vec4(mixColor, 1.0) * borderColor * uColor;\n"
- "}\n";
-
-const char* VERTEX_SHADER_ANTI_ALIASING =
- "INPUT mediump vec2 aPosition;\n"
- "INPUT mediump vec2 aDrift;\n"
- "OUTPUT mediump float vAlpha;\n"
-
- "uniform highp mat4 uMvpMatrix;\n"
- "uniform highp vec3 uSize;\n"
- "uniform mediump float borderSize;\n"
-
- "void main()\n"
- "{\n"
- " vec2 position = aPosition*(uSize.xy+vec2(0.75)) + aDrift*(borderSize+1.5);\n"
- " gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);\n"
- " vAlpha = min( abs(aDrift.x), abs(aDrift.y) )*(borderSize+1.5);"
- "}\n";
-
-const char* FRAGMENT_SHADER_ANTI_ALIASING =
- "INPUT mediump float vAlpha;\n"
-
- "uniform lowp vec4 uColor;\n"
- "uniform lowp vec4 borderColor;\n"
- "uniform lowp vec3 mixColor;\n"
- "uniform mediump float borderSize;\n"
-
- "void main()\n"
- "{\n"
- " OUT_COLOR = vec4(mixColor, 1.0) * borderColor * uColor;\n"
- " OUT_COLOR.a *= smoothstep(0.0, 1.5, vAlpha) * smoothstep( borderSize + 1.5, borderSize, vAlpha );\n"
- "}\n";
}
BorderVisualPtr BorderVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
shader = mFactoryCache.GetShader( VisualFactoryCache::BORDER_SHADER_ANTI_ALIASING );
if( !shader )
{
- shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER_ANTI_ALIASING, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ANTI_ALIASING );
+ shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_BORDER_VISUAL_ANTI_ALIASING_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_BORDER_VISUAL_ANTI_ALIASING_SHADER_FRAG.data() );
mFactoryCache.SaveShader( VisualFactoryCache::BORDER_SHADER_ANTI_ALIASING, shader );
}
}
shader = mFactoryCache.GetShader( VisualFactoryCache::BORDER_SHADER );
if( !shader )
{
- shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER );
+ shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_BORDER_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_BORDER_VISUAL_SHADER_FRAG.data() );
mFactoryCache.SaveShader( VisualFactoryCache::BORDER_SHADER, shader );
}
}
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
namespace Internal
{
-namespace
-{
-
-const char* VERTEX_SHADER =
- "INPUT mediump vec2 aPosition;\n"
-
- "uniform highp mat4 uMvpMatrix;\n"
- "uniform highp vec3 uSize;\n"
-
- "//Visual size and offset\n"
- "uniform mediump vec2 offset;\n"
- "uniform highp vec2 size;\n"
- "uniform mediump vec4 offsetSizeMode;\n"
- "uniform mediump vec2 origin;\n"
- "uniform mediump vec2 anchorPoint;\n"
- "uniform mediump vec2 extraSize;\n"
-
- "vec4 ComputeVertexPosition()\n"
- "{\n"
- " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n"
- " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
- " return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n"
- "}\n"
-
- "void main()\n"
- "{\n"
- " gl_Position = uMvpMatrix * ComputeVertexPosition();\n"
- "}\n";
-
-
-const char* FRAGMENT_SHADER =
- "uniform lowp vec4 uColor;\n"
- "uniform lowp vec3 mixColor;\n"
-
- "void main()\n"
- "{\n"
- " OUT_COLOR = vec4(mixColor, 1.0) * uColor;\n"
- "}\n";
-
-const char* VERTEX_SHADER_ROUNDED_CORNER =
- "INPUT mediump vec2 aPosition;\n"
- "OUTPUT mediump vec2 vPosition;\n"
- "OUTPUT mediump vec2 vRectSize;\n"
- "OUTPUT mediump float vCornerRadius;\n"
-
- "uniform highp mat4 uMvpMatrix;\n"
- "uniform highp vec3 uSize;\n"
-
- "//Visual size and offset\n"
- "uniform mediump vec2 offset;\n"
- "uniform highp vec2 size;\n"
- "uniform mediump vec2 extraSize;\n"
- "uniform mediump vec4 offsetSizeMode;\n"
- "uniform mediump vec2 origin;\n"
- "uniform mediump vec2 anchorPoint;\n"
- "uniform mediump float cornerRadius;\n"
- "uniform mediump float cornerRadiusPolicy;\n"
-
- "vec4 ComputeVertexPosition()\n"
- "{\n"
- " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n"
- " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
- " mediump float minSize = min( visualSize.x, visualSize.y );\n"
- " vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);\n"
- " vCornerRadius = min( vCornerRadius, minSize * 0.5 );\n"
- " vRectSize = visualSize / 2.0 - vCornerRadius;\n"
- " vPosition = aPosition* visualSize;\n"
- " return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n"
- "}\n"
-
- "void main()\n"
- "{\n"
- " gl_Position = uMvpMatrix * ComputeVertexPosition();\n"
- "}\n";
-
-//float distance = length( max( abs( position - center ), size ) - size ) - radius;
-const char* FRAGMENT_SHADER_ROUNDED_CORNER =
- "INPUT mediump vec2 vPosition;\n"
- "INPUT mediump vec2 vRectSize;\n"
- "INPUT mediump float vCornerRadius;\n"
-
- "uniform lowp vec4 uColor;\n"
- "uniform lowp vec3 mixColor;\n"
-
- "void main()\n"
- "{\n"
- " mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n"
- " OUT_COLOR = vec4(mixColor, 1.0) * uColor;\n"
- " OUT_COLOR.a *= 1.0 - smoothstep( -1.0, 1.0, dist );\n"
- "}\n";
-
-const char* VERTEX_SHADER_BLUR_EDGE =
- "INPUT mediump vec2 aPosition;\n"
- "OUTPUT mediump vec2 vPosition;\n"
- "OUTPUT mediump vec2 vRectSize;\n"
-
- "uniform highp mat4 uMvpMatrix;\n"
- "uniform highp vec3 uSize;\n"
-
- "//Visual size and offset\n"
- "uniform mediump vec2 offset;\n"
- "uniform highp vec2 size;\n"
- "uniform mediump vec2 extraSize;\n"
- "uniform mediump vec4 offsetSizeMode;\n"
- "uniform mediump vec2 origin;\n"
- "uniform mediump vec2 anchorPoint;\n"
- "uniform mediump float blurRadius;\n"
-
- "vec4 ComputeVertexPosition()\n"
- "{\n"
- " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize + blurRadius * 2.0;\n"
- " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
- " vRectSize = visualSize / 2.0;\n"
- " vPosition = aPosition* visualSize;\n"
- " return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n"
- "}\n"
-
- "void main()\n"
- "{\n"
- " gl_Position = uMvpMatrix * ComputeVertexPosition();\n"
- "}\n";
-
-const char* FRAGMENT_SHADER_BLUR_EDGE =
- "INPUT mediump vec2 vPosition;\n"
- "INPUT mediump vec2 vRectSize;\n"
-
- "uniform lowp vec4 uColor;\n"
- "uniform lowp vec3 mixColor;\n"
- "uniform mediump float blurRadius;\n"
-
- "void main()\n"
- "{\n"
- " mediump vec2 blur = 1.0 - smoothstep( vRectSize - blurRadius * 2.0, vRectSize, abs( vPosition ) );\n"
- " OUT_COLOR = vec4(mixColor, 1.0) * uColor;\n"
- " OUT_COLOR.a *= blur.x * blur.y;\n"
- "}\n";
-
-}
-
ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
{
ColorVisualPtr colorVisualPtr( new ColorVisual( factoryCache ) );
shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER_BLUR_EDGE );
if( !shader )
{
- shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER_BLUR_EDGE, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_BLUR_EDGE );
+ shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_VISUAL_BLUR_EDGE_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_VISUAL_BLUR_EDGE_SHADER_FRAG.data() );
mFactoryCache.SaveShader( VisualFactoryCache::COLOR_SHADER_BLUR_EDGE, shader );
}
}
shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER );
if( !shader )
{
- shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER );
+ shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_VISUAL_SHADER_FRAG.data() );
mFactoryCache.SaveShader( VisualFactoryCache::COLOR_SHADER, shader );
}
}
shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER );
if( !shader )
{
- shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER_ROUNDED_CORNER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ROUNDED_CORNER );
+ shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_VISUAL_ROUNDED_CORNER_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_VISUAL_ROUNDED_CORNER_SHADER_FRAG.data() );
mFactoryCache.SaveShader( VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER, shader );
}
}
#include <dali-toolkit/internal/visuals/gradient/linear-gradient.h>
#include <dali-toolkit/internal/visuals/gradient/radial-gradient.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-bounding-box-rounded-corner-shader-vert.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-bounding-box-shader-vert.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-linear-rounded-corner-shader-frag.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-linear-shader-frag.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-radial-rounded-corner-shader-frag.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-radial-shader-frag.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-user-space-rounded-corner-shader-vert.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-user-space-shader-vert.h>
namespace Dali
{
}
};
-const char* VERTEX_SHADER[] =
+const std::string_view VERTEX_SHADER[] =
{
-// vertex shader for gradient units as OBJECT_BOUNDING_BOX
-DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- uniform highp mat4 uMvpMatrix;\n
- uniform highp vec3 uSize;\n
- uniform mediump mat3 uAlignmentMatrix;\n
- varying mediump vec2 vTexCoord;\n
- \n
-
- //Visual size and offset
- uniform mediump vec2 offset;\n
- uniform highp vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
-
- vec4 ComputeVertexPosition()\n
- {\n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
- vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
- return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
- }\n
-
- void main()\n
- {\n
- mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
- vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;\n
- \n
- gl_Position = uMvpMatrix * ComputeVertexPosition();\n
- }\n
-),
-
-// vertex shader for gradient units as USER_SPACE
-DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- uniform highp mat4 uMvpMatrix;\n
- uniform highp vec3 uSize;\n
- uniform mediump mat3 uAlignmentMatrix;\n
- varying mediump vec2 vTexCoord;\n
- \n
-
- //Visual size and offset
- uniform mediump vec2 offset;\n
- uniform highp vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
-
- vec4 ComputeVertexPosition()\n
- {\n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
- vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
- return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
- }\n
-
- void main()\n
- {\n
- mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
- vertexPosition.xyz *= uSize;\n
- gl_Position = uMvpMatrix * ComputeVertexPosition();\n
- \n
- vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;\n
- }\n
-),
-
-// vertex shader for gradient units as OBJECT_BOUNDING_BOX with corner radius
-DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- uniform highp mat4 uMvpMatrix;\n
- uniform highp vec3 uSize;\n
- uniform mediump mat3 uAlignmentMatrix;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec2 vPosition;\n
- varying mediump vec2 vRectSize;\n
- varying mediump float vCornerRadius;\n
- \n
- //Visual size and offset
- uniform mediump vec2 offset;\n
- uniform highp vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
- uniform mediump float cornerRadius;\n
- uniform mediump float cornerRadiusPolicy;\n
-
- vec4 ComputeVertexPosition()\n
- {\n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
- vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
- mediump float minSize = min( visualSize.x, visualSize.y );\n
- vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);\n
- vCornerRadius = min( vCornerRadius, minSize * 0.5 );\n
- vRectSize = visualSize * 0.5 - vCornerRadius;\n
- vPosition = aPosition * visualSize;\n
- return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
- }\n
-
- void main()\n
- {\n
- mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
- vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;\n
- \n
- gl_Position = uMvpMatrix * ComputeVertexPosition();\n
- }\n
-),
-
-// vertex shader for gradient units as USER_SPACE with corner radius
-DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- uniform highp mat4 uMvpMatrix;\n
- uniform highp vec3 uSize;\n
- uniform mediump mat3 uAlignmentMatrix;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec2 vPosition;\n
- varying mediump vec2 vRectSize;\n
- varying mediump float vCornerRadius;\n
- \n
- //Visual size and offset
- uniform mediump vec2 offset;\n
- uniform highp vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
- uniform mediump float cornerRadius;\n
- uniform mediump float cornerRadiusPolicy;\n
-
- vec4 ComputeVertexPosition()\n
- {\n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
- vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
- mediump float minSize = min( visualSize.x, visualSize.y );\n
- vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);\n
- vCornerRadius = min( vCornerRadius, minSize * 0.5 );\n
- vRectSize = visualSize * 0.5 - vCornerRadius;\n
- vPosition = aPosition * visualSize;\n
- return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
- }\n
-
- void main()\n
- {\n
- mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
- vertexPosition.xyz *= uSize;\n
- gl_Position = uMvpMatrix * ComputeVertexPosition();\n
- \n
- vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;\n
- }\n
-)
+ // vertex shader for gradient units as OBJECT_BOUNDING_BOX
+ SHADER_GRADIENT_VISUAL_BOUNDING_BOX_SHADER_VERT,
+
+ // vertex shader for gradient units as USER_SPACE
+ SHADER_GRADIENT_VISUAL_USER_SPACE_SHADER_VERT,
+
+ // vertex shader for gradient units as OBJECT_BOUNDING_BOX with corner radius
+ SHADER_GRADIENT_VISUAL_BOUNDING_BOX_ROUNDED_CORNER_SHADER_VERT,
+
+ // vertex shader for gradient units as USER_SPACE with corner radius
+ SHADER_GRADIENT_VISUAL_USER_SPACE_ROUNDED_CORNER_SHADER_VERT
};
-const char* FRAGMENT_SHADER[] =
+const std::string_view FRAGMENT_SHADER[] =
{
-// fragment shader for linear gradient
-DALI_COMPOSE_SHADER(
- uniform sampler2D sTexture;\n // sampler1D?
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- varying mediump vec2 vTexCoord;\n
- \n
- void main()\n
- {\n
- gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n
- }\n
-),
-
-// fragment shader for radial gradient
-DALI_COMPOSE_SHADER(
- uniform sampler2D sTexture;\n // sampler1D?
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- varying mediump vec2 vTexCoord;\n
- \n
- void main()\n
- {\n
- gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n
- }\n
-),
-
-// fragment shader for linear gradient with corner radius
-DALI_COMPOSE_SHADER(
- uniform sampler2D sTexture;\n // sampler1D?
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec2 vPosition;\n
- varying mediump vec2 vRectSize;\n
- varying mediump float vCornerRadius;\n
- \n
- void main()\n
- {\n
- mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n
- gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n
- gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );\n
- }\n
-),
-
-// fragment shader for radial gradient with corner radius
-DALI_COMPOSE_SHADER(
- uniform sampler2D sTexture;\n // sampler1D?
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec2 vPosition;\n
- varying mediump vec2 vRectSize;\n
- varying mediump float vCornerRadius;\n
- \n
- void main()\n
- {\n
- mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n
- gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n
- gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );\n
- }\n
-)
+ // fragment shader for linear gradient
+ SHADER_GRADIENT_VISUAL_LINEAR_SHADER_FRAG,
+
+ // fragment shader for radial gradient
+ SHADER_GRADIENT_VISUAL_RADIAL_SHADER_FRAG,
+
+ // fragment shader for linear gradient with corner radius
+ SHADER_GRADIENT_VISUAL_LINEAR_ROUNDED_CORNER_SHADER_FRAG,
+
+ // fragment shader for radial gradient with corner radius
+ SHADER_GRADIENT_VISUAL_RADIAL_ROUNDED_CORNER_SHADER_FRAG
};
Dali::WrapMode::Type GetWrapMode( Toolkit::GradientVisual::SpreadMethod::Type spread )
// INTERNAL INCLUDES
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali/integration-api/debug.h>
namespace Dali
const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
-const char* VERTEX_SHADER =
- "INPUT mediump vec2 aPosition;\n"
- "OUTPUT mediump vec2 vTexCoord;\n"
-
- "uniform highp mat4 uMvpMatrix;\n"
- "uniform highp vec3 uSize;\n"
- "uniform mediump vec4 pixelArea;"
- "//Visual size and offset\n"
-
- "uniform mediump vec2 offset;\n"
- "uniform highp vec2 size;\n"
- "uniform mediump vec4 offsetSizeMode;\n"
- "uniform mediump vec2 origin;\n"
- "uniform mediump vec2 anchorPoint;\n"
- "uniform mediump vec2 extraSize;\n"
-
- "vec4 ComputeVertexPosition()\n"
- "{\n"
- " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n"
- " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
- " return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n"
- "}\n"
- "\n"
- "void main()\n"
- "{\n"
- " gl_Position = uMvpMatrix * ComputeVertexPosition();\n"
- " vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );\n"
- "}\n";
-
-const char* FRAGMENT_SHADER_NO_ATLAS =
- "INPUT mediump vec2 vTexCoord;\n"
-
- "uniform sampler2D sTexture;\n"
- "uniform lowp vec4 uColor;\n"
- "uniform lowp vec3 mixColor;\n"
- "uniform lowp float preMultipliedAlpha;\n"
-
- "void main()\n"
- "{\n"
- " OUT_COLOR = TEXTURE( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n"
- "}\n";
-
-
-const char* FRAGMENT_SHADER_ATLAS_CLAMP =
- "INPUT mediump vec2 vTexCoord;\n"
-
- "uniform sampler2D sTexture;\n"
- "uniform mediump vec4 uAtlasRect;\n"
- "uniform lowp vec4 uColor;\n"
- "uniform lowp vec3 mixColor;\n"
- "uniform lowp float preMultipliedAlpha;\n"
-
- "void main()\n"
- "{\n"
- " mediump vec2 texCoord = clamp( mix( uAtlasRect.xy, uAtlasRect.zw, vTexCoord ), uAtlasRect.xy, uAtlasRect.zw );\n"
- " OUT_COLOR = TEXTURE( sTexture, texCoord ) * uColor * vec4( mixColor, 1.0 );\n"
- "}\n";
-
-
-const char* FRAGMENT_SHADER_ATLAS_VARIOUS_WRAP =
- "INPUT mediump vec2 vTexCoord;\n"
-
- "uniform sampler2D sTexture;\n"
- "uniform mediump vec4 uAtlasRect;\n"
- "// WrapMode -- 0: CLAMP; 1: REPEAT; 2: REFLECT;"
- "uniform lowp vec2 wrapMode;\n"
- "uniform lowp vec4 uColor;\n"
- "uniform lowp vec3 mixColor;\n"
- "uniform lowp float preMultipliedAlpha;\n"
- "mediump float wrapCoordinate( mediump vec2 range, mediump float coordinate, lowp float wrap )\n"
-
- "{\n"
- " mediump float coord;\n"
- " if( wrap > 1.5 )\n // REFLECT"
- " coord = 1.0-abs(fract(coordinate*0.5)*2.0 - 1.0);\n"
- " else \n// warp == 0 or 1"
- " coord = mix(coordinate, fract( coordinate ), wrap);\n"
- " return clamp( mix(range.x, range.y, coord), range.x, range.y );"
- "}\n"
-
- "void main()\n"
- "{\n"
- " mediump vec2 texCoord = vec2( wrapCoordinate( uAtlasRect.xz, vTexCoord.x, wrapMode.x ),"
- " wrapCoordinate( uAtlasRect.yw, vTexCoord.y, wrapMode.y ) );\n"
- " OUT_COLOR = TEXTURE( sTexture, texCoord ) * uColor * vec4( mixColor, 1.0 );\n"
- "}\n";
-
-const char* VERTEX_SHADER_ROUNDED_CORNER =
- "INPUT mediump vec2 aPosition;\n"
- "OUTPUT mediump vec2 vTexCoord;\n"
- "OUTPUT mediump vec2 vPosition;\n"
- "OUTPUT mediump vec2 vRectSize;\n"
- "OUTPUT mediump float vCornerRadius;\n"
-
- "uniform highp mat4 uMvpMatrix;\n"
- "uniform highp vec3 uSize;\n"
- "uniform mediump vec4 pixelArea;"
-
- "//Visual size and offset\n"
- "uniform mediump vec2 offset;\n"
- "uniform highp vec2 size;\n"
- "uniform mediump vec4 offsetSizeMode;\n"
- "uniform mediump vec2 origin;\n"
- "uniform mediump vec2 anchorPoint;\n"
- "uniform mediump float cornerRadius;\n"
- "uniform mediump float cornerRadiusPolicy;\n"
- "uniform mediump vec2 extraSize;\n"
-
- "vec4 ComputeVertexPosition()\n"
- "{\n"
- " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n"
- " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
- " mediump float minSize = min( visualSize.x, visualSize.y );\n"
- " vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);\n"
- " vCornerRadius = min( vCornerRadius, minSize * 0.5 );\n"
- " vRectSize = visualSize * 0.5 - vCornerRadius;\n"
- " vPosition = aPosition* visualSize;\n"
- " return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n"
- "}\n"
-
- "void main()\n"
- "{\n"
- " gl_Position = uMvpMatrix * ComputeVertexPosition();\n"
- " vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );\n"
- "}\n";
-
-
-//float distance = length( max( abs( position - center ), size ) - size ) - radius;
-const char* FRAGMENT_SHADER_ROUNDED_CORNER =
- "INPUT mediump vec2 vTexCoord;\n"
- "INPUT mediump vec2 vPosition;\n"
- "INPUT mediump vec2 vRectSize;\n"
- "INPUT mediump float vCornerRadius;\n"
-
- "uniform sampler2D sTexture;\n"
- "uniform lowp vec4 uColor;\n"
- "uniform lowp vec3 mixColor;\n"
- "uniform lowp float preMultipliedAlpha;\n"
-
- "void main()\n"
- "{\n"
- " mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n"
- " mediump float opacity = 1.0 - smoothstep( -1.0, 1.0, dist );\n"
-
- " OUT_COLOR = TEXTURE( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n"
- " OUT_COLOR.a *= opacity;\n"
- " OUT_COLOR.rgb *= mix( 1.0, opacity, preMultipliedAlpha );\n"
- "}\n";
-
// global string variable to caching complate vertex shader
static std::string gVertexShader;
shader = factoryCache.GetShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_DEFAULT_WRAP );
if( !shader )
{
- shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ATLAS_CLAMP );
+ shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data(),
+ Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_ATLAS_CLAMP_SHADER_FRAG.data() );
shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_DEFAULT_WRAP, shader );
}
shader = factoryCache.GetShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_CUSTOM_WRAP );
if( !shader )
{
- shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ATLAS_VARIOUS_WRAP );
+ shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data(),
+ Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_ATLAS_VARIOUS_WRAP_SHADER_FRAG.data() );
shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_CUSTOM_WRAP, shader );
}
shader = factoryCache.GetShader( VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER );
if( !shader )
{
- shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER_ROUNDED_CORNER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ROUNDED_CORNER );
+ shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_ROUNDED_CORNER_SHADER_VERT.data(),
+ Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_ROUNDED_CORNER_SHADER_FRAG.data() );
shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER, shader );
}
shader = factoryCache.GetShader( VisualFactoryCache::IMAGE_SHADER );
if( !shader )
{
- shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_NO_ATLAS );
+ shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data(),
+ Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_NO_ATLAS_SHADER_FRAG.data() );
shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER, shader );
}
{
if(gVertexShader.empty())
{
- gVertexShader = Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER;
+ gVertexShader = Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data();
}
return gVertexShader;
{
if(gFragmentShaderNoAtlas.empty())
{
- gFragmentShaderNoAtlas = Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_NO_ATLAS;
+ gFragmentShaderNoAtlas = Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_NO_ATLAS_SHADER_FRAG.data();
}
return gFragmentShaderNoAtlas;
}
return new ImageVisual( factoryCache, shaderFactory, imageUrl, size, fittingMode, samplingMode );
}
-ImageVisual::ImageVisual( VisualFactoryCache& factoryCache,
- ImageVisualShaderFactory& shaderFactory,
- const VisualUrl& imageUrl,
- ImageDimensions size,
- FittingMode::Type fittingMode,
- Dali::SamplingMode::Type samplingMode )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::IMAGE ),
- mPixelArea( FULL_TEXTURE_RECT ),
+ImageVisual::ImageVisual(VisualFactoryCache& factoryCache,
+ ImageVisualShaderFactory& shaderFactory,
+ const VisualUrl& imageUrl,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ Dali::SamplingMode::Type samplingMode)
+: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::IMAGE),
+ mPixelArea(FULL_TEXTURE_RECT),
mPlacementActor(),
- mImageUrl( imageUrl ),
- mMaskingData( ),
- mDesiredSize( size ),
- mTextureId( TextureManager::INVALID_TEXTURE_ID ),
+ mImageUrl(imageUrl),
+ mMaskingData(),
+ mDesiredSize(size),
+ mTextureId(TextureManager::INVALID_TEXTURE_ID),
mTextures(),
- mImageVisualShaderFactory( shaderFactory ),
- mFittingMode( fittingMode ),
- mSamplingMode( samplingMode ),
- mWrapModeU( WrapMode::DEFAULT ),
- mWrapModeV( WrapMode::DEFAULT ),
- mLoadPolicy( Toolkit::ImageVisual::LoadPolicy::ATTACHED ),
- mReleasePolicy( Toolkit::ImageVisual::ReleasePolicy::DETACHED ),
- mAtlasRect( 0.0f, 0.0f, 0.0f, 0.0f ),
- mAtlasRectSize( 0, 0 ),
- mAttemptAtlasing( false ),
- mLoading( false ),
- mOrientationCorrection( true )
+ mImageVisualShaderFactory(shaderFactory),
+ mFittingMode(fittingMode),
+ mSamplingMode(samplingMode),
+ mWrapModeU(WrapMode::DEFAULT),
+ mWrapModeV(WrapMode::DEFAULT),
+ mLoadPolicy(Toolkit::ImageVisual::LoadPolicy::ATTACHED),
+ mReleasePolicy(Toolkit::ImageVisual::ReleasePolicy::DETACHED),
+ mAtlasRect(0.0f, 0.0f, 0.0f, 0.0f),
+ mAtlasRectSize(0, 0),
+ mLoadState(TextureManager::LoadState::NOT_STARTED),
+ mAttemptAtlasing(false),
+ mOrientationCorrection(true)
{
EnablePreMultipliedAlpha( mFactoryCache.GetPreMultiplyOnLoad() );
}
? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
: TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
- textures = textureManager.LoadTexture( mImageUrl, mDesiredSize, mFittingMode, mSamplingMode,
- mMaskingData, IsSynchronousLoadingRequired(), mTextureId,
- atlasRect, mAtlasRectSize, atlasing, mLoading, mWrapModeU,
- mWrapModeV, textureObserver, atlasUploadObserver, atlasManager,
- mOrientationCorrection, forceReload, preMultiplyOnLoad);
+ bool synchronousLoading = IsSynchronousLoadingRequired();
+ bool loadingStatus;
+
+ textures = textureManager.LoadTexture(mImageUrl, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, mTextureId, atlasRect, mAtlasRectSize, atlasing, loadingStatus, mWrapModeU, mWrapModeV, textureObserver, atlasUploadObserver, atlasManager, mOrientationCorrection, forceReload, preMultiplyOnLoad);
if( textures )
{
+ if(loadingStatus)
+ {
+ mLoadState = TextureManager::LoadState::LOADING;
+ }
+ else
+ {
+ mLoadState = TextureManager::LoadState::LOAD_FINISHED;
+ }
+
EnablePreMultipliedAlpha( preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD );
}
+ else if(synchronousLoading)
+ {
+ // Synchronous loading is failed
+ mLoadState = TextureManager::LoadState::LOAD_FAILED;
+ }
if( atlasing ) // Flag needs to be set before creating renderer
{
mImpl->mRenderer.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, mPixelArea );
}
- if( mLoading == false )
+ if(mLoadState == TextureManager::LoadState::LOAD_FINISHED)
{
actor.AddRenderer( mImpl->mRenderer );
mPlacementActor.Reset();
// Image loaded and ready to display
ResourceReady( Toolkit::Visual::ResourceStatus::READY );
}
+ else if(mLoadState == TextureManager::LoadState::LOAD_FAILED)
+ {
+ Texture brokenImage = mFactoryCache.GetBrokenVisualImage();
+
+ mTextures = TextureSet::New();
+ mTextures.SetTexture(0u, brokenImage);
+ mImpl->mRenderer.SetTextures(mTextures);
+
+ actor.AddRenderer(mImpl->mRenderer);
+ mPlacementActor.Reset();
+
+ ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
+ }
}
void ImageVisual::DoSetOffScene( Actor& actor )
{
RemoveTexture(); // If INVALID_TEXTURE_ID then removal will be attempted on atlas
mImpl->mResourceStatus = Toolkit::Visual::ResourceStatus::PREPARING;
+
+ mLoadState = TextureManager::LoadState::NOT_STARTED;
}
- mLoading = false;
mImpl->mRenderer.Reset();
mPlacementActor.Reset();
}
// reset the weak handle so that the renderer only get added to actor once
mPlacementActor.Reset();
}
+
// Image loaded
ResourceReady( Toolkit::Visual::ResourceStatus::READY );
- mLoading = false;
+ mLoadState = TextureManager::LoadState::LOAD_FINISHED;
}
// From Texture Manager
if( loadingSuccess )
{
resourceStatus = Toolkit::Visual::ResourceStatus::READY;
+ mLoadState = TextureManager::LoadState::LOAD_FINISHED;
}
else
{
resourceStatus = Toolkit::Visual::ResourceStatus::FAILED;
+ mLoadState = TextureManager::LoadState::LOAD_FAILED;
}
// use geometry if needed
// Signal to observers ( control ) that resources are ready. Must be all resources.
ResourceReady( resourceStatus );
- mLoading = false;
}
void ImageVisual::RemoveTexture()
Dali::Toolkit::ImageVisual::ReleasePolicy::Type mReleasePolicy;
Vector4 mAtlasRect;
Dali::ImageDimensions mAtlasRectSize;
+ TextureManager::LoadState mLoadState; ///< The texture loading state
bool mAttemptAtlasing; ///< If true will attempt atlasing, otherwise create unique texture
- bool mLoading; ///< True if the texture is still loading.
bool mOrientationCorrection; ///< true if the image will have it's orientation corrected.
};
-
-
} // namespace Internal
} // namespace Toolkit
#include <dali-toolkit/public-api/visuals/visual-properties.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
const char * const OBJECT_MATRIX_UNIFORM_NAME( "uObjectMatrix" );
const char * const STAGE_OFFSET_UNIFORM_NAME( "uStageOffset" );
-//Shaders
-//If a shader requires certain textures, they must be listed in order,
-//as detailed in the TextureIndex enum documentation.
-
-//A basic shader that doesn't use textures at all.
-const char* SIMPLE_VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute highp vec3 aPosition;\n
- attribute highp vec3 aNormal;\n
- varying mediump vec3 vIllumination;\n
- uniform mediump vec3 uSize;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump mat4 uModelView;\n
- uniform mediump mat4 uViewMatrix;\n
- uniform mediump mat3 uNormalMatrix;
- uniform mediump mat4 uObjectMatrix;\n
- uniform mediump vec3 lightPosition;\n
- uniform mediump vec2 uStageOffset;\n
-
- //Visual size and offset
- uniform mediump vec2 offset;\n
- uniform mediump vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
-
- vec4 ComputeVertexPosition()\n
- {\n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
- float scaleFactor = min( visualSize.x, visualSize.y );\n
- vec3 originFlipY = vec3(origin.x, -origin.y, 0.0);
- vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
- vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);\n
- return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );\n
- }\n
-
- void main()\n
- {\n
- vec4 normalisedVertexPosition = ComputeVertexPosition();\n
- vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
-
- //Illumination in Model-View space - Transform attributes and uniforms\n
- vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n
- vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;\n
-
- vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n
- mvLightPosition = uViewMatrix * mvLightPosition;\n
- vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n
-
- float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );\n
- vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n
-
- gl_Position = vertexPosition;\n
- }\n
-);
-
-//Fragment shader corresponding to the texture-less shader.
-const char* SIMPLE_FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- varying mediump vec3 vIllumination;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- uniform lowp float preMultipliedAlpha;\n
-
- void main()\n
- {\n
- gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a ) * vec4( mixColor, 1.0 );\n
- }\n
-);
-
-//Diffuse and specular illumination shader with albedo texture. Texture is index 0.
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute highp vec3 aPosition;\n
- attribute highp vec2 aTexCoord;\n
- attribute highp vec3 aNormal;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec3 vIllumination;\n
- varying mediump float vSpecular;\n
- uniform mediump vec3 uSize;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump mat4 uModelView;
- uniform mediump mat4 uViewMatrix;\n
- uniform mediump mat3 uNormalMatrix;
- uniform mediump mat4 uObjectMatrix;\n
- uniform mediump vec3 lightPosition;\n
- uniform mediump vec2 uStageOffset;\n
-
- //Visual size and offset
- uniform mediump vec2 offset;\n
- uniform mediump vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
-
- vec4 ComputeVertexPosition()\n
- {\n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
- float scaleFactor = min( visualSize.x, visualSize.y );\n
- vec3 originFlipY = vec3(origin.x, -origin.y, 0.0);
- vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
- vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);\n
- return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );\n
- }\n
-
- void main()
- {\n
- vec4 normalisedVertexPosition = ComputeVertexPosition();\n
- vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
-
- //Illumination in Model-View space - Transform attributes and uniforms\n
- vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n
- vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );\n
-
- vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n
- mvLightPosition = uViewMatrix * mvLightPosition;\n
- vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n
-
- vec3 viewDirection = normalize( -mvVertexPosition.xyz );
-
- float lightDiffuse = dot( vectorToLight, normal );\n
- lightDiffuse = max( 0.0,lightDiffuse );\n
- vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n
-
- vec3 reflectDirection = reflect( -vectorToLight, normal );
- vSpecular = pow( max( dot( reflectDirection, viewDirection ), 0.0 ), 4.0 );
-
- vTexCoord = aTexCoord;\n
- gl_Position = vertexPosition;\n
- }\n
-);
-
-//Fragment shader corresponding to the diffuse and specular illumination shader with albedo texture
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec3 vIllumination;\n
- varying mediump float vSpecular;\n
- uniform sampler2D sDiffuse;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- uniform lowp float preMultipliedAlpha;\n
-
- void main()\n
- {\n
- vec4 texture = texture2D( sDiffuse, vTexCoord );\n
- vec4 visualMixColor = vec4( mixColor, 1.0 );\n
- gl_FragColor = vec4( vIllumination.rgb * texture.rgb * uColor.rgb * visualMixColor.rgb + vSpecular * 0.3, texture.a * uColor.a * visualMixColor.a );\n
- }\n
-);
-
-//Diffuse and specular illumination shader with albedo texture, normal map and gloss map shader.
-//Diffuse (albedo) texture is index 0, normal is 1, gloss is 2. They must be declared in this order.
-const char* NORMAL_MAP_VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute highp vec3 aPosition;\n
- attribute highp vec2 aTexCoord;\n
- attribute highp vec3 aNormal;\n
- attribute highp vec3 aTangent;\n
- attribute highp vec3 aBiNormal;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec3 vLightDirection;\n
- varying mediump vec3 vHalfVector;\n
- uniform mediump vec3 uSize;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump mat4 uModelView;
- uniform mediump mat4 uViewMatrix;\n
- uniform mediump mat3 uNormalMatrix;
- uniform mediump mat4 uObjectMatrix;\n
- uniform mediump vec3 lightPosition;\n
- uniform mediump vec2 uStageOffset;\n
-
- //Visual size and offset
- uniform mediump vec2 offset;\n
- uniform mediump vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
-
- vec4 ComputeVertexPosition()\n
- {\n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
- float scaleFactor = min( visualSize.x, visualSize.y );\n
- vec3 originFlipY = vec3(origin.x, -origin.y, 0.0);
- vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
- vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);\n
- return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );\n
- }\n
-
- void main()
- {\n
- vec4 normalisedVertexPosition = ComputeVertexPosition();\n
- vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
-
- vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n
-
- vec3 tangent = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aTangent );
- vec3 binormal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aBiNormal );
- vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );
-
- vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n
- mvLightPosition = uViewMatrix * mvLightPosition;\n
- vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n
- vLightDirection.x = dot( vectorToLight, tangent );
- vLightDirection.y = dot( vectorToLight, binormal );
- vLightDirection.z = dot( vectorToLight, normal );
-
- vec3 viewDirection = normalize( -mvVertexPosition.xyz );
- vec3 halfVector = normalize( viewDirection + vectorToLight );
- vHalfVector.x = dot( halfVector, tangent );
- vHalfVector.y = dot( halfVector, binormal );
- vHalfVector.z = dot( halfVector, normal );
-
- vTexCoord = aTexCoord;\n
- gl_Position = vertexPosition;\n
- }\n
-);
-
-//Fragment shader corresponding to the shader that uses all textures (diffuse, normal and gloss maps)
-const char* NORMAL_MAP_FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec3 vLightDirection;\n
- varying mediump vec3 vHalfVector;\n
- uniform sampler2D sDiffuse;\n
- uniform sampler2D sNormal;\n
- uniform sampler2D sGloss;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- uniform lowp float preMultipliedAlpha;\n
-
- void main()\n
- {\n
- vec4 texture = texture2D( sDiffuse, vTexCoord );\n
- vec3 normal = normalize( texture2D( sNormal, vTexCoord ).xyz * 2.0 - 1.0 );\n
- vec4 glossMap = texture2D( sGloss, vTexCoord );\n
- vec4 visualMixColor = vec4( mixColor, 1.0 );\n
-
- float lightDiffuse = max( 0.0, dot( normal, normalize( vLightDirection ) ) );\n
- lightDiffuse = lightDiffuse * 0.5 + 0.5;\n
-
- float shininess = pow ( max ( dot ( normalize( vHalfVector ), normal ), 0.0 ), 16.0 ) ;
-
- gl_FragColor = vec4( texture.rgb * uColor.rgb * visualMixColor.rgb * lightDiffuse + shininess * glossMap.rgb, texture.a * uColor.a * visualMixColor.a );\n
- }\n
-);
-
} // unnamed namespace
MeshVisualPtr MeshVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
void MeshVisual::SupplyEmptyGeometry()
{
mGeometry = Geometry::New();
- mShader = Shader::New( SIMPLE_VERTEX_SHADER, SIMPLE_FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_MESH_VISUAL_SIMPLE_SHADER_VERT, SHADER_MESH_VISUAL_SIMPLE_SHADER_FRAG );
mImpl->mRenderer = Renderer::New( mGeometry, mShader );
DALI_LOG_ERROR( "Initialisation error in mesh visual.\n" );
{
if( mShadingMode == Toolkit::MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING )
{
- mShader = Shader::New( NORMAL_MAP_VERTEX_SHADER, NORMAL_MAP_FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_MESH_VISUAL_NORMAL_MAP_SHADER_VERT, SHADER_MESH_VISUAL_NORMAL_MAP_SHADER_FRAG );
}
else if( mShadingMode == Toolkit::MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING )
{
- mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_MESH_VISUAL_SHADER_VERT, SHADER_MESH_VISUAL_SHADER_FRAG );
}
else //Textureless
{
- mShader = Shader::New( SIMPLE_VERTEX_SHADER, SIMPLE_FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_MESH_VISUAL_SIMPLE_SHADER_VERT, SHADER_MESH_VISUAL_SIMPLE_SHADER_FRAG );
}
UpdateShaderUniforms();
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
#include <dali-toolkit/internal/visuals/rendering-addon.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
namespace
{
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec2 vMaskTexCoord;\n
- uniform highp mat4 uMvpMatrix;\n
- uniform highp vec3 uSize;\n
- uniform mediump vec2 uNinePatchFactorsX[ FACTOR_SIZE_X ];\n
- uniform mediump vec2 uNinePatchFactorsY[ FACTOR_SIZE_Y ];\n
- \n
-
- // Visual size and offset
- uniform mediump vec2 offset;\n
- uniform highp vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
- uniform mediump vec2 extraSize;\n
-
- void main()\n
- {\n
- mediump vec2 fixedFactor = vec2( uNinePatchFactorsX[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uNinePatchFactorsY[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].x );\n
- mediump vec2 stretch = vec2( uNinePatchFactorsX[ int( ( aPosition.x ) * 0.5 ) ].y, uNinePatchFactorsY[ int( ( aPosition.y ) * 0.5 ) ].y );\n
- \n
- mediump vec2 fixedTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].x, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].x );\n
- mediump vec2 stretchTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].y, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].y );\n
- \n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n
- vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
- \n
- mediump vec4 gridPosition = vec4( fixedFactor + ( visualSize.xy - fixedTotal ) * stretch / stretchTotal, 0.0, 1.0 );\n
- mediump vec4 vertexPosition = gridPosition;\n
- vertexPosition.xy -= visualSize.xy * vec2( 0.5, 0.5 );\n
- vertexPosition.xy += anchorPoint*visualSize + (visualOffset + origin)*uSize.xy;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
- \n
- vTexCoord = ( fixedFactor + stretch ) / ( fixedTotal + stretchTotal );\n
- vMaskTexCoord = gridPosition.xy / visualSize;\n
- \n
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* VERTEX_SHADER_3X3 = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec2 vMaskTexCoord;\n
- uniform highp mat4 uMvpMatrix;\n
- uniform highp vec3 uSize;\n
- uniform mediump vec2 uFixed[ 3 ];\n
- uniform mediump vec2 uStretchTotal;\n
- \n
- //Visual size and offset
- uniform mediump vec2 offset;\n
- uniform highp vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
- uniform mediump vec2 extraSize;\n
- \n
- void main()\n
- {\n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n
- vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
- \n
- mediump vec2 size = visualSize.xy;\n
- \n
- mediump vec2 fixedFactor = vec2( uFixed[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uFixed[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].y );\n
- mediump vec2 stretch = floor( aPosition * 0.5 );\n
- mediump vec2 fixedTotal = uFixed[ 2 ];\n
- \n
- mediump vec4 gridPosition = vec4( fixedFactor + ( size - fixedTotal ) * stretch, 0.0, 1.0 );\n
- mediump vec4 vertexPosition = gridPosition;\n
- vertexPosition.xy -= size * vec2( 0.5, 0.5 );\n
- vertexPosition.xy += anchorPoint*size + (visualOffset + origin)*uSize.xy;\n
- \n
- vertexPosition = uMvpMatrix * vertexPosition;\n
- \n
- vTexCoord = ( fixedFactor + stretch * uStretchTotal ) / ( fixedTotal + uStretchTotal );\n
- \n
- vMaskTexCoord = gridPosition.xy / size;\n
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- uniform lowp float preMultipliedAlpha;\n
- \n
- void main()\n
- {\n
- gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n
- }\n
-);
-
-const char* FRAGMENT_MASK_SHADER = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- varying mediump vec2 vMaskTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform sampler2D sMask;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- uniform lowp float preMultipliedAlpha;\n
- uniform mediump float auxiliaryImageAlpha;\n
- \n
- void main()\n
- {\n
- // Where mask image is transparent, all of background image must show through.
- // where mask image is opaque, only mask should be shown
- // where mask is translucent, less of background should be shown.
- // auxiliaryImageAlpha controls how much of mask is visible
-
- mediump vec4 color = texture2D( sTexture, vTexCoord );\n
- mediump vec4 mask = texture2D( sMask, vMaskTexCoord );\n
-
- mediump vec3 mixedColor = color.rgb * mix( 1.0-mask.a, 1.0, 1.0-auxiliaryImageAlpha)
- + mask.rgb*mask.a * auxiliaryImageAlpha;\n
- gl_FragColor = vec4(mixedColor,1.0) * uColor * vec4( mixColor, 1.0 );\n
- }\n
-);
/**
* @brief Creates the geometry formed from the vertices and indices
NPatchUtility::StretchRanges::SizeType xStretchCount = 0;
NPatchUtility::StretchRanges::SizeType yStretchCount = 0;
- auto fragmentShader = mAuxiliaryPixelBuffer ? FRAGMENT_MASK_SHADER
- : FRAGMENT_SHADER;
+ auto fragmentShader = mAuxiliaryPixelBuffer ? SHADER_NPATCH_VISUAL_MASK_SHADER_FRAG
+ : SHADER_NPATCH_VISUAL_SHADER_FRAG;
auto shaderType = mAuxiliaryPixelBuffer ? VisualFactoryCache::NINE_PATCH_MASK_SHADER
: VisualFactoryCache::NINE_PATCH_SHADER;
shader = mFactoryCache.GetShader( shaderType );
if( DALI_UNLIKELY( !shader ) )
{
- shader = Shader::New( VERTEX_SHADER_3X3, fragmentShader );
+ shader = Shader::New( SHADER_NPATCH_VISUAL_3X3_SHADER_VERT, fragmentShader );
// Only cache vanilla 9 patch shaders
mFactoryCache.SaveShader( shaderType, shader );
}
std::stringstream vertexShader;
vertexShader << "#define FACTOR_SIZE_X " << xStretchCount + 2 << "\n"
<< "#define FACTOR_SIZE_Y " << yStretchCount + 2 << "\n"
- << VERTEX_SHADER;
+ << SHADER_NPATCH_VISUAL_SHADER_VERT;
shader = Shader::New( vertexShader.str(), fragmentShader );
}
if( ( xStretchCount == 1 && yStretchCount == 1 ) ||
( xStretchCount == 0 && yStretchCount == 0 ) )
{
- const char* vertexShader = VERTEX_SHADER_3X3;
+ const char* vertexShader = SHADER_NPATCH_VISUAL_3X3_SHADER_VERT.data();
if( !mImpl->mCustomShader->mVertexShader.empty() )
{
std::stringstream vertexShader;
vertexShader << "#define FACTOR_SIZE_X " << xStretchCount + 2 << "\n"
<< "#define FACTOR_SIZE_Y " << yStretchCount + 2 << "\n"
- << VERTEX_SHADER;
+ << SHADER_NPATCH_VISUAL_SHADER_VERT;
shader = Shader::New( vertexShader.str(), fragmentShader, hints );
}
#include <dali-toolkit/public-api/visuals/visual-properties.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
const char * const NORMAL( "aNormal" );
const char * const INDICES( "aIndices" );
-//A simple shader that applies diffuse lighting to a mono-coloured object.
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute highp vec3 aPosition;\n
- attribute highp vec2 aTexCoord;\n
- attribute highp vec3 aNormal;\n
- varying mediump vec3 vIllumination;\n
- uniform mediump vec3 uSize;\n
- uniform mediump vec3 uObjectDimensions;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump mat4 uModelView;\n
- uniform mediump mat4 uViewMatrix;\n
- uniform mediump mat3 uNormalMatrix;\n
- uniform mediump mat4 uObjectMatrix;\n
- uniform mediump vec3 lightPosition;\n
- uniform mediump vec2 uStageOffset;\n
-
- //Visual size and offset
- uniform mediump vec2 offset;\n
- uniform mediump vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
-
- vec4 ComputeVertexPosition()\n
- {\n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
- float scaleFactor = min( visualSize.x / uObjectDimensions.x, visualSize.y / uObjectDimensions.y );\n
- vec3 originFlipY = vec3(origin.x, -origin.y, 0.0);
- vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
- vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);\n
-
- return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );\n
- }\n
-
- void main()\n
- {\n
- vec4 normalisedVertexPosition = ComputeVertexPosition();\n
- vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
-
- //Illumination in Model-View space - Transform attributes and uniforms\n
- vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n
- vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;\n
-
- vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n
- mvLightPosition = uViewMatrix * mvLightPosition;\n
- vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n
-
- float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );\n
- vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n
-
- gl_Position = vertexPosition;\n
- }\n
-);
-
-//Very simple fragment shader that merely applies the vertex shading to the color at each fragment.
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- varying mediump vec3 vIllumination;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- void main()\n
- {\n
- vec4 baseColor = vec4(mixColor, 1.0) * uColor;\n
- gl_FragColor = vec4( vIllumination.rgb * baseColor.rgb, baseColor.a );\n
- }\n
-);
-
} // unnamed namespace
PrimitiveVisualPtr PrimitiveVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
void PrimitiveVisual::CreateShader()
{
- mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_PRIMITIVE_VISUAL_SHADER_VERT, SHADER_PRIMITIVE_VISUAL_SHADER_FRAG );
UpdateShaderUniforms();
}
#include <dali-toolkit/internal/text/script-run.h>
#include <dali-toolkit/internal/text/text-enumerations-impl.h>
#include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
{
const Vector4 FULL_TEXTURE_RECT( 0.f, 0.f, 1.f, 1.f );
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- uniform highp mat4 uMvpMatrix;\n
- uniform highp vec3 uSize;\n
- uniform mediump vec4 pixelArea;\n
-
- varying mediump vec2 vTexCoord;\n
-
- //Visual size and offset
- uniform mediump vec2 offset;\n
- uniform highp vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
-
- vec4 ComputeVertexPosition()\n
- {\n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
- vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
- return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
- }\n
-
- void main()\n
- {\n
- gl_Position = uMvpMatrix * ComputeVertexPosition();\n
- vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );\n
- }\n
-);
-
-const char* FRAGMENT_SHADER_SINGLE_COLOR_TEXT = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uTextColorAnimatable;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- \n
- void main()\n
- {\n
- mediump float textTexture = texture2D( sTexture, vTexCoord ).r;\n
-
- // Set the color of the text to what it is animated to.
- gl_FragColor = uTextColorAnimatable * textTexture * uColor * vec4( mixColor, 1.0 );
- }\n
-);
-
-const char* FRAGMENT_SHADER_MULTI_COLOR_TEXT = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- \n
- void main()\n
- {\n
- mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n
-
- gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 );
- }\n
-);
-
-const char* FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform sampler2D sStyle;\n
- uniform lowp vec4 uTextColorAnimatable;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- \n
- void main()\n
- {\n
- mediump float textTexture = texture2D( sTexture, vTexCoord ).r;\n
- mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );\n
-
- // Draw the text as overlay above the style
- gl_FragColor = ( uTextColorAnimatable * textTexture + styleTexture * ( 1.0 - uTextColorAnimatable.a * textTexture ) ) * uColor * vec4( mixColor, 1.0 );\n
- }\n
-);
-
-const char* FRAGMENT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform sampler2D sStyle;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- \n
- void main()\n
- {\n
- mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n
- mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );\n
-
- // Draw the text as overlay above the style
- gl_FragColor = ( textTexture + styleTexture * ( 1.0 - textTexture.a ) ) * uColor * vec4( mixColor, 1.0 );\n
- }\n
-);
-
-const char* FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform sampler2D sMask;\n
- uniform lowp vec4 uTextColorAnimatable;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- \n
- void main()\n
- {\n
- mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n
- mediump float maskTexture = texture2D( sMask, vTexCoord ).r;\n
-
- // Set the color of non-transparent pixel in text to what it is animated to.
- // Markup text with multiple text colors are not animated (but can be supported later on if required).
- // Emoji color are not animated.
- mediump float vstep = step( 0.0001, textTexture.a );\n
- textTexture.rgb = mix( textTexture.rgb, uTextColorAnimatable.rgb, vstep * maskTexture );\n
-
- // Draw the text as overlay above the style
- gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 );\n
- }\n
-);
-
-const char* FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform sampler2D sStyle;\n
- uniform sampler2D sMask;\n
- uniform lowp float uHasMultipleTextColors;\n
- uniform lowp vec4 uTextColorAnimatable;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- \n
- void main()\n
- {\n
- mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n
- mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );\n
- mediump float maskTexture = texture2D( sMask, vTexCoord ).r;\n
-
- // Set the color of non-transparent pixel in text to what it is animated to.
- // Markup text with multiple text colors are not animated (but can be supported later on if required).
- // Emoji color are not animated.
- mediump float vstep = step( 0.0001, textTexture.a );\n
- textTexture.rgb = mix( textTexture.rgb, uTextColorAnimatable.rgb, vstep * maskTexture * ( 1.0 - uHasMultipleTextColors ) );\n
-
- // Draw the text as overlay above the style
- gl_FragColor = ( textTexture + styleTexture * ( 1.0 - textTexture.a ) ) * uColor * vec4( mixColor, 1.0 );\n
- }\n
-);
-
/**
* Return Property index for the given string key
* param[in] stringKey the string index key
shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT );
if( !shader )
{
- shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_MULTI_COLOR_TEXT );
+ shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_MULTI_COLOR_TEXT_SHADER_FRAG );
shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT, shader );
}
shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE );
if( !shader )
{
- shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE );
+ shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_MULTI_COLOR_TEXT_WITH_STYLE_SHADER_FRAG );
shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE, shader );
}
shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT );
if( !shader )
{
- shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_SINGLE_COLOR_TEXT );
+ shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_SINGLE_COLOR_TEXT_SHADER_FRAG );
shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT, shader );
}
shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE );
if( !shader )
{
- shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE );
+ shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_SINGLE_COLOR_TEXT_WITH_STYLE_SHADER_FRAG );
shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE, shader );
}
shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI );
if( !shader )
{
- shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI );
+ shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_SINGLE_COLOR_TEXT_WITH_EMOJI_SHADER_FRAG );
shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI, shader );
}
shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI );
if( !shader )
{
- shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI );
+ shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI_SHADER_FRAG );
shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI, shader );
}
mExternalTextures(),
mLifecycleObservers(),
mLoadQueue(),
- mBrokenImageUrl(""),
mCurrentTextureId( 0 ),
mQueueLoadFlag(false)
{
}
if( !pixelBuffer )
{
- // use broken image
- pixelBuffer = LoadImageFromFile( mBrokenImageUrl );
- PixelData pixelData;
- if( pixelBuffer )
- {
- pixelData = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
- }
- Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, pixelData.GetPixelFormat(),
- pixelData.GetWidth(), pixelData.GetHeight() );
- texture.Upload( pixelData );
- textureSet = TextureSet::New();
- textureSet.SetTexture( 0u, texture );
+ DALI_LOG_ERROR("TextureManager::LoadAnimatedImageTexture: Synchronous loading is failed\n");
}
else
{
}
if( !data )
{
- // use broken image
- Devel::PixelBuffer pixelBuffer = LoadImageFromFile( mBrokenImageUrl );
- if( pixelBuffer )
- {
- PreMultiply( pixelBuffer, preMultiplyOnLoad );
- data = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
- }
- Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, data.GetPixelFormat(),
- data.GetWidth(), data.GetHeight() );
- texture.Upload( data );
- textureSet = TextureSet::New();
- textureSet.SetTexture( 0u, texture );
+ DALI_LOG_ERROR("TextureManager::LoadTexture: Synchronous loading is failed\n");
}
else
{
mTextureManager.AsyncLoadComplete( mLoadingInfoContainer, id, pixelBuffer );
}
-void TextureManager::SetBrokenImageUrl(const std::string& brokenImageUrl)
-{
- mBrokenImageUrl = brokenImageUrl;
-}
-
Geometry TextureManager::GetRenderGeometry(TextureId textureId, uint32_t& frontElements, uint32_t& backElements )
{
return RenderingAddOn::Get().IsValid() ?
void RemoveObserver( TextureManager::LifecycleObserver& observer );
/**
- * @brief Set an image to be used when a visual has failed to correctly render
- * @param[in] brokenImageUrl The broken image url.
- */
- void SetBrokenImageUrl(const std::string& brokenImageUrl);
-
- /**
* @brief Returns the geometry associated with texture.
* @param[in] textureId Id of the texture
* @param[out] frontElements number of front elements
std::vector< ExternalTextureInfo > mExternalTextures; ///< Externally provided textures
Dali::Vector<LifecycleObserver*> mLifecycleObservers; ///< Lifecycle observers of texture manager
Dali::Vector<LoadQueueElement> mLoadQueue; ///< Queue of textures to load after NotifyObservers
- std::string mBrokenImageUrl; ///< Broken image url
TextureId mCurrentTextureId; ///< The current value used for the unique Texture Id generation
bool mQueueLoadFlag; ///< Flag that causes Load Textures to be queued.
};
}
mAtlasManager->SetBrokenImage( mBrokenImageUrl );
- mTextureManager.SetBrokenImageUrl( mBrokenImageUrl );
}
} // namespace Internal
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
{
const char * const POSITION_ATTRIBUTE_NAME("aPosition");
const char * const INDEX_NAME("indices");
-
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
-attribute mediump vec2 aPosition;\n
-uniform highp mat4 uMvpMatrix;\n
-uniform highp vec3 uSize;\n
-\n
-
-//Visual size and offset
-uniform mediump vec2 offset;\n
-uniform highp vec2 size;\n
-uniform mediump vec4 offsetSizeMode;\n
-uniform mediump vec2 origin;\n
-uniform mediump vec2 anchorPoint;\n
-
-vec4 ComputeVertexPosition()\n
-{\n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
- vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
- return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
-}\n
-
-void main()\n
-{\n
- gl_Position = uMvpMatrix * ComputeVertexPosition();\n
-}\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
-\n
-void main()\n
-{\n
- gl_FragColor = uColor * vec4( mixColor, 1.0 );\n
-}\n
-);
-
}
WireframeVisualPtr WireframeVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
Shader shader = mFactoryCache.GetShader( VisualFactoryCache::WIREFRAME_SHADER );
if( !shader )
{
- shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+ shader = Shader::New( SHADER_WIREFRAME_VISUAL_SHADER_VERT, SHADER_WIREFRAME_VISUAL_SHADER_FRAG );
mFactoryCache.SaveShader( VisualFactoryCache::WIREFRAME_SHADER, shader );
}
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
const unsigned int TOOLKIT_MAJOR_VERSION = 2;
const unsigned int TOOLKIT_MINOR_VERSION = 0;
-const unsigned int TOOLKIT_MICRO_VERSION = 9;
+const unsigned int TOOLKIT_MICRO_VERSION = 10;
const char* const TOOLKIT_BUILD_DATE = __DATE__ " " __TIME__;
#ifdef DEBUG_ENABLED
Name: dali2-toolkit
Summary: Dali 3D engine Toolkit
-Version: 2.0.9
+Version: 2.0.10
Release: 1
Group: System/Libraries
License: Apache-2.0 and BSD-3-Clause and MIT