2026-02-21 19:41:21 -08:00
|
|
|
#version 450
|
|
|
|
|
|
|
|
|
|
layout(set = 0, binding = 0) uniform PerFrame {
|
|
|
|
|
mat4 view;
|
|
|
|
|
mat4 projection;
|
|
|
|
|
mat4 lightSpaceMatrix;
|
|
|
|
|
vec4 lightDir;
|
|
|
|
|
vec4 lightColor;
|
|
|
|
|
vec4 ambientColor;
|
|
|
|
|
vec4 viewPos;
|
|
|
|
|
vec4 fogColor;
|
|
|
|
|
vec4 fogParams;
|
|
|
|
|
vec4 shadowParams;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
layout(set = 1, binding = 0) uniform sampler2D uBaseTexture;
|
|
|
|
|
layout(set = 1, binding = 1) uniform sampler2D uLayer1Texture;
|
|
|
|
|
layout(set = 1, binding = 2) uniform sampler2D uLayer2Texture;
|
|
|
|
|
layout(set = 1, binding = 3) uniform sampler2D uLayer3Texture;
|
|
|
|
|
layout(set = 1, binding = 4) uniform sampler2D uLayer1Alpha;
|
|
|
|
|
layout(set = 1, binding = 5) uniform sampler2D uLayer2Alpha;
|
|
|
|
|
layout(set = 1, binding = 6) uniform sampler2D uLayer3Alpha;
|
|
|
|
|
|
|
|
|
|
layout(set = 1, binding = 7) uniform TerrainParams {
|
|
|
|
|
int layerCount;
|
|
|
|
|
int hasLayer1;
|
|
|
|
|
int hasLayer2;
|
|
|
|
|
int hasLayer3;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
layout(set = 0, binding = 1) uniform sampler2DShadow uShadowMap;
|
|
|
|
|
|
|
|
|
|
layout(location = 0) in vec3 FragPos;
|
|
|
|
|
layout(location = 1) in vec3 Normal;
|
|
|
|
|
layout(location = 2) in vec2 TexCoord;
|
|
|
|
|
layout(location = 3) in vec2 LayerUV;
|
|
|
|
|
|
|
|
|
|
layout(location = 0) out vec4 outColor;
|
|
|
|
|
|
2026-02-23 04:14:27 -08:00
|
|
|
const float SHADOW_TEXEL = 1.0 / 4096.0;
|
|
|
|
|
|
|
|
|
|
float sampleShadowPCF(sampler2DShadow smap, vec3 coords) {
|
|
|
|
|
float shadow = 0.0;
|
|
|
|
|
for (int x = -1; x <= 1; ++x) {
|
|
|
|
|
for (int y = -1; y <= 1; ++y) {
|
|
|
|
|
shadow += texture(smap, vec3(coords.xy + vec2(x, y) * SHADOW_TEXEL, coords.z));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return shadow / 9.0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 19:41:21 -08:00
|
|
|
float sampleAlpha(sampler2D tex, vec2 uv) {
|
2026-04-06 18:18:14 -07:00
|
|
|
// Smooth 5-tap box near chunk edges to hide alpha-map seams;
|
|
|
|
|
// blends gradually to avoid a visible ring at the transition.
|
2026-02-21 19:41:21 -08:00
|
|
|
vec2 edge = min(uv, 1.0 - uv);
|
|
|
|
|
float border = min(edge.x, edge.y);
|
2026-04-06 18:18:14 -07:00
|
|
|
float blurWeight = 1.0 - smoothstep(0.5 / 64.0, 3.0 / 64.0, border);
|
|
|
|
|
float center = texture(tex, uv).r;
|
|
|
|
|
if (blurWeight < 0.001) return center;
|
2026-02-21 19:41:21 -08:00
|
|
|
vec2 texel = vec2(1.0 / 64.0);
|
2026-04-06 18:18:14 -07:00
|
|
|
float avg = center;
|
|
|
|
|
avg += texture(tex, uv + vec2(-texel.x, 0.0)).r;
|
|
|
|
|
avg += texture(tex, uv + vec2( texel.x, 0.0)).r;
|
|
|
|
|
avg += texture(tex, uv + vec2(0.0, -texel.y)).r;
|
|
|
|
|
avg += texture(tex, uv + vec2(0.0, texel.y)).r;
|
|
|
|
|
avg *= 0.2;
|
|
|
|
|
return mix(center, avg, blurWeight);
|
2026-02-21 19:41:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
vec4 baseColor = texture(uBaseTexture, TexCoord);
|
|
|
|
|
|
2026-02-22 02:59:24 -08:00
|
|
|
// WoW terrain: layers are blended sequentially, each on top of the previous result.
|
|
|
|
|
// Alpha=1 means the layer fully covers everything below; alpha=0 means invisible.
|
|
|
|
|
vec4 finalColor = baseColor;
|
|
|
|
|
if (hasLayer1 != 0) {
|
|
|
|
|
float a1 = sampleAlpha(uLayer1Alpha, LayerUV);
|
|
|
|
|
finalColor = mix(finalColor, texture(uLayer1Texture, TexCoord), a1);
|
|
|
|
|
}
|
|
|
|
|
if (hasLayer2 != 0) {
|
|
|
|
|
float a2 = sampleAlpha(uLayer2Alpha, LayerUV);
|
|
|
|
|
finalColor = mix(finalColor, texture(uLayer2Texture, TexCoord), a2);
|
|
|
|
|
}
|
|
|
|
|
if (hasLayer3 != 0) {
|
|
|
|
|
float a3 = sampleAlpha(uLayer3Alpha, LayerUV);
|
|
|
|
|
finalColor = mix(finalColor, texture(uLayer3Texture, TexCoord), a3);
|
|
|
|
|
}
|
2026-02-21 19:41:21 -08:00
|
|
|
|
|
|
|
|
vec3 norm = normalize(Normal);
|
2026-02-23 06:31:54 -08:00
|
|
|
|
2026-02-23 10:54:56 -08:00
|
|
|
// Derivative-based normal mapping: perturb vertex normal using texture detail.
|
2026-04-06 18:18:14 -07:00
|
|
|
// Fade out with distance and near chunk edges (dFdx/dFdy are invalid across
|
|
|
|
|
// chunk draw-call boundaries, producing visible seams if not faded).
|
2026-02-23 10:54:56 -08:00
|
|
|
float fragDist = length(viewPos.xyz - FragPos);
|
|
|
|
|
float bumpFade = 1.0 - smoothstep(50.0, 125.0, fragDist);
|
2026-04-06 18:18:14 -07:00
|
|
|
float edgeDist = min(min(LayerUV.x, 1.0 - LayerUV.x), min(LayerUV.y, 1.0 - LayerUV.y));
|
|
|
|
|
bumpFade *= smoothstep(0.0, 0.06, edgeDist);
|
2026-02-23 10:54:56 -08:00
|
|
|
if (bumpFade > 0.001) {
|
2026-02-23 06:31:54 -08:00
|
|
|
float lum = dot(finalColor.rgb, vec3(0.299, 0.587, 0.114));
|
|
|
|
|
float dLdx = dFdx(lum);
|
|
|
|
|
float dLdy = dFdy(lum);
|
|
|
|
|
vec3 dpdx = dFdx(FragPos);
|
|
|
|
|
vec3 dpdy = dFdy(FragPos);
|
2026-02-23 10:54:56 -08:00
|
|
|
float bumpStrength = 9.0 * bumpFade;
|
2026-02-23 06:31:54 -08:00
|
|
|
vec3 perturbation = (dLdx * cross(norm, dpdy) + dLdy * cross(dpdx, norm)) * bumpStrength;
|
2026-02-23 06:46:31 -08:00
|
|
|
vec3 candidate = norm - perturbation;
|
|
|
|
|
float len2 = dot(candidate, candidate);
|
|
|
|
|
norm = (len2 > 1e-8) ? candidate * inversesqrt(len2) : norm;
|
2026-02-23 06:31:54 -08:00
|
|
|
}
|
|
|
|
|
|
2026-02-21 19:41:21 -08:00
|
|
|
vec3 lightDir2 = normalize(-lightDir.xyz);
|
|
|
|
|
vec3 ambient = ambientColor.rgb * finalColor.rgb;
|
|
|
|
|
float diff = max(abs(dot(norm, lightDir2)), 0.2);
|
|
|
|
|
vec3 diffuse = diff * lightColor.rgb * finalColor.rgb;
|
|
|
|
|
|
|
|
|
|
float shadow = 1.0;
|
|
|
|
|
if (shadowParams.x > 0.5) {
|
2026-02-23 04:14:27 -08:00
|
|
|
vec3 ldir = normalize(-lightDir.xyz);
|
|
|
|
|
float normalOffset = SHADOW_TEXEL * 2.0 * (1.0 - abs(dot(norm, ldir)));
|
|
|
|
|
vec3 biasedPos = FragPos + norm * normalOffset;
|
|
|
|
|
vec4 lsPos = lightSpaceMatrix * vec4(biasedPos, 1.0);
|
2026-02-21 19:41:21 -08:00
|
|
|
vec3 proj = lsPos.xyz / lsPos.w;
|
|
|
|
|
proj.xy = proj.xy * 0.5 + 0.5;
|
feat(animation): 452 named constants, 30-phase character animation state machine
Add animation_ids.hpp/cpp with all 452 WoW animation ID constants (anim::STAND,
anim::RUN, anim::FIRE_BOW, ... anim::FLY_BACKWARDS, etc.), nameFromId() O(1)
lookup, and flyVariant() compact 218-element ground→FLY_* resolver.
Expand AnimationController into a full state machine with 20+ named states:
spell cast (directed→omni→cast fallback chain, instant one-shot release),
hit reactions (WOUND/CRIT/DODGE/BLOCK/SHIELD_BLOCK), stun, wounded idle,
stealth animation substitution, loot, fishing channel, sit/sleep/kneel
down→loop→up transitions, sheathe/unsheathe combat enter/exit, ranged weapons
(BOW/GUN/CROSSBOW/THROWN with reload states), game object OPEN/CLOSE/DESTROY,
vehicle enter/exit, mount flight directionals (FLY_LEFT/RIGHT/UP/DOWN/BACKWARDS),
emote state variants, off-hand/pierce/dual-wield alternation, NPC
birth/spawn/drown/rise, sprint aura override, totem idle, NPC greeting/farewell.
Add spell_defines.hpp with SpellEffect (~45 constants) and SpellMissInfo
(12 constants) namespaces; replace all magic numbers in spell_handler.cpp.
Add GAMEOBJECT_BYTES_1 to update field table (all 4 expansion JSONs) and wire
GameObjectStateCallback. Add DBC cross-validation on world entry.
Expand tools/_ANIM_NAMES from ~35 to 452 entries in m2_viewer.py and
asset_pipeline_gui.py. Add tests/test_animation_ids.cpp.
Bug fixes included:
- Stand state 1 was animating READY_2H(27) — fixed to SITTING(97)
- Spell casts ended freeze-frame — add one-shot release animation
- NPC 2H swing probe chain missing ATTACK_2H_LOOSE (polearm/staff)
- Chair sits (states 2/4/5/6) incorrectly played floor-sit transition
- STOP(3) used for all spell casts — replaced with model-aware chain
2026-04-04 23:02:53 +03:00
|
|
|
if (proj.x >= 0.0 && proj.x <= 1.0 && proj.y >= 0.0 && proj.y <= 1.0 && proj.z >= 0.0 && proj.z <= 1.0) {
|
|
|
|
|
float bias = max(0.0005 * (1.0 - abs(dot(norm, ldir))), 0.00005);
|
2026-02-23 04:14:27 -08:00
|
|
|
shadow = sampleShadowPCF(uShadowMap, vec3(proj.xy, proj.z - bias));
|
2026-02-21 19:41:21 -08:00
|
|
|
shadow = mix(1.0, shadow, shadowParams.y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vec3 result = ambient + shadow * diffuse;
|
|
|
|
|
|
2026-02-23 10:54:56 -08:00
|
|
|
float fogFactor = clamp((fogParams.y - fragDist) / (fogParams.y - fogParams.x), 0.0, 1.0);
|
2026-02-21 19:41:21 -08:00
|
|
|
result = mix(fogColor.rgb, result, fogFactor);
|
|
|
|
|
|
|
|
|
|
outColor = vec4(result, 1.0);
|
|
|
|
|
}
|