Skip to content

Commit

Permalink
Load visual effects in ~/.config/panon/
Browse files Browse the repository at this point in the history
  • Loading branch information
rbn42 committed Jan 11, 2020
1 parent bb9b885 commit f2618b4
Show file tree
Hide file tree
Showing 23 changed files with 306 additions and 216 deletions.
28 changes: 14 additions & 14 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,20 @@ kpackagetool5 -t Plasma/Applet --upgrade plasmoid
*** Via AUR
[[https://aur.archlinux.org/packages/plasma5-applets-panon/][plasma5-applets-panon]] and [[https://aur.archlinux.org/packages/plasma5-applets-panon-git/][plasma5-applets-panon-git]] are available for ArchLinux.

If you want to modify shaders, installing panon as a system package is not a preferred solution right now, because then the modification will require write permission in =/usr/share/plasma/plasmoids/panon=.

*** Drag panon widget to your panel (eg. [[https://github.com/psifidotos/Latte-Dock][latte-dock]]).
[[file:../../wiki/plasmoid/step1.png]]
[[file:../../wiki/plasmoid/step2.png]]

** Visual Effects

Visual effects are stored in [[kde/plasmoid/contents/shaders/]]. Providing panon is installed in your home directory, it is the same directory of =~/.local/share/plasma/plasmoids/panon/contents/shaders/=. You can add your own visual effect to this directory.
Visual effects are stored in [[kde/plasmoid/contents/shaders/]]. You can create your own visual effects in =~/.config/panon/=.

A visual effect may consist a single main shader file with its name ended with =.frag=, like [[kde/plasmoid/contents/shaders/solid.frag][solid.frag]], or a folder, like [[file:kde/plasmoid/contents/shaders/spectrogram][spectrogram/]], with the following struture.
A visual effect consists of a single main shader file with its name ended with =.frag=, like [[kde/plasmoid/contents/shaders/solid.frag][solid.frag]], or a folder, like [[file:kde/plasmoid/contents/shaders/spectrogram][spectrogram/]], with the following struture.
- effect folder
- image.frag, is the main shader file, must exist.
- image.frag, is the main shader file, must exist.
- buffer.frag, draws to the buffer, is optional.
- hint.html, shows hints to the user, is optional.
- [[#arguments][arguments.json]], declares the arguments for the user, is optional.
- [[#arguments][meta.json]], declares the arguments for the user, is optional.

*** Shader API and Shadertoy.com

Expand All @@ -106,12 +104,14 @@ These shadertoy-like uniforms are provided.
Both =image.frag= (or the single main shader) and =buffer.frag= can access these uniforms.

*** Arguments
arguments.json contains a JSON list of elements like this.
meta.json contains a JSON list like this.
#+BEGIN_SRC js
{
"name":"arg_name",
"default":1,
"type":"int"
"arguments":[{
"name":"arg_name",
"default":1,
"type":"int"
}]
}
#+END_SRC
"type" can be "int", "double" or "bool". A decalred argument can be used in a shader file's macros, like
Expand All @@ -124,15 +124,15 @@ Which will be translated into
#+END_SRC
*** Debugging Shaders

Neither KDE Panel nor Latte-Dock shows the errors caused by the shaders. To catch the error messages, =plasma-sdk= is required. To debug your shader, you must put your shader file in [[kde/plasmoid/contents/shaders/]], and then start plasmoidviewer in a console.
Neither KDE Panel nor Latte-Dock shows the errors caused by the shaders. To catch the error messages, you have install =plasma-sdk=, and start plasmoidviewer in a console.

#+BEGIN_SRC sh
cd ./kde/
#Providing plasma-sdk is installed
plasmoidviewer --applet ./plasmoid/
#+END_SRC
In plasmoidviewer, go to the configuration window and pick your own shader.
Then plasmoidviewer will run your shader and show the errors, if exist, in the console.
In plasmoidviewer, go to the configuration window and choose your own visual effect.
Then plasmoidviewer will run your visual effect and show the errors, if exist, in the console.

** Background transparency
To achieve background transparency, after installing panon, go to ~/.local/share/plasma/plasmoids/panon/contents/ui/main.qml in your home directory,
Expand All @@ -151,4 +151,4 @@ alter the following part and add the line marked below:
| =hsv2rgb= in [[file:kde/plasmoid/contents/shaders/utils.fsh][utils.fsh]] | copied from [[https://gist.github.com/patriciogonzalezvivo/114c1653de9e3da6e1e3][GLSL-color.md]] | |
| [[file:kde/plasmoid/contents/shaders/example-shadertoy.frag][example-shadertoy.frag]] | copied from [[https://www.shadertoy.com/view/lldyDs][shadertoy]] | [[https://www.shadertoy.com/terms][CC BY-NC-SA 3.0]] |
| [[file:kde/plasmoid/contents/shaders/firefly/image.frag][firefly/image.frag]] | adapted from [[https://www.shadertoy.com/view/lldyDs][shadertoy]] | [[https://www.shadertoy.com/terms][CC BY-NC-SA 3.0]] |
| [[file:kde/plasmoid/contents/shaders/example-shadertoy-fractal-tiling.frag][example-shadertoy-fractal-tiling.frag]] | copied from [[example-shadertoy-fractal-tiling.frag][shadertoy]] | [[https://www.shadertoy.com/terms][CC BY-NC-SA 3.0]] |
| [[file:kde/plasmoid/contents/shaders/example-shadertoy-fractal-tiling.frag][example-shadertoy-fractal-tiling.frag]] | copied from [[https://www.shadertoy.com/view/Ml2GWy][shadertoy]] | [[https://www.shadertoy.com/terms][CC BY-NC-SA 3.0]] |
16 changes: 0 additions & 16 deletions kde/CMakeLists.txt

This file was deleted.

122 changes: 122 additions & 0 deletions kde/plasmoid/contents/scripts/build_shader_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
"""
panon client
Usage:
freetile [options] [<effect-arguments>...]
freetile -h | --help
Options:
-h --help Show this screen.
--random-effect
--effect-name=N
--debug Debug
"""
from docopt import docopt
import sys
import json
import os.path

from helper import config_effect_home, applet_effect_home, read_file, read_file_lines

arguments = docopt(__doc__)
effect_name = arguments['--effect-name']
effect_arguments = arguments['<effect-arguments>']
if arguments['--random-effect']:
import random
import get_effect_list
effect_list = get_effect_list.get_list()
effect_name = random.choice(effect_list)
effect_arguments = []

if effect_name.endswith(' '):
effect_name = effect_name[:-1]
effect_home = config_effect_home
else:
effect_home = applet_effect_home


def value2str(value):
t=type(value)
if t==int:
return str(value)
elif t==float:
return str(value)
elif t==bool:
return 'true' if value else 'false'

def build_source(files, main_file, meta_file=None, effect_arguments=None):
if not os.path.exists(main_file):
return ''
arguments_map = {}
if meta_file is not None:
if os.path.exists(meta_file):
meta = json.load(open(meta_file, 'rb'))
meta_arg = meta['arguments']
arguments_map = {arg['name']: arg['default'] for arg in meta_arg}
if len(effect_arguments) > 0:
for i in range(len(meta_arg)):
value=effect_arguments[i]
if meta_arg[i]['type']=='double':
value=float(value)
elif meta_arg[i]['type']=='int':
value=int(value)
elif meta_arg[i]['type']=='bool':
value=(value=='true')
arguments_map[meta_arg[i]['name']] = value

version = next(read_file_lines(main_file))
source = version
for path in files:
if path == main_file:
for line in list(read_file_lines(path))[1:]:
lst = line.split()
if len(lst) >= 3:
if lst[2].startswith('$'):
lst[2] = value2str(arguments_map[lst[2][1:]])
line = ' '.join(lst) + '\n'
source += line
else:
source += read_file(path)
return source


if effect_name.endswith('.frag'):
obj = {
'image_shader':
build_source([
os.path.join(applet_effect_home, 'hsluv-glsl.fsh'),
os.path.join(applet_effect_home, 'utils.fsh'),
os.path.join(applet_effect_home, 'shadertoy-api-head.fsh'),
os.path.join(effect_home, effect_name),
os.path.join(applet_effect_home, 'shadertoy-api-foot.fsh'),
], os.path.join(effect_home, effect_name))
}
json.dump(obj, sys.stdout)
elif effect_name.endswith('/'):
obj = {
'image_shader':
build_source(
[
os.path.join(applet_effect_home, 'hsluv-glsl.fsh'),
os.path.join(applet_effect_home, 'utils.fsh'),
os.path.join(applet_effect_home, 'shadertoy-api-head.fsh'),
os.path.join(effect_home, effect_name, 'image.frag'),
os.path.join(applet_effect_home, 'shadertoy-api-foot.fsh'),
],
os.path.join(effect_home, effect_name, 'image.frag'),
os.path.join(effect_home, effect_name, 'meta.json'),
effect_arguments,
),
'buffer_shader':
build_source(
[
os.path.join(applet_effect_home, 'shadertoy-api-head.fsh'),
os.path.join(effect_home, effect_name, 'buffer.frag'),
os.path.join(applet_effect_home, 'shadertoy-api-foot-buffer.fsh'),
],
os.path.join(effect_home, effect_name, 'buffer.frag'),
os.path.join(effect_home, effect_name, 'meta.json'),
effect_arguments,
),
}
json.dump(obj, sys.stdout)
7 changes: 0 additions & 7 deletions kde/plasmoid/contents/scripts/get-all-shader-files.sh

This file was deleted.

4 changes: 0 additions & 4 deletions kde/plasmoid/contents/scripts/get-shaders.sh

This file was deleted.

23 changes: 23 additions & 0 deletions kde/plasmoid/contents/scripts/get_effect_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import glob
import sys
import os
from helper import config_effect_home, applet_effect_home


def _get_list(root):
l = glob.glob(os.path.join(root, '*/')) + glob.glob(os.path.join(root, '*.frag'))
return [n[len(root):] for n in l]


def get_list():
l1 = _get_list(applet_effect_home)
l2 = _get_list(config_effect_home)
l2 = [n + ' ' for n in l2]
l = l1 + l2
l.sort()
return l


if __name__ == '__main__':
import json
json.dump(get_list(), sys.stdout)
13 changes: 13 additions & 0 deletions kde/plasmoid/contents/scripts/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sys
import os
config_effect_home = os.path.expanduser('~/.config/panon/')
applet_effect_home = os.path.join(os.path.split(sys.argv[0])[0], '../shaders/')


def read_file(path):
return open(path, 'rb').read().decode(errors='ignore')


def read_file_lines(path):
for line in open(path, 'rb'):
yield line.decode(errors='ignore')
24 changes: 24 additions & 0 deletions kde/plasmoid/contents/scripts/read_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
panon client
Usage:
freetile [options] <effect> <file>
freetile -h | --help
Options:
-h --help Show this screen.
--debug Debug
"""
from helper import config_effect_home, applet_effect_home, read_file
from docopt import docopt
import os.path
arguments = docopt(__doc__)
effect_name = arguments['<effect>']

if effect_name.endswith(' '):
effect_name = effect_name[:-1]
effect_home = config_effect_home
else:
effect_home = applet_effect_home
s = read_file(os.path.join(effect_home, effect_name, arguments['<file>']))
print(s)
15 changes: 0 additions & 15 deletions kde/plasmoid/contents/shaders/bar1ch/arguments.json

This file was deleted.

15 changes: 15 additions & 0 deletions kde/plasmoid/contents/shaders/bar1ch/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"arguments": [{
"name": "bar_width",
"default": 5,
"type": "int"
}, {
"name": "gap_width",
"default": 2,
"type": "int"
}, {
"name": "decay",
"default": 0.003,
"type": "double"
}]
}
23 changes: 0 additions & 23 deletions kde/plasmoid/contents/shaders/chain/arguments.json

This file was deleted.

23 changes: 23 additions & 0 deletions kde/plasmoid/contents/shaders/chain/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"arguments": [{
"name": "unit_radius",
"default": 15.0,
"type": "double"
}, {
"name": "strength",
"default": 0.125,
"type": "double"
}, {
"name": "particle_opacity",
"default": 0.4,
"type": "double"
}, {
"name": "height_ratio",
"default": 1.0,
"type": "double"
}, {
"name": "density",
"default": 256,
"type": "int"
}]
}
Loading

0 comments on commit f2618b4

Please sign in to comment.