Commit Graph

22 Commits

Author SHA1 Message Date
Jonas Kulla 541e24f678 Bitmap: Use more accurate HSV-based hue shift algorithm
The previously YIQ-based algorithm turned out to be both slow,
and horribly inaccurate.

Another algorithm based on rotating the color value in the
RGB cube along the diagonal axis was also considered, which was
acceptable in terms of accuracy, and very fast.

In the end, I decided on a HSV-based one, because it is by far
the most accurate one, while still being a tad faster than the
YIQ solution.
Algorithm source: gamedev.stackexchange.com/a/59808/24839

A very simple GPU time benchmark when shifting a 2048^2 bitmap:

         YIQ rot   RGB rot   HSV shift
radeon   13.4 ms   2.8 ms    11.4 ms
intel    13.0 ms   6.0 ms    10.5 ms

radeon: HD 3650 mobility
intel:  N3540 integrated (Baytrail)

However hue shifting has never shown up as a bottleneck before,
so these are more academic.
2016-10-30 08:50:45 +01:00
Jonas Kulla 2f95c0613a Shaders: Prefer arithmetic conditionals to branching 2014-12-31 18:52:20 +01:00
Jonas Kulla 373b90af00 Graphics: Optimize Viewport effect rendering
Using the kitchen sink plane shader for viewport effects, even
if only a small part of them are active, incurs great performance
loss on mobile, so split the rendering into multiple optional
passes which additionally use the blending hardware for faster
mixing (lerping).
Also, don't mirror the PingPong textures if the viewport effect
covers the entire screen area anyway.
2014-12-31 18:52:19 +01:00
Jonas Kulla 3c0a530eba Sprite: Add special case shader for translucent effect
Translucent sprites (opacity < 255) are very common,
so using a custom shader instead of the full blown effect one
helps a lot, especially on mobile.
2014-12-31 18:52:19 +01:00
Jonas Kulla a53163660f Shader: Refine preprocessing on GLES platform
Don't globally set float precision to mediump, only fragment
shaders need that and defining it for vertex shaders causes
tilemap cracks.

Also manually define low precision for variables that hold
color / alpha values.
2014-12-31 18:52:19 +01:00
David Salvisberg 8240f3333f Fixed hue shader turning pure white pixel to pure black on some GPUs. 2014-12-31 16:02:10 +01:00
Jonas Kulla 7790bd6c2c Implement RGSS2 Tilemap class (TilemapVX) 2014-08-15 15:20:32 +02:00
Jonas Kulla 56226c40c6 Tilemap: Use vertex shader based autotile animation strategy
Previously, we would just stuff the entire tilemap vertex data
four times into the buffers, with only the autotile vertices
offset according to the animation frame. This meant we could
prepare the buffers once, and then just bind a different offset
for each animation frame without any shader changes, but it also
lead to a huge amount of data being duplicated (and blowing up
the buffer sizes).

The new method only requires one buffer, and instead animates by
recognizing vertices belonging to autotiles in a custom vertex
shader, which offsets them on the fly according to the animation
index.

With giant tilemaps, this method would turn out to be a little
less efficient, but considering the Tilemap is planned to be
rewritten to only hold the range of tiles visible on the screen
in its buffers, the on the fly offsetting will become neglient,
while at the same time the amount of data we have to send to the
GPU everytime the tilemap is updated is greatly reduced; so a
net win in the end.
2014-07-06 19:44:19 +02:00
Jonas Kulla 1b0eb2797d BltShader: Correct algorithm as provided my /cremno
The color calculation is now actually 99% correct!
Fixes #14.
2014-01-31 10:08:05 +01:00
Edward Rudd a3c9f53335 GLSL 100 doesn't do automatic type conversions.. (int to float) 2013-12-31 16:26:49 -05:00
Jonas Kulla 3a5c4eba52 BltShader: More hacks! Yay!
Seriously, I'm about to kill myself over this..
Not even gonna bother with math-if optimization.
2013-12-20 07:40:34 +01:00
Jonas Kulla b756fa5526 Shader: Fix compile issue (thanks again Mesa!) 2013-11-02 15:27:51 +01:00
Jonas Kulla 906f9fae17 BitmapBlitShader: Try a bit harder
It's not really perfect yet, but it looks a lot closer
to what was there before.
2013-10-22 06:40:24 +02:00
Jonas Kulla 19c30e3ddd Fix shader code. Thanks Mesa!
On the other hand, the kind of shit fglrx
just lets through boggles the mind.
2013-10-02 15:00:17 +02:00
Jonas Kulla a54acce6b7 Implement Bitmap 'blur'
I was a bit confused at first because I thought Enterbrain
had actually implemented a full Gaussian blur, but nope,
just dumb averaging.
2013-10-01 18:12:52 +02:00
Jonas Kulla 9f26ff9fb0 Port over Bitmap 'radial_blur' from old SFML codebase
This implementation is also heaps better than the old
one as it doesn't use a (differently sized) aux texture,
meaning the Bitmap discards its old texture and aquires
one of same size, making reuse through the TexPool a
lot more likely. It also saves on the aux texture blits
and binding switches.

As the setup / resource acquisition far outweighs the
actual rendering cost, operation time is relatively
constant no matter how many divisions are used.
2013-10-01 12:03:20 +02:00
Jonas Kulla fa77726388 Remove unneeded shader uniform 2013-09-28 15:41:09 +02:00
Jonas Kulla 6b2c892280 Simplify shader 2013-09-23 14:12:11 +02:00
Jonas Kulla 7a6c05bba0 Implement animated flash tiles in Tilemap
Flash tiles start with an alpha of 60, which ramps up to 120
in 16 frames and 4 steps, then ramps down again over the same period.
2013-09-23 08:27:28 +02:00
Jonas Kulla 9e63fb6b64 Remove the remaining bits of deprecated GL usage
The drawing is now completely shader based, which makes away
with all usage of the depracted matrix stack. This also allows
us to do things like simple translations and texture coordinate
translation directly instead of doing everything indirectly
through matrices.

Fixed vertex attributes ('vertexPointer()' etc) are also
replaced with user defined attribute arrays.
2013-09-23 07:50:22 +02:00
Jonas Kulla 494fbccb6e Remove unused code 2013-09-01 18:17:19 +02:00
Jonas Kulla ff25887f41 Initial commit 2013-09-01 16:27:21 +02:00