dup fluid set
init-gpu
initial-particles clone >>particles
- "C:/Users/erikc/Pictures/particle2.pgm" make-texture >>texture
- "C:/Users/erikc/Pictures/colors.ppm" make-texture >>ramp
+ "resource:extra/fluids/particle2.pgm" make-texture >>texture
+ "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
+ { 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 ;
{ "indexes" [ nip length 2 / 0 swap <index-range> ] }
{ "framebuffer" [ drop framebuffer>> ] }
} 2<render-set> render
-
+
world color-texture>> gaussian-blur
{ 0 0 } { 640 480 } <rect> <viewport-state> set-gpu-state
world ramp>> {
! Copyright (C) 2010 Erik Charlebois.
! See http://factorcode.org/license.txt for BSD license.
-USING: destructors fry gpu.render gpu.shaders gpu.state gpu.textures
-gpu.util images kernel locals math math.rectangles sequences ;
+USING: arrays destructors fry gpu.framebuffers gpu.render gpu.shaders
+gpu.state gpu.textures gpu.util images kernel locals math
+math.rectangles sequences ;
IN: gpu.effects.blur
GLSL-SHADER: blur-fragment-shader fragment-shader
vec4 col = 0.16 * texture2D(texture, texcoord);
if (horizontal)
{
- const vec2 blurX1 = vec2(blurSize, 0.0);
- const vec2 blurX2 = vec2(blurSize * 2.0, 0.0);
- const vec2 blurX3 = vec2(blurSize * 3.0, 0.0);
- const vec2 blurX4 = vec2(blurSize * 4.0, 0.0);
+ vec2 blurX1 = vec2(blurSize, 0.0);
+ vec2 blurX2 = vec2(blurSize * 2.0, 0.0);
+ vec2 blurX3 = vec2(blurSize * 3.0, 0.0);
+ vec2 blurX4 = vec2(blurSize * 4.0, 0.0);
col += 0.15 * ( texture2D(texture, texcoord - blurX1)
+ texture2D(texture, texcoord + blurX1));
col += 0.12 * ( texture2D(texture, texcoord - blurX2)
}
else
{
- const vec2 blurY1 = vec2(0.0, blurSize);
- const vec2 blurY2 = vec2(0.0, blurSize * 2.0);
- const vec2 blurY3 = vec2(0.0, blurSize * 3.0);
- const vec2 blurY4 = vec2(0.0, blurSize * 4.0);
+ vec2 blurY1 = vec2(0.0, blurSize);
+ vec2 blurY2 = vec2(0.0, blurSize * 2.0);
+ vec2 blurY3 = vec2(0.0, blurSize * 3.0);
+ vec2 blurY4 = vec2(0.0, blurSize * 4.0);
col += 0.15 * ( texture2D(texture, texcoord - blurY1)
+ texture2D(texture, texcoord + blurY1));
col += 0.12 * ( texture2D(texture, texcoord - blurY2)
col += 0.05 * ( texture2D(texture, texcoord - blurY4)
+ texture2D(texture, texcoord + blurY4));
}
- gl_FragColor = col ;
+ gl_FragColor = col;
}
;
{ "blurSize" float-uniform f } ;
GLSL-PROGRAM: blur-program window-vertex-shader blur-fragment-shader window-vertex-format ;
-
+
:: (blur) ( texture horizontal? framebuffer dim -- )
{ 0 0 } dim <rect> <viewport-state> set-gpu-state
texture horizontal? 1.0 dim horizontal? [ first ] [ second ] if / blur-uniforms boa framebuffer {
:: blur ( texture horizontal? -- texture )
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)
target-framebuffer dispose
target-texture ;
! (c)2009 Joe Groff bsd license
-USING: arrays gpu.buffers gpu.framebuffers gpu.render gpu.shaders
-gpu.textures images kernel locals specialized-arrays ;
+USING: accessors arrays gpu.buffers gpu.framebuffers gpu.render
+gpu.shaders gpu.textures images kernel locals opengl.framebuffers
+specialized-arrays ;
FROM: alien.c-types => float ;
SPECIALIZED-ARRAY: float
IN: gpu.util
;
GLSL-SHADER: window-point-fragment-shader fragment-shader
+#version 120
uniform sampler2D texture;
void main()
{
[ <window-vertex-buffer> ] dip window-vertex-format <vertex-array*> ; inline
:: <2d-render-texture> ( dim order type -- renderbuffer texture )
- order type T{ texture-parameters { wrap clamp-texcoord-to-edge }
- { min-filter filter-linear } { min-mipmap-filter f } } <texture-2d>
- [ 0 <texture-2d-attachment> 1array f f dim <framebuffer> ] keep ;
+ order type
+ T{ texture-parameters
+ { 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 -- )
{