Merged linux changes, water effect using a BasicEffect and a simpler pixel shader, multi-colored wires

This commit is contained in:
Regalis
2015-09-08 21:55:27 +03:00
parent 7eae6fb026
commit ea15397725
18 changed files with 221 additions and 197 deletions
@@ -19,6 +19,54 @@
<Wire/> <Wire/>
</Item> </Item>
<Item
name="Red Wire"
Tags="smallitem"
spritecolor="1.0,0.0,0.0,1.0"
pickdistance="150"
linkable="true"
canbepicked="true"
price="10">
<Sprite texture ="wire.png" depth="0.55"/>
<Body radius="15"/>
<Holdable slots="Any,RightHand,LeftHand" handle1="0,0"/>
<Wire/>
</Item>
<Item
name="Blue Wire"
Tags="smallitem"
spritecolor="0.0,0.6,1.0,1.0"
pickdistance="150"
linkable="true"
canbepicked="true"
price="10">
<Sprite texture ="wire.png" depth="0.55"/>
<Body radius="15"/>
<Holdable slots="Any,RightHand,LeftHand" handle1="0,0"/>
<Wire/>
</Item>
<Item
name="Orange Wire"
Tags="smallitem"
spritecolor="1.0,0.5,0.0,1.0"
pickdistance="150"
linkable="true"
canbepicked="true"
price="10">
<Sprite texture ="wire.png" depth="0.55"/>
<Body radius="15"/>
<Holdable slots="Any,RightHand,LeftHand" handle1="0,0"/>
<Wire/>
</Item>
<Item <Item
name="And Component" name="And Component"
Tags="smallitem" Tags="smallitem"
+1 -1
View File
@@ -8,7 +8,7 @@
<Sprite texture ="railgunbase.png"/> <Sprite texture ="railgunbase.png"/>
<Turret barrelsprite="railgunbarrel.png" canbeselected = "true" linkable="true" origin="0.5, 0.85" barrelpos="117, 57" <Turret barrelsprite="railgunbarrel.png" canbeselected = "true" linkable="true" origin="0.5, 0.85" barrelpos="128, 128"
rotationlimits="180,360" rotationlimits="180,360"
powerconsumption="500.0"> powerconsumption="500.0">
<StatusEffect type="OnUse" target="This" sound="Content/Items/Weapons/railgun.ogg"> <StatusEffect type="OnUse" target="This" sound="Content/Items/Weapons/railgun.ogg">
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.
@@ -17,12 +17,12 @@ namespace Subsurface
public BackgroundSpriteManager(string configPath) public BackgroundSpriteManager(string configPath)
{ {
XDocument doc = ToolBox.TryLoadXml(configPath);
if (doc == null) return;
activeSprites = new List<BackgroundSprite>(); activeSprites = new List<BackgroundSprite>();
prefabs = new List<BackgroundSpritePrefab>(); prefabs = new List<BackgroundSpritePrefab>();
XDocument doc = ToolBox.TryLoadXml(configPath);
if (doc == null) return;
foreach (XElement element in doc.Root.Elements()) foreach (XElement element in doc.Root.Elements())
{ {
prefabs.Add(new BackgroundSpritePrefab(element)); prefabs.Add(new BackgroundSpritePrefab(element));
@@ -31,10 +31,13 @@ namespace Subsurface
public void SpawnSprites(int count) public void SpawnSprites(int count)
{ {
count = Math.Min(count, MaxSprites);
activeSprites.Clear(); activeSprites.Clear();
if (prefabs.Count == 0) return;
count = Math.Min(count, MaxSprites);
for (int i = 0; i < count; i++ ) for (int i = 0; i < count; i++ )
{ {
Vector2 pos = Vector2.Zero; Vector2 pos = Vector2.Zero;
@@ -167,6 +167,12 @@ namespace EventInput
initialized = true; initialized = true;
} }
public static void OnCharEntered(char character)
{
if (CharEntered != null)
CharEntered(null, new CharacterEventArgs(character, 0));
}
static IntPtr HookProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) static IntPtr HookProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
{ {
IntPtr returnCode = CallWindowProc(prevWndProc, hWnd, msg, wParam, lParam); IntPtr returnCode = CallWindowProc(prevWndProc, hWnd, msg, wParam, lParam);
+1 -1
View File
@@ -72,7 +72,7 @@ namespace Subsurface
new Vector3(Game1.GraphicsWidth / 2.0f, new Vector3(Game1.GraphicsWidth / 2.0f,
Game1.GraphicsHeight / 2.0f, 0)); Game1.GraphicsHeight / 2.0f, 0));
Hull.renderer.RenderBack(graphics, renderTarget, transform); Hull.renderer.RenderBack(spriteBatch, renderTarget, transform);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
+43 -28
View File
@@ -303,7 +303,7 @@ namespace Subsurface
public void Render(GraphicsDevice graphicsDevice, Camera cam) public void Render(GraphicsDevice graphicsDevice, Camera cam)
{ {
if (renderer.positionInBuffer > renderer.vertices.Length - 6) return; if (renderer.PositionInBuffer > renderer.vertices.Length - 6) return;
//calculate where the surface should be based on the water volume //calculate where the surface should be based on the water volume
float top = rect.Y; float top = rect.Y;
@@ -313,30 +313,37 @@ namespace Subsurface
//interpolate the position of the rendered surface towards the "target surface" //interpolate the position of the rendered surface towards the "target surface"
surface = surface + (surfaceY - surface) / 10.0f; surface = surface + (surfaceY - surface) / 10.0f;
Matrix transform = Matrix transform = cam.Transform * Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f;
cam.Transform
* Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f;
if (bottom > cam.WorldView.Y || top < cam.WorldView.Y - cam.WorldView.Height) return; if (bottom > cam.WorldView.Y || top < cam.WorldView.Y - cam.WorldView.Height) return;
if (!update) if (!update)
{ {
// create the four corners of our triangle. // create the four corners of our triangle.
Vector3 p1 = new Vector3(rect.X, top, 0.0f);
Vector3 p2 = new Vector3(rect.X + rect.Width, top, 0.0f);
Vector3 p3 = new Vector3(p2.X, bottom, 0.0f); Vector3[] corners = new Vector3[4];
Vector3 p4 = new Vector3(p1.X, bottom, 0.0f);
renderer.vertices[renderer.positionInBuffer] = new WaterVertex(p1, new Vector2(p1.X, -p1.Y), transform); corners[0] = new Vector3(rect.X, top, 0.0f);
renderer.vertices[renderer.positionInBuffer + 1] = new WaterVertex(p2, new Vector2(p2.X, -p2.Y), transform); corners[1] = new Vector3(rect.X + rect.Width, top, 0.0f);
renderer.vertices[renderer.positionInBuffer + 2] = new WaterVertex(p3, new Vector2(p3.X, -p3.Y), transform);
renderer.vertices[renderer.positionInBuffer + 3] = new WaterVertex(p1, new Vector2(p1.X, -p1.Y), transform); corners[2] = new Vector3(corners[1].X, bottom, 0.0f);
renderer.vertices[renderer.positionInBuffer + 4] = new WaterVertex(p3, new Vector2(p3.X, -p3.Y), transform); corners[3] = new Vector3(corners[0].X, bottom, 0.0f);
renderer.vertices[renderer.positionInBuffer + 5] = new WaterVertex(p4, new Vector2(p4.X, -p4.Y), transform);
renderer.positionInBuffer += 6; Vector2[] uvCoords = new Vector2[4];
for (int i = 0; i < 4; i++ )
{
uvCoords[i] = Vector2.Transform(new Vector2(corners[i].X, -corners[i].Y), transform);
}
renderer.vertices[renderer.PositionInBuffer] = new VertexPositionTexture(corners[0], uvCoords[0]);
renderer.vertices[renderer.PositionInBuffer + 1] = new VertexPositionTexture(corners[1], uvCoords[1]);
renderer.vertices[renderer.PositionInBuffer + 2] = new VertexPositionTexture(corners[2], uvCoords[2]);
renderer.vertices[renderer.PositionInBuffer + 3] = new VertexPositionTexture(corners[0], uvCoords[0]);
renderer.vertices[renderer.PositionInBuffer + 4] = new VertexPositionTexture(corners[2], uvCoords[2]);
renderer.vertices[renderer.PositionInBuffer + 5] = new VertexPositionTexture(corners[3], uvCoords[3]);
renderer.PositionInBuffer += 6;
return; return;
} }
@@ -353,31 +360,39 @@ namespace Subsurface
for (int i = start; i < end; i++) for (int i = start; i < end; i++)
{ {
if (renderer.positionInBuffer > renderer.vertices.Length - 6) return; if (renderer.PositionInBuffer > renderer.vertices.Length - 6) return;
Vector3 p1 = new Vector3(x, top, 0.0f); Vector3[] corners = new Vector3[4];
Vector3 p4 = new Vector3(p1.X, surface + waveY[i], 0.0f);
corners[0] = new Vector3(x, top, 0.0f);
corners[3] = new Vector3(corners[0].X, surface + waveY[i], 0.0f);
//skip adjacent "water rects" if the surface of the water is roughly at the same position //skip adjacent "water rects" if the surface of the water is roughly at the same position
int width = WaveWidth; int width = WaveWidth;
while (i<end-1 && Math.Abs(waveY[i + 1] - waveY[i]) < 1.0f) while (i < end - 1 && Math.Abs(waveY[i + 1] - waveY[i]) < 1.0f)
{ {
width += WaveWidth; width += WaveWidth;
i++; i++;
} }
Vector3 p2 = new Vector3(x + width, top, 0.0f); corners[1] = new Vector3(x + width, top, 0.0f);
Vector3 p3 = new Vector3(p2.X, surface + waveY[i+1], 0.0f); corners[2] = new Vector3(corners[1].X, surface + waveY[i+1], 0.0f);
renderer.vertices[renderer.positionInBuffer] = new WaterVertex(p1, new Vector2(p1.X, -p1.Y), transform); Vector2[] uvCoords = new Vector2[4];
renderer.vertices[renderer.positionInBuffer + 1] = new WaterVertex(p2, new Vector2(p2.X, -p2.Y), transform); for (int n = 0; n < 4; n++)
renderer.vertices[renderer.positionInBuffer + 2] = new WaterVertex(p3, new Vector2(p3.X, -p3.Y), transform); {
uvCoords[n] = Vector2.Transform(new Vector2(corners[n].X, -corners[n].Y), transform);
}
renderer.vertices[renderer.positionInBuffer + 3] = new WaterVertex(p1, new Vector2(p1.X, -p1.Y), transform); renderer.vertices[renderer.PositionInBuffer] = new VertexPositionTexture(corners[0], uvCoords[0]);
renderer.vertices[renderer.positionInBuffer + 4] = new WaterVertex(p3, new Vector2(p3.X, -p3.Y), transform); renderer.vertices[renderer.PositionInBuffer + 1] = new VertexPositionTexture(corners[1], uvCoords[1]);
renderer.vertices[renderer.positionInBuffer + 5] = new WaterVertex(p4, new Vector2(p4.X, -p4.Y), transform); renderer.vertices[renderer.PositionInBuffer + 2] = new VertexPositionTexture(corners[2], uvCoords[2]);
renderer.positionInBuffer += 6; renderer.vertices[renderer.PositionInBuffer + 3] = new VertexPositionTexture(corners[0], uvCoords[0]);
renderer.vertices[renderer.PositionInBuffer + 4] = new VertexPositionTexture(corners[2], uvCoords[2]);
renderer.vertices[renderer.PositionInBuffer + 5] = new VertexPositionTexture(corners[3], uvCoords[3]);
renderer.PositionInBuffer += 6;
x += width; x += width;
} }
+44 -113
View File
@@ -5,122 +5,61 @@ using Microsoft.Xna.Framework.Graphics;
namespace Subsurface namespace Subsurface
{ {
struct WaterVertex
{
public Vector3 position;
private Vector2 texCoord;
public WaterVertex(Vector3 position, Vector2 texCoord, Matrix transform)
{
this.position = position;
this.texCoord = Vector2.Transform(texCoord, transform);
}
public WaterVertex(Vector3 position, Vector2 texCoord)
{
this.position = position;
this.texCoord = texCoord;
}
public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration
(
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement(sizeof(float) * 3, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
);
public void TransformTexCoord(Matrix transform)
{
texCoord = Vector2.Transform(texCoord, transform);
}
}
class WaterRenderer : IDisposable class WaterRenderer : IDisposable
{ {
const int DefaultBufferSize = 1500; const int DefaultBufferSize = 1500;
Effect effect; private Vector2 wavePos;
public Vector2 wavePos; public VertexPositionTexture[] vertices = new VertexPositionTexture[DefaultBufferSize];
public WaterVertex[] vertices = new WaterVertex[DefaultBufferSize]; private Effect waterEffect;
private BasicEffect basicEffect;
private VertexBuffer vertexBuffer; public int PositionInBuffer = 0;
public int positionInBuffer = 0; private Texture2D waterTexture;
public WaterRenderer(GraphicsDevice graphicsDevice) public WaterRenderer(GraphicsDevice graphicsDevice)
{ {
//vertexBuffer = new VertexBuffer(graphicsDevice, WaterVertex.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
//vertexBuffer.SetData(vertices);
//effect = Game1.game.Content.Load<Effect>("effects");
#if WINDOWS #if WINDOWS
byte[] bytecode = File.ReadAllBytes("Content/effects.mgfx"); byte[] bytecode = File.ReadAllBytes("Content/watershader.mgfx");
#endif #endif
#if LINUX #if LINUX
byte[] bytecode = File.ReadAllBytes("Content/effects_linux.mgfx"); byte[] bytecode = File.ReadAllBytes("Content/effects_linux.mgfx");
#endif #endif
effect = new Effect(graphicsDevice, bytecode); waterEffect = new Effect(graphicsDevice, bytecode);
//Texture2D waterBumpMap = Game1.textureLoader.FromFile("Content/waterbump.jpg"); waterTexture = Game1.TextureLoader.FromFile("Content/waterbump.jpg");
//effect.Parameters["xBump"].SetValue(waterBumpMap); waterEffect.Parameters["xWaveWidth"].SetValue(0.1f);
//effect.Parameters["xWaveLength"].SetValue(0.5f); waterEffect.Parameters["xWaveHeight"].SetValue(0.1f);
//effect.Parameters["xWaveHeight"].SetValue(0.03f); waterEffect.Parameters["xBlurDistance"].SetValue(0.0007f);
effect.Parameters["xProjection"].SetValue(Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1));
effect.Parameters["xColor"].SetValue(new Vector4(0.75f, 0.8f, 0.9f, 1.0f));
effect.Parameters["xBlurDistance"].SetValue(0.0005f);
effect.Parameters["xWaterBumpMap"].SetValue(Game1.TextureLoader.FromFile("Content/waterbump.jpg")); if (basicEffect==null)
effect.Parameters["xWaveWidth"].SetValue(0.1f); {
effect.Parameters["xWaveHeight"].SetValue(0.1f); basicEffect = new BasicEffect(Game1.CurrGraphicsDevice);
basicEffect.VertexColorEnabled = false;
vertexBuffer = new VertexBuffer(graphicsDevice, WaterVertex.VertexDeclaration, DefaultBufferSize, BufferUsage.WriteOnly); basicEffect.TextureEnabled = true;
}
} }
public void RenderBack(GraphicsDevice graphicsDevice, RenderTarget2D texture, Matrix transform) public void RenderBack (SpriteBatch spriteBatch, RenderTarget2D texture, Matrix transform)
{ {
WaterVertex[] verts = new WaterVertex[6]; spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearWrap);
// create the four corners of our triangle. waterEffect.CurrentTechnique = waterEffect.Techniques["WaterShader"];
Vector3 p1 = new Vector3(-graphicsDevice.Viewport.Width / 2.0f, graphicsDevice.Viewport.Height / 2.0f, 0.0f); waterEffect.Parameters["xTexture"].SetValue(texture);
Vector3 p2 = new Vector3(-p1.X, p1.Y, 0.0f); waterEffect.Parameters["xWavePos"].SetValue(wavePos);
waterEffect.CurrentTechnique.Passes[0].Apply();
Vector3 p3 = new Vector3(p2.X, -p1.Y, 0.0f);
Vector3 p4 = new Vector3(p1.X, -p1.Y, 0.0f);
verts[0] = new WaterVertex(p1, new Vector2(0, 0));
verts[1] = new WaterVertex(p2, new Vector2(1, 0));
verts[2] = new WaterVertex(p3, new Vector2(1, 1));
verts[3] = new WaterVertex(p1, new Vector2(0, 0));
verts[4] = new WaterVertex(p3, new Vector2(1, 1));
verts[5] = new WaterVertex(p4, new Vector2(0, 1));
vertexBuffer.SetData(verts);
wavePos.X += 0.0001f; wavePos.X += 0.0001f;
wavePos.Y += 0.0001f; wavePos.Y += 0.0001f;
effect.Parameters["xWavePos"].SetValue(wavePos); spriteBatch.Draw(waterTexture, new Rectangle(0,0,Game1.GraphicsWidth, Game1.GraphicsHeight), Color.White);
effect.CurrentTechnique = effect.Techniques["WaterShader"]; spriteBatch.End();
effect.Parameters["xTexture"].SetValue(texture);
effect.Parameters["xView"].SetValue(Matrix.Identity);
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
#if WINDOWS
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, verts, 0, verts.Length / 3, WaterVertex.VertexDeclaration);
#endif
#if LINUX
//graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, verts, 0, verts.Length / 3, WaterVertex.VertexDeclaration, );
#endif
}
} }
public void Render(GraphicsDevice graphicsDevice, Camera cam, RenderTarget2D texture, Matrix transform) public void Render(GraphicsDevice graphicsDevice, Camera cam, RenderTarget2D texture, Matrix transform)
@@ -128,22 +67,16 @@ namespace Subsurface
if (vertices == null) return; if (vertices == null) return;
if (vertices.Length < 0) return; if (vertices.Length < 0) return;
vertexBuffer.SetData(vertices); basicEffect.Texture = texture;
effect.Parameters["xBumpPos"].SetValue(cam.Position / Game1.GraphicsWidth / cam.Zoom); basicEffect.View = Matrix.Identity;
basicEffect.World = cam.ShaderTransform
* Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f;
effect.CurrentTechnique = effect.Techniques["EmptyShader"]; basicEffect.CurrentTechnique.Passes[0].Apply();
effect.Parameters["xTexture"].SetValue(texture);
effect.Parameters["xView"].SetValue(transform);
foreach (EffectPass pass in effect.CurrentTechnique.Passes) graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
{ graphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3);
pass.Apply();
#if WINDOWS
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3, WaterVertex.VertexDeclaration);
#endif
}
} }
public void Dispose() public void Dispose()
@@ -154,22 +87,20 @@ namespace Subsurface
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
if (disposing) if (!disposing) return;
{
if (vertexBuffer != null)
{
vertexBuffer.Dispose();
vertexBuffer = null;
}
if (effect != null) if (waterEffect != null)
{ {
effect.Dispose(); waterEffect.Dispose();
effect = null; waterEffect = null;
} }
if (basicEffect != null)
{
basicEffect.Dispose();
basicEffect = null;
} }
} }
} }
} }
@@ -571,7 +571,6 @@ namespace Subsurface.Networking
client.characterInfo.Job = new Job(client.assignedJob); client.characterInfo.Job = new Job(client.assignedJob);
} }
//todo: fix
if (characterInfo != null) if (characterInfo != null)
{ {
characterInfo.Job = new Job(Game1.NetLobbyScreen.JobPreferences[0]); characterInfo.Job = new Job(Game1.NetLobbyScreen.JobPreferences[0]);
+17 -4
View File
@@ -56,10 +56,6 @@ namespace Subsurface
stateQueue = false; stateQueue = false;
return value; return value;
} }
//set
//{
// stateQueue = value;
//}
} }
public void Reset() public void Reset()
@@ -168,6 +164,23 @@ namespace Subsurface
if (timeSinceClick < doubleClickDelay) doubleClicked = true; if (timeSinceClick < doubleClickDelay) doubleClicked = true;
timeSinceClick = 0.0; timeSinceClick = 0.0;
} }
#if LINUX
foreach (Keys key in keyboardState.GetPressedKeys())
{
if (!oldKeyboardState.IsKeyUp(key)) continue;
char character = (char)key;
if (keyboardState.IsKeyUp(Keys.LeftShift) && keyboardState.IsKeyUp(Keys.RightShift))
{
character = char.ToLower(character);
}
EventInput.EventInput.OnCharEntered(character);
}
#endif
} }
} }
} }
+4 -2
View File
@@ -5,8 +5,10 @@ using System.IO;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
#if WINDOWS
using System.Management; using System.Management;
using System.Windows.Forms; using System.Windows.Forms;
#endif
#endregion #endregion
@@ -70,7 +72,6 @@ namespace Subsurface
sb.AppendLine("\n"); sb.AppendLine("\n");
sb.AppendLine("System info:"); sb.AppendLine("System info:");
sb.AppendLine(" Operating system: " + System.Environment.OSVersion + (System.Environment.Is64BitOperatingSystem ? " 64 bit" : " x86")); sb.AppendLine(" Operating system: " + System.Environment.OSVersion + (System.Environment.Is64BitOperatingSystem ? " 64 bit" : " x86"));
sb.AppendLine(" Graphics device handle: " + game.GraphicsDevice.Handle.ToString());
sb.AppendLine("\n"); sb.AppendLine("\n");
sb.AppendLine("Exception: "+exception.Message); sb.AppendLine("Exception: "+exception.Message);
sb.AppendLine("Target site: " +exception.TargetSite.ToString()); sb.AppendLine("Target site: " +exception.TargetSite.ToString());
@@ -86,10 +87,11 @@ namespace Subsurface
sw.WriteLine(sb.ToString()); sw.WriteLine(sb.ToString());
#if WINDOWS
MessageBox.Show( "A crash report (''crashreport.txt'') was saved in the root folder of the game."+ MessageBox.Show( "A crash report (''crashreport.txt'') was saved in the root folder of the game."+
" If you'd like to help fix this bug, please make a bug report on the Undertow Games forum with the report attached.", " If you'd like to help fix this bug, please make a bug report on the Undertow Games forum with the report attached.",
"Oops! Subsurface just crashed.", MessageBoxButtons.OK, MessageBoxIcon.Error); "Oops! Subsurface just crashed.", MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
sw.Close(); sw.Close();
} }
+3 -3
View File
@@ -208,7 +208,7 @@ namespace Subsurface
spriteBatch.Begin(SpriteSortMode.Immediate, spriteBatch.Begin(SpriteSortMode.Immediate,
BlendState.AlphaBlend); BlendState.AlphaBlend);
spriteBatch.Draw(renderTarget, new Rectangle(0, 0, Game1.GraphicsWidth, Game1.GraphicsHeight), Color.White); spriteBatch.Draw(renderTarget, new Rectangle(0, 0, Game1.GraphicsWidth, Game1.GraphicsHeight), new Color(0.75f, 0.8f, 0.9f, 1.0f));
spriteBatch.End(); spriteBatch.End();
BlendState blend = new BlendState(); BlendState blend = new BlendState();
@@ -246,10 +246,10 @@ namespace Subsurface
//2. pass the renderTarget to the water shader to do the water effect //2. pass the renderTarget to the water shader to do the water effect
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
Hull.renderer.RenderBack(graphics, renderTargetWater, Cam.ShaderTransform); Hull.renderer.RenderBack(spriteBatch, renderTargetWater, Cam.ShaderTransform);
Array.Clear(Hull.renderer.vertices, 0, Hull.renderer.vertices.Length); Array.Clear(Hull.renderer.vertices, 0, Hull.renderer.vertices.Length);
Hull.renderer.positionInBuffer = 0; Hull.renderer.PositionInBuffer = 0;
foreach (Hull hull in Hull.hullList) foreach (Hull hull in Hull.hullList)
{ {
hull.Render(graphics, cam); hull.Render(graphics, cam);
+41 -34
View File
@@ -51,7 +51,11 @@ namespace Subsurface
#endif #endif
#if LINUX #if LINUX
using (Stream fileStream = File.OpenRead(path)) using (Stream fileStream = File.OpenRead(path))
return Texture2D.FromStream(_graphicsDevice, fileStream);// .FromStream(fileStream, preMultiplyAlpha); {
var texture = Texture2D.FromStream(_graphicsDevice, fileStream);
texture = PreMultiplyAlpha(texture);
return texture;
}
#endif #endif
} }
@@ -87,44 +91,47 @@ namespace Subsurface
texture = Texture2D.FromStream(_graphicsDevice, stream); texture = Texture2D.FromStream(_graphicsDevice, stream);
} }
if (preMultiplyAlpha) if (preMultiplyAlpha) texture = PreMultiplyAlpha(texture);
{
// Setup a render target to hold our final texture which will have premulitplied alpha values
using (RenderTarget2D renderTarget = new RenderTarget2D(_graphicsDevice, texture.Width, texture.Height))
{
Viewport viewportBackup = _graphicsDevice.Viewport;
_graphicsDevice.SetRenderTarget(renderTarget);
_graphicsDevice.Clear(Color.Black);
// Multiply each color by the source alpha, and write in just the color values into the final texture
_spriteBatch.Begin(SpriteSortMode.Immediate, BlendColorBlendState);
_spriteBatch.Draw(texture, texture.Bounds, Color.White);
_spriteBatch.End();
// Now copy over the alpha values from the source texture to the final one, without multiplying them
_spriteBatch.Begin(SpriteSortMode.Immediate, BlendAlphaBlendState);
_spriteBatch.Draw(texture, texture.Bounds, Color.White);
_spriteBatch.End();
// Release the GPU back to drawing to the screen
_graphicsDevice.SetRenderTarget(null);
_graphicsDevice.Viewport = viewportBackup;
// Store data from render target because the RenderTarget2D is volatile
Color[] data = new Color[texture.Width * texture.Height];
renderTarget.GetData(data);
// Unset texture from graphic device and set modified data back to it
_graphicsDevice.Textures[0] = null;
texture.SetData(data);
}
}
return texture; return texture;
} }
#endif #endif
private Texture2D PreMultiplyAlpha(Texture2D texture)
{
// Setup a render target to hold our final texture which will have premulitplied alpha values
using (RenderTarget2D renderTarget = new RenderTarget2D(_graphicsDevice, texture.Width, texture.Height))
{
Viewport viewportBackup = _graphicsDevice.Viewport;
_graphicsDevice.SetRenderTarget(renderTarget);
_graphicsDevice.Clear(Color.Black);
// Multiply each color by the source alpha, and write in just the color values into the final texture
_spriteBatch.Begin(SpriteSortMode.Immediate, BlendColorBlendState);
_spriteBatch.Draw(texture, texture.Bounds, Color.White);
_spriteBatch.End();
// Now copy over the alpha values from the source texture to the final one, without multiplying them
_spriteBatch.Begin(SpriteSortMode.Immediate, BlendAlphaBlendState);
_spriteBatch.Draw(texture, texture.Bounds, Color.White);
_spriteBatch.End();
// Release the GPU back to drawing to the screen
_graphicsDevice.SetRenderTarget(null);
_graphicsDevice.Viewport = viewportBackup;
// Store data from render target because the RenderTarget2D is volatile
Color[] data = new Color[texture.Width * texture.Height];
renderTarget.GetData(data);
// Unset texture from graphic device and set modified data back to it
_graphicsDevice.Textures[0] = null;
texture.SetData(data);
}
return texture;
}
private static readonly BlendState BlendColorBlendState; private static readonly BlendState BlendColorBlendState;
private static readonly BlendState BlendAlphaBlendState; private static readonly BlendState BlendAlphaBlendState;
+3
View File
@@ -943,6 +943,9 @@
<None Include="Content\Sounds\Water\WaterAmbience.ogg"> <None Include="Content\Sounds\Water\WaterAmbience.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Content\watershader.mgfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+1 -1
View File
@@ -9,6 +9,6 @@
<ErrorReportUrlHistory /> <ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture> <FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles> <VerifyUploadedFiles>false</VerifyUploadedFiles>
<ProjectView>ProjectFiles</ProjectView> <ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
-3
View File
@@ -307,7 +307,4 @@ Global
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal EndGlobal
Binary file not shown.