# Sharp Sprite - RGSS for Defold

**URL:** <https://forum.defold.com/t/sharp-sprite-rgss-for-defold/66840>\
**Category:** The Defoldmine\
**Created:** [November 18, 2020, 8:35am UTC](https://forum.defold.com/t/sharp-sprite-rgss-for-defold/66840 "2020-11-18T08:35:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [November 18, 2020, 8:35am UTC](https://forum.defold.com/t/sharp-sprite-rgss-for-defold/66840/1 "2020-11-18T08:35:58Z")

</div>

Sharp Sprite is a collection of Defold materials that implements _Rotated Grid Super-Sampling (RGSS)_ for the Defold engine. If you use down-scaled high-resolution images in your game and you want to get rid of blurriness (because of mipmapping) or sharpness (because of disabled mipmapping), then RGSS is for you.

![The comparison](https://github.com/indiesoftby/defold-sharp-sprite/raw/main/demo2.gif)

### How does it work?

RGSS samples the texture multiple times with an offset on each sample and averages the results. For this, it uses a 4x MSAA rotated grid pattern, sometimes called 4 rooks.

It’s based on an original idea by Ben Golus - [Sharper Mipmapping using Shader Based Supersampling](https://medium.com/@bgolus/sharper-mipmapping-using-shader-based-supersampling-ed7aadb47bec).

The second solution, that included in this repo, uses _mip biasing_. Mip biasing tells the GPU to adjust what mip level to use. The shaders use mip bias of -1.0 that pushes the mip level one full mip back to make 2D sprites look much sharper. It’s almost as fast as the standard materials. Use this first. If it fits your project well, keep it and don’t try RGSS at all.

Also, **[check out the demo](https://indiesoftby.github.io/defold-sharp-sprite/)**.

### Notes

- RGSS requires the [OES\_standard\_derivatives](https://www.khronos.org/registry/OpenGL/extensions/OES/OES_standard_derivatives.txt) OpenGL extension to run. It’s universally supported by WebGL 1.0, by the most of OpenGL ES 2.0 devices ([Android stats](https://opengles.gpuinfo.org/listreports.php?extension=GL_OES_standard_derivatives) and by all [iOS devices](https://developer.apple.com/library/archive/documentation/OpenGLES/Conceptual/OpenGLESHardwarePlatformGuide_iOS/OpenGLESPlatforms/OpenGLESPlatforms.html)).
- On mobile GPUs, it can have a significant performance impact. **You should always check the game performance on your target devices!**

### Installation

[https://github.com/indiesoftby/defold-sharp-sprite](https://github.com/indiesoftby/defold-sharp-sprite)

---

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [December 4, 2020, 11:07pm UTC](https://forum.defold.com/t/sharp-sprite-rgss-for-defold/66840/2 "2020-12-04T23:07:01Z")

</div>

I have been testing RGSS across all my devices this week and found out that PowerVR-based devices (iPad Air 2, Samsung SmartTVs) output a corrupted image. It turned out that UV coords should have the **highp** precision in fragment shaders.

 ![PowerVR%20RGSS%20Bug](https://forum-defold.b-cdn.net/uploads/default/original/3X/5/f/5fb71392ed8a38ca621396ad113aec16dbd8824d.png)

Fixed in [0.1.1](https://github.com/indiesoftby/defold-sharp-sprite/commit/f810f83a940e9c03c229aa236597b534bd2fdb77).

---

<div class="post-metadata">

**Author:** ![morgerion](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/morgerion/32/6641_2.png) [@morgerion](https://forum.defold.com/u/morgerion)\
**Post date:** [June 3, 2021, 11:53am UTC](https://forum.defold.com/t/sharp-sprite-rgss-for-defold/66840/3 "2021-06-03T11:53:25Z")

</div>

There is a question about how the shader works when the sprite turns out to be larger rather than smaller.

Here’s an example:

 ![photo_2021-06-03_14-13-20](https://forum-defold.b-cdn.net/uploads/default/original/3X/3/d/3d58530254ff3929d2ff74c698a06aa1b780f1a6.jpeg)

The current shader causes pixelation (with the sampler Mag filter set to linear).  
Is there any way to fix this?

---

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [June 3, 2021, 12:57pm UTC](https://forum.defold.com/t/sharp-sprite-rgss-for-defold/66840/4 "2021-06-03T12:57:09Z")

</div>

> [@morgerion](#):
>
> The current shader causes pixelation (with the sampler Mag filter set to linear).  
> Is there any way to fix this

Oh. I’m pretty sure that you posted a screenshot where images are upscaled with the “nearest” filter. Could you please check? All Sharp Sprite’s materials [have linear filtering enabled](https://github.com/indiesoftby/defold-sharp-sprite/blob/main/sharp_sprite/materials/spine.material#L31).

I noticed that you use it on Spine models, so I made a quick test scene with x5 upscale to check: [Dropbox](https://www.dropbox.com/s/ka3q44v3s6o4hhm/jXQ5FVG.png?dl=0). The image with the RGSS material is the same as the image with built-in material with linear filtering. This is the best quality you can achieve with RGSS.

---

<div class="post-metadata">

**Author:** ![morgerion](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/morgerion/32/6641_2.png) [@morgerion](https://forum.defold.com/u/morgerion)\
**Post date:** [June 8, 2021, 9:13am UTC](https://forum.defold.com/t/sharp-sprite-rgss-for-defold/66840/5 "2021-06-08T09:13:25Z")

</div>

I purposely wrote that smoothing is linear, as I have checked it several times.  
Here are the material settings:

 ![Скриншот 2021-06-08 12.09.40](https://forum-defold.b-cdn.net/uploads/default/original/3X/e/3/e311a1c960f84a1809426156f82b963bd90e75b7.png)

I also checked that if I change the shader to builtins, everything starts working properly. So in my case it’s the shader that affects the smoothing setting.

---

<div class="post-metadata">

**Author:** ![morgerion](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/morgerion/32/6641_2.png) [@morgerion](https://forum.defold.com/u/morgerion)\
**Post date:** [June 18, 2021, 9:25am UTC](https://forum.defold.com/t/sharp-sprite-rgss-for-defold/66840/6 "2021-06-18T09:25:37Z")

</div>

**Let the fun continue!**

I snapped up the new build. It was discovered that:

1. no pixelation on the PC (Win 10).
2. no pixelation on the Samsung Note 10 phone.
3. Samsung A70 have pixelation!
4. Xiaomi have pixelation!
5. The iPhones have pixelation!

Which versions?  
Different hardware picks up the shader differently?

---

<div class="post-metadata">

**Author:** ![roccosaienz](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/roccosaienz/32/19991_2.png) [@roccosaienz](https://forum.defold.com/u/roccosaienz)\
**Post date:** [June 18, 2021, 9:53pm UTC](https://forum.defold.com/t/sharp-sprite-rgss-for-defold/66840/7 "2021-06-18T21:53:20Z")

</div>

I have a similar problem on Switch. I don’t know if this is related but I ended duplicating all builtin’s. Note that some builtin materials have NOT the texture\_sampler at all. Maybe the default value for the filter of a non-declared texture\_sampler is a bit random? Or maybe I missed completely the point of your problem 🙂

---

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [June 19, 2021, 2:35pm UTC](https://forum.defold.com/t/sharp-sprite-rgss-for-defold/66840/8 "2021-06-19T14:35:59Z")

</div>

> [@morgerion](#):
>
> - no pixelation on the PC (Win 10).
> - no pixelation on the Samsung Note 10 phone.
> - Samsung A70 have pixelation!
> - Xiaomi have pixelation!
> - The iPhones have pixelation!

Good catch! I’ll check it on all my test devices and find the reason next week.

---

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [June 26, 2021, 10:19pm UTC](https://forum.defold.com/t/sharp-sprite-rgss-for-defold/66840/9 "2021-06-26T22:19:03Z")

</div>

> [@morgerion](#):
>
> I snapped up the new build.

Are your atlases 4K in size or more? Do you have fixes from [this commit](https://github.com/indiesoftby/defold-sharp-sprite/commit/f810f83a940e9c03c229aa236597b534bd2fdb77)? I noticed that you have custom shaders for RGSS, i.e. not from the `sharp_sprite` directory.

I’m still [looking into](https://github.com/indiesoftby/defold-sharp-sprite/tree/feat/morgerion) this issue, but I can’t reproduce it on my devices.

---

<div class="post-metadata">

**Author:** ![morgerion](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/morgerion/32/6641_2.png) [@morgerion](https://forum.defold.com/u/morgerion)\
**Post date:** [June 28, 2021, 8:20pm UTC](https://forum.defold.com/t/sharp-sprite-rgss-for-defold/66840/10 "2021-06-28T20:20:53Z")

</div>

Are your atlases 4K in size or more? **Yes**  
Do you have fixes from this commit? **Yes**  
Are you using the custom version of RGSS? **No, i am using original**

---

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [July 28, 2021, 9:00am UTC](https://forum.defold.com/t/sharp-sprite-rgss-for-defold/66840/11 "2021-07-28T09:00:07Z")

</div>

The new version of Sharp Sprite 0.2.0 has been released! I added new materials and reworked the demo. New materials use _mip biasing_ to increase the performance of RGSS and not only for that. Mip biasing tells the GPU to adjust what mip level to use. The shaders use mip bias of -1.0 that pushes the mip level one full mip back to make 2D sprites look much sharper.

Now Sharp Sprite contains three sets of materials that are drop-in replacements for the standard 2D materials:

- **Mipmap Bias -1.0** (`/sharp_sprite/mipmap_bias/`): almost as fast as the standard materials. Use this first. If it fits your project well, keep it and don’t try RGSS at all.
- **RGSS** (`/sharp_sprite/rgss/`): slow, and requires OES\_standard\_derivatives (see docs), and doesn’t require mipmaps.
- **RGSS Mipmap Bias -1.0** (`/sharp_sprite/rgss_bias/`): a bit faster than RGSS, and requires mipmaps.

**BREAKING CHANGE:** previous materials moved into the subdirectory `/rgss/`.
