1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Shaders for Android (GLES 2) (#10506)

Shader support for OpenGL ES 2 devices (Android)

Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
Vitaliy 2020-10-25 20:01:03 +03:00 committed by GitHub
parent 33b2c5f5b1
commit 707c8c1e95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 233 additions and 120 deletions

View file

@ -1,4 +1,3 @@
uniform mat4 mWorldViewProj;
uniform mat4 mWorld;
// Color of the light emitted by the sun.
@ -16,7 +15,8 @@ varying vec3 vPosition;
// cameraOffset + worldPosition (for large coordinates the limits of float
// precision must be considered).
varying vec3 worldPosition;
varying lowp vec4 varColor;
varying mediump vec2 varTexCoord;
varying vec3 eyeVec;
// Color of the light emitted by the light sources.
@ -81,13 +81,13 @@ float snoise(vec3 p)
void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
varTexCoord = inTexCoord0.st;
float disp_x;
float disp_z;
// OpenGL < 4.3 does not support continued preprocessor lines
#if (MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES && ENABLE_WAVING_LEAVES) || (MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS && ENABLE_WAVING_PLANTS)
vec4 pos2 = mWorld * gl_Vertex;
vec4 pos2 = mWorld * inVertexPosition;
float tOffset = (pos2.x + pos2.y) * 0.001 + pos2.z * 0.002;
disp_x = (smoothTriangleWave(animationTimer * 23.0 + tOffset) +
smoothTriangleWave(animationTimer * 11.0 + tOffset)) * 0.4;
@ -96,43 +96,43 @@ void main(void)
smoothTriangleWave(animationTimer * 13.0 + tOffset)) * 0.5;
#endif
worldPosition = (mWorld * gl_Vertex).xyz;
worldPosition = (mWorld * inVertexPosition).xyz;
// OpenGL < 4.3 does not support continued preprocessor lines
#if (MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_OPAQUE || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_BASIC) && ENABLE_WAVING_WATER
// Generate waves with Perlin-type noise.
// The constants are calibrated such that they roughly
// correspond to the old sine waves.
vec4 pos = gl_Vertex;
vec4 pos = inVertexPosition;
vec3 wavePos = worldPosition + cameraOffset;
// The waves are slightly compressed along the z-axis to get
// wave-fronts along the x-axis.
wavePos.x /= WATER_WAVE_LENGTH * 3;
wavePos.z /= WATER_WAVE_LENGTH * 2;
wavePos.z += animationTimer * WATER_WAVE_SPEED * 10;
pos.y += (snoise(wavePos) - 1) * WATER_WAVE_HEIGHT * 5;
wavePos.x /= WATER_WAVE_LENGTH * 3.0;
wavePos.z /= WATER_WAVE_LENGTH * 2.0;
wavePos.z += animationTimer * WATER_WAVE_SPEED * 10.0;
pos.y += (snoise(wavePos) - 1.0) * WATER_WAVE_HEIGHT * 5.0;
gl_Position = mWorldViewProj * pos;
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES && ENABLE_WAVING_LEAVES
vec4 pos = gl_Vertex;
vec4 pos = inVertexPosition;
pos.x += disp_x;
pos.y += disp_z * 0.1;
pos.z += disp_z;
gl_Position = mWorldViewProj * pos;
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS && ENABLE_WAVING_PLANTS
vec4 pos = gl_Vertex;
if (gl_TexCoord[0].y < 0.05) {
vec4 pos = inVertexPosition;
if (varTexCoord.y < 0.05) {
pos.x += disp_x;
pos.z += disp_z;
}
gl_Position = mWorldViewProj * pos;
#else
gl_Position = mWorldViewProj * gl_Vertex;
gl_Position = mWorldViewProj * inVertexPosition;
#endif
vPosition = gl_Position.xyz;
eyeVec = -(gl_ModelViewMatrix * gl_Vertex).xyz;
eyeVec = -(mWorldView * inVertexPosition).xyz;
// Calculate color.
// Red, green and blue components are pre-multiplied with
@ -141,16 +141,16 @@ void main(void)
// The pre-baked colors are halved to prevent overflow.
vec4 color;
// The alpha gives the ratio of sunlight in the incoming light.
float nightRatio = 1 - gl_Color.a;
color.rgb = gl_Color.rgb * (gl_Color.a * dayLight.rgb +
nightRatio * artificialLight.rgb) * 2;
color.a = 1;
float nightRatio = 1.0 - inVertexColor.a;
color.rgb = inVertexColor.rgb * (inVertexColor.a * dayLight.rgb +
nightRatio * artificialLight.rgb) * 2.0;
color.a = 1.0;
// Emphase blue a bit in darker places
// See C++ implementation in mapblock_mesh.cpp final_color_blend()
float brightness = (color.r + color.g + color.b) / 3;
float brightness = (color.r + color.g + color.b) / 3.0;
color.b += max(0.0, 0.021 - abs(0.2 * brightness - 0.021) +
0.07 * brightness);
gl_FrontColor = gl_BackColor = clamp(color, 0.0, 1.0);
varColor = clamp(color, 0.0, 1.0);
}