Get fluids working on Mac

release
Erik Charlebois 2010-04-05 01:38:39 -07:00
parent 6081abea04
commit a91d7a0e7b
3 changed files with 34 additions and 25 deletions

View File

@ -98,14 +98,14 @@ M: fluids-world begin-game-world
dup fluid set dup fluid set
init-gpu init-gpu
initial-particles clone >>particles initial-particles clone >>particles
"C:/Users/erikc/Pictures/particle2.pgm" make-texture >>texture "resource:extra/fluids/particle2.pgm" make-texture >>texture
"C:/Users/erikc/Pictures/colors.ppm" make-texture >>ramp "resource:extra/fluids/colors.ppm" make-texture >>ramp
RGB float-components T{ texture-parameters RGB float-components T{ texture-parameters
{ wrap clamp-texcoord-to-edge } { wrap clamp-texcoord-to-edge }
{ min-filter filter-linear } { min-filter filter-linear }
{ min-mipmap-filter f } { min-mipmap-filter f } }
} <texture-2d> >>color-texture <texture-2d> >>color-texture
dup color-texture>> 0 <texture-2d-attachment> 1array f f { 320 240 } <framebuffer> >>framebuffer dup color-texture>> 0 <texture-2d-attachment> 1array f f { 320 240 } <framebuffer> >>framebuffer
drop ; drop ;

View File

@ -1,7 +1,8 @@
! 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: destructors fry gpu.render gpu.shaders gpu.state gpu.textures USING: arrays destructors fry gpu.framebuffers gpu.render gpu.shaders
gpu.util images kernel locals math math.rectangles sequences ; gpu.state gpu.textures gpu.util images kernel locals math
math.rectangles sequences ;
IN: gpu.effects.blur IN: gpu.effects.blur
GLSL-SHADER: blur-fragment-shader fragment-shader GLSL-SHADER: blur-fragment-shader fragment-shader
@ -14,10 +15,10 @@ void main()
vec4 col = 0.16 * texture2D(texture, texcoord); vec4 col = 0.16 * texture2D(texture, texcoord);
if (horizontal) if (horizontal)
{ {
const vec2 blurX1 = vec2(blurSize, 0.0); vec2 blurX1 = vec2(blurSize, 0.0);
const vec2 blurX2 = vec2(blurSize * 2.0, 0.0); vec2 blurX2 = vec2(blurSize * 2.0, 0.0);
const vec2 blurX3 = vec2(blurSize * 3.0, 0.0); vec2 blurX3 = vec2(blurSize * 3.0, 0.0);
const vec2 blurX4 = vec2(blurSize * 4.0, 0.0); vec2 blurX4 = vec2(blurSize * 4.0, 0.0);
col += 0.15 * ( texture2D(texture, texcoord - blurX1) col += 0.15 * ( texture2D(texture, texcoord - blurX1)
+ texture2D(texture, texcoord + blurX1)); + texture2D(texture, texcoord + blurX1));
col += 0.12 * ( texture2D(texture, texcoord - blurX2) col += 0.12 * ( texture2D(texture, texcoord - blurX2)
@ -29,10 +30,10 @@ void main()
} }
else else
{ {
const vec2 blurY1 = vec2(0.0, blurSize); vec2 blurY1 = vec2(0.0, blurSize);
const vec2 blurY2 = vec2(0.0, blurSize * 2.0); vec2 blurY2 = vec2(0.0, blurSize * 2.0);
const vec2 blurY3 = vec2(0.0, blurSize * 3.0); vec2 blurY3 = vec2(0.0, blurSize * 3.0);
const vec2 blurY4 = vec2(0.0, blurSize * 4.0); vec2 blurY4 = vec2(0.0, blurSize * 4.0);
col += 0.15 * ( texture2D(texture, texcoord - blurY1) col += 0.15 * ( texture2D(texture, texcoord - blurY1)
+ texture2D(texture, texcoord + blurY1)); + texture2D(texture, texcoord + blurY1));
col += 0.12 * ( texture2D(texture, texcoord - blurY2) col += 0.12 * ( texture2D(texture, texcoord - blurY2)
@ -42,7 +43,7 @@ void main()
col += 0.05 * ( texture2D(texture, texcoord - blurY4) col += 0.05 * ( texture2D(texture, texcoord - blurY4)
+ texture2D(texture, texcoord + blurY4)); + texture2D(texture, texcoord + blurY4));
} }
gl_FragColor = col ; gl_FragColor = col;
} }
; ;
@ -65,7 +66,7 @@ GLSL-PROGRAM: blur-program window-vertex-shader blur-fragment-shader window-vert
:: blur ( texture horizontal? -- texture ) :: blur ( texture horizontal? -- texture )
texture 0 texture-dim :> dim texture 0 texture-dim :> dim
dim L ubyte-components <2d-render-texture> :> ( target-framebuffer target-texture ) dim RGB float-components <2d-render-texture> :> ( target-framebuffer target-texture )
texture horizontal? target-framebuffer dim (blur) texture horizontal? target-framebuffer dim (blur)
target-framebuffer dispose target-framebuffer dispose
target-texture ; target-texture ;

View File

@ -1,6 +1,7 @@
! (c)2009 Joe Groff bsd license ! (c)2009 Joe Groff bsd license
USING: arrays gpu.buffers gpu.framebuffers gpu.render gpu.shaders USING: accessors arrays gpu.buffers gpu.framebuffers gpu.render
gpu.textures images kernel locals specialized-arrays ; gpu.shaders gpu.textures images kernel locals opengl.framebuffers
specialized-arrays ;
FROM: alien.c-types => float ; FROM: alien.c-types => float ;
SPECIALIZED-ARRAY: float SPECIALIZED-ARRAY: float
IN: gpu.util IN: gpu.util
@ -83,6 +84,7 @@ void main()
; ;
GLSL-SHADER: window-point-fragment-shader fragment-shader GLSL-SHADER: window-point-fragment-shader fragment-shader
#version 120
uniform sampler2D texture; uniform sampler2D texture;
void main() void main()
{ {
@ -113,9 +115,15 @@ CONSTANT: window-vertexes
[ <window-vertex-buffer> ] dip window-vertex-format <vertex-array*> ; inline [ <window-vertex-buffer> ] dip window-vertex-format <vertex-array*> ; inline
:: <2d-render-texture> ( dim order type -- renderbuffer texture ) :: <2d-render-texture> ( dim order type -- renderbuffer texture )
order type T{ texture-parameters { wrap clamp-texcoord-to-edge } order type
{ min-filter filter-linear } { min-mipmap-filter f } } <texture-2d> T{ texture-parameters
[ 0 <texture-2d-attachment> 1array f f dim <framebuffer> ] keep ; { wrap clamp-texcoord-to-edge }
{ min-filter filter-linear }
{ min-mipmap-filter f } }
<texture-2d> [
0 <texture-2d-attachment> 1array f f dim <framebuffer>
dup { { default-attachment { 0 0 0 } } } clear-framebuffer
] keep ;
: draw-texture ( texture -- ) : draw-texture ( texture -- )
{ {