ADD water exit effect, add damage amount based hurt effects. fix water fog lightmap

This commit is contained in:
Xonk
2024-05-18 22:58:30 -04:00
parent d431109ec5
commit 044d690a52
12 changed files with 149 additions and 84 deletions

View File

@ -3,11 +3,15 @@
uniform float maxPlayerHealth;
uniform float oneHeart;
uniform float threeHeart;
uniform float CriticalDamageTaken;
uniform float MinorDamageTaken;
#else
uniform bool isDead;
#endif
uniform float hurt;
uniform float exitWater;
uniform int isEyeInWater;
// uniform float currentPlayerHunger;
// uniform float maxPlayerHunger;
@ -28,43 +32,77 @@ uniform float hurt;
// uniform bool isSpectator;
void applyGameplayEffects_FRAGMENT(inout vec3 color, in vec2 texcoord, float noise){
void applyGameplayEffects(inout vec3 color, in vec2 texcoord, float noise){
// detect when health is zero
#ifdef IS_IRIS
bool isDead = currentPlayerHealth * maxPlayerHealth <= 0.0 && currentPlayerHealth > -1;
#else
float oneHeart = 0.0;
float threeHeart = 0.0;
#endif
float distortmask = 0.0;
float vignette = sqrt(clamp(dot(texcoord*2.0 - 1.0, texcoord*2.0 - 1.0) * 0.5, 0.0, 1.0));
//////////////////////// DAMAGE DISTORTION /////////////////////
#if defined LOW_HEALTH_EFFECT || defined DAMAGE_TAKEN_EFFECT
float heartBeat = (pow(sin(frameTimeCounter * 15)*0.5+0.5,2.0)*0.2 + 0.1) ;
// apply low health distortion effects
float damageDistortion = vignette * noise * heartBeat * threeHeart;
// apply critical hit distortion effect
damageDistortion = mix(damageDistortion, vignette * (0.5 + noise), CriticalDamageTaken) * MOTION_AMOUNT;
// apply death distortion effect
distortmask = isDead ? noise*0.7 : damageDistortion;
#endif
//////////////////////// WATER DISTORTION /////////////////////
#if defined WATER_ON_CAMERA_EFFECT
if(exitWater > 0.0){
vec3 scale = vec3(1.0,1.0,0.0);
scale.xy = (isEyeInWater == 1 ? vec2(0.3) : vec2(0.5, 0.25 + (exitWater*exitWater)*0.25 ) ) * vec2(aspectRatio,1.0);
scale.z = isEyeInWater == 1 ? 0.0 : exitWater;
float waterDrops = texture2D(noisetex, (texcoord - vec2(0.0, scale.z)) * scale.xy).r;
if(isEyeInWater == 1) waterDrops = waterDrops*waterDrops * 0.3;
if(isEyeInWater == 0) waterDrops = sqrt(min(max(waterDrops - (1.0-sqrt(exitWater))*0.7,0.0) * (1.0 + exitWater),1.0)) * 0.3;
// apply distortion effects for exiting water and under water
distortmask = max(distortmask, waterDrops);
}
#endif
//////////////////////// APPLY DISTORTION /////////////////////
// all of the distortion will be based around zooming the UV in the center
vec2 zoomUV = 0.5 + (texcoord - 0.5) * (1.0 - distortmask);
vec3 distortedColor = texture2D(colortex7, zoomUV).rgb;
#ifdef WATER_ON_CAMERA_EFFECT
// apply the distorted water color to the scene, but revert back to before when it ends
if(exitWater > 0.01) color = distortedColor;
#endif
//////////////////////// APPLY COLOR EFFECTS /////////////////////
#if defined LOW_HEALTH_EFFECT || defined DAMAGE_TAKEN_EFFECT
vec3 distortedColorLuma = vec3(1.0, 0.0, 0.0) * dot(distortedColor, vec3(0.21, 0.72, 0.07));
#if defined LOW_HEALTH_EFFECT || defined DAMAGE_TAKEN_EFFECT
// detect when health is zero
#ifdef IS_IRIS
bool isDead = currentPlayerHealth * maxPlayerHealth <= 0.0 && currentPlayerHealth > -1;
#else
float oneHeart = 0.0;
float threeHeart = 0.0;
#endif
float vignette = sqrt(clamp(dot(texcoord*2.0 - 1.0, texcoord*2.0 - 1.0) * 0.5, 0.0, 1.0));
// heart beat effect to scale stuff with, make it more intense. theres a multiplier "MOTION_AMOUNT" for accessiblity
float beatingRate = isDead ? 0.0 : (oneHeart > 0.0 ? 15.0 : 7.5);
float heartBeat = (pow(sin(frameTimeCounter * beatingRate)*0.5+0.5,2.0)*0.2 + 0.1);
// scale UV to be more and more lower frequency towards the edges of the screen, to create a tunnel vision effect,
vec2 zoomUV = 0.5 + (texcoord - 0.5) * (1.0 - vignette * (isDead ? noise*0.7 : noise * heartBeat * MOTION_AMOUNT));
vec3 distortedScreen = vec3(1.0, 0.0, 0.0) * dot(texture2D(colortex7, zoomUV).rgb, vec3(0.21, 0.72, 0.07));
#ifdef LOW_HEALTH_EFFECT
// at 1 heart or 3 hearts, create 2 levels of a strain / tunnel vision effect.
float colorLuma = dot(color, vec3(0.21, 0.72, 0.07));
// black and white version of the scene color.
vec3 colorLuma = vec3(1.0, 1.0, 1.0) * dot(color,vec3(0.21, 0.72, 0.07));
vec3 LumaRedEdges = mix(vec3(colorLuma), vec3(1.0, 0.3, 0.3) * distortedColorLuma.r, vignette);
// I LOVE LINEAR INTERPOLATION
color = mix(color, mix(colorLuma, distortedScreen, vignette), mix(vignette * threeHeart, oneHeart, oneHeart));
if(isDead) color = distortedScreen*0.3;
// apply color effects for when you are at low health
color = mix(color, LumaRedEdges, mix(vignette * threeHeart, oneHeart, oneHeart));
#endif
#ifdef DAMAGE_TAKEN_EFFECT
// when damage is taken, flash the above effect. because it uses the stuff above, it seamlessly blends to them.
color = mix(color, distortedScreen, (vignette*vignette) * sqrt(hurt));
color = mix(color, distortedColorLuma, vignette * sqrt(MinorDamageTaken));
color = mix(color, distortedColorLuma, sqrt(CriticalDamageTaken));
#endif
if(isDead) color = distortedColorLuma * 0.3;
#endif
}