Fixed damageshader ignoring sprite colors. Closes #212

This commit is contained in:
Joonas Rikkonen
2017-12-30 04:51:39 +02:00
parent 6777a039d5
commit 65d6071378
5 changed files with 8 additions and 3 deletions

View File

@@ -148,14 +148,17 @@ namespace Barotrauma
{
float newCutoff = Math.Min((sections[i].damage / prefab.Health), 0.65f);
if (Math.Abs(newCutoff - Submarine.DamageEffectCutoff) > 0.01f)
if (Math.Abs(newCutoff - Submarine.DamageEffectCutoff) > 0.01f || color != Submarine.DamageEffectColor)
{
damageEffect.Parameters["aCutoff"].SetValue(newCutoff);
damageEffect.Parameters["cCutoff"].SetValue(newCutoff * 1.2f);
damageEffect.Parameters["color"].SetValue(color.ToVector4());
damageEffect.CurrentTechnique.Passes[0].Apply();
Submarine.DamageEffectCutoff = newCutoff;
Submarine.DamageEffectColor = color;
}
}

View File

@@ -67,6 +67,7 @@ namespace Barotrauma
}
public static float DamageEffectCutoff;
public static Color DamageEffectColor;
public static void DrawDamageable(SpriteBatch spriteBatch, Effect damageEffect, bool editing = false)
{

View File

@@ -5,6 +5,7 @@ sampler TextureSampler : register (s0) = sampler_state { Texture = <xTexture>; }
Texture xStencil;
sampler StencilSampler = sampler_state { Texture = <xStencil>; };
float4 color;
float aCutoff;
float aMultiplier;
@@ -14,9 +15,9 @@ float cMultiplier;
float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float4 c = tex2D(TextureSampler, texCoord);
float4 c = xTexture.Sample(TextureSampler, texCoord) * color;
float4 stencilColor = tex2D(StencilSampler, texCoord);
float4 stencilColor = xStencil.Sample(StencilSampler, texCoord);
float aDiff = stencilColor.a - aCutoff;