Skip to content

Commit

Permalink
incorperate changes for GLVisualize next2
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed Jan 27, 2016
1 parent 9f14858 commit 90870df
Showing 1 changed file with 32 additions and 34 deletions.
66 changes: 32 additions & 34 deletions src/ShaderToy.jl
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

0 comments on commit 90870df

Please sign in to comment.