Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/display/Textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ void MapCanvas::initTextures()
textures.white_pixel = MMTexture::alloc(std::vector<QImage>{whitePixel}, true);
}
{
// weather noise is 256
QImage noiseImage = createTileableValueNoiseImage(256);
// weather noise texture
QImage noiseImage = createTileableValueNoiseImage(WeatherConstants::WEATHER_NOISE_SIZE);
textures.noise = MMTexture::alloc(std::vector<QImage>{noiseImage}, false);
}

Expand Down
2 changes: 2 additions & 0 deletions src/opengl/Weather.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ constexpr float WEATHER_EXTENT = 28.0f;
constexpr float WEATHER_MASK_RADIUS_OUTER = 12.0f;
constexpr float WEATHER_MASK_RADIUS_INNER = 8.0f;
constexpr float TRANSITION_DURATION = 2.0f;
constexpr int WEATHER_NOISE_SIZE = 256;
constexpr float WEATHER_INV_NOISE_SIZE = 1.0f / static_cast<float>(WEATHER_NOISE_SIZE);
} // namespace WeatherConstants

/**
Expand Down
7 changes: 6 additions & 1 deletion src/opengl/legacy/ShaderUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,18 @@ NODISCARD static GLuint compileShader(Functions &gl, const GLenum type, const So
+ text_utils::formatFloatClassic(
WeatherConstants::WEATHER_MASK_RADIUS_INNER)
+ "\n";
std::string defineWeatherInvNoiseSize = "#define WEATHER_INV_NOISE_SIZE "
+ text_utils::formatFloatClassic(
WeatherConstants::WEATHER_INV_NOISE_SIZE)
+ "\n";

std::array<const char *, 8> ptrs = {gl.getShaderVersion(),
std::array<const char *, 9> ptrs = {gl.getShaderVersion(),
defineNamedColors.c_str(),
defineWeatherRadius.c_str(),
defineWeatherExtent.c_str(),
defineWeatherMaskOuter.c_str(),
defineWeatherMaskInner.c_str(),
defineWeatherInvNoiseSize.c_str(),
"#line 1\n",
source.source.c_str()};
gl.glShaderSource(shaderId, static_cast<GLsizei>(ptrs.size()), ptrs.data(), nullptr);
Expand Down
25 changes: 14 additions & 11 deletions src/resources/shaders/legacy/weather/atmosphere/frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ layout(std140) uniform NamedColorsBlock
layout(std140) uniform CameraBlock
{
mat4 uViewProj;
vec4 uPlayerPos; // xyz, w=zScale
vec4 uPlayerPos; // xyz, w=zScale
};

layout(std140) uniform TimeBlock
Expand All @@ -32,22 +32,22 @@ uniform sampler2D uTexture;
in vec3 vWorldPos;
out vec4 vFragmentColor;

// Avoid dynamic textureSize queries in fragment loop on Intel GPUs; WEATHER_INV_NOISE_SIZE is injected at shader compile time
float get_noise(vec2 p)
{
vec2 size = vec2(textureSize(uTexture, 0));
return texture(uTexture, p / size).r;
return texture(uTexture, p * WEATHER_INV_NOISE_SIZE).r;
}

float fbm(vec2 p)
{
float v = 0.0;
float a = 0.5;
vec2 shift = vec2(100.0);
for (int i = 0; i < 4; ++i) {
v += a * get_noise(p);
p = p * 2.0 + shift;
a *= 0.5;
}
float v = 0.5 * get_noise(p);
p = p * 2.0 + shift;
v += 0.25 * get_noise(p);
p = p * 2.0 + shift;
v += 0.125 * get_noise(p);
p = p * 2.0 + shift;
v += 0.0625 * get_noise(p);
return v;
}

Expand All @@ -56,7 +56,10 @@ void main()
vec3 worldPos = vWorldPos;

float distToPlayer = distance(worldPos.xy, uPlayerPos.xy);
float localMask = 1.0 - smoothstep(WEATHER_MASK_RADIUS_INNER, WEATHER_MASK_RADIUS_OUTER, distToPlayer);
float localMask = 1.0
- smoothstep(WEATHER_MASK_RADIUS_INNER,
WEATHER_MASK_RADIUS_OUTER,
distToPlayer);

float uCurrentTime = uTime.x;
float uWeatherStartTime = uConfig.x;
Expand Down
Loading