Skip to content

Commit

Permalink
renamed MatPassID
Browse files Browse the repository at this point in the history
  • Loading branch information
w1n7er87 committed Dec 14, 2023
1 parent ced1633 commit 51161b5
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 32 deletions.
12 changes: 6 additions & 6 deletions Unity/Assets/Scripts/SCHIZO/VFX/ARGCensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ARGCensor : MonoBehaviour
public float scale = 1.3f;
public float frameChangeInterval = 0.08f;

private MatPassID matPassID;
private CustomMaterialPropertyBlock propBlock;

private float lastUpdate;
private float lastRnd;
Expand All @@ -24,7 +24,7 @@ public void Awake()
{
_ = SchizoVFXStack.Instance;

matPassID = new MatPassID(effectMaterial);
propBlock = new CustomMaterialPropertyBlock(effectMaterial);

lastUpdate = Time.time;
arrayDepth = ((Texture2DArray) effectMaterial.GetTexture(_texID)).depth;
Expand All @@ -49,11 +49,11 @@ public void LateUpdate()

float opacity = Mathf.Clamp01((1f / pos.z) * fadeOutStartDistance);

matPassID.SetVector("_ScreenPosition", new Vector4(pos.x, pos.y, pos.z, lastRnd));
matPassID.SetFloat("_Strength", opacity);
matPassID.SetFloat("_Scale", scale);
propBlock.SetVector("_ScreenPosition", new Vector4(pos.x, pos.y, pos.z, lastRnd));
propBlock.SetFloat("_Strength", opacity);
propBlock.SetFloat("_Scale", scale);

SchizoVFXStack.Instance.RenderEffect(matPassID);
SchizoVFXStack.Instance.RenderEffect(propBlock);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Unity/Assets/Scripts/SCHIZO/VFX/ColorTint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class ColorTint : VFXComponent
public override void SetProperties()
{
base.SetProperties();
matPassID.SetColor("_Color", color);
matPassID.PassID = (int) blendMode;
propBlock.SetColor("_Color", color);
propBlock.PassID = (int) blendMode;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SCHIZO.VFX
/// <summary>
/// Material Properties can be set via <see cref="SetVector"/>, <see cref="SetFloat"/>, <see cref="SetColor"/>, <see cref="SetTexture"/> methods.
/// </summary>
public sealed class MatPassID(Material material)
public sealed class CustomMaterialPropertyBlock(Material material)
{
public int PassID { get; set; }

Expand Down
10 changes: 5 additions & 5 deletions Unity/Assets/Scripts/SCHIZO/VFX/ImageOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public class ImageOverlay : VFXComponent
public override void SetProperties()
{
base.SetProperties();
matPassID.PassID = (int) blendMode;
propBlock.PassID = (int) blendMode;
image.wrapMode = wrapMode;
matPassID.SetTexture("_Image", image);
matPassID.SetVector("_Position", new Vector4(position.x, position.y, 0f, 0f));
matPassID.SetFloat("_Strength", strength);
matPassID.SetFloat("_Scale", scale);
propBlock.SetTexture("_Image", image);
propBlock.SetVector("_Position", new Vector4(position.x, position.y, 0f, 0f));
propBlock.SetFloat("_Strength", strength);
propBlock.SetFloat("_Scale", scale);
}
}
}
8 changes: 4 additions & 4 deletions Unity/Assets/Scripts/SCHIZO/VFX/NoiseVignette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ private TriValidationResult ValidateNormalMap()
public override void SetProperties()
{
base.SetProperties();
matPassID.SetTexture("_Image", noiseTexture);
matPassID.SetTexture("_Displacement", displacementNormal);
matPassID.SetFloat("_DispStrength", displacementStrength);
matPassID.SetFloat("_Strength", strength);
propBlock.SetTexture("_Image", noiseTexture);
propBlock.SetTexture("_Displacement", displacementNormal);
propBlock.SetFloat("_DispStrength", displacementStrength);
propBlock.SetFloat("_Strength", strength);
}
}
}
14 changes: 7 additions & 7 deletions Unity/Assets/Scripts/SCHIZO/VFX/SchizoVFXStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ public static SchizoVFXStack Instance
}
}

private static readonly List<MatPassID> effectMaterials = [];
private static readonly List<CustomMaterialPropertyBlock> propertyBlocks = [];

public void RenderEffect(MatPassID m)
public void RenderEffect(CustomMaterialPropertyBlock m)
{
if (effectMaterials.Contains(m)) return;
effectMaterials.Add(m);
if (propertyBlocks.Contains(m)) return;
propertyBlocks.Add(m);
}

private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (effectMaterials.Count == 0)
if (propertyBlocks.Count == 0)
{
Graphics.Blit(source, destination);
return;
Expand All @@ -37,7 +37,7 @@ private void OnRenderImage(RenderTexture source, RenderTexture destination)
Graphics.CopyTexture(source, tempA);

bool startedWithA = true;
foreach (MatPassID effectMaterial in effectMaterials)
foreach (CustomMaterialPropertyBlock effectMaterial in propertyBlocks)
{
Graphics.Blit(startedWithA ? tempA : tempB, startedWithA ? tempB : tempA, effectMaterial.ApplyProperties(out int passID), passID);
startedWithA = !startedWithA;
Expand All @@ -46,6 +46,6 @@ private void OnRenderImage(RenderTexture source, RenderTexture destination)
Graphics.Blit(startedWithA ? tempA : tempB, destination);
RenderTexture.ReleaseTemporary(tempA);
RenderTexture.ReleaseTemporary(tempB);
effectMaterials.Clear();
propertyBlocks.Clear();
}
}
6 changes: 3 additions & 3 deletions Unity/Assets/Scripts/SCHIZO/VFX/TwoColorTint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class TwoColorTint : VFXComponent
public override void SetProperties()
{
base.SetProperties();
matPassID.SetColor("_Color", innerColor);
matPassID.SetColor("_Color0", outerColor);
matPassID.SetFloat("_Strength", strength);
propBlock.SetColor("_Color", innerColor);
propBlock.SetColor("_Color0", outerColor);
propBlock.SetFloat("_Strength", strength);
}
}
}
8 changes: 4 additions & 4 deletions Unity/Assets/Scripts/SCHIZO/VFX/VFXComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class VFXComponent : MonoBehaviour
// ReSharper disable once RedundantNameQualifier
[global::TriInspector.ReadOnly] public Material material;

[HideInInspector] public MatPassID matPassID;
[HideInInspector] public CustomMaterialPropertyBlock propBlock;

#if UNITY_EDITOR
[OnValueChanged(nameof(SetNewResultTexture))]
Expand All @@ -26,7 +26,7 @@ private void OnValidate()
if (previewResult == null || ((previewImage.height != previewResult.height) || (previewImage.width != previewResult.width))) SetNewResultTexture();
SetProperties();
RenderTexture tempResult = RenderTexture.GetTemporary(previewImage.width, previewImage.height, 0, RenderTextureFormat.ARGBHalf);
Graphics.Blit(previewImage, tempResult, matPassID.ApplyProperties(out int passID), passID);
Graphics.Blit(previewImage, tempResult, propBlock.ApplyProperties(out int passID), passID);
Graphics.ConvertTexture(tempResult, previewResult);
tempResult.Release();
}
Expand All @@ -40,13 +40,13 @@ private void SetNewResultTexture()

public virtual void SetProperties()
{
matPassID ??= new MatPassID(material);
propBlock ??= new CustomMaterialPropertyBlock(material);
}

public virtual void Update()
{
SetProperties();
SchizoVFXStack.Instance.RenderEffect(matPassID);
SchizoVFXStack.Instance.RenderEffect(propBlock);
}
}
}

0 comments on commit 51161b5

Please sign in to comment.