去掉不需要的 退回不该提交的 移动两个文件

main
Vinny 2025-11-13 15:26:58 +08:00
parent f4b4b3e9b3
commit 758a6eadba
11 changed files with 183 additions and 299 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,63 +0,0 @@
using System;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
/// <summary>
/// 边缘渐晕效果,支持上下左右独立控制
/// </summary>
[Serializable, VolumeComponentMenu("Post-processing/Edge Vignette")]
public sealed class EdgeVignette : VolumeComponent, IPostProcessComponent
{
/// <summary>
/// Vignette颜色
/// </summary>
[Tooltip("Vignette color.")]
public ColorParameter color = new ColorParameter(Color.black, false, false, true);
// ===== 上方 (Top) =====
[Tooltip("Vignette intensity at the top of the screen.")]
public ClampedFloatParameter intensityTop = new ClampedFloatParameter(0f, 0f, 1f);
[Tooltip("Vignette offset from top (0 = screen top, 1 = screen bottom).")]
public ClampedFloatParameter offsetTop = new ClampedFloatParameter(0f, 0f, 1f);
[Tooltip("Smoothness of the top vignette border.")]
public ClampedFloatParameter smoothnessTop = new ClampedFloatParameter(0.2f, 0.01f, 5f);
// ===== 下方 (Bottom) =====
[Tooltip("Vignette intensity at the bottom of the screen.")]
public ClampedFloatParameter intensityBottom = new ClampedFloatParameter(0f, 0f, 1f);
[Tooltip("Vignette offset from bottom (0 = screen bottom, 1 = screen top).")]
public ClampedFloatParameter offsetBottom = new ClampedFloatParameter(0f, 0f, 1f);
[Tooltip("Smoothness of the bottom vignette border.")]
public ClampedFloatParameter smoothnessBottom = new ClampedFloatParameter(0.2f, 0.01f, 5f);
// ===== 左侧 (Left) =====
[Tooltip("Vignette intensity at the left of the screen.")]
public ClampedFloatParameter intensityLeft = new ClampedFloatParameter(0f, 0f, 1f);
[Tooltip("Vignette offset from left (0 = screen left, 1 = screen right).")]
public ClampedFloatParameter offsetLeft = new ClampedFloatParameter(0f, 0f, 1f);
[Tooltip("Smoothness of the left vignette border.")]
public ClampedFloatParameter smoothnessLeft = new ClampedFloatParameter(0.2f, 0.01f, 5f);
// ===== 右侧 (Right) =====
[Tooltip("Vignette intensity at the right of the screen.")]
public ClampedFloatParameter intensityRight = new ClampedFloatParameter(0f, 0f, 1f);
[Tooltip("Vignette offset from right (0 = screen right, 1 = screen left).")]
public ClampedFloatParameter offsetRight = new ClampedFloatParameter(0f, 0f, 1f);
[Tooltip("Smoothness of the right vignette border.")]
public ClampedFloatParameter smoothnessRight = new ClampedFloatParameter(0.2f, 0.01f, 5f);
public bool IsActive() => intensityTop.value > 0f || intensityBottom.value > 0f ||
intensityLeft.value > 0f || intensityRight.value > 0f;
public bool IsTileCompatible() => true;
}

View File

@ -1,146 +0,0 @@
using Obfuz;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace AOT.PostProcess.Vignette
{
[ObfuzIgnore]
public class EdgeVignetteRPF : ScriptableRendererFeature
{
[System.Serializable]
public class Settings
{
public RenderPassEvent renderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing;
}
[ObfuzIgnore]
class CustomRenderPass : ScriptableRenderPass
{
private Settings _settings;
private Material _material;
private EdgeVignette _vignetteVolume;
private RTHandle _tempTarget;
private static readonly int VignetteColorId = Shader.PropertyToID("_VignetteColor");
private static readonly int VignetteIntensityId = Shader.PropertyToID("_VignetteIntensity");
private static readonly int VignetteOffsetId = Shader.PropertyToID("_VignetteOffset");
private static readonly int VignetteSmoothnessId = Shader.PropertyToID("_VignetteSmoothness");
public CustomRenderPass(Settings settings)
{
_settings = settings;
}
public void SetMaterial(Material material)
{
_material = material;
}
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
var descriptor = renderingData.cameraData.cameraTargetDescriptor;
descriptor.depthBufferBits = 0;
RenderingUtils.ReAllocateIfNeeded(ref _tempTarget, descriptor, FilterMode.Bilinear,
TextureWrapMode.Clamp, name: "_EdgeVignetteTempRT");
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
if (_material == null || _tempTarget == null)
return;
VolumeStack stack = VolumeManager.instance.stack;
_vignetteVolume = stack.GetComponent<EdgeVignette>();
if (_vignetteVolume == null || !_vignetteVolume.IsActive())
return;
CommandBuffer cmd = CommandBufferPool.Get("EdgeVignette");
// 设置shader参数
_material.SetColor(VignetteColorId, _vignetteVolume.color.value);
// 强度值 (x: top, y: bottom, z: left, w: right)
_material.SetVector(VignetteIntensityId, new Vector4(
_vignetteVolume.intensityTop.value,
_vignetteVolume.intensityBottom.value,
_vignetteVolume.intensityLeft.value,
_vignetteVolume.intensityRight.value
));
// 偏移值 (x: top, y: bottom, z: left, w: right)
_material.SetVector(VignetteOffsetId, new Vector4(
_vignetteVolume.offsetTop.value,
_vignetteVolume.offsetBottom.value,
_vignetteVolume.offsetLeft.value,
_vignetteVolume.offsetRight.value
));
// 平滑度 (x: top, y: bottom, z: left, w: right)
_material.SetVector(VignetteSmoothnessId, new Vector4(
_vignetteVolume.smoothnessTop.value,
_vignetteVolume.smoothnessBottom.value,
_vignetteVolume.smoothnessLeft.value,
_vignetteVolume.smoothnessRight.value
));
// 获取相机颜色目标
RTHandle cameraColorTarget = renderingData.cameraData.renderer.cameraColorTargetHandle;
// 使用Blitter进行双缓冲先应用效果到临时RT再复制回相机目标
Blitter.BlitCameraTexture(cmd, cameraColorTarget, _tempTarget, _material, 0);
Blitter.BlitCameraTexture(cmd, _tempTarget, cameraColorTarget);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void OnCameraCleanup(CommandBuffer cmd)
{
}
public void Dispose()
{
_tempTarget?.Release();
}
}
public Settings settings = new Settings();
private CustomRenderPass _scriptablePass;
private Material _material;
public override void Create()
{
var shader = Shader.Find("Hidden/PostProcess/EdgeVignette");
if (shader != null)
{
_material = CoreUtils.CreateEngineMaterial(shader);
_scriptablePass = new CustomRenderPass(settings);
_scriptablePass.SetMaterial(_material);
_scriptablePass.renderPassEvent = settings.renderPassEvent;
}
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
if (_scriptablePass == null || _material == null)
return;
// 只在UICamera摄像机下渲染
if (renderingData.cameraData.camera.name != "UICamera")
return;
renderer.EnqueuePass(_scriptablePass);
}
protected override void Dispose(bool disposing)
{
CoreUtils.Destroy(_material);
_scriptablePass?.Dispose();
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f88416ab97790bb429e426cba7663d78
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,68 +0,0 @@
Shader "Hidden/PostProcess/EdgeVignette"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
LOD 100
ZTest Always ZWrite Off Cull Off
Pass
{
Name "EdgeVignette"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
float4 _VignetteColor;
float4 _VignetteIntensity; // x: top, y: bottom, z: left, w: right
float4 _VignetteOffset; // x: top, y: bottom, z: left, w: right
float4 _VignetteSmoothness; // x: top, y: bottom, z: left, w: right
half4 frag(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord;
// 使用Blitter自动设置的_BlitTexture
half4 color = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
// 向量化计算所有方向的距离(考虑偏移)
// (top, bottom, left, right)
float4 dist = float4(
uv.y - _VignetteOffset.x, // Top
1.0 - uv.y - _VignetteOffset.y, // Bottom
uv.x - _VignetteOffset.z, // Left
1.0 - uv.x - _VignetteOffset.w // Right
);
// 向量化计算所有方向的vignette因子
// 防止除零同时保持intensity=0时vignette=1
float4 safeIntensity = max(_VignetteIntensity, 0.001);
float4 t = saturate(dist / safeIntensity);
// 使用step消除分支intensity>0时使用pow结果否则为1
float4 vignette = lerp(float4(1, 1, 1, 1), pow(t, _VignetteSmoothness), step(0.001, _VignetteIntensity));
// 四个方向独立渐变,通过相乘实现叠加效果
// 每个方向独立作用,不产生夹角
float vignetteFactor = vignette.x * vignette.y * vignette.z * vignette.w;
// 应用vignette
color.rgb = lerp(_VignetteColor.rgb, color.rgb, vignetteFactor);
return color;
}
ENDHLSL
}
}
}

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: fade46b1ecab15d45bb83c153bf33212
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9d6216f65ad328b449f24e98949fbd9e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,173 @@
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(PrefabRecorderTool))]
public class PrefabRecorderToolEditor : Editor
{
private SerializedProperty prefabFolderPath;
private SerializedProperty recordCountPerPrefab;
private SerializedProperty recordDuration;
private SerializedProperty spawnPosition;
private SerializedProperty spawnRotation;
private SerializedProperty outputRootFolder;
private SerializedProperty autoStartOnPlay;
private SerializedProperty existingRecorderSettings;
private SerializedProperty recordWidth;
private SerializedProperty recordHeight;
private SerializedProperty frameRate;
void OnEnable()
{
prefabFolderPath = serializedObject.FindProperty("prefabFolderPath");
recordCountPerPrefab = serializedObject.FindProperty("recordCountPerPrefab");
recordDuration = serializedObject.FindProperty("recordDuration");
spawnPosition = serializedObject.FindProperty("spawnPosition");
spawnRotation = serializedObject.FindProperty("spawnRotation");
outputRootFolder = serializedObject.FindProperty("outputRootFolder");
autoStartOnPlay = serializedObject.FindProperty("autoStartOnPlay");
existingRecorderSettings = serializedObject.FindProperty("existingRecorderSettings");
recordWidth = serializedObject.FindProperty("recordWidth");
recordHeight = serializedObject.FindProperty("recordHeight");
frameRate = serializedObject.FindProperty("frameRate");
}
public override void OnInspectorGUI()
{
PrefabRecorderTool tool = (PrefabRecorderTool)target;
serializedObject.Update();
// 标题
EditorGUILayout.Space();
GUIStyle titleStyle = new GUIStyle(GUI.skin.label);
titleStyle.fontSize = 16;
titleStyle.fontStyle = FontStyle.Bold;
titleStyle.alignment = TextAnchor.MiddleCenter;
EditorGUILayout.LabelField("Prefab批量录制工具", titleStyle);
EditorGUILayout.Space();
// 基础设置
EditorGUILayout.LabelField("基础设置", EditorStyles.boldLabel);
EditorGUILayout.BeginVertical("box");
{
EditorGUILayout.PropertyField(prefabFolderPath, new GUIContent("Prefab文件夹路径", "相对于Assets目录的路径"));
// 添加文件夹选择按钮
if (GUILayout.Button("选择文件夹", GUILayout.Height(25)))
{
string selectedPath = EditorUtility.OpenFolderPanel("选择Prefab文件夹", "Assets", "");
if (!string.IsNullOrEmpty(selectedPath))
{
// 转换为相对路径
string projectPath = Application.dataPath.Replace("/Assets", "");
if (selectedPath.StartsWith(projectPath))
{
selectedPath = selectedPath.Substring(projectPath.Length + 1);
prefabFolderPath.stringValue = selectedPath;
}
}
}
EditorGUILayout.PropertyField(recordCountPerPrefab, new GUIContent("每个Prefab录制次数", "每个Prefab将被录制的次数"));
EditorGUILayout.PropertyField(recordDuration, new GUIContent("单次录制时长(秒)", "每次录制持续的秒数"));
EditorGUILayout.PropertyField(autoStartOnPlay, new GUIContent("游戏启动时自动开始", "勾选后进入Play模式会自动开始录制"));
}
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
// 实例化设置
EditorGUILayout.LabelField("Prefab实例化设置", EditorStyles.boldLabel);
EditorGUILayout.BeginVertical("box");
{
EditorGUILayout.PropertyField(spawnPosition, new GUIContent("生成位置", "Prefab实例化的世界坐标位置"));
EditorGUILayout.PropertyField(spawnRotation, new GUIContent("生成旋转", "Prefab实例化的欧拉角旋转"));
}
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
// 输出设置
EditorGUILayout.LabelField("输出设置", EditorStyles.boldLabel);
EditorGUILayout.BeginVertical("box");
{
EditorGUILayout.PropertyField(outputRootFolder, new GUIContent("输出根文件夹", "录制文件的保存根目录"));
EditorGUILayout.HelpBox("输出格式: " + outputRootFolder.stringValue + "/{Prefab名称}_{序号}/", MessageType.Info);
}
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
// 录制器设置
EditorGUILayout.LabelField("录制器设置", EditorStyles.boldLabel);
EditorGUILayout.BeginVertical("box");
{
EditorGUILayout.PropertyField(existingRecorderSettings, new GUIContent("现有Recorder设置", "可选使用已有的Recorder设置文件留空则使用下方参数创建新设置"));
if (existingRecorderSettings.objectReferenceValue != null)
{
EditorGUILayout.HelpBox("将使用现有的Recorder设置下方参数将被忽略", MessageType.Info);
}
else
{
EditorGUILayout.HelpBox("将使用下方参数创建新的Recorder设置", MessageType.Info);
}
EditorGUI.BeginDisabledGroup(existingRecorderSettings.objectReferenceValue != null);
EditorGUILayout.PropertyField(recordWidth, new GUIContent("录制宽度", "输出图像序列的宽度"));
EditorGUILayout.PropertyField(recordHeight, new GUIContent("录制高度", "输出图像序列的高度"));
EditorGUILayout.PropertyField(frameRate, new GUIContent("帧率", "录制的帧率"));
EditorGUI.EndDisabledGroup();
}
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
// 控制按钮
EditorGUILayout.BeginVertical("box");
{
GUI.backgroundColor = Color.green;
if (GUILayout.Button("▶ 开始批量录制", GUILayout.Height(40)))
{
if (EditorApplication.isPlaying)
{
tool.StartBatchRecording();
}
else
{
EditorUtility.DisplayDialog("提示", "请先进入Play模式再开始录制", "确定");
}
}
GUI.backgroundColor = Color.white;
EditorGUILayout.Space(5);
if (!EditorApplication.isPlaying)
{
GUI.backgroundColor = new Color(0.3f, 0.8f, 1f);
if (GUILayout.Button("▶ 进入Play模式并开始录制", GUILayout.Height(35)))
{
autoStartOnPlay.boolValue = true;
serializedObject.ApplyModifiedProperties();
EditorApplication.isPlaying = true;
}
GUI.backgroundColor = Color.white;
}
}
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
// 使用说明
EditorGUILayout.HelpBox(
"使用说明:\n" +
"1. 设置Prefab文件夹路径相对于Assets目录\n" +
"2. 设置录制参数(次数、时长等)\n" +
"3. 点击'开始批量录制'按钮或勾选自动开始并进入Play模式\n" +
"4. 工具会自动遍历并录制所有Prefab\n" +
"5. 录制文件会保存在指定的输出文件夹中",
MessageType.Info);
serializedObject.ApplyModifiedProperties();
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: e0a5a60482ed3a34a8f135e1dce87b55
guid: d39b8ddafc5b5954db29628a788254ef
MonoImporter:
externalObjects: {}
serializedVersion: 2