-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
incorperate changes for GLVisualize next2
- Loading branch information
1 parent
9f14858
commit 90870df
Showing
1 changed file
with
32 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,41 @@ | ||
module ShaderToy | ||
using GeometryTypes, GLAbstraction, GLVisualize, ColorTypes, Reactive, FileIO, ModernGL | ||
|
||
using GeometryTypes, GLAbstraction, GLVisualize, ColorTypes, Reactive | ||
using GLWindow, FileIO, ModernGL | ||
|
||
function shadertoy(shaderpath, additional_uniforms::Dict{Symbol, Any}=Dict{Symbol, Any}(); templates=Dict{ASCIIString, ASCIIString}()) | ||
# package code goes here | ||
data = merge(Dict( | ||
:iResolution => lift(Vec2f0, screen.inputs[:framebuffer_size]), | ||
:iMouse => dropwhen(lift(isempty, screen.inputs[:mousebuttonspressed]), Vec2f0(0), lift(Vec2f0, screen.inputs[:mouseposition])), | ||
:iGlobalTime => bounce(0f0:0.016f0:2000f0), | ||
:preferred_camera => :nothing | ||
), collect_for_gl(GLMesh2D(Rectangle{Float32}(-1f0,-1f0,2f0,2f0))), additional_uniforms) | ||
templates = merge(templates, Dict("SHADERTOY_INPUTS" => """ | ||
uniform vec2 iResolution; | ||
uniform vec2 iMouse; | ||
uniform float iGlobalTime; | ||
uniform sampler2D iChannel0; | ||
uniform sampler2D iChannel1; | ||
uniform sampler2D iChannel2; | ||
uniform sampler2D iChannel3; | ||
""" | ||
)) | ||
program = TemplateProgram( | ||
load(Pkg.dir("ShaderToy", "src", "fullscreen.vert")), | ||
load(Pkg.dir("ShaderToy", "src", "shadertoy.frag")), | ||
load(shaderpath), | ||
view=templates | ||
) | ||
robj = std_renderobject(data, program) | ||
view(robj) | ||
|
||
isinteractive() ? @async(renderloop()) : renderloop() | ||
|
||
robj | ||
@gen_defaults! additional_uniforms begin | ||
iResolution = map(Vec2f0, screen.inputs[:framebuffer_size]) | ||
iMouse = filterwhen(map(isempty, screen.inputs[:mouse_buttons_pressed]), Vec2f0(0), map(Vec2f0, screen.inputs[:mouseposition])) | ||
iGlobalTime = bounce(0f0:0.016f0:2000f0) | ||
preferred_camera = :nothing | ||
primitive::GLMesh2D = SimpleRectangle(-1f0,-1f0,2f0,2f0) | ||
end | ||
templates = merge(templates, Dict("SHADERTOY_INPUTS" => """ | ||
uniform vec2 iResolution; | ||
uniform vec2 iMouse; | ||
uniform float iGlobalTime; | ||
uniform sampler2D iChannel0; | ||
uniform sampler2D iChannel1; | ||
uniform sampler2D iChannel2; | ||
uniform sampler2D iChannel3; | ||
""" | ||
)) | ||
program = LazyShader( | ||
load(Pkg.dir("ShaderToy", "src", "fullscreen.vert")), | ||
load(Pkg.dir("ShaderToy", "src", "shadertoy.frag")), | ||
load(shaderpath), | ||
view=templates | ||
) | ||
robj = std_renderobject(additional_uniforms, program) | ||
view(robj) | ||
isinteractive() ? @async(renderloop(screen)) : renderloop(screen) | ||
robj | ||
end | ||
export shadertoy | ||
|
||
function __init__() | ||
global screen, renderloop | ||
screen, renderloop = glscreen() | ||
end | ||
global screen | ||
screen = glscreen() | ||
end | ||
|
||
end # module |