Adaug proiectul Unity

This commit is contained in:
2026-11-01 23:39:55 +02:00
parent cb14d9d37d
commit 863eac8f2c
23463 changed files with 5412601 additions and 0 deletions
@@ -0,0 +1,13 @@
//-----------------------------------------------------------------------
// Author: Colby-O
// File: PSXDitherDisplayMode.cs
//-----------------------------------------------------------------------
namespace ColbyO.VNTG.PSX
{
public enum PSXDitherDisplayMode
{
AbsoluteScale,
RelativeScale,
PixelResolutionRelative
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: edb8add44469b6444a8ac439b78966db
@@ -0,0 +1,28 @@
//-----------------------------------------------------------------------
// Author: Colby-O
// File: PSXDitherMode.cs
//-----------------------------------------------------------------------
namespace ColbyO.VNTG.PSX
{
/// <summary>
/// Defines the dithering method used to reduce color banding and simulate higher bit-depth.
/// </summary>
public enum PSXDitherMode
{
/// <summary>
/// Dithering is applied based on the overall brightness of the scene.
/// </summary>
MultiplicativeLuminance = 0,
/// <summary>
/// Dithering is applied per color channel.
/// </summary>
MultiplicativeChannel = 1,
/// <summary>
/// Dithering shifts pixel values based on the dither pattern and color precision.
/// </summary>
Additive = 2
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5bdc231b70f81194994a50dad6bd74f3
@@ -0,0 +1,83 @@
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
//-----------------------------------------------------------------------
// Author: Colby-O
// File: PSXEffectFeature.cs
//-----------------------------------------------------------------------
namespace ColbyO.VNTG.PSX
{
public sealed class PSXEffectFeature : ScriptableRendererFeature
{
[Header("Settings")]
[SerializeField] private RenderPassEvent _renderEvent = RenderPassEvent.BeforeRenderingPostProcessing;
private Shader _psxEffectShader;
private Material _material;
private PSXEffectPass _psxEffectPass;
private PSXSetGlobalParamters _psxSetGlobalParamtersPass;
public override void Create()
{
if (_psxEffectShader == null)
_psxEffectShader = Shader.Find("Hidden/PSXMaster_URP");
if (_material == null)
_material = CoreUtils.CreateEngineMaterial(_psxEffectShader);
_psxSetGlobalParamtersPass ??= new PSXSetGlobalParamters()
{
renderPassEvent = RenderPassEvent.BeforeRendering
};
_psxEffectPass ??= new PSXEffectPass(_material)
{
renderPassEvent = _renderEvent
};
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
if (_material == null || _psxEffectPass == null)
{
Debug.LogWarning("PSX Feature missing material or pass.");
return;
}
VolumeStack stack = VolumeManager.instance.stack;
PSXEffectSettings settings = stack.GetComponent<PSXEffectSettings>();
bool isGameCamera = renderingData.cameraData.cameraType == CameraType.Game;
bool isSceneView = renderingData.cameraData.cameraType == CameraType.SceneView && settings.ShowInSceneView.value;
bool isActive = settings != null && settings.IsActive() && (isGameCamera || isSceneView);
if (isActive)
{
_psxSetGlobalParamtersPass.Setup(settings.AmbientColor.value);
_psxEffectPass.Setup(_material);
renderer.EnqueuePass(_psxSetGlobalParamtersPass);
renderer.EnqueuePass(_psxEffectPass);
}
else
{
_psxSetGlobalParamtersPass.Setup(Color.black);
renderer.EnqueuePass(_psxSetGlobalParamtersPass);
}
}
protected override void Dispose(bool disposing)
{
if (_material != null)
{
CoreUtils.Destroy(_material);
_material = null;
}
base.Dispose(disposing);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d78b87ba4758e164e9444bb6e1f0caab
@@ -0,0 +1,161 @@
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.RenderGraphModule;
using UnityEngine.Rendering.Universal;
//-----------------------------------------------------------------------
// Author: Colby-O
// File: PSXEffectPass.cs
//-----------------------------------------------------------------------
namespace ColbyO.VNTG.PSX
{
public class PSXEffectPass : ScriptableRenderPass
{
private const string _passName = "PSXEffectPass";
private Material _material;
public PSXEffectPass(Material mat)
{
_material = mat;
requiresIntermediateTexture = true;
RenderPipelineManager.beginCameraRendering += OnBeginCameraRendering;
}
~PSXEffectPass()
{
RenderPipelineManager.beginCameraRendering -= OnBeginCameraRendering;
}
public void Setup(Material material)
{
_material = material;
}
private void OnBeginCameraRendering(ScriptableRenderContext context, Camera camera)
{
VolumeStack stack = VolumeManager.instance.stack;
PSXEffectSettings settings = stack.GetComponent<PSXEffectSettings>();
if (camera.cameraType == CameraType.Game || (settings.ShowInSceneView.value && camera.cameraType == CameraType.SceneView))
{
if (settings != null && settings.IsActive() && settings.EnablePixelation.value && settings.EnableLetterbox.value)
{
if (settings.PixelResolution.value.y > 0)
{
float targetAspect = settings.PixelResolution.value.x / settings.PixelResolution.value.y;
camera.projectionMatrix = Matrix4x4.Perspective(
camera.fieldOfView,
targetAspect,
camera.nearClipPlane,
camera.farClipPlane
);
}
}
else
{
camera.ResetProjectionMatrix();
}
}
}
private void UpdateMaterialWithSettings(Material material, PSXEffectSettings settings, Vector2 screenParams)
{
material.SetVector("_VNTGScreenParams", screenParams);
material.SetFloat("_EnablePixelation", settings.EnablePixelation.value ? 1 : 0);
material.SetFloat("_EnableLetterbox", settings.EnableLetterbox.value ? 1 : 0);
material.SetVector("_PixelResolution",
new Vector2(
Mathf.Max(1, settings.PixelResolution.value.x),
Mathf.Max(1, settings.PixelResolution.value.y)
)
);
material.SetFloat("_EnableColorPrecision", (settings.EnableColorPrecision.value) ? 1 : 0);
material.SetFloat("_ColorPrecision", settings.ColorPrecision.value);
material.SetFloat("_EnableDither", (settings.EnableDither.value) ? 1 : 0);
material.SetFloat("_DitherMode", (int)settings.DitherMode.value);
material.SetInt("_DitherPattern", settings.DitherPattern.value);
material.SetFloat("_DitherPixelPerfect", settings.DitherDisplayMode.value == PSXDitherDisplayMode.PixelResolutionRelative ? 1 : 0);
material.SetFloat("_DitherRelativeScale", settings.DitherDisplayMode.value == PSXDitherDisplayMode.RelativeScale ? 1 : 0);
material.SetVector("_DitherReferenceResolution", settings.DitherReferenceRes.value);
material.SetFloat("_DitherScale", Mathf.Lerp(1, 50, settings.DitherScale.value));
material.SetFloat("_DitherThreshold", settings.DitherThreshold.value);
material.SetInt("_EnableFog", (settings.EnableFog.value) ? 1 : 0);
material.SetFloat("_IgnoreSkybox", (settings.IgnoreSkybox.value) ? 1 : 0);
material.SetColor("_FogColor", settings.FogColor.value);
material.SetFloat("_FogDensity", settings.FogDensity.value);
material.SetFloat("_FogEdgeSmoothness", settings.FogEdgeSmoothness.value);
material.SetFloat("_FogNoiseStrength", settings.FogNoiseStrength.value);
material.SetFloat("_FogNoiseScale", Mathf.Lerp(1f, 10f, settings.FogNoiseScale.value));
material.SetFloat("_FogNoiseStart", Mathf.Lerp(0f, 100f, settings.FogNoiseStart.value));
bool usePalette = settings.EnableColorPalette.value;
material.SetFloat("_EnablePalette", (usePalette && settings.PaletteAsset.value != null) ? 1f : 0f);
material.SetFloat("_PaletteNormalizeLuminance", settings.NormalizeLuminanceBeforeSampling.value ? 1f : 0f);
material.SetFloat("_PreserveLighting", settings.PreserveLighting.value ? 1f : 0f);
if (usePalette && settings.PaletteAsset.value != null && settings.PaletteAsset.value.LUT != null)
{
material.SetTexture("_PaletteLUT", settings.PaletteAsset.value.LUT);
}
}
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
{
VolumeStack stack = VolumeManager.instance.stack;
PSXEffectSettings settings = stack.GetComponent<PSXEffectSettings>();
if (settings == null || !settings.IsActive()) return;
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
if (resourceData.isActiveTargetBackBuffer)
{
Debug.LogError("Skipping render pass. PSX Effect render requries an intermediate ColorTexture.");
return;
}
TextureHandle src = resourceData.activeColorTexture;
TextureDesc dstDesc = renderGraph.GetTextureDesc(src);
dstDesc.filterMode = FilterMode.Point;
dstDesc.width = Screen.width;
dstDesc.height = Screen.height;
dstDesc.name = _passName;
TextureHandle dst = renderGraph.CreateTexture(dstDesc);
Vector2 screenParams = new Vector2(Screen.width, Screen.height);
using (IRasterRenderGraphBuilder builder = renderGraph.AddRasterRenderPass(_passName, out PassData passData))
{
passData.src = src;
passData.material = _material;
passData.settings = settings;
passData.screenParams = screenParams;
builder.UseTexture(passData.src, AccessFlags.Read);
builder.SetRenderAttachment(dst, 0, AccessFlags.Write);
builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
{
UpdateMaterialWithSettings(data.material, data.settings, data.screenParams);
Blitter.BlitTexture(context.cmd, data.src, new Vector4(1, 1, 0, 0), data.material, 0);
});
}
resourceData.cameraColor = dst;
}
private class PassData
{
public TextureHandle src;
public Material material;
public PSXEffectSettings settings;
public Vector2 screenParams;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9a14be33ec178e548856d0fa3939a7be
@@ -0,0 +1,94 @@
using UnityEngine;
using UnityEngine.Rendering;
using ColbyO.VNTG.ColorPalette;
//-----------------------------------------------------------------------
// Author: Colby-O
// File: PSXEffectSettings.cs
//-----------------------------------------------------------------------
namespace ColbyO.VNTG.PSX
{
[System.Serializable, VolumeComponentMenu("VNTG/PSX Effect Settings")]
public class PSXEffectSettings : VolumeComponent, IPostProcessComponent
{
// Settings
public BoolParameter Enabled = new BoolParameter(true, overrideState: true);
public BoolParameter ShowInSceneView = new BoolParameter(false, overrideState: true);
// Lighting
public ColorParameter AmbientColor = new ColorParameter(Color.black, overrideState: true);
// Pixelation
public BoolParameter EnablePixelation = new BoolParameter(true, overrideState: true);
public BoolParameter EnableLetterbox = new BoolParameter(false, overrideState: true);
public Vector2Parameter PixelResolution = new Vector2Parameter(new Vector2(256.0f, 256.0f), overrideState: true);
// Color Precision
public BoolParameter EnableColorPrecision = new BoolParameter(true, overrideState: true);
public ClampedFloatParameter ColorPrecision = new ClampedFloatParameter(32f, 1f, 256f, overrideState: true);
// Dither
public BoolParameter EnableDither = new BoolParameter(true);
public EnumParameter<PSXDitherMode> DitherMode = new EnumParameter<PSXDitherMode>(PSXDitherMode.Additive, overrideState: true);
public ClampedIntParameter DitherPattern = new ClampedIntParameter(1, 0, 10, overrideState: true);
public EnumParameter<PSXDitherDisplayMode> DitherDisplayMode = new EnumParameter<PSXDitherDisplayMode>(PSXDitherDisplayMode.AbsoluteScale, overrideState: true);
public Vector2Parameter DitherReferenceRes = new Vector2Parameter(new Vector2(1920, 1080), overrideState: true);
public ClampedFloatParameter DitherScale = new ClampedFloatParameter(0.2f, 0f, 1f, overrideState: true);
public ClampedFloatParameter DitherThreshold = new ClampedFloatParameter(0.1f, 0f, 1f, overrideState: true);
// Color Palette
public BoolParameter EnableColorPalette = new BoolParameter(false, overrideState: true);
public BoolParameter PreserveLighting = new BoolParameter(false, overrideState: true);
public BoolParameter NormalizeLuminanceBeforeSampling = new BoolParameter(false, overrideState: true);
public PaletteAssetParameter PaletteAsset = new PaletteAssetParameter(null, overrideState: true);
// Fog
public BoolParameter EnableFog = new BoolParameter(false, overrideState: true);
public BoolParameter IgnoreSkybox = new BoolParameter(false, overrideState: true);
public ColorParameter FogColor = new ColorParameter(Color.black, overrideState: true);
public ClampedFloatParameter FogDensity = new ClampedFloatParameter(1.0f, 0.0f, 1.0f, overrideState: true);
public ClampedFloatParameter FogNoiseStrength = new ClampedFloatParameter(0.1f, 0.0f, 1.0f, overrideState: true);
public ClampedFloatParameter FogEdgeSmoothness = new ClampedFloatParameter(0.5f, 0.01f, 1.0f, overrideState: true);
public ClampedFloatParameter FogNoiseScale = new ClampedFloatParameter(0.5f, 0f, 1f, overrideState: true);
public ClampedFloatParameter FogNoiseStart = new ClampedFloatParameter(0.7f, 0f, 1f, overrideState: true);
public bool IsActive() => Enabled.value;
public bool IsTileCompatible() => false;
private void OnValidate()
{
if (Enabled != null) Enabled.overrideState = true;
if (ShowInSceneView != null) ShowInSceneView.overrideState = true;
if (EnablePixelation != null) EnablePixelation.overrideState = true;
if (EnableLetterbox != null) EnableLetterbox.overrideState = true;
if (PixelResolution != null) PixelResolution.overrideState = true;
if (EnableColorPrecision != null) EnableColorPrecision.overrideState = true;
if (ColorPrecision != null) ColorPrecision.overrideState = true;
if (EnableDither != null) EnableDither.overrideState = true;
if (DitherMode != null) DitherMode.overrideState = true;
if (DitherPattern != null) DitherPattern.overrideState = true;
if (DitherDisplayMode != null) DitherDisplayMode.overrideState = true;
if (DitherReferenceRes != null) DitherReferenceRes.overrideState = true;
if (DitherScale != null) DitherScale.overrideState = true;
if (DitherThreshold != null) DitherThreshold.overrideState = true;
if (EnableColorPalette != null) EnableColorPalette.overrideState = true;
if (PreserveLighting != null) PreserveLighting.overrideState = true;
if (NormalizeLuminanceBeforeSampling != null) NormalizeLuminanceBeforeSampling.overrideState = true;
if (PaletteAsset != null) PaletteAsset.overrideState = true;
if (EnableFog != null) EnableFog.overrideState = true;
if (IgnoreSkybox != null) IgnoreSkybox.overrideState = true;
if (FogColor != null) FogColor.overrideState = true;
if (FogDensity != null) FogDensity.overrideState = true;
if (FogNoiseStrength != null) FogNoiseStrength.overrideState = true;
if (FogEdgeSmoothness != null) FogEdgeSmoothness.overrideState = true;
if (FogNoiseScale != null) FogNoiseScale.overrideState = true;
if (FogNoiseStart != null) FogNoiseStart.overrideState = true;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6dbed17f5f145d64589ad7ae3c637fc3
@@ -0,0 +1,98 @@
using UnityEngine;
//-----------------------------------------------------------------------
// Author: Colby-O
// File: PSXMaterialExtensions.cs
//-----------------------------------------------------------------------
namespace ColbyO.VNTG.PSX
{
public enum PSXTextureSampleMode { Point = 0, Bilinear = 1, N64 = 2 }
public enum PSXLightingMethod { Unlit = 0, Lit = 1, TexelLit = 2, VertexLit = 3 }
public enum PSXVertexJitterMode { Disabled = 0, ViewSpace = 1, ScreenSpace = 2 }
public enum DitherMode { Full, TextureRelative }
public enum PSXShadingMode { Default = 0, Flat = 1 }
public enum SkyboxMode { Cubemap = 0, Panoramic = 1, Procedual = 2 }
public enum ProcedualSkyboxMode { FlatGradient = 0, Space = 1 }
public static class PSXMaterialExtensions
{
private static readonly int TextureSampleModeID = Shader.PropertyToID("_TEXTURESAMPLEMODE");
private static readonly int LightingMethodID = Shader.PropertyToID("_LIGHTINGMETHOD");
private static readonly int VertexJitterModeID = Shader.PropertyToID("_VERTEXJITTERMODE");
private static readonly int DitherModeID = Shader.PropertyToID("_DITHERINGMETHOD");
private static readonly int SkyboxModeID = Shader.PropertyToID("_SKYBOXMODE");
private static readonly int ProcedualSkyboxModeID = Shader.PropertyToID("_PROCEDUALSKYBOXMODE");
public static void SetTextureSampleMode(this Material mat, PSXTextureSampleMode mode)
{
if (mat == null) return;
mat.SetFloat(TextureSampleModeID, (float)mode);
}
public static void SetLightingMethod(this Material mat, PSXLightingMethod method)
{
if (mat == null) return;
mat.SetFloat(LightingMethodID, (float)method);
}
public static void SetVertexJitterMode(this Material mat, PSXVertexJitterMode mode)
{
if (mat == null) return;
mat.SetFloat(VertexJitterModeID, (float)mode);
}
public static void SetDitherMode(this Material mat, DitherMode mode)
{
if (mat == null) return;
mat.SetFloat(DitherModeID, (float)mode);
}
public static void SetSkyboxMode(this Material mat, SkyboxMode mode)
{
if (mat == null) return;
mat.SetFloat(SkyboxModeID, (float)mode);
}
public static void SetProcedualSkyboxMode(this Material mat, ProcedualSkyboxMode mode)
{
if (mat == null) return;
mat.SetFloat(ProcedualSkyboxModeID, (float)mode);
}
public static PSXTextureSampleMode GetTextureSampleMode(this Material mat)
{
if (mat == null) return PSXTextureSampleMode.Point;
return (PSXTextureSampleMode)mat.GetFloat(TextureSampleModeID);
}
public static PSXLightingMethod GetLightingMethod(this Material mat)
{
if (mat == null) return PSXLightingMethod.Unlit;
return (PSXLightingMethod)mat.GetFloat(LightingMethodID);
}
public static PSXVertexJitterMode GetVertexJitterMode(this Material mat)
{
if (mat == null) return PSXVertexJitterMode.Disabled;
return (PSXVertexJitterMode)mat.GetFloat(VertexJitterModeID);
}
public static DitherMode GetDitherMode(this Material mat)
{
if (mat == null) return DitherMode.Full;
return (DitherMode)mat.GetFloat(DitherModeID);
}
public static SkyboxMode GetSkybox(this Material mat)
{
if (mat == null) return SkyboxMode.Procedual;
return (SkyboxMode)mat.GetFloat(SkyboxModeID);
}
public static ProcedualSkyboxMode GetProcedualSkyboxMode(this Material mat)
{
if (mat == null) return ProcedualSkyboxMode.FlatGradient;
return (ProcedualSkyboxMode)mat.GetFloat(ProcedualSkyboxModeID);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3c09357ab41cb354e8db7eb41238cbce
@@ -0,0 +1,35 @@
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.RenderGraphModule;
using UnityEngine.Rendering.Universal;
//-----------------------------------------------------------------------
// Author: Colby-O
// File: PSXEffectPass.cs
//-----------------------------------------------------------------------
namespace ColbyO.VNTG.PSX
{
public class PSXSetGlobalParamters : ScriptableRenderPass
{
private static readonly int AmbientColorID = Shader.PropertyToID("_VNTGAmbientColor");
private const string _passName = "PSXSetGlobalParamters";
private Color _ambientColor;
public PSXSetGlobalParamters()
{
requiresIntermediateTexture = true;
}
public void Setup(Color color)
{
_ambientColor = color;
}
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
{
Shader.SetGlobalColor(AmbientColorID, _ambientColor);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 78f4cfc4767fa3c46b02681289d215c6