Unity Shader学习:SSAO屏幕环境光遮蔽
主要思路:1.随机采样像素法线半球周围的像素,平均对比与该像素深度是否处在暗处。2.双边滤波去噪点。3.后期AO图与原图混合。
原文链接:https://blog.csdn.net/puppet_master/article/details/82929708

无AO

有AO

AO图
c#部分:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SSAO : MonoBehaviour {
public Material SSAOMaterial;
private List<Vector4> sampleKernelList = new List<Vector4>();
[Range(0f, 0.002f)]
public float depthBiasValue = 0f;
[Range(0.01f, 1f)]
public float sampleKernelRadius = 1.0f;
[Range(4,32)]
public int sampleKernelCount = 16;
[Range(0.0f, 5.0f)]
public float AOStrength = 1.0f;
[Range(0, 2)]
public int downSample = 0;
[Range(1, 4)]
public int blurRadius = 1;
[Range(0f, 0.2f)]
public float bilateralFilterStrength = 0.2f;
public bool onlyShowAO = false;
public enum SSAOPassName
{
GenerateAO=0,
BilateralFilter=1,
Composite=2
}
private Camera currentCamera;
void Start () {
currentCamera = Camera.main;
currentCamera.depthTextureMode = DepthTextureMode.DepthNormals;
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
//采样点生成
GenerateAOSampleKernel();
RenderTexture aoRT = RenderTexture.GetTemporary(source.width >> downSample, source.height >> downSample, 0);

本文介绍了Unity中实现SSAO(屏幕环境光遮蔽)的技术,包括通过随机采样像素周围法线进行深度比较,双边滤波消除噪点,以及后期如何将AO图与原图融合,提升3D场景的光照效果。
最低0.47元/天 解锁文章

1723

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



