Skip to content

Commit

Permalink
Dynamic hue count
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperFilutowski-TomTom authored and kaczy93 committed Dec 25, 2023
1 parent b6f0e25 commit 3d42e5b
Show file tree
Hide file tree
Showing 4 changed files with 17 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 @@ -237,6 +237,7 @@ public void Load(string clientPath, string clientVersion)

TextureAtlas.InitializeSharedTexture(_gfxDevice);
HuesManager.Initialize(_gfxDevice);
_mapEffect.HueCount = HuesManager.Instance.HuesCount;
RadarMap.Initialize(_gfxDevice);

var landIds = new List<int>();
Expand Down
9 changes: 9 additions & 0 deletions CentrED/Renderer/Effects/MapEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ namespace CentrED.Renderer.Effects;
public class MapEffect : Effect
{
private readonly EffectParameter _worldViewProjParam;
private readonly EffectParameter _hueCountParam;
private readonly EffectParameter _virtualLayerFillColorParam;
private readonly EffectParameter _virtualLayerBorderColorParam;

private Matrix _worldViewProj = Matrix.Identity;
private int _hueCount = 0;

private Vector4 _virtualLayerFillColor = new(0.2f, 0.2f, 0.2f, 0.1f);
private Vector4 _virtualLayerBorderColor = new(1.0f, 1.0f, 1.0f, 1.0f);
Expand All @@ -20,6 +22,11 @@ public Matrix WorldViewProj
set { _worldViewProj = value; }
}

public int HueCount
{
set => _hueCount = value;
}

public Vector4 VirtualLayerFillColor
{
set => _virtualLayerFillColor = value;
Expand Down Expand Up @@ -55,13 +62,15 @@ public MapEffect(GraphicsDevice device) : this
public MapEffect(GraphicsDevice device, byte[] effectCode) : base(device, effectCode)
{
_worldViewProjParam = Parameters["WorldViewProj"];
_hueCountParam = Parameters["HueCount"];
_virtualLayerFillColorParam = Parameters["VirtualLayerFillColor"];
_virtualLayerBorderColorParam = Parameters["VirtualLayerBorderColor"];
}

protected override void OnApply()
{
_worldViewProjParam.SetValue(_worldViewProj);
_hueCountParam.SetValue(_hueCount);
_virtualLayerFillColorParam.SetValue(_virtualLayerFillColor);
_virtualLayerBorderColorParam.SetValue(_virtualLayerBorderColor);
}
Expand Down
11 changes: 7 additions & 4 deletions CentrED/Renderer/Effects/Shaders/MapEffect.fx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define HUED 1
#define PARTIAL 2

static const float HuesPerTexture = 3000;
static const float TileSize = 31.11;

sampler TextureSampler : register(s0);
Expand All @@ -12,7 +11,11 @@ cbuffer ProjectionMatrix : register(b0) {
float4x4 WorldViewProj;
};

cbuffer VirtualLayer : register(b1) {
cbuffer Hues : register(b1) {
int HueCount;
}

cbuffer VirtualLayer : register(b2) {
float4 VirtualLayerFillColor;
float4 VirtualLayerBorderColor;
};
Expand Down Expand Up @@ -71,7 +74,7 @@ float4 TerrainPSMain(TerrainPSInput pin) : SV_Target0

if (mode == HUED || (mode == PARTIAL && color.r == color.g && color.r == color.b))
{
float2 hueCoord = float2(color.r, pin.HueCoord.x / HuesPerTexture);
float2 hueCoord = float2(color.r, pin.HueCoord.x / HueCount);
color.rgb = tex2D(HueSampler, hueCoord).rgb;
}

Expand Down Expand Up @@ -122,7 +125,7 @@ float4 StaticsPSMain(StaticsPSInput pin) : SV_Target0

if (mode == HUED || (mode == PARTIAL && color.r == color.g && color.r == color.b))
{
float2 hueCoord = float2(color.r, pin.HueCoord.x / HuesPerTexture);
float2 hueCoord = float2(color.r, pin.HueCoord.x / HueCount);
color.rgb = tex2D(HueSampler, hueCoord).rgb;
}

Expand Down
Binary file modified CentrED/Renderer/Effects/Shaders/MapEffect.fxc
Binary file not shown.

0 comments on commit 3d42e5b

Please sign in to comment.