Flatkit 추가 및 설정

This commit is contained in:
2026-01-25 11:27:33 +09:00
parent 05233497e7
commit cf16910a32
1938 changed files with 408633 additions and 244 deletions

View File

@@ -0,0 +1,92 @@
using ExternPropertyAttributes;
using UnityEngine;
using UnityEngine.Rendering.Universal;
namespace FlatKit {
public class FlatKitPixelation : ScriptableRendererFeature {
[Expandable]
[Tooltip("To create new settings use 'Create > FlatKit > Pixelation Settings'.")]
public PixelationSettings settings;
private Material _effectMaterial;
private ScreenRenderPass _fullScreenPass;
private bool _requiresColor;
private bool _injectedBeforeTransparents;
private ScriptableRenderPassInput _requirements = ScriptableRenderPassInput.Color;
private const string ShaderName = "Hidden/FlatKit/PixelationWrap";
private static int pixelSizeProperty => Shader.PropertyToID("_PixelSize");
/// <summary>
/// Access the runtime effect material to override pixelation parameters at runtime
/// without mutating the Settings asset.
///
/// Shader: "Hidden/FlatKit/PixelationWrap"
///
/// Common shader properties:
/// - Floats: _PixelSize (computed as 1 / resolution by default)
///
/// Note: Inspector changes on the Settings asset may overwrite your values if applied later.
/// </summary>
public Material EffectMaterial => _effectMaterial;
public override void Create() {
// Settings.
{
if (settings == null) return;
settings.onSettingsChanged = null;
settings.onReset = null;
settings.onSettingsChanged += SetMaterialProperties;
settings.onReset += SetMaterialProperties;
}
// Material.
{
#if UNITY_EDITOR
settings.effectMaterial = SubAssetMaterial.GetOrCreate(settings, ShaderName);
if (settings.effectMaterial == null) return;
#endif
_effectMaterial = settings.effectMaterial;
SetMaterialProperties();
}
{
_fullScreenPass = new ScreenRenderPass {
renderPassEvent = settings.renderEvent,
};
_requirements = ScriptableRenderPassInput.Color;
ScriptableRenderPassInput modifiedRequirements = _requirements;
_requiresColor = (_requirements & ScriptableRenderPassInput.Color) != 0;
_injectedBeforeTransparents = settings.renderEvent <= RenderPassEvent.BeforeRenderingTransparents;
if (_requiresColor && !_injectedBeforeTransparents) {
modifiedRequirements ^= ScriptableRenderPassInput.Color;
}
_fullScreenPass.ConfigureInput(modifiedRequirements);
}
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) {
if (settings == null || !settings.applyInSceneView && renderingData.cameraData.isSceneViewCamera) return;
if (renderingData.cameraData.isPreviewCamera) return;
if (_effectMaterial == null) return;
_fullScreenPass.Setup(_effectMaterial, _requiresColor, _injectedBeforeTransparents, "Flat Kit Pixelation",
renderingData);
renderer.EnqueuePass(_fullScreenPass);
}
protected override void Dispose(bool disposing) {
_fullScreenPass?.Dispose();
}
private void SetMaterialProperties() {
if (_effectMaterial == null) return;
var pixelSize = Mathf.Max(1f / settings.resolution, 0.0001f);
_effectMaterial.SetFloat(pixelSizeProperty, pixelSize);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: edb250ac097f481fa89c38a1e224b773
timeCreated: 1697581791

View File

@@ -0,0 +1,25 @@
#ifndef FLAT_KIT_PIXELATION_INCLUDED
#define FLAT_KIT_PIXELATION_INCLUDED
TEXTURE2D_X (_BlitTexture);
SAMPLER (sampler_BlitTexture);
float4 SampleCameraColor(float2 uv)
{
// Using sampler_PointClamp instead of sampler_BlitTexture to avoid bilinear filtering.
return SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_PointClamp, UnityStereoTransformScreenSpaceTex(uv));
}
void Pixelation_float(float2 UV, out float4 Out)
{
float longerScreenSizePixelSize = _PixelSize;
float aspectRatio = _ScreenParams.x / _ScreenParams.y;
float2 pixelSize = aspectRatio > 1
? float2(longerScreenSizePixelSize, longerScreenSizePixelSize * aspectRatio)
: float2(longerScreenSizePixelSize / aspectRatio, longerScreenSizePixelSize);
float2 uv = UV / pixelSize;
uv = floor(uv);
uv *= pixelSize;
Out = SampleCameraColor(uv);
}
#endif // FLAT_KIT_PIXELATION_INCLUDED

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d00436b1cf7a4c7c8cb42e8f0bc826c9
timeCreated: 1697581791

View File

@@ -0,0 +1,52 @@
using System;
using ExternPropertyAttributes;
using UnityEngine;
using UnityEngine.Rendering.Universal;
// ReSharper disable RedundantDefaultMemberInitializer
namespace FlatKit {
[CreateAssetMenu(fileName = "PixelationSettings", menuName = "FlatKit/Pixelation Settings")]
public class PixelationSettings : ScriptableObject {
[Space] // Expandable.
#if !UNITY_2022_3_OR_NEWER
[ExternPropertyAttributes.InfoBox(
"Pixelation Effect requires Unity 2022.3 or newer. Please upgrade your Unity version to use this feature.",
ExternPropertyAttributes.EInfoBoxType.Warning)]
[Space]
#endif
[Tooltip("The number of pixels on the longer side of the screen.\nLower values result in a more pixelated image.")]
[Min(0)]
public int resolution = 320;
[HorizontalLine(1, EColor.Translucent)]
[Tooltip("The render stage at which the effect is applied. To exclude transparent objects, like water or " +
"UI elements, set this to \"Before Transparent\".")]
public RenderPassEvent renderEvent = RenderPassEvent.BeforeRenderingPostProcessing;
[Tooltip("Whether the effect should be applied in the Scene view as well as in the Game view. Please keep in " +
"mind that Unity always renders the scene view with the default Renderer settings of the URP config.")]
public bool applyInSceneView = true;
[HideInInspector]
public Material effectMaterial;
internal Action onSettingsChanged;
internal Action onReset;
private void OnValidate() {
onSettingsChanged?.Invoke();
}
private void Reset() {
onReset?.Invoke();
}
private void OnDestroy() {
onSettingsChanged = null;
onReset = null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6bf7a6fd37ee46709aa013efc3270aba
timeCreated: 1697581791

View File

@@ -0,0 +1,625 @@
{
"m_SGVersion": 3,
"m_Type": "UnityEditor.ShaderGraph.GraphData",
"m_ObjectId": "1c91f7928335480e8da474fcedfb1646",
"m_Properties": [
{
"m_Id": "120c814773e946579675f32587651895"
}
],
"m_Keywords": [],
"m_Dropdowns": [],
"m_CategoryData": [
{
"m_Id": "9b7a3cf03dd848d99086a26aaeb3b30d"
}
],
"m_Nodes": [
{
"m_Id": "124549f5950643a09e2f87c4f74e9dd6"
},
{
"m_Id": "ca0fa6ce4dd049e6b3c0102f58e9831a"
},
{
"m_Id": "92980b70b95c486e84565917adbcdffd"
},
{
"m_Id": "1f9b5fa558dd414f8295a949f5f566b6"
},
{
"m_Id": "32f3a6d7f0d1419d9ad654a50f5ac295"
}
],
"m_GroupDatas": [],
"m_StickyNoteDatas": [],
"m_Edges": [
{
"m_OutputSlot": {
"m_Node": {
"m_Id": "1f9b5fa558dd414f8295a949f5f566b6"
},
"m_SlotId": 0
},
"m_InputSlot": {
"m_Node": {
"m_Id": "92980b70b95c486e84565917adbcdffd"
},
"m_SlotId": 2
}
},
{
"m_OutputSlot": {
"m_Node": {
"m_Id": "32f3a6d7f0d1419d9ad654a50f5ac295"
},
"m_SlotId": 4
},
"m_InputSlot": {
"m_Node": {
"m_Id": "ca0fa6ce4dd049e6b3c0102f58e9831a"
},
"m_SlotId": 0
}
},
{
"m_OutputSlot": {
"m_Node": {
"m_Id": "92980b70b95c486e84565917adbcdffd"
},
"m_SlotId": 0
},
"m_InputSlot": {
"m_Node": {
"m_Id": "124549f5950643a09e2f87c4f74e9dd6"
},
"m_SlotId": 0
}
},
{
"m_OutputSlot": {
"m_Node": {
"m_Id": "92980b70b95c486e84565917adbcdffd"
},
"m_SlotId": 0
},
"m_InputSlot": {
"m_Node": {
"m_Id": "32f3a6d7f0d1419d9ad654a50f5ac295"
},
"m_SlotId": 0
}
}
],
"m_VertexContext": {
"m_Position": {
"x": 16.999998092651368,
"y": 32.00004196166992
},
"m_Blocks": []
},
"m_FragmentContext": {
"m_Position": {
"x": 0.0,
"y": 200.0
},
"m_Blocks": [
{
"m_Id": "124549f5950643a09e2f87c4f74e9dd6"
},
{
"m_Id": "ca0fa6ce4dd049e6b3c0102f58e9831a"
}
]
},
"m_PreviewData": {
"serializedMesh": {
"m_SerializedMesh": "{\"mesh\":{\"instanceID\":0}}",
"m_Guid": ""
},
"preventRotation": false
},
"m_Path": "Hidden/FlatKit",
"m_GraphPrecision": 1,
"m_PreviewMode": 2,
"m_OutputNode": {
"m_Id": ""
},
"m_ActiveTargets": [
{
"m_Id": "6de9888e3b9844abb410aa7f1cbe319e"
}
]
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector2MaterialSlot",
"m_ObjectId": "000c5eeb790444bd82861eb7a9d73169",
"m_Id": 2,
"m_DisplayName": "UV",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "UV",
"m_StageCapability": 3,
"m_Value": {
"x": 0.0,
"y": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0
},
"m_Labels": []
}
{
"m_SGVersion": 1,
"m_Type": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty",
"m_ObjectId": "120c814773e946579675f32587651895",
"m_Guid": {
"m_GuidSerialized": "a8445f83-acbd-4186-a4dd-9348b1dc70f6"
},
"m_Name": "Pixel Size",
"m_DefaultRefNameVersion": 1,
"m_RefNameGeneratedByDisplayName": "Pixel Size",
"m_DefaultReferenceName": "_Pixel_Size",
"m_OverrideReferenceName": "_PixelSize",
"m_GeneratePropertyBlock": true,
"m_UseCustomSlotLabel": false,
"m_CustomSlotLabel": "",
"m_DismissedVersion": 0,
"m_Precision": 0,
"overrideHLSLDeclaration": false,
"hlslDeclarationOverride": 0,
"m_Hidden": false,
"m_Value": 1.0,
"m_FloatType": 0,
"m_RangeValues": {
"x": 0.0,
"y": 5.0
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "124549f5950643a09e2f87c4f74e9dd6",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.BaseColor",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "9a7200ad60604ef09f5d67209401bf75"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.BaseColor"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.ScreenPositionNode",
"m_ObjectId": "1f9b5fa558dd414f8295a949f5f566b6",
"m_Group": {
"m_Id": ""
},
"m_Name": "Screen Position",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -563.3333129882813,
"y": 200.0,
"width": 147.3333740234375,
"height": 131.99996948242188
}
},
"m_Slots": [
{
"m_Id": "491fba181a5442c296dfffa19efd71f3"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": false,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_ScreenSpaceType": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.SplitNode",
"m_ObjectId": "32f3a6d7f0d1419d9ad654a50f5ac295",
"m_Group": {
"m_Id": ""
},
"m_Name": "Split",
"m_DrawState": {
"m_Expanded": false,
"m_Position": {
"serializedVersion": "2",
"x": -145.00001525878907,
"y": 290.9999694824219,
"width": 119.00001525878906,
"height": 77.00006103515625
}
},
"m_Slots": [
{
"m_Id": "65fcd7b0d8cf498596e96f95ef3fb267"
},
{
"m_Id": "8f3a8134e0bc4a5fa20a53b54ec8382b"
},
{
"m_Id": "6c96fb89373a455dab6a5d7e074519c6"
},
{
"m_Id": "bb92d54e4f874bd3b1186db88e7338d6"
},
{
"m_Id": "8d59403795d343e5abafa7d95650a21b"
}
],
"synonyms": [
"separate"
],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot",
"m_ObjectId": "491fba181a5442c296dfffa19efd71f3",
"m_Id": 0,
"m_DisplayName": "Out",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "Out",
"m_StageCapability": 3,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot",
"m_ObjectId": "65fcd7b0d8cf498596e96f95ef3fb267",
"m_Id": 0,
"m_DisplayName": "In",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "In",
"m_StageCapability": 3,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "6c96fb89373a455dab6a5d7e074519c6",
"m_Id": 2,
"m_DisplayName": "G",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "G",
"m_StageCapability": 3,
"m_Value": 0.0,
"m_DefaultValue": 0.0,
"m_Labels": []
}
{
"m_SGVersion": 1,
"m_Type": "UnityEditor.Rendering.Universal.ShaderGraph.UniversalTarget",
"m_ObjectId": "6de9888e3b9844abb410aa7f1cbe319e",
"m_Datas": [
{
"m_Id": "f96621e0417148329344ce08081a08aa"
}
],
"m_ActiveSubTarget": {
"m_Id": "aa590bf2e5f14b53893d161e232b1f36"
},
"m_AllowMaterialOverride": false,
"m_SurfaceType": 0,
"m_ZTestMode": 4,
"m_ZWriteControl": 0,
"m_AlphaMode": 0,
"m_RenderFace": 2,
"m_AlphaClip": false,
"m_CastShadows": true,
"m_ReceiveShadows": true,
"m_SupportsLODCrossFade": false,
"m_CustomEditorGUI": "",
"m_SupportVFX": false
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "82e211689f994de0a779d29c1ea3c1eb",
"m_Id": 0,
"m_DisplayName": "Alpha",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Alpha",
"m_StageCapability": 2,
"m_Value": 1.0,
"m_DefaultValue": 1.0,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "8d59403795d343e5abafa7d95650a21b",
"m_Id": 4,
"m_DisplayName": "A",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "A",
"m_StageCapability": 3,
"m_Value": 0.0,
"m_DefaultValue": 0.0,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "8f3a8134e0bc4a5fa20a53b54ec8382b",
"m_Id": 1,
"m_DisplayName": "R",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "R",
"m_StageCapability": 3,
"m_Value": 0.0,
"m_DefaultValue": 0.0,
"m_Labels": []
}
{
"m_SGVersion": 1,
"m_Type": "UnityEditor.ShaderGraph.CustomFunctionNode",
"m_ObjectId": "92980b70b95c486e84565917adbcdffd",
"m_Group": {
"m_Id": ""
},
"m_Name": "Pixelation (Custom Function)",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -418.66668701171877,
"y": 200.0,
"width": 211.3333740234375,
"height": 95.99996948242188
}
},
"m_Slots": [
{
"m_Id": "ac3fddfa47924bab812f39451a6ecb79"
},
{
"m_Id": "000c5eeb790444bd82861eb7a9d73169"
}
],
"synonyms": [
"code",
"HLSL"
],
"m_Precision": 0,
"m_PreviewExpanded": false,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SourceType": 0,
"m_FunctionName": "Pixelation",
"m_FunctionSource": "d00436b1cf7a4c7c8cb42e8f0bc826c9",
"m_FunctionBody": "Enter function body here..."
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot",
"m_ObjectId": "9a7200ad60604ef09f5d67209401bf75",
"m_Id": 0,
"m_DisplayName": "Base Color",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "BaseColor",
"m_StageCapability": 2,
"m_Value": {
"x": 0.5,
"y": 0.5,
"z": 0.5
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_ColorMode": 0,
"m_DefaultColor": {
"r": 0.5,
"g": 0.5,
"b": 0.5,
"a": 1.0
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.CategoryData",
"m_ObjectId": "9b7a3cf03dd848d99086a26aaeb3b30d",
"m_Name": "",
"m_ChildObjectList": [
{
"m_Id": "120c814773e946579675f32587651895"
}
]
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.Rendering.Universal.ShaderGraph.UniversalFullscreenSubTarget",
"m_ObjectId": "aa590bf2e5f14b53893d161e232b1f36"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot",
"m_ObjectId": "ac3fddfa47924bab812f39451a6ecb79",
"m_Id": 0,
"m_DisplayName": "Out",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "Out",
"m_StageCapability": 3,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "bb92d54e4f874bd3b1186db88e7338d6",
"m_Id": 3,
"m_DisplayName": "B",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "B",
"m_StageCapability": 3,
"m_Value": 0.0,
"m_DefaultValue": 0.0,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "ca0fa6ce4dd049e6b3c0102f58e9831a",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Alpha",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "82e211689f994de0a779d29c1ea3c1eb"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Alpha"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.Rendering.Fullscreen.ShaderGraph.FullscreenData",
"m_ObjectId": "f96621e0417148329344ce08081a08aa",
"m_Version": 0,
"m_fullscreenMode": 0,
"m_BlendMode": 0,
"m_SrcColorBlendMode": 0,
"m_DstColorBlendMode": 1,
"m_ColorBlendOperation": 0,
"m_SrcAlphaBlendMode": 0,
"m_DstAlphaBlendMode": 1,
"m_AlphaBlendOperation": 0,
"m_EnableStencil": false,
"m_StencilReference": 0,
"m_StencilReadMask": 255,
"m_StencilWriteMask": 255,
"m_StencilCompareFunction": 8,
"m_StencilPassOperation": 0,
"m_StencilFailOperation": 0,
"m_StencilDepthFailOperation": 0,
"m_DepthWrite": false,
"m_depthWriteMode": 0,
"m_AllowMaterialOverride": false,
"m_DepthTestMode": 0
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 6b2177cf82af36949b9a8d210c2b4962
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}