Skip to content

Commit

Permalink
Core/Graphics: adding Linear Guassian blur effects (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggcrunchy authored Nov 5, 2022
1 parent 81aa447 commit 2d4e199
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 0 deletions.
18 changes: 18 additions & 0 deletions librtt/Display/Rtt_ShaderBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ static const char kFilterBlurString[] = "blur";
static const char kFilterBlurGaussianString[] = "blurGaussian";
static const char kFilterBlurHorizontalString[] = "blurHorizontal";
static const char kFilterBlurVerticalString[] = "blurVertical";
static const char kFilterBlurGaussianLinearString[] = "blurGaussianLinear";
static const char kFilterBlurLinearHorizontalString[] = "blurLinearHorizontal";
static const char kFilterBlurLinearVerticalString[] = "blurLinearVertical";
static const char kFilterBrightnessString[] = "brightness";
static const char kFilterBulgeString[] = "bulge";
static const char kFilterChromaKeyString[] = "chromaKey";
Expand Down Expand Up @@ -119,6 +122,15 @@ ShaderBuiltin::StringForFilter( Filter filter )
case kFilterBlurVertical:
result = kFilterBlurVerticalString;
break;
case kFilterBlurGaussianLinear:
result = kFilterBlurGaussianLinearString;
break;
case kFilterBlurLinearHorizontal:
result = kFilterBlurLinearHorizontalString;
break;
case kFilterBlurLinearVertical:
result = kFilterBlurLinearVerticalString;
break;
case kFilterBrightness:
result = kFilterBrightnessString;
break;
Expand Down Expand Up @@ -461,6 +473,9 @@ int luaload_kernel_filter_blur_gl( lua_State *L );
int luaload_kernel_filter_blurGaussian_gl( lua_State *L );
int luaload_kernel_filter_blurHorizontal_gl( lua_State *L );
int luaload_kernel_filter_blurVertical_gl( lua_State *L );
int luaload_kernel_filter_blurGaussianLinear_gl( lua_State *L );
int luaload_kernel_filter_blurLinearHorizontal_gl( lua_State *L );
int luaload_kernel_filter_blurLinearVertical_gl( lua_State *L );
int luaload_kernel_filter_brightness_gl( lua_State *L );
int luaload_kernel_filter_bulge_gl( lua_State *L );
int luaload_kernel_filter_chromaKey_gl( lua_State *L );
Expand Down Expand Up @@ -512,6 +527,9 @@ static const luaL_Reg kBuiltInFilterFuncs[] =
{ kFilterBlurGaussianString, Corona::Lua::Open< luaload_kernel_filter_blurGaussian_gl > },
{ kFilterBlurHorizontalString, Corona::Lua::Open< luaload_kernel_filter_blurHorizontal_gl > },
{ kFilterBlurVerticalString, Corona::Lua::Open< luaload_kernel_filter_blurVertical_gl > },
{ kFilterBlurGaussianLinearString, Corona::Lua::Open< luaload_kernel_filter_blurGaussianLinear_gl > },
{ kFilterBlurLinearHorizontalString, Corona::Lua::Open< luaload_kernel_filter_blurLinearHorizontal_gl > },
{ kFilterBlurLinearVerticalString, Corona::Lua::Open< luaload_kernel_filter_blurLinearVertical_gl > },
{ kFilterBrightnessString, Corona::Lua::Open< luaload_kernel_filter_brightness_gl > },
{ kFilterBulgeString, Corona::Lua::Open< luaload_kernel_filter_bulge_gl > },
{ kFilterChromaKeyString, Corona::Lua::Open< luaload_kernel_filter_chromaKey_gl > },
Expand Down
3 changes: 3 additions & 0 deletions librtt/Display/Rtt_ShaderBuiltin.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class ShaderBuiltin
kFilterBlurGaussian,
kFilterBlurHorizontal,
kFilterBlurVertical,
kFilterBlurGaussianLinear,
kFilterBlurLinearHorizontal,
kFilterBlurLinearVertical,
kFilterBrightness,
kFilterBulge,
kFilterChromaKey,
Expand Down
18 changes: 18 additions & 0 deletions librtt/Display/Shader/kernel_filter_blurGaussianLinear_gl.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local kernel = {}

kernel.language = "glsl"

kernel.category = "filter"

kernel.name = "blurGaussianLinear"

kernel.graph =
{
nodes = {
horizontal = { effect="filter.blurLinearHorizontal", input1="paint1" },
vertical = { effect="filter.blurLinearVertical", input1="horizontal" },
},
output = "vertical",
}

return kernel
51 changes: 51 additions & 0 deletions librtt/Display/Shader/kernel_filter_blurLinearHorizontal_gl.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
local kernel = {}

kernel.language = "glsl"

kernel.category = "filter"

kernel.name = "blurLinearHorizontal"

kernel.unsupportedPlatforms =
{
WinPhone = true,
}

kernel.vertexData =
{
{
name = "offset1",
default = 1.3846153846,
min = 0,
max = 100,
index = 0, -- v_UserData.x
},
{
name = "offset2",
default = 3.2307692308,
min = 0,
max = 100,
index = 1, -- v_UserData.y
},
}

kernel.fragment =
[[
const P_UV float kWeight0 = 0.2270270270;
const P_UV float kWeight1 = 0.3162162162;
const P_UV float kWeight2 = 0.0702702703;
P_COLOR vec4 FragmentKernel( P_UV vec2 texCoord )
{
P_COLOR vec4 color = texture2D(u_FillSampler0, texCoord.st) * kWeight0;
color += texture2D(u_FillSampler0, (texCoord.st + vec2(v_UserData.x, 0.0) * u_TexelSize.xy)) * kWeight1;
color += texture2D(u_FillSampler0, (texCoord.st - vec2(v_UserData.x, 0.0) * u_TexelSize.xy)) * kWeight1;
color += texture2D(u_FillSampler0, (texCoord.st + vec2(v_UserData.y, 0.0) * u_TexelSize.xy)) * kWeight2;
color += texture2D(u_FillSampler0, (texCoord.st - vec2(v_UserData.y, 0.0) * u_TexelSize.xy)) * kWeight2;
return color * v_ColorScale;
}
]]

return kernel
51 changes: 51 additions & 0 deletions librtt/Display/Shader/kernel_filter_blurLinearVertical_gl.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
local kernel = {}

kernel.language = "glsl"

kernel.category = "filter"

kernel.name = "blurLinearVertical"

kernel.unsupportedPlatforms =
{
WinPhone = true,
}

kernel.vertexData =
{
{
name = "offset1",
default = 1.3846153846,
min = 0,
max = 100,
index = 0, -- v_UserData.x
},
{
name = "offset2",
default = 3.2307692308,
min = 0,
max = 100,
index = 1, -- v_UserData.y
},
}

kernel.fragment =
[[
const P_UV float kWeight0 = 0.2270270270;
const P_UV float kWeight1 = 0.3162162162;
const P_UV float kWeight2 = 0.0702702703;
P_COLOR vec4 FragmentKernel( P_UV vec2 texCoord )
{
P_COLOR vec4 color = texture2D(u_FillSampler0, texCoord.st) * kWeight0;
color += texture2D(u_FillSampler0, (texCoord.st + vec2(0.0, v_UserData.x) * u_TexelSize.xy)) * kWeight1;
color += texture2D(u_FillSampler0, (texCoord.st - vec2(0.0, v_UserData.x) * u_TexelSize.xy)) * kWeight1;
color += texture2D(u_FillSampler0, (texCoord.st + vec2(0.0, v_UserData.y) * u_TexelSize.xy)) * kWeight2;
color += texture2D(u_FillSampler0, (texCoord.st - vec2(0.0, v_UserData.y) * u_TexelSize.xy)) * kWeight2;
return color * v_ColorScale;
}
]]

return kernel
6 changes: 6 additions & 0 deletions platform/android/ndk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ SET( LUA_SOURCES
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_blurGaussian_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_blurHorizontal_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_blurVertical_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_blurGaussianLinear_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_blurLinearHorizontal_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_blurLinearVertical_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_brightness_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_bulge_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_chromaKey_gl.lua"
Expand Down Expand Up @@ -549,6 +552,9 @@ add_library( corona SHARED
${Lua2CppOutputDir}/kernel_filter_blurGaussian_gl.cpp
${Lua2CppOutputDir}/kernel_filter_blurHorizontal_gl.cpp
${Lua2CppOutputDir}/kernel_filter_blurVertical_gl.cpp
${Lua2CppOutputDir}/kernel_filter_blurGaussianLinear_gl.cpp
${Lua2CppOutputDir}/kernel_filter_blurLinearHorizontal_gl.cpp
${Lua2CppOutputDir}/kernel_filter_blurLinearVertical_gl.cpp
${Lua2CppOutputDir}/kernel_filter_brightness_gl.cpp
${Lua2CppOutputDir}/kernel_filter_bulge_gl.cpp
${Lua2CppOutputDir}/kernel_filter_chromaKey_gl.cpp
Expand Down
3 changes: 3 additions & 0 deletions platform/emscripten/gmake/lua2cpp.make
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ SRCS = ../shell.lua \
$(ROOT)/../librtt/Display/Shader/kernel_filter_blurGaussian_gl.lua \
$(ROOT)/../librtt/Display/Shader/kernel_filter_blurHorizontal_gl.lua \
$(ROOT)/../librtt/Display/Shader/kernel_filter_blurVertical_gl.lua \
$(ROOT)/../librtt/Display/Shader/kernel_filter_blurGaussianLinear_gl.lua \
$(ROOT)/../librtt/Display/Shader/kernel_filter_blurLinearHorizontal_gl.lua \
$(ROOT)/../librtt/Display/Shader/kernel_filter_blurLinearVertical_gl.lua \
$(ROOT)/../librtt/Display/Shader/kernel_filter_brightness_gl.lua \
$(ROOT)/../librtt/Display/Shader/kernel_filter_bulge_gl.lua \
$(ROOT)/../librtt/Display/Shader/kernel_filter_chromaKey_gl.lua \
Expand Down
12 changes: 12 additions & 0 deletions platform/iphone/libcorona.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,9 @@
A4E76F5313A935CC00AFB095 /* json.lua in Sources */ = {isa = PBXBuildFile; fileRef = A4E76F5213A935CC00AFB095 /* json.lua */; };
A67E201A1797222C0066FF47 /* b2GLESDebugDraw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A67E20181797222C0066FF47 /* b2GLESDebugDraw.cpp */; };
A67E201B1797222C0066FF47 /* b2GLESDebugDraw.h in Headers */ = {isa = PBXBuildFile; fileRef = A67E20191797222C0066FF47 /* b2GLESDebugDraw.h */; };
AA2C69B729147BC40093B0BE /* kernel_filter_blurGaussianLinear_gl.lua in Sources */ = {isa = PBXBuildFile; fileRef = AA2C69B529147B3B0093B0BE /* kernel_filter_blurGaussianLinear_gl.lua */; };
AA2C69B829147BC40093B0BE /* kernel_filter_blurLinearHorizontal_gl.lua in Sources */ = {isa = PBXBuildFile; fileRef = AA2C69B629147B3B0093B0BE /* kernel_filter_blurLinearHorizontal_gl.lua */; };
AA2C69B929147BC40093B0BE /* kernel_filter_blurLinearVertical_gl.lua in Sources */ = {isa = PBXBuildFile; fileRef = AA2C69B429147B3A0093B0BE /* kernel_filter_blurLinearVertical_gl.lua */; };
C20EF66F1C0E832B00DF0532 /* launchpad.lua in Sources */ = {isa = PBXBuildFile; fileRef = C20EF66E1C0E824000DF0532 /* launchpad.lua */; };
C22711D518D1646A005AE714 /* composer_scene.lua in Sources */ = {isa = PBXBuildFile; fileRef = C24FA4FC18D14D50002039FB /* composer_scene.lua */; };
C26B11D218775CC300C3F259 /* composer.lua in Sources */ = {isa = PBXBuildFile; fileRef = C26B11D118775A9E00C3F259 /* composer.lua */; };
Expand Down Expand Up @@ -1644,6 +1647,9 @@
A4E76F5213A935CC00AFB095 /* json.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = json.lua; path = ../resources/json.lua; sourceTree = SOURCE_ROOT; };
A67E20181797222C0066FF47 /* b2GLESDebugDraw.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2GLESDebugDraw.cpp; sourceTree = "<group>"; };
A67E20191797222C0066FF47 /* b2GLESDebugDraw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2GLESDebugDraw.h; sourceTree = "<group>"; };
AA2C69B429147B3A0093B0BE /* kernel_filter_blurLinearVertical_gl.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = kernel_filter_blurLinearVertical_gl.lua; path = Display/Shader/kernel_filter_blurLinearVertical_gl.lua; sourceTree = "<group>"; };
AA2C69B529147B3B0093B0BE /* kernel_filter_blurGaussianLinear_gl.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = kernel_filter_blurGaussianLinear_gl.lua; path = Display/Shader/kernel_filter_blurGaussianLinear_gl.lua; sourceTree = "<group>"; };
AA2C69B629147B3B0093B0BE /* kernel_filter_blurLinearHorizontal_gl.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = kernel_filter_blurLinearHorizontal_gl.lua; path = Display/Shader/kernel_filter_blurLinearHorizontal_gl.lua; sourceTree = "<group>"; };
C20EF66E1C0E824000DF0532 /* launchpad.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = launchpad.lua; path = ../platform/resources/launchpad.lua; sourceTree = "<group>"; };
C23D8DEA1954F27D00D6555E /* widget_theme_android_holo_dark_sheet.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = widget_theme_android_holo_dark_sheet.lua; path = ../subrepos/widget/widget_theme_android_holo_dark_sheet.lua; sourceTree = "<group>"; };
C23D8DED1954F27D00D6555E /* widget_theme_android_holo_dark.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = widget_theme_android_holo_dark.lua; path = ../subrepos/widget/widget_theme_android_holo_dark.lua; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2822,6 +2828,9 @@
50B9673B17CF278B00BB1178 /* kernel_filter_blurGaussian_gl.lua */,
0720210D17C8167E00B6D424 /* kernel_filter_blurHorizontal_gl.lua */,
0720210E17C8167E00B6D424 /* kernel_filter_blurVertical_gl.lua */,
AA2C69B529147B3B0093B0BE /* kernel_filter_blurGaussianLinear_gl.lua */,
AA2C69B629147B3B0093B0BE /* kernel_filter_blurLinearHorizontal_gl.lua */,
AA2C69B429147B3A0093B0BE /* kernel_filter_blurLinearVertical_gl.lua */,
A47428FA17694EE700C63853 /* kernel_filter_brightness_gl.lua */,
A47428FB17694EE700C63853 /* kernel_filter_bulge_gl.lua */,
A47428FC17694EE700C63853 /* kernel_filter_chromaKey_gl.lua */,
Expand Down Expand Up @@ -3674,6 +3683,9 @@
50B5987417BDAA1D006CA2C9 /* kernel_composite_glow_gl.lua in Sources */,
50B5987517BDAA1D006CA2C9 /* kernel_composite_linearLight_gl.lua in Sources */,
0720211017C816DD00B6D424 /* kernel_filter_blurVertical_gl.lua in Sources */,
AA2C69B929147BC40093B0BE /* kernel_filter_blurLinearVertical_gl.lua in Sources */,
AA2C69B829147BC40093B0BE /* kernel_filter_blurLinearHorizontal_gl.lua in Sources */,
AA2C69B729147BC40093B0BE /* kernel_filter_blurGaussianLinear_gl.lua in Sources */,
0720211217C816DF00B6D424 /* kernel_filter_levels_gl.lua in Sources */,
0720211117C816DE00B6D424 /* kernel_filter_bloom_gl.lua in Sources */,
50B5987617BDAA1D006CA2C9 /* kernel_composite_phoenix_gl.lua in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions platform/linux/CMakeList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ SET( LUA_SOURCES
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_blurGaussian_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_blurHorizontal_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_blurVertical_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_blurGaussianLinear_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_blurLinearHorizontal_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_blurLinearVertical_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_brightness_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_bulge_gl.lua"
"${CORONA_ROOT}/librtt/Display/Shader/kernel_filter_chromaKey_gl.lua"
Expand Down Expand Up @@ -626,6 +629,9 @@ SET( SOLAR2D_SOURCES
${Lua2CppOutputDir}/kernel_filter_blurGaussian_gl.cpp
${Lua2CppOutputDir}/kernel_filter_blurHorizontal_gl.cpp
${Lua2CppOutputDir}/kernel_filter_blurVertical_gl.cpp
${Lua2CppOutputDir}/kernel_filter_blurGaussianLinear_gl.cpp
${Lua2CppOutputDir}/kernel_filter_blurLinearHorizontal_gl.cpp
${Lua2CppOutputDir}/kernel_filter_blurLinearVertical_gl.cpp
${Lua2CppOutputDir}/kernel_filter_brightness_gl.cpp
${Lua2CppOutputDir}/kernel_filter_bulge_gl.cpp
${Lua2CppOutputDir}/kernel_filter_chromaKey_gl.cpp
Expand Down
3 changes: 3 additions & 0 deletions platform/linux/Solar2DBuilder.project
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,9 @@
<File Name="lua/kernel_filter_blurVertical_gl.cpp"/>
<File Name="lua/kernel_filter_blurHorizontal_gl.cpp"/>
<File Name="lua/kernel_filter_blurGaussian_gl.cpp"/>
<File Name="lua/kernel_filter_blurLinearVertical_gl.cpp"/>
<File Name="lua/kernel_filter_blurLinearHorizontal_gl.cpp"/>
<File Name="lua/kernel_filter_blurGaussianLinear_gl.cpp"/>
<File Name="lua/kernel_filter_blur_gl.cpp"/>
<File Name="lua/kernel_filter_bloom_gl.cpp"/>
<File Name="lua/kernel_default_gl.cpp"/>
Expand Down
3 changes: 3 additions & 0 deletions platform/linux/Solar2DSimulator.project
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@
<File Name="lua/kernel_filter_blurVertical_gl.cpp"/>
<File Name="lua/kernel_filter_blurHorizontal_gl.cpp"/>
<File Name="lua/kernel_filter_blurGaussian_gl.cpp"/>
<File Name="lua/kernel_filter_blurLinearVertical_gl.cpp"/>
<File Name="lua/kernel_filter_blurLinearHorizontal_gl.cpp"/>
<File Name="lua/kernel_filter_blurGaussianLinear_gl.cpp"/>
<File Name="lua/kernel_filter_blur_gl.cpp"/>
<File Name="lua/kernel_filter_bloom_gl.cpp"/>
<File Name="lua/kernel_default_gl.cpp"/>
Expand Down
Loading

0 comments on commit 2d4e199

Please sign in to comment.