diff --git a/binaries/data/mods/mod/shaders/glsl/canvas2d.fs b/binaries/data/mods/mod/shaders/glsl/canvas2d.fs
index 7b4960721c..f70051631e 100644
--- a/binaries/data/mods/mod/shaders/glsl/canvas2d.fs
+++ b/binaries/data/mods/mod/shaders/glsl/canvas2d.fs
@@ -1,17 +1,12 @@
#version 110
+#include "canvas2d.h"
+
#include "common/fragment.h"
-uniform sampler2D tex;
-uniform vec4 colorAdd;
-uniform vec4 colorMul;
-uniform float grayscaleFactor;
-
-varying vec2 v_uv;
-
void main()
{
- vec4 colorTex = texture2D(tex, v_uv);
+ vec4 colorTex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(tex), v_uv);
vec3 grayColor = vec3(dot(vec3(0.3, 0.59, 0.11), colorTex.rgb));
OUTPUT_FRAGMENT_SINGLE_COLOR(clamp(mix(colorTex, vec4(grayColor, colorTex.a), grayscaleFactor) * colorMul + colorAdd, 0.0, 1.0));
}
diff --git a/binaries/data/mods/mod/shaders/glsl/canvas2d.h b/binaries/data/mods/mod/shaders/glsl/canvas2d.h
new file mode 100644
index 0000000000..e5f6d7422f
--- /dev/null
+++ b/binaries/data/mods/mod/shaders/glsl/canvas2d.h
@@ -0,0 +1,15 @@
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, tex)
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(vec4, transform)
+ UNIFORM(vec2, translation)
+ UNIFORM(vec4, colorAdd)
+ UNIFORM(vec4, colorMul)
+ UNIFORM(float, grayscaleFactor)
+END_DRAW_UNIFORMS
+
+VERTEX_OUTPUT(0, vec2, v_uv);
diff --git a/binaries/data/mods/mod/shaders/glsl/canvas2d.vs b/binaries/data/mods/mod/shaders/glsl/canvas2d.vs
index cefb143a50..d6c94d301a 100644
--- a/binaries/data/mods/mod/shaders/glsl/canvas2d.vs
+++ b/binaries/data/mods/mod/shaders/glsl/canvas2d.vs
@@ -1,15 +1,12 @@
#version 110
+#include "canvas2d.h"
+
#include "common/vertex.h"
-uniform vec4 transform;
-uniform vec2 translation;
-
VERTEX_INPUT_ATTRIBUTE(0, vec2, a_vertex);
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_uv0);
-varying vec2 v_uv;
-
void main()
{
v_uv = a_uv0;
diff --git a/binaries/data/mods/mod/shaders/glsl/cas.fs b/binaries/data/mods/mod/shaders/glsl/cas.fs
index 390fed1e4b..a96e98f9f7 100644
--- a/binaries/data/mods/mod/shaders/glsl/cas.fs
+++ b/binaries/data/mods/mod/shaders/glsl/cas.fs
@@ -20,13 +20,19 @@
// GLSL port of the CasFilter() (no scaling). https://github.com/GPUOpen-Effects/FidelityFX-CAS/blob/master/ffx-cas/ffx_cas.h
#include "common/fragment.h"
+#include "common/stage.h"
-uniform sampler2D renderedTex;
-uniform float width;
-uniform float height;
-uniform float sharpness;
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, renderedTex)
+END_DRAW_TEXTURES
-varying vec2 v_tex;
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(float, width)
+ UNIFORM(float, height)
+ UNIFORM(float, sharpness)
+END_DRAW_UNIFORMS
+
+VERTEX_OUTPUT(0, vec2, v_tex);
float saturate(float inputFloat)
{
@@ -38,7 +44,7 @@ vec3 saturate(vec3 inputFloat)
return vec3(saturate(inputFloat.x), saturate(inputFloat.y), saturate(inputFloat.z));
}
-vec3 sharpen()
+vec3 sharpen(sampler2D tex)
{
vec2 invSSize = vec2(1.0 / width, 1.0 / height);
@@ -46,15 +52,15 @@ vec3 sharpen()
// a b c
// d(e)f
// g h i
- vec3 a = texture2D(renderedTex, v_tex + vec2(-1.0, -1.0) * invSSize).rgb;
- vec3 b = texture2D(renderedTex, v_tex + vec2(0.0, -1.0) * invSSize).rgb;
- vec3 c = texture2D(renderedTex, v_tex + vec2(1.0, -1.0) * invSSize).rgb;
- vec3 d = texture2D(renderedTex, v_tex + vec2(-1.0, 0.0) * invSSize).rgb;
- vec3 e = texture2D(renderedTex, v_tex + vec2(0.0, 0.0) * invSSize).rgb;
- vec3 f = texture2D(renderedTex, v_tex + vec2(1.0, 0.0) * invSSize).rgb;
- vec3 g = texture2D(renderedTex, v_tex + vec2(-1.0, 1.0) * invSSize).rgb;
- vec3 h = texture2D(renderedTex, v_tex + vec2(0.0, 1.0) * invSSize).rgb;
- vec3 i = texture2D(renderedTex, v_tex + vec2(1.0, 1.0) * invSSize).rgb;
+ vec3 a = SAMPLE_2D(tex, v_tex + vec2(-1.0, -1.0) * invSSize).rgb;
+ vec3 b = SAMPLE_2D(tex, v_tex + vec2(0.0, -1.0) * invSSize).rgb;
+ vec3 c = SAMPLE_2D(tex, v_tex + vec2(1.0, -1.0) * invSSize).rgb;
+ vec3 d = SAMPLE_2D(tex, v_tex + vec2(-1.0, 0.0) * invSSize).rgb;
+ vec3 e = SAMPLE_2D(tex, v_tex + vec2(0.0, 0.0) * invSSize).rgb;
+ vec3 f = SAMPLE_2D(tex, v_tex + vec2(1.0, 0.0) * invSSize).rgb;
+ vec3 g = SAMPLE_2D(tex, v_tex + vec2(-1.0, 1.0) * invSSize).rgb;
+ vec3 h = SAMPLE_2D(tex, v_tex + vec2(0.0, 1.0) * invSSize).rgb;
+ vec3 i = SAMPLE_2D(tex, v_tex + vec2(1.0, 1.0) * invSSize).rgb;
// Soft min and max.
// a b c b
@@ -91,5 +97,5 @@ vec3 sharpen()
void main()
{
- OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(sharpen(), 1.0));
+ OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(sharpen(GET_DRAW_TEXTURE_2D(renderedTex)), 1.0));
}
diff --git a/binaries/data/mods/mod/shaders/glsl/common/fragment.h b/binaries/data/mods/mod/shaders/glsl/common/fragment.h
index 231bac7842..2b9d70a8bd 100644
--- a/binaries/data/mods/mod/shaders/glsl/common/fragment.h
+++ b/binaries/data/mods/mod/shaders/glsl/common/fragment.h
@@ -1,6 +1,9 @@
#ifndef INCLUDED_COMMON_FRAGMENT
#define INCLUDED_COMMON_FRAGMENT
+#include "common/texture.h"
+#include "common/uniform.h"
+
#define OUTPUT_FRAGMENT_SINGLE_COLOR(COLOR) \
gl_FragColor = COLOR
diff --git a/binaries/data/mods/mod/shaders/glsl/common/stage.h b/binaries/data/mods/mod/shaders/glsl/common/stage.h
new file mode 100644
index 0000000000..e9cabd8f93
--- /dev/null
+++ b/binaries/data/mods/mod/shaders/glsl/common/stage.h
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_COMMON_STAGE
+#define INCLUDED_COMMON_STAGE
+
+#include "common/uniform.h"
+
+#define VERTEX_OUTPUT(LOCATION, TYPE, NAME) \
+ varying TYPE NAME
+
+#endif // INCLUDED_COMMON_STAGE
diff --git a/binaries/data/mods/mod/shaders/glsl/common/texture.h b/binaries/data/mods/mod/shaders/glsl/common/texture.h
new file mode 100644
index 0000000000..8850febcdc
--- /dev/null
+++ b/binaries/data/mods/mod/shaders/glsl/common/texture.h
@@ -0,0 +1,8 @@
+#ifndef INCLUDED_COMMON_TEXTURE
+#define INCLUDED_COMMON_TEXTURE
+
+#define SAMPLE_2D texture2D
+#define SAMPLE_2D_SHADOW shadow2D
+#define SAMPLE_CUBE textureCube
+
+#endif // INCLUDED_COMMON_TEXTURE
diff --git a/binaries/data/mods/mod/shaders/glsl/common/uniform.h b/binaries/data/mods/mod/shaders/glsl/common/uniform.h
new file mode 100644
index 0000000000..0ba2d3135d
--- /dev/null
+++ b/binaries/data/mods/mod/shaders/glsl/common/uniform.h
@@ -0,0 +1,36 @@
+#ifndef INCLUDED_COMMON_UNIFORM
+#define INCLUDED_COMMON_UNIFORM
+
+#define BEGIN_DRAW_TEXTURES
+#define END_DRAW_TEXTURES
+#define NO_DRAW_TEXTURES
+
+#if STAGE_FRAGMENT
+ #define TEXTURE_2D(LOCATION, NAME) \
+ uniform sampler2D NAME;
+ #define TEXTURE_2D_SHADOW(LOCATION, NAME) \
+ uniform sampler2DShadow NAME;
+ #define TEXTURE_CUBE(LOCATION, NAME) \
+ uniform samplerCube NAME;
+#else
+ #define TEXTURE_2D(LOCATION, NAME)
+ #define TEXTURE_2D_SHADOW(LOCATION, NAME)
+ #define TEXTURE_CUBE(LOCATION, NAME)
+#endif
+
+#define GET_DRAW_TEXTURE_2D(NAME) \
+ NAME
+#define GET_DRAW_TEXTURE_2D_SHADOW(NAME) \
+ NAME
+#define GET_DRAW_TEXTURE_CUBE(NAME) \
+ NAME
+
+#define BEGIN_DRAW_UNIFORMS
+#define END_DRAW_UNIFORMS
+#define BEGIN_MATERIAL_UNIFORMS
+#define END_MATERIAL_UNIFORMS
+
+#define UNIFORM(TYPE, NAME) \
+ uniform TYPE NAME;
+
+#endif // INCLUDED_COMMON_UNIFORM
diff --git a/binaries/data/mods/mod/shaders/glsl/common/vertex.h b/binaries/data/mods/mod/shaders/glsl/common/vertex.h
index e234a23e43..56d75790ee 100644
--- a/binaries/data/mods/mod/shaders/glsl/common/vertex.h
+++ b/binaries/data/mods/mod/shaders/glsl/common/vertex.h
@@ -1,6 +1,8 @@
#ifndef INCLUDED_COMMON_VERTEX
#define INCLUDED_COMMON_VERTEX
+#include "common/uniform.h"
+
#define VERTEX_INPUT_ATTRIBUTE(LOCATION, TYPE, NAME) \
attribute TYPE NAME
diff --git a/binaries/data/mods/mod/shaders/glsl/fxaa.fs b/binaries/data/mods/mod/shaders/glsl/fxaa.fs
index e9caaeb9c9..b36221897c 100644
--- a/binaries/data/mods/mod/shaders/glsl/fxaa.fs
+++ b/binaries/data/mods/mod/shaders/glsl/fxaa.fs
@@ -7,6 +7,7 @@
// * Luma calculated by 3 components instead of the only green one.
#include "common/fragment.h"
+#include "common/stage.h"
#define FXAA_QUALITY__PRESET 10
@@ -604,11 +605,16 @@ vec4 FxaaPixelShader(
return vec4(FxaaTexTop(tex, posM).xyz, lumaM);
}
-uniform sampler2D renderedTex;
-uniform float width;
-uniform float height;
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, renderedTex)
+END_DRAW_TEXTURES
-varying vec2 v_tex;
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(float, width)
+ UNIFORM(float, height)
+END_DRAW_UNIFORMS
+
+VERTEX_OUTPUT(0, vec2, v_tex);
void main()
{
@@ -617,7 +623,7 @@ void main()
const float fxaaQualityEdgeThreshold = 0.125;
const float fxaaQualityEdgeThresholdMin = 0.0312;
OUTPUT_FRAGMENT_SINGLE_COLOR(FxaaPixelShader(
- v_tex, renderedTex,
+ v_tex, GET_DRAW_TEXTURE_2D(renderedTex),
vec2(1.0, 1.0) / vec2(width, height),
fxaaQualitySubpix,
fxaaQualityEdgeThreshold,
diff --git a/binaries/data/mods/mod/shaders/glsl/simple.vs b/binaries/data/mods/mod/shaders/glsl/simple.vs
index 4c2f4f0ed7..92202dfb19 100644
--- a/binaries/data/mods/mod/shaders/glsl/simple.vs
+++ b/binaries/data/mods/mod/shaders/glsl/simple.vs
@@ -1,12 +1,13 @@
#version 110
+#include "common/stage.h"
#include "common/vertex.h"
-varying vec2 v_tex;
-
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_uv0);
+VERTEX_OUTPUT(0, vec2, v_tex);
+
void main()
{
OUTPUT_VERTEX_POSITION(vec4(a_vertex, 1.0));
diff --git a/binaries/data/mods/public/shaders/glsl/bloom.fs b/binaries/data/mods/public/shaders/glsl/bloom.fs
index 17ed52eba8..55d1d23792 100644
--- a/binaries/data/mods/public/shaders/glsl/bloom.fs
+++ b/binaries/data/mods/public/shaders/glsl/bloom.fs
@@ -1,15 +1,22 @@
#version 110
#include "common/fragment.h"
+#include "common/stage.h"
-varying vec2 v_tex;
-uniform sampler2D renderedTex;
-uniform vec2 texSize;
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, renderedTex)
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(vec2, texSize)
+END_DRAW_UNIFORMS
+
+VERTEX_OUTPUT(0, vec2, v_tex);
void main()
{
#if BLOOM_NOP
- OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(texture2D(renderedTex, v_tex).rgb, 1.0));
+ OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(SAMPLE_2D(GET_DRAW_TEXTURE_2D(renderedTex), v_tex).rgb, 1.0));
#endif
#if BLOOM_PASS_H
@@ -18,7 +25,7 @@ void main()
for (int i = 0; i < 6; ++i)
{
- color += texture2D(renderedTex, v_tex_offs);
+ color += SAMPLE_2D(GET_DRAW_TEXTURE_2D(renderedTex), v_tex_offs);
v_tex_offs += vec2(0.004, 0.0);
}
@@ -31,10 +38,10 @@ void main()
for (int i = 0; i < 6; ++i)
{
- color += texture2D(renderedTex, v_tex_offs);
+ color += SAMPLE_2D(GET_DRAW_TEXTURE_2D(renderedTex), v_tex_offs);
v_tex_offs += vec2(0.0, 0.004);
}
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(color.rgb / 6.0, 1.0));
#endif
-}
\ No newline at end of file
+}
diff --git a/binaries/data/mods/public/shaders/glsl/common/fog.h b/binaries/data/mods/public/shaders/glsl/common/fog.h
index 4602818ee7..48b46cb5ec 100644
--- a/binaries/data/mods/public/shaders/glsl/common/fog.h
+++ b/binaries/data/mods/public/shaders/glsl/common/fog.h
@@ -1,12 +1,7 @@
-#ifndef INCLUDED_FOG
-#define INCLUDED_FOG
+#ifndef INCLUDED_COMMON_FOG
+#define INCLUDED_COMMON_FOG
-#if USE_FOG
-uniform vec3 fogColor;
-uniform vec2 fogParams;
-#endif
-
-vec3 applyFog(vec3 color)
+vec3 applyFog(vec3 color, vec3 fogColor, vec2 fogParams)
{
#if USE_FOG
float density = fogParams.x;
@@ -26,4 +21,4 @@ vec3 applyFog(vec3 color)
#endif
}
-#endif // INCLUDED_FOG
+#endif // INCLUDED_COMMON_FOG
diff --git a/binaries/data/mods/public/shaders/glsl/common/los_fragment.h b/binaries/data/mods/public/shaders/glsl/common/los_fragment.h
index b07900dead..c104e81cbe 100644
--- a/binaries/data/mods/public/shaders/glsl/common/los_fragment.h
+++ b/binaries/data/mods/public/shaders/glsl/common/los_fragment.h
@@ -1,21 +1,17 @@
-#ifndef INCLUDED_LOS_FRAGMENT
-#define INCLUDED_LOS_FRAGMENT
+#ifndef INCLUDED_COMMON_LOS_FRAGMENT
+#define INCLUDED_COMMON_LOS_FRAGMENT
+
+#include "common/texture.h"
#if !IGNORE_LOS
- uniform sampler2D losTex;
-
- varying vec2 v_los;
-#endif
-
-float getLOS()
+float getLOS(sampler2D losTex, vec2 uv)
{
-#if !IGNORE_LOS
- float los = texture2D(losTex, v_los).r;
+ float los = SAMPLE_2D(losTex, uv).r;
float threshold = 0.03;
return clamp(los - threshold, 0.0, 1.0) / (1.0 - threshold);
-#else
- return 1.0;
-#endif
-}
-#endif // INCLUDED_LOS_FRAGMENT
+ return 1.0;
+}
+#endif
+
+#endif // INCLUDED_COMMON_LOS_FRAGMENT
diff --git a/binaries/data/mods/public/shaders/glsl/common/los_vertex.h b/binaries/data/mods/public/shaders/glsl/common/los_vertex.h
index 5bcc038c40..41ffe05f55 100644
--- a/binaries/data/mods/public/shaders/glsl/common/los_vertex.h
+++ b/binaries/data/mods/public/shaders/glsl/common/los_vertex.h
@@ -1,17 +1,11 @@
-#ifndef INCLUDED_LOS_VERTEX
-#define INCLUDED_LOS_VERTEX
+#ifndef INCLUDED_COMMON_LOS_VERTEX
+#define INCLUDED_COMMON_LOS_VERTEX
#if !IGNORE_LOS
- uniform vec2 losTransform;
-
- varying vec2 v_los;
-#endif
-
-void calculateLOSCoordinates(vec2 position)
+vec2 calculateLOSCoordinates(vec2 position, vec2 losTransform)
{
-#if !IGNORE_LOS
- v_los = position * losTransform.x + losTransform.y;
-#endif
+ return position * losTransform.x + losTransform.y;
}
+#endif
-#endif // INCLUDED_LOS_VERTEX
+#endif // INCLUDED_COMMON_LOS_VERTEX
diff --git a/binaries/data/mods/public/shaders/glsl/common/shadows.h b/binaries/data/mods/public/shaders/glsl/common/shadows.h
new file mode 100644
index 0000000000..f5b122fa11
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/common/shadows.h
@@ -0,0 +1,40 @@
+#ifndef INCLUDED_SHADOWS
+#define INCLUDED_SHADOWS
+
+#include "common/stage.h"
+
+#if USE_SHADOW
+
+#if USE_SHADOW_SAMPLER
+#define SHADOWS_TEXTURES(START_LOCATION) \
+ TEXTURE_2D_SHADOW(START_LOCATION, shadowTex)
+#else
+#define SHADOWS_TEXTURES(START_LOCATION) \
+ TEXTURE_2D(START_LOCATION, shadowTex)
+#endif
+
+#if SHADOWS_CASCADE_COUNT == 1
+#define SHADOWS_UNIFORMS \
+ UNIFORM(vec4, cameraForward) \
+ UNIFORM(vec4, shadowScale) \
+ UNIFORM(mat4, shadowTransform) \
+ UNIFORM(float, shadowDistance)
+
+#define SHADOWS_VERTEX_OUTPUTS(START_LOCATION) \
+ VERTEX_OUTPUT(START_LOCATION + 0, float, v_depth); \
+ VERTEX_OUTPUT(START_LOCATION + 1, vec4, v_shadow);
+#else // SHADOWS_CASCADE_COUNT == 1
+#define SHADOWS_UNIFORMS \
+ UNIFORM(vec4, cameraForward) \
+ UNIFORM(vec4, shadowScale) \
+ UNIFORM(mat4, shadowTransforms[SHADOWS_CASCADE_COUNT]) \
+ UNIFORM(float, shadowDistances[SHADOWS_CASCADE_COUNT])
+
+#define SHADOWS_VERTEX_OUTPUTS(START_LOCATION) \
+ VERTEX_OUTPUT(START_LOCATION + 0, float, v_depth); \
+ VERTEX_OUTPUT(START_LOCATION + 1, vec4, v_shadow[SHADOWS_CASCADE_COUNT]);
+#endif // SHADOWS_CASCADE_COUNT == 1
+
+#endif // USE_SHADOW
+
+#endif // INCLUDED_SHADOWS
diff --git a/binaries/data/mods/public/shaders/glsl/common/shadows_fragment.h b/binaries/data/mods/public/shaders/glsl/common/shadows_fragment.h
index c73bed66ef..3b12802716 100644
--- a/binaries/data/mods/public/shaders/glsl/common/shadows_fragment.h
+++ b/binaries/data/mods/public/shaders/glsl/common/shadows_fragment.h
@@ -1,24 +1,7 @@
#ifndef INCLUDED_SHADOWS_FRAGMENT
#define INCLUDED_SHADOWS_FRAGMENT
-#if USE_SHADOW
- varying float v_depth;
- #if USE_SHADOW_SAMPLER
- uniform sampler2DShadow shadowTex;
- #if USE_SHADOW_PCF
- uniform vec4 shadowScale;
- #endif
- #else
- uniform sampler2D shadowTex;
- #endif
- #if SHADOWS_CASCADE_COUNT == 1
- uniform float shadowDistance;
- varying vec4 v_shadow;
- #else
- uniform float shadowDistances[SHADOWS_CASCADE_COUNT];
- varying vec4 v_shadow[SHADOWS_CASCADE_COUNT];
- #endif
-#endif
+#include "common/shadows.h"
float getShadowImpl(vec4 shadowVertex, float shadowBias)
{
@@ -30,17 +13,17 @@ float getShadowImpl(vec4 shadowVertex, float shadowBias)
vec4 size = vec4(offset + 1.0, 2.0 - offset);
vec4 weight = (vec4(1.0, 1.0, -0.5, -0.5) + (shadowVertex.xy - 0.5*offset).xyxy) * shadowScale.zwzw;
return (1.0/9.0)*dot(size.zxzx*size.wwyy,
- vec4(shadow2D(shadowTex, vec3(weight.zw, biasedShdwZ)).r,
- shadow2D(shadowTex, vec3(weight.xw, biasedShdwZ)).r,
- shadow2D(shadowTex, vec3(weight.zy, biasedShdwZ)).r,
- shadow2D(shadowTex, vec3(weight.xy, biasedShdwZ)).r));
+ vec4(SAMPLE_2D_SHADOW(GET_DRAW_TEXTURE_2D_SHADOW(shadowTex), vec3(weight.zw, biasedShdwZ)).r,
+ SAMPLE_2D_SHADOW(GET_DRAW_TEXTURE_2D_SHADOW(shadowTex), vec3(weight.xw, biasedShdwZ)).r,
+ SAMPLE_2D_SHADOW(GET_DRAW_TEXTURE_2D_SHADOW(shadowTex), vec3(weight.zy, biasedShdwZ)).r,
+ SAMPLE_2D_SHADOW(GET_DRAW_TEXTURE_2D_SHADOW(shadowTex), vec3(weight.xy, biasedShdwZ)).r));
#else
- return shadow2D(shadowTex, vec3(shadowVertex.xy, biasedShdwZ)).r;
+ return SAMPLE_2D_SHADOW(GET_DRAW_TEXTURE_2D_SHADOW(shadowTex), vec3(shadowVertex.xy, biasedShdwZ)).r;
#endif
#else
if (biasedShdwZ >= 1.0)
return 1.0;
- return (biasedShdwZ < texture2D(shadowTex, shadowVertex.xy).x ? 1.0 : 0.0);
+ return (biasedShdwZ < SAMPLE_2D(GET_DRAW_TEXTURE_2D(shadowTex), shadowVertex.xy).x ? 1.0 : 0.0);
#endif
#else
return 1.0;
diff --git a/binaries/data/mods/public/shaders/glsl/common/shadows_vertex.h b/binaries/data/mods/public/shaders/glsl/common/shadows_vertex.h
index aea278135a..23395b4136 100644
--- a/binaries/data/mods/public/shaders/glsl/common/shadows_vertex.h
+++ b/binaries/data/mods/public/shaders/glsl/common/shadows_vertex.h
@@ -1,40 +1,30 @@
#ifndef INCLUDED_SHADOWS_VERTEX
#define INCLUDED_SHADOWS_VERTEX
-#if USE_SHADOW
- uniform vec4 cameraForward;
- varying float v_depth;
- #if SHADOWS_CASCADE_COUNT == 1
- uniform mat4 shadowTransform;
- varying vec4 v_shadow;
- #else
- uniform mat4 shadowTransforms[SHADOWS_CASCADE_COUNT];
- varying vec4 v_shadow[SHADOWS_CASCADE_COUNT];
- #endif
+#include "common/shadows.h"
+
+vec4 calculatePositionInShadowSpaceImpl(
+ vec4 position, mat4 shadowTransform, vec4 shadowScale)
+{
+ vec4 shadow = shadowTransform * position;
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
- uniform vec4 shadowScale;
+ shadow.xy *= shadowScale.xy;
#endif
-#endif // USE_SHADOW
+ return shadow;
+}
void calculatePositionInShadowSpace(vec4 position)
{
#if USE_SHADOW
v_depth = dot(cameraForward.xyz, position.xyz) - cameraForward.w;
#if SHADOWS_CASCADE_COUNT == 1
- v_shadow = shadowTransform * position;
- #if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
- v_shadow.xy *= shadowScale.xy;
- #endif
+ v_shadow = calculatePositionInShadowSpaceImpl(position, shadowTransform, shadowScale);
#else
for (int cascade = 0; cascade < SHADOWS_CASCADE_COUNT; ++cascade)
{
- v_shadow[cascade] = shadowTransforms[cascade] * position;
- #if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
- v_shadow[cascade].xy *= shadowScale.xy;
- #endif
+ v_shadow[cascade] = calculatePositionInShadowSpaceImpl(
+ position, shadowTransforms[cascade], shadowScale);
}
-#else
-
#endif
#endif // USE_SHADOW
}
diff --git a/binaries/data/mods/public/shaders/glsl/debug_overlay.fs b/binaries/data/mods/public/shaders/glsl/debug_overlay.fs
index 69d54bb7cf..3c0b509bcd 100644
--- a/binaries/data/mods/public/shaders/glsl/debug_overlay.fs
+++ b/binaries/data/mods/public/shaders/glsl/debug_overlay.fs
@@ -1,19 +1,13 @@
#version 110
+#include "debug_overlay.h"
+
#include "common/fragment.h"
-#if DEBUG_TEXTURED
-uniform sampler2D baseTex;
-
-varying vec2 v_tex;
-#else
-uniform vec4 color;
-#endif
-
void main()
{
#if DEBUG_TEXTURED
- OUTPUT_FRAGMENT_SINGLE_COLOR(texture2D(baseTex, v_tex));
+ OUTPUT_FRAGMENT_SINGLE_COLOR(SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex));
#else
OUTPUT_FRAGMENT_SINGLE_COLOR(color);
#endif
diff --git a/binaries/data/mods/public/shaders/glsl/debug_overlay.h b/binaries/data/mods/public/shaders/glsl/debug_overlay.h
new file mode 100644
index 0000000000..7ba74fab7a
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/debug_overlay.h
@@ -0,0 +1,22 @@
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+#if DEBUG_TEXTURED
+ TEXTURE_2D(0, baseTex)
+#else
+ NO_DRAW_TEXTURES
+#endif
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, transform)
+#if DEBUG_TEXTURED
+ UNIFORM(vec2, textureTransform)
+#else
+ UNIFORM(vec4, color)
+#endif
+END_DRAW_UNIFORMS
+
+#if DEBUG_TEXTURED
+VERTEX_OUTPUT(0, vec2, v_tex);
+#endif
diff --git a/binaries/data/mods/public/shaders/glsl/debug_overlay.vs b/binaries/data/mods/public/shaders/glsl/debug_overlay.vs
index e2ec02c1a3..6fb385fd29 100644
--- a/binaries/data/mods/public/shaders/glsl/debug_overlay.vs
+++ b/binaries/data/mods/public/shaders/glsl/debug_overlay.vs
@@ -1,16 +1,9 @@
#version 110
+#include "debug_overlay.h"
+
#include "common/vertex.h"
-uniform mat4 transform;
-#if DEBUG_TEXTURED
-uniform vec2 textureTransform;
-#endif
-
-#if DEBUG_TEXTURED
-varying vec2 v_tex;
-#endif
-
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
#if DEBUG_TEXTURED
VERTEX_INPUT_ATTRIBUTE(1, vec3, a_uv0);
diff --git a/binaries/data/mods/public/shaders/glsl/dof.fs b/binaries/data/mods/public/shaders/glsl/dof.fs
index 5dae53ca06..09342d1b8d 100644
--- a/binaries/data/mods/public/shaders/glsl/dof.fs
+++ b/binaries/data/mods/public/shaders/glsl/dof.fs
@@ -1,48 +1,49 @@
#version 120
#include "common/fragment.h"
+#include "common/stage.h"
-uniform sampler2D renderedTex;
-uniform sampler2D depthTex;
-uniform sampler2D blurTex2;
-uniform sampler2D blurTex4;
-uniform sampler2D blurTex8;
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, renderedTex)
+ TEXTURE_2D(1, depthTex)
+ TEXTURE_2D(2, blurTex2)
+ TEXTURE_2D(3, blurTex4)
+ TEXTURE_2D(4, blurTex8)
+END_DRAW_TEXTURES
-uniform float width;
-uniform float height;
-
-uniform float zNear;
-uniform float zFar;
-
-uniform float brightness;
-uniform float hdr;
-uniform float saturation;
-uniform float bloom;
-
-varying vec2 v_tex;
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(float, width)
+ UNIFORM(float, height)
+ UNIFORM(float, zNear)
+ UNIFORM(float, zFar)
+ UNIFORM(float, brightness)
+ UNIFORM(float, hdr)
+ UNIFORM(float, saturation)
+ UNIFORM(float, bloom)
+END_DRAW_UNIFORMS
+VERTEX_OUTPUT(0, vec2, v_tex);
float linearizeDepth(float depth)
{
return -zFar * zNear / (depth * (zFar - zNear) - zFar);
}
-
void main(void)
{
- vec3 color = texture2D(renderedTex, v_tex).rgb;
+ vec3 color = SAMPLE_2D(GET_DRAW_TEXTURE_2D(renderedTex), v_tex).rgb;
- vec3 blur2 = texture2D(blurTex2, v_tex).rgb;
- vec3 blur4 = texture2D(blurTex4, v_tex).rgb;
- vec3 blur8 = texture2D(blurTex8, v_tex).rgb;
+ vec3 blur2 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(blurTex2), v_tex).rgb;
+ vec3 blur4 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(blurTex4), v_tex).rgb;
+ vec3 blur8 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(blurTex8), v_tex).rgb;
- float depth = texture2D(depthTex, v_tex).r;
+ float depth = SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), v_tex).r;
- float midDepth = texture2D(depthTex, vec2(0.5, 0.5)).r;
- midDepth += texture2D(depthTex, vec2(0.4, 0.4)).r;
- midDepth += texture2D(depthTex, vec2(0.4, 0.6)).r;
- midDepth += texture2D(depthTex, vec2(0.6, 0.4)).r;
- midDepth += texture2D(depthTex, vec2(0.6, 0.6)).r;
+ float midDepth = SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), vec2(0.5, 0.5)).r;
+ midDepth += SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), vec2(0.4, 0.4)).r;
+ midDepth += SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), vec2(0.4, 0.6)).r;
+ midDepth += SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), vec2(0.6, 0.4)).r;
+ midDepth += SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), vec2(0.6, 0.6)).r;
midDepth /= 5.0;
@@ -60,5 +61,3 @@ void main(void)
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(color, 1.0));
}
-
-
diff --git a/binaries/data/mods/public/shaders/glsl/dummy.fs b/binaries/data/mods/public/shaders/glsl/dummy.fs
index faabfadb7a..8d277e41f4 100644
--- a/binaries/data/mods/public/shaders/glsl/dummy.fs
+++ b/binaries/data/mods/public/shaders/glsl/dummy.fs
@@ -1,8 +1,8 @@
#version 110
-#include "common/fragment.h"
+#include "dummy.h"
-uniform vec4 color;
+#include "common/fragment.h"
void main()
{
diff --git a/binaries/data/mods/public/shaders/glsl/dummy.h b/binaries/data/mods/public/shaders/glsl/dummy.h
new file mode 100644
index 0000000000..6751710b08
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/dummy.h
@@ -0,0 +1,10 @@
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ NO_DRAW_TEXTURES
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, transform)
+ UNIFORM(vec4, color)
+END_DRAW_UNIFORMS
diff --git a/binaries/data/mods/public/shaders/glsl/dummy.vs b/binaries/data/mods/public/shaders/glsl/dummy.vs
index ec61cf3909..997743974c 100644
--- a/binaries/data/mods/public/shaders/glsl/dummy.vs
+++ b/binaries/data/mods/public/shaders/glsl/dummy.vs
@@ -1,11 +1,11 @@
#version 110
+#include "dummy.h"
+
#include "common/vertex.h"
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
-uniform mat4 transform;
-
void main()
{
OUTPUT_VERTEX_POSITION(transform * vec4(a_vertex, 1.0));
diff --git a/binaries/data/mods/public/shaders/glsl/foreground_overlay.fs b/binaries/data/mods/public/shaders/glsl/foreground_overlay.fs
index 91830d3064..e9670e6d36 100644
--- a/binaries/data/mods/public/shaders/glsl/foreground_overlay.fs
+++ b/binaries/data/mods/public/shaders/glsl/foreground_overlay.fs
@@ -1,12 +1,10 @@
#version 110
+#include "foreground_overlay.h"
+
#include "common/fragment.h"
-uniform sampler2D baseTex;
-uniform vec4 colorMul;
-varying vec2 v_tex;
-
void main()
{
- OUTPUT_FRAGMENT_SINGLE_COLOR(texture2D(baseTex, v_tex) * colorMul);
+ OUTPUT_FRAGMENT_SINGLE_COLOR(SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex) * colorMul);
}
diff --git a/binaries/data/mods/public/shaders/glsl/foreground_overlay.h b/binaries/data/mods/public/shaders/glsl/foreground_overlay.h
new file mode 100644
index 0000000000..1cd1b5a8c1
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/foreground_overlay.h
@@ -0,0 +1,12 @@
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, baseTex)
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, transform)
+ UNIFORM(vec4, colorMul)
+END_DRAW_UNIFORMS
+
+VERTEX_OUTPUT(0, vec2, v_tex);
diff --git a/binaries/data/mods/public/shaders/glsl/foreground_overlay.vs b/binaries/data/mods/public/shaders/glsl/foreground_overlay.vs
index c22ab5a620..1e3be662ff 100644
--- a/binaries/data/mods/public/shaders/glsl/foreground_overlay.vs
+++ b/binaries/data/mods/public/shaders/glsl/foreground_overlay.vs
@@ -1,11 +1,9 @@
#version 110
+#include "foreground_overlay.h"
+
#include "common/vertex.h"
-uniform mat4 transform;
-
-varying vec2 v_tex;
-
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_uv0);
diff --git a/binaries/data/mods/public/shaders/glsl/hdr.fs b/binaries/data/mods/public/shaders/glsl/hdr.fs
index dfbe20a404..cc50becbac 100644
--- a/binaries/data/mods/public/shaders/glsl/hdr.fs
+++ b/binaries/data/mods/public/shaders/glsl/hdr.fs
@@ -1,30 +1,33 @@
#version 120
#include "common/fragment.h"
+#include "common/stage.h"
-uniform sampler2D renderedTex;
-uniform sampler2D depthTex;
-uniform sampler2D blurTex2;
-uniform sampler2D blurTex4;
-uniform sampler2D blurTex8;
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, renderedTex)
+ TEXTURE_2D(1, depthTex)
+ TEXTURE_2D(2, blurTex2)
+ TEXTURE_2D(3, blurTex4)
+ TEXTURE_2D(4, blurTex8)
+END_DRAW_TEXTURES
-uniform float width;
-uniform float height;
-
-uniform float brightness;
-uniform float hdr;
-uniform float saturation;
-uniform float bloom;
-
-varying vec2 v_tex;
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(float, width)
+ UNIFORM(float, height)
+ UNIFORM(float, brightness)
+ UNIFORM(float, hdr)
+ UNIFORM(float, saturation)
+ UNIFORM(float, bloom)
+END_DRAW_UNIFORMS
+VERTEX_OUTPUT(0, vec2, v_tex);
void main(void)
{
- vec3 color = texture2D(renderedTex, v_tex).rgb;
- vec3 bloomv2 = texture2D(blurTex2, v_tex).rgb;
- vec3 bloomv4 = texture2D(blurTex4, v_tex).rgb;
- vec3 bloomv8 = texture2D(blurTex8, v_tex).rgb;
+ vec3 color = SAMPLE_2D(GET_DRAW_TEXTURE_2D(renderedTex), v_tex).rgb;
+ vec3 bloomv2 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(blurTex2), v_tex).rgb;
+ vec3 bloomv4 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(blurTex4), v_tex).rgb;
+ vec3 bloomv8 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(blurTex8), v_tex).rgb;
bloomv2 = max(bloomv2 - bloom, vec3(0.0));
bloomv4 = max(bloomv4 - bloom, vec3(0.0));
@@ -46,5 +49,3 @@ void main(void)
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(color, 1.0));
}
-
-
diff --git a/binaries/data/mods/public/shaders/glsl/los_interp.fs b/binaries/data/mods/public/shaders/glsl/los_interp.fs
index cbafad6c39..fa48eebdae 100644
--- a/binaries/data/mods/public/shaders/glsl/los_interp.fs
+++ b/binaries/data/mods/public/shaders/glsl/los_interp.fs
@@ -1,18 +1,13 @@
#version 110
+#include "los_interp.h"
+
#include "common/fragment.h"
-varying vec2 v_tex;
-
-uniform sampler2D losTex1, losTex2;
-
-uniform float delta;
-
-
void main(void)
{
- vec4 los2 = texture2D(losTex1, v_tex).rrrr;
- vec4 los1 = texture2D(losTex2, v_tex).rrrr;
+ vec4 los2 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(losTex1), v_tex).rrrr;
+ vec4 los1 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(losTex2), v_tex).rrrr;
OUTPUT_FRAGMENT_SINGLE_COLOR(mix(los1, los2, clamp(delta, 0.0, 1.0)));
}
diff --git a/binaries/data/mods/public/shaders/glsl/los_interp.h b/binaries/data/mods/public/shaders/glsl/los_interp.h
new file mode 100644
index 0000000000..e5c6921785
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/los_interp.h
@@ -0,0 +1,14 @@
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, losTex1)
+ TEXTURE_2D(1, losTex2)
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, transform)
+ UNIFORM(vec2, losTransform)
+ UNIFORM(float, delta)
+END_DRAW_UNIFORMS
+
+VERTEX_OUTPUT(0, vec2, v_tex);
diff --git a/binaries/data/mods/public/shaders/glsl/los_interp.vs b/binaries/data/mods/public/shaders/glsl/los_interp.vs
index bcc9a065d2..81813a3b67 100644
--- a/binaries/data/mods/public/shaders/glsl/los_interp.vs
+++ b/binaries/data/mods/public/shaders/glsl/los_interp.vs
@@ -1,13 +1,9 @@
#version 110
+#include "los_interp.h"
+
#include "common/vertex.h"
-uniform mat4 transform;
-uniform vec2 losTransform;
-
-varying vec2 v_tex;
-varying vec2 v_los;
-
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_uv0);
diff --git a/binaries/data/mods/public/shaders/glsl/minimap.fs b/binaries/data/mods/public/shaders/glsl/minimap.fs
index efbb751949..0018b7eece 100644
--- a/binaries/data/mods/public/shaders/glsl/minimap.fs
+++ b/binaries/data/mods/public/shaders/glsl/minimap.fs
@@ -1,27 +1,17 @@
#version 110
+#include "minimap.h"
+
#include "common/fragment.h"
-#if MINIMAP_BASE || MINIMAP_LOS
-uniform sampler2D baseTex;
-#endif
-
-#if MINIMAP_BASE || MINIMAP_LOS
-varying vec2 v_tex;
-#endif
-
-#if MINIMAP_POINT
-varying vec3 color;
-#endif
-
void main()
{
#if MINIMAP_BASE
- OUTPUT_FRAGMENT_SINGLE_COLOR(texture2D(baseTex, v_tex));
+ OUTPUT_FRAGMENT_SINGLE_COLOR(SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex));
#endif
#if MINIMAP_LOS
- OUTPUT_FRAGMENT_SINGLE_COLOR(texture2D(baseTex, v_tex).rrrr);
+ OUTPUT_FRAGMENT_SINGLE_COLOR(SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex).rrrr);
#endif
#if MINIMAP_POINT
diff --git a/binaries/data/mods/public/shaders/glsl/minimap.h b/binaries/data/mods/public/shaders/glsl/minimap.h
new file mode 100644
index 0000000000..0a4f1b3986
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/minimap.h
@@ -0,0 +1,26 @@
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+#if MINIMAP_BASE || MINIMAP_LOS
+ TEXTURE_2D(0, baseTex)
+#else
+ NO_DRAW_TEXTURES
+#endif
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(vec4, transform)
+ UNIFORM(vec4, translation)
+ UNIFORM(vec4, textureTransform)
+#if MINIMAP_POINT && USE_GPU_INSTANCING
+ UNIFORM(float, width)
+#endif
+END_DRAW_UNIFORMS
+
+#if MINIMAP_BASE || MINIMAP_LOS
+VERTEX_OUTPUT(0, vec2, v_tex);
+#endif
+
+#if MINIMAP_POINT
+VERTEX_OUTPUT(0, vec3, color);
+#endif
diff --git a/binaries/data/mods/public/shaders/glsl/minimap.vs b/binaries/data/mods/public/shaders/glsl/minimap.vs
index 2b1dbb1c02..55c9b7fa70 100644
--- a/binaries/data/mods/public/shaders/glsl/minimap.vs
+++ b/binaries/data/mods/public/shaders/glsl/minimap.vs
@@ -1,20 +1,13 @@
#version 110
+#include "minimap.h"
+
#include "common/vertex.h"
-uniform vec4 transform;
-uniform vec4 translation;
-uniform vec4 textureTransform;
-#if MINIMAP_POINT && USE_GPU_INSTANCING
-uniform float width;
-#endif
-
VERTEX_INPUT_ATTRIBUTE(0, vec2, a_vertex);
-
#if MINIMAP_BASE || MINIMAP_LOS
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_uv0);
#endif
-
#if MINIMAP_POINT
VERTEX_INPUT_ATTRIBUTE(1, vec3, a_color);
#if USE_GPU_INSTANCING
@@ -22,14 +15,6 @@ VERTEX_INPUT_ATTRIBUTE(2, vec2, a_uv1);
#endif
#endif
-#if MINIMAP_BASE || MINIMAP_LOS
-varying vec2 v_tex;
-#endif
-
-#if MINIMAP_POINT
-varying vec3 color;
-#endif
-
void main()
{
#if MINIMAP_BASE || MINIMAP_LOS
diff --git a/binaries/data/mods/public/shaders/glsl/model_common.fs b/binaries/data/mods/public/shaders/glsl/model_common.fs
index c94afb514a..bfbcf8ae5c 100644
--- a/binaries/data/mods/public/shaders/glsl/model_common.fs
+++ b/binaries/data/mods/public/shaders/glsl/model_common.fs
@@ -1,59 +1,13 @@
#version 120
+#include "model_common.h"
+
#include "common/debug_fragment.h"
#include "common/fog.h"
#include "common/fragment.h"
#include "common/los_fragment.h"
#include "common/shadows_fragment.h"
-uniform sampler2D baseTex;
-uniform sampler2D aoTex;
-uniform sampler2D normTex;
-uniform sampler2D specTex;
-
-#if USE_OBJECTCOLOR
- uniform vec3 objectColor;
-#else
-#if USE_PLAYERCOLOR
- uniform vec3 playerColor;
-#endif
-#endif
-
-uniform vec3 shadingColor;
-uniform vec3 ambient;
-uniform vec3 sunColor;
-uniform vec3 sunDir;
-
-varying vec4 v_lighting;
-varying vec2 v_tex;
-
-#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO
- varying vec2 v_tex2;
-#endif
-
-#if USE_SPECULAR
- uniform float specularPower;
- uniform vec3 specularColor;
-#endif
-
-#if USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX || USE_AO
- uniform vec4 effectSettings;
-#endif
-
-#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX
- varying vec4 v_normal;
- #if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX)
- varying vec4 v_tangent;
- //varying vec3 v_bitangent;
- #endif
- #if USE_SPECULAR || USE_SPECULAR_MAP
- varying vec3 v_half;
- #endif
- #if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX
- varying vec3 v_eyeVec;
- #endif
-#endif
-
void main()
{
vec2 coord = v_tex;
@@ -65,7 +19,7 @@ void main()
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX
{
- float h = texture2D(normTex, coord).a;
+ float h = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normTex), coord).a;
vec3 eyeDir = normalize(v_eyeVec * tbn);
float dist = length(v_eyeVec);
@@ -88,19 +42,19 @@ void main()
t = (h < height) ? s : 0.0;
vec2 temp = (h < height) ? move : nil;
coord += temp;
- h = texture2D(normTex, coord).a;
+ h = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normTex), coord).a;
}
// Move back to where we collided with the surface.
// This assumes the surface is linear between the sample point before we
// intersect the surface and after we intersect the surface
- float hp = texture2D(normTex, coord - move).a;
+ float hp = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normTex), coord - move).a;
coord -= move * ((h - height) / (s + h - hp));
}
}
#endif
- vec4 tex = texture2D(baseTex, coord);
+ vec4 tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), coord);
// Alpha-test as early as possible
#ifdef REQUIRE_ALPHA_GEQUAL
@@ -117,12 +71,10 @@ void main()
vec3 texdiffuse = tex.rgb;
// Apply-coloring based on texture alpha
- #if USE_OBJECTCOLOR
- texdiffuse *= mix(objectColor, vec3(1.0, 1.0, 1.0), tex.a);
- #else
#if USE_PLAYERCOLOR
- texdiffuse *= mix(playerColor, vec3(1.0, 1.0, 1.0), tex.a);
- #endif
+ texdiffuse *= mix(playerColor.rgb, vec3(1.0, 1.0, 1.0), tex.a);
+ #elif USE_OBJECTCOLOR
+ texdiffuse *= mix(objectColor, vec3(1.0, 1.0, 1.0), tex.a);
#endif
#if USE_SPECULAR || USE_SPECULAR_MAP || USE_NORMAL_MAP
@@ -130,7 +82,7 @@ void main()
#endif
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_NORMAL_MAP
- vec3 ntex = texture2D(normTex, coord).rgb * 2.0 - 1.0;
+ vec3 ntex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normTex), coord).rgb * 2.0 - 1.0;
ntex.y = -ntex.y;
normal = normalize(tbn * ntex);
vec3 bumplight = max(dot(-sunDir, normal), 0.0) * sunColor;
@@ -144,7 +96,7 @@ void main()
vec3 specCol;
float specPow;
#if USE_SPECULAR_MAP
- vec4 s = texture2D(specTex, coord);
+ vec4 s = SAMPLE_2D(GET_DRAW_TEXTURE_2D(specTex), coord);
specCol = s.rgb;
specular.a = s.a;
specPow = effectSettings.y;
@@ -156,7 +108,7 @@ void main()
#endif
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO
- float ao = texture2D(aoTex, v_tex2).r;
+ float ao = SAMPLE_2D(GET_DRAW_TEXTURE_2D(aoTex), v_tex2).r;
#else
float ao = 1.0;
#endif
@@ -168,9 +120,11 @@ void main()
color = mix(texdiffuse, color, specular.a);
#endif
- color = applyFog(color);
+ color = applyFog(color, fogColor, fogParams);
- color *= getLOS();
+#if !IGNORE_LOS
+ color *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
+#endif
color *= shadingColor;
diff --git a/binaries/data/mods/public/shaders/glsl/model_common.h b/binaries/data/mods/public/shaders/glsl/model_common.h
new file mode 100644
index 0000000000..c283ab88bf
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/model_common.h
@@ -0,0 +1,83 @@
+#include "common/shadows.h"
+#include "common/stage.h"
+
+#if USE_GPU_SKINNING
+const int MAX_INFLUENCES = 4;
+const int MAX_BONES = 64;
+#endif
+
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, baseTex)
+ TEXTURE_2D(1, aoTex)
+ TEXTURE_2D(2, normTex)
+ TEXTURE_2D(3, specTex)
+#if !IGNORE_LOS
+ TEXTURE_2D(4, losTex)
+#endif
+#if USE_SHADOW
+ SHADOWS_TEXTURES(5)
+#endif
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, instancingTransform)
+#if USE_PLAYERCOLOR
+ UNIFORM(vec4, playerColor)
+#elif USE_OBJECTCOLOR
+ UNIFORM(vec3, objectColor)
+#endif
+ UNIFORM(vec3, shadingColor)
+END_DRAW_UNIFORMS
+
+BEGIN_MATERIAL_UNIFORMS
+#if USE_SPECULAR
+ UNIFORM(float, specularPower)
+ UNIFORM(vec3, specularColor)
+#endif
+#if USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX || USE_AO
+ UNIFORM(vec4, effectSettings)
+#endif
+ UNIFORM(vec3, ambient)
+ UNIFORM(vec3, sunColor)
+ UNIFORM(vec3, sunDir)
+ UNIFORM(mat4, transform)
+ UNIFORM(vec3, cameraPos)
+#if USE_WIND
+ UNIFORM(float, sim_time)
+ UNIFORM(vec4, windData)
+#endif
+ UNIFORM(vec3, fogColor)
+ UNIFORM(vec2, fogParams)
+ UNIFORM(vec2, losTransform)
+#if USE_SHADOW
+ SHADOWS_UNIFORMS
+#endif
+#if USE_GPU_SKINNING
+ UNIFORM(mat4, skinBlendMatrices[MAX_BONES]);
+#endif
+END_MATERIAL_UNIFORMS
+
+VERTEX_OUTPUT(0, vec4, v_lighting);
+VERTEX_OUTPUT(1, vec2, v_tex);
+#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO
+VERTEX_OUTPUT(2, vec2, v_tex2);
+#endif
+#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX
+VERTEX_OUTPUT(3, vec4, v_normal);
+#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX)
+VERTEX_OUTPUT(4, vec4, v_tangent);
+//VERTEX_OUTPUT(5, vec3, v_bitangent);
+#endif
+#if USE_SPECULAR || USE_SPECULAR_MAP
+VERTEX_OUTPUT(6, vec3, v_half);
+#endif
+#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX
+VERTEX_OUTPUT(7, vec3, v_eyeVec);
+#endif
+#endif
+#if !IGNORE_LOS
+VERTEX_OUTPUT(8, vec2, v_los);
+#endif
+#if USE_SHADOW
+SHADOWS_VERTEX_OUTPUTS(9)
+#endif
diff --git a/binaries/data/mods/public/shaders/glsl/model_common.vs b/binaries/data/mods/public/shaders/glsl/model_common.vs
index e25dcdf541..5fb02c43ba 100644
--- a/binaries/data/mods/public/shaders/glsl/model_common.vs
+++ b/binaries/data/mods/public/shaders/glsl/model_common.vs
@@ -1,70 +1,29 @@
#version 120
+#include "model_common.h"
+
#include "common/los_vertex.h"
#include "common/shadows_vertex.h"
#include "common/vertex.h"
-uniform mat4 transform;
-uniform vec3 cameraPos;
-#ifdef GL_ES
-uniform mediump vec3 sunDir;
-uniform mediump vec3 sunColor;
-#else
-uniform vec3 sunDir;
-uniform vec3 sunColor;
-#endif
-uniform mat4 instancingTransform;
-
-#if USE_WIND
- uniform float sim_time;
- uniform vec4 windData;
-#endif
-
-varying vec4 v_lighting;
-varying vec2 v_tex;
-
-#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO
- varying vec2 v_tex2;
-#endif
-
-#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX
- varying vec4 v_normal;
- #if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX)
- varying vec4 v_tangent;
- //varying vec3 v_bitangent;
- #endif
- #if USE_SPECULAR || USE_SPECULAR_MAP
- varying vec3 v_half;
- #endif
- #if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX
- varying vec3 v_eyeVec;
- #endif
-#endif
-
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
VERTEX_INPUT_ATTRIBUTE(1, vec3, a_normal);
#if (USE_INSTANCING || USE_GPU_SKINNING)
- VERTEX_INPUT_ATTRIBUTE(2, vec4, a_tangent);
+VERTEX_INPUT_ATTRIBUTE(2, vec4, a_tangent);
#endif
VERTEX_INPUT_ATTRIBUTE(3, vec2, a_uv0);
VERTEX_INPUT_ATTRIBUTE(4, vec2, a_uv1);
-
#if USE_GPU_SKINNING
- const int MAX_INFLUENCES = 4;
- const int MAX_BONES = 64;
- uniform mat4 skinBlendMatrices[MAX_BONES];
- VERTEX_INPUT_ATTRIBUTE(5, vec4, a_skinJoints);
- VERTEX_INPUT_ATTRIBUTE(6, vec4, a_skinWeights);
+VERTEX_INPUT_ATTRIBUTE(5, vec4, a_skinJoints);
+VERTEX_INPUT_ATTRIBUTE(6, vec4, a_skinWeights);
#endif
-
vec4 fakeCos(vec4 x)
{
vec4 tri = abs(fract(x + 0.5) * 2.0 - 1.0);
return tri * tri *(3.0 - 2.0 * tri);
}
-
void main()
{
#if USE_GPU_SKINNING
@@ -168,5 +127,7 @@ void main()
calculatePositionInShadowSpace(position);
- calculateLOSCoordinates(position.xz);
+#if !IGNORE_LOS
+ v_los = calculateLOSCoordinates(position.xz, losTransform);
+#endif
}
diff --git a/binaries/data/mods/public/shaders/glsl/model_solid.fs b/binaries/data/mods/public/shaders/glsl/model_solid.fs
new file mode 100644
index 0000000000..edcbc2d66b
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/model_solid.fs
@@ -0,0 +1,10 @@
+#version 110
+
+#include "model_common.h"
+
+#include "common/fragment.h"
+
+void main()
+{
+ OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(0.0, 0.0, 0.0, 0.0));
+}
diff --git a/binaries/data/mods/public/shaders/glsl/model_solid.xml b/binaries/data/mods/public/shaders/glsl/model_solid.xml
index 8739efbede..8c7c4697e5 100644
--- a/binaries/data/mods/public/shaders/glsl/model_solid.xml
+++ b/binaries/data/mods/public/shaders/glsl/model_solid.xml
@@ -3,10 +3,14 @@
+
+
+
+
-
+
diff --git a/binaries/data/mods/public/shaders/glsl/model_solid_player.fs b/binaries/data/mods/public/shaders/glsl/model_solid_player.fs
index 1b20fd2304..d4ff770dd2 100644
--- a/binaries/data/mods/public/shaders/glsl/model_solid_player.fs
+++ b/binaries/data/mods/public/shaders/glsl/model_solid_player.fs
@@ -1,11 +1,11 @@
#version 110
+#include "model_common.h"
+
#include "common/fog.h"
#include "common/fragment.h"
-uniform vec4 playerColor;
-
void main()
{
- OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(applyFog(playerColor.rgb), playerColor.a));
+ OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(applyFog(playerColor.rgb, fogColor, fogParams), playerColor.a));
}
diff --git a/binaries/data/mods/public/shaders/glsl/model_solid_player.xml b/binaries/data/mods/public/shaders/glsl/model_solid_player.xml
index 02d01d9eaa..d80430aac7 100644
--- a/binaries/data/mods/public/shaders/glsl/model_solid_player.xml
+++ b/binaries/data/mods/public/shaders/glsl/model_solid_player.xml
@@ -1,10 +1,15 @@
+
+
+
+
+
diff --git a/binaries/data/mods/public/shaders/glsl/model_solid_tex.fs b/binaries/data/mods/public/shaders/glsl/model_solid_tex.fs
index 470f8bbe8d..b25482014d 100644
--- a/binaries/data/mods/public/shaders/glsl/model_solid_tex.fs
+++ b/binaries/data/mods/public/shaders/glsl/model_solid_tex.fs
@@ -1,14 +1,12 @@
#version 110
+#include "model_common.h"
+
#include "common/fragment.h"
-uniform sampler2D baseTex;
-
-varying vec2 v_tex;
-
void main()
{
- vec4 tex = texture2D(baseTex, v_tex);
+ vec4 tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex);
#ifdef REQUIRE_ALPHA_GEQUAL
if (tex.a < REQUIRE_ALPHA_GEQUAL)
diff --git a/binaries/data/mods/public/shaders/glsl/model_solid_tex.xml b/binaries/data/mods/public/shaders/glsl/model_solid_tex.xml
index c5e712f18b..b56a92a446 100644
--- a/binaries/data/mods/public/shaders/glsl/model_solid_tex.xml
+++ b/binaries/data/mods/public/shaders/glsl/model_solid_tex.xml
@@ -3,9 +3,12 @@
+
+
+
diff --git a/binaries/data/mods/public/shaders/glsl/model_water.fs b/binaries/data/mods/public/shaders/glsl/model_water.fs
index 6edea56a9c..0d5c5ae5b9 100644
--- a/binaries/data/mods/public/shaders/glsl/model_water.fs
+++ b/binaries/data/mods/public/shaders/glsl/model_water.fs
@@ -1,45 +1,15 @@
#version 120
+#include "model_water.h"
+
#include "common/debug_fragment.h"
#include "common/fragment.h"
#include "common/los_fragment.h"
#include "common/shadows_fragment.h"
-uniform sampler2D baseTex;
-uniform sampler2D aoTex;
-uniform sampler2D normTex;
-uniform sampler2D specTex;
-
-uniform sampler2D waterTex;
-uniform samplerCube skyCube;
-
-#if USE_OBJECTCOLOR
- uniform vec3 objectColor;
-#else
-#if USE_PLAYERCOLOR
- uniform vec3 playerColor;
-#endif
-#endif
-
-uniform vec3 shadingColor;
-uniform vec3 ambient;
-uniform vec3 sunColor;
-uniform vec3 sunDir;
-uniform vec3 cameraPos;
-
-uniform float specularStrength;
-uniform float waviness;
-uniform vec3 waterTint;
-uniform float murkiness;
-uniform vec3 reflectionTint;
-uniform float reflectionTintStrength;
-
float waterDepth = 4.0;
float fullDepth = 5.0; // Depth at which to use full murkiness (shallower water will be clearer)
-varying vec4 worldPos;
-varying vec4 v_tex;
-
void main()
{
vec3 n, l, h, v; // Normal, light vector, half-vector and view vector (vector to eye)
@@ -50,7 +20,7 @@ void main()
vec3 reflColor, refrColor, specular;
//vec4 wtex = textureGrad(waterTex, vec3(fract(v_tex.xy), v_tex.z), dFdx(v_tex.xy), dFdy(v_tex.xy));
- vec4 wtex = texture2D(waterTex, fract(v_tex.xy));
+ vec4 wtex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(waterTex), fract(v_tex.xy));
n = normalize(wtex.xzy - vec3(0.5, 0.5, 0.5));
l = -sunDir;
@@ -70,7 +40,7 @@ void main()
vec3 eye = reflect(v, n);
- vec3 tex = textureCube(skyCube, eye).rgb;
+ vec3 tex = SAMPLE_CUBE(GET_DRAW_TEXTURE_CUBE(skyCube), eye).rgb;
reflColor = mix(tex, sunColor * reflectionTint,
reflectionTintStrength);
@@ -92,7 +62,9 @@ void main()
#endif
vec3 color = mix(refrColor + 0.3*specular, reflColor + specular, fresShadow);
- color *= getLOS();
+#if !IGNORE_LOS
+ color *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
+#endif
// Make alpha vary based on both depth (so it blends with the shore) and view angle (make it
// become opaque faster at lower view angles so we can't look "underneath" the water plane)
diff --git a/binaries/data/mods/public/shaders/glsl/model_water.h b/binaries/data/mods/public/shaders/glsl/model_water.h
new file mode 100644
index 0000000000..24a9f42da3
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/model_water.h
@@ -0,0 +1,53 @@
+#include "common/shadows.h"
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, waterTex)
+ TEXTURE_CUBE(1, skyCube)
+#if !IGNORE_LOS
+ TEXTURE_2D(2, losTex)
+#endif
+#if USE_SHADOW
+ SHADOWS_TEXTURES(3)
+#endif
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, instancingTransform)
+END_DRAW_UNIFORMS
+
+BEGIN_MATERIAL_UNIFORMS
+ UNIFORM(vec3, shadingColor)
+ UNIFORM(vec3, ambient)
+
+ UNIFORM(float, specularStrength)
+ UNIFORM(float, waviness)
+ UNIFORM(vec3, waterTint)
+ UNIFORM(float, murkiness)
+ UNIFORM(vec3, reflectionTint)
+ UNIFORM(float, reflectionTintStrength)
+
+ UNIFORM(mat4, transform)
+ UNIFORM(vec3, cameraPos)
+ UNIFORM(vec3, sunDir)
+ UNIFORM(vec3, sunColor)
+
+ UNIFORM(float, sim_time)
+ UNIFORM(vec2, translation)
+
+ UNIFORM(vec3, fogColor)
+ UNIFORM(vec2, fogParams)
+ UNIFORM(vec2, losTransform)
+#if USE_SHADOW
+ SHADOWS_UNIFORMS
+#endif
+END_MATERIAL_UNIFORMS
+
+VERTEX_OUTPUT(0, vec4, worldPos);
+VERTEX_OUTPUT(1, vec4, v_tex);
+#if !IGNORE_LOS
+VERTEX_OUTPUT(2, vec2, v_los);
+#endif
+#if USE_SHADOW
+SHADOWS_VERTEX_OUTPUTS(3)
+#endif
diff --git a/binaries/data/mods/public/shaders/glsl/model_water.vs b/binaries/data/mods/public/shaders/glsl/model_water.vs
index e3b70fb103..926a9af127 100644
--- a/binaries/data/mods/public/shaders/glsl/model_water.vs
+++ b/binaries/data/mods/public/shaders/glsl/model_water.vs
@@ -1,25 +1,13 @@
#version 120
+#include "model_water.h"
+
#include "common/los_vertex.h"
#include "common/shadows_vertex.h"
#include "common/vertex.h"
-uniform mat4 transform;
-uniform vec3 cameraPos;
-uniform vec3 sunDir;
-uniform vec3 sunColor;
-uniform mat4 instancingTransform;
-
-uniform float sim_time;
-uniform vec2 translation;
-
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
-VERTEX_INPUT_ATTRIBUTE(1, vec3, a_normal);
VERTEX_INPUT_ATTRIBUTE(2, vec2, a_uv0);
-VERTEX_INPUT_ATTRIBUTE(3, vec2, a_uv1);
-
-varying vec4 worldPos;
-varying vec4 v_tex;
vec4 fakeCos(vec4 x)
{
@@ -37,7 +25,9 @@ void main()
calculatePositionInShadowSpace(worldPos);
- calculateLOSCoordinates(worldPos.xz);
+#if !IGNORE_LOS
+ v_los = calculateLOSCoordinates(worldPos.xz, losTransform);
+#endif
OUTPUT_VERTEX_POSITION(transform * worldPos);
}
diff --git a/binaries/data/mods/public/shaders/glsl/model_water.xml b/binaries/data/mods/public/shaders/glsl/model_water.xml
index f8ba8ac72a..676adea3e2 100644
--- a/binaries/data/mods/public/shaders/glsl/model_water.xml
+++ b/binaries/data/mods/public/shaders/glsl/model_water.xml
@@ -3,9 +3,7 @@
-
-
diff --git a/binaries/data/mods/public/shaders/glsl/model_waterfall.fs b/binaries/data/mods/public/shaders/glsl/model_waterfall.fs
index 261a1ca851..a61445636a 100644
--- a/binaries/data/mods/public/shaders/glsl/model_waterfall.fs
+++ b/binaries/data/mods/public/shaders/glsl/model_waterfall.fs
@@ -1,31 +1,16 @@
#version 120
+#include "model_waterfall.h"
+
#include "common/debug_fragment.h"
#include "common/fragment.h"
#include "common/los_fragment.h"
#include "common/shadows_fragment.h"
-uniform sampler2D baseTex;
-
-uniform vec3 shadingColor;
-uniform vec3 ambient;
-uniform vec3 sunColor;
-uniform vec3 sunDir;
-uniform vec3 cameraPos;
-
-uniform float specularPower;
-uniform vec3 specularColor;
-
-varying vec4 v_tex;
-varying vec3 v_half;
-varying vec3 v_normal;
-varying float v_transp;
-varying vec3 v_lighting;
-
void main()
{
//vec4 texdiffuse = textureGrad(baseTex, vec3(fract(v_tex.xy), v_tex.z), dFdx(v_tex.xy), dFdy(v_tex.xy));
- vec4 texdiffuse = texture2D(baseTex, fract(v_tex.xy));
+ vec4 texdiffuse = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), fract(v_tex.xy));
if (texdiffuse.a < 0.25)
discard;
@@ -37,7 +22,9 @@ void main()
vec3 color = (texdiffuse.rgb * v_lighting + specular) * getShadowOnLandscape();
color += texdiffuse.rgb * ambient;
- color *= getLOS();
+#if !IGNORE_LOS
+ color *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
+#endif
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(applyDebugColor(color, 1.0, texdiffuse.a, 0.0), texdiffuse.a));
}
diff --git a/binaries/data/mods/public/shaders/glsl/model_waterfall.h b/binaries/data/mods/public/shaders/glsl/model_waterfall.h
new file mode 100644
index 0000000000..7891020ae8
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/model_waterfall.h
@@ -0,0 +1,51 @@
+#include "common/shadows.h"
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, baseTex)
+#if !IGNORE_LOS
+ TEXTURE_2D(1, losTex)
+#endif
+#if USE_SHADOW
+ SHADOWS_TEXTURES(2)
+#endif
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, instancingTransform)
+END_DRAW_UNIFORMS
+
+BEGIN_MATERIAL_UNIFORMS
+ UNIFORM(vec3, shadingColor)
+ UNIFORM(vec3, ambient)
+
+ UNIFORM(float, specularPower)
+ UNIFORM(vec3, specularColor)
+
+ UNIFORM(mat4, transform)
+ UNIFORM(vec3, cameraPos)
+ UNIFORM(vec3, sunDir)
+ UNIFORM(vec3, sunColor)
+
+ UNIFORM(float, sim_time)
+ UNIFORM(vec2, translation)
+
+ UNIFORM(vec3, fogColor)
+ UNIFORM(vec2, fogParams)
+ UNIFORM(vec2, losTransform)
+#if USE_SHADOW
+ SHADOWS_UNIFORMS
+#endif
+END_MATERIAL_UNIFORMS
+
+VERTEX_OUTPUT(0, vec4, v_tex);
+VERTEX_OUTPUT(1, vec3, v_half);
+VERTEX_OUTPUT(2, vec3, v_normal);
+VERTEX_OUTPUT(3, float, v_transp);
+VERTEX_OUTPUT(4, vec3, v_lighting);
+#if !IGNORE_LOS
+VERTEX_OUTPUT(5, vec2, v_los);
+#endif
+#if USE_SHADOW
+SHADOWS_VERTEX_OUTPUTS(6)
+#endif
diff --git a/binaries/data/mods/public/shaders/glsl/model_waterfall.vs b/binaries/data/mods/public/shaders/glsl/model_waterfall.vs
index 054d18c229..df7c1cb2aa 100644
--- a/binaries/data/mods/public/shaders/glsl/model_waterfall.vs
+++ b/binaries/data/mods/public/shaders/glsl/model_waterfall.vs
@@ -1,40 +1,28 @@
#version 120
+#include "model_waterfall.h"
+
#include "common/los_vertex.h"
#include "common/shadows_vertex.h"
#include "common/vertex.h"
-uniform mat4 transform;
-uniform vec3 cameraPos;
-uniform vec3 sunDir;
-uniform vec3 sunColor;
-uniform mat4 instancingTransform;
-
-uniform float sim_time;
-uniform vec2 translation;
-
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
VERTEX_INPUT_ATTRIBUTE(1, vec3, a_normal);
VERTEX_INPUT_ATTRIBUTE(2, vec2, a_uv0);
VERTEX_INPUT_ATTRIBUTE(3, vec2, a_uv1);
-varying vec4 worldPos;
-varying vec4 v_tex;
-varying vec3 v_half;
-varying vec3 v_normal;
-varying float v_transp;
-varying vec3 v_lighting;
-
void main()
{
- worldPos = instancingTransform * vec4(a_vertex, 1.0);
+ vec4 worldPos = instancingTransform * vec4(a_vertex, 1.0);
v_tex.xy = a_uv0 + sim_time * translation;
v_transp = a_uv1.x;
calculatePositionInShadowSpace(worldPos);
- calculateLOSCoordinates(worldPos.xz);
+#if !IGNORE_LOS
+ v_los = calculateLOSCoordinates(worldPos.xz, losTransform);
+#endif
vec3 eyeVec = cameraPos.xyz - worldPos.xyz;
vec3 sunVec = -sunDir;
diff --git a/binaries/data/mods/public/shaders/glsl/overlay_solid.fs b/binaries/data/mods/public/shaders/glsl/overlay_solid.fs
index b01999568b..bfef33cd18 100644
--- a/binaries/data/mods/public/shaders/glsl/overlay_solid.fs
+++ b/binaries/data/mods/public/shaders/glsl/overlay_solid.fs
@@ -1,8 +1,8 @@
#version 120
-#include "common/fragment.h"
+#include "overlay_solid.h"
-uniform vec4 color;
+#include "common/fragment.h"
void main()
{
diff --git a/binaries/data/mods/public/shaders/glsl/overlay_solid.h b/binaries/data/mods/public/shaders/glsl/overlay_solid.h
new file mode 100644
index 0000000000..e36d5c3174
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/overlay_solid.h
@@ -0,0 +1,15 @@
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ NO_DRAW_TEXTURES
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, transform)
+ UNIFORM(vec4, instancingTransform)
+ UNIFORM(vec4, color)
+END_DRAW_UNIFORMS
+
+uniform mat4 transform;
+uniform vec4 instancingTransform;
+uniform vec4 color;
diff --git a/binaries/data/mods/public/shaders/glsl/overlay_solid.vs b/binaries/data/mods/public/shaders/glsl/overlay_solid.vs
index 9963d199da..151d451a39 100644
--- a/binaries/data/mods/public/shaders/glsl/overlay_solid.vs
+++ b/binaries/data/mods/public/shaders/glsl/overlay_solid.vs
@@ -1,9 +1,8 @@
#version 120
-#include "common/vertex.h"
+#include "overlay_solid.h"
-uniform mat4 transform;
-uniform vec4 instancingTransform;
+#include "common/vertex.h"
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
diff --git a/binaries/data/mods/public/shaders/glsl/overlayline.fs b/binaries/data/mods/public/shaders/glsl/overlayline.fs
index 56b5b76950..e832879db6 100644
--- a/binaries/data/mods/public/shaders/glsl/overlayline.fs
+++ b/binaries/data/mods/public/shaders/glsl/overlayline.fs
@@ -1,20 +1,11 @@
#version 120
+#include "overlayline.h"
+
#include "common/debug_fragment.h"
#include "common/fragment.h"
#include "common/los_fragment.h"
-uniform sampler2D baseTex;
-uniform sampler2D maskTex;
-
-#if USE_OBJECTCOLOR
-uniform vec4 objectColor;
-#else
-varying vec4 v_color;
-#endif
-
-varying vec2 v_tex;
-
void main()
{
#if USE_OBJECTCOLOR
@@ -25,11 +16,13 @@ void main()
float alpha = v_color.a;
#endif
- vec4 base = texture2D(baseTex, v_tex);
- vec4 mask = texture2D(maskTex, v_tex);
+ vec4 base = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex);
+ vec4 mask = SAMPLE_2D(GET_DRAW_TEXTURE_2D(maskTex), v_tex);
color = mix(base.rgb, color, mask.r);
- color *= getLOS();
+#if !IGNORE_LOS
+ color *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
+#endif
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(applyDebugColor(color, 1.0, alpha * base.a, 0.0), alpha * base.a));
}
diff --git a/binaries/data/mods/public/shaders/glsl/overlayline.h b/binaries/data/mods/public/shaders/glsl/overlayline.h
new file mode 100644
index 0000000000..258e6c4030
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/overlayline.h
@@ -0,0 +1,25 @@
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, baseTex)
+ TEXTURE_2D(1, maskTex)
+#if !IGNORE_LOS
+ TEXTURE_2D(2, losTex)
+#endif
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, transform)
+#if USE_OBJECTCOLOR
+ UNIFORM(vec4, objectColor)
+#endif
+ UNIFORM(vec2, losTransform)
+END_DRAW_UNIFORMS
+
+VERTEX_OUTPUT(0, vec2, v_tex);
+#if !USE_OBJECTCOLOR
+VERTEX_OUTPUT(1, vec4, v_color);
+#endif
+#if !IGNORE_LOS
+VERTEX_OUTPUT(2, vec2, v_los);
+#endif
diff --git a/binaries/data/mods/public/shaders/glsl/overlayline.vs b/binaries/data/mods/public/shaders/glsl/overlayline.vs
index 15c324fe4a..fcfa8d93fb 100644
--- a/binaries/data/mods/public/shaders/glsl/overlayline.vs
+++ b/binaries/data/mods/public/shaders/glsl/overlayline.vs
@@ -1,24 +1,22 @@
#version 120
+#include "overlayline.h"
+
#include "common/los_vertex.h"
#include "common/vertex.h"
-uniform mat4 transform;
-
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_uv0);
-
#if !USE_OBJECTCOLOR
VERTEX_INPUT_ATTRIBUTE(2, vec4, a_color);
-varying vec4 v_color;
#endif
-varying vec2 v_tex;
-
void main()
{
v_tex = a_uv0;
- calculateLOSCoordinates(a_vertex.xz);
+#if !IGNORE_LOS
+ v_los = calculateLOSCoordinates(a_vertex.xz, losTransform);
+#endif
#if !USE_OBJECTCOLOR
v_color = a_color;
#endif
diff --git a/binaries/data/mods/public/shaders/glsl/particle.fs b/binaries/data/mods/public/shaders/glsl/particle.fs
index 8bcbaae733..5164b38bbd 100644
--- a/binaries/data/mods/public/shaders/glsl/particle.fs
+++ b/binaries/data/mods/public/shaders/glsl/particle.fs
@@ -1,22 +1,19 @@
#version 110
+#include "particle.h"
+
#include "common/fog.h"
#include "common/fragment.h"
#include "common/los_fragment.h"
-uniform sampler2D baseTex;
-
-varying vec2 v_tex;
-varying vec4 v_color;
-
-uniform vec3 sunColor;
-
void main()
{
- vec4 color = texture2D(baseTex, v_tex) * vec4((v_color.rgb + sunColor)/2.0,v_color.a);
+ vec4 color = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex) * vec4((v_color.rgb + sunColor) / 2.0, v_color.a);
- color.rgb = applyFog(color.rgb);
- color.rgb *= getLOS();
+ color.rgb = applyFog(color.rgb, fogColor, fogParams);
+#if !IGNORE_LOS
+ color.rgb *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
+#endif
OUTPUT_FRAGMENT_SINGLE_COLOR(color);
}
diff --git a/binaries/data/mods/public/shaders/glsl/particle.h b/binaries/data/mods/public/shaders/glsl/particle.h
new file mode 100644
index 0000000000..21521ad1d1
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/particle.h
@@ -0,0 +1,27 @@
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, baseTex)
+#if !IGNORE_LOS
+ TEXTURE_2D(1, losTex)
+#endif
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, modelViewMatrix)
+END_DRAW_UNIFORMS
+
+BEGIN_MATERIAL_UNIFORMS
+ UNIFORM(mat4, transform)
+ UNIFORM(vec3, sunColor)
+ UNIFORM(vec3, fogColor)
+ UNIFORM(vec2, fogParams)
+ UNIFORM(vec2, losTransform)
+END_MATERIAL_UNIFORMS
+
+VERTEX_OUTPUT(0, vec2, v_tex);
+VERTEX_OUTPUT(1, vec4, v_color);
+
+#if !IGNORE_LOS
+VERTEX_OUTPUT(2, vec2, v_los);
+#endif
diff --git a/binaries/data/mods/public/shaders/glsl/particle.vs b/binaries/data/mods/public/shaders/glsl/particle.vs
index 3e0daa8e69..481d93b546 100644
--- a/binaries/data/mods/public/shaders/glsl/particle.vs
+++ b/binaries/data/mods/public/shaders/glsl/particle.vs
@@ -1,14 +1,10 @@
#version 110
+#include "particle.h"
+
#include "common/los_vertex.h"
#include "common/vertex.h"
-uniform mat4 transform;
-uniform mat4 modelViewMatrix;
-
-varying vec2 v_tex;
-varying vec4 v_color;
-
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
VERTEX_INPUT_ATTRIBUTE(1, vec4, a_color);
VERTEX_INPUT_ATTRIBUTE(2, vec2, a_uv0);
@@ -24,8 +20,9 @@ void main()
OUTPUT_VERTEX_POSITION(transform * vec4(position, 1.0));
- calculateLOSCoordinates(position.xz);
-
v_tex = a_uv0;
v_color = a_color;
+#if !IGNORE_LOS
+ v_los = calculateLOSCoordinates(position.xz, losTransform);
+#endif
}
diff --git a/binaries/data/mods/public/shaders/glsl/sky.fs b/binaries/data/mods/public/shaders/glsl/sky.fs
index ebe642c118..5b76e6078c 100644
--- a/binaries/data/mods/public/shaders/glsl/sky.fs
+++ b/binaries/data/mods/public/shaders/glsl/sky.fs
@@ -1,13 +1,12 @@
#version 110
+#include "sky.h"
+
#include "common/fragment.h"
-uniform samplerCube baseTex;
-varying vec3 v_tex;
-
void main()
{
- vec4 tex = textureCube(baseTex, v_tex);
+ vec4 tex = SAMPLE_CUBE(GET_DRAW_TEXTURE_CUBE(baseTex), v_tex);
float m = (1.0 - v_tex.y) - 0.75;
m *= 4.0;
diff --git a/binaries/data/mods/public/shaders/glsl/sky.h b/binaries/data/mods/public/shaders/glsl/sky.h
new file mode 100644
index 0000000000..6924848789
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/sky.h
@@ -0,0 +1,11 @@
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ TEXTURE_CUBE(0, baseTex)
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, transform)
+END_DRAW_UNIFORMS
+
+VERTEX_OUTPUT(0, vec3, v_tex);
diff --git a/binaries/data/mods/public/shaders/glsl/sky.vs b/binaries/data/mods/public/shaders/glsl/sky.vs
index 5de1fa07d8..068a8f9b60 100644
--- a/binaries/data/mods/public/shaders/glsl/sky.vs
+++ b/binaries/data/mods/public/shaders/glsl/sky.vs
@@ -1,14 +1,12 @@
#version 110
+#include "sky.h"
+
#include "common/vertex.h"
-varying vec3 v_tex;
-
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
VERTEX_INPUT_ATTRIBUTE(1, vec3, a_uv0);
-uniform mat4 transform;
-
void main()
{
OUTPUT_VERTEX_POSITION(transform * vec4(a_vertex, 1.0));
diff --git a/binaries/data/mods/public/shaders/glsl/solid.fs b/binaries/data/mods/public/shaders/glsl/solid.fs
index faabfadb7a..5a756f2ee3 100644
--- a/binaries/data/mods/public/shaders/glsl/solid.fs
+++ b/binaries/data/mods/public/shaders/glsl/solid.fs
@@ -1,8 +1,8 @@
#version 110
-#include "common/fragment.h"
+#include "solid.h"
-uniform vec4 color;
+#include "common/fragment.h"
void main()
{
diff --git a/binaries/data/mods/public/shaders/glsl/solid.h b/binaries/data/mods/public/shaders/glsl/solid.h
new file mode 100644
index 0000000000..6751710b08
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/solid.h
@@ -0,0 +1,10 @@
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ NO_DRAW_TEXTURES
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, transform)
+ UNIFORM(vec4, color)
+END_DRAW_UNIFORMS
diff --git a/binaries/data/mods/public/shaders/glsl/solid.vs b/binaries/data/mods/public/shaders/glsl/solid.vs
index 3a39e9452c..2e2462a830 100644
--- a/binaries/data/mods/public/shaders/glsl/solid.vs
+++ b/binaries/data/mods/public/shaders/glsl/solid.vs
@@ -1,8 +1,8 @@
#version 110
-#include "common/vertex.h"
+#include "solid.h"
-uniform mat4 transform;
+#include "common/vertex.h"
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
diff --git a/binaries/data/mods/public/shaders/glsl/terrain_base.xml b/binaries/data/mods/public/shaders/glsl/terrain_base.xml
index 8bc7050399..6430168ece 100644
--- a/binaries/data/mods/public/shaders/glsl/terrain_base.xml
+++ b/binaries/data/mods/public/shaders/glsl/terrain_base.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/binaries/data/mods/public/shaders/glsl/terrain_common.fs b/binaries/data/mods/public/shaders/glsl/terrain_common.fs
index e953592593..baad4e4399 100644
--- a/binaries/data/mods/public/shaders/glsl/terrain_common.fs
+++ b/binaries/data/mods/public/shaders/glsl/terrain_common.fs
@@ -1,56 +1,15 @@
#version 120
+#include "terrain_common.h"
+
#include "common/debug_fragment.h"
#include "common/fog.h"
#include "common/fragment.h"
#include "common/los_fragment.h"
#include "common/shadows_fragment.h"
-uniform sampler2D baseTex;
-uniform sampler2D blendTex;
-uniform sampler2D normTex;
-uniform sampler2D specTex;
-
-uniform vec3 shadingColor;
-uniform vec3 ambient;
-uniform vec3 sunColor;
-uniform vec3 sunDir;
-
-uniform vec2 textureTransform;
-
-varying vec3 v_lighting;
-
-varying vec2 v_blend;
-
#if USE_TRIPLANAR
- varying vec3 v_tex;
-#else
- varying vec2 v_tex;
-#endif
-
-#if USE_SPECULAR
- uniform float specularPower;
- uniform vec3 specularColor;
-#endif
-
-#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_AO
- uniform vec4 effectSettings;
-#endif
-
-varying vec3 v_normal;
-
-#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP
- #if USE_NORMAL_MAP
- varying vec4 v_tangent;
- varying vec3 v_bitangent;
- #endif
- #if USE_SPECULAR || USE_SPECULAR_MAP
- varying vec3 v_half;
- #endif
-#endif
-
-#if USE_TRIPLANAR
-vec4 triplanar(sampler2D sampler, vec3 wpos)
+vec4 triplanar(sampler2D tex, vec3 wpos)
{
float tighten = 0.4679;
@@ -64,16 +23,16 @@ vec4 triplanar(sampler2D sampler, vec3 wpos)
vec3 coords = wpos;
coords.xyz /= 32.0; // Ugh.
- vec4 col1 = texture2D(sampler, coords.yz);
- vec4 col2 = texture2D(sampler, coords.zx);
- vec4 col3 = texture2D(sampler, coords.yx);
+ vec4 col1 = SAMPLE_2D(tex, coords.yz);
+ vec4 col2 = SAMPLE_2D(tex, coords.zx);
+ vec4 col3 = SAMPLE_2D(tex, coords.yx);
vec4 colBlended = col1 * blending.x + col2 * blending.y + col3 * blending.z;
return colBlended;
}
-vec4 triplanarNormals(sampler2D sampler, vec3 wpos)
+vec4 triplanarNormals(sampler2D tex, vec3 wpos)
{
float tighten = 0.4679;
@@ -87,11 +46,11 @@ vec4 triplanarNormals(sampler2D sampler, vec3 wpos)
vec3 coords = wpos;
coords.xyz /= 32.0; // Ugh.
- vec4 col1 = texture2D(sampler, coords.yz).xyzw;
+ vec4 col1 = SAMPLE_2D(tex, coords.yz).xyzw;
col1.y = 1.0 - col1.y;
- vec4 col2 = texture2D(sampler, coords.zx).yxzw;
+ vec4 col2 = SAMPLE_2D(tex, coords.zx).yxzw;
col2.y = 1.0 - col2.y;
- vec4 col3 = texture2D(sampler, coords.yx).yxzw;
+ vec4 col3 = SAMPLE_2D(tex, coords.yx).yxzw;
col3.y = 1.0 - col3.y;
vec4 colBlended = col1 * blending.x + col2 * blending.y + col3 * blending.z;
@@ -106,15 +65,15 @@ void main()
#if BLEND
// Use alpha from blend texture
- alpha = 1.0 - texture2D(blendTex, v_blend).a;
+ alpha = 1.0 - SAMPLE_2D(GET_DRAW_TEXTURE_2D(blendTex), v_blend).a;
#else
alpha = 1.0;
#endif
#if USE_TRIPLANAR
- vec4 tex = triplanar(baseTex, v_tex);
+ vec4 tex = triplanar(GET_DRAW_TEXTURE_2D(baseTex), v_tex);
#else
- vec4 tex = texture2D(baseTex, v_tex.xy);
+ vec4 tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex.xy);
#endif
#if DECAL
@@ -132,9 +91,9 @@ void main()
float sign = v_tangent.w;
mat3 tbn = mat3(v_tangent.xyz, v_bitangent * -sign, v_normal);
#if USE_TRIPLANAR
- vec3 ntex = triplanarNormals(normTex, v_tex).rgb * 2.0 - 1.0;
+ vec3 ntex = triplanarNormals(GET_DRAW_TEXTURE_2D(normTex), v_tex).rgb * 2.0 - 1.0;
#else
- vec3 ntex = texture2D(normTex, v_tex).rgb * 2.0 - 1.0;
+ vec3 ntex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normTex), v_tex).rgb * 2.0 - 1.0;
#endif
normal = normalize(tbn * ntex);
vec3 bumplight = max(dot(-sunDir, normal), 0.0) * sunColor;
@@ -149,9 +108,9 @@ void main()
float specPow;
#if USE_SPECULAR_MAP
#if USE_TRIPLANAR
- vec4 s = triplanar(specTex, v_tex);
+ vec4 s = triplanar(GET_DRAW_TEXTURE_2D(specTex), v_tex);
#else
- vec4 s = texture2D(specTex, v_tex);
+ vec4 s = SAMPLE_2D(GET_DRAW_TEXTURE_2D(specTex), v_tex);
#endif
specCol = s.rgb;
specular.a = s.a;
@@ -169,9 +128,11 @@ void main()
color = mix(texdiffuse, color, specular.a);
#endif
- color = applyFog(color);
+ color = applyFog(color, fogColor, fogParams);
- color *= getLOS();
+#if !IGNORE_LOS
+ color *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
+#endif
#if DECAL
color *= shadingColor;
diff --git a/binaries/data/mods/public/shaders/glsl/terrain_common.h b/binaries/data/mods/public/shaders/glsl/terrain_common.h
new file mode 100644
index 0000000000..a8775de790
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/terrain_common.h
@@ -0,0 +1,69 @@
+#include "common/shadows.h"
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, baseTex)
+ TEXTURE_2D(1, blendTex)
+ TEXTURE_2D(2, normTex)
+ TEXTURE_2D(3, specTex)
+#if !IGNORE_LOS
+ TEXTURE_2D(4, losTex)
+#endif
+#if USE_SHADOW
+ SHADOWS_TEXTURES(5)
+#endif
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(vec3, shadingColor)
+ UNIFORM(vec2, textureTransform)
+#if USE_SPECULAR
+ UNIFORM(float, specularPower)
+ UNIFORM(vec3, specularColor)
+#endif
+#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_AO
+ UNIFORM(vec4, effectSettings)
+#endif
+END_DRAW_UNIFORMS
+
+BEGIN_MATERIAL_UNIFORMS
+ UNIFORM(vec3, ambient)
+ UNIFORM(mat4, transform)
+ UNIFORM(vec3, cameraPos)
+ UNIFORM(vec3, sunDir)
+ UNIFORM(vec3, sunColor)
+ UNIFORM(vec3, fogColor)
+ UNIFORM(vec2, fogParams)
+ UNIFORM(vec2, losTransform)
+#if USE_SHADOW
+ SHADOWS_UNIFORMS
+#endif
+END_MATERIAL_UNIFORMS
+
+#if USE_SPECULAR || USE_SPECULAR_MAP || USE_NORMAL_MAP || USE_TRIPLANAR
+VERTEX_OUTPUT(0, vec3, v_normal);
+#endif
+VERTEX_OUTPUT(1, vec3, v_lighting);
+#if BLEND
+VERTEX_OUTPUT(2, vec2, v_blend);
+#endif
+#if USE_TRIPLANAR
+VERTEX_OUTPUT(3, vec3, v_tex);
+#else
+VERTEX_OUTPUT(3, vec2, v_tex);
+#endif
+#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP
+#if USE_NORMAL_MAP
+VERTEX_OUTPUT(4, vec4, v_tangent);
+VERTEX_OUTPUT(5, vec3, v_bitangent);
+#endif
+#if USE_SPECULAR || USE_SPECULAR_MAP
+VERTEX_OUTPUT(6, vec3, v_half);
+#endif
+#endif
+#if !IGNORE_LOS
+VERTEX_OUTPUT(7, vec2, v_los);
+#endif
+#if USE_SHADOW
+SHADOWS_VERTEX_OUTPUTS(8)
+#endif
diff --git a/binaries/data/mods/public/shaders/glsl/terrain_common.vs b/binaries/data/mods/public/shaders/glsl/terrain_common.vs
index 064f8b20a0..c5b4f79f16 100644
--- a/binaries/data/mods/public/shaders/glsl/terrain_common.vs
+++ b/binaries/data/mods/public/shaders/glsl/terrain_common.vs
@@ -1,46 +1,19 @@
#version 120
+#include "terrain_common.h"
+
#include "common/los_vertex.h"
#include "common/shadows_vertex.h"
#include "common/vertex.h"
-uniform mat4 transform;
-uniform vec3 cameraPos;
-#ifdef GL_ES
-uniform mediump vec3 sunDir;
-uniform mediump vec3 sunColor;
-#else
-uniform vec3 sunDir;
-uniform vec3 sunColor;
-#endif
-uniform vec2 textureTransform;
-
-varying vec3 v_lighting;
-
-varying vec2 v_blend;
-
-#if USE_TRIPLANAR
- varying vec3 v_tex;
-#else
- varying vec2 v_tex;
-#endif
-
-varying vec3 v_normal;
-
-#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP
- #if USE_NORMAL_MAP
- varying vec4 v_tangent;
- varying vec3 v_bitangent;
- #endif
- #if USE_SPECULAR || USE_SPECULAR_MAP
- varying vec3 v_half;
- #endif
-#endif
-
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
VERTEX_INPUT_ATTRIBUTE(1, vec3, a_normal);
+#if DECAL
VERTEX_INPUT_ATTRIBUTE(2, vec2, a_uv0);
+#endif
+#if BLEND
VERTEX_INPUT_ATTRIBUTE(3, vec2, a_uv1);
+#endif
void main()
{
@@ -78,8 +51,9 @@ void main()
#endif
calculatePositionInShadowSpace(vec4(a_vertex, 1.0));
-
+#if USE_SPECULAR || USE_SPECULAR_MAP || USE_NORMAL_MAP || USE_TRIPLANAR
v_normal = a_normal;
+#endif
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_TRIPLANAR
#if USE_NORMAL_MAP
@@ -98,5 +72,7 @@ void main()
#endif
#endif
- calculateLOSCoordinates(a_vertex.xz);
+#if !IGNORE_LOS
+ v_los = calculateLOSCoordinates(a_vertex.xz, losTransform);
+#endif
}
diff --git a/binaries/data/mods/public/shaders/glsl/water_high.fs b/binaries/data/mods/public/shaders/glsl/water_high.fs
index ff80a6f125..2ac7480592 100644
--- a/binaries/data/mods/public/shaders/glsl/water_high.fs
+++ b/binaries/data/mods/public/shaders/glsl/water_high.fs
@@ -1,69 +1,13 @@
#version 110
+#include "water_high.h"
+
#include "common/debug_fragment.h"
#include "common/fog.h"
#include "common/fragment.h"
#include "common/los_fragment.h"
#include "common/shadows_fragment.h"
-// Environment settings
-uniform vec3 ambient;
-uniform vec3 sunDir;
-uniform vec3 sunColor;
-uniform mat4 skyBoxRot;
-
-uniform float waviness; // "Wildness" of the reflections and refractions; choose based on texture
-uniform vec3 color; // color of the water
-uniform vec3 tint; // Tint for refraction (used to simulate particles in water)
-uniform float murkiness; // Amount of tint to blend in with the refracted color
-
-uniform float windAngle;
-varying vec2 WindCosSin;
-
-uniform vec2 screenSize;
-varying float moddedTime;
-
-varying vec3 worldPos;
-varying float waterDepth;
-varying vec2 waterInfo;
-
-varying vec3 v_eyeVec;
-
-varying vec4 normalCoords;
-#if USE_REFLECTION
-varying vec3 reflectionCoords;
-#endif
-#if USE_REFRACTION
-varying vec3 refractionCoords;
-#endif
-
-varying float fwaviness;
-
-uniform samplerCube skyCube;
-
-uniform sampler2D normalMap;
-uniform sampler2D normalMap2;
-
-#if USE_FANCY_EFFECTS
- uniform sampler2D waterEffectsTex;
-#endif
-
-uniform vec4 waveParams1; // wavyEffect, BaseScale, Flattenism, Basebump
-uniform vec4 waveParams2; // Smallintensity, Smallbase, Bigmovement, Smallmovement
-
-#if USE_REFLECTION
- uniform sampler2D reflectionMap;
-#endif
-
-#if USE_REFRACTION
- uniform sampler2D refractionMap;
-#if USE_REAL_DEPTH
- uniform sampler2D depthTex;
- uniform mat4 projInvTransform;
- uniform mat4 viewInvTransform;
-#endif
-#endif
-
vec3 getNormal(vec4 fancyeffects)
{
float wavyEffect = waveParams1.r;
@@ -74,12 +18,12 @@ vec3 getNormal(vec4 fancyeffects)
// This method uses 60 animated water frames. We're blending between each two frames
// Scale the normal textures by waviness so that big waviness means bigger waves.
- vec3 ww1 = texture2D(normalMap, (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).xzy;
- vec3 ww2 = texture2D(normalMap2, (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).xzy;
+ vec3 ww1 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normalMap), (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).xzy;
+ vec3 ww2 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normalMap2), (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).xzy;
vec3 wwInterp = mix(ww1, ww2, moddedTime) - vec3(0.5, 0.0, 0.5);
- ww1.x = wwInterp.x * WindCosSin.x - wwInterp.z * WindCosSin.y;
- ww1.z = wwInterp.x * WindCosSin.y + wwInterp.z * WindCosSin.x;
+ ww1.x = wwInterp.x * windCosSin.x - wwInterp.z * windCosSin.y;
+ ww1.z = wwInterp.x * windCosSin.y + wwInterp.z * windCosSin.x;
ww1.y = wwInterp.y;
// Flatten them based on waviness.
@@ -123,19 +67,19 @@ vec4 getReflection(vec3 normal, vec3 eyeVec)
// Distort the reflection coords based on waves.
vec2 reflCoords = (0.5 * reflectionCoords.xy - 15.0 * normal.zx / refVY) / reflectionCoords.z + 0.5;
- vec4 refTex = texture2D(reflectionMap, reflCoords);
+ vec4 refTex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(reflectionMap), reflCoords);
vec3 reflColor = refTex.rgb;
// Interpolate between the sky color and nearby objects.
// Only do this when alpha is rather low, or transparent leaves show up as extremely white.
if (refTex.a < 0.4)
- reflColor = mix(textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb, refTex.rgb, refTex.a);
+ reflColor = mix(SAMPLE_CUBE(GET_DRAW_TEXTURE_CUBE(skyCube), (vec4(eye, 0.0) * skyBoxRot).xyz).rgb, refTex.rgb, refTex.a);
// Let actual objects be reflected fully.
reflMod = max(refTex.a, 0.75);
#else
- vec3 reflColor = textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb;
+ vec3 reflColor = SAMPLE_CUBE(GET_DRAW_TEXTURE_CUBE(skyCube), (vec4(eye, 0.0) * skyBoxRot).xyz).rgb;
#endif
return vec4(reflColor, reflMod);
@@ -144,7 +88,7 @@ vec4 getReflection(vec3 normal, vec3 eyeVec)
#if USE_REFRACTION && USE_REAL_DEPTH
vec3 getWorldPositionFromRefractionDepth(vec2 uv)
{
- float depth = texture2D(depthTex, uv).x;
+ float depth = SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), uv).x;
vec4 viewPosition = projInvTransform * (vec4((uv - vec2(0.5)) * 2.0, depth * 2.0 - 1.0, 1.0));
viewPosition /= viewPosition.w;
vec3 refrWorldPos = (viewInvTransform * viewPosition).xyz;
@@ -198,7 +142,7 @@ vec4 getRefraction(vec3 normal, vec3 eyeVec, float depthLimit)
// Distort the texture coords under where the water is to simulate refraction.
vec2 refrCoords = (0.5 * refractionCoords.xy - normal.xz * distoFactor) / refractionCoords.z + 0.5;
- vec3 refColor = texture2D(refractionMap, refrCoords).rgb;
+ vec3 refColor = SAMPLE_2D(GET_DRAW_TEXTURE_2D(refractionMap), refrCoords).rgb;
// Note, the refraction map is cleared using (255, 0, 0), so pixels outside of the water plane are pure red.
// If we get a pure red fragment, use an undistorted/less distorted coord instead.
@@ -208,13 +152,13 @@ vec4 getRefraction(vec3 normal, vec3 eyeVec, float depthLimit)
vec4 blurColor = vec4(refColor, 1.0);
- vec4 tex = texture2D(refractionMap, refrCoords + vec2(blur + normal.x, blur + normal.z));
+ vec4 tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(refractionMap), refrCoords + vec2(blur + normal.x, blur + normal.z));
blurColor += vec4(tex.rgb * tex.a, tex.a);
- tex = texture2D(refractionMap, refrCoords + vec2(-blur, blur + normal.z));
+ tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(refractionMap), refrCoords + vec2(-blur, blur + normal.z));
blurColor += vec4(tex.rgb * tex.a, tex.a);
- tex = texture2D(refractionMap, refrCoords + vec2(-blur, -blur + normal.x));
+ tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(refractionMap), refrCoords + vec2(-blur, -blur + normal.x));
blurColor += vec4(tex.rgb * tex.a, tex.a);
- tex = texture2D(refractionMap, refrCoords + vec2(blur + normal.z, -blur));
+ tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(refractionMap), refrCoords + vec2(blur + normal.z, -blur));
blurColor += vec4(tex.rgb * tex.a, tex.a);
blurColor /= blurColor.a;
float blurFactor = (distoFactor / 7.0);
@@ -254,14 +198,14 @@ vec4 getFoam(vec4 fancyeffects, float shadow)
float wavyEffect = waveParams1.r;
float baseScale = waveParams1.g;
float BigMovement = waveParams2.b;
- vec3 foam1 = texture2D(normalMap, (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).aaa;
- vec3 foam2 = texture2D(normalMap2, (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).aaa;
- vec3 foam3 = texture2D(normalMap, normalCoords.st / 6.0 - normalCoords.zw * 0.02).aaa;
- vec3 foam4 = texture2D(normalMap2, normalCoords.st / 6.0 - normalCoords.zw * 0.02).aaa;
+ vec3 foam1 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normalMap), (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).aaa;
+ vec3 foam2 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normalMap2), (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).aaa;
+ vec3 foam3 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normalMap), normalCoords.st / 6.0 - normalCoords.zw * 0.02).aaa;
+ vec3 foam4 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normalMap2), normalCoords.st / 6.0 - normalCoords.zw * 0.02).aaa;
vec3 foaminterp = mix(foam1, foam2, moddedTime);
foaminterp *= mix(foam3, foam4, moddedTime);
- foam1.x = abs(foaminterp.x * WindCosSin.x) + abs(foaminterp.z * WindCosSin.y);
+ foam1.x = abs(foaminterp.x * windCosSin.x) + abs(foaminterp.z * windCosSin.y);
float alpha = (fancyeffects.g + pow(foam1.x * (3.0 + waviness), 2.6 - waviness / 5.5)) * 2.0;
return vec4(sunColor * shadow + ambient, clamp(alpha, 0.0, 1.0));
@@ -272,7 +216,9 @@ vec4 getFoam(vec4 fancyeffects, float shadow)
void main()
{
- float los = getLOS();
+#if !IGNORE_LOS
+ float los = getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
+#endif
// We don't need to render a water fragment if it's invisible.
if (los < 0.001)
{
@@ -281,7 +227,7 @@ void main()
}
#if USE_FANCY_EFFECTS
- vec4 fancyeffects = texture2D(waterEffectsTex, gl_FragCoord.xy / screenSize);
+ vec4 fancyeffects = SAMPLE_2D(GET_DRAW_TEXTURE_2D(waterEffectsTex), gl_FragCoord.xy / screenSize);
#else
vec4 fancyeffects = vec4(0.0);
#endif
@@ -313,7 +259,7 @@ void main()
vec4 foam = getFoam(fancyeffects, shadow);
color = clamp(mix(color, foam.rgb, foam.a), 0.0, 1.0);
- color = applyFog(color);
+ color = applyFog(color, fogColor, fogParams);
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(applyDebugColor(color * los, 1.0, refrColor.a, 0.0), refrColor.a));
}
diff --git a/binaries/data/mods/public/shaders/glsl/water_high.h b/binaries/data/mods/public/shaders/glsl/water_high.h
new file mode 100644
index 0000000000..c4d28a0897
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/water_high.h
@@ -0,0 +1,86 @@
+#include "common/shadows.h"
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ TEXTURE_CUBE(0, skyCube)
+ TEXTURE_2D(1, normalMap)
+ TEXTURE_2D(2, normalMap2)
+#if USE_FANCY_EFFECTS
+ TEXTURE_2D(3, waterEffectsTex)
+#endif
+#if USE_REFLECTION
+ TEXTURE_2D(4, reflectionMap)
+#endif
+#if USE_REFRACTION
+ TEXTURE_2D(5, refractionMap)
+#if USE_REAL_DEPTH
+ TEXTURE_2D(6, depthTex)
+#endif
+#endif
+#if !IGNORE_LOS
+ TEXTURE_2D(4, losTex)
+#endif
+#if USE_SHADOW
+ SHADOWS_TEXTURES(5)
+#endif
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, transform)
+END_DRAW_UNIFORMS
+
+BEGIN_MATERIAL_UNIFORMS
+ UNIFORM(mat4, reflectionMatrix)
+ UNIFORM(mat4, refractionMatrix)
+#if USE_REFRACTION && USE_REAL_DEPTH
+ UNIFORM(mat4, projInvTransform)
+ UNIFORM(mat4, viewInvTransform)
+#endif
+ UNIFORM(float, time)
+ UNIFORM(float, repeatScale)
+ UNIFORM(vec2, screenSize)
+ UNIFORM(vec3, cameraPos)
+
+ UNIFORM(float, waviness) // "Wildness" of the reflections and refractions; choose based on texture
+ UNIFORM(vec3, color) // color of the water
+ UNIFORM(vec3, tint) // Tint for refraction (used to simulate particles in water)
+ UNIFORM(float, murkiness) // Amount of tint to blend in with the refracted color
+ UNIFORM(float, windAngle)
+
+ UNIFORM(vec4, waveParams1) // wavyEffect, BaseScale, Flattenism, Basebump
+ UNIFORM(vec4, waveParams2) // Smallintensity, Smallbase, Bigmovement, Smallmovement
+
+ // Environment settings
+ UNIFORM(vec3, ambient)
+ UNIFORM(vec3, sunDir)
+ UNIFORM(vec3, sunColor)
+ UNIFORM(mat4, skyBoxRot)
+
+ UNIFORM(vec3, fogColor)
+ UNIFORM(vec2, fogParams)
+ UNIFORM(vec2, losTransform)
+#if USE_SHADOW
+ SHADOWS_UNIFORMS
+#endif
+END_MATERIAL_UNIFORMS
+
+VERTEX_OUTPUT(0, vec3, worldPos);
+VERTEX_OUTPUT(1, float, waterDepth);
+VERTEX_OUTPUT(2, vec2, waterInfo);
+VERTEX_OUTPUT(3, float, fwaviness);
+VERTEX_OUTPUT(4, float, moddedTime);
+VERTEX_OUTPUT(5, vec2, windCosSin);
+VERTEX_OUTPUT(6, vec3, v_eyeVec);
+VERTEX_OUTPUT(7, vec4, normalCoords);
+#if USE_REFLECTION
+VERTEX_OUTPUT(8, vec3, reflectionCoords);
+#endif
+#if USE_REFRACTION
+VERTEX_OUTPUT(9, vec3, refractionCoords);
+#endif
+#if !IGNORE_LOS
+VERTEX_OUTPUT(10, vec2, v_los);
+#endif
+#if USE_SHADOW
+SHADOWS_VERTEX_OUTPUTS(11)
+#endif
diff --git a/binaries/data/mods/public/shaders/glsl/water_high.vs b/binaries/data/mods/public/shaders/glsl/water_high.vs
index f20de8aa23..3eb7653038 100644
--- a/binaries/data/mods/public/shaders/glsl/water_high.vs
+++ b/binaries/data/mods/public/shaders/glsl/water_high.vs
@@ -1,40 +1,11 @@
#version 110
+#include "water_high.h"
+
#include "common/los_vertex.h"
#include "common/shadows_vertex.h"
#include "common/vertex.h"
-uniform mat4 reflectionMatrix;
-uniform mat4 refractionMatrix;
-uniform float repeatScale;
-uniform float windAngle;
-// "Wildness" of the reflections and refractions; choose based on texture
-uniform float waviness;
-
-uniform float time;
-
-uniform mat4 transform;
-uniform vec3 cameraPos;
-
-varying float moddedTime;
-
-varying vec3 worldPos;
-varying float waterDepth;
-varying vec2 waterInfo;
-
-varying vec3 v_eyeVec;
-
-varying vec4 normalCoords;
-#if USE_REFLECTION
-varying vec3 reflectionCoords;
-#endif
-#if USE_REFRACTION
-varying vec3 refractionCoords;
-#endif
-
-varying float fwaviness;
-varying vec2 WindCosSin;
-
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_waterInfo);
@@ -44,10 +15,10 @@ void main()
waterInfo = a_waterInfo;
waterDepth = a_waterInfo.g;
- WindCosSin = vec2(cos(-windAngle), sin(-windAngle));
+ windCosSin = vec2(cos(-windAngle), sin(-windAngle));
- float newX = a_vertex.x * WindCosSin.x - a_vertex.z * WindCosSin.y;
- float newY = a_vertex.x * WindCosSin.y + a_vertex.z * WindCosSin.x;
+ float newX = a_vertex.x * windCosSin.x - a_vertex.z * windCosSin.y;
+ float newY = a_vertex.x * windCosSin.y + a_vertex.z * windCosSin.x;
normalCoords = vec4(newX, newY, time, 0.0);
normalCoords.xy *= repeatScale;
@@ -58,7 +29,10 @@ void main()
#if USE_REFRACTION
refractionCoords = (refractionMatrix * vec4(a_vertex, 1.0)).rga;
#endif
- calculateLOSCoordinates(a_vertex.xz);
+
+#if !IGNORE_LOS
+ v_los = calculateLOSCoordinates(a_vertex.xz, losTransform);
+#endif
calculatePositionInShadowSpace(vec4(a_vertex, 1.0));
diff --git a/binaries/data/mods/public/shaders/glsl/water_simple.fs b/binaries/data/mods/public/shaders/glsl/water_simple.fs
index 6d002b4eee..874f8e667e 100644
--- a/binaries/data/mods/public/shaders/glsl/water_simple.fs
+++ b/binaries/data/mods/public/shaders/glsl/water_simple.fs
@@ -1,14 +1,18 @@
#version 110
+#include "water_simple.h"
+
+#include "common/fog.h"
#include "common/fragment.h"
#include "common/los_fragment.h"
-uniform sampler2D baseTex;
-uniform vec3 color;
-
-varying vec2 v_coords;
-
void main()
{
- OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(texture2D(baseTex, v_coords).rgb * color * getLOS(), 1.0));
+ vec3 waterColor = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_coords).rgb;
+ waterColor *= color;
+ waterColor = applyFog(waterColor, fogColor, fogParams);
+#if !IGNORE_LOS
+ waterColor *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
+#endif
+ OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(waterColor, 1.0));
}
diff --git a/binaries/data/mods/public/shaders/glsl/water_simple.h b/binaries/data/mods/public/shaders/glsl/water_simple.h
new file mode 100644
index 0000000000..36d1398962
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/water_simple.h
@@ -0,0 +1,25 @@
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, baseTex)
+#if !IGNORE_LOS
+ TEXTURE_2D(1, losTex)
+#endif
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(mat4, transform)
+ UNIFORM(float, time)
+ UNIFORM(vec3, color)
+END_DRAW_UNIFORMS
+
+BEGIN_MATERIAL_UNIFORMS
+ UNIFORM(vec3, fogColor)
+ UNIFORM(vec2, fogParams)
+ UNIFORM(vec2, losTransform)
+END_MATERIAL_UNIFORMS
+
+VERTEX_OUTPUT(0, vec2, v_coords);
+#if !IGNORE_LOS
+VERTEX_OUTPUT(1, vec2, v_los);
+#endif
\ No newline at end of file
diff --git a/binaries/data/mods/public/shaders/glsl/water_simple.vs b/binaries/data/mods/public/shaders/glsl/water_simple.vs
index a0d1dfb609..73fb8b2b60 100644
--- a/binaries/data/mods/public/shaders/glsl/water_simple.vs
+++ b/binaries/data/mods/public/shaders/glsl/water_simple.vs
@@ -1,15 +1,12 @@
#version 110
+#include "water_simple.h"
+
#include "common/los_vertex.h"
#include "common/vertex.h"
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
-uniform mat4 transform;
-uniform float time;
-
-varying vec2 v_coords;
-
void main()
{
// Shift the texture coordinates by these amounts to make the water "flow"
@@ -18,6 +15,8 @@ void main()
float repeatPeriod = 16.0;
v_coords = a_vertex.xz / repeatPeriod + vec2(tx, tz);
- calculateLOSCoordinates(a_vertex.xz);
+#if !IGNORE_LOS
+ v_los = calculateLOSCoordinates(a_vertex.xz, losTransform);
+#endif
OUTPUT_VERTEX_POSITION(transform * vec4(a_vertex, 1.0));
}
diff --git a/binaries/data/mods/public/shaders/glsl/waves.fs b/binaries/data/mods/public/shaders/glsl/waves.fs
index b86e1e6d20..b37f145a6a 100644
--- a/binaries/data/mods/public/shaders/glsl/waves.fs
+++ b/binaries/data/mods/public/shaders/glsl/waves.fs
@@ -1,20 +1,12 @@
#version 110
+#include "waves.h"
+
#include "common/fragment.h"
-uniform sampler2D waveTex;
-uniform sampler2D foamTex;
-
-uniform float translation;
-uniform float width;
-
-varying float ttime;
-varying vec2 normal;
-varying vec2 v_tex;
-
void main()
{
- vec4 Tex = texture2D(waveTex, -v_tex.xy/8.0).rbga;
+ vec4 Tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(waveTex), -v_tex.xy/8.0).rbga;
Tex.rgb -= vec3(0.5,0.0,0.5);
Tex.rb *= -1.0;
@@ -37,8 +29,8 @@ void main()
Tex.r = norm.x * normal.x - norm.y * normal.x;
Tex.b = norm.x * normal.y + norm.y * normal.y;
- vec3 foam = texture2D(foamTex, -v_tex.xy/vec2(2.5,7.0) + vec2(0.05,-0.3)*-cos(ttime/2.0)).rbg;
- foam *= texture2D(foamTex, -v_tex.xy/5.0 + vec2(0.8,-0.8) + vec2(-0.05,-0.25)*-cos(ttime/2.0)*1.2).rbg;
+ vec3 foam = SAMPLE_2D(GET_DRAW_TEXTURE_2D(foamTex), -v_tex.xy/vec2(2.5,7.0) + vec2(0.05,-0.3)*-cos(ttime/2.0)).rbg;
+ foam *= SAMPLE_2D(GET_DRAW_TEXTURE_2D(foamTex), -v_tex.xy/5.0 + vec2(0.8,-0.8) + vec2(-0.05,-0.25)*-cos(ttime/2.0)*1.2).rbg;
Tex.g = foamAlpha * clamp(foam.r * 3.0, 0.0, 1.0) * 0.4;
OUTPUT_FRAGMENT_SINGLE_COLOR(Tex);
diff --git a/binaries/data/mods/public/shaders/glsl/waves.h b/binaries/data/mods/public/shaders/glsl/waves.h
new file mode 100644
index 0000000000..867867bbaf
--- /dev/null
+++ b/binaries/data/mods/public/shaders/glsl/waves.h
@@ -0,0 +1,17 @@
+#include "common/stage.h"
+
+BEGIN_DRAW_TEXTURES
+ TEXTURE_2D(0, waveTex)
+ TEXTURE_2D(1, foamTex)
+END_DRAW_TEXTURES
+
+BEGIN_DRAW_UNIFORMS
+ UNIFORM(float, translation)
+ UNIFORM(float, width)
+ UNIFORM(float, time)
+ UNIFORM(mat4, transform)
+END_DRAW_UNIFORMS
+
+VERTEX_OUTPUT(0, float, ttime);
+VERTEX_OUTPUT(1, vec2, normal);
+VERTEX_OUTPUT(2, vec2, v_tex);
diff --git a/binaries/data/mods/public/shaders/glsl/waves.vs b/binaries/data/mods/public/shaders/glsl/waves.vs
index c0dc177ecb..0b82aeb8c0 100644
--- a/binaries/data/mods/public/shaders/glsl/waves.vs
+++ b/binaries/data/mods/public/shaders/glsl/waves.vs
@@ -1,5 +1,7 @@
#version 110
+#include "waves.h"
+
#include "common/vertex.h"
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_basePosition);
@@ -9,16 +11,6 @@ VERTEX_INPUT_ATTRIBUTE(3, vec3, a_retreatPosition);
VERTEX_INPUT_ATTRIBUTE(4, vec2, a_normal);
VERTEX_INPUT_ATTRIBUTE(5, vec2, a_uv0);
-uniform float time;
-uniform float translation;
-uniform float width;
-
-uniform mat4 transform;
-
-varying float ttime;
-varying vec2 normal;
-varying vec2 v_tex;
-
void main()
{
normal = a_normal;
diff --git a/source/renderer/backend/gl/ShaderProgram.cpp b/source/renderer/backend/gl/ShaderProgram.cpp
index 0144502e40..c76b04a79c 100644
--- a/source/renderer/backend/gl/ShaderProgram.cpp
+++ b/source/renderer/backend/gl/ShaderProgram.cpp
@@ -173,7 +173,7 @@ int GetAttributeLocationFromStream(
}
bool PreprocessShaderFile(
- bool arb, const CShaderDefines& defines, const VfsPath& path,
+ bool arb, const CShaderDefines& defines, const VfsPath& path, const char* stage,
CStr& source, std::vector& fileDependencies)
{
CVFSFile file;
@@ -201,6 +201,8 @@ bool PreprocessShaderFile(
return true;
});
preprocessor.AddDefines(defines);
+ if (!arb)
+ preprocessor.AddDefine(stage, "1");
#if CONFIG2_GLES
if (!arb)
@@ -284,10 +286,10 @@ public:
std::vector newFileDependencies = {path, vertexFilePath, fragmentFilePath};
CStr vertexCode;
- if (!PreprocessShaderFile(true, defines, vertexFilePath, vertexCode, newFileDependencies))
+ if (!PreprocessShaderFile(true, defines, vertexFilePath, "STAGE_VERTEX", vertexCode, newFileDependencies))
return;
CStr fragmentCode;
- if (!PreprocessShaderFile(true, defines, fragmentFilePath, fragmentCode, newFileDependencies))
+ if (!PreprocessShaderFile(true, defines, fragmentFilePath, "STAGE_FRAGMENT", fragmentCode, newFileDependencies))
return;
m_FileDependencies = std::move(newFileDependencies);
@@ -614,10 +616,10 @@ public:
std::vector newFileDependencies = {path, vertexFilePath, fragmentFilePath};
CStr vertexCode;
- if (!PreprocessShaderFile(false, defines, vertexFilePath, vertexCode, newFileDependencies))
+ if (!PreprocessShaderFile(false, defines, vertexFilePath, "STAGE_VERTEX", vertexCode, newFileDependencies))
return;
CStr fragmentCode;
- if (!PreprocessShaderFile(false, defines, fragmentFilePath, fragmentCode, newFileDependencies))
+ if (!PreprocessShaderFile(false, defines, fragmentFilePath, "STAGE_FRAGMENT", fragmentCode, newFileDependencies))
return;
m_FileDependencies = std::move(newFileDependencies);