Skip to content

Instantly share code, notes, and snippets.

@ggcrunchy
Last active August 29, 2015 14:24
Show Gist options
  • Save ggcrunchy/dab2a0929055949276a9 to your computer and use it in GitHub Desktop.
Save ggcrunchy/dab2a0929055949276a9 to your computer and use it in GitHub Desktop.
Wavy text shader example
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" }
}
}
--- Shader-based example for updating some text geometry.
--
-- 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 ]
--
-- Kernel --
local kernel = { category = "filter", name = "wavy_text" }
kernel.isTimeDependent = true
kernel.vertex = [[
P_POSITION vec2 VertexKernel (P_POSITION vec2 pos)
{
P_POSITION float offset = sin(CoronaTexCoord.x * 3.7 + CoronaTotalTime * 8.2);
pos.y += offset * 8.7;
return pos;
}
]]
kernel.fragment = [[
P_COLOR vec4 FragmentKernel (P_UV vec2 uv)
{
return texture2D(CoronaSampler0, uv) * vec4(uv.x, 0., 0., 1.);
}
]]
graphics.defineEffect(kernel)
local x = -600
local verts = {}
for i = 1, 20 do
verts[#verts + 1] = x
verts[#verts + 1] = -100
x = x + 30
end
for i = 1, 20 do
x = x - 30
verts[#verts + 1] = x
verts[#verts + 1] = 100
end
local polygon = display.newPolygon(display.contentCenterX, display.contentCenterY, verts)
local paint = {
type = "image",
filename = "Text.png"
}
polygon.fill = paint
polygon.fill.effect = "filter.custom.wavy_text"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment