mirror of
https://github.com/luanti-org/luanti.git
synced 2025-11-07 18:55:18 +01:00
Port most shaders to GLSL ES 3.0 (#16639)
This commit is contained in:
@@ -6,7 +6,7 @@ uniform sampler2D textureFlags;
|
||||
#define rightImage normalTexture
|
||||
#define maskImage textureFlags
|
||||
|
||||
varying mediump vec4 varTexCoord;
|
||||
VARYING_ mediump vec4 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
varying mediump vec4 varTexCoord;
|
||||
VARYING_ mediump vec4 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -5,11 +5,7 @@
|
||||
uniform sampler2D rendered;
|
||||
uniform vec2 texelSize0;
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -6,11 +6,7 @@ uniform sampler2D previous;
|
||||
uniform vec2 texelSize0;
|
||||
uniform mediump float bloomRadius;
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -5,11 +5,7 @@ uniform vec2 texelSize0;
|
||||
uniform mediump float bloomRadius;
|
||||
uniform mat3 bloomBlurWeights;
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
// smoothstep - squared
|
||||
float smstsq(float f)
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -5,11 +5,7 @@ uniform vec2 texelSize0;
|
||||
uniform mediump float bloomRadius;
|
||||
uniform mat3 bloomBlurWeights;
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
// smoothstep - squared
|
||||
float smstsq(float f)
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
uniform lowp vec4 fogColor;
|
||||
uniform float fogDistance;
|
||||
uniform float fogShadingParameter;
|
||||
varying highp vec3 eyeVec;
|
||||
VARYING_ highp vec3 eyeVec;
|
||||
|
||||
varying lowp vec4 varColor;
|
||||
VARYING_ lowp vec4 varColor;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
uniform lowp vec4 materialColor;
|
||||
|
||||
varying lowp vec4 varColor;
|
||||
VARYING_ lowp vec4 varColor;
|
||||
|
||||
varying highp vec3 eyeVec;
|
||||
VARYING_ highp vec3 eyeVec;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -8,14 +8,10 @@ uniform sampler2D rendered;
|
||||
uniform mediump float bloomStrength;
|
||||
uniform ExposureParams exposureParams;
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
#ifdef ENABLE_AUTO_EXPOSURE
|
||||
varying float exposure; // linear exposure factor, see vertex shader
|
||||
VARYING_ float exposure; // linear exposure factor, see vertex shader
|
||||
#endif
|
||||
|
||||
void main(void)
|
||||
|
||||
@@ -3,14 +3,10 @@
|
||||
|
||||
uniform sampler2D exposureMap;
|
||||
|
||||
varying float exposure;
|
||||
VARYING_ float exposure;
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
|
||||
void main(void)
|
||||
|
||||
@@ -3,16 +3,12 @@
|
||||
uniform sampler2D rendered;
|
||||
uniform vec2 texelSize0;
|
||||
|
||||
varying vec2 sampleNW;
|
||||
varying vec2 sampleNE;
|
||||
varying vec2 sampleSW;
|
||||
varying vec2 sampleSE;
|
||||
VARYING_ vec2 sampleNW;
|
||||
VARYING_ vec2 sampleNE;
|
||||
VARYING_ vec2 sampleSW;
|
||||
VARYING_ vec2 sampleSE;
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
/**
|
||||
Basic FXAA implementation based on the code on geeks3d.com with the
|
||||
@@ -63,7 +59,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
vec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 inverseVP,
|
||||
vec2 v_rgbNW, vec2 v_rgbNE,
|
||||
vec2 v_rgbSW, vec2 v_rgbSE,
|
||||
vec2 v_rgbM) {
|
||||
vec2 v_rgbM)
|
||||
{
|
||||
vec4 color;
|
||||
vec3 rgbNW = texture2D(tex, v_rgbNW).xyz;
|
||||
vec3 rgbNE = texture2D(tex, v_rgbNE).xyz;
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
uniform vec2 texelSize0;
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
varying vec2 sampleNW;
|
||||
varying vec2 sampleNE;
|
||||
varying vec2 sampleSW;
|
||||
varying vec2 sampleSE;
|
||||
VARYING_ vec2 sampleNW;
|
||||
VARYING_ vec2 sampleNE;
|
||||
VARYING_ vec2 sampleSW;
|
||||
VARYING_ vec2 sampleSE;
|
||||
|
||||
/*
|
||||
Based on
|
||||
|
||||
@@ -1,20 +1,14 @@
|
||||
#ifdef USE_ARRAY_TEXTURE
|
||||
uniform sampler2DArray baseTexture;
|
||||
uniform mediump 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
|
||||
VARYING_ vec3 vNormal;
|
||||
VARYING_ vec3 vPosition;
|
||||
CENTROID_ VARYING_ lowp vec4 varColor;
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
CENTROID_ VARYING_ float varTexLayer; // actually int
|
||||
|
||||
|
||||
void main(void)
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
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
|
||||
VARYING_ vec3 vNormal;
|
||||
VARYING_ vec3 vPosition;
|
||||
CENTROID_ VARYING_ lowp vec4 varColor;
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
CENTROID_ VARYING_ float varTexLayer; // actually int
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@ uniform sampler2D baseTexture;
|
||||
uniform sampler2D normalTexture;
|
||||
uniform vec3 yawVec;
|
||||
|
||||
varying lowp vec4 varColor;
|
||||
varying mediump vec2 varTexCoord;
|
||||
VARYING_ lowp vec4 varColor;
|
||||
VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
void main (void)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
uniform mat4 mWorld;
|
||||
|
||||
varying lowp vec4 varColor;
|
||||
varying mediump vec2 varTexCoord;
|
||||
VARYING_ lowp vec4 varColor;
|
||||
VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifdef USE_ARRAY_TEXTURE
|
||||
uniform sampler2DArray baseTexture;
|
||||
uniform mediump sampler2DArray baseTexture;
|
||||
#else
|
||||
uniform sampler2D baseTexture;
|
||||
#endif
|
||||
@@ -33,34 +33,27 @@ uniform float crackTextureScale;
|
||||
uniform float xyPerspectiveBias1;
|
||||
uniform vec3 shadow_tint;
|
||||
|
||||
varying float adj_shadow_strength;
|
||||
varying float cosLight;
|
||||
varying float f_normal_length;
|
||||
varying vec3 shadow_position;
|
||||
varying float perspective_factor;
|
||||
VARYING_ float adj_shadow_strength;
|
||||
VARYING_ float cosLight;
|
||||
VARYING_ float f_normal_length;
|
||||
VARYING_ vec3 shadow_position;
|
||||
VARYING_ float perspective_factor;
|
||||
#endif
|
||||
|
||||
|
||||
varying vec3 vNormal;
|
||||
varying vec3 vPosition;
|
||||
VARYING_ vec3 vNormal;
|
||||
VARYING_ vec3 vPosition;
|
||||
// World position in the visible world (i.e. relative to the cameraOffset.)
|
||||
// This can be used for many shader effects without loss of precision.
|
||||
// If the absolute position is required it can be calculated with
|
||||
// cameraOffset + worldPosition (for large coordinates the limits of float
|
||||
// precision must be considered).
|
||||
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;
|
||||
VARYING_ vec3 worldPosition;
|
||||
CENTROID_ VARYING_ lowp vec4 varColor;
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
CENTROID_ VARYING_ float varTexLayer; // actually int
|
||||
CENTROID_ VARYING_ float nightRatio;
|
||||
VARYING_ highp vec3 eyeVec;
|
||||
|
||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||
#if (defined(ENABLE_WATER_REFLECTIONS) && MATERIAL_WATER_REFLECTIONS && ENABLE_WAVING_WATER)
|
||||
|
||||
@@ -6,28 +6,22 @@ uniform vec3 dayLight;
|
||||
uniform highp vec3 cameraOffset;
|
||||
uniform float animationTimer;
|
||||
|
||||
varying vec3 vNormal;
|
||||
varying vec3 vPosition;
|
||||
VARYING_ vec3 vNormal;
|
||||
VARYING_ vec3 vPosition;
|
||||
// World position in the visible world (i.e. relative to the cameraOffset.)
|
||||
// This can be used for many shader effects without loss of precision.
|
||||
// If the absolute position is required it can be calculated with
|
||||
// cameraOffset + worldPosition (for large coordinates the limits of float
|
||||
// precision must be considered).
|
||||
varying vec3 worldPosition;
|
||||
VARYING_ vec3 worldPosition;
|
||||
// The centroid keyword ensures that after interpolation the texture coordinates
|
||||
// lie within the same bounds when MSAA is en- and disabled.
|
||||
// lie within the same bounds when MSAA is en- or disabled.
|
||||
// This fixes the stripes problem with nearest-neighbor textures and MSAA.
|
||||
#ifdef GL_ES
|
||||
varying lowp vec4 varColor;
|
||||
varying mediump vec2 varTexCoord;
|
||||
varying float varTexLayer;
|
||||
varying float nightRatio;
|
||||
#else
|
||||
centroid varying vec4 varColor;
|
||||
centroid varying vec2 varTexCoord;
|
||||
centroid varying float varTexLayer; // actually int
|
||||
centroid varying float nightRatio;
|
||||
#endif
|
||||
CENTROID_ VARYING_ lowp vec4 varColor;
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
CENTROID_ VARYING_ float varTexLayer; // actually int
|
||||
CENTROID_ VARYING_ float nightRatio;
|
||||
|
||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||
// shadow uniforms
|
||||
uniform vec3 v_LightDirection;
|
||||
@@ -38,15 +32,15 @@ centroid varying float nightRatio;
|
||||
uniform float f_timeofday;
|
||||
uniform vec4 CameraPos;
|
||||
|
||||
varying float cosLight;
|
||||
varying float normalOffsetScale;
|
||||
varying float adj_shadow_strength;
|
||||
varying float f_normal_length;
|
||||
varying vec3 shadow_position;
|
||||
varying float perspective_factor;
|
||||
VARYING_ float cosLight;
|
||||
VARYING_ float normalOffsetScale;
|
||||
VARYING_ float adj_shadow_strength;
|
||||
VARYING_ float f_normal_length;
|
||||
VARYING_ vec3 shadow_position;
|
||||
VARYING_ float perspective_factor;
|
||||
#endif
|
||||
|
||||
varying highp vec3 eyeVec;
|
||||
VARYING_ highp vec3 eyeVec;
|
||||
// Color of the light emitted by the light sources.
|
||||
const vec3 artificialLight = vec3(1.04, 1.04, 1.04);
|
||||
const float e = 2.718281828459;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifdef USE_ARRAY_TEXTURE
|
||||
uniform sampler2DArray baseTexture;
|
||||
uniform mediump sampler2DArray baseTexture;
|
||||
#else
|
||||
uniform sampler2D baseTexture;
|
||||
#endif
|
||||
@@ -26,34 +26,29 @@ uniform float animationTimer;
|
||||
uniform float xyPerspectiveBias1;
|
||||
uniform vec3 shadow_tint;
|
||||
|
||||
varying float adj_shadow_strength;
|
||||
varying float cosLight;
|
||||
varying float f_normal_length;
|
||||
varying vec3 shadow_position;
|
||||
varying float perspective_factor;
|
||||
VARYING_ float adj_shadow_strength;
|
||||
VARYING_ float cosLight;
|
||||
VARYING_ float f_normal_length;
|
||||
VARYING_ vec3 shadow_position;
|
||||
VARYING_ float perspective_factor;
|
||||
#endif
|
||||
|
||||
|
||||
varying vec3 vNormal;
|
||||
varying vec3 vPosition;
|
||||
VARYING_ vec3 vNormal;
|
||||
VARYING_ vec3 vPosition;
|
||||
// World position in the visible world (i.e. relative to the cameraOffset.)
|
||||
// This can be used for many shader effects without loss of precision.
|
||||
// If the absolute position is required it can be calculated with
|
||||
// cameraOffset + worldPosition (for large coordinates the limits of float
|
||||
// precision must be considered).
|
||||
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;
|
||||
VARYING_ vec3 worldPosition;
|
||||
VARYING_ lowp vec4 varColor;
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
CENTROID_ VARYING_ float varTexLayer; // actually int
|
||||
VARYING_ highp vec3 eyeVec;
|
||||
VARYING_ float nightRatio;
|
||||
|
||||
varying float vIDiff;
|
||||
VARYING_ float vIDiff;
|
||||
|
||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||
|
||||
@@ -467,5 +462,5 @@ void main(void)
|
||||
col = mix(fogColor * pow(fogColor / fogColorMax, vec4(2.0 * clarity)), col, clarity);
|
||||
col = vec4(col.rgb, base.a);
|
||||
|
||||
gl_FragData[0] = col;
|
||||
gl_FragColor = col;
|
||||
}
|
||||
|
||||
@@ -3,17 +3,12 @@ uniform vec3 dayLight;
|
||||
uniform float animationTimer;
|
||||
uniform lowp vec4 materialColor;
|
||||
|
||||
varying vec3 vNormal;
|
||||
varying vec3 vPosition;
|
||||
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_ vec3 vNormal;
|
||||
VARYING_ vec3 vPosition;
|
||||
VARYING_ vec3 worldPosition;
|
||||
VARYING_ lowp vec4 varColor;
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
CENTROID_ VARYING_ float varTexLayer; // actually int
|
||||
|
||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||
// shadow uniforms
|
||||
@@ -25,18 +20,18 @@ centroid varying float varTexLayer; // actually int
|
||||
uniform float f_timeofday;
|
||||
uniform vec4 CameraPos;
|
||||
|
||||
varying float cosLight;
|
||||
varying float adj_shadow_strength;
|
||||
varying float f_normal_length;
|
||||
varying vec3 shadow_position;
|
||||
varying float perspective_factor;
|
||||
VARYING_ float cosLight;
|
||||
VARYING_ float adj_shadow_strength;
|
||||
VARYING_ float f_normal_length;
|
||||
VARYING_ vec3 shadow_position;
|
||||
VARYING_ float perspective_factor;
|
||||
#endif
|
||||
|
||||
varying highp vec3 eyeVec;
|
||||
varying float nightRatio;
|
||||
VARYING_ highp vec3 eyeVec;
|
||||
VARYING_ float nightRatio;
|
||||
// Color of the light emitted by the light sources.
|
||||
const vec3 artificialLight = vec3(1.04, 1.04, 1.04);
|
||||
varying float vIDiff;
|
||||
VARYING_ float vIDiff;
|
||||
const float e = 2.718281828459;
|
||||
const float BS = 10.0;
|
||||
uniform float xyPerspectiveBias0;
|
||||
|
||||
@@ -21,14 +21,10 @@ uniform ExposureParams exposureParams;
|
||||
uniform lowp float bloomIntensity;
|
||||
uniform lowp float saturation;
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
#ifdef ENABLE_AUTO_EXPOSURE
|
||||
varying float exposure; // linear exposure factor, see vertex shader
|
||||
VARYING_ float exposure; // linear exposure factor, see vertex shader
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BLOOM
|
||||
|
||||
@@ -3,14 +3,10 @@
|
||||
|
||||
uniform sampler2D exposureMap;
|
||||
|
||||
varying float exposure;
|
||||
VARYING_ float exposure;
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
uniform sampler2D baseTexture;
|
||||
|
||||
varying lowp vec4 varColor;
|
||||
varying mediump vec2 varTexCoord;
|
||||
VARYING_ lowp vec4 varColor;
|
||||
VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec2 uv = varTexCoord.st;
|
||||
vec4 color = texture2D(baseTexture, uv);
|
||||
color.rgb *= varColor.rgb;
|
||||
gl_FragData[0] = color;
|
||||
fragColor = color;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
varying lowp vec4 varColor;
|
||||
varying mediump vec2 varTexCoord;
|
||||
VARYING_ lowp vec4 varColor;
|
||||
VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
|
||||
void main(void)
|
||||
{
|
||||
varTexCoord.st = inTexCoord0.st;
|
||||
gl_Position = inVertexPosition;
|
||||
}
|
||||
|
||||
@@ -18,11 +18,7 @@ uniform vec3 v_LightDirection;
|
||||
const vec3 v_LightDirection = vec3(0.0, -1.0, 0.0);
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
const float far = 1000.;
|
||||
float mapDepth(float depth)
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
|
||||
CENTROID_ VARYING_ mediump vec2 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
@@ -63,6 +63,8 @@ struct SFrameStats {
|
||||
};
|
||||
|
||||
struct SDriverLimits {
|
||||
//! Major and minor GL version
|
||||
core::vector2di GLVersion;
|
||||
//! Maximum amount of primitives that can be rendered in a single call
|
||||
u32 MaxPrimitiveCount = 0;
|
||||
//! Maximum width/height for a texture
|
||||
|
||||
@@ -2649,6 +2649,7 @@ ITexture *COpenGLDriver::addRenderTargetTextureCubemap(const u32 sideLen, const
|
||||
SDriverLimits COpenGLDriver::getLimits() const
|
||||
{
|
||||
SDriverLimits ret;
|
||||
ret.GLVersion = core::vector2di(Version / 100, Version % 100);
|
||||
ret.MaxPrimitiveCount = 0x7fffffff;
|
||||
ret.MaxTextureSize = MaxTextureSize;
|
||||
return ret;
|
||||
|
||||
@@ -1687,6 +1687,7 @@ ITexture *COpenGL3DriverBase::addRenderTargetTextureCubemap(const u32 sideLen, c
|
||||
SDriverLimits COpenGL3DriverBase::getLimits() const
|
||||
{
|
||||
SDriverLimits ret;
|
||||
ret.GLVersion = core::vector2di(Version.Major, Version.Minor);
|
||||
ret.MaxPrimitiveCount = Version.Spec == OpenGLSpec::ES ? UINT16_MAX : INT32_MAX;
|
||||
ret.MaxTextureSize = MaxTextureSize;
|
||||
ret.MaxArrayTextureImages = MaxArrayTextureLayers;
|
||||
|
||||
@@ -255,7 +255,7 @@ public:
|
||||
if (g_settings->get("antialiasing") == "ssaa") {
|
||||
constants["ENABLE_SSAA"] = 1;
|
||||
u16 ssaa_scale = std::max<u16>(2, g_settings->getU16("fsaa"));
|
||||
constants["SSAA_SCALE"] = ssaa_scale;
|
||||
constants["SSAA_SCALE"] = (float)ssaa_scale;
|
||||
}
|
||||
|
||||
if (g_settings->getBool("debanding"))
|
||||
@@ -405,11 +405,27 @@ public:
|
||||
m_uniform_factories.emplace_back(std::move(setter));
|
||||
}
|
||||
|
||||
bool supportsSampler2DArray() const override
|
||||
{
|
||||
auto *driver = RenderingEngine::get_video_driver();
|
||||
if (driver->getDriverType() == video::EDT_OGLES2) {
|
||||
// Funnily OpenGL ES 2.0 may support creating array textures
|
||||
// with an extension, but to practically use them you need 3.0.
|
||||
return m_have_glsl3;
|
||||
}
|
||||
return m_fully_programmable;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// The id of the thread that is allowed to use irrlicht directly
|
||||
std::thread::id m_main_thread;
|
||||
|
||||
// Driver has fully programmable pipeline?
|
||||
bool m_fully_programmable = false;
|
||||
// Driver supports GLSL (ES) 3.x?
|
||||
bool m_have_glsl3 = false;
|
||||
|
||||
// Cache of source shaders
|
||||
// This should be only accessed from the main thread
|
||||
SourceShaderCache m_sourcecache;
|
||||
@@ -459,6 +475,25 @@ ShaderSource::ShaderSource()
|
||||
// Add global stuff
|
||||
addShaderConstantSetter(std::make_unique<MainShaderConstantSetter>());
|
||||
addShaderUniformSetterFactory(std::make_unique<MainShaderUniformSetterFactory>());
|
||||
|
||||
auto *driver = RenderingEngine::get_video_driver();
|
||||
const auto driver_type = driver->getDriverType();
|
||||
if (driver_type != video::EDT_NULL) {
|
||||
auto *gpu = driver->getGPUProgrammingServices();
|
||||
if (!driver->queryFeature(video::EVDF_ARB_GLSL) || !gpu)
|
||||
throw ShaderException(gettext("GLSL is not supported by the driver"));
|
||||
|
||||
v2s32 glver = driver->getLimits().GLVersion;
|
||||
infostream << "ShaderSource: driver reports GL version " << glver.X << "."
|
||||
<< glver.Y << std::endl;
|
||||
assert(glver.X >= 2);
|
||||
m_fully_programmable = driver_type != video::EDT_OPENGL;
|
||||
if (driver_type == video::EDT_OGLES2) {
|
||||
m_have_glsl3 = glver.X >= 3;
|
||||
} else if (driver_type == video::EDT_OPENGL3) {
|
||||
// future TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ShaderSource::~ShaderSource()
|
||||
@@ -467,7 +502,6 @@ ShaderSource::~ShaderSource()
|
||||
|
||||
// Delete materials
|
||||
auto *gpu = RenderingEngine::get_video_driver()->getGPUProgrammingServices();
|
||||
assert(gpu);
|
||||
u32 n = 0;
|
||||
for (ShaderInfo &i : m_shaderinfo_cache) {
|
||||
if (!i.name.empty()) {
|
||||
@@ -639,24 +673,39 @@ void ShaderSource::generateShader(ShaderInfo &shaderinfo)
|
||||
}
|
||||
|
||||
auto *gpu = driver->getGPUProgrammingServices();
|
||||
if (!driver->queryFeature(video::EVDF_ARB_GLSL) || !gpu) {
|
||||
throw ShaderException(gettext("GLSL is not supported by the driver"));
|
||||
}
|
||||
assert(gpu);
|
||||
|
||||
// Create shaders header
|
||||
bool fully_programmable = driver->getDriverType() == video::EDT_OGLES2 || driver->getDriverType() == video::EDT_OPENGL3;
|
||||
std::ostringstream shaders_header;
|
||||
shaders_header
|
||||
<< std::noboolalpha
|
||||
<< std::showpoint // for GLSL ES
|
||||
;
|
||||
std::string vertex_header, fragment_header, geometry_header;
|
||||
if (fully_programmable) {
|
||||
if (m_fully_programmable) {
|
||||
const bool use_glsl3 = m_have_glsl3;
|
||||
if (driver->getDriverType() == video::EDT_OPENGL3) {
|
||||
shaders_header << "#version 150\n";
|
||||
assert(!use_glsl3);
|
||||
shaders_header << "#version 150\n"
|
||||
<< "#define CENTROID_ centroid\n";
|
||||
} else if (driver->getDriverType() == video::EDT_OGLES2) {
|
||||
if (use_glsl3) {
|
||||
shaders_header << "#version 300 es\n"
|
||||
<< "#define CENTROID_ centroid\n";
|
||||
} else {
|
||||
shaders_header << "#version 100\n"
|
||||
<< "#define CENTROID_\n";
|
||||
}
|
||||
} else {
|
||||
shaders_header << "#version 100\n";
|
||||
assert(false);
|
||||
}
|
||||
if (use_glsl3) {
|
||||
shaders_header << "#define ATTRIBUTE_(n) layout(location = n) in\n"
|
||||
"#define texture2D texture\n";
|
||||
} else {
|
||||
shaders_header << "#define ATTRIBUTE_(n) attribute\n";
|
||||
}
|
||||
|
||||
// cf. EVertexAttributes.h for the predefined ones
|
||||
vertex_header = R"(
|
||||
precision mediump float;
|
||||
@@ -665,21 +714,34 @@ void ShaderSource::generateShader(ShaderInfo &shaderinfo)
|
||||
uniform highp mat4 mWorldViewProj;
|
||||
uniform mediump mat4 mTexture;
|
||||
|
||||
attribute highp vec4 inVertexPosition;
|
||||
attribute mediump vec3 inVertexNormal;
|
||||
attribute lowp vec4 inVertexColor;
|
||||
attribute mediump float inVertexAux;
|
||||
attribute mediump vec2 inTexCoord0;
|
||||
attribute mediump vec2 inTexCoord1;
|
||||
attribute mediump vec4 inVertexTangent;
|
||||
attribute mediump vec4 inVertexBinormal;
|
||||
ATTRIBUTE_(0) highp vec4 inVertexPosition;
|
||||
ATTRIBUTE_(1) mediump vec3 inVertexNormal;
|
||||
ATTRIBUTE_(2) lowp vec4 inVertexColor;
|
||||
ATTRIBUTE_(3) mediump float inVertexAux;
|
||||
ATTRIBUTE_(4) mediump vec2 inTexCoord0;
|
||||
ATTRIBUTE_(5) mediump vec2 inTexCoord1;
|
||||
ATTRIBUTE_(6) mediump vec4 inVertexTangent;
|
||||
ATTRIBUTE_(7) mediump vec4 inVertexBinormal;
|
||||
)";
|
||||
if (use_glsl3) {
|
||||
vertex_header += "#define VARYING_ out\n";
|
||||
} else {
|
||||
vertex_header += "#define VARYING_ varying\n";
|
||||
}
|
||||
// Our vertex color has components reversed compared to what OpenGL
|
||||
// normally expects, so we need to take that into account.
|
||||
vertex_header += "#define inVertexColor (inVertexColor.bgra)\n";
|
||||
|
||||
fragment_header = R"(
|
||||
precision mediump float;
|
||||
)";
|
||||
if (use_glsl3) {
|
||||
fragment_header += "#define VARYING_ in\n"
|
||||
"#define gl_FragColor outFragColor\n"
|
||||
"layout(location = 0) out vec4 outFragColor;\n";
|
||||
} else {
|
||||
fragment_header += "#define VARYING_ varying\n";
|
||||
}
|
||||
} else {
|
||||
/* legacy OpenGL driver */
|
||||
shaders_header << R"(
|
||||
@@ -699,6 +761,13 @@ void ShaderSource::generateShader(ShaderInfo &shaderinfo)
|
||||
#define inVertexNormal gl_Normal
|
||||
#define inVertexTangent gl_MultiTexCoord1
|
||||
#define inVertexBinormal gl_MultiTexCoord2
|
||||
|
||||
#define VARYING_ varying
|
||||
#define CENTROID_ centroid
|
||||
)";
|
||||
fragment_header = R"(
|
||||
#define VARYING_ varying
|
||||
#define CENTROID_ centroid
|
||||
)";
|
||||
}
|
||||
|
||||
@@ -719,7 +788,7 @@ void ShaderSource::generateShader(ShaderInfo &shaderinfo)
|
||||
|
||||
ShaderConstants constants = input_const;
|
||||
|
||||
bool use_discard = fully_programmable;
|
||||
bool use_discard = m_fully_programmable;
|
||||
if (!use_discard) {
|
||||
// workaround for a certain OpenGL implementation lacking GL_ALPHA_TEST
|
||||
const char *renderer = reinterpret_cast<const char*>(GL.GetString(GL.RENDERER));
|
||||
@@ -753,6 +822,10 @@ void ShaderSource::generateShader(ShaderInfo &shaderinfo)
|
||||
std::string fragment_shader = m_sourcecache.getOrLoad(name, "opengl_fragment.glsl");
|
||||
std::string geometry_shader = m_sourcecache.getOrLoad(name, "opengl_geometry.glsl");
|
||||
|
||||
if (vertex_shader.empty() || fragment_shader.empty()) {
|
||||
throw ShaderException(fmtgettext("Failed to find \"%s\" shader files.", name.c_str()));
|
||||
}
|
||||
|
||||
vertex_shader = common_header + vertex_header + final_header + vertex_shader;
|
||||
fragment_shader = common_header + fragment_header + final_header + fragment_shader;
|
||||
const char *geometry_shader_ptr = nullptr; // optional
|
||||
@@ -772,9 +845,10 @@ void ShaderSource::generateShader(ShaderInfo &shaderinfo)
|
||||
if (shadermat == -1) {
|
||||
errorstream << "generateShader(): failed to generate shaders for "
|
||||
<< log_name << ", addHighLevelShaderMaterial failed." << std::endl;
|
||||
dumpShaderProgram(warningstream, "Vertex", vertex_shader);
|
||||
dumpShaderProgram(warningstream, "Fragment", fragment_shader);
|
||||
dumpShaderProgram(warningstream, "Geometry", geometry_shader);
|
||||
dumpShaderProgram(warningstream, "vertex", vertex_shader);
|
||||
dumpShaderProgram(warningstream, "fragment", fragment_shader);
|
||||
if (geometry_shader_ptr)
|
||||
dumpShaderProgram(warningstream, "geometry", geometry_shader);
|
||||
throw ShaderException(
|
||||
fmtgettext("Failed to compile the \"%s\" shader.", log_name.c_str()) +
|
||||
strgettext("\nCheck debug.txt for details."));
|
||||
@@ -819,20 +893,21 @@ u32 IShaderSource::getShader(const std::string &name,
|
||||
return getShader(name, input_const, base_mat);
|
||||
}
|
||||
|
||||
void dumpShaderProgram(std::ostream &output_stream,
|
||||
void dumpShaderProgram(std::ostream &os,
|
||||
const std::string &program_type, std::string_view program)
|
||||
{
|
||||
output_stream << program_type << " shader program:" << std::endl <<
|
||||
"----------------------------------" << std::endl;
|
||||
size_t pos = 0;
|
||||
size_t prev = 0;
|
||||
s16 line = 1;
|
||||
os << program_type << " shader program:\n"
|
||||
"----------------------------------" << '\n';
|
||||
size_t pos = 0, prev = 0;
|
||||
int nline = 1;
|
||||
while ((pos = program.find('\n', prev)) != std::string::npos) {
|
||||
output_stream << line++ << ": "<< program.substr(prev, pos - prev) <<
|
||||
std::endl;
|
||||
auto line = program.substr(prev, pos - prev);
|
||||
// Be smart about line number reset
|
||||
if (trim(line) == "#line 0")
|
||||
nline = 0;
|
||||
os << (nline++) << ": " << line << '\n';
|
||||
prev = pos + 1;
|
||||
}
|
||||
output_stream << line << ": " << program.substr(prev) << std::endl <<
|
||||
"End of " << program_type << " shader program." << std::endl <<
|
||||
" " << std::endl;
|
||||
os << nline << ": " << program.substr(prev) << '\n' <<
|
||||
"End of " << program_type << " shader program.\n \n" << std::flush;
|
||||
}
|
||||
|
||||
@@ -282,6 +282,11 @@ public:
|
||||
video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
|
||||
return getShader(name, ShaderConstants(), base_mat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns true if 'sampler2DArray' is supported in GLSL
|
||||
*/
|
||||
virtual bool supportsSampler2DArray() const = 0;
|
||||
};
|
||||
|
||||
class IWritableShaderSource : public IShaderSource {
|
||||
|
||||
@@ -892,16 +892,14 @@ static bool isWorldAligned(AlignStyle style, WorldAlignMode mode, NodeDrawType d
|
||||
}
|
||||
|
||||
/// @return maximum number of layers in array textures we can use (0 if unsupported)
|
||||
static size_t getArrayTextureMax(video::IVideoDriver *driver)
|
||||
static size_t getArrayTextureMax(IShaderSource *shdsrc)
|
||||
{
|
||||
// needs to actually support array textures
|
||||
auto *driver = RenderingEngine::get_video_driver();
|
||||
// needs to support creating array textures
|
||||
if (!driver->queryFeature(video::EVDF_TEXTURE_2D_ARRAY))
|
||||
return 0;
|
||||
// must not be the legacy driver, due to custom vertex format
|
||||
if (driver->getDriverType() == video::EDT_OPENGL)
|
||||
return 0;
|
||||
// doesn't work on GLES yet (TODO)
|
||||
if (driver->getDriverType() == video::EDT_OGLES2)
|
||||
// must support sampling from them
|
||||
if (!shdsrc->supportsSampler2DArray())
|
||||
return 0;
|
||||
// shadow shaders can't handle array textures yet (TODO)
|
||||
if (g_settings->getBool("enable_dynamic_shadows"))
|
||||
@@ -1050,7 +1048,7 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
|
||||
}
|
||||
}
|
||||
|
||||
const bool texture_2d_array = getArrayTextureMax(RenderingEngine::get_video_driver()) > 1;
|
||||
const bool texture_2d_array = getArrayTextureMax(shdsrc) > 1;
|
||||
const auto &getNodeShader = [&] (MaterialType my_material, NodeDrawType my_drawtype) {
|
||||
ShaderIds ret;
|
||||
ret.normal = shdsrc->getShader("nodes_shader", my_material, my_drawtype);
|
||||
@@ -1673,7 +1671,7 @@ void NodeDefManager::updateTextures(IGameDef *gamedef, void *progress_callback_a
|
||||
}
|
||||
|
||||
/* texture pre-loading stage */
|
||||
const size_t arraymax = getArrayTextureMax(RenderingEngine::get_video_driver());
|
||||
const size_t arraymax = getArrayTextureMax(shdsrc);
|
||||
// Group by size
|
||||
std::unordered_map<v2u32, std::vector<std::string_view>> sizes;
|
||||
if (arraymax > 1) {
|
||||
|
||||
Reference in New Issue
Block a user