@@ -215,6 +215,10 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
private int centerY;
|
private int centerY;
|
||||||
|
|
||||||
// Uniforms
|
// Uniforms
|
||||||
|
private int uniUseFog;
|
||||||
|
private int uniFogColor;
|
||||||
|
private int uniFogDepth;
|
||||||
|
private int uniDrawDistance;
|
||||||
private int uniProjectionMatrix;
|
private int uniProjectionMatrix;
|
||||||
private int uniBrightness;
|
private int uniBrightness;
|
||||||
private int uniTex;
|
private int uniTex;
|
||||||
@@ -506,6 +510,10 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
uniProjectionMatrix = gl.glGetUniformLocation(glProgram, "projectionMatrix");
|
uniProjectionMatrix = gl.glGetUniformLocation(glProgram, "projectionMatrix");
|
||||||
uniBrightness = gl.glGetUniformLocation(glProgram, "brightness");
|
uniBrightness = gl.glGetUniformLocation(glProgram, "brightness");
|
||||||
uniSmoothBanding = gl.glGetUniformLocation(glProgram, "smoothBanding");
|
uniSmoothBanding = gl.glGetUniformLocation(glProgram, "smoothBanding");
|
||||||
|
uniUseFog = gl.glGetUniformLocation(glProgram, "useFog");
|
||||||
|
uniFogColor = gl.glGetUniformLocation(glProgram, "fogColor");
|
||||||
|
uniFogDepth = gl.glGetUniformLocation(glProgram, "fogDepth");
|
||||||
|
uniDrawDistance = gl.glGetUniformLocation(glProgram, "drawDistance");
|
||||||
|
|
||||||
uniTex = gl.glGetUniformLocation(glUiProgram, "tex");
|
uniTex = gl.glGetUniformLocation(glUiProgram, "tex");
|
||||||
uniTextures = gl.glGetUniformLocation(glProgram, "textures");
|
uniTextures = gl.glGetUniformLocation(glProgram, "textures");
|
||||||
@@ -723,7 +731,6 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
scene.setDrawDistance(drawDistance);
|
scene.setDrawDistance(drawDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void drawScenePaint(int orientation, int pitchSin, int pitchCos, int yawSin, int yawCos, int x, int y, int z,
|
public void drawScenePaint(int orientation, int pitchSin, int pitchCos, int yawSin, int yawCos, int x, int y, int z,
|
||||||
SceneTilePaint paint, int tileZ, int tileX, int tileY,
|
SceneTilePaint paint, int tileZ, int tileX, int tileY,
|
||||||
int zoom, int centerX, int centerY)
|
int zoom, int centerX, int centerY)
|
||||||
@@ -1016,6 +1023,13 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
|
|
||||||
gl.glUseProgram(glProgram);
|
gl.glUseProgram(glProgram);
|
||||||
|
|
||||||
|
final int drawDistance = Math.max(0, Math.min(MAX_DISTANCE, config.drawDistance()));
|
||||||
|
final int fogDepth = config.fogDepth();
|
||||||
|
gl.glUniform1i(uniUseFog, fogDepth > 0 ? 1 : 0);
|
||||||
|
gl.glUniform4f(uniFogColor, (sky >> 16 & 0xFF) / 255f, (sky >> 8 & 0xFF) / 255f, (sky & 0xFF) / 255f, 1f);
|
||||||
|
gl.glUniform1i(uniFogDepth, fogDepth);
|
||||||
|
gl.glUniform1i(uniDrawDistance, drawDistance * Perspective.LOCAL_TILE_SIZE);
|
||||||
|
|
||||||
// Brightness happens to also be stored in the texture provider, so we use that
|
// Brightness happens to also be stored in the texture provider, so we use that
|
||||||
gl.glUniform1f(uniBrightness, (float) textureProvider.getBrightness());
|
gl.glUniform1f(uniBrightness, (float) textureProvider.getBrightness());
|
||||||
gl.glUniform1f(uniSmoothBanding, config.smoothBanding() ? 0f : 1f);
|
gl.glUniform1f(uniSmoothBanding, config.smoothBanding() ? 0f : 1f);
|
||||||
|
|||||||
@@ -64,4 +64,15 @@ public interface GpuPluginConfig extends Config
|
|||||||
{
|
{
|
||||||
return AntiAliasingMode.DISABLED;
|
return AntiAliasingMode.DISABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "fogDepth",
|
||||||
|
name = "Fog depth",
|
||||||
|
description = "Distance from the scene edge the fog starts",
|
||||||
|
position = 4
|
||||||
|
)
|
||||||
|
default int fogDepth()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,10 +28,12 @@ uniform sampler2DArray textures;
|
|||||||
uniform vec2 textureOffsets[64];
|
uniform vec2 textureOffsets[64];
|
||||||
uniform float brightness;
|
uniform float brightness;
|
||||||
uniform float smoothBanding;
|
uniform float smoothBanding;
|
||||||
|
uniform vec4 fogColor;
|
||||||
|
|
||||||
in vec4 Color;
|
in vec4 Color;
|
||||||
in float fHsl;
|
in float fHsl;
|
||||||
in vec4 fUv;
|
in vec4 fUv;
|
||||||
|
in float fogAmount;
|
||||||
|
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
@@ -54,8 +56,9 @@ void main() {
|
|||||||
vec4 textureColor = texture(textures, vec3(animatedUv, n));
|
vec4 textureColor = texture(textures, vec3(animatedUv, n));
|
||||||
vec4 textureColorBrightness = pow(textureColor, vec4(brightness, brightness, brightness, 1.0f));
|
vec4 textureColorBrightness = pow(textureColor, vec4(brightness, brightness, brightness, 1.0f));
|
||||||
|
|
||||||
FragColor = textureColorBrightness * smoothColor;
|
smoothColor = textureColorBrightness * smoothColor;
|
||||||
} else {
|
|
||||||
FragColor = smoothColor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vec3 mixedColor = mix(smoothColor.rgb, fogColor.rgb, fogAmount);
|
||||||
|
FragColor = vec4(mixedColor, smoothColor.a);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,10 +49,12 @@ in ivec3 vPosition[];
|
|||||||
in vec4 vColor[];
|
in vec4 vColor[];
|
||||||
in float vHsl[];
|
in float vHsl[];
|
||||||
in vec4 vUv[];
|
in vec4 vUv[];
|
||||||
|
in float vFogAmount[];
|
||||||
|
|
||||||
out vec4 Color;
|
out vec4 Color;
|
||||||
out float fHsl;
|
out float fHsl;
|
||||||
out vec4 fUv;
|
out vec4 fUv;
|
||||||
|
out float fogAmount;
|
||||||
|
|
||||||
#include to_screen.glsl
|
#include to_screen.glsl
|
||||||
|
|
||||||
@@ -71,6 +73,7 @@ void main() {
|
|||||||
Color = vColor[0];
|
Color = vColor[0];
|
||||||
fHsl = vHsl[0];
|
fHsl = vHsl[0];
|
||||||
fUv = vUv[0];
|
fUv = vUv[0];
|
||||||
|
fogAmount = vFogAmount[0];
|
||||||
gl_Position = projectionMatrix * tmp;
|
gl_Position = projectionMatrix * tmp;
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
@@ -78,6 +81,7 @@ void main() {
|
|||||||
Color = vColor[1];
|
Color = vColor[1];
|
||||||
fHsl = vHsl[1];
|
fHsl = vHsl[1];
|
||||||
fUv = vUv[1];
|
fUv = vUv[1];
|
||||||
|
fogAmount = vFogAmount[1];
|
||||||
gl_Position = projectionMatrix * tmp;
|
gl_Position = projectionMatrix * tmp;
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
@@ -85,6 +89,7 @@ void main() {
|
|||||||
Color = vColor[2];
|
Color = vColor[2];
|
||||||
fHsl = vHsl[2];
|
fHsl = vHsl[2];
|
||||||
fUv = vUv[2];
|
fUv = vUv[2];
|
||||||
|
fogAmount = vFogAmount[2];
|
||||||
gl_Position = projectionMatrix * tmp;
|
gl_Position = projectionMatrix * tmp;
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
|
|||||||
@@ -25,18 +25,43 @@
|
|||||||
|
|
||||||
#version 330
|
#version 330
|
||||||
|
|
||||||
|
#define TILE_SIZE 128
|
||||||
|
|
||||||
|
#define FOG_SCENE_EDGE_MIN TILE_SIZE
|
||||||
|
#define FOG_SCENE_EDGE_MAX (103 * TILE_SIZE)
|
||||||
|
|
||||||
layout (location = 0) in ivec4 VertexPosition;
|
layout (location = 0) in ivec4 VertexPosition;
|
||||||
layout (location = 1) in vec4 uv;
|
layout (location = 1) in vec4 uv;
|
||||||
|
|
||||||
|
layout(std140) uniform uniforms {
|
||||||
|
int cameraYaw;
|
||||||
|
int cameraPitch;
|
||||||
|
int centerX;
|
||||||
|
int centerY;
|
||||||
|
int zoom;
|
||||||
|
int cameraX;
|
||||||
|
int cameraY;
|
||||||
|
int cameraZ;
|
||||||
|
ivec2 sinCosTable[2048];
|
||||||
|
};
|
||||||
|
|
||||||
uniform float brightness;
|
uniform float brightness;
|
||||||
|
uniform int useFog;
|
||||||
|
uniform int fogDepth;
|
||||||
|
uniform int drawDistance;
|
||||||
|
|
||||||
out ivec3 vPosition;
|
out ivec3 vPosition;
|
||||||
out vec4 vColor;
|
out vec4 vColor;
|
||||||
out float vHsl;
|
out float vHsl;
|
||||||
out vec4 vUv;
|
out vec4 vUv;
|
||||||
|
out float vFogAmount;
|
||||||
|
|
||||||
#include hsl_to_rgb.glsl
|
#include hsl_to_rgb.glsl
|
||||||
|
|
||||||
|
float fogFactorLinear(const float dist, const float start, const float end) {
|
||||||
|
return 1.0 - clamp((dist - start) / (end - start), 0.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
ivec3 vertex = VertexPosition.xyz;
|
ivec3 vertex = VertexPosition.xyz;
|
||||||
@@ -50,4 +75,14 @@ void main()
|
|||||||
vColor = vec4(rgb, 1.f - a);
|
vColor = vec4(rgb, 1.f - a);
|
||||||
vHsl = float(hsl);
|
vHsl = float(hsl);
|
||||||
vUv = uv;
|
vUv = uv;
|
||||||
|
|
||||||
|
int fogWest = max(FOG_SCENE_EDGE_MIN, cameraX - drawDistance);
|
||||||
|
int fogEast = min(FOG_SCENE_EDGE_MAX, cameraX + drawDistance - TILE_SIZE);
|
||||||
|
int fogSouth = max(FOG_SCENE_EDGE_MIN, cameraZ - drawDistance);
|
||||||
|
int fogNorth = min(FOG_SCENE_EDGE_MAX, cameraZ + drawDistance - TILE_SIZE);
|
||||||
|
|
||||||
|
// Calculate distance from the scene edge
|
||||||
|
float fogDistance = min(min(vertex.x - fogWest, fogEast - vertex.x), min(vertex.z - fogSouth, fogNorth - vertex.z));
|
||||||
|
|
||||||
|
vFogAmount = fogFactorLinear(fogDistance, 0, fogDepth * TILE_SIZE) * useFog;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user