first commit
This commit is contained in:
commit
417e54da96
5696 changed files with 900003 additions and 0 deletions
kivy_venv/share/kivy-examples/shader
Binary file not shown.
Binary file not shown.
Binary file not shown.
9
kivy_venv/share/kivy-examples/shader/plasma.kv
Normal file
9
kivy_venv/share/kivy-examples/shader/plasma.kv
Normal file
|
@ -0,0 +1,9 @@
|
|||
#:kivy 1.0
|
||||
|
||||
<ShaderWidget>:
|
||||
canvas:
|
||||
Color:
|
||||
rgb: 1, 0, 0
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
86
kivy_venv/share/kivy-examples/shader/plasma.py
Normal file
86
kivy_venv/share/kivy-examples/shader/plasma.py
Normal file
|
@ -0,0 +1,86 @@
|
|||
'''
|
||||
Plasma Shader
|
||||
=============
|
||||
|
||||
This shader example have been taken from
|
||||
http://www.iquilezles.org/apps/shadertoy/ with some adaptation.
|
||||
|
||||
This might become a Kivy widget when experimentation will be done.
|
||||
'''
|
||||
|
||||
|
||||
from kivy.clock import Clock
|
||||
from kivy.app import App
|
||||
from kivy.uix.floatlayout import FloatLayout
|
||||
from kivy.core.window import Window
|
||||
from kivy.graphics import RenderContext
|
||||
from kivy.properties import StringProperty
|
||||
|
||||
|
||||
# Plasma shader
|
||||
plasma_shader = '''
|
||||
$HEADER$
|
||||
|
||||
uniform vec2 resolution;
|
||||
uniform float time;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 frag_coord = frag_modelview_mat * gl_FragCoord;
|
||||
float x = frag_coord.x;
|
||||
float y = frag_coord.y;
|
||||
float mov0 = x+y+cos(sin(time)*2.)*100.+sin(x/100.)*1000.;
|
||||
float mov1 = y / resolution.y / 0.2 + time;
|
||||
float mov2 = x / resolution.x / 0.2;
|
||||
float c1 = abs(sin(mov1+time)/2.+mov2/2.-mov1-mov2+time);
|
||||
float c2 = abs(sin(c1+sin(mov0/1000.+time)
|
||||
+sin(y/40.+time)+sin((x+y)/100.)*3.));
|
||||
float c3 = abs(sin(c2+cos(mov1+mov2+c2)+cos(mov2)+sin(x/1000.)));
|
||||
gl_FragColor = vec4( c1,c2,c3,1.0);
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
class ShaderWidget(FloatLayout):
|
||||
|
||||
# property to set the source code for fragment shader
|
||||
fs = StringProperty(None)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
# Instead of using Canvas, we will use a RenderContext,
|
||||
# and change the default shader used.
|
||||
self.canvas = RenderContext()
|
||||
|
||||
# call the constructor of parent
|
||||
# if they are any graphics object, they will be added on our new canvas
|
||||
super(ShaderWidget, self).__init__(**kwargs)
|
||||
|
||||
# We'll update our glsl variables in a clock
|
||||
Clock.schedule_interval(self.update_glsl, 1 / 60.)
|
||||
|
||||
def on_fs(self, instance, value):
|
||||
# set the fragment shader to our source code
|
||||
shader = self.canvas.shader
|
||||
old_value = shader.fs
|
||||
shader.fs = value
|
||||
if not shader.success:
|
||||
shader.fs = old_value
|
||||
raise Exception('failed')
|
||||
|
||||
def update_glsl(self, *largs):
|
||||
self.canvas['time'] = Clock.get_boottime()
|
||||
self.canvas['resolution'] = list(map(float, self.size))
|
||||
# This is needed for the default vertex shader.
|
||||
win_rc = Window.render_context
|
||||
self.canvas['projection_mat'] = win_rc['projection_mat']
|
||||
self.canvas['modelview_mat'] = win_rc['modelview_mat']
|
||||
self.canvas['frag_modelview_mat'] = win_rc['frag_modelview_mat']
|
||||
|
||||
|
||||
class PlasmaApp(App):
|
||||
def build(self):
|
||||
return ShaderWidget(fs=plasma_shader)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
PlasmaApp().run()
|
91
kivy_venv/share/kivy-examples/shader/rotated.kv
Normal file
91
kivy_venv/share/kivy-examples/shader/rotated.kv
Normal file
|
@ -0,0 +1,91 @@
|
|||
#:kivy 1.10.1
|
||||
|
||||
<TiltedWidget@Widget>:
|
||||
canvas.before:
|
||||
PushMatrix
|
||||
Rotate:
|
||||
angle: 45
|
||||
origin: self.center
|
||||
canvas.after:
|
||||
PopMatrix
|
||||
|
||||
<TiltedShiftedWidget@Widget>:
|
||||
canvas.before:
|
||||
PushMatrix
|
||||
PushMatrix:
|
||||
stack: 'frag_modelview_mat'
|
||||
Rotate:
|
||||
angle: 45
|
||||
origin: self.center
|
||||
Rotate:
|
||||
stack: 'frag_modelview_mat'
|
||||
angle: 45
|
||||
origin: self.center
|
||||
canvas.after:
|
||||
PopMatrix
|
||||
PopMatrix:
|
||||
stack: 'frag_modelview_mat'
|
||||
|
||||
<SmallLabel@Label>:
|
||||
font_size: 30
|
||||
outline_width: 1
|
||||
pos_hint: {'center_x': .5, 'center_y': .5}
|
||||
|
||||
<LargeTiltedLabel@TiltedWidget+Label>:
|
||||
font_size: 60
|
||||
outline_width: 3
|
||||
|
||||
<MiniShaderWidget@ShaderWidget>:
|
||||
size_hint: .3, .3
|
||||
pos_hint: {'center_x': .25, 'center_y': .25}
|
||||
canvas:
|
||||
Color:
|
||||
rgb: 1., .6, .3
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
<PhaseShiftedWidget@TiltedShiftedWidget+FloatLayout>:
|
||||
size_hint: .3, .3
|
||||
pos_hint: {'center_x': .75, 'center_y': .75}
|
||||
canvas:
|
||||
Color:
|
||||
rgb: .3, .6, .9
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
SmallLabel:
|
||||
text: 'Phase Shifted'
|
||||
|
||||
<InPhaseWidget@TiltedWidget+FloatLayout>:
|
||||
size_hint: .3, .3
|
||||
pos_hint: {'center_x': .25, 'center_y': .75}
|
||||
canvas:
|
||||
Color:
|
||||
rgb: .3, .6, .9
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
SmallLabel:
|
||||
text: 'In Phase'
|
||||
|
||||
<MainWidget@ShaderWidget+FloatLayout>:
|
||||
mini: mini
|
||||
canvas:
|
||||
Color:
|
||||
rgb: .9, .6, .3
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
LargeTiltedLabel:
|
||||
text: 'far out'
|
||||
pos_hint: {'center_x': .75, 'center_y': .25}
|
||||
|
||||
MiniShaderWidget
|
||||
id: mini
|
||||
|
||||
PhaseShiftedWidget
|
||||
InPhaseWidget
|
102
kivy_venv/share/kivy-examples/shader/rotated.py
Normal file
102
kivy_venv/share/kivy-examples/shader/rotated.py
Normal file
|
@ -0,0 +1,102 @@
|
|||
'''
|
||||
Rotated Shader
|
||||
=============
|
||||
|
||||
This shader example is a modified version of plasma.py that shows how to
|
||||
rotate areas of fragment shaders bounded by vertex_instructions.
|
||||
'''
|
||||
from kivy.app import App
|
||||
from kivy.clock import Clock
|
||||
from kivy.factory import Factory
|
||||
from kivy.graphics import RenderContext
|
||||
from kivy.properties import StringProperty
|
||||
from kivy.uix.widget import Widget
|
||||
|
||||
# imported early for side effects needed for Shader
|
||||
import kivy.core.window
|
||||
|
||||
|
||||
shared_code = '''
|
||||
$HEADER$
|
||||
|
||||
uniform float time;
|
||||
|
||||
vec4 tex(void)
|
||||
{
|
||||
return frag_color * texture2D(texture0, tex_coord0);
|
||||
}
|
||||
|
||||
float plasmaFunc(float n1, float n2, float n3, float n4)
|
||||
{
|
||||
vec4 fPos = frag_modelview_mat * gl_FragCoord;
|
||||
return abs(sin(
|
||||
sin(sin(fPos.x / n1) + time) +
|
||||
sin(fPos.y / n2 + time) +
|
||||
n4 * sin((fPos.x + fPos.y) / n3)));
|
||||
}
|
||||
|
||||
'''
|
||||
|
||||
|
||||
plasma_shader = shared_code + '''
|
||||
void main(void)
|
||||
{
|
||||
float green = plasmaFunc(40., 30., 100., 3.5);
|
||||
gl_FragColor = vec4(1.0, green, 1.0, 1.0) * tex();
|
||||
}
|
||||
|
||||
'''
|
||||
|
||||
|
||||
plasma_shader2 = shared_code + '''
|
||||
void main(void)
|
||||
{
|
||||
float red = plasmaFunc(30., 20., 10., .5);
|
||||
gl_FragColor = vec4(red, 1.0, 1.0, 1.0) * tex();
|
||||
}
|
||||
|
||||
'''
|
||||
|
||||
|
||||
class ShaderWidget(Widget):
|
||||
|
||||
# property to set the source code for fragment shader
|
||||
fs = StringProperty(None)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
# Instead of using Canvas, we will use a RenderContext,
|
||||
# and change the default fragment shader used.
|
||||
self.canvas = RenderContext(use_parent_projection=True,
|
||||
use_parent_modelview=True,
|
||||
use_parent_frag_modelview=True)
|
||||
|
||||
# call the constructor of parent
|
||||
# if they are any graphics object, they will be added on our new canvas
|
||||
super(ShaderWidget, self).__init__(**kwargs)
|
||||
|
||||
# We'll update our glsl variables in a clock
|
||||
Clock.schedule_interval(self.update_glsl, 1 / 60.)
|
||||
|
||||
def update_glsl(self, *largs):
|
||||
self.canvas['time'] = Clock.get_boottime()
|
||||
|
||||
def on_fs(self, instance, value):
|
||||
# set the fragment shader to our source code
|
||||
shader = self.canvas.shader
|
||||
old_value = shader.fs
|
||||
shader.fs = value
|
||||
if not shader.success:
|
||||
shader.fs = old_value
|
||||
raise Exception('failed')
|
||||
|
||||
|
||||
class RotatedApp(App):
|
||||
def build(self):
|
||||
main_widget = Factory.MainWidget()
|
||||
main_widget.fs = plasma_shader
|
||||
main_widget.mini.fs = plasma_shader2
|
||||
return main_widget
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
RotatedApp().run()
|
29
kivy_venv/share/kivy-examples/shader/shadertree.kv
Normal file
29
kivy_venv/share/kivy-examples/shader/shadertree.kv
Normal file
|
@ -0,0 +1,29 @@
|
|||
#:kivy 1.10.1
|
||||
|
||||
<ShaderWidget>:
|
||||
Button:
|
||||
text: 'Hello World'
|
||||
pos_hint: {'center_x': .25, 'center_y': .5}
|
||||
size_hint: None, None
|
||||
ScatterImage
|
||||
|
||||
<ScatterImage@Scatter>:
|
||||
size: image.size
|
||||
pos_hint: {'center_x': .75, 'center_y': .5}
|
||||
size_hint: None, None
|
||||
Image:
|
||||
id: image
|
||||
source: 'tex3.jpg'
|
||||
size: self.texture_size
|
||||
|
||||
<RootWidget>:
|
||||
shader_btn: shader_btn
|
||||
shader_widget: shader_widget
|
||||
|
||||
ShaderWidget:
|
||||
id: shader_widget
|
||||
Button:
|
||||
id: shader_btn
|
||||
text: 'Change fragment shader'
|
||||
size_hint_y: None
|
||||
height: 50
|
193
kivy_venv/share/kivy-examples/shader/shadertree.py
Normal file
193
kivy_venv/share/kivy-examples/shader/shadertree.py
Normal file
|
@ -0,0 +1,193 @@
|
|||
'''
|
||||
Tree shader
|
||||
===========
|
||||
|
||||
This example is an experimentation to show how we can use shader for a tree
|
||||
subset. Here, we made a ShaderTreeWidget, different than the ShaderWidget
|
||||
in the plasma.py example.
|
||||
|
||||
The ShaderTree widget create a Framebuffer, render his children on it, and
|
||||
render the Framebuffer with a specific Shader.
|
||||
With this way, you can apply cool effect on your widgets :)
|
||||
|
||||
'''
|
||||
|
||||
from kivy.clock import Clock
|
||||
from kivy.app import App
|
||||
from kivy.uix.floatlayout import FloatLayout
|
||||
from kivy.core.window import Window # side effects needed by Shader
|
||||
from kivy.properties import StringProperty, ObjectProperty
|
||||
from kivy.graphics import (RenderContext, Fbo, Color, ClearColor, ClearBuffers,
|
||||
Rectangle)
|
||||
|
||||
import itertools
|
||||
|
||||
|
||||
header = '''
|
||||
$HEADER$
|
||||
|
||||
uniform vec2 resolution;
|
||||
uniform float time;
|
||||
'''
|
||||
|
||||
# pulse (Danguafer/Silexars, 2010)
|
||||
shader_pulse = header + '''
|
||||
void main(void)
|
||||
{
|
||||
vec2 halfres = resolution.xy/2.0;
|
||||
vec2 cPos = vec4(frag_modelview_mat * gl_FragCoord).xy;
|
||||
|
||||
cPos.x -= 0.5*halfres.x*sin(time/2.0)+0.3*halfres.x*cos(time)+halfres.x;
|
||||
cPos.y -= 0.4*halfres.y*sin(time/5.0)+0.3*halfres.y*cos(time)+halfres.y;
|
||||
float cLength = length(cPos);
|
||||
|
||||
vec2 uv = tex_coord0+(cPos/cLength)*sin(cLength/30.0-time*10.0)/25.0;
|
||||
vec3 col = texture2D(texture0,uv).xyz*50.0/cLength;
|
||||
|
||||
gl_FragColor = vec4(col,1.0);
|
||||
}
|
||||
'''
|
||||
|
||||
# post processing (by iq, 2009)
|
||||
shader_postprocessing = header + '''
|
||||
uniform vec2 uvsize;
|
||||
uniform vec2 uvpos;
|
||||
void main(void)
|
||||
{
|
||||
vec2 q = tex_coord0 * vec2(1, -1);
|
||||
vec2 uv = 0.5 + (q-0.5);//*(0.9);// + 0.1*sin(0.2*time));
|
||||
|
||||
vec3 oricol = texture2D(texture0,vec2(q.x,1.0-q.y)).xyz;
|
||||
vec3 col;
|
||||
|
||||
col.r = texture2D(texture0,vec2(uv.x+0.003,-uv.y)).x;
|
||||
col.g = texture2D(texture0,vec2(uv.x+0.000,-uv.y)).y;
|
||||
col.b = texture2D(texture0,vec2(uv.x-0.003,-uv.y)).z;
|
||||
|
||||
col = clamp(col*0.5+0.5*col*col*1.2,0.0,1.0);
|
||||
|
||||
//col *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y);
|
||||
|
||||
col *= vec3(0.8,1.0,0.7);
|
||||
|
||||
col *= 0.9+0.1*sin(10.0*time+uv.y*1000.0);
|
||||
|
||||
col *= 0.97+0.03*sin(110.0*time);
|
||||
|
||||
float comp = smoothstep( 0.2, 0.7, sin(time) );
|
||||
//col = mix( col, oricol, clamp(-2.0+2.0*q.x+3.0*comp,0.0,1.0) );
|
||||
|
||||
gl_FragColor = vec4(col,1.0);
|
||||
}
|
||||
'''
|
||||
|
||||
shader_monochrome = header + '''
|
||||
void main() {
|
||||
vec4 rgb = texture2D(texture0, tex_coord0);
|
||||
float c = (rgb.x + rgb.y + rgb.z) * 0.3333;
|
||||
gl_FragColor = vec4(c, c, c, 1.0);
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
class ShaderWidget(FloatLayout):
|
||||
|
||||
# property to set the source code for fragment shader
|
||||
fs = StringProperty(None)
|
||||
|
||||
# texture of the framebuffer
|
||||
texture = ObjectProperty(None)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
# Instead of using canvas, we will use a RenderContext,
|
||||
# and change the default shader used.
|
||||
self.canvas = RenderContext(use_parent_projection=True,
|
||||
use_parent_modelview=True,
|
||||
use_parent_frag_modelview=True)
|
||||
|
||||
with self.canvas:
|
||||
self.fbo = Fbo(size=self.size)
|
||||
self.fbo_color = Color(1, 1, 1, 1)
|
||||
self.fbo_rect = Rectangle()
|
||||
|
||||
with self.fbo:
|
||||
ClearColor(0, 0, 0, 0)
|
||||
ClearBuffers()
|
||||
|
||||
# call the constructor of parent
|
||||
# if they are any graphics object, they will be added on our new canvas
|
||||
super(ShaderWidget, self).__init__(**kwargs)
|
||||
|
||||
# We'll update our glsl variables in a clock
|
||||
Clock.schedule_interval(self.update_glsl, 0)
|
||||
|
||||
def update_glsl(self, *largs):
|
||||
self.canvas['time'] = Clock.get_boottime()
|
||||
self.canvas['resolution'] = [float(v) for v in self.size]
|
||||
|
||||
def on_fs(self, instance, value):
|
||||
# set the fragment shader to our source code
|
||||
shader = self.canvas.shader
|
||||
old_value = shader.fs
|
||||
shader.fs = value
|
||||
if not shader.success:
|
||||
shader.fs = old_value
|
||||
raise Exception('failed')
|
||||
|
||||
#
|
||||
# now, if we have new widget to add,
|
||||
# add their graphics canvas to our Framebuffer, not the usual canvas.
|
||||
#
|
||||
|
||||
def add_widget(self, *args, **kwargs):
|
||||
c = self.canvas
|
||||
self.canvas = self.fbo
|
||||
super(ShaderWidget, self).add_widget(*args, **kwargs)
|
||||
self.canvas = c
|
||||
|
||||
def remove_widget(self, *args, **kwargs):
|
||||
c = self.canvas
|
||||
self.canvas = self.fbo
|
||||
super(ShaderWidget, self).remove_widget(*args, **kwargs)
|
||||
self.canvas = c
|
||||
|
||||
def on_size(self, instance, value):
|
||||
self.fbo.size = value
|
||||
self.texture = self.fbo.texture
|
||||
self.fbo_rect.size = value
|
||||
|
||||
def on_pos(self, instance, value):
|
||||
self.fbo_rect.pos = value
|
||||
|
||||
def on_texture(self, instance, value):
|
||||
self.fbo_rect.texture = value
|
||||
|
||||
|
||||
class RootWidget(FloatLayout):
|
||||
shader_btn = ObjectProperty(None)
|
||||
shader_widget = ObjectProperty(None)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(RootWidget, self).__init__(**kwargs)
|
||||
|
||||
# prepare shader list
|
||||
available_shaders = [
|
||||
shader_pulse,
|
||||
shader_postprocessing,
|
||||
shader_monochrome,
|
||||
]
|
||||
self.shaders = itertools.cycle(available_shaders)
|
||||
|
||||
self.shader_btn.bind(on_release=self.change)
|
||||
|
||||
def change(self, *largs):
|
||||
self.shader_widget.fs = next(self.shaders)
|
||||
|
||||
|
||||
class ShaderTreeApp(App):
|
||||
def build(self):
|
||||
return RootWidget()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ShaderTreeApp().run()
|
BIN
kivy_venv/share/kivy-examples/shader/tex3.jpg
Normal file
BIN
kivy_venv/share/kivy-examples/shader/tex3.jpg
Normal file
Binary file not shown.
After ![]() (image error) Size: 86 KiB |
Loading…
Add table
Add a link
Reference in a new issue