Wall damage shader testing (WIP)

This commit is contained in:
Regalis
2016-09-16 14:47:08 +03:00
parent 0265d075a5
commit b24359464b
8 changed files with 124 additions and 11 deletions
+7
View File
@@ -496,6 +496,7 @@
<Content Include="Content\Characters\Watcher\watcher.png"> <Content Include="Content\Characters\Watcher\watcher.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\damageshader.fx" />
<Content Include="Content\InfoTexts.xml"> <Content Include="Content\InfoTexts.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType> <SubType>Designer</SubType>
@@ -803,6 +804,9 @@
<Content Include="Content\Map\structures2.png"> <Content Include="Content\Map\structures2.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Map\walldamage.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Map\waypointIcons.png"> <Content Include="Content\Map\waypointIcons.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@@ -1105,6 +1109,9 @@
<None Include="Content\Content.mgcb"> <None Include="Content\Content.mgcb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Content\damageshader.xnb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\effects.mgfx"> <None Include="Content\effects.mgfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
+6
View File
@@ -43,3 +43,9 @@
/processorParam:DebugMode=Auto /processorParam:DebugMode=Auto
/build:blurshader.fx /build:blurshader.fx
#begin damageshader.fx
/importer:EffectImporter
/processor:EffectProcessor
/processorParam:DebugMode=Auto
/build:damageshader.fx
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

+34
View File
@@ -0,0 +1,34 @@
Texture xTexture;
sampler TextureSampler : register (s0) = sampler_state { Texture = <xTexture>; };
Texture xStencil;
sampler StencilSampler = sampler_state { Texture = <xStencil>; };
float cutoff;
float multiplier;
float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float4 c = tex2D(TextureSampler, texCoord);
float4 stencilColor = tex2D(StencilSampler, texCoord);
float a = stencilColor.a - cutoff;
clip(a);
a = min(a * multiplier, 1.0f);
c = lerp(c, stencilColor, 1.0f - a);
return c * a;
}
technique StencilShader
{
pass Pass1
{
PixelShader = compile ps_4_0_level_9_3 main();
}
}
Binary file not shown.
+33 -8
View File
@@ -370,6 +370,13 @@ namespace Barotrauma
public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true) public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true)
{
Draw(spriteBatch, editing, back, null);
}
private static float prevCutoff;
public void Draw(SpriteBatch spriteBatch, bool editing, bool back = true, Effect damageEffect = null)
{ {
if (prefab.sprite == null) return; if (prefab.sprite == null) return;
@@ -382,14 +389,32 @@ namespace Barotrauma
} }
Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition; Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition;
if(sections.Length == 1) if (sections.Length == 1)
prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), new Vector2(rect.Width, rect.Height), Vector2.Zero, color,Point.Zero); {
prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), new Vector2(rect.Width, rect.Height), Vector2.Zero, color, Point.Zero);
return;
}
foreach (WallSection s in sections) foreach (WallSection s in sections)
{ {
if (damageEffect != null)
{
float newCutoff = Math.Min((s.damage / prefab.MaxHealth)*0.5f - 0.2f, 0.1f);
if (Math.Abs(newCutoff - prevCutoff) > 0.01f)
{
damageEffect.Parameters["cutoff"].SetValue(newCutoff);
damageEffect.CurrentTechnique.Passes[0].Apply();
prevCutoff = newCutoff;
}
}
Point offset = new Point(Math.Abs(rect.Location.X - s.rect.Location.X), Math.Abs(rect.Location.Y - s.rect.Location.Y)); Point offset = new Point(Math.Abs(rect.Location.X - s.rect.Location.X), Math.Abs(rect.Location.Y - s.rect.Location.Y));
if (sections.Length != 1 && s.damage < prefab.MaxHealth) if (sections.Length != 1)
prefab.sprite.DrawTiled(spriteBatch, new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height), Vector2.Zero, color, offset); prefab.sprite.DrawTiled(spriteBatch, new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height), Vector2.Zero, color, offset);
if (s.isHighLighted) if (s.isHighLighted)
{ {
@@ -400,11 +425,11 @@ namespace Barotrauma
s.isHighLighted = false; s.isHighLighted = false;
if (s.damage < 0.01f) continue; //if (s.damage < 0.01f) continue;
GUI.DrawRectangle(spriteBatch, //GUI.DrawRectangle(spriteBatch,
new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height), // new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height),
Color.Black * (s.damage / prefab.MaxHealth), true); // Color.Black * (s.damage / prefab.MaxHealth), true);
} }
/* /*
if(_convexHulls == null) return; if(_convexHulls == null) return;
+15 -1
View File
@@ -149,7 +149,7 @@ namespace Barotrauma
{ {
get get
{ {
return subBody.Position; return subBody ==null ? Vector2.Zero : subBody.Position;
} }
} }
@@ -287,11 +287,25 @@ namespace Barotrauma
{ {
for (int i = 0; i < MapEntity.mapEntityList.Count; i++) for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
{ {
if (MapEntity.mapEntityList[i] is Structure) continue;
if (MapEntity.mapEntityList[i].Sprite == null || MapEntity.mapEntityList[i].Sprite.Depth < 0.5f) if (MapEntity.mapEntityList[i].Sprite == null || MapEntity.mapEntityList[i].Sprite.Depth < 0.5f)
MapEntity.mapEntityList[i].Draw(spriteBatch, editing, false); MapEntity.mapEntityList[i].Draw(spriteBatch, editing, false);
} }
} }
public static void DrawDamageable(SpriteBatch spriteBatch, Effect damageEffect, bool editing = false)
{
for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
{
var structure = MapEntity.mapEntityList[i] as Structure;
if (structure == null || structure.Sprite.Depth > 0.5f) continue;
structure.Draw(spriteBatch, editing, false, damageEffect);
}
damageEffect.Parameters["cutoff"].SetValue(0.5f);
}
public static void DrawBack(SpriteBatch spriteBatch, bool editing = false) public static void DrawBack(SpriteBatch spriteBatch, bool editing = false)
{ {
for (int i = 0; i < MapEntity.mapEntityList.Count; i++) for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
+27
View File
@@ -18,6 +18,10 @@ namespace Barotrauma
private BlurEffect lightBlur; private BlurEffect lightBlur;
private Effect damageEffect;
private Texture2D damageStencil;
public BackgroundCreatureManager BackgroundCreatureManager; public BackgroundCreatureManager BackgroundCreatureManager;
public Camera Cam public Camera Cam
@@ -46,6 +50,13 @@ namespace Barotrauma
var blurEffect = content.Load<Effect>("blurshader"); var blurEffect = content.Load<Effect>("blurshader");
#endif #endif
damageStencil = TextureLoader.FromFile("Content/Map/walldamage.png");
damageEffect = content.Load<Effect>("damageshader");
// damageEffect.Parameters["cutoff"].SetValue(0.5f);
damageEffect.Parameters["xStencil"].SetValue(damageStencil);
lightBlur = new BlurEffect(blurEffect, 0.001f, 0.001f); lightBlur = new BlurEffect(blurEffect, 0.001f, 0.001f);
@@ -162,6 +173,9 @@ namespace Barotrauma
{ {
cam.UpdateTransform(true); cam.UpdateTransform(true);
//damageStencil = TextureLoader.FromFile("Content/Map/background.png");
DrawMap(graphics, spriteBatch); DrawMap(graphics, spriteBatch);
spriteBatch.Begin(); spriteBatch.Begin();
@@ -325,6 +339,19 @@ namespace Barotrauma
spriteBatch.End(); spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Immediate,
BlendState.AlphaBlend, SamplerState.LinearWrap,
null, null,
damageEffect,
cam.Transform);
damageEffect.Parameters["cutoff"].SetValue(-0.2f);
damageEffect.Parameters["multiplier"].SetValue(5.0f);
Submarine.DrawDamageable(spriteBatch, damageEffect);
spriteBatch.End();
GameMain.LightManager.DrawLightMap(spriteBatch, cam, lightBlur.Effect); GameMain.LightManager.DrawLightMap(spriteBatch, cam, lightBlur.Effect);
spriteBatch.Begin(SpriteSortMode.BackToFront, spriteBatch.Begin(SpriteSortMode.BackToFront,