1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 03:22:33 +01:00

Merge branch '71-create-a-shader-library-subproject' into 'master'

Resolve "Create a shader library subproject"

Closes #71

See merge request kelteseth/ScreenPlay!36
This commit is contained in:
Elias Steurer 2020-09-27 18:47:19 +00:00
commit c8529e4c9c
24 changed files with 600 additions and 10 deletions

View File

@ -31,11 +31,20 @@ build:windows:
- cd Common
- if (!(Test-Path "vcpkg")){git clone https://github.com/microsoft/vcpkg.git}
- cd vcpkg
- git pull | git checkout 18ab4b72a26284f0df28295ce7bf9b21c96f20f4
- call bootstrap-vcpkg.bat
- vcpkg.exe install openssl --triplet x64-windows --recurse
- git remote set-url origin https://github.com/microsoft/vcpkg.git
- git pull origin master
- git checkout 18ab4b72a26284f0df28295ce7bf9b21c96f20f4
- cmd /c bootstrap-vcpkg.bat
- ls
- cmd /c vcpkg.exe install openssl --triplet x64-windows --recurse
- cd ..
- cd ..
- curl.exe -L https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-4.3.1-2020-09-16-full_build.zip --output ffmpeg.zip
- tar -xvf ffmpeg.zip --strip-components 2 ffmpeg-4.3.1-full_build/bin
- if (!(Test-Path "Common/ffmpeg")){ mkdir Common/ffmpeg }
- cmd /c DEL ffplay.exe
- cmd /c move /Y ffmpeg.exe Common/ffmpeg
- cmd /c move /Y ffprobe.exe Common/ffmpeg
- mkdir BUILD_WINDOWS
- cd BUILD_WINDOWS
- cmake.exe ../ -DCMAKE_PREFIX_PATH=c:/Qt/5.15.1/msvc2019 -DCMAKE_IGNORE_PATH=C:/Strawberry/c/bin -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_TOOLCHAIN_FILE="$(Get-Location)/../Common/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows "-GCodeBlocks - Ninja" -B.

View File

@ -51,6 +51,7 @@ project(ScreenPlay)
add_subdirectory(ScreenPlay)
add_subdirectory(ScreenPlaySDK)
add_subdirectory(ScreenPlayShader)
add_subdirectory(ScreenPlayWallpaper)
add_subdirectory(ScreenPlayWidget)
add_subdirectory(ScreenPlaySysInfo)

View File

@ -9,6 +9,9 @@ import Qt.labs.platform 1.0
import ScreenPlay 1.0
import Settings 1.0
import ScreenPlay.Shader 1.0
import "ShaderWrapper" as ShaderWrapper
import "qml/"
import "qml/Monitors" as Monitors
import "qml/Common" as Common
@ -34,6 +37,8 @@ ApplicationWindow {
}
}
// Partial workaround for
// https://bugreports.qt.io/browse/QTBUG-86047
Material.accent: Material.color(Material.Orange)

View File

@ -57,7 +57,6 @@ Item {
icon.source: "qrc:/assets/icons/icon_supervisor_account.svg"
}
CommunityNavItem {
enabled: false
text: qsTr("Steam Workshop")
openLink: "steam://url/GameHub/672870"
icon.source: "qrc:/assets/icons/icon_steam.svg"

View File

@ -82,7 +82,7 @@ Item {
Button {
id: btnWorkshop
text: qsTr("Browse the Steam Workshop")
Material.background: Material.Blue
Material.background: Material.color(Material.Green)
Material.foreground: "white"
smooth: true
font.pointSize: 18

View File

@ -19,7 +19,7 @@ set(headers
inc/screenplay-sdk_plugin.h
inc/screenplaysdk.h)
add_library(${PROJECT_NAME} ${src} ${headers})
add_library(${PROJECT_NAME} ${src} ${headers})
target_link_libraries(${PROJECT_NAME}
PRIVATE

View File

@ -0,0 +1,66 @@
cmake_minimum_required(VERSION 3.17 )
project(ScreenPlayShader LANGUAGES CXX)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)
find_package(
Qt5
COMPONENTS Quick
Core
REQUIRED)
set(src
screenplayshader_plugin.cpp
shaderlibrary.cpp
)
set(headers
screenplayshader_plugin.h
shaderlibrary.h
)
set(shader shader.qrc)
add_library(${PROJECT_NAME} SHARED ${src} ${headers} ${shader})
target_link_libraries(${PROJECT_NAME}
PRIVATE
Qt5::Core
Qt5::Quick
Qt5::Gui)
target_include_directories(
${PROJECT_NAME}
PUBLIC inc
)
# QML module deployment
set(URI "ScreenPlay/Shader")
string(REPLACE "." "/" TARGETPATH ${URI})
if (NOT DEFINED QT_QMAKE_EXECUTABLE)
get_target_property (QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
if (NOT QT_QMAKE_EXECUTABLE)
message(FATAL_ERROR "Cannot find qmake")
endif()
endif()
execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_QML OUTPUT_VARIABLE QT_INSTALL_QML_RAW)
string(STRIP ${QT_INSTALL_QML_RAW} QT_INSTALL_QML)
set(DESTDIR "${QT_INSTALL_QML}/${TARGETPATH}")
message("DESTDIR ${DESTDIR}")
file(MAKE_DIRECTORY ${DESTDIR})
configure_file(qmldir ${DESTDIR} COPYONLY)
# Copies ScreenPlayShader.* into qt qml plugins folder
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:ScreenPlayShader>
${DESTDIR}/$<TARGET_FILE_NAME:ScreenPlayShader>)

View File

@ -0,0 +1,164 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
ShaderEffect {
id: root
// based on shadertoy default variables
readonly property vector3d iResolution: defaultResolution
readonly property vector3d defaultResolution: Qt.vector3d(
root.width, root.height,
root.width / root.height)
property real iTime: 0
property real iTimeDelta: 100
property int iFrame: 10
property real iFrameRate
property vector4d iMouse
//only Image or ShaderEffectSource
property var iChannel0: ich0
property var iChannel1: ich1
property var iChannel2: ich2
property var iChannel3: ich3
property var iChannelTime: [0, 1, 2, 3]
property var iChannelResolution: [calcResolution(iChannel0), calcResolution(
iChannel1), calcResolution(iChannel2), calcResolution(iChannel3)]
property vector4d iDate
property real iSampleRate: 44100
property bool hoverEnabled: false
property bool running: true
function restart() {
root.iTime = 0
running = true
timer1.restart()
}
function calcResolution(channel) {
if (channel) {
return Qt.vector3d(channel.width, channel.height,
channel.width / channel.height)
} else {
return defaultResolution
}
}
Image {
id: ich0
visible: false
}
Image {
id: ich1
visible: false
}
Image {
id: ich2
visible: false
}
Image {
id: ich3
visible: false
}
Timer {
id: timer1
running: root.running
triggeredOnStart: true
interval: 16
repeat: true
onTriggered: {
root.iTime += 0.016
}
}
Timer {
running: root.running
interval: 1000
property date currentDate: new Date()
onTriggered: {
currentDate = new Date()
root.iDate.x = currentDate.getFullYear()
root.iDate.y = currentDate.getMonth()
root.iDate.z = currentDate.getDay()
root.iDate.w = currentDate.getSeconds()
}
}
readonly property string gles2Ver: "
#define texture texture2D
precision mediump float;"
readonly property string gles3Ver: "#version 300 es
#define varying in
#define gl_FragColor fragColor
precision mediump float;
out vec4 fragColor;"
readonly property string gl3Ver: "
#version 150
#define varying in
#define gl_FragColor fragColor
#define lowp
#define mediump
#define highp
out vec4 fragColor;"
readonly property string gl3Ver_igpu: "
#version 130
#define varying in
#define gl_FragColor fragColor
#define lowp
#define mediump
#define highp
out vec4 fragColor;"
readonly property string gl2Ver: "
#version 110
#define texture texture2D"
property string versionString: (GraphicsInfo.majorVersion === 3
|| GraphicsInfo.majorVersion === 4) ? gl3Ver : gl2Ver
vertexShader: "
uniform mat4 qt_Matrix;
attribute vec4 qt_Vertex;
attribute vec2 qt_MultiTexCoord0;
varying vec2 qt_TexCoord0;
varying vec4 vertex;
void main() {
vertex = qt_Vertex;
gl_Position = qt_Matrix * vertex;
qt_TexCoord0 = qt_MultiTexCoord0;
}"
readonly property string forwardString: versionString + "
varying vec2 qt_TexCoord0;
varying vec4 vertex;
uniform lowp float qt_Opacity;
uniform vec3 iResolution;
uniform float iTime;
uniform float iTimeDelta;
uniform int iFrame;
uniform float iFrameRate;
uniform float iChannelTime[4];
uniform vec3 iChannelResolution[4];
uniform vec4 iMouse;
uniform vec4 iDate;
uniform float iSampleRate;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;
uniform sampler2D iChannel3;"
readonly property string startCode: "
void main(void)
{
mainImage(gl_FragColor, vec2(vertex.x, iResolution.y - vertex.y));
}"
property bool runShader: true
property string pixelShader
onPixelShaderChanged: root.fragmentShader = forwardString + pixelShader + startCode
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 761 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -0,0 +1,84 @@
#ifdef GL_ES
precision mediump float;
#endif
uniform float time;
uniform vec2 resolution;
float hash( float n ) { return fract(sin(n)*753.5453123); }
// Slight modification of iq's noise function.
float noise( in vec2 x )
{
vec2 p = floor(x);
vec2 f = fract(x);
f = f*f*(3.0-2.0*f);
float n = p.x + p.y*157.0;
return mix(
mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
mix( hash(n+157.0), hash(n+158.0),f.x),
f.y);
}
float fbm(vec2 p, vec3 a)
{
float v = 0.0;
v += noise(p*a.x)*1.20;
v += noise(p*a.y)*1.20;
v += noise(p*a.z)*.125;
return v;
}
vec3 drawLines( vec2 uv, vec3 fbmOffset, vec3 color1, vec3 color2 )
{
float timeVal = time * 0.1;
vec3 finalColor = vec3( 0.0 );
for( int i=0; i < 3; ++i )
{
float indexAsFloat = float(i);
float amp = 40.0 + (indexAsFloat*10.0);
float period = 2.0 + (indexAsFloat+2.0);
float thickness = mix( 0.9, 1.0, noise(uv*10.0) );
float t = abs( 0.9 / (sin(uv.x + fbm( uv + timeVal * period, fbmOffset )) * amp) * thickness );
finalColor += t * color1;
}
for( int i=0; i < 0; ++i )
{
float indexAsFloat = float(i);
float amp = 40.0 + (indexAsFloat*7.0);
float period = 2.0 + (indexAsFloat+8.0);
float thickness = mix( 0.7, 1.0, noise(uv*10.0) );
float t = abs( 0.8 / (sin(uv.x + fbm( uv + timeVal * period, fbmOffset )) * amp) * thickness );
finalColor += t * color2 * 0.6;
}
return finalColor;
}
void main( void )
{
vec2 uv = ( gl_FragCoord.xy / resolution.xy ) * 1.0 - 1.8;
uv.x *= resolution.x/resolution.y;
uv.xy = uv.yx;
vec3 lineColor1 = vec3( 2.3, 0.5, .5 );
vec3 lineColor2 = vec3( 0.3, 0.5, 2.5 );
vec3 finalColor = vec3(0.0);
float t = sin( time ) * 0.5 + 0.5;
float pulse = mix( 0.10, 0.20, t);
finalColor += drawLines( uv, vec3( 1.0, 1.0, 8.0), lineColor2, lineColor2 );
gl_FragColor = vec4( finalColor, 1.0 );
}

View File

@ -0,0 +1,9 @@
uniform highp mat4 qt_Matrix;
attribute highp vec4 qt_Vertex;
attribute highp vec2 qt_MultiTexCoord0;
varying highp vec2 coord;
void main() {
coord = qt_MultiTexCoord0;
gl_Position = qt_Matrix * qt_Vertex;
}

2
ScreenPlayShader/qmldir Normal file
View File

@ -0,0 +1,2 @@
module ScreenPlay.Shader
plugin ScreenPlayShader

View File

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

View File

@ -0,0 +1,15 @@
#pragma once
#include <QQmlExtensionPlugin>
#include "shaderlibrary.h"
class ScreenPlayShaderPlugin : public QQmlExtensionPlugin {
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
public:
void registerTypes(const char* uri) override;
private:
ShaderLibrary m_shaderLibrary;
};

View File

@ -0,0 +1,14 @@
<RCC>
<qresource prefix="/">
<file>lightning.frag</file>
<file>lightning.vert</file>
<file>water.frag</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>
</qresource>
<qresource prefix="/ShaderWrapper">
<file>ShadertoyShader.qml</file>
</qresource>
</RCC>

View File

@ -0,0 +1,22 @@
#include "shaderlibrary.h"
ShaderLibrary::ShaderLibrary(QQuickItem* parent)
: QQuickItem(parent)
{
QFile lightningFragFile(":/lightning.frag");
lightningFragFile.open(QIODevice::ReadOnly);
QFile lightningVertFile(":/lightning.vert");
lightningVertFile.open(QIODevice::ReadOnly);
m_lightning = std::make_unique<Shader>(lightningVertFile.readAll(), lightningFragFile.readAll());
QFile waterFragFile(":/water.frag");
waterFragFile.open(QIODevice::ReadOnly);
QFile waterVertFile(":/water.vert");
waterVertFile.open(QIODevice::ReadOnly);
m_water = std::make_unique<Shader>(waterVertFile.readAll(), waterFragFile.readAll());
}
ShaderLibrary::~ShaderLibrary()
{
}

View File

@ -0,0 +1,108 @@
#pragma once
#include <QObject>
#include <QQuickItem>
#include <QString>
#include <memory>
class Shader : public QObject {
Q_OBJECT
Q_PROPERTY(QString vertex READ vertex WRITE setVertex NOTIFY vertexChanged)
Q_PROPERTY(QString fragment READ fragment WRITE setFragment NOTIFY fragmentChanged)
public:
Shader() { }
Shader(const QString& vertex, const QString& fragment)
{
m_vertex = vertex;
m_fragment = fragment;
}
QString vertex() const
{
return m_vertex;
}
QString fragment() const
{
return m_fragment;
}
public slots:
void setVertex(QString vertex)
{
if (m_vertex == vertex)
return;
m_vertex = vertex;
emit vertexChanged(m_vertex);
}
void setFragment(QString fragment)
{
if (m_fragment == fragment)
return;
m_fragment = fragment;
emit fragmentChanged(m_fragment);
}
signals:
void vertexChanged(QString vertex);
void fragmentChanged(QString fragment);
private:
QString m_vertex;
QString m_fragment;
};
class ShaderLibrary : public QQuickItem {
Q_OBJECT
Q_DISABLE_COPY(ShaderLibrary)
Q_PROPERTY(Shader* lightning READ lightning WRITE setLightning NOTIFY lightningChanged)
Q_PROPERTY(Shader* water READ water WRITE setWater NOTIFY waterChanged)
public:
explicit ShaderLibrary(QQuickItem* parent = nullptr);
~ShaderLibrary() override;
Shader* lightning() const
{
return m_lightning.get();
}
Shader* water() const
{
return m_water.get();
}
public slots:
void setLightning(Shader* lightning)
{
if (m_lightning.get() == lightning)
return;
m_lightning.reset(lightning);
emit lightningChanged(m_lightning.get());
}
void setWater(Shader* water)
{
if (m_water.get() == water)
return;
m_water.reset(water);
emit waterChanged(m_water.get());
}
signals:
void lightningChanged(Shader* lightning);
void waterChanged(Shader* water);
private:
std::unique_ptr<Shader> m_lightning;
std::unique_ptr<Shader> m_water;
};

View File

@ -0,0 +1,59 @@
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D qt_Texture0;
varying vec4 qt_TexCoord0;
//uniform float reflectionOffset; // allows player to control reflection position
//uniform float reflectionBlur ; // works only if projec's driver is set to GLES3, more information here https://docs.godotengine.org/ru/stable/tutorials/shading/screen-reading_shaders.html
//uniform float calculatedOffset ; // this is controlled by script, it takes into account camera position and water object position, that way reflection stays in the same place when camera is moving
//uniform float calculatedAspect ; // is controlled by script, ensures that noise is not affected by object scale
//uniform sampler2D noiseTexture;
//uniform float offsetStrength;
//uniform float maxOffset;
//uniform vec2 distortionScale;
//uniform vec2 distortionSpeed;
//uniform float waveSmoothing;
//uniform float mainWaveSpeed ;
//uniform float mainWaveFrequency ;
//uniform float mainWaveAmplitude;
//uniform float secondWaveSpeed ;
//uniform float secondWaveFrequency ;
//uniform float secondWaveAmplitude ;
//uniform float thirdWaveSpeed ;
//uniform float thirdWaveFrequency ;
//uniform float thirdWaveAmplitude ;
//uniform float squashing ;
//uniform vec4 shorelineColor; //: hint_color = vec4(1.);
//uniform float shorelineSize; //: hint_range(0., 0.1) = 0.0025;
//uniform float shorelineFoamSize ; // : hint_range(0., 0.1)
//uniform float foamSpeed;
//uniform vec2 foamScale;
uniform float time;
void main(void)
{
vec2 uv = fragCoord.xy / iResolution.xy;
vec4 texture_color = vec4(0.192156862745098, 0.6627450980392157, 0.9333333333333333, 1.0);
vec4 k = vec4(time)*0.8;
k.xy = uv * 7.0;
float val1 = length(0.5-fract(k.xyw*=mat3(vec3(-2.0,-1.0,0.0), vec3(3.0,-1.0,1.0), vec3(1.0,-1.0,-1.0))*0.5));
float val2 = length(0.5-fract(k.xyw*=mat3(vec3(-2.0,-1.0,0.0), vec3(3.0,-1.0,1.0), vec3(1.0,-1.0,-1.0))*0.2));
float val3 = length(0.5-fract(k.xyw*=mat3(vec3(-2.0,-1.0,0.0), vec3(3.0,-1.0,1.0), vec3(1.0,-1.0,-1.0))*0.5));
vec4 color = vec4 ( pow(min(min(val1,val2),val3), 7.0) * 3.0)+texture_color;
gl_FragColor = color;
//gl_FragColor = texture2D(qt_Texture0, qt_TexCoord0.st);
}

View File

@ -0,0 +1,10 @@
attribute vec4 qt_Vertex;
attribute vec4 qt_MultiTexCoord0;
uniform mat4 qt_ModelViewProjectionMatrix;
varying vec4 qt_TexCoord0;
void main(void)
{
gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;
qt_TexCoord0 = qt_MultiTexCoord0;
}

View File

@ -1,6 +1,9 @@
import QtQuick 2.14
import QtQml 2.14
import ScreenPlayWallpaper 1.0
import ScreenPlay.Shader 1.0
import "ShaderWrapper" as ShaderWrapper
Rectangle {
id: root
@ -218,4 +221,5 @@ Rectangle {
}
}
}
}

View File

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

View File

@ -15,7 +15,7 @@ cd ..
cd ..
rem Donwload ffmpeg
curl.exe -L --ssl-no-revoke https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-4.3.1-full_build.zip --output ffmpeg.zip
curl.exe -L https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-4.3.1-2020-09-16-full_build.zip --output ffmpeg.zip
rem Extract ffmpeg. Needs Windows 10 build 17063 or higher!
rem We only need the content of the bin folder