load-shader

reset-shaderclj

shader

load-shader

Arguments
[fragment-filename vertex-filename][fragment-filename]
Docstring

Loads a shader into the PShader object for clj and Shader object for cljs. In clj mode shaders are compatible with the P2D and P3D renderers, but not with the default renderer. In cljs mode shaders are compatible with the P3D renderer.

Works only inside sketch functions?
Yes
Original Processing method
loadShader()
Original p5js method
loadShader()
Example
clojure specific
  • ; 
    ; setup
    ; 
    (let [path (clojure.java.io/resource "SimpleShader.glsl")
          shd (q/load-shader (.getPath path))]
      (q/set-state! :shader shd))
    ; 
    ; draw
    ; 
    (let [gr (q/create-graphics 250 250)
          shd (q/state :shader)]
      (when (q/loaded? shd)
        (q/with-graphics gr
          (q/background 255)
          (q/fill 255 0 0)
          (q/triangle 50 30 220 120 20 180))
        (q/image gr 0 0)
        (q/image gr 250 0)
        (q/shader shd)
        (q/image gr 0 250)
        (q/reset-shader)
        (q/image gr 250 250)))
clojurescript specific
  • ; 
    ; setup
    ; 
    (let [shd (q/load-shader "shader.frag" "shader.vert")]
      (q/set-state! :shader shd))
    ; 
    ; draw
    ; 
    (let [shd (q/state :shader)]
      (when (q/loaded? shd)
        (q/shader shd)
        (q/set-uniform shd "p" (array -0.74364388703 0.13182590421))
        (q/set-uniform shd
                       "r"
                       (* 1.5 (q/exp (* -6.5 (+ 1 (q/sin (/ (q/millis) 2000)))))))
        (q/quad -1 -1 1 -1 1 1 -1 1)))
    try example

reset-shaderclj

Arguments
[kind][]
Docstring

Restores the default shaders. Code that runs after reset-shader will not be affected by previously defined shaders. Optional kind parameter - type of shader, either :points, :lines, or :triangles

Works only inside sketch functions?
Yes
Original Processing method
resetShader()
Original p5js method
None.
Example
clojure specific
  • ; 
    ; setup
    ; 
    (let [path (clojure.java.io/resource "SimpleShader.glsl")
          shd (q/load-shader (.getPath path))]
      (q/set-state! :shader shd))
    ; 
    ; draw
    ; 
    (let [gr (q/create-graphics 250 250)
          shd (q/state :shader)]
      (when (q/loaded? shd)
        (q/with-graphics gr
          (q/background 255)
          (q/fill 255 0 0)
          (q/triangle 50 30 220 120 20 180))
        (q/image gr 0 0)
        (q/image gr 250 0)
        (q/shader shd)
        (q/image gr 0 250)
        (q/reset-shader)
        (q/image gr 250 250)))

shader

Arguments
[shader kind]clj[shader]
Docstring

Applies the shader specified by the parameters. It's compatible with the :p2d and :p3d renderers, but not with the default :java2d renderer. In clj mode you can pass an optional kind parameter that specifies the type of shader, either :points, :lines, or :triangles

Works only inside sketch functions?
Yes
Original Processing method
shader()
Original p5js method
None.
Example
clojure specific
  • ; 
    ; setup
    ; 
    (let [path (clojure.java.io/resource "SimpleShader.glsl")
          shd (q/load-shader (.getPath path))]
      (q/set-state! :shader shd))
    ; 
    ; draw
    ; 
    (let [gr (q/create-graphics 250 250)
          shd (q/state :shader)]
      (when (q/loaded? shd)
        (q/with-graphics gr
          (q/background 255)
          (q/fill 255 0 0)
          (q/triangle 50 30 220 120 20 180))
        (q/image gr 0 0)
        (q/image gr 250 0)
        (q/shader shd)
        (q/image gr 0 250)
        (q/reset-shader)
        (q/image gr 250 250)))
clojurescript specific
  • ; 
    ; setup
    ; 
    (let [shd (q/load-shader "shader.frag" "shader.vert")]
      (q/set-state! :shader shd))
    ; 
    ; draw
    ; 
    (let [shd (q/state :shader)]
      (when (q/loaded? shd)
        (q/shader shd)
        (q/set-uniform shd "p" (array -0.74364388703 0.13182590421))
        (q/set-uniform shd
                       "r"
                       (* 1.5 (q/exp (* -6.5 (+ 1 (q/sin (/ (q/millis) 2000)))))))
        (q/quad -1 -1 1 -1 1 1 -1 1)))
    try example