非HDR开启bloom的效果
主要是URP作者的教程

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
partial class PostFXStack
{
private const string bufferName = "Post FX";
CommandBuffer buffer = new CommandBuffer()
{
name = bufferName
};
private ScriptableRenderContext context;
private Camera camera;
private PostFXSettings settings;
private int fxSourceId = Shader.PropertyToID("_PostFXSource");
private int fxSource2Id = Shader.PropertyToID("_PostFXSource2");
private int bloomBucibicUpsamplingId = Shader.PropertyToID("_BloomBicubicUpsampling");
private int bloomPrefilterId = Shader.PropertyToID("_BloomPrefilter");
private int bloomThresholdId = Shader.PropertyToID("_BloomThreshold");
private int bloomIntensityId = Shader.PropertyToID("_BloomIntensity");
public bool IsActive => settings != null;
private const int maxBloomPyramidLevels = 16;
private int bloomPyramidId;
enum Pass
{
// BloomPrefilter,
// BloomCombine,
BloomVertical,
BloomHorizontal,
BloomCombine,
BloomPrefilter,
Copy,
}
public PostFXStack()
{
bloomPyramidId = Shader.PropertyToID("_BloomPyramid0");
for (int i = 0; i < maxBloomPyramidLevels * 2; i++)
{
// id的结果是 申请的顺序 +1的结果
Shader.PropertyToID("_BloomPyramid"+i);
}
}
void DoBloom(int sourceId)
{
buffer.BeginSample("Bloom");
PostFXSettings.BloomSettings bloom = settings.Bloom;
int width = camera.pixelWidth / 2, height = camera.pixelHeight / 2;
Vector4 threshold;
threshold.x = Mathf.GammaToLinearSpace(bloom.threshold);
threshold.y = threshold.x * bloom.thresholdKnee;
threshold.z = threshold.y * 2f;
threshold.w = 0.25f /( threshold.y + 0.00001f);
threshold.y -= threshold.x;
buffer.SetGlobalVector(bloomThresholdId,threshold);
RenderTextureFormat format = RenderTextureFormat.Default;
buffer.GetTemporaryRT(bloomPrefilterId,width,height,0,FilterMode.Bilinear,format);
Draw(sourceId,bloomPrefilterId,Pass.BloomPrefilter);
width /= 2;
height /= 2;
int formId = bloomPrefilterId

本文介绍如何在不使用HDR的情况下实现Bloom效果。通过Unity的URP系统,利用自定义后处理堆栈实现Bloom算法。文章详细介绍了Bloom效果的实现步骤,包括预过滤、水平垂直模糊及融合等过程。
最低0.47元/天 解锁文章
638

被折叠的 条评论
为什么被折叠?



