├── title.gif ├── main ├── gem1.png ├── gem1.atlas ├── main.script └── main.collection ├── input └── game.input_binding ├── .gitignore ├── game.project ├── sparkle_material ├── sparkle.vp ├── sparkle.fp └── sparkle.material ├── README.md └── .gitattributes /title.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ufgo/sparkle_effect/HEAD/title.gif -------------------------------------------------------------------------------- /main/gem1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ufgo/sparkle_effect/HEAD/main/gem1.png -------------------------------------------------------------------------------- /main/gem1.atlas: -------------------------------------------------------------------------------- 1 | images { 2 | image: "/main/gem1.png" 3 | } 4 | extrude_borders: 2 5 | -------------------------------------------------------------------------------- /input/game.input_binding: -------------------------------------------------------------------------------- 1 | mouse_trigger { 2 | input: MOUSE_BUTTON_1 3 | action: "touch" 4 | } 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.internal 2 | /build 3 | .externalToolBuilders 4 | .DS_Store 5 | Thumbs.db 6 | .lock-wscript 7 | *.pyc 8 | .project 9 | .cproject 10 | builtins -------------------------------------------------------------------------------- /main/main.script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | --shader animation 3 | local url = msg.url(nil, go.get_id(), "sprite") 4 | go.animate(url, "pos.x", go.PLAYBACK_LOOP_FORWARD, 0.8, go.EASING_INSINE, 0.7) 5 | end 6 | -------------------------------------------------------------------------------- /game.project: -------------------------------------------------------------------------------- 1 | [bootstrap] 2 | main_collection = /main/main.collectionc 3 | 4 | [script] 5 | shared_state = 1 6 | 7 | [display] 8 | width = 960 9 | height = 640 10 | 11 | [android] 12 | input_method = HiddenInputField 13 | 14 | [project] 15 | title = sparkle_effect 16 | 17 | [library] 18 | include_dirs = sparkle_material 19 | 20 | -------------------------------------------------------------------------------- /sparkle_material/sparkle.vp: -------------------------------------------------------------------------------- 1 | uniform highp mat4 view_proj; 2 | 3 | // positions are in world space 4 | attribute highp vec4 position; 5 | attribute mediump vec2 texcoord0; 6 | 7 | varying mediump vec2 var_texcoord0; 8 | 9 | void main() 10 | { 11 | gl_Position = view_proj * vec4(position.xyz, 1.0); 12 | var_texcoord0 = texcoord0; 13 | } 14 | -------------------------------------------------------------------------------- /main/main.collection: -------------------------------------------------------------------------------- 1 | name: "main" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "go" 5 | data: "components {\n" 6 | " id: \"main\"\n" 7 | " component: \"/main/main.script\"\n" 8 | "}\n" 9 | "embedded_components {\n" 10 | " id: \"sprite\"\n" 11 | " type: \"sprite\"\n" 12 | " data: \"default_animation: \\\"gem1\\\"\\n" 13 | "material: \\\"/sparkle_material/sparkle.material\\\"\\n" 14 | "textures {\\n" 15 | " sampler: \\\"texture_sampler\\\"\\n" 16 | " texture: \\\"/main/gem1.atlas\\\"\\n" 17 | "}\\n" 18 | "\"\n" 19 | "}\n" 20 | "" 21 | position { 22 | x: 480.0 23 | y: 320.0 24 | } 25 | scale3 { 26 | x: 2.0 27 | y: 2.0 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sparkle_material/sparkle.fp: -------------------------------------------------------------------------------- 1 | varying mediump vec2 var_texcoord0; 2 | 3 | uniform lowp sampler2D texture_sampler; 4 | uniform lowp vec4 tint; 5 | uniform lowp vec4 pos; 6 | uniform lowp vec4 size; 7 | uniform lowp vec4 angle; 8 | 9 | void main() 10 | { 11 | vec4 color1 = vec4(1, 1, 1, 1.); 12 | vec4 color2 = vec4(2.0, 2.0, 2.0, 1.); 13 | 14 | float x = var_texcoord0.x; 15 | float y = var_texcoord0.y; 16 | 17 | // Adjust the step functions to include a slope 18 | vec4 tint = mix(color1, color2, step(pos.x + angle.x * y, x)); 19 | tint = mix(tint, color1, step(pos.x+size.x + angle.x * y, x)); 20 | 21 | // Pre-multiply alpha since all runtime textures already are 22 | lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w); 23 | gl_FragColor = texture2D(texture_sampler, var_texcoord0.xy) * tint_pm; 24 | } 25 | -------------------------------------------------------------------------------- /sparkle_material/sparkle.material: -------------------------------------------------------------------------------- 1 | name: "sprite" 2 | tags: "tile" 3 | vertex_program: "/sparkle_material/sparkle.vp" 4 | fragment_program: "/sparkle_material/sparkle.fp" 5 | vertex_constants { 6 | name: "view_proj" 7 | type: CONSTANT_TYPE_VIEWPROJ 8 | } 9 | fragment_constants { 10 | name: "tint" 11 | type: CONSTANT_TYPE_USER 12 | value { 13 | x: 1.0 14 | y: 1.0 15 | z: 1.0 16 | w: 1.0 17 | } 18 | } 19 | fragment_constants { 20 | name: "pos" 21 | type: CONSTANT_TYPE_USER 22 | value { 23 | x: -0.6 24 | } 25 | } 26 | fragment_constants { 27 | name: "size" 28 | type: CONSTANT_TYPE_USER 29 | value { 30 | x: 0.3 31 | } 32 | } 33 | fragment_constants { 34 | name: "angle" 35 | type: CONSTANT_TYPE_USER 36 | value { 37 | x: 0.45 38 | } 39 | } 40 | samplers { 41 | name: "texture_sampler" 42 | wrap_u: WRAP_MODE_CLAMP_TO_EDGE 43 | wrap_v: WRAP_MODE_CLAMP_TO_EDGE 44 | filter_min: FILTER_MODE_MIN_DEFAULT 45 | filter_mag: FILTER_MODE_MAG_DEFAULT 46 | } 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](title.gif) 2 | # Simple Sparkle Effect for Defold 3 | 4 | Simple Sparkle Effect is Material for creating a sparkle or glare effect on the sprite. You can adjust parameters such as size, angle, and position in the material constants, as well as animate them via go.animate() 5 | 6 | ## Setup 7 | 8 | ### Dependency 9 | 10 | To integrate the **Sparkle Effect** extension into your own project, add this project as a [dependency](https://www.defold.com/manuals/libraries/) in your **Defold** game. Open your `game.project` file and add the following line to the dependencies field under the project section: 11 | 12 | > [https://github.com/ufgo/sparkle_effect/archive/master.zip](https://github.com/ufgo/sparkle_effect/archive/master.zip) 13 | 14 | 15 | ## Usage 16 | 17 | - I highly recommend using a single image in the atlas. 18 | - Adjust the constants in the material so that they match your sprite. 19 | - Copy the material in order to be able to edit the constants of the materials or set them via go.set() Adjust the constants in the material so that they match your sprite. 20 | - Set sparkle_material to sprite then animate it. 21 | 22 | ## Example 23 | 24 | ```lua 25 | function init(self) 26 | --shader animation 27 | local url = msg.url(nil, go.get_id(), "sprite") 28 | go.animate(url, "pos.x", go.PLAYBACK_LOOP_FORWARD, 0.8, go.EASING_INSINE, 0.7) 29 | end 30 | ``` 31 | 32 | ## License 33 | ![CC0](http://i.creativecommons.org/p/zero/1.0/88x31.png) -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Defold Protocol Buffer Text Files (https://github.com/github/linguist/issues/5091) 2 | *.animationset linguist-language=JSON5 3 | *.atlas linguist-language=JSON5 4 | *.camera linguist-language=JSON5 5 | *.collection linguist-language=JSON5 6 | *.collectionfactory linguist-language=JSON5 7 | *.collectionproxy linguist-language=JSON5 8 | *.collisionobject linguist-language=JSON5 9 | *.cubemap linguist-language=JSON5 10 | *.display_profiles linguist-language=JSON5 11 | *.factory linguist-language=JSON5 12 | *.font linguist-language=JSON5 13 | *.gamepads linguist-language=JSON5 14 | *.go linguist-language=JSON5 15 | *.gui linguist-language=JSON5 16 | *.input_binding linguist-language=JSON5 17 | *.label linguist-language=JSON5 18 | *.material linguist-language=JSON5 19 | *.mesh linguist-language=JSON5 20 | *.model linguist-language=JSON5 21 | *.particlefx linguist-language=JSON5 22 | *.render linguist-language=JSON5 23 | *.sound linguist-language=JSON5 24 | *.sprite linguist-language=JSON5 25 | *.spinemodel linguist-language=JSON5 26 | *.spinescene linguist-language=JSON5 27 | *.texture_profiles linguist-language=JSON5 28 | *.tilemap linguist-language=JSON5 29 | *.tilesource linguist-language=JSON5 30 | 31 | # Defold JSON Files 32 | *.buffer linguist-language=JSON 33 | 34 | # Defold GLSL Shaders 35 | *.fp linguist-language=GLSL 36 | *.vp linguist-language=GLSL 37 | 38 | # Defold Lua Files 39 | *.editor_script linguist-language=Lua 40 | *.render_script linguist-language=Lua 41 | *.script linguist-language=Lua 42 | *.gui_script linguist-language=Lua 43 | --------------------------------------------------------------------------------