Added UtsEvaluateAngelRing;
Added UTSTonemapping;
This commit is contained in:
@@ -11,12 +11,16 @@ namespace Misaki.HdrpToon.Editor
|
|||||||
public static MaterialProperty angelRingColor;
|
public static MaterialProperty angelRingColor;
|
||||||
public static MaterialProperty angelRingColorMap;
|
public static MaterialProperty angelRingColorMap;
|
||||||
public static MaterialProperty angelRingIntensity;
|
public static MaterialProperty angelRingIntensity;
|
||||||
|
public static MaterialProperty angelRingOffsetU;
|
||||||
|
public static MaterialProperty angelRingOffsetV;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Styles
|
private static class Styles
|
||||||
{
|
{
|
||||||
public static readonly GUIContent angelRingColorText = new("Angel Ring Color", "Specifies the color of the angel ring.");
|
public static readonly GUIContent angelRingColorText = new("Angel Ring Color", "Specifies the color of the angel ring.");
|
||||||
public static readonly GUIContent angelRingIntensityText = new("Angel Ring Intensity", "Specifies the intensity of the angel ring.");
|
public static readonly GUIContent angelRingIntensityText = new("Angel Ring Intensity", "Specifies the intensity of the angel ring.");
|
||||||
|
public static readonly GUIContent angelRingOffsetUText = new("Angel Ring Offset U", "Specifies the offset of the angel ring in the U direction.");
|
||||||
|
public static readonly GUIContent angelRingOffsetVText = new("Angel Ring Offset V", "Specifies the offset of the angel ring in the V direction.");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool ShowSection => owner.GetUIScope<SurfaceOptionsScope>().HasFeature(SurfaceFeatureFlags.AngelRing);
|
protected override bool ShowSection => owner.GetUIScope<SurfaceOptionsScope>().HasFeature(SurfaceFeatureFlags.AngelRing);
|
||||||
@@ -30,12 +34,16 @@ namespace Misaki.HdrpToon.Editor
|
|||||||
Properties.angelRingColor = FindProperty("_AngelRingColor");
|
Properties.angelRingColor = FindProperty("_AngelRingColor");
|
||||||
Properties.angelRingColorMap = FindProperty("_AngelRingColorMap");
|
Properties.angelRingColorMap = FindProperty("_AngelRingColorMap");
|
||||||
Properties.angelRingIntensity = FindProperty("_AngelRingIntensity");
|
Properties.angelRingIntensity = FindProperty("_AngelRingIntensity");
|
||||||
|
Properties.angelRingOffsetU = FindProperty("_AngelRingOffsetU");
|
||||||
|
Properties.angelRingOffsetV = FindProperty("_AngelRingOffsetV");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DrawContent()
|
protected override void DrawContent()
|
||||||
{
|
{
|
||||||
editor.TexturePropertySingleLine(Styles.angelRingColorText, Properties.angelRingColorMap, Properties.angelRingColor);
|
editor.TexturePropertySingleLine(Styles.angelRingColorText, Properties.angelRingColorMap, Properties.angelRingColor);
|
||||||
editor.ShaderProperty(Properties.angelRingIntensity, Styles.angelRingIntensityText);
|
editor.ShaderProperty(Properties.angelRingIntensity, Styles.angelRingIntensityText);
|
||||||
|
editor.ShaderProperty(Properties.angelRingOffsetU, Styles.angelRingOffsetUText);
|
||||||
|
editor.ShaderProperty(Properties.angelRingOffsetV, Styles.angelRingOffsetVText);
|
||||||
|
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
editor.TextureScaleOffsetProperty(Properties.angelRingColorMap);
|
editor.TextureScaleOffsetProperty(Properties.angelRingColorMap);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace Misaki.HdrpToon.Editor
|
|||||||
|
|
||||||
public bool HasFeature(SurfaceFeatureFlags feature)
|
public bool HasFeature(SurfaceFeatureFlags feature)
|
||||||
{
|
{
|
||||||
return ((SurfaceFeatureFlags)Properties.surfaceFeatures.floatValue & feature) == feature;
|
return ((SurfaceFeatureFlags)Properties.surfaceFeatures.floatValue & feature) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void LoadMaterialProperties()
|
public override void LoadMaterialProperties()
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using UnityEngine.Rendering;
|
||||||
|
|
||||||
namespace Misaki.HdrpToon
|
namespace Misaki.HdrpToon
|
||||||
{
|
{
|
||||||
[Flags]
|
[Flags]
|
||||||
|
[GenerateHLSL(PackingRules.Exact)]
|
||||||
public enum SurfaceFeatureFlags : uint
|
public enum SurfaceFeatureFlags : uint
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
|
|||||||
17
Runtime/Models/SurfaceFeatureFlags.cs.hlsl
Normal file
17
Runtime/Models/SurfaceFeatureFlags.cs.hlsl
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// This file was automatically generated. Please don't edit by hand. Execute Editor command [ Edit > Rendering > Generate Shader Includes ] instead
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SURFACEFEATUREFLAGS_CS_HLSL
|
||||||
|
#define SURFACEFEATUREFLAGS_CS_HLSL
|
||||||
|
//
|
||||||
|
// Misaki.HdrpToon.SurfaceFeatureFlags: static fields
|
||||||
|
//
|
||||||
|
#define SURFACEFEATUREFLAGS_NONE (0)
|
||||||
|
#define SURFACEFEATUREFLAGS_RIM_LIGHT (1)
|
||||||
|
#define SURFACEFEATUREFLAGS_STOCKING (2)
|
||||||
|
#define SURFACEFEATUREFLAGS_ANGEL_RING (4)
|
||||||
|
#define SURFACEFEATUREFLAGS_OUTLINE (8)
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
7
Runtime/Models/SurfaceFeatureFlags.cs.hlsl.meta
Normal file
7
Runtime/Models/SurfaceFeatureFlags.cs.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ec297400b1508d647a7cdbad2c0edf40
|
||||||
|
ShaderIncludeImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -246,7 +246,7 @@ Shader "HDRP/Toon"
|
|||||||
_EmissionColor("Color", Color) = (1, 1, 1)
|
_EmissionColor("Color", Color) = (1, 1, 1)
|
||||||
|
|
||||||
// HACK: GI Baking system relies on some properties existing in the shader ("_MainTex", "_Cutoff" and "_Color") for opacity handling, so we need to store our version of those parameters in the hard-coded name the GI baking system recognizes.
|
// HACK: GI Baking system relies on some properties existing in the shader ("_MainTex", "_Cutoff" and "_Color") for opacity handling, so we need to store our version of those parameters in the hard-coded name the GI baking system recognizes.
|
||||||
_MainTex("BaseMap", 2D) = "white" {}
|
_MainTex("Base Map", 2D) = "white" {}
|
||||||
_Color("Color", Color) = (1,1,1,1)
|
_Color("Color", Color) = (1,1,1,1)
|
||||||
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
|
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
|
||||||
|
|
||||||
@@ -274,23 +274,25 @@ Shader "HDRP/Toon"
|
|||||||
[Enum(Off, 0, FRONT, 1, BACK, 2)] _CullMode("Cull Mode", int) = 2 //OFF/FRONT/BACK
|
[Enum(Off, 0, FRONT, 1, BACK, 2)] _CullMode("Cull Mode", int) = 2 //OFF/FRONT/BACK
|
||||||
[KeywordEnum(Standard, FrontHair, Face, Eye)] _Material_Type("Material Type", int) = 0
|
[KeywordEnum(Standard, FrontHair, Face, Eye)] _Material_Type("Material Type", int) = 0
|
||||||
[KeywordEnum(Off, Standard, Anisotropy, Hair, Toon)] _PBR_Mode("PBR MODE", int) = 0
|
[KeywordEnum(Off, Standard, Anisotropy, Hair, Toon)] _PBR_Mode("PBR MODE", int) = 0
|
||||||
[Toggle] _Receive_Hair_Shadow("ReceiveHairShadow", Float) = 0
|
[Toggle] _Receive_Hair_Shadow("Receive HairS hadow", Float) = 0
|
||||||
[ToggleUI] _HairBlendingTarget("HairBlendingTarget", Float) = 0
|
[ToggleUI] _HairBlendingTarget("Hair Blending Target", Float) = 0
|
||||||
[HideInInspector] _SurfaceFeatures("SurfaceFeatures", Float) = 0
|
_SurfaceFeatures("Surface Features", Float) = 0
|
||||||
|
|
||||||
// Angel Rings
|
// Angel Rings
|
||||||
_AngelRingColor("AngelRingColor", Color) = (1, 1, 1, 1)
|
_AngelRingColor("Angel Ring Color", Color) = (1, 1, 1, 1)
|
||||||
_AngelRingColorMap("AngelRingColorMap", 2D) = "black" {}
|
_AngelRingColorMap("Angel Ring Color Map", 2D) = "black" {}
|
||||||
_AngelRingIntensity("AngelRingIntensity", Range(0, 10)) = 1
|
_AngelRingIntensity("Angel Ring Intensity", Range(0, 10)) = 1
|
||||||
|
_AngelRingOffsetU("Angel Ring Offset U", Range(0, 1)) = 0
|
||||||
|
_AngelRingOffsetV("Angel Ring Offset V", Range(0, 1)) = 0
|
||||||
|
|
||||||
// Outline
|
// Outline
|
||||||
_OutlineWidth("OutlineWidth", Float) = 0
|
_OutlineWidth("Outline Width", Float) = 0
|
||||||
_OutlineWidthMap("OutlineTex", 2D) = "white" {}
|
_OutlineWidthMap("Outline Tex", 2D) = "white" {}
|
||||||
_OutlineColor("OutlineColor", Color) = (0.5, 0.5, 0.5, 1)
|
_OutlineColor("Outline Color", Color) = (0.5, 0.5, 0.5, 1)
|
||||||
_OutlineColorMap("OutlineColorMap", 2D) = "white" {}
|
_OutlineColorMap("Outline Color Map", 2D) = "white" {}
|
||||||
[Toggle(_)] _AlbedoAffectOutline("AlbedoAffectOutline", Float) = 0
|
[Toggle(_)] _AlbedoAffectOutline("AlbedoAffectOutline", Float) = 0
|
||||||
_OutlineFadeIn("_OutlineFadeIn", Float) = 50
|
_OutlineFadeIn("Outline Fade In", Float) = 50
|
||||||
_OutlineFadeOut("_OutlineFadeOut", Float) = 100
|
_OutlineFadeOut("Outline Fade Out", Float) = 100
|
||||||
[Toggle(_)] _UseSmoothedNormal("Use Smoothed Normal", Float) = 0
|
[Toggle(_)] _UseSmoothedNormal("Use Smoothed Normal", Float) = 0
|
||||||
//[HideInInspector]_Cutoff("Alpha cutoff", Range(0, 1)) = 0.5
|
//[HideInInspector]_Cutoff("Alpha cutoff", Range(0, 1)) = 0.5
|
||||||
_BakedNormal("Baked Normal for Outline", 2D) = "white" {}
|
_BakedNormal("Baked Normal for Outline", 2D) = "white" {}
|
||||||
|
|||||||
@@ -9,12 +9,6 @@ struct UtsShadeMask
|
|||||||
float firstShadeMask;
|
float firstShadeMask;
|
||||||
};
|
};
|
||||||
|
|
||||||
float3 GetSpecularColor(float3 albedo, float metalic)
|
|
||||||
{
|
|
||||||
float3 specColor = lerp(ColorSpaceDielectricSpec.rgb, albedo, metalic);
|
|
||||||
return specColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
float RoughnessToBlinnPhongSpecularExponent(float roughness)
|
float RoughnessToBlinnPhongSpecularExponent(float roughness)
|
||||||
{
|
{
|
||||||
return clamp(2 * rcp(roughness * roughness) - 2, FLT_EPS, rcp(FLT_EPS));
|
return clamp(2 * rcp(roughness * roughness) - 2, FLT_EPS, rcp(FLT_EPS));
|
||||||
@@ -228,6 +222,35 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
|
|||||||
return lighting;
|
return lighting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DirectLighting UtsEvaluateAngelRing(FragInputs input, float3 normalWS, float3 V)
|
||||||
|
{
|
||||||
|
DirectLighting lighting;
|
||||||
|
ZERO_INITIALIZE(DirectLighting, lighting);
|
||||||
|
|
||||||
|
// Should we scroll the angel ring texture on x?
|
||||||
|
float3 cameraRight = UNITY_MATRIX_V[0].xyz;
|
||||||
|
float3 cameraFront = UNITY_MATRIX_V[2].xyz;
|
||||||
|
float3 upVector = float3(0, 1, 0);
|
||||||
|
float3 rightAxis = cross(cameraFront, upVector);
|
||||||
|
float cameraRightMagnitude = sqrt(cameraRight.x * cameraRight.x + cameraRight.y * cameraRight.y + cameraRight.z * cameraRight.z);
|
||||||
|
float rightAxisMagnitude = sqrt(rightAxis.x * rightAxis.x + rightAxis.y * rightAxis.y + rightAxis.z * rightAxis.z);
|
||||||
|
float cameraRollCos = dot(rightAxis, cameraRight) / (rightAxisMagnitude * cameraRightMagnitude);
|
||||||
|
float3 cameraRoll = acos(clamp(cameraRollCos, -1.0, 1.0));
|
||||||
|
float cameraDir = cameraRight.y < 0 ? -1.0 : 1.0;
|
||||||
|
|
||||||
|
float2 arOffsetU = lerp(mul(UNITY_MATRIX_V, float4(normalWS, 0)).xyz, float3(0, 0, 1), _AngelRingOffsetU).xy;
|
||||||
|
arOffsetU = arOffsetU * 0.5 + 0.5;
|
||||||
|
float2 arvnRotate = RotateUV(arOffsetU, -(cameraDir * cameraRoll), 0.5, 1.0);
|
||||||
|
float2 arOffsetUV = float2(arvnRotate.x, lerp(input.texCoord0.y, arvnRotate.y, _AngelRingOffsetV));
|
||||||
|
float4 angelRingColor = SAMPLE_TEXTURE2D(_AngelRingColorMap, sampler_AngelRingColorMap, TRANSFORM_TEX(arOffsetUV, _AngelRingColorMap)) * _AngelRingColor * _AngelRingIntensity;
|
||||||
|
|
||||||
|
float weight = saturate(dot(normalize(V), normalWS));
|
||||||
|
|
||||||
|
lighting.specular += angelRingColor.r * angelRingColor.a * weight;
|
||||||
|
|
||||||
|
return lighting;
|
||||||
|
}
|
||||||
|
|
||||||
// Todo: SDF nose high light
|
// Todo: SDF nose high light
|
||||||
// #if define(_SDFShadow) || define(_SDFNoiseHelight)
|
// #if define(_SDFShadow) || define(_SDFNoiseHelight)
|
||||||
#ifdef _SDFShadow
|
#ifdef _SDFShadow
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/PhysicalCamera.hlsl"
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/PhysicalCamera.hlsl"
|
||||||
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsMaterialEvaluation.hlsl"
|
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsMaterialEvaluation.hlsl"
|
||||||
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Lighting/UtsLightEvaluation.hlsl"
|
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Lighting/UtsLightEvaluation.hlsl"
|
||||||
|
#include "Packages/com.misaki.hdrp-toon/Runtime/Models/SurfaceFeatureFlags.cs.hlsl"
|
||||||
|
|
||||||
// Channel mask enum.
|
// Channel mask enum.
|
||||||
// this must be same to UI cs code
|
// this must be same to UI cs code
|
||||||
@@ -205,8 +206,8 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
|
|||||||
{
|
{
|
||||||
if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, builtinData.renderingLayers))
|
if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, builtinData.renderingLayers))
|
||||||
{
|
{
|
||||||
DirectLighting direct = UtsEvaluateBSDF_Directional(context, posInput, builtinData, _DirectionalLightDatas[i], bsdfData, preLightData, V, fragInputs.texCoord0.xy);
|
DirectLighting lighting = UtsEvaluateBSDF_Directional(context, posInput, builtinData, _DirectionalLightDatas[i], bsdfData, preLightData, V, fragInputs.texCoord0.xy);
|
||||||
AccumulateDirectLighting(direct, aggregateLighting);
|
AccumulateDirectLighting(lighting, aggregateLighting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -371,6 +372,12 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (HasFlag(bsdfData.surfaceFeatures, SURFACEFEATUREFLAGS_ANGEL_RING))
|
||||||
|
{
|
||||||
|
DirectLighting lighting = UtsEvaluateAngelRing(fragInputs, bsdfData.normalWS, V);
|
||||||
|
AccumulateDirectLighting(lighting, aggregateLighting);
|
||||||
|
}
|
||||||
|
|
||||||
UtsPostEvaluateBSDF(posInput, preLightData, bsdfData, builtinData, aggregateLighting, lightLoopOutput);
|
UtsPostEvaluateBSDF(posInput, preLightData, bsdfData, builtinData, aggregateLighting, lightLoopOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -159,7 +159,9 @@ float _Light_Intensity_Multiplier;
|
|||||||
|
|
||||||
float4 _AngelRingColor;
|
float4 _AngelRingColor;
|
||||||
float4 _AngelRingColorMap_ST;
|
float4 _AngelRingColorMap_ST;
|
||||||
float _AR_Intensity;
|
float _AngelRingIntensity;
|
||||||
|
float _AngelRingOffsetU;
|
||||||
|
float _AngelRingOffsetV;
|
||||||
|
|
||||||
float _OutlineWidth;
|
float _OutlineWidth;
|
||||||
float4 _OutlineColor;
|
float4 _OutlineColor;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#ifndef UTSDEBUG_CS_HLSL
|
#ifndef UTSDEBUG_CS_HLSL
|
||||||
#define UTSDEBUG_CS_HLSL
|
#define UTSDEBUG_CS_HLSL
|
||||||
//
|
//
|
||||||
// Unity.Toonshader.UTS_BSDFDebug: static fields
|
// Misaki.HdrpToon.UTS_BSDFDebug: static fields
|
||||||
//
|
//
|
||||||
#define UTS_BSDFDEBUG_NONE (0)
|
#define UTS_BSDFDEBUG_NONE (0)
|
||||||
#define UTS_BSDFDEBUG_BASE_COLOR (1)
|
#define UTS_BSDFDEBUG_BASE_COLOR (1)
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
#define UTS_BSDFDEBUG_NORMAL_WS (10)
|
#define UTS_BSDFDEBUG_NORMAL_WS (10)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Unity.Toonshader.UTS_LightingDebug: static fields
|
// Misaki.HdrpToon.UTS_LightingDebug: static fields
|
||||||
//
|
//
|
||||||
#define UTS_LIGHTINGDEBUG_NONE (0)
|
#define UTS_LIGHTINGDEBUG_NONE (0)
|
||||||
#define UTS_LIGHTINGDEBUG_DIFFUSE_LIGHTING (1)
|
#define UTS_LIGHTINGDEBUG_DIFFUSE_LIGHTING (1)
|
||||||
|
|||||||
@@ -1,132 +0,0 @@
|
|||||||
using UnityEditor;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Experimental.Rendering;
|
|
||||||
using UnityEngine.Rendering;
|
|
||||||
using UnityEngine.Rendering.HighDefinition;
|
|
||||||
using UnityEngine.Rendering.RendererUtils;
|
|
||||||
|
|
||||||
namespace Misaki.HdrpToon
|
|
||||||
{
|
|
||||||
[HideInInspector]
|
|
||||||
internal class UTSHairShadowPass : DrawRenderersCustomPass
|
|
||||||
{
|
|
||||||
private const string Hair_Shadow_RTHandle_Scale_Prop_Name = "_HairShadowRTHandleScale";
|
|
||||||
private const string Hair_Shadow_Distance_Prop_Name = "_HairShadowDistance";
|
|
||||||
private const string Hair_Shadow_Distance_Scale_Prop_Name = "_HairShadowDistanceScaleFactor";
|
|
||||||
private const string Hair_Shadow_Depth_Bias_Prop_Name = "_HairShadowDepthBias";
|
|
||||||
private const string Hair_Shadow_FadeIn_Prop_Name = "_HairShadowFadeInDistance";
|
|
||||||
private const string Hair_Shadow_Fade_Out_Prop_Name = "_HairShadowFadeOutDistance";
|
|
||||||
|
|
||||||
private const string Output_RT_Prop_Name = "_HairShadowTex";
|
|
||||||
|
|
||||||
private RTHandle _outputRTHandle;
|
|
||||||
private bool _needReallocate;
|
|
||||||
|
|
||||||
private BufferQuality _shadowQuality = BufferQuality.High;
|
|
||||||
internal BufferQuality CurrentShadowQuality
|
|
||||||
{
|
|
||||||
get => _shadowQuality;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_shadowQuality == value)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_shadowQuality = value;
|
|
||||||
_needReallocate = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool ShouldReallocateBuffer()
|
|
||||||
{
|
|
||||||
return _outputRTHandle == null || _outputRTHandle.rt == null || !_outputRTHandle.rt.IsCreated() || _needReallocate;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ReallocateBuffer()
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
if (EditorApplication.isCompiling)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
var scale = _shadowQuality switch
|
|
||||||
{
|
|
||||||
BufferQuality.Low => new Vector2(0.5f, 0.5f),
|
|
||||||
BufferQuality.High => Vector2.one,
|
|
||||||
_ => Vector2.zero
|
|
||||||
};
|
|
||||||
|
|
||||||
var format = _shadowQuality switch
|
|
||||||
{
|
|
||||||
BufferQuality.Low => GraphicsFormat.D16_UNorm,
|
|
||||||
BufferQuality.High => GraphicsFormat.D32_SFloat,
|
|
||||||
_ => GraphicsFormat.D16_UNorm
|
|
||||||
};
|
|
||||||
|
|
||||||
_outputRTHandle?.Release();
|
|
||||||
_outputRTHandle = RTHandles.Alloc(scale, colorFormat: format, filterMode: FilterMode.Bilinear, wrapMode: TextureWrapMode.Clamp, isShadowMap: true, useDynamicScale: true, name: Output_RT_Prop_Name);
|
|
||||||
Shader.SetGlobalTexture(Output_RT_Prop_Name, _outputRTHandle);
|
|
||||||
|
|
||||||
_needReallocate = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
|
|
||||||
{
|
|
||||||
ReallocateBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Execute(CustomPassContext ctx)
|
|
||||||
{
|
|
||||||
if (ShouldReallocateBuffer())
|
|
||||||
{
|
|
||||||
ReallocateBuffer();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CoreUtils.SetRenderTarget(ctx.cmd, _outputRTHandle, ClearFlag.DepthStencil);
|
|
||||||
|
|
||||||
var utsRenderer = ctx.hdCamera.volumeStack.GetComponent<UTSRenderer>();
|
|
||||||
var shouldRender = utsRenderer != null && utsRenderer.enableHairShadow.value && utsRenderer.state.value;
|
|
||||||
if (!shouldRender)
|
|
||||||
{
|
|
||||||
CoreUtils.ClearRenderTarget(ctx.cmd, ClearFlag.DepthStencil, Color.black);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = new RendererListDesc(UtsShaderPassName.hairShadowCasterPassId, ctx.cullingResults, ctx.hdCamera.camera)
|
|
||||||
{
|
|
||||||
renderQueueRange = GetRenderQueueRange(RenderQueueType.All),
|
|
||||||
sortingCriteria = SortingCriteria.CommonOpaque,
|
|
||||||
excludeObjectMotionVectors = false,
|
|
||||||
};
|
|
||||||
|
|
||||||
CoreUtils.DrawRendererList(ctx.renderContext, ctx.cmd, ctx.renderContext.CreateRendererList(result));
|
|
||||||
|
|
||||||
Shader.SetGlobalVector(Hair_Shadow_RTHandle_Scale_Prop_Name, _outputRTHandle.rtHandleProperties.rtHandleScale);
|
|
||||||
Shader.SetGlobalFloat(Hair_Shadow_Distance_Prop_Name, utsRenderer.shadowDistance.value);
|
|
||||||
Shader.SetGlobalFloat(Hair_Shadow_Distance_Scale_Prop_Name, utsRenderer.shadowDistanceScale.value);
|
|
||||||
Shader.SetGlobalFloat(Hair_Shadow_Depth_Bias_Prop_Name, utsRenderer.shadowDepthBias.value);
|
|
||||||
Shader.SetGlobalFloat(Hair_Shadow_FadeIn_Prop_Name, utsRenderer.shadowFadeIn.value);
|
|
||||||
Shader.SetGlobalFloat(Hair_Shadow_Fade_Out_Prop_Name, utsRenderer.shadowFadeOut.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Cleanup()
|
|
||||||
{
|
|
||||||
Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Release()
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
if (EditorApplication.isCompiling)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
_outputRTHandle?.Release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 7157c6dc91cee0d4aae565d1c8d66807
|
|
||||||
8
Runtime/UTS Renderer/UTSToonmapping.meta
Normal file
8
Runtime/UTS Renderer/UTSToonmapping.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fdfeda4b69aae2340a45f31eae9933b3
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
48
Runtime/UTS Renderer/UTSToonmapping/UTSTonemapping.cs
Normal file
48
Runtime/UTS Renderer/UTSToonmapping/UTSTonemapping.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Rendering;
|
||||||
|
using UnityEngine.Rendering.HighDefinition;
|
||||||
|
|
||||||
|
[Serializable, VolumeComponentMenu("Post-processing/UTS Tonemapping")]
|
||||||
|
public sealed class UTSTonemapping : CustomPostProcessVolumeComponent, IPostProcessComponent
|
||||||
|
{
|
||||||
|
[Tooltip("Controls the intensity of the effect.")]
|
||||||
|
public BoolParameter state = new BoolParameter(true, BoolParameter.DisplayType.EnumPopup);
|
||||||
|
|
||||||
|
private Material _material;
|
||||||
|
|
||||||
|
public bool IsActive() => _material != null && state.value;
|
||||||
|
|
||||||
|
// Do not forget to add this post process in the Custom Post Process Orders list (Project Settings > Graphics > HDRP Global Settings).
|
||||||
|
public override CustomPostProcessInjectionPoint injectionPoint => CustomPostProcessInjectionPoint.AfterPostProcess;
|
||||||
|
|
||||||
|
const string Shader_Name = "Hidden/Shader/UTSTonemapping";
|
||||||
|
|
||||||
|
public override void Setup()
|
||||||
|
{
|
||||||
|
if (Shader.Find(Shader_Name) != null)
|
||||||
|
{
|
||||||
|
_material = CoreUtils.CreateEngineMaterial(Shader_Name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogError($"Unable to find shader '{Shader_Name}'. Post Process Volume UTSToonmapping is unable to load. To fix this, please edit the 'kShaderName' constant in UTSToonmapping.cs or change the name of your custom post process shader.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)
|
||||||
|
{
|
||||||
|
if (_material == null || !state.value)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_material.SetTexture("_MainTex", source);
|
||||||
|
HDUtils.DrawFullScreen(cmd, _material, destination, shaderPassId: 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Cleanup()
|
||||||
|
{
|
||||||
|
CoreUtils.Destroy(_material);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 44c60e0af0b15b8419fb621925bc41f4
|
||||||
86
Runtime/UTS Renderer/UTSToonmapping/UTSToonmapping.shader
Normal file
86
Runtime/UTS Renderer/UTSToonmapping/UTSToonmapping.shader
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
Shader "Hidden/Shader/UTSTonemapping"
|
||||||
|
{
|
||||||
|
Properties
|
||||||
|
{
|
||||||
|
// This property is necessary to make the CommandBuffer.Blit bind the source texture to _MainTex
|
||||||
|
_MainTex("Main Texture", 2DArray) = "grey" {}
|
||||||
|
}
|
||||||
|
|
||||||
|
HLSLINCLUDE
|
||||||
|
|
||||||
|
#pragma target 4.5
|
||||||
|
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
|
||||||
|
|
||||||
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||||
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
||||||
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||||
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl"
|
||||||
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl"
|
||||||
|
|
||||||
|
struct Attributes
|
||||||
|
{
|
||||||
|
uint vertexID : SV_VertexID;
|
||||||
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Varyings
|
||||||
|
{
|
||||||
|
float4 positionCS : SV_POSITION;
|
||||||
|
float2 texcoord : TEXCOORD0;
|
||||||
|
UNITY_VERTEX_OUTPUT_STEREO
|
||||||
|
};
|
||||||
|
|
||||||
|
Varyings Vert(Attributes input)
|
||||||
|
{
|
||||||
|
Varyings output;
|
||||||
|
UNITY_SETUP_INSTANCE_ID(input);
|
||||||
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||||
|
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
|
||||||
|
output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEXTURE2D_X(_MainTex);
|
||||||
|
|
||||||
|
inline float3 UTSToonmap(float3 x)
|
||||||
|
{
|
||||||
|
// See https://www.desmos.com/calculator/j4tpqazyfw
|
||||||
|
return (x * (2.63 * x + 0.03)) / (x * (2.11 * x + 0.72) + 0.31);
|
||||||
|
}
|
||||||
|
|
||||||
|
float4 CustomPostProcess(Varyings input) : SV_Target
|
||||||
|
{
|
||||||
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||||
|
|
||||||
|
// Note that if HDUtils.DrawFullScreen is not used to render the post process, you don't need to call ClampAndScaleUVForBilinearPostProcessTexture.
|
||||||
|
float3 sourceColor = SAMPLE_TEXTURE2D_X(_MainTex, s_linear_clamp_sampler, ClampAndScaleUVForBilinearPostProcessTexture(input.texcoord.xy)).rgb;
|
||||||
|
|
||||||
|
float whiteScale = 1.0 / UTSToonmap(5.3);
|
||||||
|
float3 color = UTSToonmap(sourceColor * whiteScale);
|
||||||
|
color *= whiteScale;
|
||||||
|
|
||||||
|
return float4(color, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ENDHLSL
|
||||||
|
|
||||||
|
SubShader
|
||||||
|
{
|
||||||
|
Tags{ "RenderPipeline" = "HDRenderPipeline" }
|
||||||
|
Pass
|
||||||
|
{
|
||||||
|
Name "UTSToonmapping"
|
||||||
|
|
||||||
|
ZWrite Off
|
||||||
|
ZTest Always
|
||||||
|
Blend Off
|
||||||
|
Cull Off
|
||||||
|
|
||||||
|
HLSLPROGRAM
|
||||||
|
#pragma fragment CustomPostProcess
|
||||||
|
#pragma vertex Vert
|
||||||
|
ENDHLSL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Fallback Off
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7f1e1745716de164d8f4837e7ee587e6
|
||||||
|
ShaderImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
defaultTextures: []
|
||||||
|
nonModifiableTextures: []
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user