diff --git a/extra/fluids/fluids.factor b/extra/fluids/fluids.factor index d241a82ede..1b4f1524de 100644 --- a/extra/fluids/fluids.factor +++ b/extra/fluids/fluids.factor @@ -98,14 +98,14 @@ M: fluids-world begin-game-world 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 } - } >>color-texture + { wrap clamp-texcoord-to-edge } + { min-filter filter-linear } + { min-mipmap-filter f } } + >>color-texture dup color-texture>> 0 1array f f { 320 240 } >>framebuffer drop ; @@ -135,7 +135,7 @@ M:: fluids-world draw-world* ( world -- ) { "indexes" [ nip length 2 / 0 swap ] } { "framebuffer" [ drop framebuffer>> ] } } 2 render - + world color-texture>> gaussian-blur { 0 0 } { 640 480 } set-gpu-state world ramp>> { diff --git a/extra/gpu/effects/blur/blur.factor b/extra/gpu/effects/blur/blur.factor index 0a25654976..ed72b28374 100644 --- a/extra/gpu/effects/blur/blur.factor +++ b/extra/gpu/effects/blur/blur.factor @@ -1,7 +1,8 @@ ! 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 @@ -14,10 +15,10 @@ void main() 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) @@ -29,10 +30,10 @@ void main() } 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) @@ -42,7 +43,7 @@ void main() col += 0.05 * ( texture2D(texture, texcoord - blurY4) + texture2D(texture, texcoord + blurY4)); } - gl_FragColor = col ; + gl_FragColor = col; } ; @@ -52,7 +53,7 @@ UNIFORM-TUPLE: blur-uniforms { "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 set-gpu-state texture horizontal? 1.0 dim horizontal? [ first ] [ second ] if / blur-uniforms boa framebuffer { @@ -65,7 +66,7 @@ GLSL-PROGRAM: blur-program window-vertex-shader blur-fragment-shader window-vert :: 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 ; diff --git a/extra/gpu/util/util.factor b/extra/gpu/util/util.factor index ffca3a5478..29fe5f1314 100644 --- a/extra/gpu/util/util.factor +++ b/extra/gpu/util/util.factor @@ -1,6 +1,7 @@ ! (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 @@ -83,6 +84,7 @@ void main() ; GLSL-SHADER: window-point-fragment-shader fragment-shader +#version 120 uniform sampler2D texture; void main() { @@ -113,9 +115,15 @@ CONSTANT: window-vertexes [ ] dip window-vertex-format ; 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 } } - [ 0 1array f f dim ] keep ; + order type + T{ texture-parameters + { wrap clamp-texcoord-to-edge } + { min-filter filter-linear } + { min-mipmap-filter f } } + [ + 0 1array f f dim + dup { { default-attachment { 0 0 0 } } } clear-framebuffer + ] keep ; : draw-texture ( texture -- ) {