[Fluxus] big texture overhaul

Dave Griffiths dave at pawfal.org
Sun Oct 28 07:08:54 PDT 2007


Hi all,

Finally improved the texturing possibilities:

* (load-texture) now takes an optional parameter list for controlling
how your textures are created.

* new (texture-params) command for setting texture state - it's a local
state command, so works with push, pop and grab as usual.

(see the help for more detailed info on these)

* also (vreflect) added to the maths commands - returns the reflection
of one vector about another.

To give you some actual examples (none of these use GLSL - but lots more
is possible with shaders + textures now too)

Fast, cheap, dirty depth of field for texture sprites by heavily
gaussian blurring the upper mip levels:
http://www.flickr.com/photos/7905273@N07/1789111583/

And also proper hardware cube mapping:
http://www.flickr.com/photos/7905273@N07/1789111597/
With a real environment cube map:
http://www.flickr.com/photos/7905273@N07/1789111615/

Mipmapping code:

(clear)
(clear-colour (vector 0.5 0.5 0.5))

(define t (load-texture "f0.png" (list 'generate-mipmaps 0 'mip-level
0)))
(load-texture "f1.png" (list 'id t 'generate-mipmaps 0 'mip-level 1))
(load-texture "f2.png" (list 'id t 'generate-mipmaps 0 'mip-level 2))
(load-texture "f3.png" (list 'id t 'generate-mipmaps 0 'mip-level 3))
(load-texture "f4.png" (list 'id t 'generate-mipmaps 0 'mip-level 4))
(load-texture "f5.png" (list 'id t 'generate-mipmaps 0 'mip-level 5))
(load-texture "f6.png" (list 'id t 'generate-mipmaps 0 'mip-level 6))
(load-texture "f7.png" (list 'id t 'generate-mipmaps 0 'mip-level 7))
(load-texture "f8.png" (list 'id t 'generate-mipmaps 0 'mip-level 8))

(texture t)
(texture-params 0 '(max-lod 1000 min-lod -1000))
(hint-depth-sort)

(define (p n)
    (cond ((not (zero? n))
        (push)
        (translate (vmul (vsub (vector (flxrnd) (flxrnd) (flxrnd))
                        (vector 0.5 0.5 0.5)) 5))
        (build-plane)
        (pop)
        (p (- n 1)))))

(p 100)

Cubemapping code:

(clear)
(clear-texture-cache)
(clear-colour (vector 0.5 0.5 0.5))

(define t (load-texture "cube-left.png" (list 'type
'cube-map-positive-x)))
(load-texture "cube-right.png" (list 'id t 'type 'cube-map-negative-x))
(load-texture "cube-top.png" (list 'id t 'type 'cube-map-positive-y))
(load-texture "cube-bottom.png" (list 'id t 'type 'cube-map-negative-y))
(load-texture "cube-front.png" (list 'id t 'type 'cube-map-positive-z))
(load-texture "cube-back.png" (list 'id t 'type 'cube-map-negative-z))

(define (calc-reflection n eye-pos)
    (cond ((not (zero? n))
        (pdata-set "t" n 
            (vreflect 
                (pdata-get "n" n) 
                (vnormalise (vsub eye-pos 
                    (pdata-get "p" n)))))
        (calc-reflection (- n 1) eye-pos))))

(texture t)
(define o (build-torus 2 3 20 20))

(define (render)
    (grab o)
    (calc-reflection (pdata-size) 
            (vtransform (vector 0 0 0) (get-camera)))           
    (ungrab))

(every-frame (render))




More information about the Fluxus mailing list