question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Texture loading doesn't work on Xiaomi phones

See original GitHub issue

After adding the default noise texture via ‘Add uniform/texture’ menu and filling out the rest of the method that tiles the noise texture all over the screen, the app renders a black shader instead of repeating the texture. I’m not well familiarized with OpenGL, so apologies, if I’m doing something wrong. This issue has been reproduced on Xiaomi Mi4c and Xiaomi Redmi 4 Prime/Pro. The code that does the tiling itself is below.

#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif

uniform vec2 resolution;
uniform sampler2D noise;

void main( void )
{
vec2 tempPos= vec2(mod(gl_FragCoord.x,256.),mod(gl_FragCoord.y,256.));
vec3 uv = texture2D(noise, tempPos).rgb;

gl_FragColor = vec4( uv, 1.0 );
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fekgacommented, May 15, 2017

The docs.gl page could be included in the Readme to help old and new GLSL users 😉

1reaction
fekgacommented, May 4, 2017

The variable gl_FragCoord has the coordinates of your screen in pixels, it means that the integer part of them will be usable (e.g 1920*1080 -> vec2(1920.0,1080.0)) Dividing it by your resolution will return value between 0.0 and 1.0. This normalized value can be used to sample the texture. As you want to use the texture as sampling, use it’s resolution to divide the coordinates:

uniform sampler2D noise;

void main( void )
{
    vec2 noiseResolution = vec2(256.0); // == vec2(256.0,256.0)
    vec2 st = gl_FragCoord.xy/noiseResolution; // normalized to [vec2(0.0),vec2(1.0)]
    vec3 color = texture2D(noise, st).rgb; // sample the texture

    gl_FragColor = vec4( color, 1.0 ); // set the final fragment's color
}

ShaderEditor is set up to repeat your texture, so you actually don’t have to use the modulo function. This isn’t a GLSL setting, it’s an OpenGL setting. It would be nice to have different repeating/clamping settings, but in your case it will work as you want it.

PS: welcome to OpenGL and GLSL 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to enable Paper Reading Mode in Xiaomi phones
Enable Reading Mode. Tap on Paper. Press the small arrow button on the right-side of the Paper option. Adjust Color temperature and Texture....
Read more >
Android OpenGL some Texture not loading/reloading
I seem to have a bit of a strange problem, on one phone two textures dont load up at all as they appear...
Read more >
Android export for GLES2 doesn't include textures unless ETC ...
I'm testing a project I was developing in 3.0, just imported the whole thing into 3.1 alpha 2. I get a whole bunch...
Read more >
Xiaomi buyer's guide: Everything you need to know
Looking to buy something from Xiaomi but you don't know much about the brand? Here is a roundup of everything you need to...
Read more >
Phasmophobia not loading or throws 'Game Does Not Exist ...
Troubleshooting methods like verifying game files, lowering resolution/textures, using a VPN, and uninstalling and reinstalling the game don't ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found