Shader compatibility

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

Shader compatibility

Postby dhanushka » Mon Oct 14, 2019 12:27 pm

I had my fragment shader as follows:

Code: Select all
#ifdef GL_ES
#define LOW lowp
#define MED mediump
#define HIGH highp
precision mediump float;
#else
#define MED
#define LOW
#define HIGH
#endif

varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;

uniform vec2 oneOverResolution;

vec2 frgCOverRes;

void main() {
   frgCOverRes = gl_FragCoord.xy*oneOverResolution.xy;
   frgCOverRes.y = -frgCOverRes.y+1;
   
   vec4 c = texture2D(u_texture, frgCOverRes);
   
   gl_FragColor = c;
}


Then I read that highp is not compatible with some devices. So I changed it to as follows:

Code: Select all
#ifdef GL_ES
precision mediump float;
#endif

varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;

uniform vec2 oneOverResolution;

vec2 frgCOverRes;

void main() {
   frgCOverRes = gl_FragCoord.xy*oneOverResolution.xy;
   frgCOverRes.y = -frgCOverRes.y+1.0;
   
   vec4 c = texture2D(u_texture, frgCOverRes);
   
   gl_FragColor = c;
}


It works in my phone (Huawei j6ii) and in emulator.
But I'm worried about it. Is the second code safe?

BTW my vertex shader (which I did not change) is as follows:

Code: Select all
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;

uniform mat4 u_projTrans;

varying vec4 v_color;
varying vec2 v_texCoords;

void main() {
    v_color = a_color;
    v_texCoords = a_texCoord0;
    gl_Position = u_projTrans * a_position;
}


Love LibGDX, Thank you!
dhanushka
 
Posts: 13
Joined: Fri Nov 25, 2016 8:55 am

Return to General Development

Who is online

Users browsing this forum: No registered users and 1 guest