Terraria 1.4.0.5 Source Code
This commit is contained in:
commit
05205f009e
1059 changed files with 563450 additions and 0 deletions
118
Graphics/Shaders/ArmorShaderData.cs
Normal file
118
Graphics/Shaders/ArmorShaderData.cs
Normal file
|
@ -0,0 +1,118 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.ArmorShaderData
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using ReLogic.Content;
|
||||
using System;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class ArmorShaderData : ShaderData
|
||||
{
|
||||
private Vector3 _uColor = Vector3.One;
|
||||
private Vector3 _uSecondaryColor = Vector3.One;
|
||||
private float _uSaturation = 1f;
|
||||
private float _uOpacity = 1f;
|
||||
private Asset<Texture2D> _uImage;
|
||||
private Vector2 _uTargetPosition = Vector2.One;
|
||||
|
||||
public ArmorShaderData(Ref<Effect> shader, string passName)
|
||||
: base(shader, passName)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Apply(Entity entity, DrawData? drawData = null)
|
||||
{
|
||||
this.Shader.Parameters["uColor"].SetValue(this._uColor);
|
||||
this.Shader.Parameters["uSaturation"].SetValue(this._uSaturation);
|
||||
this.Shader.Parameters["uSecondaryColor"].SetValue(this._uSecondaryColor);
|
||||
this.Shader.Parameters["uTime"].SetValue(Main.GlobalTimeWrappedHourly);
|
||||
this.Shader.Parameters["uOpacity"].SetValue(this._uOpacity);
|
||||
this.Shader.Parameters["uTargetPosition"].SetValue(this._uTargetPosition);
|
||||
if (drawData.HasValue)
|
||||
{
|
||||
DrawData drawData1 = drawData.Value;
|
||||
Vector4 vector4 = !drawData1.sourceRect.HasValue ? new Vector4(0.0f, 0.0f, (float) drawData1.texture.Width, (float) drawData1.texture.Height) : new Vector4((float) drawData1.sourceRect.Value.X, (float) drawData1.sourceRect.Value.Y, (float) drawData1.sourceRect.Value.Width, (float) drawData1.sourceRect.Value.Height);
|
||||
this.Shader.Parameters["uSourceRect"].SetValue(vector4);
|
||||
this.Shader.Parameters["uLegacyArmorSourceRect"].SetValue(vector4);
|
||||
this.Shader.Parameters["uWorldPosition"].SetValue(Main.screenPosition + drawData1.position);
|
||||
this.Shader.Parameters["uImageSize0"].SetValue(new Vector2((float) drawData1.texture.Width, (float) drawData1.texture.Height));
|
||||
this.Shader.Parameters["uLegacyArmorSheetSize"].SetValue(new Vector2((float) drawData1.texture.Width, (float) drawData1.texture.Height));
|
||||
this.Shader.Parameters["uRotation"].SetValue(drawData1.rotation * (drawData1.effect.HasFlag((Enum) SpriteEffects.FlipHorizontally) ? -1f : 1f));
|
||||
this.Shader.Parameters["uDirection"].SetValue(drawData1.effect.HasFlag((Enum) SpriteEffects.FlipHorizontally) ? -1 : 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector4 vector4 = new Vector4(0.0f, 0.0f, 4f, 4f);
|
||||
this.Shader.Parameters["uSourceRect"].SetValue(vector4);
|
||||
this.Shader.Parameters["uLegacyArmorSourceRect"].SetValue(vector4);
|
||||
this.Shader.Parameters["uRotation"].SetValue(0.0f);
|
||||
}
|
||||
if (this._uImage != null)
|
||||
{
|
||||
Main.graphics.GraphicsDevice.Textures[1] = (Texture) this._uImage.Value;
|
||||
this.Shader.Parameters["uImageSize1"].SetValue(new Vector2((float) this._uImage.Width(), (float) this._uImage.Height()));
|
||||
}
|
||||
if (entity != null)
|
||||
this.Shader.Parameters["uDirection"].SetValue((float) entity.direction);
|
||||
if (entity is Player player)
|
||||
{
|
||||
Rectangle bodyFrame = player.bodyFrame;
|
||||
this.Shader.Parameters["uLegacyArmorSourceRect"].SetValue(new Vector4((float) bodyFrame.X, (float) bodyFrame.Y, (float) bodyFrame.Width, (float) bodyFrame.Height));
|
||||
this.Shader.Parameters["uLegacyArmorSheetSize"].SetValue(new Vector2(40f, 1120f));
|
||||
}
|
||||
this.Apply();
|
||||
}
|
||||
|
||||
public ArmorShaderData UseColor(float r, float g, float b) => this.UseColor(new Vector3(r, g, b));
|
||||
|
||||
public ArmorShaderData UseColor(Color color) => this.UseColor(color.ToVector3());
|
||||
|
||||
public ArmorShaderData UseColor(Vector3 color)
|
||||
{
|
||||
this._uColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArmorShaderData UseImage(string path)
|
||||
{
|
||||
this._uImage = Main.Assets.Request<Texture2D>(path, (AssetRequestMode) 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArmorShaderData UseOpacity(float alpha)
|
||||
{
|
||||
this._uOpacity = alpha;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArmorShaderData UseTargetPosition(Vector2 position)
|
||||
{
|
||||
this._uTargetPosition = position;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArmorShaderData UseSecondaryColor(float r, float g, float b) => this.UseSecondaryColor(new Vector3(r, g, b));
|
||||
|
||||
public ArmorShaderData UseSecondaryColor(Color color) => this.UseSecondaryColor(color.ToVector3());
|
||||
|
||||
public ArmorShaderData UseSecondaryColor(Vector3 color)
|
||||
{
|
||||
this._uSecondaryColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArmorShaderData UseSaturation(float saturation)
|
||||
{
|
||||
this._uSaturation = saturation;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual ArmorShaderData GetSecondaryShader(Entity entity) => this;
|
||||
}
|
||||
}
|
47
Graphics/Shaders/ArmorShaderDataSet.cs
Normal file
47
Graphics/Shaders/ArmorShaderDataSet.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.ArmorShaderDataSet
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class ArmorShaderDataSet
|
||||
{
|
||||
protected List<ArmorShaderData> _shaderData = new List<ArmorShaderData>();
|
||||
protected Dictionary<int, int> _shaderLookupDictionary = new Dictionary<int, int>();
|
||||
protected int _shaderDataCount;
|
||||
|
||||
public T BindShader<T>(int itemId, T shaderData) where T : ArmorShaderData
|
||||
{
|
||||
this._shaderLookupDictionary[itemId] = ++this._shaderDataCount;
|
||||
this._shaderData.Add((ArmorShaderData) shaderData);
|
||||
return shaderData;
|
||||
}
|
||||
|
||||
public void Apply(int shaderId, Entity entity, DrawData? drawData = null)
|
||||
{
|
||||
if (shaderId >= 1 && shaderId <= this._shaderDataCount)
|
||||
this._shaderData[shaderId - 1].Apply(entity, drawData);
|
||||
else
|
||||
Main.pixelShader.CurrentTechnique.Passes[0].Apply();
|
||||
}
|
||||
|
||||
public void ApplySecondary(int shaderId, Entity entity, DrawData? drawData = null)
|
||||
{
|
||||
if (shaderId >= 1 && shaderId <= this._shaderDataCount)
|
||||
this._shaderData[shaderId - 1].GetSecondaryShader(entity).Apply(entity, drawData);
|
||||
else
|
||||
Main.pixelShader.CurrentTechnique.Passes[0].Apply();
|
||||
}
|
||||
|
||||
public ArmorShaderData GetShaderFromItemId(int type) => this._shaderLookupDictionary.ContainsKey(type) ? this._shaderData[this._shaderLookupDictionary[type] - 1] : (ArmorShaderData) null;
|
||||
|
||||
public int GetShaderIdFromItemId(int type) => this._shaderLookupDictionary.ContainsKey(type) ? this._shaderLookupDictionary[type] : 0;
|
||||
|
||||
public ArmorShaderData GetSecondaryShader(int id, Player player) => id != 0 && id <= this._shaderDataCount && this._shaderData[id - 1] != null ? this._shaderData[id - 1].GetSecondaryShader((Entity) player) : (ArmorShaderData) null;
|
||||
}
|
||||
}
|
17
Graphics/Shaders/GameShaders.cs
Normal file
17
Graphics/Shaders/GameShaders.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.GameShaders
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class GameShaders
|
||||
{
|
||||
public static ArmorShaderDataSet Armor = new ArmorShaderDataSet();
|
||||
public static HairShaderDataSet Hair = new HairShaderDataSet();
|
||||
public static Dictionary<string, MiscShaderData> Misc = new Dictionary<string, MiscShaderData>();
|
||||
}
|
||||
}
|
106
Graphics/Shaders/HairShaderData.cs
Normal file
106
Graphics/Shaders/HairShaderData.cs
Normal file
|
@ -0,0 +1,106 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.HairShaderData
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using ReLogic.Content;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class HairShaderData : ShaderData
|
||||
{
|
||||
protected Vector3 _uColor = Vector3.One;
|
||||
protected Vector3 _uSecondaryColor = Vector3.One;
|
||||
protected float _uSaturation = 1f;
|
||||
protected float _uOpacity = 1f;
|
||||
protected Asset<Texture2D> _uImage;
|
||||
protected bool _shaderDisabled;
|
||||
private Vector2 _uTargetPosition = Vector2.One;
|
||||
|
||||
public bool ShaderDisabled => this._shaderDisabled;
|
||||
|
||||
public HairShaderData(Ref<Effect> shader, string passName)
|
||||
: base(shader, passName)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Apply(Player player, DrawData? drawData = null)
|
||||
{
|
||||
if (this._shaderDisabled)
|
||||
return;
|
||||
this.Shader.Parameters["uColor"].SetValue(this._uColor);
|
||||
this.Shader.Parameters["uSaturation"].SetValue(this._uSaturation);
|
||||
this.Shader.Parameters["uSecondaryColor"].SetValue(this._uSecondaryColor);
|
||||
this.Shader.Parameters["uTime"].SetValue(Main.GlobalTimeWrappedHourly);
|
||||
this.Shader.Parameters["uOpacity"].SetValue(this._uOpacity);
|
||||
this.Shader.Parameters["uTargetPosition"].SetValue(this._uTargetPosition);
|
||||
if (drawData.HasValue)
|
||||
{
|
||||
DrawData drawData1 = drawData.Value;
|
||||
this.Shader.Parameters["uSourceRect"].SetValue(new Vector4((float) drawData1.sourceRect.Value.X, (float) drawData1.sourceRect.Value.Y, (float) drawData1.sourceRect.Value.Width, (float) drawData1.sourceRect.Value.Height));
|
||||
this.Shader.Parameters["uWorldPosition"].SetValue(Main.screenPosition + drawData1.position);
|
||||
this.Shader.Parameters["uImageSize0"].SetValue(new Vector2((float) drawData1.texture.Width, (float) drawData1.texture.Height));
|
||||
}
|
||||
else
|
||||
this.Shader.Parameters["uSourceRect"].SetValue(new Vector4(0.0f, 0.0f, 4f, 4f));
|
||||
if (this._uImage != null)
|
||||
{
|
||||
Main.graphics.GraphicsDevice.Textures[1] = (Texture) this._uImage.Value;
|
||||
this.Shader.Parameters["uImageSize1"].SetValue(new Vector2((float) this._uImage.Width(), (float) this._uImage.Height()));
|
||||
}
|
||||
if (player != null)
|
||||
this.Shader.Parameters["uDirection"].SetValue((float) player.direction);
|
||||
this.Apply();
|
||||
}
|
||||
|
||||
public virtual Color GetColor(Player player, Color lightColor) => new Color(lightColor.ToVector4() * player.hairColor.ToVector4());
|
||||
|
||||
public HairShaderData UseColor(float r, float g, float b) => this.UseColor(new Vector3(r, g, b));
|
||||
|
||||
public HairShaderData UseColor(Color color) => this.UseColor(color.ToVector3());
|
||||
|
||||
public HairShaderData UseColor(Vector3 color)
|
||||
{
|
||||
this._uColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HairShaderData UseImage(string path)
|
||||
{
|
||||
this._uImage = Main.Assets.Request<Texture2D>(path, (AssetRequestMode) 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HairShaderData UseOpacity(float alpha)
|
||||
{
|
||||
this._uOpacity = alpha;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HairShaderData UseSecondaryColor(float r, float g, float b) => this.UseSecondaryColor(new Vector3(r, g, b));
|
||||
|
||||
public HairShaderData UseSecondaryColor(Color color) => this.UseSecondaryColor(color.ToVector3());
|
||||
|
||||
public HairShaderData UseSecondaryColor(Vector3 color)
|
||||
{
|
||||
this._uSecondaryColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HairShaderData UseSaturation(float saturation)
|
||||
{
|
||||
this._uSaturation = saturation;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HairShaderData UseTargetPosition(Vector2 position)
|
||||
{
|
||||
this._uTargetPosition = position;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
43
Graphics/Shaders/HairShaderDataSet.cs
Normal file
43
Graphics/Shaders/HairShaderDataSet.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.HairShaderDataSet
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class HairShaderDataSet
|
||||
{
|
||||
protected List<HairShaderData> _shaderData = new List<HairShaderData>();
|
||||
protected Dictionary<int, short> _shaderLookupDictionary = new Dictionary<int, short>();
|
||||
protected byte _shaderDataCount;
|
||||
|
||||
public T BindShader<T>(int itemId, T shaderData) where T : HairShaderData
|
||||
{
|
||||
if (this._shaderDataCount == byte.MaxValue)
|
||||
throw new Exception("Too many shaders bound.");
|
||||
this._shaderLookupDictionary[itemId] = (short) ++this._shaderDataCount;
|
||||
this._shaderData.Add((HairShaderData) shaderData);
|
||||
return shaderData;
|
||||
}
|
||||
|
||||
public void Apply(short shaderId, Player player, DrawData? drawData = null)
|
||||
{
|
||||
if (shaderId != (short) 0 && (int) shaderId <= (int) this._shaderDataCount)
|
||||
this._shaderData[(int) shaderId - 1].Apply(player, drawData);
|
||||
else
|
||||
Main.pixelShader.CurrentTechnique.Passes[0].Apply();
|
||||
}
|
||||
|
||||
public Color GetColor(short shaderId, Player player, Color lightColor) => shaderId != (short) 0 && (int) shaderId <= (int) this._shaderDataCount ? this._shaderData[(int) shaderId - 1].GetColor(player, lightColor) : new Color(lightColor.ToVector4() * player.hairColor.ToVector4());
|
||||
|
||||
public HairShaderData GetShaderFromItemId(int type) => this._shaderLookupDictionary.ContainsKey(type) ? this._shaderData[(int) this._shaderLookupDictionary[type] - 1] : (HairShaderData) null;
|
||||
|
||||
public short GetShaderIdFromItemId(int type) => this._shaderLookupDictionary.ContainsKey(type) ? this._shaderLookupDictionary[type] : (short) -1;
|
||||
}
|
||||
}
|
138
Graphics/Shaders/MiscShaderData.cs
Normal file
138
Graphics/Shaders/MiscShaderData.cs
Normal file
|
@ -0,0 +1,138 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.MiscShaderData
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using ReLogic.Content;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class MiscShaderData : ShaderData
|
||||
{
|
||||
private Vector3 _uColor = Vector3.One;
|
||||
private Vector3 _uSecondaryColor = Vector3.One;
|
||||
private float _uSaturation = 1f;
|
||||
private float _uOpacity = 1f;
|
||||
private Asset<Texture2D> _uImage0;
|
||||
private Asset<Texture2D> _uImage1;
|
||||
private Asset<Texture2D> _uImage2;
|
||||
private bool _useProjectionMatrix;
|
||||
private Vector4 _shaderSpecificData = Vector4.Zero;
|
||||
|
||||
public MiscShaderData(Ref<Effect> shader, string passName)
|
||||
: base(shader, passName)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Apply(DrawData? drawData = null)
|
||||
{
|
||||
this.Shader.Parameters["uColor"].SetValue(this._uColor);
|
||||
this.Shader.Parameters["uSaturation"].SetValue(this._uSaturation);
|
||||
this.Shader.Parameters["uSecondaryColor"].SetValue(this._uSecondaryColor);
|
||||
this.Shader.Parameters["uTime"].SetValue(Main.GlobalTimeWrappedHourly);
|
||||
this.Shader.Parameters["uOpacity"].SetValue(this._uOpacity);
|
||||
this.Shader.Parameters["uShaderSpecificData"].SetValue(this._shaderSpecificData);
|
||||
if (drawData.HasValue)
|
||||
{
|
||||
DrawData drawData1 = drawData.Value;
|
||||
Vector4 vector4 = Vector4.Zero;
|
||||
if (drawData.Value.sourceRect.HasValue)
|
||||
vector4 = new Vector4((float) drawData1.sourceRect.Value.X, (float) drawData1.sourceRect.Value.Y, (float) drawData1.sourceRect.Value.Width, (float) drawData1.sourceRect.Value.Height);
|
||||
this.Shader.Parameters["uSourceRect"].SetValue(vector4);
|
||||
this.Shader.Parameters["uWorldPosition"].SetValue(Main.screenPosition + drawData1.position);
|
||||
this.Shader.Parameters["uImageSize0"].SetValue(new Vector2((float) drawData1.texture.Width, (float) drawData1.texture.Height));
|
||||
}
|
||||
else
|
||||
this.Shader.Parameters["uSourceRect"].SetValue(new Vector4(0.0f, 0.0f, 4f, 4f));
|
||||
if (this._uImage0 != null)
|
||||
{
|
||||
Main.graphics.GraphicsDevice.Textures[0] = (Texture) this._uImage0.Value;
|
||||
Main.graphics.GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
|
||||
this.Shader.Parameters["uImageSize0"].SetValue(new Vector2((float) this._uImage0.Width(), (float) this._uImage0.Height()));
|
||||
}
|
||||
if (this._uImage1 != null)
|
||||
{
|
||||
Main.graphics.GraphicsDevice.Textures[1] = (Texture) this._uImage1.Value;
|
||||
Main.graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearWrap;
|
||||
this.Shader.Parameters["uImageSize1"].SetValue(new Vector2((float) this._uImage1.Width(), (float) this._uImage1.Height()));
|
||||
}
|
||||
if (this._uImage2 != null)
|
||||
{
|
||||
Main.graphics.GraphicsDevice.Textures[2] = (Texture) this._uImage2.Value;
|
||||
Main.graphics.GraphicsDevice.SamplerStates[2] = SamplerState.LinearWrap;
|
||||
this.Shader.Parameters["uImageSize2"].SetValue(new Vector2((float) this._uImage2.Width(), (float) this._uImage2.Height()));
|
||||
}
|
||||
if (this._useProjectionMatrix)
|
||||
this.Shader.Parameters["uMatrixTransform0"].SetValue(Main.GameViewMatrix.NormalizedTransformationmatrix);
|
||||
this.Apply();
|
||||
}
|
||||
|
||||
public MiscShaderData UseColor(float r, float g, float b) => this.UseColor(new Vector3(r, g, b));
|
||||
|
||||
public MiscShaderData UseColor(Color color) => this.UseColor(color.ToVector3());
|
||||
|
||||
public MiscShaderData UseColor(Vector3 color)
|
||||
{
|
||||
this._uColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MiscShaderData UseImage0(string path)
|
||||
{
|
||||
this._uImage0 = Main.Assets.Request<Texture2D>(path, (AssetRequestMode) 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MiscShaderData UseImage1(string path)
|
||||
{
|
||||
this._uImage1 = Main.Assets.Request<Texture2D>(path, (AssetRequestMode) 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MiscShaderData UseImage2(string path)
|
||||
{
|
||||
this._uImage2 = Main.Assets.Request<Texture2D>(path, (AssetRequestMode) 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MiscShaderData UseOpacity(float alpha)
|
||||
{
|
||||
this._uOpacity = alpha;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MiscShaderData UseSecondaryColor(float r, float g, float b) => this.UseSecondaryColor(new Vector3(r, g, b));
|
||||
|
||||
public MiscShaderData UseSecondaryColor(Color color) => this.UseSecondaryColor(color.ToVector3());
|
||||
|
||||
public MiscShaderData UseSecondaryColor(Vector3 color)
|
||||
{
|
||||
this._uSecondaryColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MiscShaderData UseProjectionMatrix(bool doUse)
|
||||
{
|
||||
this._useProjectionMatrix = doUse;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MiscShaderData UseSaturation(float saturation)
|
||||
{
|
||||
this._uSaturation = saturation;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual MiscShaderData GetSecondaryShader(Entity entity) => this;
|
||||
|
||||
public MiscShaderData UseShaderSpecificData(Vector4 specificData)
|
||||
{
|
||||
this._shaderSpecificData = specificData;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
179
Graphics/Shaders/ScreenShaderData.cs
Normal file
179
Graphics/Shaders/ScreenShaderData.cs
Normal file
|
@ -0,0 +1,179 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.ScreenShaderData
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using ReLogic.Content;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class ScreenShaderData : ShaderData
|
||||
{
|
||||
private Vector3 _uColor = Vector3.One;
|
||||
private Vector3 _uSecondaryColor = Vector3.One;
|
||||
private float _uOpacity = 1f;
|
||||
private float _globalOpacity = 1f;
|
||||
private float _uIntensity = 1f;
|
||||
private Vector2 _uTargetPosition = Vector2.One;
|
||||
private Vector2 _uDirection = new Vector2(0.0f, 1f);
|
||||
private float _uProgress;
|
||||
private Vector2 _uImageOffset = Vector2.Zero;
|
||||
private Asset<Texture2D>[] _uAssetImages = new Asset<Texture2D>[3];
|
||||
private Texture2D[] _uCustomImages = new Texture2D[3];
|
||||
private SamplerState[] _samplerStates = new SamplerState[3];
|
||||
private Vector2[] _imageScales = new Vector2[3]
|
||||
{
|
||||
Vector2.One,
|
||||
Vector2.One,
|
||||
Vector2.One
|
||||
};
|
||||
|
||||
public float Intensity => this._uIntensity;
|
||||
|
||||
public float CombinedOpacity => this._uOpacity * this._globalOpacity;
|
||||
|
||||
public ScreenShaderData(string passName)
|
||||
: base(Main.ScreenShaderRef, passName)
|
||||
{
|
||||
}
|
||||
|
||||
public ScreenShaderData(Ref<Effect> shader, string passName)
|
||||
: base(shader, passName)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Update(GameTime gameTime)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Apply()
|
||||
{
|
||||
Vector2 vector2_1 = new Vector2((float) Main.offScreenRange, (float) Main.offScreenRange);
|
||||
Vector2 vector2_2 = new Vector2((float) Main.screenWidth, (float) Main.screenHeight) / Main.GameViewMatrix.Zoom;
|
||||
Vector2 vector2_3 = new Vector2((float) Main.screenWidth, (float) Main.screenHeight) * 0.5f;
|
||||
Vector2 vector2_4 = Main.screenPosition + vector2_3 * (Vector2.One - Vector2.One / Main.GameViewMatrix.Zoom);
|
||||
this.Shader.Parameters["uColor"].SetValue(this._uColor);
|
||||
this.Shader.Parameters["uOpacity"].SetValue(this.CombinedOpacity);
|
||||
this.Shader.Parameters["uSecondaryColor"].SetValue(this._uSecondaryColor);
|
||||
this.Shader.Parameters["uTime"].SetValue(Main.GlobalTimeWrappedHourly);
|
||||
this.Shader.Parameters["uScreenResolution"].SetValue(vector2_2);
|
||||
this.Shader.Parameters["uScreenPosition"].SetValue(vector2_4 - vector2_1);
|
||||
this.Shader.Parameters["uTargetPosition"].SetValue(this._uTargetPosition - vector2_1);
|
||||
this.Shader.Parameters["uImageOffset"].SetValue(this._uImageOffset);
|
||||
this.Shader.Parameters["uIntensity"].SetValue(this._uIntensity);
|
||||
this.Shader.Parameters["uProgress"].SetValue(this._uProgress);
|
||||
this.Shader.Parameters["uDirection"].SetValue(this._uDirection);
|
||||
this.Shader.Parameters["uZoom"].SetValue(Main.GameViewMatrix.Zoom);
|
||||
for (int index = 0; index < this._uAssetImages.Length; ++index)
|
||||
{
|
||||
Texture2D uCustomImage = this._uCustomImages[index];
|
||||
if (this._uAssetImages[index] != null && this._uAssetImages[index].IsLoaded)
|
||||
uCustomImage = this._uAssetImages[index].Value;
|
||||
if (uCustomImage != null)
|
||||
{
|
||||
Main.graphics.GraphicsDevice.Textures[index + 1] = (Texture) uCustomImage;
|
||||
int width = uCustomImage.Width;
|
||||
int height = uCustomImage.Height;
|
||||
Main.graphics.GraphicsDevice.SamplerStates[index + 1] = this._samplerStates[index] == null ? (!Utils.IsPowerOfTwo(width) || !Utils.IsPowerOfTwo(height) ? SamplerState.AnisotropicClamp : SamplerState.LinearWrap) : this._samplerStates[index];
|
||||
this.Shader.Parameters["uImageSize" + (object) (index + 1)].SetValue(new Vector2((float) width, (float) height) * this._imageScales[index]);
|
||||
}
|
||||
}
|
||||
base.Apply();
|
||||
}
|
||||
|
||||
public ScreenShaderData UseImageOffset(Vector2 offset)
|
||||
{
|
||||
this._uImageOffset = offset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseIntensity(float intensity)
|
||||
{
|
||||
this._uIntensity = intensity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseColor(float r, float g, float b) => this.UseColor(new Vector3(r, g, b));
|
||||
|
||||
public ScreenShaderData UseProgress(float progress)
|
||||
{
|
||||
this._uProgress = progress;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseImage(
|
||||
Texture2D image,
|
||||
int index = 0,
|
||||
SamplerState samplerState = null)
|
||||
{
|
||||
this._samplerStates[index] = samplerState;
|
||||
this._uAssetImages[index] = (Asset<Texture2D>) null;
|
||||
this._uCustomImages[index] = image;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseImage(
|
||||
string path,
|
||||
int index = 0,
|
||||
SamplerState samplerState = null)
|
||||
{
|
||||
this._uAssetImages[index] = Main.Assets.Request<Texture2D>(path, (AssetRequestMode) 1);
|
||||
this._uCustomImages[index] = (Texture2D) null;
|
||||
this._samplerStates[index] = samplerState;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseColor(Color color) => this.UseColor(color.ToVector3());
|
||||
|
||||
public ScreenShaderData UseColor(Vector3 color)
|
||||
{
|
||||
this._uColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseDirection(Vector2 direction)
|
||||
{
|
||||
this._uDirection = direction;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseGlobalOpacity(float opacity)
|
||||
{
|
||||
this._globalOpacity = opacity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseTargetPosition(Vector2 position)
|
||||
{
|
||||
this._uTargetPosition = position;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseSecondaryColor(float r, float g, float b) => this.UseSecondaryColor(new Vector3(r, g, b));
|
||||
|
||||
public ScreenShaderData UseSecondaryColor(Color color) => this.UseSecondaryColor(color.ToVector3());
|
||||
|
||||
public ScreenShaderData UseSecondaryColor(Vector3 color)
|
||||
{
|
||||
this._uSecondaryColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseOpacity(float opacity)
|
||||
{
|
||||
this._uOpacity = opacity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScreenShaderData UseImageScale(Vector2 scale, int index = 0)
|
||||
{
|
||||
this._imageScales[index] = scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual ScreenShaderData GetSecondaryShader(Player player) => this;
|
||||
}
|
||||
}
|
40
Graphics/Shaders/ShaderData.cs
Normal file
40
Graphics/Shaders/ShaderData.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Graphics.Shaders.ShaderData
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace Terraria.Graphics.Shaders
|
||||
{
|
||||
public class ShaderData
|
||||
{
|
||||
private readonly Ref<Effect> _shader;
|
||||
private string _passName;
|
||||
private EffectPass _effectPass;
|
||||
|
||||
public Effect Shader => this._shader != null ? this._shader.Value : (Effect) null;
|
||||
|
||||
public ShaderData(Ref<Effect> shader, string passName)
|
||||
{
|
||||
this._passName = passName;
|
||||
this._shader = shader;
|
||||
}
|
||||
|
||||
public void SwapProgram(string passName)
|
||||
{
|
||||
this._passName = passName;
|
||||
if (passName == null)
|
||||
return;
|
||||
this._effectPass = this.Shader.CurrentTechnique.Passes[passName];
|
||||
}
|
||||
|
||||
public virtual void Apply()
|
||||
{
|
||||
if (this._shader != null && this.Shader != null && this._passName != null)
|
||||
this._effectPass = this.Shader.CurrentTechnique.Passes[this._passName];
|
||||
this._effectPass.Apply();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue