You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
My bgfx api version: #define BGFX_API_VERSION UINT32_C(98)
This year, I used the fragment code from the 2019 iOS-bgfx project in an Android project and discovered some anomalies. These included aliasing issues when offsetting textures and precision issues with linear interpolation during image convolution operations.
Here are the issues and effects observed on Android devices.
aliasing issues
Effect result on iOS is:
Effect result on Android is:
The fragment code adapts the input texture to the specified area of the output texture, involving only UV calculations. I suspect the issue is due to insufficient precision of the UV values (it seems bgfx only supports medium precision). It could also be due to anomalies in texture linear interpolation.
Here is my UV handling code.
vec4 calCoord_Normal(vec2 p, vec4 viewSize, vec4 layerSize, vec4 canvasSize, float angle, vec4 center)
{
vec4 ret = vec4(p.x, p.y, 0., 0.);
// Normalized Local Rendering Experiment
// i_texcoord0 is calculated relative to the width and height of viewRect, so it needs to be converted to a normalized ratio in canvasRect.
vec2 normal_ratio = canvasSize.zw / viewSize.zw;
// Convert the UV values to the aspect ratio of canvasRect.
vec2 uv = p * normal_ratio;
uv += viewSize.xy;
float insideCanvas = step(0., uv.x) * step(uv.x, 1.) * step(0., uv.y) * step(uv.y, 1.);
ret.z = insideCanvas;
// Convert the UV coordinates to the layer coordinate system.
vec2 layer_origin = layerSize.xy;
uv = uv - layer_origin;
// Rotation
uv = rotate_Normal(uv, angle, center.xy, layerSize.w/layerSize.z);
float insideLayer = step(0., uv.x) * step(uv.x, 1.) * step(0., uv.y) * step(uv.y, 1.);
ret.w = insideLayer;
ret.xy = uv;
return ret;
}
Image convolution issues:
Effect result on iOS is:
Effect result on Android is:
I tried adding precision highp float; to the fragment code to increase float precision, but shaderc reported a compilation error. I also attempted to specify precision in the fragment value type with , but neither approach worked.
I also tried setting texture sampling interpolation flags in the “bgfx.setTexture” 、“bgfx::createTexture2D” functions, such as BGFX_SAMPLER_MAG_ANISOTROPIC and BGFX_SAMPLER_MIN_ANISOTROPIC. However, I did not find any flags for bilinear or trilinear interpolation. None of these attempts resolved the anomaly in the results.
I urgently need your help and look forward to your response. @bkaradzic
The text was updated successfully, but these errors were encountered:
BobliiExp
changed the title
The same fragment code has a significant precision difference when executed on iOS and Android.
[Android]The same fragment code has a significant precision difference when executed on iOS and Android.
Aug 1, 2024
Describe the bug
My bgfx api version: #define BGFX_API_VERSION UINT32_C(98)
This year, I used the fragment code from the 2019 iOS-bgfx project in an Android project and discovered some anomalies. These included aliasing issues when offsetting textures and precision issues with linear interpolation during image convolution operations.
Here are the issues and effects observed on Android devices.
Effect result on iOS is:
Effect result on Android is:
The fragment code adapts the input texture to the specified area of the output texture, involving only UV calculations. I suspect the issue is due to insufficient precision of the UV values (it seems bgfx only supports medium precision). It could also be due to anomalies in texture linear interpolation.
Here is my UV handling code.
Effect result on iOS is:
Effect result on Android is:
I tried adding precision highp float; to the fragment code to increase float precision, but shaderc reported a compilation error. I also attempted to specify precision in the fragment value type with , but neither approach worked.
I also tried setting texture sampling interpolation flags in the “bgfx.setTexture” 、“bgfx::createTexture2D” functions, such as BGFX_SAMPLER_MAG_ANISOTROPIC and BGFX_SAMPLER_MIN_ANISOTROPIC. However, I did not find any flags for bilinear or trilinear interpolation. None of these attempts resolved the anomaly in the results.
I urgently need your help and look forward to your response. @bkaradzic
The text was updated successfully, but these errors were encountered: