Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source.Common/MaterialSystem/ITextureInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static ReadOnlySpan<char> NormalizeTextureName(ReadOnlySpan<char> name, S
void Bind(Sampler sampler, int frame);
int GetTextureHandle(int frame, int textureChannel = 0);
void OnRestore();
void SetFilteringAndClampingMode(bool onlyLodValues = false);
void Precache();
bool SetRenderTarget(int rt, ITexture? depthTexture = null);
void CopyFrameBufferToMe(int renderTargetID = 0, Rectangle? srcRect = null, Rectangle? dstRect = null);
Expand Down Expand Up @@ -77,6 +78,7 @@ public void Dispose() { }
public void Bind(Sampler sampler, int frame) => throw new NotSupportedException();
public int GetTextureHandle(int v) => throw new NotSupportedException();
public void OnRestore() => throw new NotSupportedException();
public void SetFilteringAndClampingMode(bool onlyLodValues = false) => throw new NotSupportedException();
public void Precache() => throw new NotSupportedException();
public bool SetRenderTarget(int rt, ITexture? depthTexture = null) => throw new NotSupportedException();
public void GetReflectivity(out Vector3 reflectivity) => throw new NotSupportedException();
Expand Down
2 changes: 1 addition & 1 deletion Source.Engine/MatSysInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ static void mat_savechanges(in TokenizedCommand args) {
WriteMaterialSystemConfigToRegistry(MaterialSystemConfig);
}

static void UpdateMaterialSystemConfig() {
internal static void UpdateMaterialSystemConfig() {
if (host_state.WorldBrush != null && host_state.WorldBrush.LightData?.Length == 0)
mat_fullbright.SetValue(1);

Expand Down
2 changes: 2 additions & 0 deletions Source.Engine/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ public void LevelInit() {
g_ShadowMgr.LevelInit(host_state.WorldBrush!.NumSurfaces);
}

UpdateMaterialSystemConfig();

LoadWorldGeometry();

Surface_LevelInit();
Expand Down
12 changes: 6 additions & 6 deletions Source.MaterialSystem/MaterialSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public class MaterialSystem : IMaterialSystemInternal, IShaderUtil

readonly static ConVar mat_vsync = new("mat_vsync", "0", 0, "Force sync to vertical retrace", 0, 1);
readonly static ConVar mat_forcehardwaresync = new(IsPC() ? "1" : "0", 0);
readonly static ConVar mat_trilinear = new("0", 0);
readonly static ConVar mat_forceaniso = new("1", FCvar.Archive); // 0 = Bilinear, 1 = Trilinear, 2+ = Aniso
readonly static ConVar mat_trilinear = new("1", 0);
readonly static ConVar mat_forceaniso = new("16", FCvar.Archive); // 0 = Bilinear, 1 = Trilinear, 2+ = Aniso
readonly static ConVar mat_filterlightmaps = new("1", 0);
readonly static ConVar mat_filtertextures = new("1", 0);
readonly static ConVar mat_mipmaptextures = new("1", 0);
Expand Down Expand Up @@ -303,23 +303,23 @@ public bool OverrideConfig(MaterialSystem_Config config, bool forceUpdate) {
if (reloadMaterials)
ReloadMaterials();

if (resetAnisotropy)
ShaderAPI.SetAnisotropicLevel(config.ForceAnisotropicLevel);

if (redownloadTextures) {
if (ShaderAPI.CanDownloadTextures()) {
TextureSystem.RestoreRenderTargets();
TextureSystem.RestoreNonRenderTargetTextures();
}
}
else if (resetTextureFilter) {
// TextureSystem.ResetTextureFilteringState();
TextureSystem.ResetTextureFilteringState();
}

// Recompute all state snapshots
if (recomputeSnapshots)
RecomputeAllStateSnapshots();

// if (resetAnisotropy)
// ShaderAPI.SetAnisotropicLevel(config.ForceAnisotropicLevel);

// if (setStandardVertexShaderConstants)
// ShaderAPI.SetStandardVertexShaderConstants(IMaterialSystem.OVERBRIGHT);

Expand Down
2 changes: 1 addition & 1 deletion Source.MaterialSystem/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ private void DownloadTexture(Rectangle rect, bool copyFromCurrent = false) {
ActualDimensionLimit = DesiredDimensionLimit;
}

private void SetFilteringAndClampingMode(bool onlyLodValues = false) {
public void SetFilteringAndClampingMode(bool onlyLodValues = false) {
if (!HasBeenAllocated())
return;

Expand Down
5 changes: 5 additions & 0 deletions Source.MaterialSystem/TextureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ internal void RestoreNonRenderTargetTextures() {
RestoreTexture(tex.Value);
}

internal void ResetTextureFilteringState() {
foreach (var tex in TextureList)
tex.Value.SetFilteringAndClampingMode();
}

internal void AllocateStandardRenderTargets() {
MaterialSystem.BeginRenderTargetAllocation();
MaterialSystem.EndRenderTargetAllocation();
Expand Down
13 changes: 9 additions & 4 deletions Source.ShaderAPI.Gl46/ShaderAPIGl46.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ unsafe void ApplyForcedFilter(Sampler sampler, ShaderAPITextureHandle_t textureH
glSamplerParameteri(samplerObject, GL_TEXTURE_MIN_FILTER, mipped ? GL_NEAREST_MIPMAP_LINEAR : GL_NEAREST);
break;
case 3:
glSamplerParameterf(samplerObject, GL_TEXTURE_MAX_ANISOTROPY, HardwareConfig.MaximumAnisotropicLevel());
glSamplerParameterf(samplerObject, GL_TEXTURE_MAX_ANISOTROPY, AnisotropicLevel);
glSamplerParameteri(samplerObject, GL_TEXTURE_MIN_FILTER, mipped ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
break;
default:
Expand Down Expand Up @@ -2640,7 +2640,7 @@ public void TexMinFilter(TexFilterMode mode) {
glTextureParameteri(GetModifyTexture(), GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
break;
case TexFilterMode.Anisotropic:
glTextureParameterf(GetModifyTexture(), GL_TEXTURE_MAX_ANISOTROPY, HardwareConfig.MaximumAnisotropicLevel());
glTextureParameterf(GetModifyTexture(), GL_TEXTURE_MAX_ANISOTROPY, AnisotropicLevel);
glTextureParameteri(GetModifyTexture(), GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
break;
default:
Expand Down Expand Up @@ -2670,7 +2670,7 @@ public void TexMagFilter(TexFilterMode mode) {
break;
case TexFilterMode.Anisotropic:
glTextureParameteri(GetModifyTexture(), GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTextureParameterf(GetModifyTexture(), GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f);
glTextureParameterf(GetModifyTexture(), GL_TEXTURE_MAX_ANISOTROPY_EXT, AnisotropicLevel);
break;
default:
break;
Expand Down Expand Up @@ -3251,8 +3251,13 @@ public int SelectionMode(bool selectionMode) {
throw new NotImplementedException("Incomplete port of IShaderAPI");
}

int AnisotropicLevel = 1;
public void SetAnisotropicLevel(int anisotropyLevel) {
throw new NotImplementedException("Incomplete port of IShaderAPI");
int maxAnisotropy = HardwareConfig.MaximumAnisotropicLevel();
if (anisotropyLevel > maxAnisotropy || anisotropyLevel <= 1)
anisotropyLevel = Math.Max(2, Math.Min(8, maxAnisotropy / 4));

AnisotropicLevel = anisotropyLevel;
}

public void SetClipPlane(int index, ReadOnlySpan<float> plane) {
Expand Down
Loading