1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-11-09 19:45:21 +01:00

Introduce array textures for node rendering (#16574)

This commit is contained in:
sfan5
2025-11-01 17:21:41 +01:00
committed by GitHub
parent 1ead48c58b
commit de5ef4ca29
31 changed files with 777 additions and 187 deletions

View File

@@ -0,0 +1,43 @@
#ifdef USE_ARRAY_TEXTURE
uniform sampler2DArray baseTexture;
#else
uniform sampler2D baseTexture;
#endif
varying vec3 vNormal;
varying vec3 vPosition;
#ifdef GL_ES
varying lowp vec4 varColor;
varying mediump vec2 varTexCoord;
varying float varTexLayer;
#else
centroid varying vec4 varColor;
centroid varying vec2 varTexCoord;
centroid varying float varTexLayer; // actually int
#endif
void main(void)
{
vec2 uv = varTexCoord.st;
#ifdef USE_ARRAY_TEXTURE
vec4 base = texture(baseTexture, vec3(uv, varTexLayer)).rgba;
#else
vec4 base = texture2D(baseTexture, uv).rgba;
#endif
// Handle transparency by discarding pixel as appropriate.
#ifdef USE_DISCARD
if (base.a == 0.0)
discard;
#endif
#ifdef USE_DISCARD_REF
if (base.a < 0.5)
discard;
#endif
vec4 col = vec4(base.rgb * varColor.rgb, base.a);
gl_FragColor = col;
}

View File

@@ -0,0 +1,27 @@
varying vec3 vNormal;
varying vec3 vPosition;
#ifdef GL_ES
varying lowp vec4 varColor;
varying mediump vec2 varTexCoord;
varying float varTexLayer;
#else
centroid varying vec4 varColor;
centroid varying vec2 varTexCoord;
centroid varying float varTexLayer; // actually int
#endif
void main(void)
{
#ifdef USE_ARRAY_TEXTURE
varTexLayer = inVertexAux;
#endif
varTexCoord = inTexCoord0.st;
vec4 pos = inVertexPosition;
gl_Position = mWorldViewProj * pos;
vPosition = gl_Position.xyz;
vNormal = inVertexNormal;
vec4 color = inVertexColor;
varColor = clamp(color, 0.0, 1.0);
}

View File

@@ -1,4 +1,8 @@
uniform sampler2D baseTexture;
#ifdef USE_ARRAY_TEXTURE
uniform sampler2DArray baseTexture;
#else
uniform sampler2D baseTexture;
#endif
#define crackTexture texture1
uniform sampler2D crackTexture;
@@ -48,10 +52,12 @@ varying vec3 worldPosition;
#ifdef GL_ES
varying lowp vec4 varColor;
varying mediump vec2 varTexCoord;
varying float varTexLayer;
varying float nightRatio;
#else
centroid varying lowp vec4 varColor;
centroid varying vec2 varTexCoord;
centroid varying float varTexLayer; // actually int
centroid varying float nightRatio;
#endif
varying highp vec3 eyeVec;
@@ -431,10 +437,13 @@ void main(void)
{
vec2 uv = varTexCoord.st;
#ifdef USE_ARRAY_TEXTURE
vec4 base = texture(baseTexture, vec3(uv, varTexLayer)).rgba;
#else
vec4 base = texture2D(baseTexture, uv).rgba;
// 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,
// and also on GLES 2, where GL_ALPHA_TEST is missing entirely.
#endif
// Handle transparency by discarding pixel as appropriate.
#ifdef USE_DISCARD
if (base.a == 0.0)
discard;

View File

@@ -20,10 +20,12 @@ varying vec3 worldPosition;
#ifdef GL_ES
varying lowp vec4 varColor;
varying mediump vec2 varTexCoord;
varying float varTexLayer;
varying float nightRatio;
#else
centroid varying lowp vec4 varColor;
centroid varying vec4 varColor;
centroid varying vec2 varTexCoord;
centroid varying float varTexLayer; // actually int
centroid varying float nightRatio;
#endif
#ifdef ENABLE_DYNAMIC_SHADOWS
@@ -149,6 +151,9 @@ float snoise(vec3 p)
void main(void)
{
#ifdef USE_ARRAY_TEXTURE
varTexLayer = inVertexAux;
#endif
varTexCoord = inTexCoord0.st;
float disp_x;
@@ -181,6 +186,7 @@ void main(void)
pos.y += disp_z * 0.1;
pos.z += disp_z;
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS && ENABLE_WAVING_PLANTS
// bottom of plant doesn't wave
if (varTexCoord.y < 0.05) {
pos.x += disp_x;
pos.z += disp_z;

View File

@@ -1,4 +1,8 @@
uniform sampler2D baseTexture;
#ifdef USE_ARRAY_TEXTURE
uniform sampler2DArray baseTexture;
#else
uniform sampler2D baseTexture;
#endif
uniform vec3 dayLight;
uniform lowp vec4 fogColor;
@@ -41,8 +45,10 @@ varying vec3 worldPosition;
varying lowp vec4 varColor;
#ifdef GL_ES
varying mediump vec2 varTexCoord;
varying float varTexLayer;
#else
centroid varying vec2 varTexCoord;
centroid varying float varTexLayer; // actually int
#endif
varying highp vec3 eyeVec;
varying float nightRatio;
@@ -365,10 +371,13 @@ void main(void)
vec3 color;
vec2 uv = varTexCoord.st;
#ifdef USE_ARRAY_TEXTURE
vec4 base = texture(baseTexture, vec3(uv, varTexLayer)).rgba;
#else
vec4 base = texture2D(baseTexture, uv).rgba;
// 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,
// and also on GLES 2, where GL_ALPHA_TEST is missing entirely.
#endif
// Handle transparency by discarding pixel as appropriate.
#ifdef USE_DISCARD
if (base.a == 0.0)
discard;

View File

@@ -9,8 +9,10 @@ varying vec3 worldPosition;
varying lowp vec4 varColor;
#ifdef GL_ES
varying mediump vec2 varTexCoord;
varying float varTexLayer;
#else
centroid varying vec2 varTexCoord;
centroid varying float varTexLayer; // actually int
#endif
#ifdef ENABLE_DYNAMIC_SHADOWS
@@ -91,7 +93,11 @@ float directional_ambient(vec3 normal)
void main(void)
{
#ifdef USE_ARRAY_TEXTURE
varTexLayer = inVertexAux;
#endif
varTexCoord = (mTexture * vec4(inTexCoord0.xy, 1.0, 1.0)).st;
gl_Position = mWorldViewProj * inVertexPosition;
vPosition = gl_Position.xyz;

View File

@@ -1,3 +1,4 @@
// FIXME missing array texture handling
uniform sampler2D ColorMapSampler;
varying vec4 tPos;
@@ -10,7 +11,7 @@ centroid varying vec2 varTexCoord;
void main()
{
vec4 col = texture2D(ColorMapSampler, varTexCoord);
// FIXME: magic number???
if (col.a < 0.70)
discard;

View File

@@ -1,3 +1,4 @@
// FIXME missing array texture handling
uniform sampler2D ColorMapSampler;
varying vec4 tPos;