Skip to content

Commit

Permalink
Configurable Virtual Layer colors
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Nov 18, 2023
1 parent cf51960 commit cc52ac0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class MapManager
private readonly GraphicsDevice _gfxDevice;

private MapEffect _mapEffect;
public MapEffect MapEffect => _mapEffect;
private readonly MapRenderer _mapRenderer;
private readonly SpriteBatch _spriteBatch;
private readonly Texture2D _background;
Expand Down
19 changes: 19 additions & 0 deletions CentrED/Renderer/Effects/MapEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ public class MapEffect : Effect
private readonly EffectParameter _ambientLightColorParam;
private readonly EffectParameter _worldViewProjParam;
private readonly EffectParameter _lightWorldViewProjParam;
private readonly EffectParameter _virtualLayerFillColorParam;
private readonly EffectParameter _virtualLayerBorderColorParam;
private DirectionalLight _lightSource;

private Matrix _worldViewProj = Matrix.Identity;
private Matrix _lightWorldViewProj = Matrix.Identity;

private Vector3 _ambientLightColor = Vector3.One;

private Vector4 _virtualLayerFillColor = new(0.2f, 0.2f, 0.2f, 0.1f);
private Vector4 _virtualLayerBorderColor = new(1.0f, 1.0f, 1.0f, 1.0f);

public Matrix WorldViewProj
{
get { return _worldViewProj; }
Expand All @@ -34,6 +39,16 @@ public Vector3 AmbientLightColor
set { _ambientLightColor = value; }
}

public Vector4 VirtualLayerFillColor
{
set => _virtualLayerFillColor = value;
}

public Vector4 VirtualLayerBorderColor
{
set => _virtualLayerBorderColor = value;
}

public DirectionalLight LightSource
{
get { return _lightSource; }
Expand Down Expand Up @@ -66,6 +81,8 @@ public MapEffect(GraphicsDevice device, byte[] effectCode) : base(device, effect
_ambientLightColorParam = Parameters["AmbientLightColor"];
_worldViewProjParam = Parameters["WorldViewProj"];
_lightWorldViewProjParam = Parameters["LightWorldViewProj"];
_virtualLayerFillColorParam = Parameters["VirtualLayerFillColor"];
_virtualLayerBorderColorParam = Parameters["VirtualLayerBorderColor"];

_lightSource = new DirectionalLight
(
Expand All @@ -81,5 +98,7 @@ protected override void OnApply()
_worldViewProjParam.SetValue(_worldViewProj);
_lightWorldViewProjParam.SetValue(_lightWorldViewProj);
_ambientLightColorParam.SetValue(new Vector4(_ambientLightColor, 1));
_virtualLayerFillColorParam.SetValue(_virtualLayerFillColor);
_virtualLayerBorderColorParam.SetValue(_virtualLayerBorderColor);
}
}
10 changes: 8 additions & 2 deletions CentrED/Renderer/Effects/Shaders/MapEffect.fx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ cbuffer LightParameters : register(b1) {
float3 DirectionalLightSpecularColor;
};

cbuffer VirtualLayer : register(b2) {
float4 VirtualLayerFillColor;
float4 VirtualLayerBorderColor;
};


/* For now, all the techniques use the same vertex definition */
struct VSInput {
float4 Position : SV_Position;
Expand Down Expand Up @@ -303,11 +309,11 @@ float4 VirtualLayerPSMain(float4 WorldPosition : TEXCOORD0) : SV_Target0
//0.7 worked for me as it's not glitching when moving camera
if (abs(fmod(WorldPosition.x, TileSize)) < 0.7 || abs(fmod(WorldPosition.y, TileSize)) < 0.7)
{
return float4(1.0, 1.0, 1.0, 1.0);
return VirtualLayerBorderColor;
}
else
{
return float4(0.2, 0.2, 0.2, 0.1);
return VirtualLayerFillColor;
}
}

Expand Down
Binary file modified CentrED/Renderer/Effects/Shaders/MapEffect.fxc
Binary file not shown.
30 changes: 28 additions & 2 deletions CentrED/UI/Windows/OptionsWindow.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
using ImGuiNET;
using System.Numerics;
using ImGuiNET;
using static CentrED.Application;

namespace CentrED.UI.Windows;

public class OptionsWindow : Window
{
public override string Name => "Options";

private Vector4 _virtualLayerFillColor;
private Vector4 _virtualLayerBorderColor;


public override void Draw()
{
if (!Show)
return;

ImGui.Begin("Options", ref _show, ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoResize);
ImGui.Text("Nothing to see here (yet) :)");
if (ImGui.ColorPicker4("Virtual Layer Fill Color", ref _virtualLayerFillColor))
{
CEDGame.MapManager.MapEffect.VirtualLayerFillColor = new Microsoft.Xna.Framework.Vector4
(
_virtualLayerFillColor.X,
_virtualLayerFillColor.Y,
_virtualLayerFillColor.Z,
_virtualLayerFillColor.W
);
}
if (ImGui.ColorPicker4("Virtual Layer Border Color", ref _virtualLayerBorderColor))
{
CEDGame.MapManager.MapEffect.VirtualLayerBorderColor = new Microsoft.Xna.Framework.Vector4
(
_virtualLayerBorderColor.X,
_virtualLayerBorderColor.Y,
_virtualLayerBorderColor.Z,
_virtualLayerBorderColor.W
);
}

ImGui.End();
}
}

0 comments on commit cc52ac0

Please sign in to comment.