mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 11:12:44 +01:00
graphics: Improve roundTexel implementation
This commit is contained in:
parent
1152439e65
commit
7b74a8f29f
@ -71,12 +71,14 @@ varying vec2 varying_tex_coord_min;
|
|||||||
varying vec2 varying_tex_coord_max;
|
varying vec2 varying_tex_coord_max;
|
||||||
|
|
||||||
vec2 roundTexel(vec2 p) {
|
vec2 roundTexel(vec2 p) {
|
||||||
// Many devices can't use highp in fragment shaders, so use only mediump here.
|
vec2 factor = 1.0 / (source_size * 256.0);
|
||||||
// According to the spec, mediump value range is -2**14 to 2**14 (16384).
|
if (factor.x > 0.0) {
|
||||||
// Some machines have higher precisions, but a very slight value difference causes
|
p.x -= mod(p.x + factor.x * 0.5, factor.x) - factor.x * 0.5;
|
||||||
// a different result of getColorAt. This function avoids such flakines by rounding values.
|
}
|
||||||
float max_mediump = 16384.0;
|
if (factor.y > 0.0) {
|
||||||
return floor(p * max_mediump + 0.5) / max_mediump;
|
p.y -= mod(p.y + factor.y * 0.5, factor.y) - factor.y * 0.5;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 getColorAt(vec2 pos) {
|
vec4 getColorAt(vec2 pos) {
|
||||||
|
Loading…
Reference in New Issue
Block a user