17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-02 19:49:15 +01:00

fix(track): seasonal and specgloss track materials blended at the joints

This commit is contained in:
2026-10-21 23:15:29 +02:00
parent 283b8523e6
commit 674abfeeab
9 changed files with 220 additions and 69 deletions

View File

@@ -1,2 +1,10 @@
// the rails of a track faded into those of the tracks joined at its ends, see trackblend.glsl
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (diffuse1, 1, sRGB_A)
uniform sampler2D diffuse1;
#texture (diffuse2, 2, sRGB_A)
uniform sampler2D diffuse2;
#texture (diffuse3, 3, sRGB_A)
uniform sampler2D diffuse3;
#include <trackblend.glsl>

View File

@@ -1,3 +1,11 @@
// the ballast of a track mixed in grains into that of the tracks joined at its ends, see trackblend.glsl
#define TRACKBLEND_GRAIN 1
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (diffuse1, 1, sRGB_A)
uniform sampler2D diffuse1;
#texture (diffuse2, 2, sRGB_A)
uniform sampler2D diffuse2;
#texture (diffuse3, 3, sRGB_A)
uniform sampler2D diffuse3;
#include <trackblend.glsl>

View File

@@ -1,5 +1,13 @@
// the rails of a track of a normal mapped material faded into those of the tracks joined at its ends, see trackblend.glsl
#define TRACKBLEND_NORMALMAP 1
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (diffuse1, 1, sRGB_A)
uniform sampler2D diffuse1;
#texture (diffuse2, 2, sRGB_A)
uniform sampler2D diffuse2;
#texture (diffuse3, 3, sRGB_A)
uniform sampler2D diffuse3;
#texture (normalmap, 4, RGBA)
uniform sampler2D normalmap;
#texture (normalmap1, 5, RGBA)

View File

@@ -1,6 +1,14 @@
// the ballast of a track of a normal mapped material mixed in grains into that of the tracks joined at its ends, see trackblend.glsl
#define TRACKBLEND_GRAIN 1
#define TRACKBLEND_NORMALMAP 1
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (diffuse1, 1, sRGB_A)
uniform sampler2D diffuse1;
#texture (diffuse2, 2, sRGB_A)
uniform sampler2D diffuse2;
#texture (diffuse3, 3, sRGB_A)
uniform sampler2D diffuse3;
#texture (normalmap, 4, RGBA)
uniform sampler2D normalmap;
#texture (normalmap1, 5, RGBA)

View File

@@ -0,0 +1,18 @@
// the rails of a track of a material with normal and specgloss maps faded into those of the tracks joined at its ends, see trackblend.glsl
#define TRACKBLEND_NORMALMAP 1
#define TRACKBLEND_SPECGLOSS 1
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (diffuse1, 1, sRGB_A)
uniform sampler2D diffuse1;
#texture (diffuse2, 2, sRGB_A)
uniform sampler2D diffuse2;
#texture (normalmap, 3, RGBA)
uniform sampler2D normalmap;
#texture (normalmap1, 4, RGBA)
uniform sampler2D normalmap1;
#texture (normalmap2, 5, RGBA)
uniform sampler2D normalmap2;
#texture (specgloss, 6, RGBA)
uniform sampler2D specgloss;
#include <trackblend.glsl>

View File

@@ -0,0 +1,19 @@
// the ballast of a track of a material with normal and specgloss maps mixed in grains into that of the tracks joined at its ends, see trackblend.glsl
#define TRACKBLEND_GRAIN 1
#define TRACKBLEND_NORMALMAP 1
#define TRACKBLEND_SPECGLOSS 1
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (diffuse1, 1, sRGB_A)
uniform sampler2D diffuse1;
#texture (diffuse2, 2, sRGB_A)
uniform sampler2D diffuse2;
#texture (normalmap, 3, RGBA)
uniform sampler2D normalmap;
#texture (normalmap1, 4, RGBA)
uniform sampler2D normalmap1;
#texture (normalmap2, 5, RGBA)
uniform sampler2D normalmap2;
#texture (specgloss, 6, RGBA)
uniform sampler2D specgloss;
#include <trackblend.glsl>

View File

@@ -1,12 +1,15 @@
// a track drawn with the textures of the tracks joined at its ends blended in near them (world/TrackBlend.h): the weights of the
// tracks joined at the ends p1, p2 and p4 of a switch in UserData.yzw, their textures in diffuse1..3, lit as mat_default.
// TRACKBLEND_GRAIN: the others come in as grains, as the stones of two ballasts would mix, rather than faded in.
// TRACKBLEND_NORMALMAP: with the normal maps of the four in normalmap..normalmap3 (declared by the including shader), lit as
// the shader of the material of the track: param[2].x 1 normalmap, 2 sunlessnormalmap, 3 shadowlessnormalmap
// tracks joined at the ends p1, p2 and p4 of a switch in UserData.yzw, their textures in diffuse1..3, normalmap1..3. the
// including shader declares the textures and sets:
// TRACKBLEND_GRAIN the others come in as grains, as the stones of two ballasts would mix, rather than faded in
// TRACKBLEND_NORMALMAP with the normal maps of the four, lit as the shader of the material of the track: param[2].x 0 as
// mat_default, 1 normalmap, 2 sunlessnormalmap, 3 shadowlessnormalmap
// TRACKBLEND_SPECGLOSS the specgloss map of the track itself as well, the textures of the ends p1 and p2 alone (no room
// for a third set of them)
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
#if TRACKBLEND_NORMALMAP
#ifdef TRACKBLEND_NORMALMAP
in mat3 f_tbn;
#endif
@@ -22,15 +25,6 @@ in vec4 f_clip_future_pos;
#param (glossiness, 1, 3, 1, glossiness)
#param (blendlighting, 2, 0, 1, zero)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (diffuse1, 1, sRGB_A)
uniform sampler2D diffuse1;
#texture (diffuse2, 2, sRGB_A)
uniform sampler2D diffuse2;
#texture (diffuse3, 3, sRGB_A)
uniform sampler2D diffuse3;
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
@@ -40,7 +34,7 @@ layout(location = 1) out vec4 out_motion;
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#if TRACKBLEND_GRAIN
#ifdef TRACKBLEND_GRAIN
// grains per repeat of the texture: a ballast texture repeats every few metres, a grain is a handful of its stones
const float GRAIN_CELLS = 28.0;
@@ -85,7 +79,11 @@ float grain_value(vec2 p)
void main()
{
#ifdef TRACKBLEND_SPECGLOSS
vec3 weights = clamp(vec3(UserData.yz, 0.0), 0.0, 1.0);
#else
vec3 weights = clamp(UserData.yzw, 0.0, 1.0);
#endif
float total = weights.x + weights.y + weights.z;
if (total > 1.0)
{
@@ -95,19 +93,19 @@ void main()
// the gradients are taken outside the branches the textures are sampled in
vec2 dx = dFdx(f_coord);
vec2 dy = dFdy(f_coord);
#if TRACKBLEND_GRAIN
#ifdef TRACKBLEND_GRAIN
vec2 grainpos = f_coord * GRAIN_CELLS;
// grains smaller than a pixel would shimmer, there the textures fade into each other instead
float footprint = max(length(dx), length(dy)) * GRAIN_CELLS;
float grained = 1.0 - smoothstep(0.35, 0.9, footprint);
#endif
vec4 tex_color = textureGrad(diffuse, f_coord, dx, dy);
#if TRACKBLEND_NORMALMAP
#ifdef TRACKBLEND_NORMALMAP
vec4 tex_normal = textureGrad(normalmap, f_coord, dx, dy);
#endif
if (total > 0.0)
{
#if TRACKBLEND_GRAIN
#ifdef TRACKBLEND_GRAIN
// the grain is of the track joined at the end whose share its value falls in, of the track itself past them
float pick = grain_value(grainpos);
float first = weights.x;
@@ -117,32 +115,34 @@ void main()
total = weights.x + weights.y + weights.z;
#endif
vec4 blended = tex_color * (1.0 - total);
#if TRACKBLEND_NORMALMAP
#ifdef TRACKBLEND_NORMALMAP
vec4 blendednormal = tex_normal * (1.0 - total);
#endif
if (weights.x > 0.0)
{
blended += textureGrad(diffuse1, f_coord, dx, dy) * weights.x;
#if TRACKBLEND_NORMALMAP
#ifdef TRACKBLEND_NORMALMAP
blendednormal += textureGrad(normalmap1, f_coord, dx, dy) * weights.x;
#endif
}
if (weights.y > 0.0)
{
blended += textureGrad(diffuse2, f_coord, dx, dy) * weights.y;
#if TRACKBLEND_NORMALMAP
#ifdef TRACKBLEND_NORMALMAP
blendednormal += textureGrad(normalmap2, f_coord, dx, dy) * weights.y;
#endif
}
#ifndef TRACKBLEND_SPECGLOSS
if (weights.z > 0.0)
{
blended += textureGrad(diffuse3, f_coord, dx, dy) * weights.z;
#if TRACKBLEND_NORMALMAP
#ifdef TRACKBLEND_NORMALMAP
blendednormal += textureGrad(normalmap3, f_coord, dx, dy) * weights.z;
#endif
}
#endif
tex_color = blended;
#if TRACKBLEND_NORMALMAP
#ifdef TRACKBLEND_NORMALMAP
tex_normal = blendednormal;
#endif
}
@@ -152,14 +152,21 @@ void main()
discard;
vec3 fragcolor = ambient;
#if TRACKBLEND_NORMALMAP
#ifdef TRACKBLEND_NORMALMAP
vec3 normal;
normal.xy = (tex_normal.rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * tex_normal.a;
#ifdef TRACKBLEND_SPECGLOSS
vec4 tex_specgloss = textureGrad(specgloss, f_coord, dx, dy);
float specularity = tex_specgloss.r;
glossiness = tex_specgloss.g * abs(param[1].w);
metalic = tex_specgloss.b;
#else
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
legacy_gloss();
#endif
int lighting = int(param[2].x + 0.5);
if (lighting == 2)
fragcolor = apply_lights_sunless(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);