You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.2 KiB

using System.Collections;
using System.Collections.Generic;
using UC;
using UnityEngine;
[ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
public class PrettySkin : MonoBehaviour {
[AutoUI]
[SerializeField]
[Range(0.001f,1)]
private float Bsigma;
[AutoUI]
[SerializeField]
[Range(0, 15)]
private float Sigma;
[AutoUI]
[SerializeField]
[Range(0,3)]
private float log;
[AutoUI]
[SerializeField]
[Range(0,1)]
private float smoothDegree;
[SerializeField]
private Shader m_PrettyShader;
public Shader PrettyShader
{
get
{
if (m_PrettyShader == null)
m_PrettyShader = Shader.Find("Unlit/PrettySkin 2.0");
return m_PrettyShader;
}
}
[SerializeField]
private Material m_PrettyMaterial;
public Material PrettyMaterial
{
get
{
if (m_PrettyMaterial == null)
m_PrettyMaterial = ImageEffectHelper.CheckShaderAndCreateMaterial(PrettyShader);
return m_PrettyMaterial;
}
}
private void OnEnable()
{
GetComponent<Camera>().depthTextureMode = DepthTextureMode.DepthNormals;
}
private void OnDisable()
{
}
private void DestroyMaterial(Material mat)
{
if (mat != null)
DestroyImmediate(mat);
mat = null;
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
RenderTexture rt1 = RenderTexture.GetTemporary(source.width, source.height);
RenderTexture rt2 = RenderTexture.GetTemporary(source.width, source.height);
PrettyMaterial.SetFloat("_BSIGMA", Bsigma);
PrettyMaterial.SetFloat("_SIGMA", Sigma);
Graphics.Blit(source, rt1, PrettyMaterial, 0);
Graphics.Blit(source, rt2, PrettyMaterial, 1);
PrettyMaterial.SetFloat("_smoothDegree", smoothDegree);
PrettyMaterial.SetFloat("_Log", log);
PrettyMaterial.SetTexture("_Bilateral",rt1);
PrettyMaterial.SetTexture("_Canny", rt2);
Graphics.Blit(source, destination, PrettyMaterial, 2);
RenderTexture.ReleaseTemporary(rt1);
RenderTexture.ReleaseTemporary(rt2);
}
}