1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-25 12:13:00 +01:00

Add shadertoy shader

This commit is contained in:
Elias Steurer 2020-09-24 19:08:06 +02:00
parent 6d7389833d
commit 0fa55884ac
5 changed files with 18 additions and 16 deletions

View File

@ -3,12 +3,10 @@ import QtQuick.Controls 2.12
ShaderEffect { ShaderEffect {
id: root id: root
property real speed: 1 property real speed: 1
readonly property vector3d defaultResolution: Qt.vector3d( readonly property vector3d defaultResolution: Qt.vector3d(
root.width, root.width, root.height,
root.height,
root.width / root.height) root.width / root.height)
function calcResolution(channel) { function calcResolution(channel) {
if (channel) { if (channel) {
@ -19,7 +17,7 @@ ShaderEffect {
} }
} }
// based on shadertoy default vartiables // based on shadertoy default variables
readonly property vector3d iResolution: defaultResolution readonly property vector3d iResolution: defaultResolution
property real iTime: 0 property real iTime: 0
property real iTimeDelta: 100 property real iTimeDelta: 100
@ -119,7 +117,8 @@ out vec4 fragColor;"
#version 110 #version 110
#define texture texture2D" #define texture texture2D"
property string versionString: GraphicsInfo.majorVersion === 3 ? "gl3Ver" : "gl2Ver" property string versionString: (GraphicsInfo.majorVersion === 3
|| GraphicsInfo.majorVersion === 4) ? gl3Ver : gl2Ver
vertexShader: " vertexShader: "
uniform mat4 qt_Matrix; uniform mat4 qt_Matrix;
@ -165,6 +164,6 @@ fragColor = vec4(fragCoord, fragCoord.x, fragCoord.y);
}" }"
property bool runShader: true property bool runShader: true
property string pixelShader: "" property string pixelShader
fragmentShader: forwardString + (pixelShader ? pixelShader : defaultPixelShader) + startCode onPixelShaderChanged: root.fragmentShader = forwardString + pixelShader + startCode
} }

View File

@ -1,19 +1,18 @@
#include "screenplayshader_plugin.h" #include "screenplayshader_plugin.h"
#include <qqml.h>
#include <QQmlEngine> #include <QQmlEngine>
#include <QUrl>
#include <qqml.h>
QObject* ScreenPlayShaderLibrarySingleton(QQmlEngine* engine, QJSEngine* scriptEngine) QObject* ScreenPlayShaderLibrarySingleton(QQmlEngine* engine, QJSEngine* scriptEngine)
{ {
Q_UNUSED(scriptEngine) Q_UNUSED(scriptEngine)
//Add QRC
// engine->addImportPath("qrc:/ShaderWrapper/");
// engine->addImportPath("..");
return new ShaderLibrary(); return new ShaderLibrary();
} }
void ScreenPlayShaderPlugin::registerTypes(const char* uri) void ScreenPlayShaderPlugin::registerTypes(const char* uri)
{ {
qmlRegisterType(QUrl("qrc:/ShaderWrapper/ShadertoyShader.qml"), "ScreenPlay.ShadertoyShader", 1,0, "ShadertoyShader");
qmlRegisterSingletonType<ShaderLibrary>(uri, 1, 0, "ShaderLibrary", ScreenPlayShaderLibrarySingleton); qmlRegisterSingletonType<ShaderLibrary>(uri, 1, 0, "ShaderLibrary", ScreenPlayShaderLibrarySingleton);
} }

View File

@ -4,9 +4,12 @@
<file>lightning.vert</file> <file>lightning.vert</file>
<file>water.frag</file> <file>water.frag</file>
<file>water.vert</file> <file>water.vert</file>
<file>assets/Shadertoy_Bayer.png</file>
<file>assets/Shadertoy_Gray_Noise_Medium.png</file>
<file>assets/Shadertoy_Lichen.jpg</file>
<file>Noise_Watery.frag</file>
</qresource> </qresource>
<qresource prefix="/ShaderWrapper"> <qresource prefix="/ShaderWrapper">
<file>ScreenPlayShader.qml</file> <file>ShadertoyShader.qml</file>
<file>Testyyy.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -28,8 +28,7 @@ BaseWindow::BaseWindow(QString projectFilePath, const QVector<int> activeScreens
QJsonDocument configJsonDocument; QJsonDocument configJsonDocument;
QJsonParseError parseError; QJsonParseError parseError;
if (projectFilePath.contains("file:\\\\\\"))
projectFilePath = projectFilePath.remove("file:\\\\\\");
projectFile.setFileName(projectFilePath + "/project.json"); projectFile.setFileName(projectFilePath + "/project.json");
projectFile.open(QIODevice::ReadOnly | QIODevice::Text); projectFile.open(QIODevice::ReadOnly | QIODevice::Text);
@ -64,7 +63,7 @@ BaseWindow::BaseWindow(QString projectFilePath, const QVector<int> activeScreens
qFatal("No type was specified inside the json object!"); qFatal("No type was specified inside the json object!");
} }
setBasePath(projectFilePath); setBasePath(QUrl::fromUserInput(projectFilePath).toLocalFile());
setFullContentPath("file:///" + projectFilePath + "/" + projectObject.value("file").toString()); setFullContentPath("file:///" + projectFilePath + "/" + projectObject.value("file").toString());
auto reloadQMLLambda = [this]() { emit reloadQML(type()); }; auto reloadQMLLambda = [this]() { emit reloadQML(type()); };
@ -166,9 +165,11 @@ QString BaseWindow::loadFromFile(const QString& filename)
{ {
QFile file; QFile file;
file.setFileName(basePath() + "/" + filename); file.setFileName(basePath() + "/" + filename);
qWarning() << " loadFromFile: " << file.fileName() << file.readAll();
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
return file.readAll(); return file.readAll();
} }
qWarning() << "Could not loadFromFile: " << file.fileName();
return ""; return "";
} }