More work on fluids
parent
6699560327
commit
e6b4e54e2c
|
@ -1,12 +1,12 @@
|
||||||
! Copyright (C) 2010 Erik Charlebois.
|
! Copyright (C) 2010 Erik Charlebois.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays classes.struct destructors game.loop
|
USING: accessors arrays classes.struct destructors game.loop
|
||||||
game.worlds gpu gpu.buffers gpu.framebuffers gpu.render gpu.shaders
|
game.worlds gpu gpu.buffers gpu.effects.blur gpu.framebuffers
|
||||||
gpu.state gpu.textures gpu.util images images.loader kernel literals
|
gpu.render gpu.shaders gpu.state gpu.textures gpu.util images
|
||||||
locals make math math.rectangles math.vectors namespaces opengl.gl
|
images.loader kernel literals locals make math math.rectangles
|
||||||
sequences specialized-arrays ui.gadgets.worlds images.ppm
|
math.vectors namespaces opengl.gl sequences specialized-arrays
|
||||||
ui.gestures ui.pixel-formats images.pgm gpu.effects.blur
|
ui.gadgets.worlds ui.gestures ui.pixel-formats gpu.effects.step
|
||||||
gpu.effects.step ;
|
images.pgm images.ppm ;
|
||||||
FROM: alien.c-types => float ;
|
FROM: alien.c-types => float ;
|
||||||
SPECIALIZED-ARRAY: float
|
SPECIALIZED-ARRAY: float
|
||||||
IN: fluids
|
IN: fluids
|
||||||
|
@ -65,7 +65,7 @@ particle_t-array{
|
||||||
[ verlet-integrate-particle ] curry map! ;
|
[ verlet-integrate-particle ] curry map! ;
|
||||||
|
|
||||||
TUPLE: fluids-world < game-world
|
TUPLE: fluids-world < game-world
|
||||||
particles texture framebuffer color-texture ramp { paused boolean initial: f } ;
|
particles texture ramp { paused boolean initial: f } ;
|
||||||
|
|
||||||
: make-texture ( pathname -- texture )
|
: make-texture ( pathname -- texture )
|
||||||
load-image
|
load-image
|
||||||
|
@ -100,50 +100,27 @@ M: fluids-world begin-game-world
|
||||||
initial-particles clone >>particles
|
initial-particles clone >>particles
|
||||||
"resource:extra/fluids/particle2.pgm" make-texture >>texture
|
"resource:extra/fluids/particle2.pgm" make-texture >>texture
|
||||||
"resource:extra/fluids/colors.ppm" make-texture >>ramp
|
"resource:extra/fluids/colors.ppm" make-texture >>ramp
|
||||||
|
|
||||||
RGB float-components T{ texture-parameters
|
|
||||||
{ wrap clamp-texcoord-to-edge }
|
|
||||||
{ min-filter filter-linear }
|
|
||||||
{ min-mipmap-filter f } }
|
|
||||||
<texture-2d> >>color-texture
|
|
||||||
|
|
||||||
dup color-texture>> 0 <texture-2d-attachment> 1array f f { 320 240 } <framebuffer> >>framebuffer
|
|
||||||
drop ;
|
drop ;
|
||||||
|
|
||||||
M: fluids-world end-game-world
|
M: fluids-world end-game-world
|
||||||
framebuffer>> dispose ;
|
drop ;
|
||||||
|
|
||||||
M: fluids-world tick-game-world
|
M: fluids-world tick-game-world
|
||||||
dup paused>> [ drop ] [ integrate ] if ;
|
dup paused>> [ drop ] [ integrate ] if ;
|
||||||
|
|
||||||
M:: fluids-world draw-world* ( world -- )
|
M:: fluids-world draw-world* ( world -- )
|
||||||
world framebuffer>> { { default-attachment { 0 0 0 } } } clear-framebuffer
|
|
||||||
system-framebuffer { { default-attachment { 0 0 0 } } } clear-framebuffer
|
|
||||||
|
|
||||||
f eq-add func-one func-one <blend-mode> dup <blend-state> set-gpu-state
|
|
||||||
f origin-upper-left 1.0 <point-state> set-gpu-state
|
|
||||||
world particles>> [
|
world particles>> [
|
||||||
[ p>> [ x>> , ] [ y>> , ] bi ] each
|
[ p>> [ x>> , ] [ y>> , ] bi ] each
|
||||||
] curry float-array{ } make :> verts
|
] curry float-array{ } make :> verts
|
||||||
|
|
||||||
{ 0 0 } { 320 240 } <rect> <viewport-state> set-gpu-state
|
[
|
||||||
GL_POINT_SPRITE glEnable
|
verts world texture>> 50.0 { 320 240 } blended-point-sprite-batch &dispose
|
||||||
world verts {
|
|
||||||
{ "primitive-mode" [ 2drop points-mode ] }
|
|
||||||
{ "uniforms" [ drop texture>> 50.0 window-point-uniforms boa ] }
|
|
||||||
{ "vertex-array" [ nip stream-upload draw-usage vertex-buffer byte-array>buffer &dispose window-point-program <program-instance> &dispose <vertex-array> &dispose ] }
|
|
||||||
{ "indexes" [ nip length 2 / 0 swap <index-range> ] }
|
|
||||||
{ "framebuffer" [ drop framebuffer>> ] }
|
|
||||||
} 2<render-set> render
|
|
||||||
|
|
||||||
world color-texture>> gaussian-blur
|
blend-state new set-gpu-state
|
||||||
{ 0 0 } { 640 480 } <rect> <viewport-state> set-gpu-state
|
|
||||||
world ramp>> {
|
gaussian-blur &dispose world ramp>> { 1024 768 } step-texture &dispose
|
||||||
{ "primitive-mode" [ 2drop triangle-strip-mode ] }
|
{ 1024 768 } draw-texture
|
||||||
{ "uniforms" [ step-uniforms boa ] }
|
] with-destructors
|
||||||
{ "vertex-array" [ 2drop <window-vertex-buffer> step-program <program-instance> <vertex-array> ] }
|
|
||||||
{ "indexes" [ 2drop T{ index-range f 0 4 } ] }
|
|
||||||
} 2<render-set> render
|
|
||||||
;
|
;
|
||||||
|
|
||||||
GAME: fluids {
|
GAME: fluids {
|
||||||
|
@ -151,7 +128,7 @@ GAME: fluids {
|
||||||
{ title "Fluids Test" }
|
{ title "Fluids Test" }
|
||||||
{ pixel-format-attributes {
|
{ pixel-format-attributes {
|
||||||
windowed double-buffered T{ depth-bits { value 24 } } } }
|
windowed double-buffered T{ depth-bits { value 24 } } } }
|
||||||
{ pref-dim { 640 480 } }
|
{ pref-dim { 1024 768 } }
|
||||||
{ tick-interval-micros $[ 60 fps ] }
|
{ tick-interval-micros $[ 60 fps ] }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -159,7 +136,7 @@ MAIN: fluids
|
||||||
|
|
||||||
fluids-world H{
|
fluids-world H{
|
||||||
{ T{ button-down } [ [
|
{ T{ button-down } [ [
|
||||||
hand-loc get { 640 480 } v/ 2 v*n 1 v-n { 1 -1 } v* first2 float2_t <struct-boa>
|
hand-loc get { 1024 768 } v/ 2 v*n 1 v-n { 1 -1 } v* first2 float2_t <struct-boa>
|
||||||
dup 2.0 particle_t <struct-boa> suffix
|
dup 2.0 particle_t <struct-boa> suffix
|
||||||
] change-particles drop ] }
|
] change-particles drop ] }
|
||||||
} set-gestures
|
} set-gestures
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
! Copyright (C) 2010 Erik Charlebois.
|
! Copyright (C) 2010 Erik Charlebois.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: gpu.render gpu.shaders gpu.util ;
|
USING: destructors gpu.render gpu.shaders gpu.state gpu.textures
|
||||||
|
gpu.util images kernel locals math.rectangles ;
|
||||||
IN: gpu.effects.step
|
IN: gpu.effects.step
|
||||||
|
|
||||||
GLSL-SHADER: step-fragment-shader fragment-shader
|
GLSL-SHADER: step-fragment-shader fragment-shader
|
||||||
|
@ -21,3 +22,19 @@ UNIFORM-TUPLE: step-uniforms
|
||||||
{ "ramp" texture-uniform f } ;
|
{ "ramp" texture-uniform f } ;
|
||||||
|
|
||||||
GLSL-PROGRAM: step-program window-vertex-shader step-fragment-shader window-vertex-format ;
|
GLSL-PROGRAM: step-program window-vertex-shader step-fragment-shader window-vertex-format ;
|
||||||
|
|
||||||
|
: (step-texture) ( texture ramp texture dim -- )
|
||||||
|
{ 0 0 } swap <rect> <viewport-state> set-gpu-state
|
||||||
|
[ step-uniforms boa ] dip {
|
||||||
|
{ "primitive-mode" [ 2drop triangle-strip-mode ] }
|
||||||
|
{ "uniforms" [ drop ] }
|
||||||
|
{ "vertex-array" [ 2drop <window-vertex-buffer> step-program <program-instance> <vertex-array> ] }
|
||||||
|
{ "indexes" [ 2drop T{ index-range f 0 4 } ] }
|
||||||
|
{ "framebuffer" [ nip ] }
|
||||||
|
} 2<render-set> render ;
|
||||||
|
|
||||||
|
:: step-texture ( texture ramp dim -- texture )
|
||||||
|
dim RGB float-components <2d-render-texture> :> ( target-framebuffer target-texture )
|
||||||
|
texture ramp target-framebuffer dim (step-texture)
|
||||||
|
target-framebuffer dispose
|
||||||
|
target-texture ;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! (c)2009 Joe Groff bsd license
|
! (c)2009 Joe Groff bsd license
|
||||||
USING: accessors arrays gpu.buffers gpu.framebuffers gpu.render
|
USING: arrays destructors gpu.buffers gpu.framebuffers gpu.render
|
||||||
gpu.shaders gpu.textures images kernel locals opengl.framebuffers
|
gpu.shaders gpu.state gpu.textures images kernel locals math
|
||||||
specialized-arrays ;
|
math.rectangles opengl.gl sequences specialized-arrays ;
|
||||||
FROM: alien.c-types => float ;
|
FROM: alien.c-types => float ;
|
||||||
SPECIALIZED-ARRAY: float
|
SPECIALIZED-ARRAY: float
|
||||||
IN: gpu.util
|
IN: gpu.util
|
||||||
|
@ -125,10 +125,34 @@ CONSTANT: window-vertexes
|
||||||
dup { { default-attachment { 0 0 0 } } } clear-framebuffer
|
dup { { default-attachment { 0 0 0 } } } clear-framebuffer
|
||||||
] keep ;
|
] keep ;
|
||||||
|
|
||||||
: draw-texture ( texture -- )
|
: draw-texture ( texture dim -- )
|
||||||
|
{ 0 0 } swap <rect> <viewport-state> set-gpu-state
|
||||||
{
|
{
|
||||||
{ "primitive-mode" [ drop triangle-strip-mode ] }
|
{ "primitive-mode" [ drop triangle-strip-mode ] }
|
||||||
{ "uniforms" [ window-uniforms boa ] }
|
{ "uniforms" [ window-uniforms boa ] }
|
||||||
{ "vertex-array" [ drop <window-vertex-buffer> window-program <program-instance> <vertex-array> ] }
|
{ "vertex-array" [ drop window-program <program-instance> <window-vertex-array> &dispose ] }
|
||||||
{ "indexes" [ drop T{ index-range f 0 4 } ] }
|
{ "indexes" [ drop T{ index-range f 0 4 } ] }
|
||||||
} <render-set> render ;
|
} <render-set> render ;
|
||||||
|
|
||||||
|
:: <streamed-vertex-array> ( verts program-instance -- vertex-array )
|
||||||
|
verts stream-upload draw-usage vertex-buffer byte-array>buffer &dispose
|
||||||
|
program-instance <vertex-array> &dispose ;
|
||||||
|
|
||||||
|
: (blended-point-sprite-batch) ( verts framebuffer texture point-size dim -- )
|
||||||
|
f eq-add func-one func-one <blend-mode> dup <blend-state> set-gpu-state
|
||||||
|
f origin-upper-left 1.0 <point-state> set-gpu-state
|
||||||
|
GL_POINT_SPRITE glEnable
|
||||||
|
{ 0 0 } swap <rect> <viewport-state> set-gpu-state
|
||||||
|
window-point-uniforms boa {
|
||||||
|
{ "primitive-mode" [ 3drop points-mode ] }
|
||||||
|
{ "uniforms" [ 2nip ] }
|
||||||
|
{ "vertex-array" [ 2drop window-point-program <program-instance> <streamed-vertex-array> ] }
|
||||||
|
{ "indexes" [ 2drop length 2 / 0 swap <index-range> ] }
|
||||||
|
{ "framebuffer" [ drop nip ] }
|
||||||
|
} 3<render-set> render ;
|
||||||
|
|
||||||
|
:: blended-point-sprite-batch ( verts texture point-size dim -- texture )
|
||||||
|
dim RGB float-components <2d-render-texture> :> ( target-framebuffer target-texture )
|
||||||
|
verts target-framebuffer texture point-size dim (blended-point-sprite-batch)
|
||||||
|
target-framebuffer dispose
|
||||||
|
target-texture ;
|
||||||
|
|
Loading…
Reference in New Issue