diff options
author | Vitaliy <numzer0@yandex.ru> | 2020-10-25 20:01:03 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-25 18:01:03 +0100 |
commit | 707c8c1e95d8db2d84909e7957b4dc9138e05599 (patch) | |
tree | 84604fc1868c7b8ca8e977d5dd0485498500cdfe /client/shaders/object_shader | |
parent | 33b2c5f5b1c565171296f26395d803b08f4575e9 (diff) | |
download | minetest-707c8c1e95d8db2d84909e7957b4dc9138e05599.tar.gz minetest-707c8c1e95d8db2d84909e7957b4dc9138e05599.tar.bz2 minetest-707c8c1e95d8db2d84909e7957b4dc9138e05599.zip |
Shaders for Android (GLES 2) (#10506)
Shader support for OpenGL ES 2 devices (Android)
Co-authored-by: sfan5 <sfan5@live.de>
Diffstat (limited to 'client/shaders/object_shader')
-rw-r--r-- | client/shaders/object_shader/opengl_fragment.glsl | 11 | ||||
-rw-r--r-- | client/shaders/object_shader/opengl_vertex.glsl | 25 |
2 files changed, 20 insertions, 16 deletions
diff --git a/client/shaders/object_shader/opengl_fragment.glsl b/client/shaders/object_shader/opengl_fragment.glsl index 86d5c1c92..7ac182a63 100644 --- a/client/shaders/object_shader/opengl_fragment.glsl +++ b/client/shaders/object_shader/opengl_fragment.glsl @@ -8,6 +8,8 @@ uniform vec3 eyePosition; varying vec3 vNormal; varying vec3 vPosition; varying vec3 worldPosition; +varying lowp vec4 varColor; +varying mediump vec2 varTexCoord; varying vec3 eyeVec; varying float vIDiff; @@ -15,7 +17,7 @@ varying float vIDiff; const float e = 2.718281828459; const float BS = 10.0; const float fogStart = FOG_START; -const float fogShadingParameter = 1 / ( 1 - fogStart); +const float fogShadingParameter = 1.0 / (1.0 - fogStart); #ifdef ENABLE_TONE_MAPPING @@ -52,13 +54,14 @@ vec4 applyToneMapping(vec4 color) void main(void) { vec3 color; - vec2 uv = gl_TexCoord[0].st; + vec2 uv = varTexCoord.st; vec4 base = texture2D(baseTexture, uv).rgba; #ifdef USE_DISCARD // If alpha is zero, we can just discard the pixel. This fixes transparency - // on GPUs like GC7000L, where GL_ALPHA_TEST is not implemented in mesa. + // on GPUs like GC7000L, where GL_ALPHA_TEST is not implemented in mesa, + // and also on GLES 2, where GL_ALPHA_TEST is missing entirely. if (base.a == 0.0) { discard; } @@ -68,7 +71,7 @@ void main(void) vec4 col = vec4(color.rgb, base.a); - col.rgb *= gl_Color.rgb; + col.rgb *= varColor.rgb; col.rgb *= emissiveColor.rgb * vIDiff; diff --git a/client/shaders/object_shader/opengl_vertex.glsl b/client/shaders/object_shader/opengl_vertex.glsl index f8c1cd932..e44984dc8 100644 --- a/client/shaders/object_shader/opengl_vertex.glsl +++ b/client/shaders/object_shader/opengl_vertex.glsl @@ -1,4 +1,3 @@ -uniform mat4 mWorldViewProj; uniform mat4 mWorld; uniform vec3 eyePosition; @@ -7,6 +6,8 @@ uniform float animationTimer; varying vec3 vNormal; varying vec3 vPosition; varying vec3 worldPosition; +varying lowp vec4 varColor; +varying mediump vec2 varTexCoord; varying vec3 eyeVec; varying float vIDiff; @@ -18,31 +19,31 @@ float directional_ambient(vec3 normal) { vec3 v = normal * normal; - if (normal.y < 0) - return dot(v, vec3(0.670820f, 0.447213f, 0.836660f)); + if (normal.y < 0.0) + return dot(v, vec3(0.670820, 0.447213, 0.836660)); - return dot(v, vec3(0.670820f, 1.000000f, 0.836660f)); + return dot(v, vec3(0.670820, 1.000000, 0.836660)); } void main(void) { - gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; - gl_Position = mWorldViewProj * gl_Vertex; + varTexCoord = (mTexture * inTexCoord0).st; + gl_Position = mWorldViewProj * inVertexPosition; vPosition = gl_Position.xyz; - vNormal = gl_Normal; - worldPosition = (mWorld * gl_Vertex).xyz; - eyeVec = -(gl_ModelViewMatrix * gl_Vertex).xyz; + vNormal = inVertexNormal; + worldPosition = (mWorld * inVertexPosition).xyz; + eyeVec = -(mWorldView * inVertexPosition).xyz; #if (MATERIAL_TYPE == TILE_MATERIAL_PLAIN) || (MATERIAL_TYPE == TILE_MATERIAL_PLAIN_ALPHA) vIDiff = 1.0; #else // This is intentional comparison with zero without any margin. // If normal is not equal to zero exactly, then we assume it's a valid, just not normalized vector - vIDiff = length(gl_Normal) == 0.0 + vIDiff = length(inVertexNormal) == 0.0 ? 1.0 - : directional_ambient(normalize(gl_Normal)); + : directional_ambient(normalize(inVertexNormal)); #endif - gl_FrontColor = gl_BackColor = gl_Color; + varColor = inVertexColor; } |