59 lines
2.1 KiB
HLSL
59 lines
2.1 KiB
HLSL
#ifndef SEASON_CORE_INCLUDED
|
|
#define SEASON_CORE_INCLUDED
|
|
|
|
// =====================================================================================
|
|
// Season Core - logique de saison PARTAGÉE (herbe, feuilles, ...).
|
|
// Pas de CBUFFER ici : que des fonctions pures + le global _Season.
|
|
// À inclure APRÈS Core.hlsl dans chaque shader saisonnier.
|
|
// =====================================================================================
|
|
|
|
// Global saison 0..3 : 0 = Été/vert, 1 = Automne, 2 = Hiver (reboucle à l'été).
|
|
// Poussé par le SeasonManager via Shader.SetGlobalFloat("_Season", ...).
|
|
float _Season;
|
|
|
|
// Indices des 2 saisons actives + fraction de transition (gère le wrap hiver->été).
|
|
void SeasonBlend(out int i0, out int i1, out float f)
|
|
{
|
|
float s = _Season - 3.0 * floor(_Season / 3.0); // wrap dans [0,3)
|
|
float fl = floor(s);
|
|
i0 = ((int)fl) % 3;
|
|
i1 = (i0 + 1) % 3;
|
|
f = s - fl;
|
|
}
|
|
|
|
// Poids de l'hiver dans le mélange courant (0 = pas d'hiver, 1 = plein hiver). Hiver = index 2.
|
|
float SeasonWinterWeight()
|
|
{
|
|
int i0, i1; float f;
|
|
SeasonBlend(i0, i1, f);
|
|
float w = 0.0;
|
|
if (i0 == 2) w += (1.0 - f);
|
|
if (i1 == 2) w += f;
|
|
return w;
|
|
}
|
|
|
|
// -------------------------------------------------------------------------------------
|
|
// Bruit procédural (gradient noise, équivalent du noeud "Gradient Noise" de SG).
|
|
// -------------------------------------------------------------------------------------
|
|
float2 SeasonHash22(float2 p)
|
|
{
|
|
p = float2(dot(p, float2(127.1, 311.7)), dot(p, float2(269.5, 183.3)));
|
|
return -1.0 + 2.0 * frac(sin(p) * 43758.5453123);
|
|
}
|
|
|
|
float SeasonGradientNoise(float2 uv)
|
|
{
|
|
float2 i = floor(uv);
|
|
float2 f = frac(uv);
|
|
float2 u = f * f * (3.0 - 2.0 * f);
|
|
|
|
float a = dot(SeasonHash22(i + float2(0, 0)), f - float2(0, 0));
|
|
float b = dot(SeasonHash22(i + float2(1, 0)), f - float2(1, 0));
|
|
float c = dot(SeasonHash22(i + float2(0, 1)), f - float2(0, 1));
|
|
float d = dot(SeasonHash22(i + float2(1, 1)), f - float2(1, 1));
|
|
|
|
return lerp(lerp(a, b, u.x), lerp(c, d, u.x), u.y) * 0.5 + 0.5; // -> 0..1
|
|
}
|
|
|
|
#endif // SEASON_CORE_INCLUDED
|