Last active
August 29, 2015 14:24
-
-
Save ggcrunchy/8c73faea9f568d1e7006 to your computer and use it in GitHub Desktop.
Multi-pass blur shader example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
settings = | |
{ | |
android = | |
{ | |
-- versionCode = "3" | |
}, | |
androidPermissions = | |
{ | |
"android.permission.INTERNET" | |
}, | |
orientation = | |
{ | |
default = "landscape" | |
}, | |
excludeFiles = | |
{ | |
-- | |
all = {}, | |
-- Exclude all Android icon files and .ogg files | |
-- TODO: Filter out auxiliary Android databases; needs some naming convention (right now, seems to be either root-level or ending in "_assets"?) | |
iphone = { "Icon-*dpi.png", "*.ogg" }, | |
-- Exclude iOS "retina" image files and .m4a files | |
-- TODO: Filter out images, etc. that would get incorporated into the database (mentioned above for iphone); again, needs naming convention | |
android = { "Icon.png", "*@2x.png", "*.m4a" } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- Multi-pass shader-based blur example. | |
-- | |
-- Permission is hereby granted, free of charge, to any person obtaining | |
-- a copy of this software and associated documentation files (the | |
-- "Software"), to deal in the Software without restriction, including | |
-- without limitation the rights to use, copy, modify, merge, publish, | |
-- distribute, sublicense, and/or sell copies of the Software, and to | |
-- permit persons to whom the Software is furnished to do so, subject to | |
-- the following conditions: | |
-- | |
-- The above copyright notice and this permission notice shall be | |
-- included in all copies or substantial portions of the Software. | |
-- | |
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
-- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
-- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
-- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
-- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
-- | |
-- [ MIT license: http://www.opensource.org/licenses/mit-license.php ] | |
-- | |
do | |
-- Kernel -- | |
local kernel = { category = "filter", name = "gradient" } | |
kernel.isTimeDependent = true | |
kernel.fragment = [[ | |
P_COLOR vec4 FragmentKernel (P_UV vec2 uv) | |
{ | |
P_POSITION float pos = sin(CoronaTotalTime * 1.3); | |
P_POSITION float where = 2. * uv.x - 1.; | |
P_POSITION float diff = abs(where - pos); | |
return vec4(pow(log(1. + diff), 1.7), 0., 0., 1.); | |
} | |
]] | |
graphics.defineEffect(kernel) | |
end | |
do | |
-- Kernel -- | |
local kernel = { category = "filter", name = "stretch" } | |
kernel.isTimeDependent = true | |
kernel.fragment = [[ | |
P_COLOR vec4 FragmentKernel (P_UV vec2 uv) | |
{ | |
P_UV float stretch = 65. * CoronaTexelSize.z * texture2D(CoronaSampler0, uv).r; | |
P_COLOR vec4 middle = texture2D(CoronaSampler1, uv); | |
P_COLOR vec4 left = texture2D(CoronaSampler1, uv - vec2(stretch, 0.)); | |
P_COLOR vec4 right = texture2D(CoronaSampler1, uv + vec2(stretch, 0.)); | |
return middle * .75 + left * .125 + right * .125; | |
} | |
]] | |
graphics.defineEffect(kernel) | |
end | |
do | |
-- Kernel -- | |
local kernel = { category = "filter", name = "stretch_gradient" } | |
kernel.graph = { | |
nodes = { | |
gradient = { effect = "filter.custom.gradient", input1 = "paint1" }, | |
stretch = { effect = "filter.custom.stretch", input1 = "gradient" }, | |
}, output = "stretch", | |
} | |
graphics.defineEffect(kernel) | |
end | |
local rect = display.newRect(display.contentCenterX, display.contentCenterY, 300, 300) | |
-- rect.fill.effect = "filter.custom.gradient" | |
---[[ | |
rect.fill = { | |
type = "composite", | |
paint1 = { 1 }, | |
paint2 = { type = "image", filename = "Image.jpg" } | |
} | |
rect.fill.effect = "filter.custom.stretch_gradient" | |
--]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment