[Fluxus] Postprocessing in fluxus
Johann Korndoerfer
cupe-fluxus at erleuchtet.org
Sun May 15 04:11:59 PDT 2011
Hi, i'm new
I am currently trying to do postprocessing in a shader with fluxus (for
blur, glow, distortion, kaleidoscope, ...). Below is how i do it
currently, which works fine, except i have a few issues with it:
0) fluxus limits texture size to power-of-two which is no longer
needed, every graphics card should be able to use arbitrary sizes AFAIK.
This is only a minor performance and image quality issue.
1) It seems that the primitive must be drawn (with the mysterious #t
flag) and hiding it won't work. I have to move it out of the way, which
is a really crude workaround.
2) When i use the mouse to change the camera transform, of course i
rotate the pixels primitive (or the plane, if i draw onto one) instead
of the objects rendered into its texture. I tried storing the cam
transform, setting the transform to its initial state and applying it by
hand to the objects drawn (see the code below). Somehow, the current cam
transform seems to be ignored - i suspect the cam transform is set
before every-frame calls its payload and not when i call
set-camera-transform. So i tried storing the cam transform and then
multiplying its inverse onto the current matrix to get a pristine state
for drawing the plane, only to discover that minverse doesn't actually
invert matrices. Im out of ideas now.
3) It's an awful lot of code with lots of stuff to get wrong when
coding it live.
Here is my simple 4-fold symmetry kaleidoscope effect. Drag the mouse
and you'll see what i mean.
(clear)
(reset-camera)
(define v
"
varying vec2 tc;
void main(){
gl_Position = ftransform();
tc = gl_MultiTexCoord0.st;
}")
(define f
"
uniform sampler2D tex;
varying vec2 tc;
void main() {
gl_FragColor = texture2D(tex,abs(tc-vec2(0.5))+vec2(0.5));
}")
(define p (build-pixels 2048 1024 #t))
(with-primitive p
;(hide 1)
(translate (vector 23232342 0 0)))
(define transform (mtranslate (vector 0 0 -10)))
(define (render)
(texture (load-texture "test.png"))
(with-state
(identity)
(concat transform) ;apply cam transform
(scale 15.0)
(draw-cube)))
(every-frame
(begin
(set! transform (get-camera-transform)) ;store cam tranform
(set-camera-transform (mtranslate (vector 0 0 -10))) ;this seems to
be ignored for the current frame
(with-pixels-renderer p
(render))
(with-state
(texture (pixels->texture p))
(shader-source v f)
(scale (vector 20 15 1)) ;somehow, scaling by 20 and 15 makes it
fit my screen
(draw-plane))
(set-camera-transform transform) ;restore cam transform
(unlock-camera)))
I'd appreciate any suggestions.
Thanks,
Johann
More information about the Fluxus
mailing list