Update custom pass to global custom pass
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
using UnityObject = UnityEngine.Object;
|
||||
using System.Linq;
|
||||
|
||||
#if HDRP_IS_INSTALLED_FOR_UTS
|
||||
@@ -36,7 +32,7 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
internal HDAdditionalLightData m_targetBoxLight;
|
||||
|
||||
[SerializeField]
|
||||
internal bool m_FollowGameObjectPosition = false;
|
||||
internal bool m_FollowGameObjectPosition = false;
|
||||
|
||||
[SerializeField]
|
||||
internal bool m_FollowGameObjectRotation = false;
|
||||
@@ -106,18 +102,19 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
return;
|
||||
}
|
||||
|
||||
for (int ii = 0; ii < m_Renderers.Length; ii++)
|
||||
// TODO: Set rendering layer mask when property changed.
|
||||
for (var ii = 0; ii < m_Renderers.Length; ii++)
|
||||
{
|
||||
m_Renderers[ii].renderingLayerMask &= 0xffffff00;
|
||||
m_Renderers[ii].renderingLayerMask |= (uint)m_targetBoxLight.lightlayersMask;
|
||||
}
|
||||
if ( /* m_targetBoxLight != null && */ m_GameObjects != null && m_GameObjects.Length > 0 && m_GameObjects[0] != null )
|
||||
if ( /* m_targetBoxLight != null && */ m_GameObjects != null && m_GameObjects.Length > 0 && m_GameObjects[0] != null)
|
||||
{
|
||||
if (m_FollowGameObjectPosition )
|
||||
if (m_FollowGameObjectPosition)
|
||||
{
|
||||
m_targetBoxLight.transform.position = m_GameObjects[0].transform.position + m_PositionOffset;
|
||||
}
|
||||
if (m_FollowGameObjectRotation )
|
||||
if (m_FollowGameObjectRotation)
|
||||
{
|
||||
m_targetBoxLight.transform.rotation = m_GameObjects[0].transform.rotation * m_RotationOffset;
|
||||
}
|
||||
@@ -163,22 +160,22 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
|
||||
}
|
||||
|
||||
internal static GameObject CreateBoxLight(GameObject[] gameObjects)
|
||||
internal static GameObject CreateBoxLight(GameObject[] gameObjects)
|
||||
{
|
||||
if (gameObjects == null || gameObjects[0] == null )
|
||||
if (gameObjects == null || gameObjects[0] == null)
|
||||
{
|
||||
Debug.LogError("Please, select a GameObject you want a Box Light to follow.");
|
||||
return null;
|
||||
}
|
||||
var gameObjectName = "Box Light for " + gameObjects[0].name;
|
||||
GameObject lightGameObject = new GameObject(gameObjectName);
|
||||
var lightGameObject = new GameObject(gameObjectName);
|
||||
#if UNITY_EDITOR
|
||||
Undo.RegisterCreatedObjectUndo(lightGameObject, "Created Boxlight adjustment");
|
||||
#endif
|
||||
HDAdditionalLightData hdLightData = lightGameObject.AddHDLight(HDLightTypeAndShape.BoxSpot);
|
||||
var hdLightData = lightGameObject.AddHDLight(LightType.Box);
|
||||
// light size
|
||||
hdLightData.SetBoxSpotSize(new Vector2(10.0f, 10.0f)); // Size should be culculated with more acculacy?
|
||||
BoxLightAdjustment boxLightAdjustment = lightGameObject.GetComponent<BoxLightAdjustment>();
|
||||
var boxLightAdjustment = lightGameObject.GetComponent<BoxLightAdjustment>();
|
||||
if (boxLightAdjustment == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
@@ -229,17 +226,17 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
if (EditorApplication.isCompiling)
|
||||
return;
|
||||
#endif
|
||||
if (m_GameObjects == null )
|
||||
if (m_GameObjects == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int objCount = m_GameObjects.Length;
|
||||
int rendererCount = 0;
|
||||
var objCount = m_GameObjects.Length;
|
||||
var rendererCount = 0;
|
||||
|
||||
List<Renderer> rendererList = new List<Renderer>();
|
||||
for (int ii = 0; ii < objCount; ii++)
|
||||
var rendererList = new List<Renderer>();
|
||||
for (var ii = 0; ii < objCount; ii++)
|
||||
{
|
||||
if (m_GameObjects[ii] == null )
|
||||
if (m_GameObjects[ii] == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -251,20 +248,20 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
rendererCount++;
|
||||
rendererList.Add(renderer);
|
||||
}
|
||||
GameObject[] childGameObjects = m_GameObjects[ii].GetComponentsInChildren<Transform>().Select(t => t.gameObject).ToArray();
|
||||
int childCount = childGameObjects.Length;
|
||||
for (int jj = 0; jj < childCount; jj++)
|
||||
var childGameObjects = m_GameObjects[ii].GetComponentsInChildren<Transform>().Select(t => t.gameObject).ToArray();
|
||||
var childCount = childGameObjects.Length;
|
||||
for (var jj = 0; jj < childCount; jj++)
|
||||
{
|
||||
if (m_GameObjects[ii] == childGameObjects[jj])
|
||||
continue;
|
||||
var modelToonEvAdjustment = childGameObjects[jj].GetComponent<BoxLightAdjustment>();
|
||||
if ( modelToonEvAdjustment != null )
|
||||
if (modelToonEvAdjustment != null)
|
||||
{
|
||||
|
||||
break;
|
||||
}
|
||||
renderer = childGameObjects[jj].GetComponent<Renderer>();
|
||||
if ( renderer != null )
|
||||
if (renderer != null)
|
||||
{
|
||||
rendererList.Add(renderer);
|
||||
rendererCount++;
|
||||
@@ -278,12 +275,12 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
|
||||
}
|
||||
}
|
||||
if (m_targetBoxLight != null && objCount > 0 )
|
||||
if (m_targetBoxLight != null && objCount > 0)
|
||||
{
|
||||
m_PositionOffset = m_targetBoxLight.transform.position - m_GameObjects[0].transform.position;
|
||||
m_RotationOffset = Quaternion.Inverse(m_GameObjects[0].transform.rotation) * m_targetBoxLight.transform.rotation;
|
||||
}
|
||||
|
||||
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
using Unity.Toonshader;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
|
||||
public class HairShadowPass : DrawRenderersCustomPass
|
||||
{
|
||||
const string kHairShadowDistancePropName = "_HairShadowDistance";
|
||||
const string kHairShadowDistanceScalePropName = "_HairShadowDistanceScaleFactor";
|
||||
const string kHairShadowDepthBiasPropName = "_HairShadowDepthBias";
|
||||
const string kHairShadowFadeInPropName = "_HairShadowFadeInDistance";
|
||||
const string kHairShadowFadeOutPropName = "_HairShadowFadeOutDistance";
|
||||
|
||||
const string shaderPath = "Renderers/HairShadowRenderer";
|
||||
const string outputRT = "_HairShadowTex";
|
||||
const string passName = "HairShadow";
|
||||
|
||||
RTHandle outputRTHandle;
|
||||
bool m_Initialized = false;
|
||||
int passIndex = -1;
|
||||
//public List<Renderer> hairRenderers; //Change to layer mask
|
||||
|
||||
|
||||
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
|
||||
{
|
||||
overrideMaterial = CoreUtils.CreateEngineMaterial(shaderPath);
|
||||
|
||||
if (!overrideMaterial)
|
||||
{
|
||||
Debug.LogWarning($"Shader {shaderPath} not fond");
|
||||
return;
|
||||
}
|
||||
|
||||
overrideMode = OverrideMaterialMode.Material;
|
||||
passIndex = overrideMaterial.FindPass(passName);
|
||||
outputRTHandle = RTHandles.Alloc(Screen.width, Screen.height, colorFormat: UnityEngine.Experimental.Rendering.GraphicsFormat.R16G16B16A16_SFloat, filterMode: FilterMode.Bilinear, wrapMode: TextureWrapMode.Clamp, name: $"{outputRT}");
|
||||
Shader.EnableKeyword("_HAIR_SHADOWS");
|
||||
|
||||
base.Setup(renderContext, cmd);
|
||||
|
||||
m_Initialized = true;
|
||||
}
|
||||
|
||||
protected override void Execute(CustomPassContext ctx)
|
||||
{
|
||||
if (!m_Initialized)
|
||||
Setup(ctx.renderContext, ctx.cmd);
|
||||
|
||||
var utsRenderer = ctx.hdCamera.volumeStack.GetComponent<UTSRenderer>();
|
||||
if (utsRenderer == null)
|
||||
{
|
||||
Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!utsRenderer.enableHairShadow.value || !utsRenderer.enable.value)
|
||||
{
|
||||
Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!overrideMaterial)
|
||||
{
|
||||
Debug.LogError("You need to a material to render the hair buffer");
|
||||
//enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
SetShadowParameter(utsRenderer);
|
||||
|
||||
var cmd = ctx.cmd;
|
||||
// Copy custom buffer to our RT
|
||||
if (null != outputRTHandle)
|
||||
{
|
||||
//Set Global Texture using outputRT name
|
||||
cmd.SetGlobalTexture(outputRT, outputRTHandle);
|
||||
}
|
||||
|
||||
base.Execute(ctx);
|
||||
HDUtils.BlitCameraTexture(cmd, ctx.cameraColorBuffer, outputRTHandle, 0, true);
|
||||
}
|
||||
|
||||
private static void SetShadowParameter(UTSRenderer utsRenderer)
|
||||
{
|
||||
Shader.SetGlobalFloat(kHairShadowDistancePropName, utsRenderer.shadowDistance.value);
|
||||
Shader.SetGlobalFloat(kHairShadowDistanceScalePropName, utsRenderer.shadowDistanceScale.value);
|
||||
Shader.SetGlobalFloat(kHairShadowDepthBiasPropName, utsRenderer.shadowDepthBias.value);
|
||||
Shader.SetGlobalFloat(kHairShadowFadeInPropName, utsRenderer.shadowFadeIn.value);
|
||||
Shader.SetGlobalFloat(kHairShadowFadeOutPropName, utsRenderer.shadowFadeOut.value);
|
||||
}
|
||||
|
||||
protected override void Cleanup()
|
||||
{
|
||||
Clear();
|
||||
base.Cleanup();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
Shader.DisableKeyword("_HAIR_SHADOWS");
|
||||
|
||||
if (outputRTHandle != null)
|
||||
{
|
||||
outputRTHandle.Release();
|
||||
outputRTHandle = null;
|
||||
}
|
||||
|
||||
m_Initialized = false;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e13d0e716db95234cad6baafb57328fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Runtime/HDRP/Models.meta
Normal file
8
Runtime/HDRP/Models.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c01a4137078c4644a387ab35f8457c0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Runtime/HDRP/Models/UTSRenderPassSetting.cs
Normal file
46
Runtime/HDRP/Models/UTSRenderPassSetting.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.Toonshader
|
||||
{
|
||||
[Serializable]
|
||||
public struct UTSOutlineSetting
|
||||
{
|
||||
public bool enable;
|
||||
public LayerMask layerMask;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct UtsHairShadowSetting
|
||||
{
|
||||
public bool enable;
|
||||
public LayerMask casterLayerMask;
|
||||
}
|
||||
|
||||
[CreateAssetMenu(fileName = "UTSRenderSetting", menuName = "UTS/RenderSetting")]
|
||||
public class UTSRenderPassSetting : ScriptableObject
|
||||
{
|
||||
public const string RENDERER_SETTING_ASSET_PATH = "Packages/com.misaki.hdrp-toon/Runtime/HDRP/Resources/UTSRenderSetting.asset";
|
||||
|
||||
public UTSOutlineSetting outlineSetting;
|
||||
public UtsHairShadowSetting hairShadowSetting;
|
||||
|
||||
internal static UTSRenderPassSetting GetOrCreateSettings()
|
||||
{
|
||||
var settings = AssetDatabase.LoadAssetAtPath<UTSRenderPassSetting>(RENDERER_SETTING_ASSET_PATH);
|
||||
if (settings == null)
|
||||
{
|
||||
settings = CreateInstance<UTSRenderPassSetting>();
|
||||
AssetDatabase.CreateAsset(settings, RENDERER_SETTING_ASSET_PATH);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static SerializedObject GetSerializedSettings()
|
||||
{
|
||||
return new(GetOrCreateSettings());
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/HDRP/Models/UTSRenderPassSetting.cs.meta
Normal file
2
Runtime/HDRP/Models/UTSRenderPassSetting.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d19dc5e91de57e46b4b146b129d4c87
|
||||
@@ -1,30 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class ObjectShadingHelper : MonoBehaviour
|
||||
{
|
||||
public Material material;
|
||||
|
||||
public Transform objectCenter;
|
||||
|
||||
public Transform[] shadowPosition = new Transform[4];
|
||||
// Start is called before the first frame update
|
||||
void OnEbale()
|
||||
{
|
||||
if (objectCenter = null)
|
||||
{
|
||||
objectCenter = transform;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (material == null)
|
||||
return;
|
||||
|
||||
material.SetVector("_ObjectCenter", objectCenter.position);
|
||||
}
|
||||
}
|
||||
8
Runtime/HDRP/Resources.meta
Normal file
8
Runtime/HDRP/Resources.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8d9ae1381ecb2141b4a741976d1c827
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Runtime/HDRP/Resources/UTSRenderSetting.asset
Normal file
24
Runtime/HDRP/Resources/UTSRenderSetting.asset
Normal file
@@ -0,0 +1,24 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0d19dc5e91de57e46b4b146b129d4c87, type: 3}
|
||||
m_Name: UTSRenderSetting
|
||||
m_EditorClassIdentifier:
|
||||
outlineSetting:
|
||||
enable: 1
|
||||
layerMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 72
|
||||
hairShadowSetting:
|
||||
enable: 1
|
||||
casterLayerMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 8
|
||||
8
Runtime/HDRP/Resources/UTSRenderSetting.asset.meta
Normal file
8
Runtime/HDRP/Resources/UTSRenderSetting.asset.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37f2c2f5a413a874b9ec560b74248a71
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,3 @@
|
||||
#define unity_ColorSpaceDielectricSpec half4(0.04, 0.04, 0.04, 1 - 0.04)
|
||||
|
||||
// _preIntegratedFGD and _CubemapLD are unique for each BRDF
|
||||
IndirectLighting EvaluateBSDF_Env(LightLoopContext lightLoopContext,
|
||||
float3 V, PositionInputs posInput,
|
||||
@@ -171,7 +169,7 @@ float3 ComputeIndirectDiffuse(PositionInputs posInput, BSDFData bsdfData, float3
|
||||
}
|
||||
|
||||
//Compelete the indirect lighting
|
||||
indirectDiffuse = indirectDiffuse * bsdfData.diffuseColor * _BaseColor;
|
||||
indirectDiffuse = indirectDiffuse * bsdfData.diffuseColor.rgb * _BaseColor.rgb;
|
||||
|
||||
//SSAO
|
||||
if(_ReceivesSSAO == 1)
|
||||
@@ -204,8 +202,8 @@ float3 ComputeIndirectSpecular(LightLoopContext lightLoopContext, PositionInputs
|
||||
float NdotV = saturate(dot(bsdfData.normalWS, V));
|
||||
|
||||
indirectSpecular = SampleSkyTexture(reflect(-V, bsdfData.normalWS), mip, 0).rgb;
|
||||
float3 specColor = lerp(unity_ColorSpaceDielectricSpec, albedo, surfaceData.metallic);;
|
||||
float oneMinusReflectivity = unity_ColorSpaceDielectricSpec.a * (1 - surfaceData.metallic);
|
||||
float3 specColor = lerp(ColorSpaceDielectricSpec.rgb, albedo, surfaceData.metallic);
|
||||
float oneMinusReflectivity = ColorSpaceDielectricSpec.a * (1 - surfaceData.metallic);
|
||||
float grazingTerm = saturate((1 - bsdfData.perceptualRoughness) + (1 - oneMinusReflectivity));
|
||||
|
||||
//Reflection Probe
|
||||
|
||||
@@ -316,8 +316,8 @@ Shader "HDRP/Toon"
|
||||
_SDFNoseHighlightCoef("SDFNoseHighlightCoef", Range(0.0, 5.0)) = 1.25
|
||||
_SDFNoseHighlightSmoothRange("SDFNoseHighlightSmoothRange", Range(0.0, 0.1)) = 0.02
|
||||
|
||||
// Hair Shadow
|
||||
[Toggle(_)] _Is_ReceiveHairShadow("_Is_ReceiveHairShadow", Float) = 0
|
||||
// Hair Shadow
|
||||
[Toggle(_)] _Is_ReceiveHairShadow("Is_ReceiveHairShadow", Float) = 0
|
||||
|
||||
_ShadowBias("ShadowBias", Range(0.0, 5.0)) = 0.0
|
||||
|
||||
@@ -326,11 +326,11 @@ Shader "HDRP/Toon"
|
||||
|
||||
// Eye Parallax
|
||||
[Toggle(_)] _Is_EyeParallax("_Is_EyeParallax", Float) = 0
|
||||
_EyeParallaxAmount("_EyeParallaxAmount", Float) = 0.1
|
||||
_EyeParallaxAmount("EyeParallaxAmount", Float) = 0.1
|
||||
|
||||
// Eyebrow Seethrough
|
||||
[Togle(_)] _Is_EyebrowSeethrough("_Is_EyebrowSeethrough", Float) = 0
|
||||
_EyeBrowBlendingFactor("_EyeBrowBlendingFactor", Float) = 0.5
|
||||
_EyeBrowBlendingFactor("EyeBrowBlendingFactor", Float) = 0.5
|
||||
|
||||
//v.2.0.6
|
||||
_BaseColor_Step("BaseColor_Step", Range(0, 1)) = 0.5
|
||||
|
||||
@@ -33,6 +33,7 @@ struct UTSData
|
||||
fixed signMirror;
|
||||
};
|
||||
|
||||
//#define UTSDATA_ZERO_INITIALIZE (UTSData)
|
||||
|
||||
struct UTSLightData
|
||||
{
|
||||
@@ -42,6 +43,7 @@ struct UTSLightData
|
||||
float specularDimmer;
|
||||
float3 shadowTint;
|
||||
float penumbraTint;
|
||||
float shadowValue;
|
||||
};
|
||||
|
||||
struct UTSAggregateLighting
|
||||
@@ -325,5 +327,26 @@ float3 SampleBakedGI_UTS(float3 positionRWS, float3 normalWS, float2 uvStaticLig
|
||||
return bakeDiffuseLighting;
|
||||
}
|
||||
|
||||
float3 SampleBakedGI_UTS_OutLine(float3 positionRWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap)
|
||||
{
|
||||
float3 bakeDiffuseLighting = float3(0, 0, 0);
|
||||
float3 backBakeDiffuseLighting = float3(0, 0, 0);
|
||||
float3 backNormalWS = float3(0, 0, 0);
|
||||
|
||||
#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
|
||||
EvaluateLightmap(positionRWS, normalWS, backNormalWS, uvStaticLightmap, uvDynamicLightmap, bakeDiffuseLighting, backBakeDiffuseLighting);
|
||||
#elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
|
||||
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(positionRWS), normalWS, backNormalWS, GetWorldSpaceNormalizeViewDir(positionRWS), 0.0, bakeDiffuseLighting, backBakeDiffuseLighting);
|
||||
#else
|
||||
EvaluateLightProbeBuiltin(positionRWS, normalWS, backNormalWS, bakeDiffuseLighting, backBakeDiffuseLighting);
|
||||
#if defined(SHADER_STAGE_RAY_TRACING)
|
||||
bakeDiffuseLighting *= _RayTracingAmbientProbeDimmer;
|
||||
backBakeDiffuseLighting *= _RayTracingAmbientProbeDimmer;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return bakeDiffuseLighting;
|
||||
}
|
||||
|
||||
|
||||
#endif //#ifndef UCTS_HDRP_INCLUDED
|
||||
@@ -152,10 +152,10 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
//float4 unity_AmbientEquator = float4(0.05, 0.05, 0.05, 1.0); //Todo.
|
||||
//v.2.0.9
|
||||
//float3 envLightSource_GradientEquator = unity_AmbientEquator.rgb > 0.05 ? unity_AmbientEquator.rgb : half3(0.05, 0.05, 0.05);
|
||||
float3 envLightSource_GradientEquator = ShadeSH9(float4(0, 1, 0, 0)) * 10.0;
|
||||
float3 envLightSource_GradientEquator = ShadeSH9(float4(0, 1, 0, 0));
|
||||
float3 envLightSource_SkyboxIntensity = max(
|
||||
SampleBakedGI_UTS(objPos, float3(0.0, 0.0, 0.0), input.texCoord1.xy, input.texCoord2.xy, true),
|
||||
SampleBakedGI_UTS(objPos, float3(0.0, -1.0, 0.0), input.texCoord1.xy, input.texCoord2.xy, true)
|
||||
SampleBakedGI_UTS_OutLine(objPos.xyz, float3(0.0, 0.0, 0.0), input.texCoord1.xy, input.texCoord2.xy),
|
||||
SampleBakedGI_UTS_OutLine(objPos.xyz, float3(0.0, -1.0, 0.0), input.texCoord1.xy, input.texCoord2.xy)
|
||||
).rgb;
|
||||
float3 ambientSkyColor = envLightSource_SkyboxIntensity.rgb > 0.0 ? envLightSource_SkyboxIntensity : envLightSource_GradientEquator;
|
||||
ambientSkyColor *= GetCurrentExposureMultiplier() * 5.0f;
|
||||
|
||||
@@ -31,13 +31,13 @@
|
||||
float3 FinalNormal;
|
||||
if(_UseSmoothedNormal == 1)
|
||||
{
|
||||
float3 normal = float3(inputMesh.uv1, 0);
|
||||
normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
|
||||
FinalNormal = mul(normal, tangentTransform);
|
||||
float3 normal = float3(inputMesh.uv1, 0);
|
||||
normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
|
||||
FinalNormal = mul(normal, tangentTransform);
|
||||
}
|
||||
else
|
||||
{
|
||||
FinalNormal = lerp(inputMesh.normalOS, _BakedNormalDir, _Is_BakedNormal);
|
||||
FinalNormal = lerp(inputMesh.normalOS, _BakedNormalDir, _Is_BakedNormal);
|
||||
}
|
||||
|
||||
//v2.0.4
|
||||
@@ -50,7 +50,7 @@
|
||||
float3 normal = mul((float3x3)transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)), signVar * normalize(inputMesh.positionOS));
|
||||
#endif
|
||||
// screen space width
|
||||
float2 extendDir = normalize(TransformWViewToHClip(normal));
|
||||
float2 extendDir = normalize(TransformWViewToHClip(normal).xy);
|
||||
float4 clipPos = UnityObjectToClipPos(inputMesh.positionOS);
|
||||
clipPos.xy += extendDir * min(_Outline_MaxWidth, (clipPos.w * Set_Outline_Width));
|
||||
clipPos.z = clipPos.z + _Offset_Z * _ClipCameraPos.z;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#define unity_ColorSpaceDielectricSpec half4(0.22, 0.22, 0.22, 0.779)
|
||||
#define ColorSpaceDielectricSpec half4(0.22, 0.22, 0.22, 0.779)
|
||||
|
||||
float3 schlick(float f0, float hl) {
|
||||
real x = 1.0 - hl;
|
||||
@@ -9,7 +9,7 @@ float3 schlick(float f0, float hl) {
|
||||
|
||||
float3 SpecularColor(float3 albedo, float metalic)
|
||||
{
|
||||
float3 specColor = lerp(unity_ColorSpaceDielectricSpec, albedo, metalic);
|
||||
float3 specColor = lerp(ColorSpaceDielectricSpec.rgb, albedo, metalic);
|
||||
return specColor;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ float3 ComputeSpecularTerm(float3 V, float3 L, BSDFData bsdfData)
|
||||
float NdotH = saturate(dot(N, H));
|
||||
float HdotL = saturate(dot(H, L));
|
||||
|
||||
float3 F = schlick(bsdfData.fresnel0, HdotL);
|
||||
float3 F = schlick(bsdfData.fresnel0.x, HdotL);
|
||||
|
||||
float partLambdaV;
|
||||
float3 DV = 0;
|
||||
@@ -80,7 +80,7 @@ float3 ComputeSpecularTerm(float3 V, float3 L, BSDFData bsdfData)
|
||||
float specularExponent = RoughnessToBlinnPhongSpecularExponent(PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness));
|
||||
specTerm = pow(NdotH, 5.0 * specularExponent);
|
||||
specTerm = StepFeatherToon(specTerm, _ToonSpecularStep, _ToonSpecularFeather);
|
||||
return specTerm * unity_ColorSpaceDielectricSpec * clampedNdotL;
|
||||
return specTerm * ColorSpaceDielectricSpec.rgb * clampedNdotL;
|
||||
#endif
|
||||
|
||||
specTerm = DV * F;
|
||||
@@ -132,8 +132,8 @@ half3 FitWithCurveApprox(half NdotL, half Curvature)
|
||||
float2 right_uv = float2(1 - UV.x, UV.y);
|
||||
rSDF_Tex = SAMPLE_TEXTURE2D(_SDFShadowTex, sampler_SDFShadowTex, right_uv);
|
||||
|
||||
leftVector = normalize(mul(UNITY_MATRIX_M, float3(1, 0, 0)).xz);
|
||||
forwardVector = normalize(mul(UNITY_MATRIX_M, float3(0, 0, 1)).xz);
|
||||
leftVector = normalize(mul(UNITY_MATRIX_M, float4(1, 0, 0, 0)).xz);
|
||||
forwardVector = normalize(mul(UNITY_MATRIX_M, float4(0, 0, 1, 0)).xz);
|
||||
}
|
||||
|
||||
// Return 1 -> right side
|
||||
@@ -165,26 +165,11 @@ half3 FitWithCurveApprox(half NdotL, half Curvature)
|
||||
|
||||
float SDFMask(float angle, float tex_direct)
|
||||
{
|
||||
float SDFMask = 0;
|
||||
float smoothGamma = _SDFSmoothGamma / 10.0f;
|
||||
float shadowLevel = _SDFShadowLevel / 10.0f;
|
||||
|
||||
float isShadow = smoothstep(tex_direct - smoothGamma, tex_direct + smoothGamma, angle - shadowLevel);
|
||||
//float bias = saturate(smoothstep(0, _SDFShadowLevel , (angle - tex_direct)));
|
||||
|
||||
//if(angle > 0.99)
|
||||
//{
|
||||
// SDFMask = lerp(0, 1, bias) * saturate(angle);
|
||||
//}
|
||||
|
||||
//if(isShadow > 0.95)
|
||||
//{
|
||||
// SDFMask = lerp(0, 1, bias) * saturate(isShadow);
|
||||
//}
|
||||
|
||||
////float v = SDFMask - 0.5;
|
||||
////SDFMask = saturate(v / (fwidth(v) + HALF_MIN));
|
||||
return isShadow;
|
||||
float SDFMask = smoothstep(tex_direct - smoothGamma, tex_direct + smoothGamma, angle - shadowLevel);
|
||||
return SDFMask;
|
||||
}
|
||||
|
||||
float SDFNoseHighlight(float angle,float tex_value, bool rightside, float2 UV)
|
||||
@@ -196,7 +181,7 @@ half3 FitWithCurveApprox(half NdotL, half Curvature)
|
||||
float cutU = UV.x;
|
||||
|
||||
float uvMask=lerp(cutU, 1 - cutU, rightside);//discard half of the sdf we sampled (Only one side of highlight wanted)
|
||||
float lightAtten = pow(angle - (_SDFShadowLevel / 10.0f), 0.8);
|
||||
float lightAtten = pow(max(0, angle - (_SDFShadowLevel / 10.0f)), 0.8);
|
||||
|
||||
return smoothstep(lightAtten-_SDFNoseHighlightSmoothRange,lightAtten+_SDFNoseHighlightSmoothRange , uvMask * tex_value) * tex_value; // Safeguard, return 0 when tex_value = 0
|
||||
}
|
||||
|
||||
@@ -304,8 +304,9 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
ZERO_INITIALIZE(UTSAggregateLighting, utsAggregateLighting);
|
||||
|
||||
UTSLightData customMainLight;
|
||||
UTSLightData mainPunctualLight;
|
||||
mainPunctualLight.lightColor = float3(0, 0, 0);
|
||||
customMainLight.shadowValue = 1.0f;
|
||||
//UTSLightData mainPunctualLight;
|
||||
//mainPunctualLight.lightColor = float3(0, 0, 0);
|
||||
|
||||
#define UNITY_PROJ_COORD(a) a
|
||||
#define UNITY_SAMPLE_SCREEN_SHADOW(tex, uv) tex2Dproj( tex, UNITY_PROJ_COORD(uv) ).r
|
||||
@@ -350,13 +351,13 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
float3 lightColor = ApplyCurrentExposureMultiplier(lightData.color);
|
||||
float3 lightDirection = -lightData.forward;
|
||||
|
||||
#ifndef LIGHT_EVALUATION_NO_COOKIE
|
||||
#ifndef LIGHT_EVALUATION_NO_COOKIE
|
||||
if (lightData.cookieMode != COOKIEMODE_NONE)
|
||||
{
|
||||
float3 lightToSample = input.positionRWS - lightData.positionRWS;
|
||||
lightColor *= EvaluateCookie_Directional(context, lightData, lightToSample);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
UTSLightData utsLightData;
|
||||
utsLightData.lightDirection = lightDirection;
|
||||
@@ -366,18 +367,20 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
utsLightData.shadowTint = lightData.shadowTint;
|
||||
utsLightData.penumbraTint = lightData.penumbraTint;
|
||||
|
||||
customMainLight = utsLightData;
|
||||
|
||||
// Evaluate sun shadows.
|
||||
if (_DirectionalShadowIndex >= 0)
|
||||
{
|
||||
DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex];
|
||||
#if defined(SCREEN_SPACE_SHADOWS_ON) && !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(UTS_USE_RAYTRACING_SHADOW)
|
||||
#if defined(SCREEN_SPACE_SHADOWS_ON) && !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(UTS_USE_RAYTRACING_SHADOW)
|
||||
if (UtsUseScreenSpaceShadow(light, bsdfData.normalWS))
|
||||
{
|
||||
// HDRP Contact Shadow
|
||||
context.shadowValue = GetScreenSpaceColorShadow(posInput, light.screenSpaceShadowIndex).SHADOW_TYPE_SWIZZLE;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
// TODO: this will cause us to load from the normal buffer first. Does this cause a performance problem?
|
||||
float3 L = -light.forward;
|
||||
@@ -388,7 +391,7 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
!ShouldEvaluateThickObjectTransmission(V, L, preLightData, bsdfData, light.shadowIndex))
|
||||
{
|
||||
|
||||
#if defined(UTS_USE_RAYTRACING_SHADOW)
|
||||
#if defined(UTS_USE_RAYTRACING_SHADOW)
|
||||
{
|
||||
/*
|
||||
struct PositionInputs
|
||||
@@ -406,37 +409,37 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
float r = UNITY_SAMPLE_SCREEN_SHADOW(_RaytracedHardShadow, float4(posInput.positionNDC.xy, lightDirection * _ShadowBias, 1));
|
||||
context.shadowValue = r;
|
||||
}
|
||||
#else
|
||||
#else
|
||||
{
|
||||
context.shadowValue = GetDirectionalShadowAttenuation(context.shadowContext,
|
||||
posInput.positionSS, posInput.positionWS + lightDirection * _ShadowBias, GetNormalForShadowBias(bsdfData),
|
||||
light.shadowIndex, L);
|
||||
|
||||
}
|
||||
#endif // UTS_USE_RAYTRACING_SHADOW
|
||||
#endif // UTS_USE_RAYTRACING_SHADOW
|
||||
|
||||
|
||||
}
|
||||
#if defined (UTS_USE_RAYTRACING_SHADOW)
|
||||
#if defined (UTS_USE_RAYTRACING_SHADOW)
|
||||
else
|
||||
{
|
||||
float r = UNITY_SAMPLE_SCREEN_SHADOW(_RaytracedHardShadow, float4(posInput.positionNDC.xy, lightDirection * _ShadowBias, 1));
|
||||
context.shadowValue = r;
|
||||
}
|
||||
#endif // UTS_USE_RAYTRACING_SHADOW
|
||||
#endif // UTS_USE_RAYTRACING_SHADOW
|
||||
}
|
||||
|
||||
context.shadowValue = lerp(1, context.shadowValue, lightData.shadowDimmer);
|
||||
|
||||
customMainLight.shadowValue = context.shadowValue;
|
||||
}
|
||||
|
||||
#if defined(UTS_DEBUG_SELFSHADOW)
|
||||
#if defined(UTS_DEBUG_SELFSHADOW)
|
||||
if (_DirectionalShadowIndex >= 0)
|
||||
finalColor = UTS_SelfShdowMainLight(context, input, _DirectionalShadowIndex);
|
||||
#else
|
||||
#else
|
||||
UTS_MainLight(context, input, utsLightData, surfaceData, bsdfData, inverseClipping, channelAlpha, utsData, utsAggregateLighting);
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
int i = 0; // Declare once to avoid the D3D11 compiler warning.
|
||||
@@ -455,11 +458,11 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
utsLightData.shadowTint = _DirectionalLightDatas[i].shadowTint;
|
||||
utsLightData.penumbraTint = _DirectionalLightDatas[i].penumbraTint;
|
||||
|
||||
#if defined(UTS_DEBUG_SELFSHADOW)
|
||||
#if defined(UTS_DEBUG_SELFSHADOW)
|
||||
|
||||
#else
|
||||
#else
|
||||
UTS_OtherLights(context, input, utsLightData, surfaceData, bsdfData, 0, i_normalDir, notDirectional, channelAlpha, utsAggregateLighting);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -474,14 +477,14 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
{
|
||||
uint lightCount, lightStart;
|
||||
|
||||
#ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
|
||||
#ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
|
||||
GetCountAndStart(posInput, LIGHTCATEGORY_PUNCTUAL, lightStart, lightCount);
|
||||
#else // LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
|
||||
#else // LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
|
||||
lightCount = _PunctualLightCount;
|
||||
lightStart = 0;
|
||||
#endif
|
||||
#endif
|
||||
bool fastPath = false;
|
||||
#if SCALARIZE_LIGHT_LOOP
|
||||
#if SCALARIZE_LIGHT_LOOP
|
||||
uint lightStartLane0;
|
||||
fastPath = IsFastPath(lightStart, lightStartLane0);
|
||||
|
||||
@@ -489,7 +492,7 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
{
|
||||
lightStart = lightStartLane0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -506,11 +509,11 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
while (v_lightListOffset < lightCount)
|
||||
{
|
||||
v_lightIdx = FetchIndex(lightStart, v_lightListOffset);
|
||||
#if SCALARIZE_LIGHT_LOOP
|
||||
#if SCALARIZE_LIGHT_LOOP
|
||||
uint s_lightIdx = ScalarizeElementIndex(v_lightIdx, fastPath);
|
||||
#else
|
||||
#else
|
||||
uint s_lightIdx = v_lightIdx;
|
||||
#endif
|
||||
#endif
|
||||
if (s_lightIdx == -1)
|
||||
break;
|
||||
|
||||
@@ -531,13 +534,6 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
float3 additionalLightColor = ApplyCurrentExposureMultiplier(lightColor.rgb) * lightColor.a;
|
||||
const float notDirectional = 1.0f;
|
||||
|
||||
float3 lightDirectionToObject;
|
||||
float4 distancesToObject; // {d, d^2, 1/d, d_proj}
|
||||
float3 objectCenter = (TransformObjectToWorld(float3(0, 0, 0)));
|
||||
GetPunctualLightVectors(objectCenter, s_lightData, lightDirectionToObject, distancesToObject);
|
||||
float4 lightColorToObject = EvaluateLight_Punctual(context, posInput, s_lightData, lightDirectionToObject, distancesToObject);
|
||||
float3 additionalLightColorToObject = ApplyCurrentExposureMultiplier(lightColorToObject.rgb) * lightColorToObject.a;
|
||||
|
||||
UTSLightData utsLightData;
|
||||
utsLightData.lightColor = additionalLightColor;
|
||||
utsLightData.lightDirection = lightDirection;
|
||||
@@ -546,23 +542,31 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
utsLightData.shadowTint = s_lightData.shadowTint;
|
||||
utsLightData.penumbraTint = s_lightData.penumbraTint;
|
||||
|
||||
if (length(utsLightData.lightColor) >= length(mainPunctualLight.lightColor))
|
||||
{
|
||||
//mainPunctualLight = utsLightData;
|
||||
mainPunctualLight.lightColor = additionalLightColorToObject;
|
||||
mainPunctualLight.lightDirection = lightDirectionToObject;
|
||||
}
|
||||
#if defined(UTS_DEBUG_SELFSHADOW)
|
||||
|
||||
#if defined(UTS_DEBUG_SELFSHADOW)
|
||||
|
||||
#else
|
||||
#else
|
||||
posInput.positionWS = posInput.positionWS + lightDirection * _ShadowBias;
|
||||
float shadow = EvaluateShadow_Punctual(context, posInput, s_lightData, builtinData, GetNormalForShadowBias(bsdfData), lightDirection, distances);
|
||||
context.shadowValue = shadow;
|
||||
posInput.positionWS = posInput.positionWS - lightDirection * _ShadowBias;
|
||||
|
||||
if (length(utsLightData.lightColor) >= length(customMainLight.lightColor))
|
||||
{
|
||||
float3 lightDirectionToObject;
|
||||
float4 distancesToObject; // {d, d^2, 1/d, d_proj}
|
||||
float3 objectCenter = (TransformObjectToWorld(float3(0, 0, 0)));
|
||||
GetPunctualLightVectors(objectCenter, s_lightData, lightDirectionToObject, distancesToObject);
|
||||
float4 lightColorToObject = EvaluateLight_Punctual(context, posInput, s_lightData, lightDirectionToObject, distancesToObject);
|
||||
float3 additionalLightColorToObject = ApplyCurrentExposureMultiplier(lightColorToObject.rgb) * lightColorToObject.a;
|
||||
|
||||
customMainLight = utsLightData;
|
||||
customMainLight.lightColor = additionalLightColorToObject;
|
||||
customMainLight.lightDirection = lightDirectionToObject;
|
||||
customMainLight.shadowValue = context.shadowValue;
|
||||
}
|
||||
|
||||
UTS_OtherLights(context, input, utsLightData, surfaceData, bsdfData, s_lightData.lightType, i_normalDir, notDirectional, channelAlpha, utsAggregateLighting);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
@@ -575,12 +579,12 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
{
|
||||
uint lightCount, lightStart;
|
||||
|
||||
#ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
|
||||
#ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
|
||||
GetCountAndStart(posInput, LIGHTCATEGORY_AREA, lightStart, lightCount);
|
||||
#else
|
||||
#else
|
||||
lightCount = _AreaLightCount;
|
||||
lightStart = _PunctualLightCount;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// COMPILER BEHAVIOR WARNING!
|
||||
// If rectangle lights are before line lights, the compiler will duplicate light matrices in VGPR because they are used differently between the two types of lights.
|
||||
@@ -645,13 +649,13 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
//Evaluate the shadow part
|
||||
float shadow;
|
||||
posInput.positionWS = posInput.positionWS + utsLightData.lightDirection * _ShadowBias;
|
||||
#if defined(SCREEN_SPACE_SHADOWS_ON) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
||||
#if defined(SCREEN_SPACE_SHADOWS_ON) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
||||
if ((s_lightData.screenSpaceShadowIndex & SCREEN_SPACE_SHADOW_INDEX_MASK) != INVALID_SCREEN_SPACE_SHADOW)
|
||||
{
|
||||
shadow = GetScreenSpaceShadow(posInput, s_lightData.screenSpaceShadowIndex);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
shadow = EvaluateShadow_RectArea(context, posInput, s_lightData, builtinData, GetNormalForShadowBias(bsdfData), normalize(s_lightData.positionRWS), length(s_lightData.positionRWS));
|
||||
}
|
||||
@@ -659,13 +663,13 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
posInput.positionWS = posInput.positionWS - lightDirection * _ShadowBias;
|
||||
}
|
||||
|
||||
#if defined(UTS_DEBUG_SELFSHADOW)
|
||||
#if defined(UTS_DEBUG_SELFSHADOW)
|
||||
|
||||
#else
|
||||
#else
|
||||
UTS_OtherLights(context, input, utsLightData, surfaceData, bsdfData, s_lightData.lightType, i_normalDir, notDirectional, channelAlpha, utsAggregateLighting);
|
||||
//utsAggregateLighting.directDiffuse += ltcValue.rgb * ltcValue.a * intensity * s_lightData.diffuseDimmer;
|
||||
//utsAggregateLighting.directDiffuse += intensity;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
if(s_lightData.lightType == GPULIGHTTYPE_RECTANGLE)
|
||||
@@ -829,7 +833,7 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif // SHADEROPTIONS_AREA_LIGHTS
|
||||
|
||||
#ifdef _EMISSIVE_SIMPLE
|
||||
float4 _Emissive_Tex_var = tex2D(_Emissive_Tex, TRANSFORM_TEX(Set_UV0, _Emissive_Tex));
|
||||
@@ -872,7 +876,8 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
//v.2.0.6: GI_Intensity with Intensity Multiplier Filter
|
||||
#endif
|
||||
|
||||
customMainLight = GetCustomMainLightData(builtinData, mainPunctualLight);
|
||||
// We directly calculate custome main light during the light loop in upper code to avoid extra calculation
|
||||
//customMainLight = GetCustomMainLightData(builtinData, mainPunctualLight);
|
||||
|
||||
#if _SDFShadow || _RECEIVE_HAIR_SHADOW
|
||||
float3 defaultLightDirection = normalize(UNITY_MATRIX_V[2].xyz + UNITY_MATRIX_V[1].xyz);
|
||||
@@ -888,6 +893,8 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
|
||||
float4 _1st_ShadeMap_var = lerp(SAMPLE_TEXTURE2D(_1st_ShadeMap, sampler_BaseColorMap,TRANSFORM_TEX(Set_UV0, _1st_ShadeMap)), _MainTex_var, _Use_BaseAs1st);
|
||||
float3 _1st_Shade_var = lerp((_1st_ShadeMap_var.rgb * _1st_ShadeColor.rgb), ((_1st_ShadeMap_var.rgb * _1st_ShadeColor.rgb) * lightColor), _Is_LightColor_1st_Shade);
|
||||
|
||||
float systemShadowValue = lerp(1.0f, saturate(customMainLight.shadowValue * 2.0f), _Set_SystemShadowsToBase);
|
||||
#endif
|
||||
|
||||
#ifdef _SDFShadow
|
||||
@@ -897,12 +904,11 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
bool rightside;
|
||||
float2 SDF_UV = TRANSFORM_TEX(Set_UV0, _BaseColorMap);
|
||||
float4 sdfRes = SDFResult(rightside, angle, customMainLight.lightDirection, SDF_UV);
|
||||
float sdfMask = SDFMask(angle, sdfRes.r);
|
||||
|
||||
utsAggregateLighting.directDiffuse = lerp(bsdfData.diffuseColor * _BaseColor * lightColor, _1st_Shade_var, sdfMask);
|
||||
utsAggregateLighting.directSpecular = lerp(utsAggregateLighting.directSpecular, 0, sdfMask);
|
||||
utsAggregateLighting.directDiffuse += _SDFNoseHighlightCoef * SDFNoseHighlight(angle, sdfRes.g, rightside, SDF_UV) * lightColor;
|
||||
//utsAggregateLighting.directDiffuse = lightColor;
|
||||
float sdfShadowValue = 1.0f - SDFMask(angle, sdfRes.r);
|
||||
|
||||
utsAggregateLighting.directDiffuse = lerp(_1st_Shade_var, bsdfData.diffuseColor * _BaseColor.rgb * lightColor, sdfShadowValue * systemShadowValue);
|
||||
utsAggregateLighting.directSpecular = lerp(0, utsAggregateLighting.directSpecular, sdfShadowValue * systemShadowValue);
|
||||
utsAggregateLighting.directSpecular += _SDFNoseHighlightCoef * SDFNoseHighlight(angle, sdfRes.g, rightside, SDF_UV) * lightColor;
|
||||
#endif
|
||||
|
||||
#if defined(_RECEIVE_HAIR_SHADOW) && defined(_HAIR_SHADOWS)
|
||||
@@ -911,19 +917,18 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
|
||||
if(hairShadowOpacity > 0)
|
||||
{
|
||||
float2 scrPos = input.positionSS.xy;
|
||||
float3 viewLightDir = TransformWorldToViewDir(customMainLight.lightDirection) / posInput.linearDepth; // / posInput.deviceDepth; when linearDepth grows large, the movement amount should be lower since we are getting further from the face.
|
||||
float shadowLength = _HairShadowDistance * 5.0 * max(0.5, posInput.linearDepth * _HairShadowDistanceScaleFactor);
|
||||
float2 samplingPoint = (scrPos + shadowLength * viewLightDir.xy ) * _ScreenSize.zw;
|
||||
float3 viewLightDir = TransformWorldToViewDir(customMainLight.lightDirection); // / posInput.deviceDepth; when linearDepth grows large, the movement amount should be lower since we are getting further from the face.
|
||||
float shadowLength = _HairShadowDistance * 5.0 * max(0.5, posInput.linearDepth * _HairShadowDistanceScaleFactor) / posInput.linearDepth;
|
||||
float2 samplingPoint = (input.positionSS.xy + shadowLength * viewLightDir.xy * (_ScreenSize.xy / float2 (1920.0f, 1080.0f))) * _ScreenSize.zw; // Use 1080p as the reference resolution to achieve consistent shadow lengths across various screen resolutions.
|
||||
// Then sample the hair buffer, to see if the fragment lands in shadow.
|
||||
float3 hairBuffer = SAMPLE_TEXTURE2D(_HairShadowTex, s_trilinear_clamp_sampler, samplingPoint);
|
||||
float4 hairBuffer = SAMPLE_TEXTURE2D(_HairShadowTex, s_trilinear_clamp_sampler, samplingPoint);
|
||||
float hairDepth = hairBuffer.r;
|
||||
float depthCorrect = posInput.deviceDepth <= hairDepth + _HairShadowDepthBias ? 1 : 0; // Hair < Face means Hair are closer to camera
|
||||
// Note that we have LinearEyeDepth in the buffer. A comparison of depth is needed so that we don't project the shadow of hair behind the face.
|
||||
float hairShadow = lerp(0,hairShadowOpacity,depthCorrect);
|
||||
|
||||
utsAggregateLighting.directDiffuse = lerp(utsAggregateLighting.directDiffuse, _1st_Shade_var, hairShadow);
|
||||
utsAggregateLighting.directSpecular = lerp(utsAggregateLighting.directSpecular, 0, hairShadow);
|
||||
utsAggregateLighting.directDiffuse = lerp(utsAggregateLighting.directDiffuse, _1st_Shade_var, hairShadow * systemShadowValue);
|
||||
utsAggregateLighting.directSpecular = lerp(utsAggregateLighting.directSpecular, 0, hairShadow * systemShadowValue);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -950,25 +955,7 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
outColor = float4(outColor.rgb, Set_Opacity * ApplyChannelAlpha(channelAlpha));
|
||||
#endif
|
||||
|
||||
#if defined(UTS_DEBUG_SHADOWMAP) || defined(UTS_DEBUG_SELFSHADOW)
|
||||
outColor.rgb = 1;
|
||||
#ifdef UTS_DEBUG_SELFSHADOW
|
||||
outColor.rgb = min(finalColor, outColor.rgb);
|
||||
#endif
|
||||
|
||||
#ifdef UTS_DEBUG_SHADOWMAP
|
||||
#ifdef UTS_DEBUG_SHADOWMAP_BINALIZATION
|
||||
outColor.rgb = min(context.shadowValue < 0.9f ? clamp(context.shadowValue - 0.2, 0.0, 0.9) : 1.0f, outColor.rgb);
|
||||
#else
|
||||
outColor.rgb = min(context.shadowValue, outColor.rgb);
|
||||
#endif
|
||||
#endif // ifdef UTS_DEBUG_SHADOWMAP
|
||||
#endif // defined(UTS_DEBUG_SHADOWMAP) || defined(UTS_DEBUG_SELFSHADOW)
|
||||
|
||||
#ifdef _EYEBROW_SEETHROUGH
|
||||
|
||||
|
||||
|
||||
// By Suomi, 20230915
|
||||
// The eyebrow should use transparent pass and utilize the hair depth texture we have from HairShadowPass
|
||||
float2 samplingPoint = posInput.positionNDC;
|
||||
@@ -989,9 +976,22 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
|
||||
|
||||
//outColor.rgb = float3(hDepth.rg * 5,0);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(UTS_DEBUG_SHADOWMAP) || defined(UTS_DEBUG_SELFSHADOW)
|
||||
outColor.rgb = 1;
|
||||
#ifdef UTS_DEBUG_SELFSHADOW
|
||||
outColor.rgb = min(finalColor, outColor.rgb);
|
||||
#endif
|
||||
|
||||
#ifdef UTS_DEBUG_SHADOWMAP
|
||||
#ifdef UTS_DEBUG_SHADOWMAP_BINALIZATION
|
||||
outColor.rgb = min(context.shadowValue < 0.9f ? clamp(context.shadowValue - 0.2, 0.0, 0.9) : 1.0f, outColor.rgb);
|
||||
#else
|
||||
outColor.rgb = min(context.shadowValue, outColor.rgb);
|
||||
#endif
|
||||
#endif // ifdef UTS_DEBUG_SHADOWMAP
|
||||
#endif // defined(UTS_DEBUG_SHADOWMAP) || defined(UTS_DEBUG_SELFSHADOW)
|
||||
|
||||
#ifdef _DEPTHOFFSET_ON
|
||||
outputDepth = posInput.deviceDepth;
|
||||
|
||||
@@ -12,21 +12,25 @@
|
||||
|
||||
void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLightData utsLightData, SurfaceData surfaceData, BSDFData bsdfData, out float inverseClipping, out float channelOutAlpha, out UTSData utsData, inout UTSAggregateLighting utsAggregateLighting)
|
||||
{
|
||||
inverseClipping = 0;
|
||||
channelOutAlpha = 1.0f;
|
||||
ZERO_INITIALIZE(UTSData, utsData);
|
||||
|
||||
// We dont have to calculate lighting here if we are using sdf shadow
|
||||
#ifndef _SDFShadow
|
||||
|
||||
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
|
||||
inverseClipping = 0;
|
||||
// input.positionSS is SV_Position
|
||||
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
|
||||
float2 screenUV = posInput.positionNDC;
|
||||
|
||||
|
||||
#ifdef VARYINGS_NEED_POSITION_WS
|
||||
#ifdef VARYINGS_NEED_POSITION_WS
|
||||
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
||||
#else
|
||||
#else
|
||||
// Unused
|
||||
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
|
||||
/* todo. these should be put int a struct */
|
||||
@@ -40,9 +44,9 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
|
||||
/* to here todo. these should be put int a struct */
|
||||
//v.2.0.4
|
||||
#ifdef _IS_TRANSCLIPPING_OFF
|
||||
//
|
||||
#elif _IS_TRANSCLIPPING_ON
|
||||
#ifdef _IS_TRANSCLIPPING_OFF
|
||||
//
|
||||
#elif _IS_TRANSCLIPPING_ON
|
||||
float4 _ClippingMask_var = SAMPLE_TEXTURE2D(_ClippingMask, sampler_BaseColorMap, TRANSFORM_TEX(Set_UV0, _ClippingMask));
|
||||
float Set_MainTexAlpha = _MainTex_var.a;
|
||||
float _IsBaseMapAlphaAsClippingMask_var = lerp(_ClippingMask_var.r, Set_MainTexAlpha, _IsBaseMapAlphaAsClippingMask);
|
||||
@@ -50,16 +54,16 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
float Set_Clipping = saturate((_Inverse_Clipping_var + _Clipping_Level));
|
||||
clip(Set_Clipping - 0.5);
|
||||
inverseClipping = _Inverse_Clipping_var;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
SHADOW_TYPE shadowAttenuation = lightLoopContext.shadowValue;
|
||||
//v.2.0.6
|
||||
//Minmimum value is same as the Minimum Feather's value with the Minimum Step's value as threshold.
|
||||
#if !defined (UTS_USE_RAYTRACING_SHADOW)
|
||||
#if !defined (UTS_USE_RAYTRACING_SHADOW)
|
||||
shadowAttenuation *= 2.0f;
|
||||
shadowAttenuation = saturate(shadowAttenuation);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
float3 mainLightDirection = utsLightData.lightDirection;
|
||||
float3 mainLightColor = utsLightData.lightColor;
|
||||
@@ -90,22 +94,22 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
float3 Set_BaseColor = lerp((_BaseColor.rgb * _MainTex_var.rgb), ((_BaseColor.rgb * _MainTex_var.rgb) * Set_LightColor), _Is_LightColor_Base);
|
||||
float Set_BaseColorAlpha = _BaseColorVisible;
|
||||
float3 clippingColor = float3(1.0f, 1.0f, 1.0f);
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode == 1)
|
||||
{
|
||||
clippingColor = Set_BaseColor;
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
|
||||
float4 overridingColor = lerp(_BaseColorMaskColor, float4(_BaseColorMaskColor.w, _BaseColorMaskColor.w, _BaseColorMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_BaseColorOverridden, _ComposerMaskMode);
|
||||
Set_BaseColor = lerp(Set_BaseColor, overridingColor, maskEnabled);
|
||||
Set_BaseColor = lerp(Set_BaseColor, overridingColor.rgb, maskEnabled);
|
||||
Set_BaseColor *= _BaseColorVisible;
|
||||
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY
|
||||
//v.2.0.5
|
||||
float4 _1st_ShadeMap_var = lerp(SAMPLE_TEXTURE2D(_1st_ShadeMap, sampler_BaseColorMap,TRANSFORM_TEX(Set_UV0, _1st_ShadeMap)), _MainTex_var, _Use_BaseAs1st);
|
||||
float3 _Is_LightColor_1st_Shade_var = lerp((_1st_ShadeMap_var.rgb * _1st_ShadeColor.rgb), ((_1st_ShadeMap_var.rgb * _1st_ShadeColor.rgb) * Set_LightColor), _Is_LightColor_1st_Shade);
|
||||
@@ -114,7 +118,7 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
//v.2.0.6
|
||||
float4 _ShadingGradeMap_var = tex2Dlod(_ShadingGradeMap, float4(TRANSFORM_TEX(Set_UV0, _ShadingGradeMap), 0.0, _BlurLevelSGM));
|
||||
|
||||
float _SystemShadowsLevel_var = (shadowAttenuation *0.5)+0.5+_Tweak_SystemShadowsLevel > 0.001 ? (shadowAttenuation*0.5)+0.5+_Tweak_SystemShadowsLevel : 0.0001;
|
||||
float _SystemShadowsLevel_var = (shadowAttenuation * 0.5f) + 0.5f + _Tweak_SystemShadowsLevel > 0.001f ? (shadowAttenuation * 0.5f)+0.5f+_Tweak_SystemShadowsLevel : 0.0001f;
|
||||
|
||||
float _ShadingGradeMapLevel_var = _ShadingGradeMap_var.r < 0.95 ? _ShadingGradeMap_var.r + _Tweak_ShadingGradeMapLevel : 1;
|
||||
|
||||
@@ -162,23 +166,23 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
|
||||
|
||||
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode == 2)
|
||||
{
|
||||
clippingColor = _Is_LightColor_1st_Shade_var;
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
{
|
||||
float4 overridingColor = lerp(_FirstShadeMaskColor, float4(_FirstShadeMaskColor.w, _FirstShadeMaskColor.w, _FirstShadeMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_FirstShadeOverridden, _ComposerMaskMode);
|
||||
_Is_LightColor_1st_Shade_var = lerp(_Is_LightColor_1st_Shade_var, overridingColor, maskEnabled);
|
||||
_Is_LightColor_1st_Shade_var = lerp(_Is_LightColor_1st_Shade_var, overridingColor.rgb, maskEnabled);
|
||||
_Is_LightColor_1st_Shade_var = lerp(_Is_LightColor_1st_Shade_var, Set_BaseColor, 1.0f - _FirstShadeVisible);
|
||||
}
|
||||
float Set_1st_ShadeAlpha = _FirstShadeVisible;
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY
|
||||
float3 _BaseColor_var = lerp(Set_BaseColor, _Is_LightColor_1st_Shade_var, Set_FinalShadowMask);
|
||||
//v.2.0.5
|
||||
float4 _2nd_ShadeMap_var = lerp(SAMPLE_TEXTURE2D(_2nd_ShadeMap, sampler_BaseColorMap,TRANSFORM_TEX(Set_UV0, _2nd_ShadeMap)), _1st_ShadeMap_var, _Use_1stAs2nd);
|
||||
@@ -186,14 +190,14 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
float Set_ShadeShadowMask = saturate((1.0 + ((_HalfLambert_var - (_ShadeColor_Step - _2ndColorFeatherForMask)) * ((1.0 - 1).r - 1.0)) / (_ShadeColor_Step - (_ShadeColor_Step - _2ndColorFeatherForMask)))); // 1st and 2nd Shades Mask
|
||||
//Composition: 3 Basic Colors as Set_FinalBaseColor
|
||||
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
float3 Set_FinalBaseColor;
|
||||
{
|
||||
float4 overridingColor = lerp(_SecondShadeMaskColor, float4(_SecondShadeMaskColor.w, _SecondShadeMaskColor.w, _SecondShadeMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_SecondShadeOverridden, _ComposerMaskMode);
|
||||
|
||||
float3 _Is_LightColor_2nd_Shade_var = lerp((_2nd_ShadeMap_var.rgb * _2nd_ShadeColor.rgb), ((_2nd_ShadeMap_var.rgb * _2nd_ShadeColor.rgb) * Set_LightColor), _Is_LightColor_2nd_Shade);
|
||||
_Is_LightColor_2nd_Shade_var = lerp(_Is_LightColor_2nd_Shade_var, overridingColor, maskEnabled);
|
||||
_Is_LightColor_2nd_Shade_var = lerp(_Is_LightColor_2nd_Shade_var, overridingColor.rgb, maskEnabled);
|
||||
_Is_LightColor_2nd_Shade_var = lerp(_Is_LightColor_2nd_Shade_var, Set_BaseColor, 1.0f - _SecondShadeVisible);
|
||||
float Set_2nd_ShadeAlpha = _SecondShadeVisible;
|
||||
Set_FinalBaseColor =
|
||||
@@ -206,7 +210,7 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
#else
|
||||
float3 Set_FinalBaseColor =
|
||||
lerp(_BaseColor_var,
|
||||
lerp(_Is_LightColor_1st_Shade_var,
|
||||
@@ -214,19 +218,19 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
, _Is_LightColor_2nd_Shade)
|
||||
, Set_ShadeShadowMask)
|
||||
, Set_FinalShadowMask);
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY
|
||||
|
||||
float albedoIntensity = max(0.1, (1 - sqrt(surfaceData.metallic)) * (1.7 - 0.7 * (1 - sqrt(surfaceData.metallic))));
|
||||
Set_FinalBaseColor = Set_FinalBaseColor * albedoIntensity;
|
||||
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode == 3)
|
||||
{
|
||||
clippingColor = lerp((_2nd_ShadeMap_var.rgb * _2nd_ShadeColor.rgb), ((_2nd_ShadeMap_var.rgb * _2nd_ShadeColor.rgb) * Set_LightColor)
|
||||
, _Is_LightColor_2nd_Shade);
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
|
||||
float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask));
|
||||
|
||||
@@ -237,14 +241,14 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
//Composition: 3 Basic Colors and HighColor as Set_HighColor
|
||||
float3 _HighColorWithOutTweak_var = lerp((_HighColor_Tex_var.rgb * _HighColor.rgb), ((_HighColor_Tex_var.rgb * _HighColor.rgb) * Set_LightColor), _Is_LightColor_HighColor);
|
||||
float3 _HighColor_var = _HighColorWithOutTweak_var * _TweakHighColorMask_var;
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode == 4)
|
||||
{
|
||||
clippingColor = _HighColorWithOutTweak_var;
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
float3 Set_HighColor;
|
||||
{
|
||||
float4 overridingColor = lerp(_HighlightMaskColor, float4(_HighlightMaskColor.w, _HighlightMaskColor.w, _HighlightMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
@@ -261,13 +265,13 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
Set_HighColor += addColor;
|
||||
if (any(addColor))
|
||||
{
|
||||
Set_HighColor = lerp(Set_HighColor, overridingColor, maskEnabled);
|
||||
Set_HighColor = lerp(Set_HighColor, overridingColor.rgb, maskEnabled);
|
||||
channelOutAlpha = _HighlightVisible;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#else
|
||||
float3 Set_HighColor = (lerp(SATURATE_IF_SDR((Set_FinalBaseColor - _TweakHighColorMask_var)), Set_FinalBaseColor, lerp(_Is_BlendAddToHiColor, 1.0, _Is_SpecularToHighColor)) + lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow))), _Is_UseTweakHighColorOnShadow));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
float4 _Set_RimLightMask_var = tex2D(_Set_RimLightMask, TRANSFORM_TEX(Set_UV0, _Set_RimLightMask));
|
||||
@@ -284,7 +288,7 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
float _ApRimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _Ap_RimLight_Power)));
|
||||
//Composition: HighColor and RimLight as _RimLight_var
|
||||
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
|
||||
float4 overridingRimColor = lerp(_RimLightMaskColor, float4(_RimLightMaskColor.w, _RimLightMaskColor.w, _RimLightMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskRimEnabled = max(_RimLightOverridden, _ComposerMaskMode);
|
||||
@@ -310,7 +314,7 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
|
||||
_RimLight_var = lerp(_RimLight_var, (_RimLight_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow))), _Is_UseTweakHighColorOnShadow);
|
||||
|
||||
#else
|
||||
#else
|
||||
float3 Set_RimLight = (saturate((_Set_RimLightMask_var.g + _Tweak_RimLightMaskLevel)) * lerp(_LightDirection_MaskOn_var, (_LightDirection_MaskOn_var + (lerp(_Ap_RimLightColor.rgb, (_Ap_RimLightColor.rgb * Set_LightColor), _Is_LightColor_Ap_RimLight) * saturate((lerp((0.0 + ((_ApRimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), step(_RimLight_InsideMask, _ApRimLightPower_var), _Ap_RimLight_FeatherOff) - (saturate(_VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel))))), _Add_Antipodean_RimLight));
|
||||
Set_RimLight *= _RimLight_Strength;
|
||||
float3 _RimLight_var;
|
||||
@@ -324,7 +328,7 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
}
|
||||
|
||||
_RimLight_var = lerp(_RimLight_var, (_RimLight_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow))), _Is_UseTweakHighColorOnShadow);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//Matcap
|
||||
//v.2.0.6 : CameraRolling Stabilizer
|
||||
@@ -394,17 +398,17 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
float3 matCapColorOnMultiplyMode = Set_HighColor * (1 - _Tweak_MatcapMaskLevel_var_MultiplyMode) + Set_HighColor * Set_MatCap * _Tweak_MatcapMaskLevel_var_MultiplyMode + lerp(float3(0, 0, 0), Set_RimLight, _RimLight);
|
||||
float3 matCapColorFinal = lerp(matCapColorOnMultiplyMode, matCapColorOnAddMode, _Is_BlendAddToMatCap);
|
||||
//v.2.0.4
|
||||
#ifdef _IS_ANGELRING_OFF
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
#ifdef _IS_ANGELRING_OFF
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode == 5)
|
||||
{
|
||||
clippingColor = float3(0.0f,0.0f,0.0f);
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
float3 diffuseTerm = lerp(_RimLight_var, matCapColorFinal, _MatCap);// Final Composition before Emissive
|
||||
//
|
||||
#elif _IS_ANGELRING_ON
|
||||
#elif _IS_ANGELRING_ON
|
||||
float3 diffuseTerm = lerp(_RimLight_var, matCapColorFinal, _MatCap);// Final Composition before AR
|
||||
//v.2.0.7 AR Camera Rolling Stabilizer
|
||||
float3 _AR_OffsetU_var = lerp(mul(UNITY_MATRIX_V, float4(utsData.normalDirection, 0)).xyz, float3(0, 0, 1), _AR_OffsetU);
|
||||
@@ -418,7 +422,7 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
float Set_ARtexAlpha = _AngelRing_Sampler_var.a;
|
||||
float3 Set_AngelRingWithAlpha = (_Is_LightColor_AR_var * _AngelRing_Sampler_var.a);
|
||||
//Composition: MatCap and AngelRing as diffuseTerm
|
||||
# ifdef UTS_LAYER_VISIBILITY
|
||||
# ifdef UTS_LAYER_VISIBILITY
|
||||
{
|
||||
float4 overridingColor = lerp(_AngelRingMaskColor, float4(_AngelRingMaskColor.w, _AngelRingMaskColor.w, _AngelRingMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_AngelRingOverridden, _ComposerMaskMode);
|
||||
@@ -431,24 +435,23 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
channelOutAlpha = _AngelRingVisible;
|
||||
}
|
||||
}
|
||||
# else
|
||||
# else
|
||||
diffuseTerm = lerp(diffuseTerm, lerp((diffuseTerm + Set_AngelRing), ((diffuseTerm * (1.0 - Set_ARtexAlpha)) + Set_AngelRingWithAlpha), _ARSampler_AlphaOn), _AngelRing);// Final Composition before Emissive
|
||||
# endif //#ifdef UTS_LAYER_VISIBILITY
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
# endif //#ifdef UTS_LAYER_VISIBILITY
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode == 5)
|
||||
{
|
||||
clippingColor = _Is_LightColor_AR_var;
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
//diffuseTerm = Set_AngelRing * 10 * (1 - Set_FinalShadowMask);
|
||||
#endif //#ifdef _IS_ANGELRING_OFF
|
||||
#endif //#ifdef _IS_ANGELRING_OFF
|
||||
|
||||
// PBR----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//Specular Term
|
||||
float3 specularTerm = ComputeSpecularTerm(V, lightDirection, bsdfData) * (1 - Set_FinalShadowMask) * PI * surfaceData.specularColor * Set_LightColor * utsLightData.specularDimmer;
|
||||
//specularTerm = saturate(specularTerm);
|
||||
|
||||
//SSS
|
||||
if (_Use_SSSLut == 1)
|
||||
@@ -461,10 +464,8 @@ void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLight
|
||||
|
||||
diffuseTerm = diffuseTerm * utsLightData.diffuseDimmer;
|
||||
|
||||
//float3 finalColor = diffuseTerm + specularTerm + emissive;
|
||||
|
||||
utsAggregateLighting.directDiffuse += diffuseTerm;
|
||||
utsAggregateLighting.directSpecular += specularTerm;
|
||||
|
||||
//return finalColor;
|
||||
#endif // _SDFShadow
|
||||
}
|
||||
@@ -6,6 +6,9 @@
|
||||
void UTS_OtherLights(LightLoopContext lightLoopContext, FragInputs input, UTSLightData utsLightData, SurfaceData surfaceData, BSDFData bsdfData, int lightType, float3 i_normalDir, float notDirectional, out float channelOutAlpha, inout UTSAggregateLighting utsAggregateLighting)
|
||||
{
|
||||
channelOutAlpha = 1.0f;
|
||||
|
||||
// We dont have to calculate lighting here if we are using sdf shadow
|
||||
#ifndef _SDFShadow
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode != 0)
|
||||
{
|
||||
@@ -249,11 +252,8 @@ void UTS_OtherLights(LightLoopContext lightLoopContext, FragInputs input, UTSLig
|
||||
|
||||
specularTerm = specularTerm * (1.0 - Set_FinalShadowMask) * PI * surfaceData.specularColor;
|
||||
diffuseTerm = diffuseTerm * albedoIntensity;
|
||||
|
||||
//float3 finalColor = diffuseTerm + specularTerm;
|
||||
|
||||
utsAggregateLighting.directDiffuse += diffuseTerm;
|
||||
utsAggregateLighting.directSpecular += specularTerm;
|
||||
|
||||
//return finalColor;
|
||||
#endif // _SDFShadow
|
||||
}
|
||||
@@ -6,6 +6,12 @@
|
||||
|
||||
#define fixed half
|
||||
|
||||
#define UNITY_TEXTURE_STREAMING_DEBUG_VARS
|
||||
float4 unity_MipmapStreaming_DebugTex_ST;
|
||||
float4 unity_MipmapStreaming_DebugTex_TexelSize;
|
||||
float4 unity_MipmapStreaming_DebugTex_MipInfo;
|
||||
float4 unity_MipmapStreaming_DebugTex_StreamInfo;
|
||||
|
||||
// Unity Toon Shader
|
||||
#include "UtsTextures.hlsl"
|
||||
|
||||
@@ -114,7 +120,6 @@ SAMPLER(sampler_LayerInfluenceMaskMap);
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
|
||||
|
||||
#include "UtsUnityPerMaterial.hlsl"
|
||||
|
||||
// shared constant between lit and layered lit
|
||||
@@ -336,3 +341,11 @@ int _ObjectId;
|
||||
int _PassValue;
|
||||
|
||||
CBUFFER_END
|
||||
|
||||
float _Outline_MaxWidth;
|
||||
|
||||
float _HairShadowDistance;
|
||||
float _HairShadowDistanceScaleFactor;
|
||||
float _HairShadowDepthBias;
|
||||
float _HairShadowFadeInDistance;
|
||||
float _HairShadowFadeOutDistance;
|
||||
@@ -259,7 +259,6 @@ UTSLightData GetCustomMainLightData(BuiltinData builtinData, UTSLightData mainPu
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
utsLightData.lightColor = ApplyCurrentExposureMultiplier(_DirectionalLightDatas[mainLightIndex].color);
|
||||
utsLightData.lightDirection = -_DirectionalLightDatas[mainLightIndex].forward;
|
||||
utsLightData.diffuseDimmer = _DirectionalLightDatas[mainLightIndex].diffuseDimmer;
|
||||
|
||||
@@ -21,11 +21,7 @@ float _SDFShadowLevel;
|
||||
float _SDFSmoothGamma;
|
||||
float _SDFNoseHighlightCoef;
|
||||
float _SDFNoseHighlightSmoothRange;
|
||||
float _HairShadowDistance;
|
||||
float _HairShadowDistanceScaleFactor;
|
||||
float _HairShadowDepthBias;
|
||||
float _HairShadowFadeInDistance;
|
||||
float _HairShadowFadeOutDistance;
|
||||
|
||||
float _EyeParallaxAmount;
|
||||
float _EyeBrowBlendingFactor;
|
||||
|
||||
@@ -178,7 +174,6 @@ fixed _ARSampler_AlphaOn;
|
||||
// Unity Toon Shader Outline
|
||||
|
||||
float _Outline_Width;
|
||||
float _Outline_MaxWidth;
|
||||
float _Farthest_Distance;
|
||||
float _Nearest_Distance;
|
||||
float4 _Outline_Sampler_ST;
|
||||
@@ -205,5 +200,6 @@ float _ToonEvAdjustmentCompensation;
|
||||
#endif //#if !defined(_UTS_TOON_EV_PER_MODEL)
|
||||
|
||||
|
||||
float3 _ObjectCenter;
|
||||
float _BlendMode;
|
||||
float _BlendMode;
|
||||
|
||||
float3 _ObjectCenterPositionWS;
|
||||
@@ -1,66 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
using System;
|
||||
|
||||
[Serializable, VolumeComponentMenu("Post-processing/Custom/Sobel")]
|
||||
public sealed class Sobel : CustomPostProcessVolumeComponent, IPostProcessComponent
|
||||
{
|
||||
[Tooltip("Controls the intensity of the effect.")]
|
||||
public ClampedFloatParameter intensity = new ClampedFloatParameter(0f, 0f, 1f);
|
||||
|
||||
[Tooltip("Controls the colour of the outline.")]
|
||||
public ColorParameter outlineColour = new ColorParameter(Color.black);
|
||||
|
||||
[Tooltip("Controls the thickness of the outline.")]
|
||||
public FloatParameter outlineThickness = new FloatParameter(1f);
|
||||
|
||||
[Tooltip("Linearly scales the depth calculation.")]
|
||||
public FloatParameter depthMultiplier = new FloatParameter(1f);
|
||||
|
||||
[Tooltip("Bias (ie. power) applied to the scaled depth value.")]
|
||||
public FloatParameter depthBias = new FloatParameter(1f);
|
||||
|
||||
[Tooltip("Linearly scales the normal calculation.")]
|
||||
public FloatParameter normalMultiplier = new FloatParameter(1f);
|
||||
|
||||
[Tooltip("Bias (ie. power) applied to the scaled normal value.")]
|
||||
public FloatParameter normalBias = new FloatParameter(1f);
|
||||
|
||||
Material m_Material;
|
||||
|
||||
public bool IsActive() => m_Material != null && intensity.value > 0f;
|
||||
|
||||
// Do not forget to add this post process in the Custom Post Process Orders list (Project Settings > Graphics > HDRP Settings).
|
||||
public override CustomPostProcessInjectionPoint injectionPoint => CustomPostProcessInjectionPoint.AfterPostProcess;
|
||||
|
||||
const string kShaderName = "Hidden/Shader/Sobel";
|
||||
|
||||
public override void Setup()
|
||||
{
|
||||
if (Shader.Find(kShaderName) != null)
|
||||
m_Material = new Material(Shader.Find(kShaderName));
|
||||
else
|
||||
Debug.LogError($"Unable to find shader '{kShaderName}'. Post Process Volume Sobel is unable to load.");
|
||||
}
|
||||
|
||||
public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)
|
||||
{
|
||||
if (m_Material == null)
|
||||
return;
|
||||
|
||||
m_Material.SetFloat("_Intensity", intensity.value);
|
||||
m_Material.SetColor("_Colour", outlineColour.value);
|
||||
m_Material.SetFloat("_Thickness", outlineThickness.value);
|
||||
m_Material.SetFloat("_DepthMultiplier", depthMultiplier.value);
|
||||
m_Material.SetFloat("_DepthBias", depthBias.value);
|
||||
m_Material.SetFloat("_NormalMultiplier", normalMultiplier.value);
|
||||
m_Material.SetFloat("_NormalBias", normalBias.value);
|
||||
cmd.Blit(source, destination, m_Material, 0);
|
||||
}
|
||||
|
||||
public override void Cleanup()
|
||||
{
|
||||
CoreUtils.Destroy(m_Material);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31d53e0c1ce16d74988b57447ce52eb8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
106
Runtime/HDRP/UTS Renderer/UTSHairShadowPass.cs
Normal file
106
Runtime/HDRP/UTS Renderer/UTSHairShadowPass.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using Unity.Toonshader;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
using UnityEngine.Rendering.RendererUtils;
|
||||
|
||||
[HideInInspector]
|
||||
public class UTSHairShadowPass : DrawRenderersCustomPass
|
||||
{
|
||||
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_Name = "_HairShadowTex";
|
||||
|
||||
private RTHandle _outputRTHandle;
|
||||
private bool _isEnable = false;
|
||||
|
||||
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
|
||||
{
|
||||
_outputRTHandle?.Release();
|
||||
_outputRTHandle = RTHandles.Alloc(Screen.width, Screen.height, colorFormat: GraphicsFormat.D32_SFloat, filterMode: FilterMode.Bilinear, wrapMode: TextureWrapMode.Clamp, name: Output_RT_Name);
|
||||
|
||||
SetEnable(true);
|
||||
}
|
||||
|
||||
protected override void Execute(CustomPassContext ctx)
|
||||
{
|
||||
var utsRenderer = ctx.hdCamera.volumeStack.GetComponent<UTSRenderer>();
|
||||
if (utsRenderer == null || !utsRenderer.enableHairShadow.value || !utsRenderer.enable.value)
|
||||
{
|
||||
SetEnable(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_isEnable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SetShadowProperty(utsRenderer);
|
||||
|
||||
if (_outputRTHandle != null)
|
||||
{
|
||||
Shader.SetGlobalTexture(Output_RT_Name, _outputRTHandle);
|
||||
CoreUtils.SetRenderTarget(ctx.cmd, _outputRTHandle, ClearFlag.DepthStencil);
|
||||
}
|
||||
|
||||
var mask = RenderStateMask.Nothing;
|
||||
var stateBlock = new RenderStateBlock(mask)
|
||||
{
|
||||
depthState = new DepthState(depthWrite, depthCompareFunction),
|
||||
};
|
||||
|
||||
var result = new RendererListDesc(HDShaderPassNames.s_DepthForwardOnlyName, ctx.cullingResults, ctx.hdCamera.camera)
|
||||
{
|
||||
renderQueueRange = GetRenderQueueRange(renderQueueType),
|
||||
sortingCriteria = sortingCriteria,
|
||||
excludeObjectMotionVectors = false,
|
||||
stateBlock = stateBlock,
|
||||
layerMask = layerMask,
|
||||
};
|
||||
|
||||
CoreUtils.DrawRendererList(ctx.renderContext, ctx.cmd, ctx.renderContext.CreateRendererList(result));
|
||||
}
|
||||
|
||||
private static void SetShadowProperty(UTSRenderer utsRenderer)
|
||||
{
|
||||
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()
|
||||
{
|
||||
SetEnable(false);
|
||||
_outputRTHandle?.Release();
|
||||
}
|
||||
|
||||
public void SetEnable(bool isEnable)
|
||||
{
|
||||
if (_isEnable != isEnable)
|
||||
{
|
||||
if (isEnable)
|
||||
{
|
||||
Shader.EnableKeyword("_HAIR_SHADOWS");
|
||||
}
|
||||
else
|
||||
{
|
||||
Shader.DisableKeyword("_HAIR_SHADOWS");
|
||||
}
|
||||
|
||||
_isEnable = isEnable;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/HDRP/UTS Renderer/UTSHairShadowPass.cs.meta
Normal file
2
Runtime/HDRP/UTS Renderer/UTSHairShadowPass.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7157c6dc91cee0d4aae565d1c8d66807
|
||||
@@ -3,11 +3,12 @@ using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
|
||||
[HideInInspector]
|
||||
public class UTSOutlinePass : DrawRenderersCustomPass
|
||||
{
|
||||
protected override void Execute(CustomPassContext ctx)
|
||||
{
|
||||
UTSRenderer utsRenderer = ctx.hdCamera.volumeStack.GetComponent<UTSRenderer>();
|
||||
var utsRenderer = ctx.hdCamera.volumeStack.GetComponent<UTSRenderer>();
|
||||
if (utsRenderer == null)
|
||||
return;
|
||||
|
||||
@@ -16,31 +17,29 @@ public class UTSOutlinePass : DrawRenderersCustomPass
|
||||
|
||||
Shader.SetGlobalFloat("_Outline_MaxWidth", utsRenderer.outlineMaxWidth.value * 0.01f);
|
||||
|
||||
ShaderTagId outlineTag = new ShaderTagId("Outline");
|
||||
var outlineTag = new ShaderTagId("Outline");
|
||||
|
||||
RenderStateMask mask = RenderStateMask.Nothing;
|
||||
RenderStateBlock stateBlock = new RenderStateBlock(mask)
|
||||
var mask = RenderStateMask.Nothing;
|
||||
var stateBlock = new RenderStateBlock(mask)
|
||||
{
|
||||
depthState = new DepthState(depthWrite, depthCompareFunction),
|
||||
// We disable the stencil when the depth is overwritten but we don't write to it, to prevent writing to the stencil.
|
||||
stencilState = new StencilState(false),
|
||||
};
|
||||
|
||||
PerObjectData renderConfig = ctx.hdCamera.frameSettings.IsEnabled(FrameSettingsField.Shadowmask) ? HDUtils.GetRendererConfiguration(true, false) : HDUtils.GetRendererConfiguration(false, true);
|
||||
|
||||
UnityEngine.Rendering.RendererUtils.RendererListDesc result = new UnityEngine.Rendering.RendererUtils.RendererListDesc(outlineTag, ctx.cullingResults, ctx.hdCamera.camera)
|
||||
var renderConfig = HDUtils.GetRendererConfiguration(false, false);
|
||||
var result = new UnityEngine.Rendering.RendererUtils.RendererListDesc(outlineTag, ctx.cullingResults, ctx.hdCamera.camera)
|
||||
{
|
||||
rendererConfiguration = renderConfig,
|
||||
renderQueueRange = GetRenderQueueRange(renderQueueType),
|
||||
sortingCriteria = sortingCriteria,
|
||||
excludeObjectMotionVectors = true,
|
||||
excludeObjectMotionVectors = false,
|
||||
overrideMaterial = overrideMaterial,
|
||||
overrideMaterialPassIndex = (overrideMaterial != null) ? overrideMaterial.FindPass(overrideMaterialPassName) : 0,
|
||||
stateBlock = stateBlock,
|
||||
layerMask = layerMask,
|
||||
};
|
||||
|
||||
ScriptableRenderContext renderCtx = ctx.renderContext;
|
||||
CoreUtils.DrawRendererList(renderCtx, ctx.cmd, renderCtx.CreateRendererList(result));
|
||||
CoreUtils.DrawRendererList(ctx.renderContext, ctx.cmd, ctx.renderContext.CreateRendererList(result));
|
||||
}
|
||||
}
|
||||
70
Runtime/HDRP/UTS Renderer/UTSRenderPass.cs
Normal file
70
Runtime/HDRP/UTS Renderer/UTSRenderPass.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
|
||||
namespace Unity.Toonshader
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.InitializeOnLoad]
|
||||
#endif
|
||||
public static class RegisterUTSRenderPass
|
||||
{
|
||||
private static readonly UTSRenderPassSetting _renderSetting;
|
||||
|
||||
private static readonly UTSOutlinePass _outlinePass;
|
||||
private static readonly UTSHairShadowPass _hairShadowPass;
|
||||
|
||||
static RegisterUTSRenderPass()
|
||||
{
|
||||
var assetPath = Path.GetFileNameWithoutExtension(UTSRenderPassSetting.RENDERER_SETTING_ASSET_PATH);
|
||||
_renderSetting = Resources.Load<UTSRenderPassSetting>(assetPath);
|
||||
|
||||
if (_renderSetting == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_outlinePass = new()
|
||||
{
|
||||
name = "UTS Outline",
|
||||
layerMask = _renderSetting.outlineSetting.layerMask
|
||||
};
|
||||
|
||||
_hairShadowPass = new()
|
||||
{
|
||||
name = "UTS Hair Shadow Map",
|
||||
layerMask = _renderSetting.hairShadowSetting.casterLayerMask,
|
||||
targetColorBuffer = CustomPass.TargetBuffer.None,
|
||||
targetDepthBuffer = CustomPass.TargetBuffer.None,
|
||||
};
|
||||
|
||||
RegisterCustomPasses();
|
||||
}
|
||||
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
public static void RegisterCustomPasses()
|
||||
{
|
||||
CustomPassVolume.RegisterGlobalCustomPass(CustomPassInjectionPoint.AfterOpaqueAndSky, _outlinePass);
|
||||
CustomPassVolume.RegisterGlobalCustomPass(CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, _hairShadowPass);
|
||||
|
||||
_outlinePass.enabled = _renderSetting.outlineSetting.enable;
|
||||
_hairShadowPass.SetEnable(_renderSetting.hairShadowSetting.enable);
|
||||
}
|
||||
|
||||
public static void UnregisterGlobalCustomPass()
|
||||
{
|
||||
CustomPassVolume.UnregisterGlobalCustomPass(_outlinePass);
|
||||
CustomPassVolume.UnregisterGlobalCustomPass(_hairShadowPass);
|
||||
_hairShadowPass.Release();
|
||||
}
|
||||
|
||||
public static void NotifyRendererSettingChanged()
|
||||
{
|
||||
_outlinePass.enabled = _renderSetting.outlineSetting.enable;
|
||||
_outlinePass.layerMask = _renderSetting.outlineSetting.layerMask;
|
||||
|
||||
_hairShadowPass.SetEnable(_renderSetting.hairShadowSetting.enable);
|
||||
_hairShadowPass.layerMask = _renderSetting.hairShadowSetting.casterLayerMask;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/HDRP/UTS Renderer/UTSRenderPass.cs.meta
Normal file
2
Runtime/HDRP/UTS Renderer/UTSRenderPass.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 651a4bd94acf45c459468b2d4db62b29
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
|
||||
namespace Unity.Toonshader
|
||||
{
|
||||
@@ -10,8 +9,7 @@ namespace Unity.Toonshader
|
||||
public class UTSRenderer : VolumeComponent
|
||||
{
|
||||
// flags
|
||||
bool m_initialized = false;
|
||||
bool m_srpCallbackInitialized = false;
|
||||
bool _initialized = false;
|
||||
|
||||
const int kAdjustmentCurvePrecision = 128;
|
||||
|
||||
@@ -24,12 +22,12 @@ namespace Unity.Toonshader
|
||||
const string kIgnoreVolumeExposurePropName = "_ToonIgnoreExposureMultiplier";
|
||||
|
||||
[SerializeField]
|
||||
internal float[] m_ExposureArray;
|
||||
internal float[] _ExposureArray;
|
||||
[SerializeField]
|
||||
internal float m_Max, m_Min;
|
||||
internal float _Max, _Min;
|
||||
|
||||
CustomPassVolume customPassVolume = new();
|
||||
UTSOutlinePass outlinePass = new();
|
||||
//CustomPassVolume customPassVolume = new();
|
||||
//UTSOutlinePass outlinePass = new();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
#pragma warning restore CS0414
|
||||
@@ -89,7 +87,7 @@ namespace Unity.Toonshader
|
||||
|
||||
Initialize();
|
||||
|
||||
if (!m_initialized)
|
||||
if (!_initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -100,20 +98,20 @@ namespace Unity.Toonshader
|
||||
|
||||
if (curve == null || curve.length == 0)
|
||||
{
|
||||
m_Min = 0f;
|
||||
m_Max = 0f;
|
||||
_Min = 0f;
|
||||
_Max = 0f;
|
||||
|
||||
for (var i = 0; i < kAdjustmentCurvePrecision; i++)
|
||||
m_ExposureArray[i] = 0.0f;
|
||||
_ExposureArray[i] = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Min = curve[0].time;
|
||||
m_Max = curve[curve.length - 1].time;
|
||||
var step = (m_Max - m_Min) / (kAdjustmentCurvePrecision - 1f);
|
||||
_Min = curve[0].time;
|
||||
_Max = curve[curve.length - 1].time;
|
||||
var step = (_Max - _Min) / (kAdjustmentCurvePrecision - 1f);
|
||||
|
||||
for (var i = 0; i < kAdjustmentCurvePrecision; i++)
|
||||
m_ExposureArray[i] = curve.Evaluate(m_Min + step * i);
|
||||
_ExposureArray[i] = curve.Evaluate(_Min + step * i);
|
||||
}
|
||||
|
||||
|
||||
@@ -132,9 +130,9 @@ namespace Unity.Toonshader
|
||||
m_isCompiling = false;
|
||||
}
|
||||
#endif
|
||||
Shader.SetGlobalFloatArray(kExposureArrayPropName, m_ExposureArray);
|
||||
Shader.SetGlobalFloat(kExposureMinPropName, m_Min);
|
||||
Shader.SetGlobalFloat(kExposureMaxPropName, m_Max);
|
||||
Shader.SetGlobalFloatArray(kExposureArrayPropName, _ExposureArray);
|
||||
Shader.SetGlobalFloat(kExposureMinPropName, _Min);
|
||||
Shader.SetGlobalFloat(kExposureMaxPropName, _Max);
|
||||
Shader.SetGlobalInt(kExposureAdjustmentPropName, toonEVAdjustment.value ? 1 : 0);
|
||||
Shader.SetGlobalInt(kToonLightFilterPropName, lightIntensityLimiter.value ? 1 : 0);
|
||||
Shader.SetGlobalInt(kIgnoreVolumeExposurePropName, ignoreVolumeExposure.value ? 1 : 0);
|
||||
@@ -148,7 +146,7 @@ namespace Unity.Toonshader
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
if (m_initialized)
|
||||
if (_initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -159,12 +157,12 @@ namespace Unity.Toonshader
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (m_ExposureArray == null || m_ExposureArray.Length != kAdjustmentCurvePrecision)
|
||||
if (_ExposureArray == null || _ExposureArray.Length != kAdjustmentCurvePrecision)
|
||||
{
|
||||
m_ExposureArray = new float[kAdjustmentCurvePrecision];
|
||||
_ExposureArray = new float[kAdjustmentCurvePrecision];
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
@@ -173,11 +171,11 @@ namespace Unity.Toonshader
|
||||
Release();
|
||||
}
|
||||
|
||||
void Release()
|
||||
new void Release()
|
||||
{
|
||||
if (m_initialized)
|
||||
if (_initialized)
|
||||
{
|
||||
m_ExposureArray = null;
|
||||
_ExposureArray = null;
|
||||
Shader.SetGlobalFloat(kExposureMinPropName, 0);
|
||||
Shader.SetGlobalFloat(kExposureMaxPropName, 0);
|
||||
Shader.SetGlobalInt(kExposureAdjustmentPropName, 0);
|
||||
@@ -186,8 +184,8 @@ namespace Unity.Toonshader
|
||||
Shader.SetGlobalFloat(kCompensationPropName, 0);
|
||||
}
|
||||
|
||||
m_initialized = false;
|
||||
|
||||
_initialized = false;
|
||||
base.Release();
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
|
||||
22
Runtime/HDRP/UTSMeshRenderer.cs
Normal file
22
Runtime/HDRP/UTSMeshRenderer.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class UTSMeshRenderer : MonoBehaviour
|
||||
{
|
||||
private const string Shader_Prop_Object_Center_Name = "_ObjectCenterPositionWS";
|
||||
|
||||
public Material material;
|
||||
|
||||
public Transform objectCenter;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (material == null)
|
||||
return;
|
||||
|
||||
if (objectCenter != null)
|
||||
{
|
||||
material.SetVector(Shader_Prop_Object_Center_Name, objectCenter.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user