shader customisation
This commit is contained in:
@@ -94,6 +94,7 @@ namespace SpriteStacker
|
||||
}
|
||||
if (Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds - LastFT > 16)
|
||||
{
|
||||
Config.SunAngle++;
|
||||
LastFT = Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds;
|
||||
if (Camera.Rotation == 360 || !Rotate && Camera.Rotation != 0) Camera.Rotation = 0;
|
||||
if(Rotate)Camera.Rotation++;
|
||||
|
||||
@@ -16,6 +16,47 @@ namespace SpriteStacker
|
||||
Editing,
|
||||
Rendering
|
||||
}
|
||||
public class RenderConfig
|
||||
{
|
||||
public float ShadowR = 0.0f;
|
||||
public float ShadowG = 0.0f;
|
||||
public float ShadowB = 0.0f;
|
||||
public float ShadowA = 1.0f;
|
||||
public float ModifyR = 0.0f;
|
||||
public float ModifyG = 0.0f;
|
||||
public float ModifyB = 0.0f;
|
||||
public float ModifyA = 0.0f;
|
||||
float[][] colorMatrixElements = {
|
||||
new float[] {1.0f, 0, 0, 0, 0},//R
|
||||
new float[] {0,1.0f, 0, 0, 0},//G
|
||||
new float[] {0, 0, 1.0f, 0, 0},//B
|
||||
new float[] {0, 0, 0, 1f, 0},
|
||||
new float[] {0.0f, 0.0f, 0.0f, 0f, 1}};
|
||||
public bool Interpolate = false;
|
||||
public bool PixelPerfect = true;
|
||||
|
||||
public RenderConfig(float ShadowR, float ShadowG, float ShadowB, float ShadowA, float ModifyR, float ModifyG, float ModifyB, float ModifyA, bool Interpolate, bool PixelPerfect) {
|
||||
this.ShadowR = ShadowR;
|
||||
this.ShadowG = ShadowG;
|
||||
this.ShadowB = ShadowB;
|
||||
this.ShadowA = ShadowA;
|
||||
this.ModifyR = ModifyR;
|
||||
this.ModifyG = ModifyG;
|
||||
this.ModifyB = ModifyB;
|
||||
this.ModifyA = ModifyA;
|
||||
this.Interpolate = Interpolate;
|
||||
this.PixelPerfect = PixelPerfect;
|
||||
colorMatrixElements = new float[][]{
|
||||
new float[] { ShadowR, 0, 0, 0, 0 },
|
||||
new float[] { 0, ShadowG, 0, 0, 0 },
|
||||
new float[] { 0, 0, ShadowB, 0, 0 },
|
||||
new float[] { 0, 0, 0, ShadowA, 0 },
|
||||
new float[] { ModifyR, ModifyG, ModifyB, ModifyA, 1 }}
|
||||
;
|
||||
}
|
||||
|
||||
public float[][] GetColorMatrix() { return colorMatrixElements; }
|
||||
}
|
||||
public static class Config
|
||||
{
|
||||
public static Color BasePlateColour = Color.FromArgb(255, 255, 255, 255);
|
||||
@@ -25,6 +66,9 @@ namespace SpriteStacker
|
||||
public static int RenderIndex = 0;
|
||||
public static RenderMode renderMode = RenderMode.Editing;
|
||||
public static int RenderResolution = 1;
|
||||
public static RenderConfig ShadowRenderConfig = new RenderConfig(0f,0f,0.15f,1.0f,0f,0f,0f,0f,false,true);
|
||||
public static RenderConfig ShadowLayerConfig = new RenderConfig(1.0f, 1.0f, 1.0f, 1.0f, 0f, 0f, 0f, -0.6f, false, true);
|
||||
public static int SunAngle = 0;
|
||||
}
|
||||
public class ColourPalette
|
||||
{
|
||||
@@ -239,35 +283,44 @@ namespace SpriteStacker
|
||||
{
|
||||
RenderResolution = Math.Max(RenderResolution, 1);
|
||||
Bitmap Render = new Bitmap((Width * 2 * RenderResolution), (Length + (int)(ModelData.Count * Camera.ViewAngle)) * 2 * RenderResolution);
|
||||
Bitmap Shadows = new Bitmap((Width * 2 * RenderResolution), (Length + (int)(ModelData.Count * Camera.ViewAngle)) * 2 * RenderResolution);
|
||||
Graphics G = Graphics.FromImage(Render);
|
||||
Graphics S = Graphics.FromImage(Shadows);
|
||||
G.ResetTransform();
|
||||
G.TranslateTransform(Render.Width/2, Render.Height/2);
|
||||
G.RotateTransform(Camera.Rotation);
|
||||
float AngleScale = Camera.ViewAngle * RenderResolution;
|
||||
if (!Config.ShadowLayerConfig.Interpolate)
|
||||
{
|
||||
G.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
|
||||
G.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
||||
G.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
|
||||
float[][] colorMatrixElements = {
|
||||
new float[] {0.0f, 0, 0, 0, 0},//R
|
||||
new float[] {0, 0.0f, 0, 0, 0},//G
|
||||
new float[] {0, 0, 0.0f, 0, 0},//B
|
||||
new float[] {0, 0, 0, 0.8f, 0},
|
||||
new float[] {0.0f, 0.0f, 0.0f, 0f, 1}};
|
||||
|
||||
ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
|
||||
}
|
||||
if (Config.ShadowLayerConfig.PixelPerfect) G.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
|
||||
if (Config.ShadowRenderConfig.PixelPerfect)
|
||||
{
|
||||
S.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
|
||||
}
|
||||
if (!Config.ShadowRenderConfig.Interpolate)
|
||||
{
|
||||
S.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
|
||||
S.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
||||
}
|
||||
ColorMatrix colorMatrix = new ColorMatrix(Config.ShadowRenderConfig.GetColorMatrix());
|
||||
ImageAttributes imageAttributes = new ImageAttributes();
|
||||
imageAttributes.SetColorMatrix(
|
||||
colorMatrix,
|
||||
ColorMatrixFlag.Default,
|
||||
ColorAdjustType.Bitmap);
|
||||
imageAttributes.SetColorMatrix(colorMatrix,ColorMatrixFlag.Default,ColorAdjustType.Bitmap);
|
||||
for (int i = 0; i < ModelData.Count; i++)
|
||||
{
|
||||
G.ResetTransform();
|
||||
G.TranslateTransform(Render.Width / 2 - ((i * RenderResolution / 1.25f) * (float)Math.Cos(Camera.Rotation * Math.PI / 180.0)), Render.Height / 2 - (((i / 1.25f) * (float)Math.Sin(Camera.Rotation * Math.PI / 180.0)) * AngleScale));
|
||||
G.RotateTransform(Camera.Rotation);
|
||||
G.DrawImage(LayerImages[i], new Rectangle(-(LayerImages[i].Width / 2) * RenderResolution, -(LayerImages[i].Height / 2) * RenderResolution, LayerImages[i].Width * RenderResolution, LayerImages[i].Height * RenderResolution)
|
||||
S.ResetTransform();
|
||||
S.TranslateTransform(Render.Width / 2 - ((i * RenderResolution / 1.25f) * (float)Math.Cos((Camera.Rotation + Config.SunAngle) * Math.PI / 180.0)), Render.Height / 2 - (((i / 1.25f) * (float)Math.Sin((Camera.Rotation + Config.SunAngle) * Math.PI / 180.0)) * AngleScale));
|
||||
S.RotateTransform(Camera.Rotation);
|
||||
S.DrawImage(LayerImages[i], new Rectangle(-(LayerImages[i].Width / 2) * RenderResolution, -(LayerImages[i].Height / 2) * RenderResolution, LayerImages[i].Width * RenderResolution, LayerImages[i].Height * RenderResolution)
|
||||
, 0, 0, LayerImages[i].Width, LayerImages[i].Height, GraphicsUnit.Pixel, imageAttributes);
|
||||
}
|
||||
colorMatrix = new ColorMatrix(Config.ShadowLayerConfig.GetColorMatrix());
|
||||
imageAttributes = new ImageAttributes();
|
||||
imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
|
||||
G.ResetTransform();
|
||||
G.DrawImage(Shadows, new Rectangle(0,0,Shadows.Width,Shadows.Height),0,0,Shadows.Width,Shadows.Height,GraphicsUnit.Pixel,imageAttributes);
|
||||
for (int i = 0; i < ModelData.Count; i++)
|
||||
{
|
||||
G.ResetTransform();
|
||||
|
||||
Reference in New Issue
Block a user