Upload project file
This commit is contained in:
146
Runtime/HDRP/Shaders/Common.hlsl
Normal file
146
Runtime/HDRP/Shaders/Common.hlsl
Normal file
@@ -0,0 +1,146 @@
|
||||
#ifndef UTS_COMMON
|
||||
#define UTS_COMMON
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
||||
|
||||
#define inverselerp(a, b, x) saturate(((x) - (a)) / ((b) - (a)))
|
||||
|
||||
float2 GetWHRatio()
|
||||
{
|
||||
return float2(_ScreenParams.y / _ScreenParams.x, 1);
|
||||
}
|
||||
|
||||
float StepAntiAliasing(float x, float y)
|
||||
{
|
||||
float v = x - y;
|
||||
return saturate(v / fwidth(v));//fwidth(x) = abs(ddx(x) + ddy(x))
|
||||
|
||||
}
|
||||
|
||||
#define SampleRampSignalLine(texture, u) (SAMPLE_TEXTURE2D_LOD(texture, s_linear_clamp_sampler, float2(u, 0.5), 0))
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Transform
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
float3 ProjectOnPlane(float3 vec, float3 normal)
|
||||
{
|
||||
return vec - normal * dot(vec, normal);
|
||||
}
|
||||
|
||||
float2 Rotate_UV(float2 _uv, float _radian, float2 _piv, float _time)
|
||||
{
|
||||
float RotateUV_ang = _radian;
|
||||
float RotateUV_cos = cos(_time * RotateUV_ang);
|
||||
float RotateUV_sin = sin(_time * RotateUV_ang);
|
||||
return(mul(_uv - _piv, float2x2(RotateUV_cos, -RotateUV_sin, RotateUV_sin, RotateUV_cos)) + _piv);
|
||||
}
|
||||
|
||||
// Anti-perspective form Colin: Counteract perspective effects by replacing regular depth with uniform depth
|
||||
uniform float _AntiPerspectiveIntensity;
|
||||
void AntiPerspective(inout float4 clipPos)
|
||||
{
|
||||
float centerVSz = mul(UNITY_MATRIX_V, float4(UNITY_MATRIX_M._m03_m13_m23, 1.0)).z;
|
||||
clipPos.xy *= lerp(1.0, abs(clipPos.w) / - centerVSz, _AntiPerspectiveIntensity);
|
||||
}
|
||||
|
||||
// ASE
|
||||
float2 UnStereo(float2 UV)
|
||||
{
|
||||
#if UNITY_SINGLE_PASS_STEREO
|
||||
float4 scaleOffset = unity_StereoScaleOffset[ unity_StereoEyeIndex ];
|
||||
UV.xy = (UV.xy - scaleOffset.zw) / scaleOffset.xy;
|
||||
#endif
|
||||
return UV;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Color
|
||||
// ----------------------------------------------------------------------------
|
||||
float3 ShiftColorPurity(float3 color, float purity)
|
||||
{
|
||||
return lerp(Luminance(color), color, purity);
|
||||
}
|
||||
|
||||
void AlphaGammaCorrection(inout float a1, inout float a2, inout float a3, inout float a4)
|
||||
{
|
||||
float4 a = float4(a1, a2, a3, a4);
|
||||
a = pow(abs(a), 1 / 1.48);
|
||||
a1 = a.x;
|
||||
a2 = a.y;
|
||||
a3 = a.z;
|
||||
a4 = a.w;
|
||||
}
|
||||
|
||||
void AlphaGammaCorrection(inout float alpha)
|
||||
{
|
||||
alpha = pow(abs(alpha), 1 / 1.48);
|
||||
}
|
||||
|
||||
void AlphaGammaCorrection(inout float alpha, inout float alpha2)
|
||||
{
|
||||
AlphaGammaCorrection(alpha, alpha2, alpha, alpha);
|
||||
}
|
||||
|
||||
void AlphaGammaCorrection(inout float alpha, inout float alpha2, inout float alpha3)
|
||||
{
|
||||
AlphaGammaCorrection(alpha, alpha2, alpha3, alpha3);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Depth
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
float LinearEyeDepth(float z)
|
||||
{
|
||||
return LinearEyeDepth(z, _ZBufferParams);
|
||||
}
|
||||
|
||||
// https://forum.unity.com/threads/what-does-unity-exactly-do-when-we-modify-z-buffer-value-using-sv_depth.526406/
|
||||
float LinearEyeDepthToOutDepth(float z)
|
||||
{
|
||||
return(1 - _ZBufferParams.w * z) / (_ZBufferParams.z * z);
|
||||
}
|
||||
|
||||
// Returns the forward (Right) direction of the current view in the world space.
|
||||
float3 GetViewRightDir()
|
||||
{
|
||||
float4x4 viewMat = GetWorldToViewMatrix();
|
||||
return viewMat[0].xyz;
|
||||
}
|
||||
|
||||
// ASE
|
||||
float3 InvertDepthDirHD(float3 In)
|
||||
{
|
||||
float3 result = In;
|
||||
#if !defined(ASE_SRP_VERSION) || ASE_SRP_VERSION <= 70301 || ASE_SRP_VERSION == 70503 || ASE_SRP_VERSION >= 80301
|
||||
result *= float3(1, 1, -1);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
float4x4 unity_CameraProjection;
|
||||
float4x4 unity_CameraInvProjection;
|
||||
float4x4 unity_WorldToCamera;
|
||||
float4x4 unity_CameraToWorld;
|
||||
|
||||
// ASE
|
||||
float3 GetWorldPosFromDepthBuffer(float2 clipPos01, float cameraDepth)
|
||||
{
|
||||
#ifdef UNITY_REVERSED_Z
|
||||
float depth = (1.0 - cameraDepth);
|
||||
#else
|
||||
float depth = cameraDepth;
|
||||
#endif
|
||||
float3 screenPos_DepthBuffer = (float3(clipPos01, depth));
|
||||
float4 clipPos = (float4((screenPos_DepthBuffer * 2.0 - 1.0), 1.0));
|
||||
float4 viewPos = mul(unity_CameraInvProjection, clipPos);
|
||||
float3 viewPosNorm = viewPos.xyz / viewPos.w;
|
||||
float3 localInvertDepthDirHD = InvertDepthDirHD(viewPosNorm);
|
||||
|
||||
return mul(unity_CameraToWorld, float4(localInvertDepthDirHD, 1.0)).xyz;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
7
Runtime/HDRP/Shaders/Common.hlsl.meta
Normal file
7
Runtime/HDRP/Shaders/Common.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac88fd7420b835748990a40f42a2478f
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
263
Runtime/HDRP/Shaders/DebugDisplay.hlsl
Normal file
263
Runtime/HDRP/Shaders/DebugDisplay.hlsl
Normal file
@@ -0,0 +1,263 @@
|
||||
#ifdef DEBUG_DISPLAY // Guard define here to be compliant with how shader graph generate code for include
|
||||
|
||||
#ifndef UNITY_DEBUG_DISPLAY_INCLUDED
|
||||
#define UNITY_DEBUG_DISPLAY_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/MaterialDebug.cs.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/LightingDebug.cs.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/MipMapDebug.cs.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/ColorPickerDebug.cs.hlsl"
|
||||
|
||||
|
||||
// Local shader variables
|
||||
static SHADOW_TYPE g_DebugShadowAttenuation = 0;
|
||||
|
||||
StructuredBuffer<int2> _DebugDepthPyramidOffsets;
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/PBRValidator.hlsl"
|
||||
|
||||
// When displaying lux meter we compress the light in order to be able to display value higher than 65504
|
||||
// The sun is between 100 000 and 150 000, so we use 4 to be able to cover such a range (4 * 65504)
|
||||
#define LUXMETER_COMPRESSION_RATIO 4
|
||||
|
||||
TEXTURE2D(_DebugFont); // Debug font to write string in shader
|
||||
TEXTURE2D(_DebugMatCapTexture);
|
||||
|
||||
void GetPropertiesDataDebug(uint paramId, inout float3 result, inout bool needLinearToSRGB)
|
||||
{
|
||||
switch (paramId)
|
||||
{
|
||||
case DEBUGVIEWPROPERTIES_TESSELLATION:
|
||||
#ifdef TESSELLATION_ON
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DEBUGVIEWPROPERTIES_PIXEL_DISPLACEMENT:
|
||||
#ifdef _PIXEL_DISPLACEMENT // Caution: This define is related to a shader features (But it may become a standard features for HD)
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DEBUGVIEWPROPERTIES_VERTEX_DISPLACEMENT:
|
||||
#ifdef _VERTEX_DISPLACEMENT // Caution: This define is related to a shader features (But it may become a standard features for HD)
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DEBUGVIEWPROPERTIES_TESSELLATION_DISPLACEMENT:
|
||||
#ifdef _TESSELLATION_DISPLACEMENT // Caution: This define is related to a shader features (But it may become a standard features for HD)
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DEBUGVIEWPROPERTIES_DEPTH_OFFSET:
|
||||
#ifdef _DEPTHOFFSET_ON // Caution: This define is related to a shader features (But it may become a standard features for HD)
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DEBUGVIEWPROPERTIES_LIGHTMAP:
|
||||
#if defined(LIGHTMAP_ON) || defined (DIRLIGHTMAP_COMBINED) || defined(DYNAMICLIGHTMAP_ON)
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DEBUGVIEWPROPERTIES_INSTANCING:
|
||||
#if defined(UNITY_INSTANCING_ENABLED)
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float3 GetTextureDataDebug(uint paramId, float2 uv, Texture2D tex, float4 texelSize, float4 mipInfo, float3 originalColor)
|
||||
{
|
||||
float3 outColor = originalColor;
|
||||
|
||||
switch (paramId)
|
||||
{
|
||||
case DEBUGMIPMAPMODE_MIP_RATIO:
|
||||
outColor = GetDebugMipColorIncludingMipReduction(originalColor, tex, texelSize, uv, mipInfo);
|
||||
break;
|
||||
case DEBUGMIPMAPMODE_MIP_COUNT:
|
||||
outColor = GetDebugMipCountColor(originalColor, tex);
|
||||
break;
|
||||
case DEBUGMIPMAPMODE_MIP_COUNT_REDUCTION:
|
||||
outColor = GetDebugMipReductionColor(tex, mipInfo);
|
||||
break;
|
||||
case DEBUGMIPMAPMODE_STREAMING_MIP_BUDGET:
|
||||
outColor = GetDebugStreamingMipColor(tex, mipInfo);
|
||||
break;
|
||||
case DEBUGMIPMAPMODE_STREAMING_MIP:
|
||||
outColor = GetDebugStreamingMipColorBlended(originalColor, tex, mipInfo);
|
||||
break;
|
||||
}
|
||||
|
||||
return outColor;
|
||||
}
|
||||
|
||||
// DebugFont code assume black and white font with texture size 256x128 with bloc of 16x16
|
||||
#define DEBUG_FONT_TEXT_WIDTH 16
|
||||
#define DEBUG_FONT_TEXT_HEIGHT 16
|
||||
#define DEBUG_FONT_TEXT_COUNT_X 16
|
||||
#define DEBUG_FONT_TEXT_COUNT_Y 8
|
||||
#define DEBUG_FONT_TEXT_ASCII_START 32
|
||||
|
||||
#define DEBUG_FONT_TEXT_SCALE_WIDTH 10 // This control the spacing between characters (if a character fill the text block it will overlap).
|
||||
|
||||
// Only support ASCII symbol from DEBUG_FONT_TEXT_ASCII_START to 126
|
||||
// return black or white depends if we hit font character or not
|
||||
// currentUnormCoord is current unormalized screen position
|
||||
// fixedUnormCoord is the position where we want to draw something, this will be incremented by block font size in provided direction
|
||||
// color is current screen color
|
||||
// color of the font to use
|
||||
// direction is 1 or -1 and indicate fixedUnormCoord block shift
|
||||
void DrawCharacter(uint asciiValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color, int direction, int fontTextScaleWidth)
|
||||
{
|
||||
// Are we inside a font display block on the screen ?
|
||||
uint2 localCharCoord = currentUnormCoord - fixedUnormCoord;
|
||||
if (localCharCoord.x >= 0 && localCharCoord.x < DEBUG_FONT_TEXT_WIDTH && localCharCoord.y >= 0 && localCharCoord.y < DEBUG_FONT_TEXT_HEIGHT)
|
||||
{
|
||||
localCharCoord.y = DEBUG_FONT_TEXT_HEIGHT - localCharCoord.y;
|
||||
|
||||
asciiValue -= DEBUG_FONT_TEXT_ASCII_START; // Our font start at ASCII table 32;
|
||||
uint2 asciiCoord = uint2(asciiValue % DEBUG_FONT_TEXT_COUNT_X, asciiValue / DEBUG_FONT_TEXT_COUNT_X);
|
||||
// Unorm coordinate inside the font texture
|
||||
uint2 unormTexCoord = asciiCoord * uint2(DEBUG_FONT_TEXT_WIDTH, DEBUG_FONT_TEXT_HEIGHT) + localCharCoord;
|
||||
// normalized coordinate
|
||||
float2 normTexCoord = float2(unormTexCoord) / float2(DEBUG_FONT_TEXT_WIDTH * DEBUG_FONT_TEXT_COUNT_X, DEBUG_FONT_TEXT_HEIGHT * DEBUG_FONT_TEXT_COUNT_Y);
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
normTexCoord.y = 1.0 - normTexCoord.y;
|
||||
#endif
|
||||
|
||||
float charColor = SAMPLE_TEXTURE2D_LOD(_DebugFont, s_point_clamp_sampler, normTexCoord, 0).r;
|
||||
color = color * (1.0 - charColor) + charColor * fontColor;
|
||||
}
|
||||
|
||||
fixedUnormCoord.x += fontTextScaleWidth * direction;
|
||||
}
|
||||
|
||||
void DrawCharacter(uint asciiValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color, int direction)
|
||||
{
|
||||
DrawCharacter(asciiValue, fontColor, currentUnormCoord, fixedUnormCoord, color, direction, DEBUG_FONT_TEXT_SCALE_WIDTH);
|
||||
}
|
||||
|
||||
// Shortcut to not have to file direction
|
||||
void DrawCharacter(uint asciiValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
|
||||
{
|
||||
DrawCharacter(asciiValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 1);
|
||||
}
|
||||
|
||||
// Draw a signed integer
|
||||
// Can't display more than 16 digit
|
||||
// The two following parameter are for float representation
|
||||
// leading0 is used when drawing frac part of a float to draw the leading 0 (call is in charge of it)
|
||||
// forceNegativeSign is used to force to display a negative sign as -0 is not recognize
|
||||
void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color, int leading0, bool forceNegativeSign)
|
||||
{
|
||||
const uint maxStringSize = 16;
|
||||
|
||||
uint absIntValue = abs(intValue);
|
||||
|
||||
// 1. Get size of the number of display
|
||||
int numEntries = min((intValue == 0 ? 0 : log10(absIntValue)) + ((intValue < 0 || forceNegativeSign) ? 1 : 0) + leading0, maxStringSize);
|
||||
|
||||
// 2. Shift curseur to last location as we will go reverse
|
||||
fixedUnormCoord.x += numEntries * DEBUG_FONT_TEXT_SCALE_WIDTH;
|
||||
|
||||
// 3. Display the number
|
||||
bool drawCharacter = true; // bit weird, but it is to appease the compiler.
|
||||
for (uint j = 0; j < maxStringSize; ++j)
|
||||
{
|
||||
// Numeric value incurrent font start on the second row at 0
|
||||
if(drawCharacter)
|
||||
DrawCharacter((absIntValue % 10) + '0', fontColor, currentUnormCoord, fixedUnormCoord, color, -1);
|
||||
|
||||
if (absIntValue < 10)
|
||||
drawCharacter = false;
|
||||
|
||||
absIntValue /= 10;
|
||||
}
|
||||
|
||||
// 4. Display leading 0
|
||||
if (leading0 > 0)
|
||||
{
|
||||
for (int i = 0; i < leading0; ++i)
|
||||
{
|
||||
DrawCharacter('0', fontColor, currentUnormCoord, fixedUnormCoord, color, -1);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Display sign
|
||||
if (intValue < 0 || forceNegativeSign)
|
||||
{
|
||||
DrawCharacter('-', fontColor, currentUnormCoord, fixedUnormCoord, color, -1);
|
||||
}
|
||||
|
||||
// 6. Reset cursor at end location
|
||||
fixedUnormCoord.x += (numEntries + 2) * DEBUG_FONT_TEXT_SCALE_WIDTH;
|
||||
}
|
||||
|
||||
void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
|
||||
{
|
||||
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 0, false);
|
||||
}
|
||||
|
||||
void DrawFloatExplicitPrecision(float floatValue, float3 fontColor, uint2 currentUnormCoord, uint digitCount, inout uint2 fixedUnormCoord, inout float3 color)
|
||||
{
|
||||
if (IsNaN(floatValue))
|
||||
{
|
||||
DrawCharacter('N', fontColor, currentUnormCoord, fixedUnormCoord, color);
|
||||
DrawCharacter('a', fontColor, currentUnormCoord, fixedUnormCoord, color);
|
||||
DrawCharacter('N', fontColor, currentUnormCoord, fixedUnormCoord, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
int intValue = int(floatValue);
|
||||
bool forceNegativeSign = floatValue >= 0.0f ? false : true;
|
||||
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 0, forceNegativeSign);
|
||||
DrawCharacter('.', fontColor, currentUnormCoord, fixedUnormCoord, color);
|
||||
int fracValue = int(frac(abs(floatValue)) * pow(10, digitCount));
|
||||
int leading0 = digitCount - (int(log10(fracValue)) + 1); // Counting leading0 to add in front of the float
|
||||
DrawInteger(fracValue, fontColor, currentUnormCoord, fixedUnormCoord, color, leading0, false);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawFloat(float floatValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
|
||||
{
|
||||
DrawFloatExplicitPrecision(floatValue, fontColor, currentUnormCoord, 6, fixedUnormCoord, color);
|
||||
}
|
||||
|
||||
// Debug rendering is performed at the end of the frame (after post-processing).
|
||||
// Debug textures are never flipped upside-down automatically. Therefore, we must always flip manually.
|
||||
bool ShouldFlipDebugTexture()
|
||||
{
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
return (_ProjectionParams.x > 0);
|
||||
#else
|
||||
return (_ProjectionParams.x < 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // DEBUG_DISPLAY
|
||||
9
Runtime/HDRP/Shaders/DebugDisplay.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/DebugDisplay.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ab1498776c236c4da0411cc76a11bf6
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
272
Runtime/HDRP/Shaders/DebugDisplayHDRP7.hlsl
Normal file
272
Runtime/HDRP/Shaders/DebugDisplayHDRP7.hlsl
Normal file
@@ -0,0 +1,272 @@
|
||||
#ifndef UNITY_DEBUG_DISPLAY_INCLUDED
|
||||
#define UNITY_DEBUG_DISPLAY_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/MaterialDebug.cs.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/LightingDebug.cs.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/MipMapDebug.cs.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/ColorPickerDebug.cs.hlsl"
|
||||
|
||||
CBUFFER_START(UnityDebugDisplay)
|
||||
// Set of parameters available when switching to debug shader mode
|
||||
int _DebugLightingMode; // Match enum DebugLightingMode
|
||||
int _DebugShadowMapMode;
|
||||
float _DebugViewMaterialArray[11]; // Contain the id (define in various materialXXX.cs.hlsl) of the property to display
|
||||
int _DebugMipMapMode; // Match enum DebugMipMapMode
|
||||
int _DebugMipMapModeTerrainTexture; // Match enum DebugMipMapModeTerrainTexture
|
||||
int _ColorPickerMode; // Match enum ColorPickerDebugMode
|
||||
int _DebugStep;
|
||||
int _DebugDepthPyramidMip;
|
||||
int _DebugFullScreenMode;
|
||||
float _DebugTransparencyOverdrawWeight;
|
||||
float4 _DebugLightingAlbedo; // x == bool override, yzw = albedo for diffuse
|
||||
float4 _DebugLightingSmoothness; // x == bool override, y == override value
|
||||
float4 _DebugLightingNormal; // x == bool override
|
||||
float4 _DebugLightingAmbientOcclusion; // x == bool override, y == override value
|
||||
float4 _DebugLightingSpecularColor; // x == bool override, yzw = specular color
|
||||
float4 _DebugLightingEmissiveColor; // x == bool override, yzw = emissive color
|
||||
float4 _DebugLightingMaterialValidateHighColor; // user can specific the colors for the validator error conditions
|
||||
float4 _DebugLightingMaterialValidateLowColor;
|
||||
float4 _DebugLightingMaterialValidatePureMetalColor;
|
||||
float4 _MousePixelCoord; // xy unorm, zw norm
|
||||
float4 _MouseClickPixelCoord; // xy unorm, zw norm
|
||||
int _MatcapMixAlbedo;
|
||||
int _MatcapViewScale;
|
||||
uint _DebugContactShadowLightIndex;
|
||||
CBUFFER_END
|
||||
|
||||
// Local shader variables
|
||||
static DirectionalShadowType g_DebugShadowAttenuation = 0;
|
||||
|
||||
StructuredBuffer<int2> _DebugDepthPyramidOffsets;
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/PBRValidator.hlsl"
|
||||
|
||||
// When displaying lux meter we compress the light in order to be able to display value higher than 65504
|
||||
// The sun is between 100 000 and 150 000, so we use 4 to be able to cover such a range (4 * 65504)
|
||||
#define LUXMETER_COMPRESSION_RATIO 4
|
||||
|
||||
TEXTURE2D(_DebugFont); // Debug font to write string in shader
|
||||
TEXTURE2D(_DebugMatCapTexture);
|
||||
|
||||
void GetPropertiesDataDebug(uint paramId, inout float3 result, inout bool needLinearToSRGB)
|
||||
{
|
||||
switch (paramId)
|
||||
{
|
||||
case DEBUGVIEWPROPERTIES_TESSELLATION:
|
||||
#ifdef TESSELLATION_ON
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DEBUGVIEWPROPERTIES_PIXEL_DISPLACEMENT:
|
||||
#ifdef _PIXEL_DISPLACEMENT // Caution: This define is related to a shader features (But it may become a standard features for HD)
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DEBUGVIEWPROPERTIES_VERTEX_DISPLACEMENT:
|
||||
#ifdef _VERTEX_DISPLACEMENT // Caution: This define is related to a shader features (But it may become a standard features for HD)
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DEBUGVIEWPROPERTIES_TESSELLATION_DISPLACEMENT:
|
||||
#ifdef _TESSELLATION_DISPLACEMENT // Caution: This define is related to a shader features (But it may become a standard features for HD)
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DEBUGVIEWPROPERTIES_DEPTH_OFFSET:
|
||||
#ifdef _DEPTHOFFSET_ON // Caution: This define is related to a shader features (But it may become a standard features for HD)
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DEBUGVIEWPROPERTIES_LIGHTMAP:
|
||||
#if defined(LIGHTMAP_ON) || defined (DIRLIGHTMAP_COMBINED) || defined(DYNAMICLIGHTMAP_ON)
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DEBUGVIEWPROPERTIES_INSTANCING:
|
||||
#if defined(UNITY_INSTANCING_ENABLED)
|
||||
result = float3(1.0, 0.0, 0.0);
|
||||
#else
|
||||
result = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float3 GetTextureDataDebug(uint paramId, float2 uv, Texture2D tex, float4 texelSize, float4 mipInfo, float3 originalColor)
|
||||
{
|
||||
float3 outColor = originalColor;
|
||||
|
||||
switch (paramId)
|
||||
{
|
||||
case DEBUGMIPMAPMODE_MIP_RATIO:
|
||||
outColor = GetDebugMipColorIncludingMipReduction(originalColor, tex, texelSize, uv, mipInfo);
|
||||
break;
|
||||
case DEBUGMIPMAPMODE_MIP_COUNT:
|
||||
outColor = GetDebugMipCountColor(originalColor, tex);
|
||||
break;
|
||||
case DEBUGMIPMAPMODE_MIP_COUNT_REDUCTION:
|
||||
outColor = GetDebugMipReductionColor(tex, mipInfo);
|
||||
break;
|
||||
case DEBUGMIPMAPMODE_STREAMING_MIP_BUDGET:
|
||||
outColor = GetDebugStreamingMipColor(tex, mipInfo);
|
||||
break;
|
||||
case DEBUGMIPMAPMODE_STREAMING_MIP:
|
||||
outColor = GetDebugStreamingMipColorBlended(originalColor, tex, mipInfo);
|
||||
break;
|
||||
}
|
||||
|
||||
return outColor;
|
||||
}
|
||||
|
||||
// DebugFont code assume black and white font with texture size 256x128 with bloc of 16x16
|
||||
#define DEBUG_FONT_TEXT_WIDTH 16
|
||||
#define DEBUG_FONT_TEXT_HEIGHT 16
|
||||
#define DEBUG_FONT_TEXT_COUNT_X 16
|
||||
#define DEBUG_FONT_TEXT_COUNT_Y 8
|
||||
#define DEBUG_FONT_TEXT_ASCII_START 32
|
||||
|
||||
#define DEBUG_FONT_TEXT_SCALE_WIDTH 10 // This control the spacing between characters (if a character fill the text block it will overlap).
|
||||
|
||||
// Only support ASCII symbol from DEBUG_FONT_TEXT_ASCII_START to 126
|
||||
// return black or white depends if we hit font character or not
|
||||
// currentUnormCoord is current unormalized screen position
|
||||
// fixedUnormCoord is the position where we want to draw something, this will be incremented by block font size in provided direction
|
||||
// color is current screen color
|
||||
// color of the font to use
|
||||
// direction is 1 or -1 and indicate fixedUnormCoord block shift
|
||||
void DrawCharacter(uint asciiValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color, int direction)
|
||||
{
|
||||
// Are we inside a font display block on the screen ?
|
||||
uint2 localCharCoord = currentUnormCoord - fixedUnormCoord;
|
||||
if (localCharCoord.x >= 0 && localCharCoord.x < DEBUG_FONT_TEXT_WIDTH && localCharCoord.y >= 0 && localCharCoord.y < DEBUG_FONT_TEXT_HEIGHT)
|
||||
{
|
||||
localCharCoord.y = DEBUG_FONT_TEXT_HEIGHT - localCharCoord.y;
|
||||
|
||||
asciiValue -= DEBUG_FONT_TEXT_ASCII_START; // Our font start at ASCII table 32;
|
||||
uint2 asciiCoord = uint2(asciiValue % DEBUG_FONT_TEXT_COUNT_X, asciiValue / DEBUG_FONT_TEXT_COUNT_X);
|
||||
// Unorm coordinate inside the font texture
|
||||
uint2 unormTexCoord = asciiCoord * uint2(DEBUG_FONT_TEXT_WIDTH, DEBUG_FONT_TEXT_HEIGHT) + localCharCoord;
|
||||
// normalized coordinate
|
||||
float2 normTexCoord = float2(unormTexCoord) / float2(DEBUG_FONT_TEXT_WIDTH * DEBUG_FONT_TEXT_COUNT_X, DEBUG_FONT_TEXT_HEIGHT * DEBUG_FONT_TEXT_COUNT_Y);
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
normTexCoord.y = 1.0 - normTexCoord.y;
|
||||
#endif
|
||||
|
||||
float charColor = SAMPLE_TEXTURE2D_LOD(_DebugFont, s_point_clamp_sampler, normTexCoord, 0).r;
|
||||
color = color * (1.0 - charColor) + charColor * fontColor;
|
||||
}
|
||||
|
||||
fixedUnormCoord.x += DEBUG_FONT_TEXT_SCALE_WIDTH * direction;
|
||||
}
|
||||
|
||||
// Shortcut to not have to file direction
|
||||
void DrawCharacter(uint asciiValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
|
||||
{
|
||||
DrawCharacter(asciiValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 1);
|
||||
}
|
||||
|
||||
// Draw a signed integer
|
||||
// Can't display more than 16 digit
|
||||
// The two following parameter are for float representation
|
||||
// leading0 is used when drawing frac part of a float to draw the leading 0 (call is in charge of it)
|
||||
// forceNegativeSign is used to force to display a negative sign as -0 is not recognize
|
||||
void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color, int leading0, bool forceNegativeSign)
|
||||
{
|
||||
const uint maxStringSize = 16;
|
||||
|
||||
uint absIntValue = abs(intValue);
|
||||
|
||||
// 1. Get size of the number of display
|
||||
int numEntries = min((intValue == 0 ? 0 : log10(absIntValue)) + ((intValue < 0 || forceNegativeSign) ? 1 : 0) + leading0, maxStringSize);
|
||||
|
||||
// 2. Shift curseur to last location as we will go reverse
|
||||
fixedUnormCoord.x += numEntries * DEBUG_FONT_TEXT_SCALE_WIDTH;
|
||||
|
||||
// 3. Display the number
|
||||
for (uint j = 0; j < maxStringSize; ++j)
|
||||
{
|
||||
// Numeric value incurrent font start on the second row at 0
|
||||
DrawCharacter((absIntValue % 10) + '0', fontColor, currentUnormCoord, fixedUnormCoord, color, -1);
|
||||
if (absIntValue < 10)
|
||||
break;
|
||||
absIntValue /= 10;
|
||||
}
|
||||
|
||||
// 4. Display leading 0
|
||||
if (leading0 > 0)
|
||||
{
|
||||
for (int i = 0; i < leading0; ++i)
|
||||
{
|
||||
DrawCharacter('0', fontColor, currentUnormCoord, fixedUnormCoord, color, -1);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Display sign
|
||||
if (intValue < 0 || forceNegativeSign)
|
||||
{
|
||||
DrawCharacter('-', fontColor, currentUnormCoord, fixedUnormCoord, color, -1);
|
||||
}
|
||||
|
||||
// 6. Reset cursor at end location
|
||||
fixedUnormCoord.x += (numEntries + 2) * DEBUG_FONT_TEXT_SCALE_WIDTH;
|
||||
}
|
||||
|
||||
void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
|
||||
{
|
||||
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 0, false);
|
||||
}
|
||||
|
||||
void DrawFloat(float floatValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
|
||||
{
|
||||
if (IsNaN(floatValue))
|
||||
{
|
||||
DrawCharacter('N', fontColor, currentUnormCoord, fixedUnormCoord, color);
|
||||
DrawCharacter('a', fontColor, currentUnormCoord, fixedUnormCoord, color);
|
||||
DrawCharacter('N', fontColor, currentUnormCoord, fixedUnormCoord, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
int intValue = int(floatValue);
|
||||
bool forceNegativeSign = floatValue >= 0.0f ? false : true;
|
||||
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 0, forceNegativeSign);
|
||||
DrawCharacter('.', fontColor, currentUnormCoord, fixedUnormCoord, color);
|
||||
int fracValue = int(frac(abs(floatValue)) * 1e6); // 6 digit
|
||||
int leading0 = 6 - (int(log10(fracValue)) + 1); // Counting leading0 to add in front of the float
|
||||
DrawInteger(fracValue, fontColor, currentUnormCoord, fixedUnormCoord, color, leading0, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Debug rendering is performed at the end of the frame (after post-processing).
|
||||
// Debug textures are never flipped upside-down automatically. Therefore, we must always flip manually.
|
||||
bool ShouldFlipDebugTexture()
|
||||
{
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
return (_ProjectionParams.x > 0);
|
||||
#else
|
||||
return (_ProjectionParams.x < 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
9
Runtime/HDRP/Shaders/DebugDisplayHDRP7.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/DebugDisplayHDRP7.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca33d18de8f732043b31a7b3d76017f0
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Runtime/HDRP/Shaders/DecodeDepthNormals.hlsl
Normal file
27
Runtime/HDRP/Shaders/DecodeDepthNormals.hlsl
Normal file
@@ -0,0 +1,27 @@
|
||||
//#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl"
|
||||
|
||||
#ifndef DECODEDEPTHNORMALS_INCLUDED
|
||||
#define DECODEDEPTHNORMALS_INCLUDED
|
||||
|
||||
|
||||
inline float DecodeFloatRG(float2 enc) {
|
||||
float2 kDecodeDot = float2(1.0, 1 / 255.0);
|
||||
return dot(enc, kDecodeDot);
|
||||
}
|
||||
|
||||
inline float3 DecodeViewNormalStereo(float4 enc4) {
|
||||
float kScale = 1.7777;
|
||||
float3 nn = enc4.xyz * float3(2 * kScale, 2 * kScale, 0) + float3(-kScale, -kScale, 1);
|
||||
float g = 2.0 / dot(nn.xyz, nn.xyz);
|
||||
float3 n;
|
||||
n.xy = g * nn.xy;
|
||||
n.z = g - 1;
|
||||
return n;
|
||||
}
|
||||
|
||||
inline void DecodeDepthNormal(float4 enc, out float depth, out float3 normal) {
|
||||
depth = DecodeFloatRG(enc.zw);
|
||||
normal = DecodeViewNormalStereo(enc);
|
||||
}
|
||||
|
||||
#endif
|
||||
7
Runtime/HDRP/Shaders/DecodeDepthNormals.hlsl.meta
Normal file
7
Runtime/HDRP/Shaders/DecodeDepthNormals.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 583ca489f74f54c45a708f3a17018fca
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
298
Runtime/HDRP/Shaders/DoubleShadeWithFeatherMainLight.hlsl
Normal file
298
Runtime/HDRP/Shaders/DoubleShadeWithFeatherMainLight.hlsl
Normal file
@@ -0,0 +1,298 @@
|
||||
//Unity Toon Shader/HDRP
|
||||
//nobuyuki@unity3d.com
|
||||
//toshiyuki@unity3d.com (Universal RP/HDRP)
|
||||
|
||||
float3 UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, float3 mainLihgtDirection, float3 mainLightColor, out float inverseClipping, out float channelOutAlpha, out UTSData utsData)
|
||||
{
|
||||
channelOutAlpha = 1.0f;
|
||||
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);
|
||||
|
||||
|
||||
#ifdef VARYINGS_NEED_POSITION_WS
|
||||
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
||||
#else
|
||||
// Unused
|
||||
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
|
||||
#endif
|
||||
|
||||
SurfaceData surfaceData;
|
||||
BuiltinData builtinData;
|
||||
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
|
||||
|
||||
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData);
|
||||
|
||||
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
|
||||
/* todo. these should be put int a struct */
|
||||
float4 Set_UV0 = input.texCoord0;
|
||||
float3x3 tangentTransform = input.tangentToWorld;
|
||||
//UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, texCoords))
|
||||
float4 n = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, Set_UV0.xy);
|
||||
// float3 _NormalMap_var = UnpackNormalScale(tex2D(_NormalMap, TRANSFORM_TEX(Set_UV0, _NormalMap)), _BumpScale);
|
||||
float3 _NormalMap_var = UnpackNormalScale(n, _BumpScale);
|
||||
float3 normalLocal = _NormalMap_var.rgb;
|
||||
utsData.normalDirection = normalize(mul(normalLocal, tangentTransform)); // Perturbed normals
|
||||
|
||||
float4 _BaseColorMap_var = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, TRANSFORM_TEX(Set_UV0, _BaseColorMap));
|
||||
float3 i_normalDir = surfaceData.normalWS;
|
||||
utsData.viewDirection = V;
|
||||
/* to here todo. these should be put int a struct */
|
||||
|
||||
//v.2.0.4
|
||||
#if defined(_IS_CLIPPING_MODE)
|
||||
//DoubleShadeWithFeather_Clipping
|
||||
float4 _ClippingMask_var = SAMPLE_TEXTURE2D(_ClippingMask, sampler_BaseColorMap, TRANSFORM_TEX(Set_UV0, _ClippingMask));
|
||||
float Set_Clipping = saturate((lerp(_ClippingMask_var.r, (1.0 - _ClippingMask_var.r), _Inverse_Clipping) + _Clipping_Level));
|
||||
clip(Set_Clipping - 0.5);
|
||||
#elif defined(_IS_CLIPPING_TRANSMODE) || defined(_IS_TRANSCLIPPING_ON)
|
||||
//DoubleShadeWithFeather_TransClipping
|
||||
float4 _ClippingMask_var = SAMPLE_TEXTURE2D(_ClippingMask, sampler_BaseColorMap, TRANSFORM_TEX(Set_UV0, _ClippingMask));
|
||||
float Set_BaseColorMapAlpha = _BaseColorMap_var.a;
|
||||
float _IsBaseMapAlphaAsClippingMask_var = lerp(_ClippingMask_var.r, Set_BaseColorMapAlpha, _IsBaseMapAlphaAsClippingMask);
|
||||
float _Inverse_Clipping_var = lerp(_IsBaseMapAlphaAsClippingMask_var, (1.0 - _IsBaseMapAlphaAsClippingMask_var), _Inverse_Clipping);
|
||||
float Set_Clipping = saturate((_Inverse_Clipping_var + _Clipping_Level));
|
||||
clip(Set_Clipping - 0.5);
|
||||
inverseClipping = _Inverse_Clipping_var;
|
||||
#elif defined(_IS_CLIPPING_OFF) || defined(_IS_TRANSCLIPPING_OFF)
|
||||
//DoubleShadeWithFeather
|
||||
#endif
|
||||
|
||||
float shadowAttenuation = (float)lightLoopContext.shadowValue;
|
||||
|
||||
|
||||
|
||||
// float4 tmpColor = EvaluateLight_Directional(context, posInput, _DirectionalLightDatas[mainLightIndex]);
|
||||
// float3 mainLightColor = tmpColor.xyz;
|
||||
float3 defaultLightDirection = normalize(UNITY_MATRIX_V[2].xyz + UNITY_MATRIX_V[1].xyz);
|
||||
float3 defaultLightColor = saturate(max(float3(0.05, 0.05, 0.05) * _Unlit_Intensity, max(ShadeSH9(float4(0.0, 0.0, 0.0, 1.0)), ShadeSH9(float4(0.0, -1.0, 0.0, 1.0)).rgb) * _Unlit_Intensity));
|
||||
float3 customLightDirection = normalize(mul(UNITY_MATRIX_M, float4(((float3(1.0, 0.0, 0.0) * _Offset_X_Axis_BLD * 10) + (float3(0.0, 1.0, 0.0) * _Offset_Y_Axis_BLD * 10) + (float3(0.0, 0.0, -1.0) * lerp(-1.0, 1.0, _Inverse_Z_Axis_BLD))), 0)).xyz);
|
||||
float3 lightDirection = normalize(lerp(defaultLightDirection, mainLihgtDirection.xyz, any(mainLihgtDirection.xyz)));
|
||||
lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD);
|
||||
float3 originalLightColor = mainLightColor;
|
||||
|
||||
originalLightColor = lerp(originalLightColor, clamp(originalLightColor, ConvertFromEV100(_ToonEvAdjustmentValueMin ), ConvertFromEV100(_ToonEvAdjustmentValueMax)), _ToonEvAdjustmentCurve);
|
||||
float3 lightColor = lerp(max(defaultLightColor, originalLightColor), max(defaultLightColor, saturate(originalLightColor)), max(_Is_Filter_LightColor, _ToonLightHiCutFilter));
|
||||
|
||||
|
||||
////// Lighting:
|
||||
float3 halfDirection = normalize(utsData.viewDirection + lightDirection);
|
||||
//v.2.0.5
|
||||
_Color = _BaseColor;
|
||||
float3 Set_LightColor = lightColor.rgb;
|
||||
float3 Set_BaseColor = lerp((_BaseColorMap_var.rgb * _BaseColor.rgb), ((_BaseColorMap_var.rgb * _BaseColor.rgb) * Set_LightColor), _Is_LightColor_Base);
|
||||
float3 clippingColor = float3(1.0f, 1.0f, 1.0f);
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode == 5)
|
||||
{
|
||||
clippingColor = float3(0.0f, 0.0f, 0.0f);
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode == 1)
|
||||
{
|
||||
clippingColor = Set_BaseColor;
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
float3 overridingColor = lerp(_BaseColorMaskColor, float4(_BaseColorMaskColor.w, _BaseColorMaskColor.w, _BaseColorMaskColor.w, 1.0f), _ComposerMaskMode).xyz;
|
||||
float maskEnabled = max(_BaseColorOverridden, _ComposerMaskMode);
|
||||
Set_BaseColor = lerp(Set_BaseColor, overridingColor, maskEnabled);
|
||||
Set_BaseColor *= _BaseColorVisible;
|
||||
float Set_BaseColorAlpha = _BaseColorVisible;
|
||||
#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)), _BaseColorMap_var, _Use_BaseAs1st);
|
||||
float3 Set_1st_ShadeColor = lerp((_1st_ShadeColor.rgb * _1st_ShadeMap_var.rgb), ((_1st_ShadeColor.rgb * _1st_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_1st_Shade);
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode == 2)
|
||||
{
|
||||
clippingColor = Set_1st_ShadeColor;
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
{
|
||||
float4 overridingColor = lerp(_FirstShadeMaskColor, float4(_FirstShadeMaskColor.w, _FirstShadeMaskColor.w, _FirstShadeMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_FirstShadeOverridden, _ComposerMaskMode);
|
||||
Set_1st_ShadeColor = lerp(Set_1st_ShadeColor, overridingColor.xyz, maskEnabled);
|
||||
Set_1st_ShadeColor = lerp(Set_1st_ShadeColor, Set_BaseColor, 1.0f - _FirstShadeVisible);
|
||||
}
|
||||
float Set_1st_ShadeAlpha = _FirstShadeVisible;
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY
|
||||
//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);
|
||||
float3 Set_2nd_ShadeColor = lerp((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb), ((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_2nd_Shade);
|
||||
float _HalfLambert_var = 0.5 * dot(lerp(i_normalDir, utsData.normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5;
|
||||
float4 _Set_2nd_ShadePosition_var = tex2D(_Set_2nd_ShadePosition, TRANSFORM_TEX(Set_UV0, _Set_2nd_ShadePosition));
|
||||
float4 _Set_1st_ShadePosition_var = tex2D(_Set_1st_ShadePosition, TRANSFORM_TEX(Set_UV0, _Set_1st_ShadePosition));
|
||||
|
||||
float _1stColorFeatherForMask = lerp(_BaseShade_Feather, 0.0f, max(_FirstShadeOverridden, _ComposerMaskMode));
|
||||
float _2ndColorFeatherForMask = lerp(_1st2nd_Shades_Feather, 0.0f, max(_SecondShadeOverridden, _ComposerMaskMode));
|
||||
|
||||
|
||||
//v.2.0.6
|
||||
//Minmimum value is same as the Minimum Feather's value with the Minimum Step's value as threshold.
|
||||
float _SystemShadowsLevel_var = (shadowAttenuation * 0.5) + 0.5 + _Tweak_SystemShadowsLevel > 0.001 ? (shadowAttenuation * 0.5) + 0.5 + _Tweak_SystemShadowsLevel : 0.0001;
|
||||
float Set_FinalShadowMask = saturate((1.0 + ((lerp(_HalfLambert_var, _HalfLambert_var * saturate(_SystemShadowsLevel_var), _Set_SystemShadowsToBase) - (_BaseColor_Step - _1stColorFeatherForMask)) * ((1.0 - _Set_1st_ShadePosition_var.rgb).r - 1.0)) / (_BaseColor_Step - (_BaseColor_Step - _1stColorFeatherForMask))));
|
||||
//
|
||||
//Composition: 3 Basic Colors as Set_FinalBaseColor
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode == 3)
|
||||
{
|
||||
clippingColor = Set_2nd_ShadeColor;
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
{
|
||||
float4 overridingColor = lerp(_SecondShadeMaskColor, float4(_SecondShadeMaskColor.w, _SecondShadeMaskColor.w, _SecondShadeMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_SecondShadeOverridden, _ComposerMaskMode);
|
||||
Set_2nd_ShadeColor = lerp(Set_2nd_ShadeColor, overridingColor.xyz, maskEnabled);
|
||||
Set_2nd_ShadeColor = lerp(Set_2nd_ShadeColor, Set_BaseColor, 1.0f - _SecondShadeVisible);
|
||||
}
|
||||
float Set_2nd_ShadeAlpha = _SecondShadeVisible;
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY
|
||||
float3 Set_FinalBaseColor = lerp(Set_BaseColor, lerp(Set_1st_ShadeColor, Set_2nd_ShadeColor, saturate((1.0 + ((_HalfLambert_var - (_ShadeColor_Step - _2ndColorFeatherForMask)) * ((1.0 - _Set_2nd_ShadePosition_var.rgb).r - 1.0)) / (_ShadeColor_Step - (_ShadeColor_Step - _2ndColorFeatherForMask))))), Set_FinalShadowMask); // Final Color
|
||||
channelOutAlpha = lerp(Set_BaseColorAlpha, lerp(Set_1st_ShadeAlpha, Set_2nd_ShadeAlpha, saturate((1.0 + ((_HalfLambert_var - (_ShadeColor_Step - _2ndColorFeatherForMask)) * ((1.0 - _Set_2nd_ShadePosition_var.rgb).r - 1.0)) / (_ShadeColor_Step - (_ShadeColor_Step - _2ndColorFeatherForMask))))), Set_FinalShadowMask);
|
||||
float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask));
|
||||
float _Specular_var = 0.5 * dot(halfDirection, lerp(i_normalDir, utsData.normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular
|
||||
float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel)) * lerp((1.0 - step(_Specular_var, (1.0 - pow(_HighColor_Power, 5)))), pow(abs(_Specular_var), exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor));
|
||||
float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex));
|
||||
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
|
||||
if (_ClippingMatteMode == 4)
|
||||
{
|
||||
clippingColor = _HighColorWithOutTweak_var;
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
//Composition: 3 Basic Colors and HighColor as Set_HighColor
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
float3 Set_HighColor;
|
||||
{
|
||||
float4 overridingColor = lerp(_HighlightMaskColor, float4(_HighlightMaskColor.w, _HighlightMaskColor.w, _HighlightMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_HighlightOverridden, _ComposerMaskMode);
|
||||
|
||||
_HighColor_var *= _HighlightVisible;
|
||||
Set_HighColor =
|
||||
lerp(SATURATE_IF_SDR(Set_FinalBaseColor - _TweakHighColorMask_var), Set_FinalBaseColor,
|
||||
lerp(_Is_BlendAddToHiColor, 1.0
|
||||
, _Is_SpecularToHighColor));
|
||||
float3 addColor =
|
||||
lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow)))
|
||||
, _Is_UseTweakHighColorOnShadow);
|
||||
Set_HighColor += addColor;
|
||||
if (any(addColor))
|
||||
{
|
||||
Set_HighColor = lerp(Set_HighColor, overridingColor.xyz, maskEnabled);
|
||||
channelOutAlpha = _HighlightVisible;
|
||||
}
|
||||
}
|
||||
|
||||
#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
|
||||
float4 _Set_RimLightMask_var = tex2D(_Set_RimLightMask, TRANSFORM_TEX(Set_UV0, _Set_RimLightMask));
|
||||
float3 _Is_LightColor_RimLight_var = lerp(_RimLightColor.rgb, (_RimLightColor.rgb * Set_LightColor), _Is_LightColor_RimLight);
|
||||
float _RimArea_var = abs((1.0 - dot(lerp(i_normalDir, utsData.normalDirection, _Is_NormalMapToRimLight), utsData.viewDirection)));
|
||||
float _RimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _RimLight_Power)));
|
||||
float _Rimlight_InsideMask_var = saturate(lerp((0.0 + ((_RimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), step(_RimLight_InsideMask, _RimLightPower_var), _RimLight_FeatherOff));
|
||||
float _VertHalfLambert_var = 0.5 * dot(i_normalDir, lightDirection) + 0.5;
|
||||
float3 _LightDirection_MaskOn_var = lerp((_Is_LightColor_RimLight_var * _Rimlight_InsideMask_var), (_Is_LightColor_RimLight_var * saturate((_Rimlight_InsideMask_var - ((1.0 - _VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel)))), _LightDirection_MaskOn);
|
||||
float _ApRimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _Ap_RimLight_Power)));
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
float4 overridingRimColor = lerp(_RimLightMaskColor, float4(_RimLightMaskColor.w, _RimLightMaskColor.w, _RimLightMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskRimEnabled = max(_RimLightOverridden, _ComposerMaskMode);
|
||||
float Set_RimLightAlpha = _RimLightVisible;
|
||||
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 *= _RimLightVisible;
|
||||
float3 _RimLight_var = lerp(Set_HighColor, (Set_HighColor + Set_RimLight), _RimLight);
|
||||
if (any(Set_RimLight) * maskRimEnabled)
|
||||
{
|
||||
_RimLight_var = overridingRimColor.xyz;
|
||||
channelOutAlpha = Set_RimLightAlpha;
|
||||
}
|
||||
#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));
|
||||
//Composition: HighColor and RimLight as _RimLight_var
|
||||
float3 _RimLight_var = lerp(Set_HighColor, (Set_HighColor + Set_RimLight), _RimLight);
|
||||
#endif
|
||||
//Matcap
|
||||
//v.2.0.6 : CameraRolling Stabilizer
|
||||
//Mirror Script Determination: if sign_Mirror = -1, determine "Inside the mirror".
|
||||
//v.2.0.7
|
||||
utsData.signMirror = 0.0; // i.mirrorFlag; todo.
|
||||
float3 _Camera_Right = UNITY_MATRIX_V[0].xyz;
|
||||
float3 _Camera_Front = UNITY_MATRIX_V[2].xyz;
|
||||
float3 _Up_Unit = float3(0, 1, 0);
|
||||
float3 _Right_Axis = cross(_Camera_Front, _Up_Unit);
|
||||
|
||||
//Invert if it's "inside the mirror".
|
||||
if (utsData.signMirror < 0) {
|
||||
_Right_Axis = -1 * _Right_Axis;
|
||||
_Rotate_MatCapUV = -1 * _Rotate_MatCapUV;
|
||||
}
|
||||
else {
|
||||
_Right_Axis = _Right_Axis;
|
||||
}
|
||||
float _Camera_Right_Magnitude = sqrt(_Camera_Right.x * _Camera_Right.x + _Camera_Right.y * _Camera_Right.y + _Camera_Right.z * _Camera_Right.z);
|
||||
float _Right_Axis_Magnitude = sqrt(_Right_Axis.x * _Right_Axis.x + _Right_Axis.y * _Right_Axis.y + _Right_Axis.z * _Right_Axis.z);
|
||||
float _Camera_Roll_Cos = dot(_Right_Axis, _Camera_Right) / (_Right_Axis_Magnitude * _Camera_Right_Magnitude);
|
||||
utsData.cameraRoll = acos(clamp(_Camera_Roll_Cos, -1, 1));
|
||||
utsData.cameraDir = _Camera_Right.y < 0 ? -1 : 1;
|
||||
float _Rot_MatCapUV_var_ang = (_Rotate_MatCapUV * 3.141592654) - utsData.cameraDir * utsData.cameraRoll * _CameraRolling_Stabilizer;
|
||||
//v.2.0.7
|
||||
float2 _Rot_MatCapNmUV_var = RotateUV(Set_UV0.xy, (_Rotate_NormalMapForMatCapUV * 3.141592654f), float2(0.5, 0.5), 1.0);
|
||||
//V.2.0.6
|
||||
float3 _NormalMapForMatCap_var = UnpackNormalScale(tex2D(_NormalMapForMatCap, TRANSFORM_TEX(_Rot_MatCapNmUV_var, _NormalMapForMatCap)), _BumpScaleMatcap);
|
||||
//v.2.0.5: MatCap with camera skew correction
|
||||
float3 viewNormal = (mul(UNITY_MATRIX_V, float4(lerp(i_normalDir, mul(_NormalMapForMatCap_var.rgb, tangentTransform).rgb, _Is_NormalMapForMatCap), 0))).rgb;
|
||||
float3 NormalBlend_MatcapUV_Detail = viewNormal.rgb * float3(-1, -1, 1);
|
||||
float3 NormalBlend_MatcapUV_Base = (mul(UNITY_MATRIX_V, float4(utsData.viewDirection, 0)).rgb * float3(-1, -1, 1)) + float3(0, 0, 1);
|
||||
float3 noSknewViewNormal = NormalBlend_MatcapUV_Base * dot(NormalBlend_MatcapUV_Base, NormalBlend_MatcapUV_Detail) / NormalBlend_MatcapUV_Base.b - NormalBlend_MatcapUV_Detail;
|
||||
float2 _ViewNormalAsMatCapUV = (lerp(noSknewViewNormal, viewNormal, _Is_Ortho).rg * 0.5) + 0.5;
|
||||
//v.2.0.7
|
||||
float2 _Rot_MatCapUV_var = RotateUV((0.0 + ((_ViewNormalAsMatCapUV - (0.0 + _Tweak_MatCapUV)) * (1.0 - 0.0)) / ((1.0 - _Tweak_MatCapUV) - (0.0 + _Tweak_MatCapUV))), _Rot_MatCapUV_var_ang, float2(0.5, 0.5), 1.0);
|
||||
//Invert if it's "inside the mirror".
|
||||
if (utsData.signMirror < 0) {
|
||||
_Rot_MatCapUV_var.x = 1 - _Rot_MatCapUV_var.x;
|
||||
}
|
||||
else {
|
||||
_Rot_MatCapUV_var = _Rot_MatCapUV_var;
|
||||
}
|
||||
//v.2.0.6 : LOD of Matcap
|
||||
//
|
||||
//MatcapMask
|
||||
float4 _MatCap_Sampler_var = tex2Dlod(_MatCap_Sampler, float4(TRANSFORM_TEX(_Rot_MatCapUV_var, _MatCap_Sampler), 0.0, _BlurLevelMatcap));
|
||||
float4 _Set_MatcapMask_var = tex2D(_Set_MatcapMask, TRANSFORM_TEX(Set_UV0, _Set_MatcapMask));
|
||||
float _Tweak_MatcapMaskLevel_var = saturate(lerp(_Set_MatcapMask_var.g, (1.0 - _Set_MatcapMask_var.g), _Inverse_MatcapMask) + _Tweak_MatcapMaskLevel);
|
||||
//
|
||||
float3 _Is_LightColor_MatCap_var = lerp((_MatCap_Sampler_var.rgb * _MatCapColor.rgb), ((_MatCap_Sampler_var.rgb * _MatCapColor.rgb) * Set_LightColor), _Is_LightColor_MatCap);
|
||||
//v.2.0.6 : ShadowMask on Matcap in Blend mode : multiply
|
||||
float3 Set_MatCap = lerp(_Is_LightColor_MatCap_var, (_Is_LightColor_MatCap_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakMatCapOnShadow)) + lerp(Set_HighColor * Set_FinalShadowMask * (1.0 - _TweakMatCapOnShadow), float3(0.0, 0.0, 0.0), _Is_BlendAddToMatCap)), _Is_UseTweakMatCapOnShadow);
|
||||
|
||||
//
|
||||
//Composition: RimLight and MatCap as finalColor
|
||||
//Broke down finalColor composition
|
||||
float3 matCapColorOnAddMode = _RimLight_var + Set_MatCap * _Tweak_MatcapMaskLevel_var;
|
||||
float _Tweak_MatcapMaskLevel_var_MultiplyMode = _Tweak_MatcapMaskLevel_var * lerp(1.0, (1.0 - (Set_FinalShadowMask) * (1.0 - _TweakMatCapOnShadow)), _Is_UseTweakMatCapOnShadow);
|
||||
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);
|
||||
float3 finalColor = lerp(_RimLight_var, matCapColorFinal, _MatCap);// Final Composition before Emissive
|
||||
//
|
||||
//v.2.0.6: GI_Intensity with Intensity Multiplier Filter
|
||||
float3 envLightColor = DecodeLightProbe(utsData.normalDirection) < float3(1, 1, 1) ? DecodeLightProbe(utsData.normalDirection) : float3(1, 1, 1);
|
||||
float envLightIntensity = 0.299 * envLightColor.r + 0.587 * envLightColor.g + 0.114 * envLightColor.b < 1 ? (0.299 * envLightColor.r + 0.587 * envLightColor.g + 0.114 * envLightColor.b) : 1;
|
||||
|
||||
finalColor = SATURATE_IF_SDR(finalColor) + (envLightColor * envLightIntensity * _GI_Intensity * smoothstep(1, 0, envLightIntensity / 2)) + emissive;
|
||||
|
||||
|
||||
return finalColor;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f3d7136d29e4e94694ab0df05f6a94c
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
143
Runtime/HDRP/Shaders/DoubleShadeWithFeatherOtherLight.hlsl
Normal file
143
Runtime/HDRP/Shaders/DoubleShadeWithFeatherOtherLight.hlsl
Normal file
@@ -0,0 +1,143 @@
|
||||
//Unity Toon Shader/HDRP
|
||||
//nobuyuki@unity3d.com
|
||||
//toshiyuki@unity3d.com (Universal RP/HDRP)
|
||||
|
||||
float3 UTS_OtherLights(FragInputs input, float3 i_normalDir,
|
||||
float3 additionalLightColor, float3 lightDirection, float notDirectional, out float channelOutAlpha)
|
||||
{
|
||||
channelOutAlpha = 1.0f;
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode != 0)
|
||||
{
|
||||
|
||||
return float3(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
|
||||
/* todo. these should be put into struct */
|
||||
#ifdef VARYINGS_NEED_POSITION_WS
|
||||
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
||||
#else
|
||||
// Unused
|
||||
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
|
||||
#endif
|
||||
|
||||
float4 Set_UV0 = input.texCoord0;
|
||||
float3x3 tangentTransform = input.tangentToWorld;
|
||||
//UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, texCoords))
|
||||
float4 n = SAMPLE_TEXTURE2D_LOD(_NormalMap, sampler_NormalMap, Set_UV0.xy, 0);
|
||||
// float3 _NormalMap_var = UnpackNormalScale(tex2D(_NormalMap, TRANSFORM_TEX(Set_UV0, _NormalMap)), _BumpScale);
|
||||
float3 _NormalMap_var = UnpackNormalScale(n, _BumpScale);
|
||||
float3 normalLocal = _NormalMap_var.rgb;
|
||||
float3 normalDirection = normalize(mul(normalLocal, tangentTransform)); // Perturbed normals
|
||||
// float3 i_normalDir = surfaceData.normalWS;
|
||||
float3 viewDirection = V;
|
||||
float4 _MainTex_var = SAMPLE_TEXTURE2D_LOD(_MainTex, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _MainTex), 0.0f);
|
||||
/* end of todo.*/
|
||||
|
||||
|
||||
|
||||
//v.2.0.5:
|
||||
float3 addPassLightColor = (0.5 * dot(lerp(i_normalDir, normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5) * additionalLightColor.rgb;
|
||||
float pureIntencity = max(0.001, (0.299 * additionalLightColor.r + 0.587 * additionalLightColor.g + 0.114 * additionalLightColor.b));
|
||||
float3 lightColor = max(0, lerp(addPassLightColor, lerp(0, min(addPassLightColor, addPassLightColor / pureIntencity), notDirectional), _Is_Filter_LightColor));
|
||||
float3 halfDirection = normalize(viewDirection + lightDirection); // has to be recalced here.
|
||||
//v.2.0.5:
|
||||
_BaseColor_Step = saturate(_BaseColor_Step + _StepOffset);
|
||||
_ShadeColor_Step = saturate(_ShadeColor_Step + _StepOffset);
|
||||
//
|
||||
//v.2.0.5: If Added lights is directional, set 0 as _LightIntensity
|
||||
float _LightIntensity = lerp(0, (0.299 * additionalLightColor.r + 0.587 * additionalLightColor.g + 0.114 * additionalLightColor.b), notDirectional);
|
||||
//v.2.0.5: Filtering the high intensity zone of PointLights
|
||||
float3 Set_LightColor = lightColor;
|
||||
//
|
||||
float3 Set_BaseColor = lerp((_BaseColor.rgb * _MainTex_var.rgb * _LightIntensity), ((_BaseColor.rgb * _MainTex_var.rgb) * Set_LightColor), _Is_LightColor_Base);
|
||||
|
||||
#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.xyz, maskEnabled);
|
||||
Set_BaseColor *= _BaseColorVisible;
|
||||
float Set_BaseColorAlpha = _BaseColorVisible;
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY //v.2.0.5
|
||||
float4 _1st_ShadeMap_var = lerp(SAMPLE_TEXTURE2D_LOD(_1st_ShadeMap, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _1st_ShadeMap),0.0f), _MainTex_var, _Use_BaseAs1st);
|
||||
float3 Set_1st_ShadeColor = lerp((_1st_ShadeColor.rgb * _1st_ShadeMap_var.rgb * _LightIntensity), ((_1st_ShadeColor.rgb * _1st_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_1st_Shade);
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
{
|
||||
float4 overridingColor = lerp(_FirstShadeMaskColor, float4(_FirstShadeMaskColor.w, _FirstShadeMaskColor.w, _FirstShadeMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_FirstShadeOverridden, _ComposerMaskMode);
|
||||
Set_1st_ShadeColor = lerp(Set_1st_ShadeColor, overridingColor.xyz, maskEnabled);
|
||||
Set_1st_ShadeColor = lerp(Set_1st_ShadeColor, Set_BaseColor, 1.0f - _FirstShadeVisible);
|
||||
}
|
||||
float Set_1st_ShadeAlpha = _FirstShadeVisible;
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY //v.2.0.5
|
||||
float4 _2nd_ShadeMap_var = lerp(SAMPLE_TEXTURE2D_LOD(_2nd_ShadeMap, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _2nd_ShadeMap), 0.0), _1st_ShadeMap_var, _Use_1stAs2nd);
|
||||
float3 Set_2nd_ShadeColor = lerp((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb * _LightIntensity), ((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_2nd_Shade);
|
||||
float _HalfLambert_var = 0.5 * dot(lerp(i_normalDir, normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5;
|
||||
float4 _Set_2nd_ShadePosition_var = tex2Dlod(_Set_2nd_ShadePosition, float4(TRANSFORM_TEX(Set_UV0, _Set_2nd_ShadePosition),0.0f,0.0f));
|
||||
float4 _Set_1st_ShadePosition_var = tex2Dlod(_Set_1st_ShadePosition, float4(TRANSFORM_TEX(Set_UV0, _Set_1st_ShadePosition),0.0f, 0.0f));
|
||||
//v.2.0.5:
|
||||
float _1stColorFeatherForMask = lerp(_BaseShade_Feather, 0.0f, max(_FirstShadeOverridden, _ComposerMaskMode));
|
||||
float _2ndColorFeatherForMask = lerp(_1st2nd_Shades_Feather, 0.0f, max(_SecondShadeOverridden, _ComposerMaskMode));
|
||||
float Set_FinalShadowMask = saturate((1.0 + ((lerp(_HalfLambert_var, (_HalfLambert_var * saturate(1.0 + _Tweak_SystemShadowsLevel)), _Set_SystemShadowsToBase) - (_BaseColor_Step - _1stColorFeatherForMask)) * ((1.0 - _Set_1st_ShadePosition_var.rgb).r - 1.0)) / (_BaseColor_Step - (_BaseColor_Step - _1stColorFeatherForMask))));
|
||||
|
||||
|
||||
|
||||
|
||||
//Composition: 3 Basic Colors as finalColor
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
{
|
||||
float4 overridingColor = lerp(_SecondShadeMaskColor, float4(_SecondShadeMaskColor.w, _SecondShadeMaskColor.w, _SecondShadeMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_SecondShadeOverridden, _ComposerMaskMode);
|
||||
Set_2nd_ShadeColor = lerp(Set_2nd_ShadeColor, overridingColor.xyz, maskEnabled);
|
||||
Set_2nd_ShadeColor = lerp(Set_2nd_ShadeColor, Set_BaseColor, 1.0f - _SecondShadeVisible);
|
||||
}
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY
|
||||
float3 finalColor = lerp(Set_BaseColor, lerp(Set_1st_ShadeColor, Set_2nd_ShadeColor, saturate((1.0 + ((_HalfLambert_var - (_ShadeColor_Step - _2ndColorFeatherForMask)) * ((1.0 - _Set_2nd_ShadePosition_var.rgb).r - 1.0)) / (_ShadeColor_Step - (_ShadeColor_Step - _2ndColorFeatherForMask))))), Set_FinalShadowMask); // Final Color
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
float Set_2nd_ShadeAlpha = _SecondShadeVisible;
|
||||
channelOutAlpha = lerp(Set_BaseColorAlpha, lerp(Set_1st_ShadeAlpha, Set_2nd_ShadeAlpha, saturate((1.0 + ((_HalfLambert_var - (_ShadeColor_Step - _2ndColorFeatherForMask)) * ((1.0 - _Set_2nd_ShadePosition_var.rgb).r - 1.0)) / (_ShadeColor_Step - (_ShadeColor_Step - _2ndColorFeatherForMask))))), Set_FinalShadowMask);
|
||||
#endif
|
||||
//v.2.0.6: Add HighColor if _Is_Filter_HiCutPointLightColor is False
|
||||
|
||||
float4 _Set_HighColorMask_var = tex2Dlod(_Set_HighColorMask, float4(TRANSFORM_TEX(Set_UV0, _Set_HighColorMask),0.0f,0.0f));
|
||||
float _Specular_var = 0.5 * dot(halfDirection, lerp(i_normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular
|
||||
float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel)) * lerp((1.0 - step(_Specular_var, (1.0 - pow(abs(_HighColor_Power), 5)))), pow(abs(_Specular_var), exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor));
|
||||
float4 _HighColor_Tex_var = tex2Dlod(_HighColor_Tex, float4( TRANSFORM_TEX(Set_UV0, _HighColor_Tex),0.0f,0.0f));
|
||||
|
||||
float3 _HighColor_var = lerp((_HighColor_Tex_var.rgb * _HighColor.rgb), ((_HighColor_Tex_var.rgb * _HighColor.rgb) * Set_LightColor), _Is_LightColor_HighColor);
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
{
|
||||
float4 overridingColor = lerp(_HighlightMaskColor, float4(_HighlightMaskColor.w, _HighlightMaskColor.w, _HighlightMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_HighlightOverridden, _ComposerMaskMode);
|
||||
_HighColor_var *= _TweakHighColorMask_var;
|
||||
_HighColor_var *= _HighlightVisible;
|
||||
finalColor =
|
||||
lerp(saturate(finalColor - _TweakHighColorMask_var), finalColor,
|
||||
lerp(_Is_BlendAddToHiColor, 1.0
|
||||
, _Is_SpecularToHighColor));
|
||||
float3 addColor =
|
||||
lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow)))
|
||||
, _Is_UseTweakHighColorOnShadow);
|
||||
finalColor += addColor;
|
||||
if (any(addColor))
|
||||
{
|
||||
finalColor = lerp(finalColor, overridingColor.xyz, maskEnabled);
|
||||
channelOutAlpha = _HighlightVisible;
|
||||
}
|
||||
|
||||
}
|
||||
#else
|
||||
_HighColor_var *= _TweakHighColorMask_var;
|
||||
finalColor = finalColor + lerp(lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow))), _Is_UseTweakHighColorOnShadow), float3(0, 0, 0), _Is_Filter_HiCutPointLightColor);
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY
|
||||
//
|
||||
|
||||
finalColor = SATURATE_IF_SDR(finalColor);
|
||||
|
||||
// pointLightColor += finalColor;
|
||||
|
||||
|
||||
|
||||
return finalColor;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 840a356bfe23a2d47830da601e134150
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
239
Runtime/HDRP/Shaders/EnvLighting.hlsl
Normal file
239
Runtime/HDRP/Shaders/EnvLighting.hlsl
Normal file
@@ -0,0 +1,239 @@
|
||||
#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,
|
||||
PreLightData preLightData, EnvLightData lightData, BSDFData bsdfData,
|
||||
int influenceShapeType,
|
||||
inout float hierarchyWeight)
|
||||
{
|
||||
IndirectLighting lighting;
|
||||
ZERO_INITIALIZE(IndirectLighting, lighting);
|
||||
|
||||
float3 envLighting;
|
||||
float weight = 1.0;
|
||||
|
||||
float3 R = reflect(-V, bsdfData.normalWS);
|
||||
|
||||
EvaluateLight_EnvIntersection(posInput.positionWS, bsdfData.normalWS, lightData, influenceShapeType, R, weight);
|
||||
|
||||
// 31 bit index, 1 bit cache type
|
||||
uint cacheType = IsEnvIndexCubemap(lightData.envIndex) ? ENVCACHETYPE_CUBEMAP : ENVCACHETYPE_TEXTURE2D;
|
||||
// Index start at 1, because -0 == 0, so we can't known which cache to sample for that index. Thus it is invalid.
|
||||
int index = abs(lightData.envIndex) - 1;
|
||||
|
||||
float lod = PerceptualRoughnessToMipmapLevel(preLightData.iblPerceptualRoughness) * lightData.roughReflections;
|
||||
float2 atlasCoords = GetReflectionAtlasCoordsCube(CUBE_SCALE_OFFSET[index], R, lod);
|
||||
|
||||
// No distance based roughness for simple lit
|
||||
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, PerceptualRoughnessToMipmapLevel(preLightData.iblPerceptualRoughness) * lightData.roughReflections, lightData.rangeCompressionFactorCompensation, posInput.positionNDC);
|
||||
weight *= preLD.a; // Used by planar reflection to discard pixel
|
||||
|
||||
//envLighting = F_Schlick(bsdfData.fresnel0, dot(bsdfData.normalWS, V)) * preLD.rgb;
|
||||
envLighting = preLD.rgb;
|
||||
|
||||
UpdateLightingHierarchyWeights(hierarchyWeight, weight);
|
||||
envLighting *= weight * lightData.multiplier;
|
||||
|
||||
lighting.specularReflected = envLighting;
|
||||
|
||||
return lighting;
|
||||
}
|
||||
|
||||
float4 ComputeReflection(LightLoopContext context, PositionInputs posInput, PreLightData preLightData, BuiltinData builtinData, float3 V, float lod, BSDFData bsdfData)
|
||||
{
|
||||
float3 refcolor = 0;
|
||||
float reflectionHierarchyWeight = 0.0; // Max: 1.0
|
||||
|
||||
uint envLightStart, envLightCount;
|
||||
|
||||
// Fetch first env light to provide the scene proxy for screen space computation
|
||||
#ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
|
||||
GetCountAndStart(posInput, LIGHTCATEGORY_ENV, envLightStart, envLightCount);
|
||||
#else // LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
|
||||
envLightCount = _EnvLightCount;
|
||||
envLightStart = 0;
|
||||
#endif
|
||||
|
||||
bool fastPath = false;
|
||||
#if SCALARIZE_LIGHT_LOOP
|
||||
uint envStartFirstLane;
|
||||
fastPath = IsFastPath(envLightStart, envStartFirstLane);
|
||||
#endif
|
||||
|
||||
context.sampleReflection = SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES;
|
||||
|
||||
#if SCALARIZE_LIGHT_LOOP
|
||||
if (fastPath)
|
||||
{
|
||||
envLightStart = envStartFirstLane;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Scalarized loop, same rationale of the punctual light version
|
||||
uint v_envLightListOffset = 0;
|
||||
uint v_envLightIdx = envLightStart;
|
||||
#if NEED_TO_CHECK_HELPER_LANE
|
||||
// On some platform helper lanes don't behave as we'd expect, therefore we prevent them from entering the loop altogether.
|
||||
// IMPORTANT! This has implications if ddx/ddy is used on results derived from lighting, however given Lightloop is called in compute we should be
|
||||
// sure it will not happen.
|
||||
bool isHelperLane = WaveIsHelperLane();
|
||||
while (!isHelperLane && v_envLightListOffset < envLightCount)
|
||||
#else
|
||||
while (v_envLightListOffset < envLightCount)
|
||||
#endif
|
||||
{
|
||||
v_envLightIdx = FetchIndex(envLightStart, v_envLightListOffset);
|
||||
#if SCALARIZE_LIGHT_LOOP
|
||||
uint s_envLightIdx = ScalarizeElementIndex(v_envLightIdx, fastPath);
|
||||
#else
|
||||
uint s_envLightIdx = v_envLightIdx;
|
||||
#endif
|
||||
if (s_envLightIdx == -1)
|
||||
break;
|
||||
|
||||
EnvLightData s_envLightData = FetchEnvLight(s_envLightIdx); // Scalar load.
|
||||
|
||||
// If current scalar and vector light index match, we process the light. The v_envLightListOffset for current thread is increased.
|
||||
// Note that the following should really be ==, however, since helper lanes are not considered by WaveActiveMin, such helper lanes could
|
||||
// end up with a unique v_envLightIdx value that is smaller than s_envLightIdx hence being stuck in a loop. All the active lanes will not have this problem.
|
||||
if (s_envLightIdx >= v_envLightIdx)
|
||||
{
|
||||
v_envLightListOffset++;
|
||||
if (reflectionHierarchyWeight < 1.0)
|
||||
{
|
||||
if (IsMatchingLightLayer(s_envLightData.lightLayers, builtinData.renderingLayers))
|
||||
{
|
||||
IndirectLighting lighting = EvaluateBSDF_Env(context, V, posInput, preLightData, s_envLightData, bsdfData, s_envLightData.influenceShapeType, reflectionHierarchyWeight);
|
||||
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
|
||||
float3 lightInReflDir = float3(-1, -1, -1);
|
||||
if (s_envLightData.normalizeWithAPV > 0 && all(lightInReflDir >= 0))
|
||||
{
|
||||
float factor = GetReflectionProbeNormalizationFactor(lightInReflDir, bsdfData.normalWS, s_envLightData.L0L1, s_envLightData.L2_1, s_envLightData.L2_2);
|
||||
lighting.specularReflected *= factor;
|
||||
}
|
||||
#endif
|
||||
refcolor += lighting.specularReflected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return float4(refcolor.r, refcolor.g, refcolor.b, reflectionHierarchyWeight);
|
||||
}
|
||||
|
||||
float3 ComputeFresnelLerp(float3 c0, float3 c1, float cosA)
|
||||
{
|
||||
float t = pow(1 - cosA, 5);
|
||||
return lerp(c0, c1, t);
|
||||
}
|
||||
|
||||
float3 ComputeIndirectDiffuse(PositionInputs posInput, BSDFData bsdfData, float3 V)
|
||||
{
|
||||
float3 indirectDiffuse = 0.0;
|
||||
|
||||
if(_ID_Intensity > 0)
|
||||
{
|
||||
#ifdef _PBR_Mode_ANISO
|
||||
GetGGXAnisotropicModifiedNormalAndRoughness(bsdfData.bitangentWS, bsdfData.tangentWS , bsdfData.normalWS, V, bsdfData.anisotropy, bsdfData.perceptualRoughness, bsdfData.normalWS, bsdfData.perceptualRoughness);
|
||||
#endif
|
||||
|
||||
float NdotV = saturate(dot(bsdfData.normalWS, V));
|
||||
|
||||
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
|
||||
BuiltinData apvBuiltinData;
|
||||
ZERO_INITIALIZE(BuiltinData, apvBuiltinData);
|
||||
|
||||
#if defined(_PBR_Mode_OFF) || defined(_PBR_Mode_TOON)
|
||||
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(posInput.positionWS), 0.0, 0.0, V, posInput.positionSS, apvBuiltinData.bakeDiffuseLighting, apvBuiltinData.backBakeDiffuseLighting);
|
||||
#else
|
||||
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(posInput.positionWS), bsdfData.normalWS, -bsdfData.normalWS, V, posInput.positionSS, apvBuiltinData.bakeDiffuseLighting, apvBuiltinData.backBakeDiffuseLighting);
|
||||
#endif
|
||||
|
||||
float3 probeDiffuse = apvBuiltinData.bakeDiffuseLighting * GetCurrentExposureMultiplier();
|
||||
|
||||
indirectDiffuse = probeDiffuse;
|
||||
#else
|
||||
#if defined(_PBR_Mode_OFF) || defined(_PBR_Mode_TOON)
|
||||
indirectDiffuse = EvaluateAmbientProbe(0.0) * GetCurrentExposureMultiplier();
|
||||
#else
|
||||
indirectDiffuse = EvaluateAmbientProbe(bsdfData.normalWS) * GetCurrentExposureMultiplier();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//SSGI
|
||||
if(_ReceivesSSGI == 1)
|
||||
{
|
||||
float4 ssgiLighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, posInput.positionSS);
|
||||
ssgiLighting *= _GIMultiplier;
|
||||
indirectDiffuse = lerp(indirectDiffuse, ssgiLighting.rgb, ssgiLighting.a);
|
||||
}
|
||||
|
||||
//Compelete the indirect lighting
|
||||
indirectDiffuse = indirectDiffuse * bsdfData.diffuseColor * _BaseColor;
|
||||
|
||||
//SSAO
|
||||
if(_ReceivesSSAO == 1)
|
||||
{
|
||||
AmbientOcclusionFactor aoFactor;
|
||||
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
|
||||
indirectDiffuse *= lerp(_AOMin, 1, aoFactor.indirectAmbientOcclusion);
|
||||
}
|
||||
indirectDiffuse = indirectDiffuse * bsdfData.ambientOcclusion;
|
||||
}
|
||||
|
||||
return indirectDiffuse;
|
||||
}
|
||||
|
||||
float3 ComputeIndirectSpecular(LightLoopContext lightLoopContext, PositionInputs posInput, PreLightData preLightData, BSDFData bsdfData, SurfaceData surfaceData, BuiltinData builtinData, float3 V)
|
||||
{
|
||||
#if defined(_PBR_Mode_OFF) || defined(_PBR_Mode_TOON)
|
||||
return 0;
|
||||
#else
|
||||
float3 indirectSpecular = 0;
|
||||
|
||||
if(_IR_Intensity > 0)
|
||||
{
|
||||
#ifdef _PBR_Mode_ANISO
|
||||
GetGGXAnisotropicModifiedNormalAndRoughness(bsdfData.bitangentWS, bsdfData.tangentWS , bsdfData.normalWS, V, bsdfData.anisotropy, bsdfData.perceptualRoughness, bsdfData.normalWS, bsdfData.perceptualRoughness);
|
||||
#endif
|
||||
|
||||
float3 albedo = _BaseColor.rgb * surfaceData.baseColor;
|
||||
float mip = PerceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness);
|
||||
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);
|
||||
float grazingTerm = saturate((1 - bsdfData.perceptualRoughness) + (1 - oneMinusReflectivity));
|
||||
|
||||
//Reflection Probe
|
||||
float4 refProbe = ComputeReflection(lightLoopContext, posInput, preLightData, builtinData, V, mip, bsdfData);
|
||||
indirectSpecular = lerp(indirectSpecular, refProbe.rgb, refProbe.a);
|
||||
|
||||
//SSR
|
||||
if(_ReceivesSSR == 1)
|
||||
{
|
||||
float4 ssrLighting = LOAD_TEXTURE2D_X(_SsrLightingTexture, posInput.positionSS);
|
||||
InversePreExposeSsrLighting(ssrLighting);
|
||||
ApplyScreenSpaceReflectionWeight(ssrLighting);
|
||||
indirectSpecular = lerp(indirectSpecular, ssrLighting.rgb, ssrLighting.a);
|
||||
}
|
||||
|
||||
//Compelete the indirect lighting
|
||||
indirectSpecular = indirectSpecular * ComputeFresnelLerp(specColor, grazingTerm, NdotV) * GetCurrentExposureMultiplier();
|
||||
|
||||
// Occlusion
|
||||
if(_ReceivesSSAO == 1)
|
||||
{
|
||||
AmbientOcclusionFactor aoFactor;
|
||||
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
|
||||
|
||||
indirectSpecular *= lerp(_AOMin, 1, aoFactor.indirectSpecularOcclusion);
|
||||
}
|
||||
indirectSpecular = indirectSpecular * bsdfData.specularOcclusion;
|
||||
}
|
||||
return indirectSpecular;
|
||||
#endif
|
||||
}
|
||||
7
Runtime/HDRP/Shaders/EnvLighting.hlsl.meta
Normal file
7
Runtime/HDRP/Shaders/EnvLighting.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52ab7245a70fe6a4e80663ca80f9811b
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1371
Runtime/HDRP/Shaders/HDRPToon.shader
Normal file
1371
Runtime/HDRP/Shaders/HDRPToon.shader
Normal file
File diff suppressed because it is too large
Load Diff
9
Runtime/HDRP/Shaders/HDRPToon.shader.meta
Normal file
9
Runtime/HDRP/Shaders/HDRPToon.shader.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 873188af6a7b5ca49aa69929a5d863c1
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Runtime/HDRP/Shaders/HDRPToonFunction.hlsl
Normal file
23
Runtime/HDRP/Shaders/HDRPToonFunction.hlsl
Normal file
@@ -0,0 +1,23 @@
|
||||
float StepAntiAliasing(float x, float y)
|
||||
{
|
||||
float v = x - y;
|
||||
return saturate(v / (fwidth(v)+HALF_MIN));//fwidth(x) = abs(ddx(x) + ddy(x))
|
||||
}
|
||||
|
||||
float Remap(float In, float2 InMinMax, float2 OutMinMax)
|
||||
{
|
||||
return OutMinMax.x + (In - InMinMax.x) * (OutMinMax.y - OutMinMax.x) / (InMinMax.y - InMinMax.x);
|
||||
}
|
||||
|
||||
float3 ToonMaping(float3 x)
|
||||
{
|
||||
x = x * (2.51 * x + 0.03) / (x * (2.43 * x + 0.59) + 0.14);
|
||||
return x;
|
||||
}
|
||||
|
||||
float3 GetSmoothedWorldNormal(float2 uv, float3x3 t_tbn)
|
||||
{
|
||||
float3 normal = float3(uv, 0);
|
||||
normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
|
||||
return mul(normal, t_tbn);
|
||||
}
|
||||
7
Runtime/HDRP/Shaders/HDRPToonFunction.hlsl.meta
Normal file
7
Runtime/HDRP/Shaders/HDRPToonFunction.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a37603210e947e945be7817ada46bff5
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
329
Runtime/HDRP/Shaders/HDRPToonHead.hlsl
Normal file
329
Runtime/HDRP/Shaders/HDRPToonHead.hlsl
Normal file
@@ -0,0 +1,329 @@
|
||||
//Unity Toon Shader/HDRP
|
||||
//nobuyuki@unity3d.com
|
||||
//toshiyuki@unity3d.com (Universal RP/HDRP)
|
||||
|
||||
#ifndef UCTS_HDRP_INCLUDED
|
||||
#define UCTS_HDRP_INCLUDED
|
||||
|
||||
#define UCTS_HDRP 1
|
||||
|
||||
#define UTS_LAYER_VISIBILITY
|
||||
|
||||
|
||||
|
||||
#ifndef DIRECTIONAL
|
||||
# define DIRECTIONAL
|
||||
#endif
|
||||
|
||||
#define FP_BUFFER 1
|
||||
#if FP_BUFFER
|
||||
#define SATURATE_IF_SDR(x) (x)
|
||||
#define SATURATE_BASE_COLOR_IF_SDR(x) (x)
|
||||
#else
|
||||
#define SATURATE_IF_SDR(x) saturate(x)
|
||||
#define SATURATE_BASE_COLOR_IF_SDR(x) saturate(x)
|
||||
#endif
|
||||
|
||||
struct UTSData
|
||||
{
|
||||
float3 viewDirection;
|
||||
float3 normalDirection;
|
||||
fixed cameraDir;
|
||||
float cameraRoll;
|
||||
fixed signMirror;
|
||||
};
|
||||
|
||||
|
||||
struct UTSLightData
|
||||
{
|
||||
float3 lightDirection;
|
||||
float3 lightColor;
|
||||
float diffuseDimmer;
|
||||
float specularDimmer;
|
||||
float3 shadowTint;
|
||||
float penumbraTint;
|
||||
};
|
||||
|
||||
struct UTSAggregateLighting
|
||||
{
|
||||
float3 directDiffuse;
|
||||
float3 directSpecular;
|
||||
float3 indirectDiffuse;
|
||||
float3 indirectSpecular;
|
||||
};
|
||||
|
||||
float3 AccumulateAggregateLighting(UTSAggregateLighting aggregateLighting)
|
||||
{
|
||||
return SATURATE_IF_SDR(aggregateLighting.directDiffuse + aggregateLighting.directSpecular) + aggregateLighting.indirectDiffuse + aggregateLighting.indirectSpecular;
|
||||
}
|
||||
|
||||
#if defined(UNITY_PASS_PREPASSBASE) || defined(UNITY_PASS_DEFERRED) || defined(UNITY_PASS_SHADOWCASTER)
|
||||
#undef FOG_LINEAR
|
||||
#undef FOG_EXP
|
||||
#undef FOG_EXP2
|
||||
#endif
|
||||
|
||||
|
||||
#if 1
|
||||
|
||||
// Legacy for compatibility with existing shaders
|
||||
inline bool IsGammaSpace()
|
||||
{
|
||||
#ifdef UNITY_COLORSPACE_GAMMA
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// normal should be normalized, w=1.0
|
||||
half3 SHEvalLinearL0L1(half4 normal)
|
||||
{
|
||||
half3 x;
|
||||
|
||||
// Linear (L1) + constant (L0) polynomial terms
|
||||
x.r = dot(unity_SHAr, normal);
|
||||
x.g = dot(unity_SHAg, normal);
|
||||
x.b = dot(unity_SHAb, normal);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
// normal should be normalized, w=1.0
|
||||
half3 SHEvalLinearL2(half4 normal)
|
||||
{
|
||||
half3 x1, x2;
|
||||
// 4 of the quadratic (L2) polynomials
|
||||
half4 vB = normal.xyzz * normal.yzzx;
|
||||
x1.r = dot(unity_SHBr, vB);
|
||||
x1.g = dot(unity_SHBg, vB);
|
||||
x1.b = dot(unity_SHBb, vB);
|
||||
|
||||
// Final (5th) quadratic (L2) polynomial
|
||||
half vC = normal.x * normal.x - normal.y * normal.y;
|
||||
x2 = unity_SHC.rgb * vC;
|
||||
|
||||
return x1 + x2;
|
||||
}
|
||||
|
||||
// normal should be normalized, w=1.0
|
||||
// output in active color space
|
||||
half3 ShadeSH9(half4 normal)
|
||||
{
|
||||
// Linear + constant polynomial terms
|
||||
half3 res = SHEvalLinearL0L1(normal);
|
||||
|
||||
// Quadratic polynomials
|
||||
res += SHEvalLinearL2(normal);
|
||||
|
||||
# ifdef UNITY_COLORSPACE_GAMMA
|
||||
res = LinearToGammaSpace(res);
|
||||
# endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
float3 DecodeLightProbe(float3 N) {
|
||||
return ShadeSH9(float4(N, 1));
|
||||
}
|
||||
|
||||
|
||||
inline float GammaToLinearSpaceExact(float value)
|
||||
{
|
||||
if (value <= 0.04045F)
|
||||
return value / 12.92F;
|
||||
else if (value < 1.0F)
|
||||
return pow((value + 0.055F) / 1.055F, 2.4F);
|
||||
else
|
||||
return pow(value, 2.2F);
|
||||
}
|
||||
|
||||
inline float3 GammaToLinearSpace(float3 sRGB)
|
||||
{
|
||||
// Approximate version from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
|
||||
return sRGB * (sRGB * (sRGB * 0.305306011h + 0.682171111h) + 0.012522878h);
|
||||
|
||||
// Precise version, useful for debugging.
|
||||
//return half3(GammaToLinearSpaceExact(sRGB.r), GammaToLinearSpaceExact(sRGB.g), GammaToLinearSpaceExact(sRGB.b));
|
||||
}
|
||||
|
||||
inline float LinearToGammaSpaceExact(float value)
|
||||
{
|
||||
if (value <= 0.0F)
|
||||
return 0.0F;
|
||||
else if (value <= 0.0031308F)
|
||||
return 12.92F * value;
|
||||
else if (value < 1.0F)
|
||||
return 1.055F * pow(value, 0.4166667F) - 0.055F;
|
||||
else
|
||||
return pow(value, 0.45454545F);
|
||||
}
|
||||
|
||||
inline float3 LinearToGammaSpace(float3 linRGB)
|
||||
{
|
||||
linRGB = max(linRGB, float3(0.h, 0.h, 0.h));
|
||||
// An almost-perfect approximation from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
|
||||
return max(1.055h * pow(linRGB, 0.416666667h) - 0.055h, 0.h);
|
||||
|
||||
// Exact version, useful for debugging.
|
||||
//return half3(LinearToGammaSpaceExact(linRGB.r), LinearToGammaSpaceExact(linRGB.g), LinearToGammaSpaceExact(linRGB.b));
|
||||
}
|
||||
|
||||
|
||||
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
|
||||
#define UNITY_FOG_COORDS(idx) UNITY_FOG_COORDS_PACKED(idx, float1)
|
||||
|
||||
#if (SHADER_TARGET < 30) || defined(SHADER_API_MOBILE)
|
||||
// mobile or SM2.0: calculate fog factor per-vertex
|
||||
#define UNITY_TRANSFER_FOG(o,outpos) UNITY_CALC_FOG_FACTOR((outpos).z); o.fogCoord.x = unityFogFactor
|
||||
#else
|
||||
// SM3.0 and PC/console: calculate fog distance per-vertex, and fog factor per-pixel
|
||||
#define UNITY_TRANSFER_FOG(o,outpos) o.fogCoord.x = (outpos).z
|
||||
#endif
|
||||
#else
|
||||
#define UNITY_FOG_COORDS(idx)
|
||||
#define UNITY_TRANSFER_FOG(o,outpos)
|
||||
#endif
|
||||
|
||||
#define UNITY_FOG_LERP_COLOR(col,fogCol,fogFac) col.rgb = lerp((fogCol).rgb, (col).rgb, saturate(fogFac))
|
||||
|
||||
|
||||
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
|
||||
#if (SHADER_TARGET < 30) || defined(SHADER_API_MOBILE)
|
||||
// mobile or SM2.0: fog factor was already calculated per-vertex, so just lerp the color
|
||||
#define UNITY_APPLY_FOG_COLOR(coord,col,fogCol) UNITY_FOG_LERP_COLOR(col,fogCol,(coord).x)
|
||||
#else
|
||||
// SM3.0 and PC/console: calculate fog factor and lerp fog color
|
||||
#define UNITY_APPLY_FOG_COLOR(coord,col,fogCol) UNITY_CALC_FOG_FACTOR((coord).x); UNITY_FOG_LERP_COLOR(col,fogCol,unityFogFactor)
|
||||
#endif
|
||||
#else
|
||||
#define UNITY_APPLY_FOG_COLOR(coord,col,fogCol)
|
||||
#endif
|
||||
|
||||
#ifdef UNITY_PASS_FORWARDADD
|
||||
#define UNITY_APPLY_FOG(coord,col) UNITY_APPLY_FOG_COLOR(coord,col,fixed4(0,0,0,0))
|
||||
#else
|
||||
#define UNITY_APPLY_FOG(coord,col) UNITY_APPLY_FOG_COLOR(coord,col,unity_FogColor)
|
||||
#endif
|
||||
|
||||
#endif //#if false
|
||||
|
||||
#ifdef DIRECTIONAL
|
||||
#define LIGHTING_COORDS(idx1,idx2) SHADOW_COORDS(idx1)
|
||||
#define TRANSFER_VERTEX_TO_FRAGMENT(a) TRANSFER_SHADOW(a)
|
||||
#define LIGHT_ATTENUATION(a) SHADOW_ATTENUATION(a)
|
||||
#endif
|
||||
|
||||
// Transforms 2D UV by scale/bias property
|
||||
//#define TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw)
|
||||
#define UCTS_TEXTURE2D(tex,name) SAMPLE_TEXTURE2D(tex,sampler##tex,TRANSFORM_TEX(name, tex));
|
||||
|
||||
|
||||
inline float4 UnityObjectToClipPosInstanced(in float3 pos)
|
||||
{
|
||||
// return mul(UNITY_MATRIX_VP, mul(unity_ObjectToWorldArray[unity_InstanceID], float4(pos, 1.0)));
|
||||
// todo. right?
|
||||
return mul(UNITY_MATRIX_VP, mul(UNITY_MATRIX_M, float4(pos, 1.0)));
|
||||
}
|
||||
inline float4 UnityObjectToClipPosInstanced(float4 pos)
|
||||
{
|
||||
return UnityObjectToClipPosInstanced(pos.xyz);
|
||||
}
|
||||
#define UnityObjectToClipPos UnityObjectToClipPosInstanced
|
||||
|
||||
inline float3 UnityObjectToWorldNormal( in float3 norm )
|
||||
{
|
||||
#ifdef UNITY_ASSUME_UNIFORM_SCALING
|
||||
return UnityObjectToWorldDir(norm);
|
||||
#else
|
||||
// mul(IT_M, norm) => mul(norm, I_M) => {dot(norm, I_M.col0), dot(norm, I_M.col1), dot(norm, I_M.col2)}
|
||||
return normalize(mul(norm, (float3x3)UNITY_MATRIX_M));
|
||||
#endif
|
||||
}
|
||||
// normal should be normalized, w=1.0
|
||||
float3 SHEvalLinearL0L1 (float4 normal)
|
||||
{
|
||||
float3 x;
|
||||
|
||||
// Linear (L1) + constant (L0) polynomial terms
|
||||
x.r = dot(unity_SHAr,normal);
|
||||
x.g = dot(unity_SHAg,normal);
|
||||
x.b = dot(unity_SHAb,normal);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
// normal should be normalized, w=1.0
|
||||
float3 SHEvalLinearL2 (float4 normal)
|
||||
{
|
||||
float3 x1, x2;
|
||||
// 4 of the quadratic (L2) polynomials
|
||||
float4 vB = normal.xyzz * normal.yzzx;
|
||||
x1.r = dot(unity_SHBr,vB);
|
||||
x1.g = dot(unity_SHBg,vB);
|
||||
x1.b = dot(unity_SHBb,vB);
|
||||
|
||||
// Final (5th) quadratic (L2) polynomial
|
||||
half vC = normal.x*normal.x - normal.y*normal.y;
|
||||
x2 = unity_SHC.rgb * vC;
|
||||
|
||||
return x1 + x2;
|
||||
}
|
||||
|
||||
// normal should be normalized, w=1.0
|
||||
// output in active color space
|
||||
float3 ShadeSH9 (float4 normal)
|
||||
{
|
||||
// Linear + constant polynomial terms
|
||||
float3 res = SHEvalLinearL0L1 (normal);
|
||||
|
||||
// Quadratic polynomials
|
||||
res += SHEvalLinearL2 (normal);
|
||||
|
||||
# ifdef UNITY_COLORSPACE_GAMMA
|
||||
res = LinearToGammaSpace (res);
|
||||
# endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
float rateR = 0.299;
|
||||
float rateG = 0.587;
|
||||
float rateB = 0.114;
|
||||
|
||||
float3 SampleBakedGI_UTS(float3 positionRWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap, bool needToIncludeAPV = false)
|
||||
{
|
||||
float3 bakeDiffuseLighting = float3(0, 0, 0);
|
||||
float3 backBakeDiffuseLighting = float3(0, 0, 0);
|
||||
float3 backNormalWS = float3(0, 0, 0);
|
||||
|
||||
#if !defined(_SURFACE_TYPE_TRANSPARENT) && (SHADERPASS != SHADERPASS_RAYTRACING_INDIRECT) && (SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER)
|
||||
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF
|
||||
#if (SHADERPASS == SHADERPASS_GBUFER)
|
||||
&& _IndirectDiffuseMode != INDIRECTDIFFUSEMODE_MIXED && _ReflectionsMode != REFLECTIONSMODE_MIXED
|
||||
#endif
|
||||
)
|
||||
return bakeDiffuseLighting;
|
||||
#endif
|
||||
|
||||
#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
|
||||
EvaluateLightmap(positionRWS, normalWS, backNormalWS, uvStaticLightmap, uvDynamicLightmap, bakeDiffuseLighting, backBakeDiffuseLighting);
|
||||
#elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
|
||||
if (needToIncludeAPV)
|
||||
{
|
||||
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
|
||||
9
Runtime/HDRP/Shaders/HDRPToonHead.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/HDRPToonHead.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2fc592d7e0eb2d47b07a315b3ec3ea8
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
224
Runtime/HDRP/Shaders/HDRPToonOutline.hlsl
Normal file
224
Runtime/HDRP/Shaders/HDRPToonOutline.hlsl
Normal file
@@ -0,0 +1,224 @@
|
||||
//Unity Toon Shader/HDRP
|
||||
//nobuyuki@unity3d.com
|
||||
//toshiyuki@unity3d.com (Universal RP/HDRP)
|
||||
|
||||
#undef unity_ObjectToWorld
|
||||
#undef unity_WorldToObject
|
||||
|
||||
float4 _LightColor0; // not referenced in c# code ??
|
||||
|
||||
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl"
|
||||
|
||||
// PackedVaryingsType
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/e4117c07b479adafed38237f3407a363eefb4590/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl#L120
|
||||
|
||||
PackedVaryingsType Vert(AttributesMesh inputMesh, AttributesPass inputPass)
|
||||
{
|
||||
// VaryingsType
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/e4117c07b479adafed38237f3407a363eefb4590/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl#L118
|
||||
|
||||
VaryingsType varyingsType;
|
||||
varyingsType.vmesh = VertMesh(inputMesh);
|
||||
varyingsType.vmesh.
|
||||
#include "HDRPToonOutlineVertMain.hlsl"
|
||||
|
||||
return MotionVectorVS(varyingsType, inputMesh, inputPass);
|
||||
}
|
||||
|
||||
#ifdef TESSELLATION_ON
|
||||
|
||||
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
|
||||
{
|
||||
VaryingsToPS output;
|
||||
output.vmesh = VertMeshTesselation(input.vmesh);
|
||||
MotionVectorPositionZBias(output);
|
||||
|
||||
output.vpass.positionCS = input.vpass.positionCS;
|
||||
output.vpass.previousPositionCS = input.vpass.previousPositionCS;
|
||||
|
||||
return PackVaryingsToPS(output);
|
||||
}
|
||||
|
||||
#endif // TESSELLATION_ON
|
||||
|
||||
#else // _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl"
|
||||
|
||||
PackedVaryingsType Vert(AttributesMesh inputMesh)
|
||||
{
|
||||
VaryingsType varyingsType;
|
||||
varyingsType.vmesh = VertMesh(inputMesh);
|
||||
#include "HDRPToonOutlineVertMain.hlsl"
|
||||
|
||||
return PackVaryingsType(varyingsType);
|
||||
}
|
||||
|
||||
#ifdef TESSELLATION_ON
|
||||
|
||||
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
|
||||
{
|
||||
VaryingsToPS output;
|
||||
output.vmesh = VertMeshTesselation(input.vmesh);
|
||||
|
||||
return PackVaryingsToPS(output);
|
||||
}
|
||||
|
||||
|
||||
#endif // TESSELLATION_ON
|
||||
|
||||
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
|
||||
|
||||
#ifdef TESSELLATION_ON
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/TessellationShare.hlsl"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef UNITY_VIRTUAL_TEXTURING
|
||||
#define VT_BUFFER_TARGET SV_Target1
|
||||
#define EXTRA_BUFFER_TARGET SV_Target2
|
||||
#else
|
||||
#define EXTRA_BUFFER_TARGET SV_Target1
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void Frag(PackedVaryingsToPS packedInput,
|
||||
#ifdef OUTPUT_SPLIT_LIGHTING
|
||||
out float4 outColor : SV_Target0, // outSpecularLighting
|
||||
#ifdef UNITY_VIRTUAL_TEXTURING
|
||||
out float4 outVTFeedback : VT_BUFFER_TARGET,
|
||||
#endif
|
||||
out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET,
|
||||
OUTPUT_SSSBUFFER(outSSSBuffer)
|
||||
#else
|
||||
out float4 outColor : SV_Target0
|
||||
#ifdef UNITY_VIRTUAL_TEXTURING
|
||||
, out float4 outVTFeedback : VT_BUFFER_TARGET
|
||||
#endif
|
||||
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
, out float4 outMotionVec : EXTRA_BUFFER_TARGET
|
||||
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
#endif // OUTPUT_SPLIT_LIGHTING
|
||||
#ifdef _DEPTHOFFSET_ON
|
||||
, out float outputDepth : SV_Depth
|
||||
#endif
|
||||
)
|
||||
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
|
||||
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
|
||||
#ifdef _IS_CLIPPING_MASK
|
||||
if (_ClippingMaskMode != 0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode != 0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
#if defined(UTS_DEBUG_SHADOWMAP_NO_OUTLINE)
|
||||
discard;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//v.2.0.5
|
||||
if (_ZOverDrawMode > 0.99f)
|
||||
{
|
||||
#ifdef _DEPTHOFFSET_ON
|
||||
outputDepth = posInput.deviceDepth;
|
||||
#endif
|
||||
#ifdef UNITY_VIRTUAL_TEXTURING
|
||||
|
||||
outVTFeedback = builtinData.vtPackedFeedback;
|
||||
#endif
|
||||
outColor = float4(1.0f, 1.0f, 1.0f, 1.0f); // but nothing should be drawn except Z value as colormask is set to 0
|
||||
return;
|
||||
}
|
||||
_Color = _BaseColor;
|
||||
float4 objPos = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
|
||||
float4 Set_UV0 = input.texCoord0;
|
||||
|
||||
// The following temporary definition of unity_AmbientEquator is for HDRP only.
|
||||
//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_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)
|
||||
).rgb;
|
||||
float3 ambientSkyColor = envLightSource_SkyboxIntensity.rgb > 0.0 ? envLightSource_SkyboxIntensity : envLightSource_GradientEquator;
|
||||
ambientSkyColor *= GetCurrentExposureMultiplier() * 5.0f;
|
||||
|
||||
float4 _MainTex_var = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, TRANSFORM_TEX(Set_UV0, _MainTex));
|
||||
float3 Set_BaseColor = _BaseColor.rgb*_MainTex_var.rgb;
|
||||
float3 _Is_BlendBaseColor_var = lerp(_Outline_Color.rgb * ambientSkyColor, (_Outline_Color.rgb * ambientSkyColor * Set_BaseColor * Set_BaseColor), _Is_BlendBaseColor);
|
||||
//
|
||||
float3 _OutlineTex_var = tex2D(_OutlineTex,TRANSFORM_TEX(Set_UV0, _OutlineTex)).xyz;
|
||||
|
||||
float4 overridingColor = lerp(_OutlineMaskColor, float4(_OutlineMaskColor.w, _OutlineMaskColor.w, _OutlineMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_OutlineOverridden, _ComposerMaskMode);
|
||||
|
||||
//v.2.0.7.5
|
||||
#ifdef _IS_OUTLINE_CLIPPING_NO
|
||||
float3 Set_Outline_Color = lerp(_Is_BlendBaseColor_var, _OutlineTex_var.rgb*_Outline_Color.rgb * ambientSkyColor, _Is_OutlineTex );
|
||||
if (_OutlineVisible < 0.1)
|
||||
{
|
||||
// Todo.
|
||||
// without this, something is drawn even if _OutlineVisible = 0, in AngelRing(HDRP)
|
||||
discard;
|
||||
}
|
||||
Set_Outline_Color = lerp(Set_Outline_Color, overridingColor.xyz, maskEnabled);
|
||||
float3 volColor, volOpacity;
|
||||
|
||||
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
|
||||
// input.positionSS is SV_Position
|
||||
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
|
||||
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
||||
|
||||
EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha
|
||||
Set_Outline_Color.xyz = Set_Outline_Color.xyz * (1 - volOpacity) + volColor * _OutlineVisible;
|
||||
outColor =float4(Set_Outline_Color, _OutlineVisible );
|
||||
|
||||
|
||||
#elif _IS_OUTLINE_CLIPPING_YES
|
||||
float4 _ClippingMask_var = SAMPLE_TEXTURE2D(_ClippingMask, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _ClippingMask));
|
||||
float Set_MainTexAlpha = _MainTex_var.a;
|
||||
float _IsBaseMapAlphaAsClippingMask_var = lerp( _ClippingMask_var.r, Set_MainTexAlpha, _IsBaseMapAlphaAsClippingMask );
|
||||
float _Inverse_Clipping_var = lerp( _IsBaseMapAlphaAsClippingMask_var, (1.0 - _IsBaseMapAlphaAsClippingMask_var), _Inverse_Clipping );
|
||||
float Set_Clipping = saturate((_Inverse_Clipping_var+_Clipping_Level));
|
||||
clip(Set_Clipping - 0.5);
|
||||
float4 Set_Outline_Color = lerp( float4(_Is_BlendBaseColor_var, Set_Clipping), float4((_OutlineTex_var.rgb * _Outline_Color.rgb * ambientSkyColor),Set_Clipping), _Is_OutlineTex );
|
||||
Set_Outline_Color = lerp(Set_Outline_Color, overridingColor, maskEnabled);
|
||||
Set_Outline_Color.w *= _OutlineVisible;
|
||||
|
||||
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
|
||||
// input.positionSS is SV_Position
|
||||
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
|
||||
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
||||
|
||||
float3 volColor, volOpacity;
|
||||
EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha
|
||||
Set_Outline_Color.xyz = Set_Outline_Color.xyz * (1 - volOpacity.x) + volColor * Set_Outline_Color.w;
|
||||
outColor = Set_Outline_Color;
|
||||
#endif
|
||||
//outColor.rgb = ambientSkyColor;
|
||||
#ifdef _DEPTHOFFSET_ON
|
||||
outputDepth = posInput.deviceDepth;
|
||||
#endif
|
||||
#ifdef UNITY_VIRTUAL_TEXTURING
|
||||
outVTFeedback = builtinData.vtPackedFeedback;
|
||||
#endif
|
||||
}
|
||||
// End of File
|
||||
|
||||
9
Runtime/HDRP/Shaders/HDRPToonOutline.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/HDRPToonOutline.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da01533aa573e30428720fa587ddbe94
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
65
Runtime/HDRP/Shaders/HDRPToonOutlineVertMain.hlsl
Normal file
65
Runtime/HDRP/Shaders/HDRPToonOutlineVertMain.hlsl
Normal file
@@ -0,0 +1,65 @@
|
||||
//Unity Toon Shader/HDRP
|
||||
//nobuyuki@unity3d.com
|
||||
//toshiyuki@unity3d.com (Universal RP/HDRP)
|
||||
|
||||
|
||||
#if 1
|
||||
float4 objPos = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
|
||||
float2 Set_UV0 = inputMesh.uv0;
|
||||
float4 _Outline_Sampler_var = tex2Dlod(_Outline_Sampler, float4(TRANSFORM_TEX(Set_UV0, _Outline_Sampler), 0.0, 0));
|
||||
//v.2.0.4.3 baked Normal Texture for Outline
|
||||
float3 normalDir = UnityObjectToWorldNormal(inputMesh.normalOS);
|
||||
float3 tangentDir = normalize(mul(unity_ObjectToWorld, float4(inputMesh.tangentOS.xyz, 0.0)).xyz);
|
||||
float3 bitangentDir = normalize(cross(normalDir, tangentDir) * inputMesh.tangentOS.w);
|
||||
float3x3 tangentTransform = float3x3(tangentDir, bitangentDir, normalDir);
|
||||
//UnpackNormal() can't be used, and so as follows. Do not specify a bump for the texture to be used.
|
||||
float4 _BakedNormal_var = (tex2Dlod(_BakedNormal, float4(TRANSFORM_TEX(Set_UV0, _BakedNormal), 0.0, 0)) * 2 - 1);
|
||||
float3 _BakedNormalDir = normalize(mul(_BakedNormal_var.rgb, tangentTransform));
|
||||
//end
|
||||
float Set_Outline_Width = (_Outline_Width * 0.01 * smoothstep(_Farthest_Distance, _Nearest_Distance, distance(objPos.rgb, _WorldSpaceCameraPos)) * _Outline_Sampler_var.rgb).r;
|
||||
Set_Outline_Width *= (1.0f - _ZOverDrawMode);
|
||||
//v.2.0.7.5
|
||||
float4 _ClipCameraPos = mul(UNITY_MATRIX_VP, float4(_WorldSpaceCameraPos.xyz, 1));
|
||||
//v.2.0.7
|
||||
#if defined(UNITY_REVERSED_Z)
|
||||
//v.2.0.4.2 (DX)
|
||||
_Offset_Z = _Offset_Z * -0.01;
|
||||
#else
|
||||
//OpenGL
|
||||
_Offset_Z = _Offset_Z * 0.01;
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
FinalNormal = lerp(inputMesh.normalOS, _BakedNormalDir, _Is_BakedNormal);
|
||||
}
|
||||
|
||||
//v2.0.4
|
||||
#ifdef _OUTLINE_NML
|
||||
//v.2.0.4.3 baked Normal Texture for Outline
|
||||
float3 normal = mul((float3x3)transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)), FinalNormal);
|
||||
#elif _OUTLINE_POS
|
||||
Set_Outline_Width = Set_Outline_Width * 2;
|
||||
float signVar = dot(normalize(inputMesh.positionOS), normalize(inputMesh.normalOS)) < 0 ? -1 : 1;
|
||||
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));
|
||||
float4 clipPos = UnityObjectToClipPos(inputMesh.positionOS);
|
||||
clipPos.xy += extendDir * min(_Outline_MaxWidth, (clipPos.w * Set_Outline_Width));
|
||||
clipPos.z = clipPos.z + _Offset_Z * _ClipCameraPos.z;
|
||||
|
||||
float4 rws = mul(UNITY_MATRIX_I_P, clipPos); // use UNITY_MATRIX_I_P instead of unity_CameraInvProjection.
|
||||
rws = mul(UNITY_MATRIX_I_V, rws); // use UNITY_MATRIX_I_V instead of unity_cameraToWorld.
|
||||
#ifndef TESSELLATION_ON
|
||||
varyingsType.vmesh.positionCS = clipPos;
|
||||
#endif // TESSELLATION_ON
|
||||
varyingsType.vmesh.positionRWS = rws.xyz;
|
||||
|
||||
#endif // #if 1
|
||||
9
Runtime/HDRP/Shaders/HDRPToonOutlineVertMain.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/HDRPToonOutlineVertMain.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 317af98a1c897dd46b2d3839bc92aaa5
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1156
Runtime/HDRP/Shaders/HDRPToonTessellation.shader
Normal file
1156
Runtime/HDRP/Shaders/HDRPToonTessellation.shader
Normal file
File diff suppressed because it is too large
Load Diff
9
Runtime/HDRP/Shaders/HDRPToonTessellation.shader.meta
Normal file
9
Runtime/HDRP/Shaders/HDRPToonTessellation.shader.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6499b7b5ccaae6944ae5fe89b016c50b
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
130
Runtime/HDRP/Shaders/HairShadowRenderer.shader
Normal file
130
Runtime/HDRP/Shaders/HairShadowRenderer.shader
Normal file
@@ -0,0 +1,130 @@
|
||||
Shader "Renderers/HairShadowRenderer"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Color("Color", Color) = (1,1,1,1)
|
||||
_ColorMap("ColorMap", 2D) = "white" {}
|
||||
|
||||
// Transparency
|
||||
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
|
||||
[HideInInspector]_BlendMode("_BlendMode", Range(0.0, 1.0)) = 0.5
|
||||
}
|
||||
|
||||
HLSLINCLUDE
|
||||
|
||||
#pragma target 4.5
|
||||
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
|
||||
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
|
||||
//#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
|
||||
|
||||
//enable GPU instancing support
|
||||
#pragma multi_compile_instancing
|
||||
#pragma multi_compile _ DOTS_INSTANCING_ON
|
||||
|
||||
ENDHLSL
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags{ "RenderPipeline" = "HDRenderPipeline" }
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "HairShadow"
|
||||
Tags { "LightMode" = "HairShadow" }
|
||||
|
||||
Blend Off
|
||||
ZWrite On
|
||||
ZTest LEqual
|
||||
|
||||
Cull Front
|
||||
|
||||
HLSLPROGRAM
|
||||
|
||||
#define _SURFACE_TYPE_OPAQUE
|
||||
|
||||
// Toggle the alpha test
|
||||
#define _ALPHATEST_ON
|
||||
|
||||
// Toggle transparency
|
||||
// #define _SURFACE_TYPE_TRANSPARENT
|
||||
|
||||
// Toggle fog on transparent
|
||||
#define _ENABLE_FOG_ON_TRANSPARENT
|
||||
|
||||
// List all the attributes needed in your shader (will be passed to the vertex shader)
|
||||
// you can see the complete list of these attributes in VaryingMesh.hlsl
|
||||
#define ATTRIBUTES_NEED_TEXCOORD0
|
||||
#define ATTRIBUTES_NEED_NORMAL
|
||||
#define ATTRIBUTES_NEED_TANGENT
|
||||
|
||||
// List all the varyings needed in your fragment shader
|
||||
#define VARYINGS_NEED_TEXCOORD0
|
||||
#define VARYINGS_NEED_TANGENT_TO_WORLD
|
||||
|
||||
#define SHADERPASS SHADERPASS_FORWARD_UNLIT
|
||||
|
||||
int _HairShadowPassChannel;
|
||||
TEXTURE2D(_ColorMap);
|
||||
TEXTURE2D(_HairShadowTex);
|
||||
SAMPLER(sampler_HairShadowTex);
|
||||
|
||||
// Declare properties in the UnityPerMaterial cbuffer to make the shader compatible with SRP Batcher.
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
float4 _ColorMap_ST;
|
||||
float4 _Color;
|
||||
|
||||
float _AlphaCutoff;
|
||||
float _BlendMode;
|
||||
CBUFFER_END
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassRenderersV2.hlsl"
|
||||
|
||||
// If you need to modify the vertex datas, you can uncomment this code
|
||||
// Note: all the transformations here are done in object space
|
||||
// #define HAVE_MESH_MODIFICATION
|
||||
// AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
|
||||
// {
|
||||
// input.positionOS += input.normalOS * 0.0001; // inflate a bit the mesh to avoid z-fight
|
||||
// return input;
|
||||
// }
|
||||
|
||||
// Put the code to render the objects in your custom pass in this function
|
||||
void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 viewDirection, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
|
||||
{
|
||||
float cDepth = SampleCameraDepth(posInput.positionNDC);
|
||||
float mDepth = posInput.deviceDepth;
|
||||
|
||||
float opacity = 1;
|
||||
// const float3 color = float3(LinearEyeDepth(posInput.deviceDepth, _ZBufferParams), 0, 0);
|
||||
|
||||
// A manual depth test is needed here. Custom pass will always draw with no regard of depth.
|
||||
// This test was given a quite large leeway to avoid discarding when cDepth = mDepth [Suomi, 20230915]
|
||||
|
||||
//float3 color = float3(cDepth < mDepth + 0.01 ? mDepth : 0, 0, 0); // Can get that in HDRP directly
|
||||
float3 color = float3(0, 0, 0);
|
||||
color.r = mDepth;
|
||||
|
||||
#ifdef _ALPHATEST_ON
|
||||
DoAlphaTest(opacity, _AlphaCutoff);
|
||||
#endif
|
||||
|
||||
// Write back the data to the output structures
|
||||
ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting
|
||||
ZERO_INITIALIZE(SurfaceData, surfaceData);
|
||||
builtinData.opacity = opacity;
|
||||
builtinData.emissiveColor = float3(0, 0, 0);
|
||||
surfaceData.color = color;
|
||||
}
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl"
|
||||
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Runtime/HDRP/Shaders/HairShadowRenderer.shader.meta
Normal file
10
Runtime/HDRP/Shaders/HairShadowRenderer.shader.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3740fc2ef8a5094a81cfb53915422de
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
204
Runtime/HDRP/Shaders/PBR.hlsl
Normal file
204
Runtime/HDRP/Shaders/PBR.hlsl
Normal file
@@ -0,0 +1,204 @@
|
||||
#define unity_ColorSpaceDielectricSpec half4(0.22, 0.22, 0.22, 0.779)
|
||||
|
||||
float3 schlick(float f0, float hl) {
|
||||
real x = 1.0 - hl;
|
||||
real x2 = x * x;
|
||||
real x5 = x * x2 * x2;
|
||||
return (1.0 - f0) * x5 + f0;
|
||||
}
|
||||
|
||||
float3 SpecularColor(float3 albedo, float metalic)
|
||||
{
|
||||
float3 specColor = lerp(unity_ColorSpaceDielectricSpec, albedo, metalic);
|
||||
return specColor;
|
||||
}
|
||||
|
||||
float RoughnessToBlinnPhongSpecularExponent(float roughness)
|
||||
{
|
||||
return clamp(2 * rcp(roughness * roughness) - 2, FLT_EPS, rcp(FLT_EPS));
|
||||
}
|
||||
|
||||
float StepFeatherToon(float value,float step,float feather)
|
||||
{
|
||||
return saturate((value - step + feather) / feather);
|
||||
}
|
||||
|
||||
float3 ComputeSpecularTerm(float3 V, float3 L, BSDFData bsdfData)
|
||||
{
|
||||
float3 specTerm;
|
||||
#ifdef _PBR_Mode_OFF
|
||||
return 0;
|
||||
#else
|
||||
float3 N = bsdfData.normalWS;
|
||||
float3 H = normalize(L + V);
|
||||
|
||||
float NdotL = dot(N, L);
|
||||
float NdotV = dot(N, V);
|
||||
float clampedNdotV = ClampNdotV(NdotV);
|
||||
float clampedNdotL = saturate(NdotL);
|
||||
float flippedNdotL = ComputeWrappedDiffuseLighting(-NdotL, TRANSMISSION_WRAP_LIGHT);
|
||||
float diffuseNdotL = clampedNdotL;
|
||||
float LdotV = dot(L, V);
|
||||
float NdotH = saturate(dot(N, H));
|
||||
float HdotL = saturate(dot(H, L));
|
||||
|
||||
float3 F = schlick(bsdfData.fresnel0, HdotL);
|
||||
|
||||
float partLambdaV;
|
||||
float3 DV = 0;
|
||||
#ifdef _PBR_Mode_ST
|
||||
ConvertAnisotropyToRoughness(bsdfData.perceptualRoughness, 0, bsdfData.roughnessT, bsdfData.roughnessB);
|
||||
partLambdaV = GetSmithJointGGXPartLambdaV(clampedNdotV, bsdfData.roughnessT);
|
||||
// We use abs(NdotL) to handle the none case of double sided
|
||||
DV = DV_SmithJointGGX(NdotH, abs(NdotL), clampedNdotV, bsdfData.roughnessT, partLambdaV);
|
||||
|
||||
#elif _PBR_Mode_ANISO
|
||||
float TdotV = dot(bsdfData.tangentWS, V);
|
||||
float BdotV = dot(bsdfData.bitangentWS, V);
|
||||
|
||||
ConvertAnisotropyToRoughness(bsdfData.perceptualRoughness, bsdfData.anisotropy, bsdfData.roughnessT, bsdfData.roughnessB);
|
||||
partLambdaV = GetSmithJointGGXAnisoPartLambdaV(TdotV, BdotV, clampedNdotV, bsdfData.roughnessT, bsdfData.roughnessB);
|
||||
|
||||
// For anisotropy we must not saturate these values
|
||||
float TdotH = dot(bsdfData.tangentWS, H);
|
||||
float TdotL = dot(bsdfData.tangentWS, L);
|
||||
float BdotH = dot(bsdfData.bitangentWS, H);
|
||||
float BdotL = dot(bsdfData.bitangentWS, L);
|
||||
|
||||
// We use abs(NdotL) to handle the none case of double sided
|
||||
DV = DV_SmithJointGGXAniso(TdotH, BdotH, NdotH, clampedNdotV, TdotL, BdotL, abs(NdotL), bsdfData.roughnessT, bsdfData.roughnessB, partLambdaV);
|
||||
|
||||
#elif _PBR_Mode_KK
|
||||
float3 t = ShiftTangent(bsdfData.bitangentWS, N, bsdfData.anisotropy);
|
||||
float specularExponent = RoughnessToBlinnPhongSpecularExponent(PerceptualRoughnessToRoughness(bsdfData.coatRoughness));
|
||||
DV = D_KajiyaKay(t, H, specularExponent);
|
||||
|
||||
float normalizeSpec = DV * rcp(specularExponent + 2) * 2 * PI;
|
||||
//DV *= StepFeatherToon(normalizeSpec,specularStep,specularFeather);
|
||||
DV = DV * normalizeSpec * _KKColor.rgb;
|
||||
#elif _PBR_Mode_TOON
|
||||
float specularExponent = RoughnessToBlinnPhongSpecularExponent(PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness));
|
||||
specTerm = pow(NdotH, 5.0 * specularExponent);
|
||||
specTerm = StepFeatherToon(specTerm, _ToonSpecularStep, _ToonSpecularFeather);
|
||||
return specTerm * unity_ColorSpaceDielectricSpec * clampedNdotL;
|
||||
#endif
|
||||
|
||||
specTerm = DV * F;
|
||||
specTerm = specTerm * clampedNdotL;
|
||||
|
||||
return specTerm;
|
||||
#endif
|
||||
}
|
||||
|
||||
half3 FitWithCurveApprox(half NdotL, half Curvature)
|
||||
{
|
||||
half curva = (1.0 / mad(Curvature, 0.5 - 0.0625, 0.0625) - 2.0) / (16.0 - 2.0);
|
||||
half oneMinusCurva = 1.0 - curva;
|
||||
half3 curve0;
|
||||
{
|
||||
half3 rangeMin = half3(0.0, 0.3, 0.3);
|
||||
half3 rangeMax = half3(1.0, 0.7, 0.7);
|
||||
half3 offset = half3(0.0, 0.06, 0.06);
|
||||
half3 t = saturate(mad(NdotL, 1.0 / (rangeMax - rangeMin), (offset + rangeMin) / (rangeMin - rangeMax)));
|
||||
half3 lowerLine = (t * t) * half3(0.65, 0.5, 0.9);
|
||||
lowerLine.r += 0.045;
|
||||
lowerLine.b *= t.b;
|
||||
half3 m = half3(1.75, 2.0, 1.97);
|
||||
half3 upperLine = mad(NdotL, m, half3(0.99, 0.99, 0.99) - m);
|
||||
upperLine = saturate(upperLine);
|
||||
half3 lerpMin = half3(0.0, 0.35, 0.35);
|
||||
half3 lerpMax = half3(1.0, 0.7, 0.6);
|
||||
half3 lerpT = saturate(mad(NdotL, 1.0 / (lerpMax - lerpMin), lerpMin / (lerpMin - lerpMax)));
|
||||
curve0 = lerp(lowerLine, upperLine, lerpT * lerpT);
|
||||
}
|
||||
half3 curve1;
|
||||
{
|
||||
half3 m = half3(1.95, 2.0, 2.0);
|
||||
half3 upperLine = mad(NdotL, m, half3(0.99, 0.99, 1.0) - m);
|
||||
curve1 = saturate(upperLine);
|
||||
}
|
||||
float oneMinusCurva2 = oneMinusCurva * oneMinusCurva;
|
||||
return lerp(curve0, curve1, mad(oneMinusCurva2, -1.0 * oneMinusCurva2, 1.0));
|
||||
}
|
||||
|
||||
// Todo: SDF nose high light
|
||||
// #if define(_SDFShadow) || define(_SDFNoiseHelight)
|
||||
#ifdef _SDFShadow
|
||||
|
||||
// Use main light XZ direction & world Left/Forward Vector to sample character face SDF
|
||||
void SDFSample(out float4 lSDF_Tex, out float4 rSDF_Tex, out float2 leftVector, out float2 forwardVector, float2 UV)
|
||||
{
|
||||
lSDF_Tex = SAMPLE_TEXTURE2D(_SDFShadowTex, sampler_SDFShadowTex, UV);
|
||||
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);
|
||||
}
|
||||
|
||||
// Return 1 -> right side
|
||||
bool SDFPickSide(out float angle, float2 Left, float2 Front, float2 lightDir)
|
||||
{
|
||||
// Remap [-1,1] tp [0,1] | 0 <- Face Toward Light ---- Back Toward Light -> 1
|
||||
angle = 1- clamp(0 , 1, dot(Front, lightDir) * 0.5 + 0.5);
|
||||
// Pick side
|
||||
return dot(lightDir,Left) > 0;
|
||||
}
|
||||
|
||||
// Output: readjusted angle between light and pixel facing direction (Represented by a projection length) [Out Param, angle]
|
||||
// Output: SDF Texel Color [Return Value]
|
||||
float4 SDFResult(inout bool rightside, out float angle, float3 L, float2 UV)
|
||||
{
|
||||
|
||||
float4 left_SDFTex;
|
||||
float4 right_SDFTex;
|
||||
float2 Left;
|
||||
float2 Front;
|
||||
|
||||
SDFSample(left_SDFTex, right_SDFTex, Left, Front, UV);
|
||||
|
||||
float2 light_Dir = normalize(L.xz);
|
||||
rightside = SDFPickSide(angle, Left, Front, light_Dir);
|
||||
|
||||
return rightside ? right_SDFTex : left_SDFTex;
|
||||
}
|
||||
|
||||
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 SDFNoseHighlight(float angle,float tex_value, bool rightside, float2 UV)
|
||||
{
|
||||
// REF: https://zhuanlan.zhihu.com/p/411188212 3.2.1
|
||||
float highlightValue = 0;
|
||||
|
||||
//float cutU = step(0.5, UV.x);
|
||||
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);
|
||||
|
||||
return smoothstep(lightAtten-_SDFNoseHighlightSmoothRange,lightAtten+_SDFNoseHighlightSmoothRange , uvMask * tex_value) * tex_value; // Safeguard, return 0 when tex_value = 0
|
||||
}
|
||||
#endif
|
||||
|
||||
7
Runtime/HDRP/Shaders/PBR.hlsl.meta
Normal file
7
Runtime/HDRP/Shaders/PBR.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38093af06622fce4f85f440a6840c65f
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
269
Runtime/HDRP/Shaders/ShaderPassForward.hlsl
Normal file
269
Runtime/HDRP/Shaders/ShaderPassForward.hlsl
Normal file
@@ -0,0 +1,269 @@
|
||||
#if SHADERPASS != SHADERPASS_FORWARD
|
||||
#error SHADERPASS_is_not_correctly_define
|
||||
#endif
|
||||
|
||||
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl"
|
||||
|
||||
PackedVaryingsType Vert(AttributesMesh inputMesh, AttributesPass inputPass)
|
||||
{
|
||||
VaryingsType varyingsType;
|
||||
varyingsType.vmesh = VertMesh(inputMesh);
|
||||
return MotionVectorVS(varyingsType, inputMesh, inputPass);
|
||||
}
|
||||
|
||||
#ifdef TESSELLATION_ON
|
||||
|
||||
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
|
||||
{
|
||||
VaryingsToPS output;
|
||||
output.vmesh = VertMeshTesselation(input.vmesh);
|
||||
MotionVectorPositionZBias(output);
|
||||
|
||||
output.vpass.positionCS = input.vpass.positionCS;
|
||||
output.vpass.previousPositionCS = input.vpass.previousPositionCS;
|
||||
|
||||
return PackVaryingsToPS(output);
|
||||
}
|
||||
|
||||
#endif // TESSELLATION_ON
|
||||
|
||||
#else // _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl"
|
||||
|
||||
PackedVaryingsType Vert(AttributesMesh inputMesh)
|
||||
{
|
||||
VaryingsType varyingsType;
|
||||
|
||||
#if defined(HAVE_RECURSIVE_RENDERING)
|
||||
// If we have a recursive raytrace object, we will not render it.
|
||||
// As we don't want to rely on renderqueue to exclude the object from the list,
|
||||
// we cull it by settings position to NaN value.
|
||||
// TODO: provide a solution to filter dyanmically recursive raytrace object in the DrawRenderer
|
||||
if (_EnableRecursiveRayTracing && _RayTracing > 0.0)
|
||||
{
|
||||
ZERO_INITIALIZE(VaryingsType, varyingsType); // Divide by 0 should produce a NaN and thus cull the primitive.
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
varyingsType.vmesh = VertMesh(inputMesh);
|
||||
}
|
||||
|
||||
return PackVaryingsType(varyingsType);
|
||||
}
|
||||
|
||||
#ifdef TESSELLATION_ON
|
||||
|
||||
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
|
||||
{
|
||||
VaryingsToPS output;
|
||||
output.vmesh = VertMeshTesselation(input.vmesh);
|
||||
|
||||
return PackVaryingsToPS(output);
|
||||
}
|
||||
|
||||
|
||||
#endif // TESSELLATION_ON
|
||||
|
||||
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
|
||||
|
||||
#ifdef TESSELLATION_ON
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/TessellationShare.hlsl"
|
||||
#endif
|
||||
|
||||
#ifdef UNITY_VIRTUAL_TEXTURING
|
||||
#define VT_BUFFER_TARGET SV_Target1
|
||||
#define EXTRA_BUFFER_TARGET SV_Target2
|
||||
#else
|
||||
#define EXTRA_BUFFER_TARGET SV_Target1
|
||||
#endif
|
||||
|
||||
void Frag(PackedVaryingsToPS packedInput,
|
||||
#ifdef OUTPUT_SPLIT_LIGHTING
|
||||
out float4 outColor : SV_Target0, // outSpecularLighting
|
||||
#ifdef UNITY_VIRTUAL_TEXTURING
|
||||
out float4 outVTFeedback : VT_BUFFER_TARGET,
|
||||
#endif
|
||||
out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET,
|
||||
OUTPUT_SSSBUFFER(outSSSBuffer)
|
||||
#else
|
||||
out float4 outColor : SV_Target0
|
||||
#ifdef UNITY_VIRTUAL_TEXTURING
|
||||
,out float4 outVTFeedback : VT_BUFFER_TARGET
|
||||
#endif
|
||||
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
, out float4 outMotionVec : EXTRA_BUFFER_TARGET
|
||||
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
#endif // OUTPUT_SPLIT_LIGHTING
|
||||
#ifdef _DEPTHOFFSET_ON
|
||||
, out float outputDepth : SV_Depth
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
// Init outMotionVector here to solve compiler warning (potentially unitialized variable)
|
||||
// It is init to the value of forceNoMotion (with 2.0)
|
||||
outMotionVec = float4(2.0, 0.0, 0.0, 0.0);
|
||||
#endif
|
||||
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
|
||||
FragInputs input = UnpackVaryingsToFragInputs(packedInput);
|
||||
|
||||
// We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer.
|
||||
input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy;
|
||||
|
||||
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
|
||||
|
||||
// input.positionSS is SV_Position
|
||||
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
|
||||
|
||||
#ifdef VARYINGS_NEED_POSITION_WS
|
||||
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
||||
#else
|
||||
// Unused
|
||||
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
|
||||
#endif
|
||||
|
||||
SurfaceData surfaceData;
|
||||
BuiltinData builtinData;
|
||||
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
|
||||
|
||||
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData);
|
||||
|
||||
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
|
||||
|
||||
outColor = float4(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
// We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4.
|
||||
|
||||
#ifdef DEBUG_DISPLAY
|
||||
// Init in debug display mode to quiet warning
|
||||
#ifdef OUTPUT_SPLIT_LIGHTING
|
||||
outDiffuseLighting = 0;
|
||||
ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer);
|
||||
#endif
|
||||
float4 Set_UV0 = input.texCoord0;
|
||||
float4 _MainTex_var = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _MainTex));
|
||||
|
||||
surfaceData.baseColor = _MainTex_var.xyz;
|
||||
|
||||
// Same code in ShaderPassForwardUnlit.shader
|
||||
// Reminder: _DebugViewMaterialArray[i]
|
||||
// i==0 -> the size used in the buffer
|
||||
// i>0 -> the index used (0 value means nothing)
|
||||
// The index stored in this buffer could either be
|
||||
// - a gBufferIndex (always stored in _DebugViewMaterialArray[1] as only one supported)
|
||||
// - a property index which is different for each kind of material even if reflecting the same thing (see MaterialSharedProperty)
|
||||
bool viewMaterial = false;
|
||||
int bufferSize = _DebugViewMaterialArray[0].x;
|
||||
if (bufferSize != 0)
|
||||
{
|
||||
bool needLinearToSRGB = false;
|
||||
float3 result = float3(1.0, 0.0, 1.0);
|
||||
|
||||
// Loop through the whole buffer
|
||||
// Works because GetSurfaceDataDebug will do nothing if the index is not a known one
|
||||
for (int index = 1; index <= bufferSize; index++)
|
||||
{
|
||||
int indexMaterialProperty = _DebugViewMaterialArray[index].x;
|
||||
|
||||
// skip if not really in use
|
||||
if (indexMaterialProperty != 0)
|
||||
{
|
||||
viewMaterial = true;
|
||||
|
||||
GetPropertiesDataDebug(indexMaterialProperty, result, needLinearToSRGB);
|
||||
GetVaryingsDataDebug(indexMaterialProperty, input, result, needLinearToSRGB);
|
||||
GetBuiltinDataDebug(indexMaterialProperty, builtinData, posInput, result, needLinearToSRGB);
|
||||
GetSurfaceDataDebug(indexMaterialProperty, surfaceData, result, needLinearToSRGB);
|
||||
GetBSDFDataDebug(indexMaterialProperty, bsdfData, result, needLinearToSRGB);
|
||||
}
|
||||
}
|
||||
|
||||
// TEMP!
|
||||
// For now, the final blit in the backbuffer performs an sRGB write
|
||||
// So in the meantime we apply the inverse transform to linear data to compensate, unless we output to AOVs.
|
||||
if (!needLinearToSRGB && _DebugAOVOutput == 0)
|
||||
result = SRGBToLinear(max(0, result));
|
||||
|
||||
outColor = float4(result, 1.0);
|
||||
}
|
||||
|
||||
if (!viewMaterial)
|
||||
{
|
||||
if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR)
|
||||
{
|
||||
float3 result = float3(0.0, 0.0, 0.0);
|
||||
|
||||
GetPBRValidatorDebug(surfaceData, result);
|
||||
|
||||
outColor = float4(result, 1.0f);
|
||||
}
|
||||
else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW)
|
||||
{
|
||||
float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A);
|
||||
outColor = result;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
#ifdef _SURFACE_TYPE_TRANSPARENT
|
||||
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT;
|
||||
#else
|
||||
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE;
|
||||
#endif
|
||||
LightLoopOutput lightLoopOutput;
|
||||
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput);
|
||||
|
||||
// Alias
|
||||
float3 diffuseLighting = lightLoopOutput.diffuseLighting;
|
||||
float3 specularLighting = lightLoopOutput.specularLighting;
|
||||
|
||||
diffuseLighting *= GetCurrentExposureMultiplier();
|
||||
specularLighting *= GetCurrentExposureMultiplier();
|
||||
|
||||
#ifdef OUTPUT_SPLIT_LIGHTING
|
||||
if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData))
|
||||
{
|
||||
outColor = float4(specularLighting, 1.0);
|
||||
outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
outColor = float4(diffuseLighting + specularLighting, 1.0);
|
||||
outDiffuseLighting = 0;
|
||||
}
|
||||
ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer);
|
||||
#else
|
||||
outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity);
|
||||
outColor = EvaluateAtmosphericScattering(posInput, V, outColor);
|
||||
#endif
|
||||
|
||||
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
VaryingsPassToPS inputPass = UnpackVaryingsPassToPS(packedInput.vpass);
|
||||
bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0);
|
||||
// outMotionVec is already initialize at the value of forceNoMotion (see above)
|
||||
if (!forceNoMotion)
|
||||
{
|
||||
float2 motionVec = CalculateMotionVector(inputPass.positionCS, inputPass.previousPositionCS);
|
||||
EncodeMotionVector(motionVec * 0.5, outMotionVec);
|
||||
outMotionVec.zw = 1.0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DISPLAY
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _DEPTHOFFSET_ON
|
||||
outputDepth = posInput.deviceDepth;
|
||||
#endif
|
||||
|
||||
#ifdef UNITY_VIRTUAL_TEXTURING
|
||||
outVTFeedback = builtinData.vtPackedFeedback;
|
||||
#endif
|
||||
}
|
||||
9
Runtime/HDRP/Shaders/ShaderPassForward.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/ShaderPassForward.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e90380c2b26b694b99ad3d90989105b
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
237
Runtime/HDRP/Shaders/ShaderPassForwardHDRP7.hlsl
Normal file
237
Runtime/HDRP/Shaders/ShaderPassForwardHDRP7.hlsl
Normal file
@@ -0,0 +1,237 @@
|
||||
#if SHADERPASS != SHADERPASS_FORWARD
|
||||
#error SHADERPASS_is_not_correctly_define
|
||||
#endif
|
||||
|
||||
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl"
|
||||
|
||||
PackedVaryingsType Vert(AttributesMesh inputMesh, AttributesPass inputPass)
|
||||
{
|
||||
VaryingsType varyingsType;
|
||||
varyingsType.vmesh = VertMesh(inputMesh);
|
||||
return MotionVectorVS(varyingsType, inputMesh, inputPass);
|
||||
}
|
||||
|
||||
#ifdef TESSELLATION_ON
|
||||
|
||||
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
|
||||
{
|
||||
VaryingsToPS output;
|
||||
output.vmesh = VertMeshTesselation(input.vmesh);
|
||||
MotionVectorPositionZBias(output);
|
||||
|
||||
output.vpass.positionCS = input.vpass.positionCS;
|
||||
output.vpass.previousPositionCS = input.vpass.previousPositionCS;
|
||||
|
||||
return PackVaryingsToPS(output);
|
||||
}
|
||||
|
||||
#endif // TESSELLATION_ON
|
||||
|
||||
#else // _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl"
|
||||
|
||||
PackedVaryingsType Vert(AttributesMesh inputMesh)
|
||||
{
|
||||
VaryingsType varyingsType;
|
||||
varyingsType.vmesh = VertMesh(inputMesh);
|
||||
|
||||
return PackVaryingsType(varyingsType);
|
||||
}
|
||||
|
||||
#ifdef TESSELLATION_ON
|
||||
|
||||
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
|
||||
{
|
||||
VaryingsToPS output;
|
||||
output.vmesh = VertMeshTesselation(input.vmesh);
|
||||
|
||||
return PackVaryingsToPS(output);
|
||||
}
|
||||
|
||||
|
||||
#endif // TESSELLATION_ON
|
||||
|
||||
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
|
||||
|
||||
#ifdef TESSELLATION_ON
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/TessellationShare.hlsl"
|
||||
#endif
|
||||
|
||||
void Frag(PackedVaryingsToPS packedInput,
|
||||
#ifdef OUTPUT_SPLIT_LIGHTING
|
||||
out float4 outColor : SV_Target0, // outSpecularLighting
|
||||
out float4 outDiffuseLighting : SV_Target1,
|
||||
OUTPUT_SSSBUFFER(outSSSBuffer)
|
||||
#else
|
||||
out float4 outColor : SV_Target0
|
||||
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
, out float4 outMotionVec : SV_Target1
|
||||
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
#endif // OUTPUT_SPLIT_LIGHTING
|
||||
#ifdef _DEPTHOFFSET_ON
|
||||
, out float outputDepth : SV_Depth
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
// Init outMotionVector here to solve compiler warning (potentially unitialized variable)
|
||||
// It is init to the value of forceNoMotion (with 2.0)
|
||||
outMotionVec = float4(2.0, 0.0, 0.0, 0.0);
|
||||
#endif
|
||||
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
|
||||
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
|
||||
|
||||
// We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer.
|
||||
input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy;
|
||||
|
||||
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
|
||||
|
||||
// input.positionSS is SV_Position
|
||||
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
|
||||
|
||||
#ifdef VARYINGS_NEED_POSITION_WS
|
||||
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
||||
#else
|
||||
// Unused
|
||||
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
|
||||
#endif
|
||||
|
||||
SurfaceData surfaceData;
|
||||
BuiltinData builtinData;
|
||||
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
|
||||
|
||||
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData);
|
||||
|
||||
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
|
||||
|
||||
outColor = float4(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
// We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4.
|
||||
|
||||
#ifdef DEBUG_DISPLAY
|
||||
// Init in debug display mode to quiet warning
|
||||
#ifdef OUTPUT_SPLIT_LIGHTING
|
||||
outDiffuseLighting = 0;
|
||||
ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer);
|
||||
#endif
|
||||
float4 Set_UV0 = input.texCoord0;
|
||||
float4 _MainTex_var = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _MainTex));
|
||||
|
||||
surfaceData.baseColor = _MainTex_var.xyz;
|
||||
|
||||
|
||||
// Same code in ShaderPassForwardUnlit.shader
|
||||
// Reminder: _DebugViewMaterialArray[i]
|
||||
// i==0 -> the size used in the buffer
|
||||
// i>0 -> the index used (0 value means nothing)
|
||||
// The index stored in this buffer could either be
|
||||
// - a gBufferIndex (always stored in _DebugViewMaterialArray[1] as only one supported)
|
||||
// - a property index which is different for each kind of material even if reflecting the same thing (see MaterialSharedProperty)
|
||||
bool viewMaterial = false;
|
||||
int bufferSize = int(_DebugViewMaterialArray[0]);
|
||||
if (bufferSize != 0)
|
||||
{
|
||||
bool needLinearToSRGB = false;
|
||||
float3 result = float3(1.0, 0.0, 1.0);
|
||||
|
||||
// Loop through the whole buffer
|
||||
// Works because GetSurfaceDataDebug will do nothing if the index is not a known one
|
||||
for (int index = 1; index <= bufferSize; index++)
|
||||
{
|
||||
int indexMaterialProperty = int(_DebugViewMaterialArray[index]);
|
||||
|
||||
// skip if not really in use
|
||||
if (indexMaterialProperty != 0)
|
||||
{
|
||||
viewMaterial = true;
|
||||
|
||||
GetPropertiesDataDebug(indexMaterialProperty, result, needLinearToSRGB);
|
||||
GetVaryingsDataDebug(indexMaterialProperty, input, result, needLinearToSRGB);
|
||||
GetBuiltinDataDebug(indexMaterialProperty, builtinData, result, needLinearToSRGB);
|
||||
GetSurfaceDataDebug(indexMaterialProperty, surfaceData, result, needLinearToSRGB);
|
||||
GetBSDFDataDebug(indexMaterialProperty, bsdfData, result, needLinearToSRGB);
|
||||
}
|
||||
}
|
||||
|
||||
// TEMP!
|
||||
// For now, the final blit in the backbuffer performs an sRGB write
|
||||
// So in the meantime we apply the inverse transform to linear data to compensate.
|
||||
if (!needLinearToSRGB)
|
||||
result = SRGBToLinear(max(0, result));
|
||||
|
||||
outColor = float4(result, 1.0);
|
||||
}
|
||||
|
||||
if (!viewMaterial)
|
||||
{
|
||||
if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR)
|
||||
{
|
||||
float3 result = float3(0.0, 0.0, 0.0);
|
||||
|
||||
GetPBRValidatorDebug(surfaceData, result);
|
||||
|
||||
outColor = float4(result, 1.0f);
|
||||
}
|
||||
else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW)
|
||||
{
|
||||
float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A);
|
||||
outColor = result;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
#ifdef _SURFACE_TYPE_TRANSPARENT
|
||||
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT;
|
||||
#else
|
||||
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE;
|
||||
#endif
|
||||
float3 diffuseLighting;
|
||||
float3 specularLighting;
|
||||
|
||||
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting);
|
||||
|
||||
diffuseLighting *= GetCurrentExposureMultiplier();
|
||||
specularLighting *= GetCurrentExposureMultiplier();
|
||||
|
||||
#ifdef OUTPUT_SPLIT_LIGHTING
|
||||
if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData))
|
||||
{
|
||||
outColor = float4(specularLighting, 1.0);
|
||||
outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
outColor = float4(diffuseLighting + specularLighting, 1.0);
|
||||
outDiffuseLighting = 0;
|
||||
}
|
||||
ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer);
|
||||
#else
|
||||
outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity);
|
||||
outColor = EvaluateAtmosphericScattering(posInput, V, outColor);
|
||||
#endif
|
||||
|
||||
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
VaryingsPassToPS inputPass = UnpackVaryingsPassToPS(packedInput.vpass);
|
||||
bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0);
|
||||
// outMotionVec is already initialize at the value of forceNoMotion (see above)
|
||||
if (!forceNoMotion)
|
||||
{
|
||||
float2 motionVec = CalculateMotionVector(inputPass.positionCS, inputPass.previousPositionCS);
|
||||
EncodeMotionVector(motionVec * 0.5, outMotionVec);
|
||||
outMotionVec.zw = 1.0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DISPLAY
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _DEPTHOFFSET_ON
|
||||
outputDepth = posInput.deviceDepth;
|
||||
#endif
|
||||
}
|
||||
9
Runtime/HDRP/Shaders/ShaderPassForwardHDRP7.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/ShaderPassForwardHDRP7.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b4f1c7876302e04a81e6bd06cb9dd39
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1003
Runtime/HDRP/Shaders/ShaderPassForwardUTS.hlsl
Normal file
1003
Runtime/HDRP/Shaders/ShaderPassForwardUTS.hlsl
Normal file
File diff suppressed because it is too large
Load Diff
9
Runtime/HDRP/Shaders/ShaderPassForwardUTS.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/ShaderPassForwardUTS.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d797988f43f630944b3b0de4c7cfab37
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
470
Runtime/HDRP/Shaders/ShadingMainLight.hlsl
Normal file
470
Runtime/HDRP/Shaders/ShadingMainLight.hlsl
Normal file
@@ -0,0 +1,470 @@
|
||||
//Unity Toon Shader/HDRP
|
||||
//nobuyuki@unity3d.com
|
||||
//toshiyuki@unity3d.com (Universal RP/HDRP)
|
||||
|
||||
#ifndef DirectionalShadowType
|
||||
# if (SHADEROPTIONS_RAYTRACING && (defined(SHADER_API_D3D11) || defined(SHADER_API_D3D12)) && !defined(SHADER_API_XBOXONE) && !defined(SHADER_API_PSSL))
|
||||
# define DirectionalShadowType float3
|
||||
# else
|
||||
# define DirectionalShadowType float
|
||||
# endif
|
||||
#endif
|
||||
|
||||
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)
|
||||
{
|
||||
channelOutAlpha = 1.0f;
|
||||
|
||||
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
|
||||
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
||||
#else
|
||||
// Unused
|
||||
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
|
||||
#endif
|
||||
|
||||
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
|
||||
/* todo. these should be put int a struct */
|
||||
float4 Set_UV0 = input.texCoord0;
|
||||
float3x3 tangentTransform = input.tangentToWorld;
|
||||
utsData.normalDirection = surfaceData.normalWS; // Perturbed normals
|
||||
|
||||
float4 _MainTex_var = float4(surfaceData.baseColor.r, surfaceData.baseColor.g, surfaceData.baseColor.b, surfaceData.coatMask);
|
||||
utsData.viewDirection = V;
|
||||
|
||||
|
||||
/* to here todo. these should be put int a struct */
|
||||
//v.2.0.4
|
||||
#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);
|
||||
float _Inverse_Clipping_var = lerp(_IsBaseMapAlphaAsClippingMask_var, (1.0 - _IsBaseMapAlphaAsClippingMask_var), _Inverse_Clipping);
|
||||
float Set_Clipping = saturate((_Inverse_Clipping_var + _Clipping_Level));
|
||||
clip(Set_Clipping - 0.5);
|
||||
inverseClipping = _Inverse_Clipping_var;
|
||||
#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)
|
||||
shadowAttenuation *= 2.0f;
|
||||
shadowAttenuation = saturate(shadowAttenuation);
|
||||
#endif
|
||||
|
||||
float3 mainLightDirection = utsLightData.lightDirection;
|
||||
float3 mainLightColor = utsLightData.lightColor;
|
||||
|
||||
|
||||
//v.2.0.4
|
||||
|
||||
float3 defaultLightDirection = normalize(UNITY_MATRIX_V[2].xyz + UNITY_MATRIX_V[1].xyz);
|
||||
//v.2.0.5
|
||||
float3 defaultLightColor = saturate(max(float3(0.05, 0.05, 0.05) * _Unlit_Intensity, max(ShadeSH9(float4(0.0, 0.0, 0.0, 1.0)), ShadeSH9(float4(0.0, -1.0, 0.0, 1.0)).rgb) * _Unlit_Intensity));
|
||||
float3 customLightDirection = normalize(mul(UNITY_MATRIX_M, float4(((float3(1.0, 0.0, 0.0) * _Offset_X_Axis_BLD * 10) + (float3(0.0, 1.0, 0.0) * _Offset_Y_Axis_BLD * 10) + (float3(0.0, 0.0, -1.0) * lerp(-1.0, 1.0, _Inverse_Z_Axis_BLD))), 0)).xyz);
|
||||
float3 lightDirection = normalize(lerp(defaultLightDirection, mainLightDirection.xyz, any(mainLightDirection.xyz)));
|
||||
lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD);
|
||||
float3 originalLightColor = mainLightColor.rgb;
|
||||
|
||||
originalLightColor = lerp(originalLightColor, clamp(originalLightColor, ConvertFromEV100(_ToonEvAdjustmentValueMin), ConvertFromEV100(_ToonEvAdjustmentValueMax)), _ToonEvAdjustmentCurve) * _Light_Intensity_Multiplier;
|
||||
float3 lightColor = lerp(max(defaultLightColor, originalLightColor), max(defaultLightColor, saturate(originalLightColor)), max(_Is_Filter_LightColor, _ToonLightHiCutFilter));
|
||||
|
||||
|
||||
////// Lighting:
|
||||
float3 halfDirection = normalize(utsData.viewDirection + lightDirection);
|
||||
//v.2.0.5
|
||||
_Color = _BaseColor;
|
||||
|
||||
|
||||
float3 Set_LightColor = lightColor.rgb;
|
||||
|
||||
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
|
||||
if (_ClippingMatteMode == 1)
|
||||
{
|
||||
clippingColor = Set_BaseColor;
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
|
||||
#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 *= _BaseColorVisible;
|
||||
|
||||
#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);
|
||||
float _HalfLambert_var = 0.5 * dot(utsData.normalDirection, lightDirection) + 0.5; // Half Lambert
|
||||
|
||||
//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 _ShadingGradeMapLevel_var = _ShadingGradeMap_var.r < 0.95 ? _ShadingGradeMap_var.r + _Tweak_ShadingGradeMapLevel : 1;
|
||||
|
||||
float Set_ShadingGrade = saturate(_ShadingGradeMapLevel_var) * lerp(_HalfLambert_var, (_HalfLambert_var * saturate(_SystemShadowsLevel_var)), _Set_SystemShadowsToBase );
|
||||
|
||||
// float Set_ShadingGrade = saturate(_ShadingGradeMapLevel_var) * lerp(_HalfLambert_var, (_HalfLambert_var * saturate(1.0 + _Tweak_SystemShadowsLevel)), _Set_SystemShadowsToBase);
|
||||
|
||||
float _1stColorFeatherForMask = lerp(_1st_ShadeColor_Feather, 0.0f, max(_ComposerMaskMode, _FirstShadeOverridden));
|
||||
//
|
||||
|
||||
float Set_FinalShadowMask = saturate((1.0 + ((Set_ShadingGrade - (_1st_ShadeColor_Step - _1stColorFeatherForMask)) * -1) / (_1st_ShadeColor_Step - (_1st_ShadeColor_Step - _1stColorFeatherForMask)))); // Base and 1st Shade Mask
|
||||
|
||||
// #ifdef _SDFShadow
|
||||
// // modified by Suomi @ 20230902 - SDFResult is used to sample SDF texture on the correct side
|
||||
|
||||
// float angle;
|
||||
// bool rightside;
|
||||
// float2 SDF_UV = TRANSFORM_TEX(Set_UV0, _BaseColorMap);
|
||||
// float4 sdfRes = SDFResult(rightside, angle, mainLightDirection, SDF_UV);
|
||||
// Set_FinalShadowMask = max(SDFMask(angle, sdfRes.r), Set_FinalShadowMask);
|
||||
// Set_BaseColor += _SDFNoseHighlightCoef * SDFNoseHighlight(angle, sdfRes.g, rightside, SDF_UV);
|
||||
|
||||
|
||||
// //#else
|
||||
// #endif
|
||||
|
||||
// #ifdef _RECEIVE_HAIR_SHADOW
|
||||
// // Push the face fragment view space position towards the light for a little bit
|
||||
// float2 scrPos = input.positionSS.xy;
|
||||
// float3 viewLightDir = TransformWorldToViewDir(mainLightDirection) / posInput.linearDepth; // / posInput.deviceDepth; when linearDepth grows large, the movement amount should be lower since we are getting further from the face.
|
||||
// float2 samplingPoint = (scrPos + _HairShadowDistance * viewLightDir.xy ) * _ScreenSize.zw;
|
||||
// // Then sample the hair buffer, to see if the fragment lands in shadow.
|
||||
// float3 hairBuffer = SAMPLE_TEXTURE2D(_HairShadowTex, sampler_HairShadowTex, samplingPoint);
|
||||
// float hairDepth = hairBuffer.r;
|
||||
// float depthCorrect = posInput.deviceDepth < hairDepth + 0.0001 ? 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,1,depthCorrect);
|
||||
// Set_FinalShadowMask = max(hairShadow, Set_FinalShadowMask);
|
||||
|
||||
// // Set_FinalShadowMask += SAMPLE_TEXTURE2D(_HairShadowTex, sampler_HairShadowTex, screenUV).r;
|
||||
// // Set_BaseColor = float3(samplingPoint, 0);
|
||||
// #endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode == 2)
|
||||
{
|
||||
clippingColor = _Is_LightColor_1st_Shade_var;
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
|
||||
#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, Set_BaseColor, 1.0f - _FirstShadeVisible);
|
||||
}
|
||||
float Set_1st_ShadeAlpha = _FirstShadeVisible;
|
||||
#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);
|
||||
float _2ndColorFeatherForMask = lerp(_2nd_ShadeColor_Feather, 0.0f, max(_SecondShadeOverridden, _ComposerMaskMode));
|
||||
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
|
||||
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, Set_BaseColor, 1.0f - _SecondShadeVisible);
|
||||
float Set_2nd_ShadeAlpha = _SecondShadeVisible;
|
||||
Set_FinalBaseColor =
|
||||
lerp(_BaseColor_var,
|
||||
lerp(_Is_LightColor_1st_Shade_var, _Is_LightColor_2nd_Shade_var
|
||||
, Set_ShadeShadowMask)
|
||||
, Set_FinalShadowMask);
|
||||
channelOutAlpha =
|
||||
lerp(Set_BaseColorAlpha, lerp(Set_1st_ShadeAlpha, Set_2nd_ShadeAlpha, Set_ShadeShadowMask),Set_FinalShadowMask);
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
float3 Set_FinalBaseColor =
|
||||
lerp(_BaseColor_var,
|
||||
lerp(_Is_LightColor_1st_Shade_var,
|
||||
lerp((_2nd_ShadeMap_var.rgb * _2nd_ShadeColor.rgb), ((_2nd_ShadeMap_var.rgb * _2nd_ShadeColor.rgb) * Set_LightColor)
|
||||
, _Is_LightColor_2nd_Shade)
|
||||
, Set_ShadeShadowMask)
|
||||
, Set_FinalShadowMask);
|
||||
#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
|
||||
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
|
||||
|
||||
float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask));
|
||||
|
||||
float _Specular_var = 0.5 * dot(halfDirection, utsData.normalDirection) + 0.5; // Specular
|
||||
float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel)) * lerp((1.0 - step(_Specular_var, (1.0 - pow(_HighColor_Power, 5)))), pow(_Specular_var, exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor));
|
||||
float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex));
|
||||
|
||||
//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
|
||||
if (_ClippingMatteMode == 4)
|
||||
{
|
||||
clippingColor = _HighColorWithOutTweak_var;
|
||||
return clippingColor;
|
||||
}
|
||||
#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);
|
||||
float maskEnabled = max(_HighlightOverridden, _ComposerMaskMode);
|
||||
|
||||
_HighColor_var *= _HighlightVisible;
|
||||
Set_HighColor =
|
||||
lerp(SATURATE_IF_SDR(Set_FinalBaseColor - _TweakHighColorMask_var), Set_FinalBaseColor,
|
||||
lerp(_Is_BlendAddToHiColor, 1.0
|
||||
, _Is_SpecularToHighColor));
|
||||
float3 addColor =
|
||||
lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow)))
|
||||
, _Is_UseTweakHighColorOnShadow);
|
||||
Set_HighColor += addColor;
|
||||
if (any(addColor))
|
||||
{
|
||||
Set_HighColor = lerp(Set_HighColor, overridingColor, maskEnabled);
|
||||
channelOutAlpha = _HighlightVisible;
|
||||
}
|
||||
}
|
||||
#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
|
||||
|
||||
|
||||
float4 _Set_RimLightMask_var = tex2D(_Set_RimLightMask, TRANSFORM_TEX(Set_UV0, _Set_RimLightMask));
|
||||
float3 _Is_LightColor_RimLight_var = lerp(_RimLightColor.rgb, (_RimLightColor.rgb * Set_LightColor), _Is_LightColor_RimLight);
|
||||
float _RimArea_var = dot(utsData.normalDirection, utsData.viewDirection);
|
||||
if(_Is_BlendAddToRimColor == 1)
|
||||
{
|
||||
_RimArea_var = 1 - _RimArea_var;
|
||||
}
|
||||
float _RimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _RimLight_Power)));
|
||||
float _Rimlight_InsideMask_var = saturate(lerp((0.0 + ((_RimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), step(_RimLight_InsideMask, _RimLightPower_var), _RimLight_FeatherOff));
|
||||
float _VertHalfLambert_var = 0.5 * dot(utsData.normalDirection, lightDirection) + 0.5;
|
||||
float3 _LightDirection_MaskOn_var = lerp((_Is_LightColor_RimLight_var * _Rimlight_InsideMask_var), (_Is_LightColor_RimLight_var * saturate((_Rimlight_InsideMask_var - ((1.0 - _VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel)))), _LightDirection_MaskOn);
|
||||
float _ApRimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _Ap_RimLight_Power)));
|
||||
//Composition: HighColor and RimLight as _RimLight_var
|
||||
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
|
||||
float4 overridingRimColor = lerp(_RimLightMaskColor, float4(_RimLightMaskColor.w, _RimLightMaskColor.w, _RimLightMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskRimEnabled = max(_RimLightOverridden, _ComposerMaskMode);
|
||||
float Set_RimLightAlpha = _RimLightVisible;
|
||||
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 *= _RimLightVisible;
|
||||
Set_RimLight *= _RimLight_Strength;
|
||||
float3 _RimLight_var;
|
||||
if(_Is_BlendAddToRimColor == 0)
|
||||
{
|
||||
_RimLight_var = lerp(Set_HighColor, (Set_HighColor * Set_RimLight), _RimLight);
|
||||
}
|
||||
else
|
||||
{
|
||||
_RimLight_var = lerp(Set_HighColor, (Set_HighColor + Set_RimLight), _RimLight);
|
||||
}
|
||||
|
||||
if (any(Set_RimLight) * maskRimEnabled)
|
||||
{
|
||||
_RimLight_var = overridingRimColor;
|
||||
channelOutAlpha = Set_RimLightAlpha;
|
||||
}
|
||||
|
||||
_RimLight_var = lerp(_RimLight_var, (_RimLight_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow))), _Is_UseTweakHighColorOnShadow);
|
||||
|
||||
#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;
|
||||
if(_Is_BlendAddToRimColor == 0)
|
||||
{
|
||||
_RimLight_var = lerp(Set_HighColor, (Set_HighColor * Set_RimLight), _RimLight);
|
||||
}
|
||||
else
|
||||
{
|
||||
_RimLight_var = lerp(Set_HighColor, (Set_HighColor + Set_RimLight), _RimLight);
|
||||
}
|
||||
|
||||
_RimLight_var = lerp(_RimLight_var, (_RimLight_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow))), _Is_UseTweakHighColorOnShadow);
|
||||
#endif
|
||||
|
||||
//Matcap
|
||||
//v.2.0.6 : CameraRolling Stabilizer
|
||||
//Mirror Script Determination: if sign_Mirror = -1, determine "Inside the mirror".
|
||||
//v.2.0.7
|
||||
utsData.signMirror= 0.0; // i.mirrorFlag; todo.
|
||||
|
||||
//
|
||||
float3 _Camera_Right = UNITY_MATRIX_V[0].xyz;
|
||||
float3 _Camera_Front = UNITY_MATRIX_V[2].xyz;
|
||||
float3 _Up_Unit = float3(0, 1, 0);
|
||||
float3 _Right_Axis = cross(_Camera_Front, _Up_Unit);
|
||||
//Invert if it's "inside the mirror".
|
||||
if (utsData.signMirror < 0) {
|
||||
_Right_Axis = -1 * _Right_Axis;
|
||||
_Rotate_MatCapUV = -1 * _Rotate_MatCapUV;
|
||||
}
|
||||
else {
|
||||
_Right_Axis = _Right_Axis;
|
||||
}
|
||||
float _Camera_Right_Magnitude = sqrt(_Camera_Right.x * _Camera_Right.x + _Camera_Right.y * _Camera_Right.y + _Camera_Right.z * _Camera_Right.z);
|
||||
float _Right_Axis_Magnitude = sqrt(_Right_Axis.x * _Right_Axis.x + _Right_Axis.y * _Right_Axis.y + _Right_Axis.z * _Right_Axis.z);
|
||||
float _Camera_Roll_Cos = dot(_Right_Axis, _Camera_Right) / (_Right_Axis_Magnitude * _Camera_Right_Magnitude);
|
||||
utsData.cameraRoll = acos(clamp(_Camera_Roll_Cos, -1, 1));
|
||||
utsData.cameraDir = _Camera_Right.y < 0 ? -1 : 1;
|
||||
float _Rot_MatCapUV_var_ang = (_Rotate_MatCapUV * 3.141592654) - utsData.cameraDir * utsData.cameraRoll * _CameraRolling_Stabilizer;
|
||||
//v.2.0.7
|
||||
float2 _Rot_MatCapNmUV_var = RotateUV(Set_UV0, (_Rotate_NormalMapForMatCapUV * 3.141592654), float2(0.5, 0.5), 1.0);
|
||||
//V.2.0.6
|
||||
|
||||
float3 _NormalMapForMatCap_var = UnpackNormalScale(tex2D(_NormalMapForMatCap, TRANSFORM_TEX(_Rot_MatCapNmUV_var, _NormalMapForMatCap)), _BumpScaleMatcap);
|
||||
|
||||
//v.2.0.5: MatCap with camera skew correction
|
||||
float3 viewNormal = (mul(UNITY_MATRIX_V, float4(mul(_NormalMapForMatCap_var.rgb, tangentTransform).rgb, 0))).rgb;
|
||||
float3 NormalBlend_MatcapUV_Detail = viewNormal.rgb * float3(-1, -1, 1);
|
||||
float3 NormalBlend_MatcapUV_Base = (mul(UNITY_MATRIX_V, float4(utsData.viewDirection, 0)).rgb * float3(-1, -1, 1)) + float3(0, 0, 1);
|
||||
float3 noSknewViewNormal = NormalBlend_MatcapUV_Base * dot(NormalBlend_MatcapUV_Base, NormalBlend_MatcapUV_Detail) / NormalBlend_MatcapUV_Base.b - NormalBlend_MatcapUV_Detail;
|
||||
float2 _ViewNormalAsMatCapUV = (lerp(noSknewViewNormal, viewNormal, _Is_Ortho).rg * 0.5) + 0.5;
|
||||
//
|
||||
//v.2.0.7
|
||||
float2 _Rot_MatCapUV_var = RotateUV((0.0 + ((_ViewNormalAsMatCapUV - (0.0 + _Tweak_MatCapUV)) * (1.0 - 0.0)) / ((1.0 - _Tweak_MatCapUV) - (0.0 + _Tweak_MatCapUV))), _Rot_MatCapUV_var_ang, float2(0.5, 0.5), 1.0);
|
||||
//Invert if it's "inside the mirror".
|
||||
if (utsData.signMirror < 0) {
|
||||
_Rot_MatCapUV_var.x = 1 - _Rot_MatCapUV_var.x;
|
||||
}
|
||||
else {
|
||||
_Rot_MatCapUV_var = _Rot_MatCapUV_var;
|
||||
}
|
||||
|
||||
//v.2.0.6 : LOD of Matcap
|
||||
float4 _MatCap_Sampler_var = tex2Dlod(_MatCap_Sampler, float4(TRANSFORM_TEX(_Rot_MatCapUV_var, _MatCap_Sampler), 0.0, _BlurLevelMatcap));
|
||||
float4 _Set_MatcapMask_var = tex2D(_Set_MatcapMask, TRANSFORM_TEX(Set_UV0, _Set_MatcapMask));
|
||||
//
|
||||
//MatcapMask
|
||||
float _Tweak_MatcapMaskLevel_var = saturate(lerp(_Set_MatcapMask_var.g, (1.0 - _Set_MatcapMask_var.g), _Inverse_MatcapMask) + _Tweak_MatcapMaskLevel);
|
||||
float3 _Is_LightColor_MatCap_var = lerp((_MatCap_Sampler_var.rgb * _MatCapColor.rgb), ((_MatCap_Sampler_var.rgb * _MatCapColor.rgb) * Set_LightColor), _Is_LightColor_MatCap);
|
||||
//v.2.0.6 : ShadowMask on Matcap in Blend mode : multiply
|
||||
float3 Set_MatCap = lerp(_Is_LightColor_MatCap_var, (_Is_LightColor_MatCap_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakMatCapOnShadow)) + lerp(Set_HighColor * Set_FinalShadowMask * (1.0 - _TweakMatCapOnShadow), float3(0.0, 0.0, 0.0), _Is_BlendAddToMatCap)), _Is_UseTweakMatCapOnShadow);
|
||||
|
||||
|
||||
//
|
||||
//v.2.0.6
|
||||
//Composition: RimLight and MatCap as diffuseTerm
|
||||
//Broke down diffuseTerm composition
|
||||
float3 matCapColorOnAddMode = _RimLight_var + Set_MatCap * _Tweak_MatcapMaskLevel_var;
|
||||
float _Tweak_MatcapMaskLevel_var_MultiplyMode = _Tweak_MatcapMaskLevel_var * lerp(1, (1 - (Set_FinalShadowMask) * (1 - _TweakMatCapOnShadow)), _Is_UseTweakMatCapOnShadow);
|
||||
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
|
||||
if (_ClippingMatteMode == 5)
|
||||
{
|
||||
clippingColor = float3(0.0f,0.0f,0.0f);
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
float3 diffuseTerm = lerp(_RimLight_var, matCapColorFinal, _MatCap);// Final Composition before Emissive
|
||||
//
|
||||
#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);
|
||||
float2 AR_VN = _AR_OffsetU_var.xy * 0.5 + float2(0.5, 0.5);
|
||||
float2 AR_VN_Rotate = RotateUV(AR_VN, -(utsData.cameraDir * utsData.cameraRoll), float2(0.5, 0.5), 1.0);
|
||||
float2 _AR_OffsetV_var = float2(AR_VN_Rotate.x, lerp(input.texCoord1.y, AR_VN_Rotate.y, _AR_OffsetV));
|
||||
float4 _AngelRing_Sampler_var = tex2D(_AngelRing_Sampler, TRANSFORM_TEX(_AR_OffsetV_var, _AngelRing_Sampler));
|
||||
float3 _Is_LightColor_AR_var = lerp((_AngelRing_Sampler_var.rgb * _AngelRing_Color.rgb), ((_AngelRing_Sampler_var.rgb * _AngelRing_Color.rgb) * Set_LightColor), _Is_LightColor_AR);
|
||||
_Is_LightColor_AR_var = _Is_LightColor_AR_var * max(_AR_ShadowIntensity, (1 - Set_FinalShadowMask));
|
||||
float3 Set_AngelRing = _Is_LightColor_AR_var * _AR_Intensity;
|
||||
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
|
||||
{
|
||||
float4 overridingColor = lerp(_AngelRingMaskColor, float4(_AngelRingMaskColor.w, _AngelRingMaskColor.w, _AngelRingMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_AngelRingOverridden, _ComposerMaskMode);
|
||||
|
||||
_AngelRing *= _AngelRingVisible;
|
||||
diffuseTerm = lerp(diffuseTerm, lerp((diffuseTerm + Set_AngelRing), ((diffuseTerm * (1.0 - Set_ARtexAlpha)) + Set_AngelRingWithAlpha), _ARSampler_AlphaOn), _AngelRing);// Final Composition before Emissive
|
||||
if (any(Set_AngelRing) * maskEnabled)
|
||||
{
|
||||
diffuseTerm = lerp(diffuseTerm, lerp(overridingColor.xyz, ((diffuseTerm * (1.0 - Set_ARtexAlpha)) + Set_AngelRingWithAlpha), _ARSampler_AlphaOn), _AngelRing);// Final Composition before Emissive
|
||||
channelOutAlpha = _AngelRingVisible;
|
||||
}
|
||||
}
|
||||
# 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
|
||||
if (_ClippingMatteMode == 5)
|
||||
{
|
||||
clippingColor = _Is_LightColor_AR_var;
|
||||
return clippingColor;
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
//diffuseTerm = Set_AngelRing * 10 * (1 - Set_FinalShadowMask);
|
||||
#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)
|
||||
{
|
||||
float3 sssColor = SAMPLE_TEXTURE2D(_SSSLutMap, s_linear_clamp_sampler, FitWithCurveApprox(1 - Set_FinalShadowMask, 1));
|
||||
sssColor *= _BaseColor.rgb * _MainTex_var.rgb * Set_LightColor;
|
||||
specularTerm *= lerp((1 - Set_FinalShadowMask), FitWithCurveApprox(1 - Set_FinalShadowMask, 1).r, _Use_SSSLut);
|
||||
diffuseTerm = lerp(diffuseTerm, sssColor, _Use_SSSLut);
|
||||
}
|
||||
|
||||
diffuseTerm = diffuseTerm * utsLightData.diffuseDimmer;
|
||||
|
||||
//float3 finalColor = diffuseTerm + specularTerm + emissive;
|
||||
|
||||
utsAggregateLighting.directDiffuse += diffuseTerm;
|
||||
utsAggregateLighting.directSpecular += specularTerm;
|
||||
|
||||
//return finalColor;
|
||||
}
|
||||
9
Runtime/HDRP/Shaders/ShadingMainLight.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/ShadingMainLight.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b18b203f15b921a47a7cf30e26007d1a
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
259
Runtime/HDRP/Shaders/ShadingOtherLight.hlsl
Normal file
259
Runtime/HDRP/Shaders/ShadingOtherLight.hlsl
Normal file
@@ -0,0 +1,259 @@
|
||||
//Unity Toon Shader/HDRP
|
||||
//nobuyuki@unity3d.com
|
||||
//toshiyuki@unity3d.com (Universal RP/HDRP)
|
||||
|
||||
#include "PBR.hlsl"
|
||||
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;
|
||||
#ifdef _IS_CLIPPING_MATTE
|
||||
if (_ClippingMatteMode != 0)
|
||||
{
|
||||
|
||||
return float3(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
#endif // _IS_CLIPPING_MATTE
|
||||
|
||||
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
|
||||
// input.positionSS is SV_Position
|
||||
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
|
||||
|
||||
/* todo. these should be put into struct */
|
||||
#ifdef VARYINGS_NEED_POSITION_WS
|
||||
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
||||
#else
|
||||
// Unused
|
||||
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
|
||||
#endif
|
||||
|
||||
float3 lightDirection = utsLightData.lightDirection;
|
||||
float3 additionalLightColor = utsLightData.lightColor * _Light_Intensity_Multiplier;
|
||||
|
||||
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
|
||||
|
||||
float4 Set_UV0 = input.texCoord0;
|
||||
float3x3 tangentTransform = input.tangentToWorld;
|
||||
//UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, texCoords))
|
||||
float3 normalDirection = surfaceData.normalWS; // Perturbed normals
|
||||
float3 viewDirection = V;
|
||||
float4 _MainTex_var = float4(surfaceData.baseColor.r, surfaceData.baseColor.g, surfaceData.baseColor.b, surfaceData.coatMask);
|
||||
/* end of todo.*/
|
||||
|
||||
SHADOW_TYPE shadowAttenuation = lightLoopContext.shadowValue;
|
||||
#if !defined (UTS_USE_RAYTRACING_SHADOW)
|
||||
shadowAttenuation *= 2.0f;
|
||||
shadowAttenuation = saturate(shadowAttenuation);
|
||||
#endif
|
||||
|
||||
//v.2.0.5:
|
||||
float3 addPassLightColor;
|
||||
if (lightType == GPULIGHTTYPE_TUBE)
|
||||
{
|
||||
addPassLightColor = (0.5f * (preLightData.diffuseFGD * utsLightData.diffuseDimmer) + 0.5f) / PI * additionalLightColor.rgb;
|
||||
}
|
||||
else if (lightType == GPULIGHTTYPE_RECTANGLE)
|
||||
{
|
||||
addPassLightColor = ((preLightData.diffuseFGD * utsLightData.diffuseDimmer)) * additionalLightColor.rgb;
|
||||
}
|
||||
else
|
||||
{
|
||||
addPassLightColor = (0.5f * dot(lerp(i_normalDir, normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5f) * additionalLightColor.rgb ;
|
||||
}
|
||||
|
||||
float pureIntencity = max(0.001, (0.299 * additionalLightColor.r + 0.587 * additionalLightColor.g + 0.114 * additionalLightColor.b));
|
||||
float3 lightColor = max(float3(0.0, 0.0, 0.0), lerp(addPassLightColor, lerp(float3(0.0, 0.0, 0.0), min(addPassLightColor, addPassLightColor / pureIntencity), notDirectional), _Is_Filter_LightColor));
|
||||
float3 halfDirection = normalize(viewDirection + lightDirection); // has to be recalced here.
|
||||
//v.2.0.5:
|
||||
//v.2.0.5:
|
||||
_1st_ShadeColor_Step = saturate(_1st_ShadeColor_Step + _StepOffset);
|
||||
_2nd_ShadeColor_Step = saturate(_2nd_ShadeColor_Step + _StepOffset);
|
||||
//
|
||||
//v.2.0.5: If Added lights is directional, set 0 as _LightIntensity
|
||||
float _LightIntensity = lerp(0, (0.299 * additionalLightColor.r + 0.587 * additionalLightColor.g + 0.114 * additionalLightColor.b), notDirectional);
|
||||
//v.2.0.5: Filtering the high intensity zone of PointLights
|
||||
float3 Set_LightColor = lightColor;
|
||||
//
|
||||
float3 Set_BaseColor = lerp((_BaseColor.rgb * _MainTex_var.rgb * _LightIntensity), ((_BaseColor.rgb * _MainTex_var.rgb) * Set_LightColor), _Is_LightColor_Base);
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
float Set_BaseColorAlpha = _BaseColorVisible;
|
||||
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 *= _BaseColorVisible;
|
||||
|
||||
#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 Set_1st_ShadeColor = lerp((_1st_ShadeColor.rgb * _1st_ShadeMap_var.rgb * _LightIntensity), ((_1st_ShadeColor.rgb * _1st_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_1st_Shade);
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
{
|
||||
float4 overridingColor = lerp(_FirstShadeMaskColor, float4(_FirstShadeMaskColor.w, _FirstShadeMaskColor.w, _FirstShadeMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_FirstShadeOverridden, _ComposerMaskMode);
|
||||
Set_1st_ShadeColor = lerp(Set_1st_ShadeColor, overridingColor, maskEnabled);
|
||||
Set_1st_ShadeColor = lerp(Set_1st_ShadeColor, Set_BaseColor, 1.0f - _FirstShadeVisible);
|
||||
}
|
||||
float Set_1st_ShadeAlpha = _FirstShadeVisible;
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY //v.2.0.5
|
||||
//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);
|
||||
float3 Set_2nd_ShadeColor = lerp((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb * _LightIntensity), ((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_2nd_Shade);
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
{
|
||||
float4 overridingColor = lerp(_SecondShadeMaskColor, float4(_SecondShadeMaskColor.w, _SecondShadeMaskColor.w, _SecondShadeMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskEnabled = max(_SecondShadeOverridden, _ComposerMaskMode);
|
||||
Set_2nd_ShadeColor = lerp(Set_2nd_ShadeColor, overridingColor, maskEnabled);
|
||||
Set_2nd_ShadeColor = lerp(Set_2nd_ShadeColor, Set_BaseColor, 1.0f - _SecondShadeVisible);
|
||||
|
||||
}
|
||||
#endif //#ifdef UTS_LAYER_VISIBILITY
|
||||
|
||||
float _HalfLambert_var = 0.5 * dot(lerp(i_normalDir, normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5;
|
||||
|
||||
// //v.2.0.5:
|
||||
//SGM
|
||||
//v.2.0.6
|
||||
float4 _ShadingGradeMap_var = tex2Dlod(_ShadingGradeMap, float4(TRANSFORM_TEX(Set_UV0, _ShadingGradeMap), 0.0, _BlurLevelSGM));
|
||||
|
||||
//v.2.0.6
|
||||
//Minmimum value is same as the Minimum Feather's value with the Minimum Step's value as threshold.
|
||||
float _SystemShadowsLevel_var = (shadowAttenuation*0.5)+0.5+_Tweak_SystemShadowsLevel > 0.001 ? (shadowAttenuation*0.5)+0.5+_Tweak_SystemShadowsLevel : 0.0001;
|
||||
float _ShadingGradeMapLevel_var = _ShadingGradeMap_var.r < 0.95 ? _ShadingGradeMap_var.r + _Tweak_ShadingGradeMapLevel : 1;
|
||||
|
||||
float Set_ShadingGrade = saturate(_ShadingGradeMapLevel_var)*lerp( _HalfLambert_var, (_HalfLambert_var*saturate(_SystemShadowsLevel_var)), _Set_SystemShadowsToBase );
|
||||
|
||||
//float Set_ShadingGrade = saturate(_ShadingGradeMapLevel_var) * lerp(_HalfLambert_var, (_HalfLambert_var * saturate(1.0 + _Tweak_SystemShadowsLevel)), _Set_SystemShadowsToBase);
|
||||
|
||||
|
||||
float _1stColorFeatherForMask = lerp(_1st_ShadeColor_Feather, 0.0f, max(_FirstShadeOverridden, _ComposerMaskMode));
|
||||
float _2ndColorFeatherForMask = lerp(_2nd_ShadeColor_Feather, 0.0f, max(_SecondShadeOverridden, _ComposerMaskMode));
|
||||
|
||||
//
|
||||
float Set_FinalShadowMask = saturate((1.0 + ((Set_ShadingGrade - (_1st_ShadeColor_Step - _1stColorFeatherForMask)) * (0.0 - 1.0)) / (_1st_ShadeColor_Step - (_1st_ShadeColor_Step - _1stColorFeatherForMask))));
|
||||
float Set_ShadeShadowMask = saturate((1.0 + ((Set_ShadingGrade - (_2nd_ShadeColor_Step - _2ndColorFeatherForMask)) * (0.0 - 1.0)) / (_2nd_ShadeColor_Step - (_2nd_ShadeColor_Step - _2ndColorFeatherForMask)))); // 1st and 2nd Shades Mask
|
||||
|
||||
//SGM
|
||||
|
||||
//Composition: 3 Basic Colors as diffuseTerm
|
||||
|
||||
float3 diffuseTerm =
|
||||
lerp(
|
||||
Set_BaseColor,
|
||||
lerp(
|
||||
Set_1st_ShadeColor,
|
||||
Set_2nd_ShadeColor,
|
||||
Set_ShadeShadowMask
|
||||
),
|
||||
Set_FinalShadowMask);
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
float Set_2nd_ShadeAlpha = _SecondShadeVisible;
|
||||
channelOutAlpha =
|
||||
lerp(Set_BaseColorAlpha, lerp(Set_1st_ShadeAlpha, Set_2nd_ShadeAlpha, Set_ShadeShadowMask), Set_FinalShadowMask);
|
||||
#endif
|
||||
//v.2.0.6: Add HighColor if _Is_Filter_HiCutPointLightColor is False
|
||||
|
||||
float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask));
|
||||
float _Specular_var = 0.5 * dot(halfDirection, lerp(i_normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular
|
||||
float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel)) * lerp((1.0 - step(_Specular_var, (1.0 - pow(_HighColor_Power, 5)))), pow(_Specular_var, exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor));
|
||||
float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex));
|
||||
float3 _HighColor_var = lerp((_HighColor_Tex_var.rgb * _HighColor.rgb), ((_HighColor_Tex_var.rgb * _HighColor.rgb) * Set_LightColor), _Is_LightColor_HighColor);
|
||||
|
||||
|
||||
float4 _Set_RimLightMask_var = tex2D(_Set_RimLightMask, TRANSFORM_TEX(Set_UV0, _Set_RimLightMask));
|
||||
float3 _Is_LightColor_RimLight_var = lerp(_RimLightColor.rgb, (_RimLightColor.rgb * Set_LightColor), _Is_LightColor_RimLight);
|
||||
float _RimArea_var = dot(surfaceData.normalWS, V);
|
||||
if (_Is_BlendAddToRimColor == 1)
|
||||
{
|
||||
_RimArea_var = 1 - _RimArea_var;
|
||||
}
|
||||
float _RimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _RimLight_Power)));
|
||||
float _Rimlight_InsideMask_var = saturate(lerp((0.0 + ((_RimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), step(_RimLight_InsideMask, _RimLightPower_var), _RimLight_FeatherOff));
|
||||
float _VertHalfLambert_var = 0.5 * dot(surfaceData.normalWS, lightDirection) + 0.5;
|
||||
float3 _LightDirection_MaskOn_var = lerp((_Is_LightColor_RimLight_var * _Rimlight_InsideMask_var), (_Is_LightColor_RimLight_var * saturate((_Rimlight_InsideMask_var - ((1.0 - _VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel)))), _LightDirection_MaskOn);
|
||||
float _ApRimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _Ap_RimLight_Power)));
|
||||
//Composition: HighColor and RimLight as _RimLight_var
|
||||
|
||||
#ifdef UTS_LAYER_VISIBILITY
|
||||
float4 overrideColor = lerp(_HighlightMaskColor, float4(_HighlightMaskColor.w, _HighlightMaskColor.w, _HighlightMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float isMaskEnabled = max(_HighlightOverridden, _ComposerMaskMode);
|
||||
_HighColor_var *= _TweakHighColorMask_var;
|
||||
_HighColor_var *= _HighlightVisible;
|
||||
|
||||
float4 overridingRimColor = lerp(_RimLightMaskColor, float4(_RimLightMaskColor.w, _RimLightMaskColor.w, _RimLightMaskColor.w, 1.0f), _ComposerMaskMode);
|
||||
float maskRimEnabled = max(_RimLightOverridden, _ComposerMaskMode);
|
||||
float Set_RimLightAlpha = _RimLightVisible;
|
||||
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 *= _RimLightVisible;
|
||||
Set_RimLight *= _RimLight_Strength;
|
||||
if(_Is_BlendAddToRimColor == 0)
|
||||
{
|
||||
_HighColor_var = lerp(_HighColor_var, (_HighColor_var * Set_RimLight) * 1, _RimLight);
|
||||
}
|
||||
else
|
||||
{
|
||||
_HighColor_var = lerp(_HighColor_var, (_HighColor_var + Set_RimLight) * 1, _RimLight);
|
||||
}
|
||||
|
||||
if (any(Set_RimLight) * maskRimEnabled)
|
||||
{
|
||||
_HighColor_var = overridingRimColor;
|
||||
channelOutAlpha = Set_RimLightAlpha;
|
||||
}
|
||||
|
||||
diffuseTerm =
|
||||
lerp(saturate(diffuseTerm - _TweakHighColorMask_var), diffuseTerm,
|
||||
lerp(_Is_BlendAddToHiColor, 1.0
|
||||
, _Is_SpecularToHighColor));
|
||||
float3 addColor =
|
||||
lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow)))
|
||||
, _Is_UseTweakHighColorOnShadow);
|
||||
diffuseTerm += addColor;
|
||||
if (any(addColor))
|
||||
{
|
||||
diffuseTerm = lerp(diffuseTerm, overrideColor, isMaskEnabled);
|
||||
channelOutAlpha = _HighlightVisible;
|
||||
}
|
||||
|
||||
#else
|
||||
_HighColor_var *= _TweakHighColorMask_var;
|
||||
|
||||
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;
|
||||
if (_Is_BlendAddToRimColor == 0)
|
||||
{
|
||||
_HighColor_var = lerp(_HighColor_var, (_HighColor_var * Set_RimLight), _RimLight);
|
||||
}
|
||||
else
|
||||
{
|
||||
_HighColor_var = lerp(_HighColor_var, (_HighColor_var + Set_RimLight), _RimLight);
|
||||
}
|
||||
|
||||
diffuseTerm = diffuseTerm + lerp(lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow))), _Is_UseTweakHighColorOnShadow), float3(0, 0, 0), _Is_Filter_HiCutPointLightColor);
|
||||
#endif
|
||||
|
||||
// PBR----------------------------------------------------------------------------------------------------------------
|
||||
float albedoIntensity = max(0.1, (1 - sqrt(surfaceData.metallic)) * (1.7 - 0.7 * (1 - sqrt(surfaceData.metallic))));
|
||||
|
||||
//Specular Term
|
||||
float3 specularTerm = 0;
|
||||
if(lightType == GPULIGHTTYPE_RECTANGLE || lightType == GPULIGHTTYPE_TUBE)
|
||||
{
|
||||
specularTerm = preLightData.specularFGD * Set_LightColor * utsLightData.specularDimmer;
|
||||
#ifdef _PBR_Mode_TOON
|
||||
specularTerm = StepFeatherToon(specularTerm, _ToonSpecularStep, _ToonSpecularFeather);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
specularTerm = ComputeSpecularTerm(V, lightDirection, bsdfData) * Set_LightColor * utsLightData.specularDimmer;
|
||||
}
|
||||
|
||||
specularTerm = specularTerm * (1.0 - Set_FinalShadowMask) * PI * surfaceData.specularColor;
|
||||
diffuseTerm = diffuseTerm * albedoIntensity;
|
||||
|
||||
//float3 finalColor = diffuseTerm + specularTerm;
|
||||
|
||||
utsAggregateLighting.directDiffuse += diffuseTerm;
|
||||
utsAggregateLighting.directSpecular += specularTerm;
|
||||
|
||||
//return finalColor;
|
||||
}
|
||||
9
Runtime/HDRP/Shaders/ShadingOtherLight.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/ShadingOtherLight.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0d6ddf3fb34bef48b91a2fb9cae8cb1
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
209
Runtime/HDRP/Shaders/SobelOutline.shader
Normal file
209
Runtime/HDRP/Shaders/SobelOutline.shader
Normal file
@@ -0,0 +1,209 @@
|
||||
// This is based on the work of Steven Sell
|
||||
// Check out their excellent article at https://www.vertexfragment.com/ramblings/unity-postprocessing-sobel-outline/
|
||||
Shader "Hidden/Shader/Sobel"
|
||||
{
|
||||
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"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
uint vertexID : SV_VertexID;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
float4 worldPos : TEXCOORD2;
|
||||
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;
|
||||
}
|
||||
|
||||
// List of properties to control your post process effect
|
||||
float _Intensity;
|
||||
float _Thickness;
|
||||
float4 _Colour;
|
||||
float _DepthMultiplier;
|
||||
float _DepthBias;
|
||||
float _NormalMultiplier;
|
||||
float _NormalBias;
|
||||
TEXTURE2D_X(_MainTex);
|
||||
|
||||
float Sobel_Basic(float topLeft, float top, float topRight,
|
||||
float left, float right,
|
||||
float bottomLeft, float bottom, float bottomRight)
|
||||
{
|
||||
float x = topLeft + 2 * left + bottomLeft - topRight - 2 * right - bottomRight;
|
||||
float y = -topLeft - 2 * top - topRight + bottomLeft + 2 * bottom + bottomRight;
|
||||
|
||||
return sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
float Sobel_Scharr(float topLeft, float top, float topRight,
|
||||
float left, float right,
|
||||
float bottomLeft, float bottom, float bottomRight)
|
||||
{
|
||||
float x = -3 * topLeft - 10 * left - 3 * bottomLeft + 3 * topRight + 10 * right + 3 * bottomRight;
|
||||
float y = 3 * topLeft + 10 * top + 3 * topRight - 3 * bottomLeft - 10 * bottom - 3 * bottomRight;
|
||||
|
||||
return sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
float SobelSampleDepth(float2 uv, float offsetU, float offsetV)
|
||||
{
|
||||
float topLeft = SampleCameraDepth(uv + float2(-offsetU, offsetV));
|
||||
//float top = SampleCameraDepth(uv + float2( 0, offsetV));
|
||||
float topRight = SampleCameraDepth(uv + float2( offsetU, offsetV));
|
||||
|
||||
//float left = SampleCameraDepth(uv + float2(-offsetU, 0));
|
||||
//float centre = SampleCameraDepth(uv + float2( 0, 0));
|
||||
//float right = SampleCameraDepth(uv + float2( offsetU, 0));
|
||||
|
||||
float bottomLeft = SampleCameraDepth(uv + float2(-offsetU, -offsetV));
|
||||
//float bottom = SampleCameraDepth(uv + float2( 0, -offsetV));
|
||||
float bottomRight = SampleCameraDepth(uv + float2( offsetU, -offsetV));
|
||||
|
||||
float DepthEdgeDetection = saturate((abs(topLeft - bottomRight) + abs(topRight - bottomLeft)) / max(max(max(topLeft, topRight), bottomLeft), bottomRight));
|
||||
return DepthEdgeDetection;
|
||||
}
|
||||
|
||||
float3 SampleWorldNormal(float2 uv)
|
||||
{
|
||||
// if the camera depth is invalid - early out
|
||||
if (SampleCameraDepth(uv) <= 0)
|
||||
return float3(0, 0, 0);
|
||||
|
||||
NormalData normalData;
|
||||
DecodeFromNormalBuffer(uv * _ScreenSize.xy, normalData);
|
||||
|
||||
return normalData.normalWS;
|
||||
}
|
||||
|
||||
|
||||
float Sobel_Basic(float3 topLeft, float3 top, float3 topRight,
|
||||
float3 left, float3 right,
|
||||
float3 bottomLeft, float3 bottom, float3 bottomRight)
|
||||
{
|
||||
float3 x = topLeft + 2 * left + bottomLeft - topRight - 2 * right - bottomRight;
|
||||
float3 y = -topLeft - 2 * top - topRight + bottomLeft + 2 * bottom + bottomRight;
|
||||
|
||||
return sqrt(dot(x, x) + dot(y, y));
|
||||
}
|
||||
|
||||
float Sobel_Scharr(float3 topLeft, float3 top, float3 topRight,
|
||||
float3 left, float3 right,
|
||||
float3 bottomLeft, float3 bottom, float3 bottomRight)
|
||||
{
|
||||
float3 x = -3 * topLeft - 10 * left - 3 * bottomLeft + 3 * topRight + 10 * right + 3 * bottomRight;
|
||||
float3 y = 3 * topLeft + 10 * top + 3 * topRight - 3 * bottomLeft - 10 * bottom - 3 * bottomRight;
|
||||
|
||||
return sqrt(dot(x, x) + dot(y, y));
|
||||
}
|
||||
|
||||
float2 SobelSampleNormal(float2 uv, float offsetU, float offsetV, float3 V)
|
||||
{
|
||||
float3 topLeft = (SampleWorldNormal(uv + float2(-offsetU, offsetV)) + float3(1, 1, 1)) / float3(0.5, 0.5, 0.5);
|
||||
//float3 top = SampleWorldNormal(uv + float2( 0, offsetV));
|
||||
float3 topRight = (SampleWorldNormal(uv + float2( offsetU, offsetV)) + float3(1, 1, 1)) / float3(0.5, 0.5, 0.5);
|
||||
|
||||
//float3 left = SampleWorldNormal(uv + float2(-offsetU, 0));
|
||||
//float3 centre = SampleWorldNormal(uv + float2( 0, 0));
|
||||
//float3 right = SampleWorldNormal(uv + float2( offsetU, 0));
|
||||
|
||||
float3 bottomLeft = (SampleWorldNormal(uv + float2(-offsetU, -offsetV)) + float3(1, 1, 1)) / float3(0.5, 0.5, 0.5);
|
||||
//float3 bottom = SampleWorldNormal(uv + float2( 0, -offsetV));
|
||||
float3 bottomRight = (SampleWorldNormal(uv + float2( offsetU, -offsetV)) + float3(1, 1, 1)) / float3(0.5, 0.5, 0.5);
|
||||
|
||||
float3 DepthEdgeDetection = abs(topLeft - bottomRight) + abs(topRight - bottomLeft);
|
||||
DepthEdgeDetection = max(max(DepthEdgeDetection.x, DepthEdgeDetection.y), DepthEdgeDetection.z);
|
||||
float mask = min(min(min(dot(V, topLeft), dot(V, topRight)), dot(V, bottomLeft)), dot(V, bottomRight));
|
||||
return float2(DepthEdgeDetection.x, mask);
|
||||
}
|
||||
|
||||
float4 CustomPostProcess(Varyings input) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
// Note that if HDUtils.DrawFullScreen is used to render the post process, use ClampAndScaleUVForBilinearPostProcessTexture(input.texcoord.xy) to get the correct UVs
|
||||
|
||||
float3 sourceColor = SAMPLE_TEXTURE2D_X(_MainTex, s_linear_clamp_sampler, input.texcoord).xyz;
|
||||
|
||||
// determine our offsets
|
||||
float offsetU = _Thickness / _ScreenSize.x;
|
||||
float offsetV = _Thickness / _ScreenSize.y;
|
||||
|
||||
// determine the uv coordinates
|
||||
float2 uv = input.positionCS.xy* _ScreenSize.zw;
|
||||
|
||||
float3 V = GetWorldSpaceNormalizeViewDir(input.positionCS);
|
||||
|
||||
// run the sobel sampling of the depth buffer
|
||||
float sobelDepth = SobelSampleDepth(uv, offsetU, offsetV);
|
||||
//sobelDepth = pow(abs(saturate(sobelDepth)) * _DepthMultiplier, _DepthBias);
|
||||
sobelDepth = smoothstep(_DepthMultiplier, _DepthMultiplier + _DepthBias, sobelDepth);
|
||||
|
||||
// run the sobel sampling of the normals
|
||||
float2 sobelNormal = SobelSampleNormal(uv, offsetU, offsetV, V);
|
||||
//sobelNormal = pow(abs(saturate(sobelNormal)) * _NormalMultiplier, _NormalBias);
|
||||
float normalEdge = sobelNormal.x;
|
||||
sobelDepth *= sobelNormal.y;
|
||||
|
||||
normalEdge = smoothstep(_NormalMultiplier, _NormalMultiplier + _NormalBias, normalEdge);
|
||||
float outlineIntensity = saturate(max(sobelDepth, normalEdge));
|
||||
//outlineIntensity = step(0.999f, outlineIntensity);
|
||||
|
||||
// apply the sobel effect
|
||||
float3 finalColor = lerp(sourceColor, _Colour, outlineIntensity * _Intensity);
|
||||
|
||||
//return float4(sobelNormal, sobelNormal, sobelNormal, 1);
|
||||
//return float4(sobelDepth, sobelDepth, sobelDepth, 1);
|
||||
return float4(finalColor, 1);
|
||||
}
|
||||
|
||||
ENDHLSL
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags{ "RenderPipeline" = "HDRenderPipeline" }
|
||||
Pass
|
||||
{
|
||||
Name "Sobel"
|
||||
|
||||
ZWrite Off
|
||||
ZTest Always
|
||||
Blend Off
|
||||
Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma fragment CustomPostProcess
|
||||
#pragma vertex Vert
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
Fallback Off
|
||||
}
|
||||
10
Runtime/HDRP/Shaders/SobelOutline.shader.meta
Normal file
10
Runtime/HDRP/Shaders/SobelOutline.shader.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f97c2f059b7d0d49ab5dbc4ab44051d
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
338
Runtime/HDRP/Shaders/UtsHdrpProperties.hlsl
Normal file
338
Runtime/HDRP/Shaders/UtsHdrpProperties.hlsl
Normal file
@@ -0,0 +1,338 @@
|
||||
// ===========================================================================
|
||||
// WARNING:
|
||||
// On PS4, texture/sampler declarations need to be outside of CBuffers
|
||||
// Otherwise those parameters are not bound correctly at runtime.
|
||||
// ===========================================================================
|
||||
|
||||
#define fixed half
|
||||
|
||||
// Unity Toon Shader
|
||||
#include "UtsTextures.hlsl"
|
||||
|
||||
// Lit
|
||||
TEXTURE2D(_DistortionVectorMap);
|
||||
SAMPLER(sampler_DistortionVectorMap);
|
||||
|
||||
TEXTURE2D(_EmissiveColorMap);
|
||||
SAMPLER(sampler_EmissiveColorMap);
|
||||
|
||||
#ifndef LAYERED_LIT_SHADER
|
||||
|
||||
TEXTURE2D(_DiffuseLightingMap);
|
||||
SAMPLER(sampler_DiffuseLightingMap);
|
||||
|
||||
TEXTURE2D(_BaseColorMap);
|
||||
SAMPLER(sampler_BaseColorMap);
|
||||
|
||||
TEXTURE2D(_MaskMap);
|
||||
SAMPLER(sampler_MaskMap);
|
||||
TEXTURE2D(_BentNormalMap); // Reuse sampler from normal map
|
||||
SAMPLER(sampler_BentNormalMap);
|
||||
|
||||
TEXTURE2D(_NormalMap);
|
||||
SAMPLER(sampler_NormalMap);
|
||||
TEXTURE2D(_NormalMapOS);
|
||||
SAMPLER(sampler_NormalMapOS);
|
||||
|
||||
TEXTURE2D(_DetailMap);
|
||||
SAMPLER(sampler_DetailMap);
|
||||
|
||||
TEXTURE2D(_HeightMap);
|
||||
SAMPLER(sampler_HeightMap);
|
||||
|
||||
TEXTURE2D(_TangentMap);
|
||||
SAMPLER(sampler_TangentMap);
|
||||
TEXTURE2D(_TangentMapOS);
|
||||
SAMPLER(sampler_TangentMapOS);
|
||||
|
||||
TEXTURE2D(_AnisotropyMap);
|
||||
SAMPLER(sampler_AnisotropyMap);
|
||||
|
||||
TEXTURE2D(_SubsurfaceMaskMap);
|
||||
SAMPLER(sampler_SubsurfaceMaskMap);
|
||||
TEXTURE2D(_ThicknessMap);
|
||||
SAMPLER(sampler_ThicknessMap);
|
||||
|
||||
TEXTURE2D(_IridescenceThicknessMap);
|
||||
SAMPLER(sampler_IridescenceThicknessMap);
|
||||
|
||||
TEXTURE2D(_IridescenceMaskMap);
|
||||
SAMPLER(sampler_IridescenceMaskMap);
|
||||
|
||||
TEXTURE2D(_SpecularColorMap);
|
||||
SAMPLER(sampler_SpecularColorMap);
|
||||
|
||||
TEXTURE2D(_TransmittanceColorMap);
|
||||
SAMPLER(sampler_TransmittanceColorMap);
|
||||
|
||||
TEXTURE2D(_CoatMaskMap);
|
||||
SAMPLER(sampler_CoatMaskMap);
|
||||
|
||||
TEXTURE2D(_SSSLutMap);
|
||||
//SAMPLER(sampler_SSSLutMap); //Use s_linear_clamp_sampler instead
|
||||
|
||||
TEXTURE2D(_SDFShadowTex);
|
||||
SAMPLER(sampler_SDFShadowTex);
|
||||
|
||||
TEXTURE2D(_HairShadowTex);
|
||||
//SAMPLER(sampler_HairShadowTex); //registered number of this sampler is more than 16, so we can't use this sampler, use s_trilinear_clamp_sampler instead
|
||||
|
||||
#else
|
||||
|
||||
// Set of users variables
|
||||
#define PROP_DECL(type, name) type name##0, name##1, name##2, name##3
|
||||
// sampler are share by texture type inside a layered material but we need to support that a particualr layer have no texture, so we take the first sampler of available texture as the share one
|
||||
// mean we must declare all sampler
|
||||
#define PROP_DECL_TEX2D(name)\
|
||||
TEXTURE2D(CALL_MERGE_NAME(name, 0)); \
|
||||
SAMPLER(CALL_MERGE_NAME(CALL_MERGE_NAME(sampler, name), 0)); \
|
||||
TEXTURE2D(CALL_MERGE_NAME(name, 1)); \
|
||||
SAMPLER(CALL_MERGE_NAME(CALL_MERGE_NAME(sampler, name), 1)); \
|
||||
TEXTURE2D(CALL_MERGE_NAME(name, 2)); \
|
||||
SAMPLER(CALL_MERGE_NAME(CALL_MERGE_NAME(sampler, name), 2)); \
|
||||
TEXTURE2D(CALL_MERGE_NAME(name, 3)); \
|
||||
SAMPLER(CALL_MERGE_NAME(CALL_MERGE_NAME(sampler, name), 3))
|
||||
|
||||
|
||||
PROP_DECL_TEX2D(_BaseColorMap);
|
||||
PROP_DECL_TEX2D(_MaskMap);
|
||||
PROP_DECL_TEX2D(_BentNormalMap);
|
||||
PROP_DECL_TEX2D(_NormalMap);
|
||||
PROP_DECL_TEX2D(_NormalMapOS);
|
||||
PROP_DECL_TEX2D(_DetailMap);
|
||||
PROP_DECL_TEX2D(_HeightMap);
|
||||
|
||||
PROP_DECL_TEX2D(_SubsurfaceMaskMap);
|
||||
PROP_DECL_TEX2D(_ThicknessMap);
|
||||
|
||||
TEXTURE2D(_LayerMaskMap);
|
||||
SAMPLER(sampler_LayerMaskMap);
|
||||
TEXTURE2D(_LayerInfluenceMaskMap);
|
||||
SAMPLER(sampler_LayerInfluenceMaskMap);
|
||||
|
||||
#endif
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
|
||||
|
||||
#include "UtsUnityPerMaterial.hlsl"
|
||||
|
||||
// shared constant between lit and layered lit
|
||||
float _AlphaCutoff;
|
||||
float _UseShadowThreshold;
|
||||
float _AlphaCutoffShadow;
|
||||
float _AlphaCutoffPrepass;
|
||||
float _AlphaCutoffPostpass;
|
||||
float4 _DoubleSidedConstants;
|
||||
float _DistortionScale;
|
||||
float _DistortionVectorScale;
|
||||
float _DistortionVectorBias;
|
||||
float _DistortionBlurScale;
|
||||
float _DistortionBlurRemapMin;
|
||||
float _DistortionBlurRemapMax;
|
||||
|
||||
float _PPDMaxSamples;
|
||||
float _PPDMinSamples;
|
||||
float _PPDLodThreshold;
|
||||
|
||||
float3 _EmissiveColor;
|
||||
float _AlbedoAffectEmissive;
|
||||
float _EmissiveExposureWeight;
|
||||
|
||||
int _SpecularOcclusionMode;
|
||||
|
||||
// Transparency
|
||||
float3 _TransmittanceColor;
|
||||
float _Ior;
|
||||
float _ATDistance;
|
||||
|
||||
// Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor"
|
||||
// value that exist to identify if the GI emission need to be enabled.
|
||||
// In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it.
|
||||
// TODO: Fix the code in legacy unity so we can customize the beahvior for GI
|
||||
float3 _EmissionColor;
|
||||
float4 _EmissiveColorMap_ST;
|
||||
float _TexWorldScaleEmissive;
|
||||
float4 _UVMappingMaskEmissive;
|
||||
|
||||
float _ID_Intensity;
|
||||
float _IR_Intensity;
|
||||
|
||||
float4 _InvPrimScale; // Only XY are used
|
||||
|
||||
// Wind
|
||||
float _InitialBend;
|
||||
float _Stiffness;
|
||||
float _Drag;
|
||||
float _ShiverDrag;
|
||||
float _ShiverDirectionality;
|
||||
|
||||
// Specular AA
|
||||
float _EnableGeometricSpecularAA;
|
||||
float _SpecularAAScreenSpaceVariance;
|
||||
float _SpecularAAThreshold;
|
||||
|
||||
#ifndef LAYERED_LIT_SHADER
|
||||
|
||||
// Set of users variables
|
||||
float4 _BaseColor;
|
||||
float4 _BaseColorMap_ST;
|
||||
float4 _BaseColorMap_TexelSize;
|
||||
float4 _BaseColorMap_MipInfo;
|
||||
|
||||
float _Metallic;
|
||||
float _MetallicRemapMin;
|
||||
float _MetallicRemapMax;
|
||||
float _Smoothness;
|
||||
float _SmoothnessRemapMin;
|
||||
float _SmoothnessRemapMax;
|
||||
float _Roughness;
|
||||
float _RoughnessRemapMin;
|
||||
float _RoughnessRemapMax;
|
||||
float _AlphaRemapMin;
|
||||
float _AlphaRemapMax;
|
||||
float _AORemapMin;
|
||||
float _AORemapMax;
|
||||
float _SSSIntensity;
|
||||
int _Use_SSSLut;
|
||||
|
||||
float4 _SpecularColor;
|
||||
float _ToonSpecularStep;
|
||||
float _ToonSpecularFeather;
|
||||
|
||||
float _ReceivesSSR;
|
||||
float _ReceivesSSAO;
|
||||
float _AOMin;
|
||||
float _ReceivesSSGI;
|
||||
float _GIMultiplier;
|
||||
|
||||
float _NormalScale;
|
||||
|
||||
float4 _DetailMap_ST;
|
||||
float _DetailAlbedoScale;
|
||||
float _DetailNormalScale;
|
||||
float _DetailSmoothnessScale;
|
||||
|
||||
float4 _HeightMap_TexelSize; // Unity facility. This will provide the size of the heightmap to the shader
|
||||
|
||||
float _HeightAmplitude;
|
||||
float _HeightCenter;
|
||||
|
||||
float _Anisotropy;
|
||||
float4 _AnisotropyMap_ST;
|
||||
int _Use_Anisotropy;
|
||||
float4 _KKColor;
|
||||
float _BSDFContribution;
|
||||
|
||||
float _DiffusionProfileHash;
|
||||
float _SubsurfaceMask;
|
||||
float _TransmissionMask;
|
||||
float _Thickness;
|
||||
float4 _ThicknessRemap;
|
||||
|
||||
|
||||
float _IridescenceThickness;
|
||||
float4 _IridescenceThicknessRemap;
|
||||
float _IridescenceMask;
|
||||
|
||||
float _CoatMask;
|
||||
|
||||
//float4 _SpecularColor;
|
||||
float _EnergyConservingSpecularColor;
|
||||
|
||||
float _TexWorldScale;
|
||||
float _InvTilingScale;
|
||||
float4 _UVMappingMask;
|
||||
float4 _UVDetailsMappingMask;
|
||||
float _LinkDetailsWithBase;
|
||||
float _ObjectSpaceUVMapping;
|
||||
#else // LAYERED_LIT_SHADER
|
||||
|
||||
// Set of users variables
|
||||
PROP_DECL(float4, _BaseColor);
|
||||
float4 _BaseColorMap0_ST;
|
||||
float4 _BaseColorMap1_ST;
|
||||
float4 _BaseColorMap2_ST;
|
||||
float4 _BaseColorMap3_ST;
|
||||
|
||||
float4 _BaseColorMap0_TexelSize;
|
||||
float4 _BaseColorMap0_MipInfo;
|
||||
|
||||
PROP_DECL(float, _Metallic);
|
||||
PROP_DECL(float, _MetallicRemapMin);
|
||||
PROP_DECL(float, _MetallicRemapMax);
|
||||
PROP_DECL(float, _Smoothness);
|
||||
PROP_DECL(float, _SmoothnessRemapMin);
|
||||
PROP_DECL(float, _SmoothnessRemapMax);
|
||||
PROP_DECL(float, _AORemapMin);
|
||||
PROP_DECL(float, _AORemapMax);
|
||||
|
||||
PROP_DECL(float, _NormalScale);
|
||||
float4 _NormalMap0_TexelSize; // Unity facility. This will provide the size of the base normal to the shader
|
||||
|
||||
float4 _HeightMap0_TexelSize;
|
||||
float4 _HeightMap1_TexelSize;
|
||||
float4 _HeightMap2_TexelSize;
|
||||
float4 _HeightMap3_TexelSize;
|
||||
|
||||
float4 _DetailMap0_ST;
|
||||
float4 _DetailMap1_ST;
|
||||
float4 _DetailMap2_ST;
|
||||
float4 _DetailMap3_ST;
|
||||
PROP_DECL(float, _UVDetail);
|
||||
PROP_DECL(float, _DetailAlbedoScale);
|
||||
PROP_DECL(float, _DetailNormalScale);
|
||||
PROP_DECL(float, _DetailSmoothnessScale);
|
||||
|
||||
PROP_DECL(float, _HeightAmplitude);
|
||||
PROP_DECL(float, _HeightCenter);
|
||||
|
||||
PROP_DECL(float, _DiffusionProfileHash);
|
||||
PROP_DECL(float, _SubsurfaceMask);
|
||||
PROP_DECL(float, _Thickness);
|
||||
PROP_DECL(float4, _ThicknessRemap);
|
||||
|
||||
PROP_DECL(float, _OpacityAsDensity);
|
||||
float _InheritBaseNormal1;
|
||||
float _InheritBaseNormal2;
|
||||
float _InheritBaseNormal3;
|
||||
float _InheritBaseHeight1;
|
||||
float _InheritBaseHeight2;
|
||||
float _InheritBaseHeight3;
|
||||
float _InheritBaseColor1;
|
||||
float _InheritBaseColor2;
|
||||
float _InheritBaseColor3;
|
||||
PROP_DECL(float, _HeightOffset);
|
||||
float _HeightTransition;
|
||||
|
||||
float4 _LayerMaskMap_ST;
|
||||
float _TexWorldScaleBlendMask;
|
||||
PROP_DECL(float, _TexWorldScale);
|
||||
PROP_DECL(float, _InvTilingScale);
|
||||
float4 _UVMappingMaskBlendMask;
|
||||
PROP_DECL(float4, _UVMappingMask);
|
||||
PROP_DECL(float4, _UVDetailsMappingMask);
|
||||
PROP_DECL(float, _LinkDetailsWithBase);
|
||||
|
||||
#endif // LAYERED_LIT_SHADER
|
||||
|
||||
|
||||
|
||||
// Tessellation specific
|
||||
|
||||
#ifdef TESSELLATION_ON
|
||||
float _TessellationFactor;
|
||||
float _TessellationFactorMinDistance;
|
||||
float _TessellationFactorMaxDistance;
|
||||
float _TessellationFactorTriangleSize;
|
||||
float _TessellationShapeFactor;
|
||||
float _TessellationBackFaceCullEpsilon;
|
||||
float _TessellationObjectScale;
|
||||
float _TessellationTilingScale;
|
||||
#endif
|
||||
|
||||
// Following two variables are feeded by the C++ Editor for Scene selection
|
||||
int _ObjectId;
|
||||
int _PassValue;
|
||||
|
||||
CBUFFER_END
|
||||
9
Runtime/HDRP/Shaders/UtsHdrpProperties.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/UtsHdrpProperties.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f766a049b2bd4cd4bac4693fe41e62b2
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
276
Runtime/HDRP/Shaders/UtsLightLoop.hlsl
Normal file
276
Runtime/HDRP/Shaders/UtsLightLoop.hlsl
Normal file
@@ -0,0 +1,276 @@
|
||||
//Unity Toon Shader/HDRP
|
||||
//nobuyuki@unity3d.com
|
||||
//toshiyuki@unity3d.com (Universal RP/HDRP)
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Macros.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/PhysicalCamera.hlsl"
|
||||
#include "HDRPToonHead.hlsl"
|
||||
|
||||
// Channel mask enum.
|
||||
// this must be same to UI cs code
|
||||
// HDRPToonGUI._ChannelEnum
|
||||
int eBaseColor = 0;
|
||||
int eFirstShade = 1;
|
||||
int eSecondShade = 2;
|
||||
int eHighlight = 3;
|
||||
int eAngelRing = 4;
|
||||
int eRimLight = 5;
|
||||
int eOutline = 6;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// not in materials
|
||||
int _ToonLightHiCutFilter;
|
||||
int _ToonEvAdjustmentCurve;
|
||||
float _ToonEvAdjustmentValueArray[128];
|
||||
float _ToonEvAdjustmentValueMin;
|
||||
float _ToonEvAdjustmentValueMax;
|
||||
float _ToonEvAdjustmentCompensation;
|
||||
float _ToonIgnoreExposureMultiplier;
|
||||
|
||||
|
||||
// function to rotate the UV: RotateUV()
|
||||
//float2 rotatedUV = RotateUV(i.uv0, (_angular_Verocity*3.141592654), float2(0.5, 0.5), _Time.g);
|
||||
float2 RotateUV(float2 _uv, float _radian, float2 _piv, float _time)
|
||||
{
|
||||
float RotateUV_ang = _radian;
|
||||
float RotateUV_cos = cos(_time*RotateUV_ang);
|
||||
float RotateUV_sin = sin(_time*RotateUV_ang);
|
||||
return (mul(_uv - _piv, float2x2(RotateUV_cos, -RotateUV_sin, RotateUV_sin, RotateUV_cos)) + _piv);
|
||||
}
|
||||
|
||||
float3 ConvertFromEV100(float3 EV100)
|
||||
{
|
||||
#if 1
|
||||
float3 value = pow(2, EV100) * 2.5f;
|
||||
return value;
|
||||
#else
|
||||
float3 maxLuminance = 1.2f * pow(2.0f, EV100);
|
||||
return 1.0f / maxLuminance;
|
||||
#endif
|
||||
}
|
||||
|
||||
float3 ConvertToEV100(float3 value)
|
||||
{
|
||||
#if 1
|
||||
return log2(value*0.4f);
|
||||
#else
|
||||
return log2(1.0f / (1.2f * value));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
float WeightSample(PositionInputs positionInput)
|
||||
{
|
||||
// Center-weighted
|
||||
const float2 kCenter = _ScreenParams.xy * 0.5;
|
||||
const float weight = pow(length((kCenter.xy - positionInput.positionSS.xy) / _ScreenParams.xy),1.0) ;
|
||||
return 1.0 - saturate(weight);
|
||||
}
|
||||
|
||||
float3 ApplyCompensation(float3 originalColor)
|
||||
{
|
||||
float3 ev100_Color = ConvertToEV100(originalColor) +_ToonEvAdjustmentCompensation * 0.5f;
|
||||
|
||||
|
||||
float3 resultColor = max(0, ConvertFromEV100(ev100_Color));
|
||||
return resultColor;
|
||||
}
|
||||
|
||||
float3 ApplyCurrentExposureMultiplier(float3 color)
|
||||
{
|
||||
return color * lerp(GetCurrentExposureMultiplier(), 1, _ToonIgnoreExposureMultiplier);
|
||||
}
|
||||
|
||||
|
||||
float3 GetExposureAdjustedColor(float3 originalColor)
|
||||
{
|
||||
if (_ToonEvAdjustmentCurve != 0)
|
||||
{
|
||||
|
||||
float3 ev100_Color = ConvertToEV100(originalColor);
|
||||
ev100_Color = clamp(ev100_Color, _ToonEvAdjustmentValueMin, _ToonEvAdjustmentValueMax);
|
||||
float3 ev100_remap = (ev100_Color - _ToonEvAdjustmentValueMin) * (128-1) / (_ToonEvAdjustmentValueMax - _ToonEvAdjustmentValueMin);
|
||||
ev100_remap = clamp(ev100_remap, 0.0, 127.0);
|
||||
int3 ev100_idx = (int3)ev100_remap;
|
||||
float3 ev100_lerp = ev100_remap - ev100_idx;
|
||||
float3 ev100_remapped;
|
||||
|
||||
ev100_remapped.r = _ToonEvAdjustmentValueArray[ev100_idx.r] +(_ToonEvAdjustmentValueArray[ev100_idx.r + 1] - _ToonEvAdjustmentValueArray[ev100_idx.r]) * ev100_lerp.r;
|
||||
ev100_remapped.g = _ToonEvAdjustmentValueArray[ev100_idx.g] +(_ToonEvAdjustmentValueArray[ev100_idx.g + 1] - _ToonEvAdjustmentValueArray[ev100_idx.g]) * ev100_lerp.g;
|
||||
ev100_remapped.b = _ToonEvAdjustmentValueArray[ev100_idx.b] +(_ToonEvAdjustmentValueArray[ev100_idx.b + 1] - _ToonEvAdjustmentValueArray[ev100_idx.b]) * ev100_lerp.b;
|
||||
|
||||
|
||||
float3 resultColor = ConvertFromEV100(ev100_remapped);
|
||||
|
||||
|
||||
return resultColor;
|
||||
}
|
||||
else // else is neccessary to avoid warrnings.
|
||||
{
|
||||
return originalColor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float GetLightAttenuation(float3 lightColor)
|
||||
{
|
||||
float lightAttenuation = rateR *lightColor.r + rateG *lightColor.g + rateB *lightColor.b;
|
||||
return lightAttenuation;
|
||||
}
|
||||
|
||||
|
||||
int GetNextDirectionalLightIndex(BuiltinData builtinData, int currentIndex, int mainLightIndex)
|
||||
{
|
||||
int i = 0; // Declare once to avoid the D3D11 compiler warning.
|
||||
for (i = 0; i < (int)_DirectionalLightCount; ++i)
|
||||
{
|
||||
if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, builtinData.renderingLayers))
|
||||
{
|
||||
if (mainLightIndex != i)
|
||||
{
|
||||
if (currentIndex < i)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
int GetUtsMainLightIndex(BuiltinData builtinData)
|
||||
{
|
||||
int mainLightIndex = -1;
|
||||
float3 lightColor = float3(0.0f, 0.0f, 0.0f);
|
||||
float lightAttenuation = 0.0f;
|
||||
uint i = 0; // Declare once to avoid the D3D11 compiler warning.
|
||||
for (i = 0; i < _DirectionalLightCount; ++i)
|
||||
{
|
||||
if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, builtinData.renderingLayers))
|
||||
{
|
||||
float3 currentLightColor = _DirectionalLightDatas[i].color;
|
||||
float currentLightAttenuation = GetLightAttenuation(currentLightColor);
|
||||
|
||||
if (mainLightIndex == -1 || (currentLightAttenuation > lightAttenuation))
|
||||
{
|
||||
mainLightIndex = i;
|
||||
lightAttenuation = currentLightAttenuation;
|
||||
|
||||
lightColor = currentLightColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mainLightIndex;
|
||||
}
|
||||
|
||||
// UTSLightData GetUTSMainPunctualLightData(BuiltinData builtinData, PositionInputs posInput)
|
||||
// {
|
||||
// UTSLightData mainPunctualLight;
|
||||
|
||||
// uint lightCount, lightStart;
|
||||
|
||||
// #ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
|
||||
// GetCountAndStart(posInput, LIGHTCATEGORY_PUNCTUAL, lightStart, lightCount);
|
||||
// #else // LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
|
||||
// lightCount = _PunctualLightCount;
|
||||
// lightStart = 0;
|
||||
// #endif
|
||||
// bool fastPath = false;
|
||||
// #if SCALARIZE_LIGHT_LOOP
|
||||
// uint lightStartLane0;
|
||||
// fastPath = IsFastPath(lightStart, lightStartLane0);
|
||||
|
||||
// if (fastPath)
|
||||
// {
|
||||
// lightStart = lightStartLane0;
|
||||
// }
|
||||
// #endif
|
||||
|
||||
// uint v_lightListOffset = 0;
|
||||
// uint v_lightIdx = lightStart;
|
||||
// float channelAlpha = 0.0f;
|
||||
// [loop] // vulkan shader compiler can not unroll.
|
||||
// while (v_lightListOffset < lightCount)
|
||||
// {
|
||||
// v_lightIdx = FetchIndex(lightStart, v_lightListOffset);
|
||||
// #if SCALARIZE_LIGHT_LOOP
|
||||
// uint s_lightIdx = ScalarizeElementIndex(v_lightIdx, fastPath);
|
||||
// #else
|
||||
// uint s_lightIdx = v_lightIdx;
|
||||
// #endif
|
||||
// if (s_lightIdx == -1)
|
||||
// break;
|
||||
|
||||
// LightData s_lightData = FetchLight(s_lightIdx);
|
||||
|
||||
// // If current scalar and vector light index match, we process the light. The v_lightListOffset for current thread is increased.
|
||||
// // Note that the following should really be ==, however, since helper lanes are not considered by WaveActiveMin, such helper lanes could
|
||||
// // end up with a unique v_lightIdx value that is smaller than s_lightIdx hence being stuck in a loop. All the active lanes will not have this problem.
|
||||
// if (s_lightIdx >= v_lightIdx)
|
||||
// {
|
||||
// v_lightListOffset++;
|
||||
// if (IsMatchingLightLayer(s_lightData.lightLayers, builtinData.renderingLayers))
|
||||
// {
|
||||
// float3 lightDirection;
|
||||
// float4 distances; // {d, d^2, 1/d, d_proj}
|
||||
// GetPunctualLightVectors(posInput.positionWS, s_lightData, lightDirection, distances);
|
||||
// float4 lightColor = EvaluateLight_Punctual(context, posInput, s_lightData, lightDirection, distances);
|
||||
// float3 additionalLightColor = ApplyCurrentExposureMultiplier(lightColor.rgb) * lightColor.a;
|
||||
// const float notDirectional = 1.0f;
|
||||
|
||||
// UTSLightData utsLightData;
|
||||
// utsLightData.lightColor = additionalLightColor;
|
||||
// utsLightData.lightDirection = lightDirection;
|
||||
// utsLightData.diffuseDimmer = s_lightData.diffuseDimmer;
|
||||
// utsLightData.specularDimmer = s_lightData.specularDimmer;
|
||||
// utsLightData.shadowTint = s_lightData.shadowTint;
|
||||
// utsLightData.penumbraTint = s_lightData.penumbraTint;
|
||||
|
||||
// if(length(additionalLightColor) >= length(mainPunctualLight.lightColor))
|
||||
// {
|
||||
// mainPunctualLight = utsLightData;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// return mainPunctualLight;
|
||||
// }
|
||||
|
||||
// Todo: calculate the acutal main lighboth dorectional and punctual)t based on the light attenuation, rather than using the main directional light
|
||||
UTSLightData GetCustomMainLightData(BuiltinData builtinData, UTSLightData mainPunctualLight)
|
||||
{
|
||||
UTSLightData utsLightData;
|
||||
int mainLightIndex;
|
||||
|
||||
mainLightIndex = GetUtsMainLightIndex(builtinData);
|
||||
|
||||
if (mainLightIndex == -1 || length(_DirectionalLightDatas[mainLightIndex].color) < length(mainPunctualLight.lightColor))
|
||||
{
|
||||
utsLightData = mainPunctualLight;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
utsLightData.lightColor = ApplyCurrentExposureMultiplier(_DirectionalLightDatas[mainLightIndex].color);
|
||||
utsLightData.lightDirection = -_DirectionalLightDatas[mainLightIndex].forward;
|
||||
utsLightData.diffuseDimmer = _DirectionalLightDatas[mainLightIndex].diffuseDimmer;
|
||||
utsLightData.specularDimmer = _DirectionalLightDatas[mainLightIndex].specularDimmer;
|
||||
utsLightData.shadowTint = _DirectionalLightDatas[mainLightIndex].shadowTint;
|
||||
utsLightData.penumbraTint = _DirectionalLightDatas[mainLightIndex].penumbraTint;
|
||||
}
|
||||
|
||||
return utsLightData;
|
||||
}
|
||||
|
||||
# include "ShadingOtherLight.hlsl"
|
||||
# include "UtsSelfShadowMainLight.hlsl"
|
||||
# include "ShadingMainLight.hlsl"
|
||||
9
Runtime/HDRP/Shaders/UtsLightLoop.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/UtsLightLoop.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ed2a3a7c9a17104c9792d8ec79bf631
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
83
Runtime/HDRP/Shaders/UtsSelfShadowMainLight.hlsl
Normal file
83
Runtime/HDRP/Shaders/UtsSelfShadowMainLight.hlsl
Normal file
@@ -0,0 +1,83 @@
|
||||
//Unity Toon Shader/HDRP
|
||||
//nobuyuki@unity3d.com
|
||||
//toshiyuki@unity3d.com (Universal RP/HDRP)
|
||||
|
||||
|
||||
#ifndef DirectionalShadowType
|
||||
# if (SHADEROPTIONS_RAYTRACING && (defined(SHADER_API_D3D11) || defined(SHADER_API_D3D12)) && !defined(SHADER_API_XBOXONE) && !defined(SHADER_API_PSSL))
|
||||
# define DirectionalShadowType float3
|
||||
# else
|
||||
# define DirectionalShadowType float
|
||||
# endif
|
||||
#endif
|
||||
|
||||
float3 UTS_SelfShdowMainLight(LightLoopContext lightLoopContext, FragInputs input, int mainLightIndex)
|
||||
{
|
||||
|
||||
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
|
||||
|
||||
// input.positionSS is SV_Position
|
||||
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
|
||||
|
||||
|
||||
#ifdef VARYINGS_NEED_POSITION_WS
|
||||
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
||||
#else
|
||||
// Unused
|
||||
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
|
||||
#endif
|
||||
|
||||
SurfaceData surfaceData;
|
||||
BuiltinData builtinData;
|
||||
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
|
||||
|
||||
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData);
|
||||
|
||||
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
|
||||
/* todo. these should be put int a struct */
|
||||
float4 Set_UV0 = input.texCoord0;
|
||||
float3x3 tangentTransform = input.tangentToWorld;
|
||||
//UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, texCoords))
|
||||
float4 n = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, Set_UV0.xy);
|
||||
// float3 _NormalMap_var = UnpackNormalScale(tex2D(_NormalMap, TRANSFORM_TEX(Set_UV0, _NormalMap)), _BumpScale);
|
||||
float3 _NormalMap_var = UnpackNormalScale(n, _BumpScale);
|
||||
float3 normalLocal = _NormalMap_var.rgb;
|
||||
|
||||
|
||||
float3 i_normalDir = surfaceData.normalWS;
|
||||
|
||||
/* to here todo. these should be put int a struct */
|
||||
|
||||
|
||||
float shadowAttenuation = (float)lightLoopContext.shadowValue;
|
||||
|
||||
|
||||
float3 mainLihgtDirection = -_DirectionalLightDatas[mainLightIndex].forward;
|
||||
float3 mainLightColor = ApplyCurrentExposureMultiplier(_DirectionalLightDatas[mainLightIndex].color);
|
||||
// float4 tmpColor = EvaluateLight_Directional(context, posInput, _DirectionalLightDatas[mainLightIndex]);
|
||||
// float3 mainLightColor = tmpColor.xyz;
|
||||
float3 defaultLightDirection = normalize(UNITY_MATRIX_V[2].xyz + UNITY_MATRIX_V[1].xyz);
|
||||
float3 defaultLightColor = saturate(max(float3(0.05, 0.05, 0.05) * _Unlit_Intensity, max(ShadeSH9(float4(0.0, 0.0, 0.0, 1.0)), ShadeSH9(float4(0.0, -1.0, 0.0, 1.0)).rgb) * _Unlit_Intensity));
|
||||
float3 customLightDirection = normalize(mul(UNITY_MATRIX_M, float4(((float3(1.0, 0.0, 0.0) * _Offset_X_Axis_BLD * 10) + (float3(0.0, 1.0, 0.0) * _Offset_Y_Axis_BLD * 10) + (float3(0.0, 0.0, -1.0) * lerp(-1.0, 1.0, _Inverse_Z_Axis_BLD))), 0)).xyz);
|
||||
float3 lightDirection = normalize(lerp(defaultLightDirection, mainLihgtDirection.xyz, any(mainLihgtDirection.xyz)));
|
||||
lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD);
|
||||
|
||||
////// Lighting:
|
||||
|
||||
|
||||
|
||||
float _HalfLambert_var = 0.5 * dot(i_normalDir, lightDirection) + 0.5;
|
||||
float lambert = dot(i_normalDir, lightDirection);
|
||||
_HalfLambert_var = lambert;
|
||||
|
||||
float baseColorStep = 0.00001;
|
||||
float Set_FinalShadowMask = saturate(1.0 + (-_HalfLambert_var) / (baseColorStep));
|
||||
|
||||
float3 Set_FinalBaseColor = 1 - Set_FinalShadowMask;
|
||||
|
||||
|
||||
|
||||
return Set_FinalBaseColor;
|
||||
|
||||
|
||||
}
|
||||
9
Runtime/HDRP/Shaders/UtsSelfShadowMainLight.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/UtsSelfShadowMainLight.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d53a3bfa05741064d9b4d15154890a04
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Runtime/HDRP/Shaders/UtsTextures.hlsl
Normal file
27
Runtime/HDRP/Shaders/UtsTextures.hlsl
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
// Unity Toon Shader
|
||||
// sampler2D _MainTex;
|
||||
// sampler2D _1st_ShadeMap;
|
||||
// sampler2D _2nd_ShadeMap;
|
||||
|
||||
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
|
||||
TEXTURE2D(_1st_ShadeMap);
|
||||
TEXTURE2D(_2nd_ShadeMap);
|
||||
|
||||
|
||||
sampler _Set_1st_ShadePosition;
|
||||
sampler _Set_2nd_ShadePosition;
|
||||
sampler _ShadingGradeMap;
|
||||
sampler _HighColor_Tex;
|
||||
sampler _Set_HighColorMask;
|
||||
sampler _Set_RimLightMask;
|
||||
sampler _MatCap_Sampler;
|
||||
sampler _NormalMapForMatCap;
|
||||
sampler _Set_MatcapMask;
|
||||
sampler _Emissive_Tex;
|
||||
// sampler2D _ClippingMask;
|
||||
TEXTURE2D(_ClippingMask);
|
||||
sampler _AngelRing_Sampler;
|
||||
sampler _Outline_Sampler;
|
||||
sampler _OutlineTex;
|
||||
sampler _BakedNormal;
|
||||
9
Runtime/HDRP/Shaders/UtsTextures.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/UtsTextures.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b757fd47d2cd7d4e8b2e32ece1f6f8d
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
209
Runtime/HDRP/Shaders/UtsUnityPerMaterial.hlsl
Normal file
209
Runtime/HDRP/Shaders/UtsUnityPerMaterial.hlsl
Normal file
@@ -0,0 +1,209 @@
|
||||
|
||||
// cosntant in Unity Toon Shader
|
||||
float _utsTechnique;
|
||||
float4 _Color;
|
||||
fixed _Use_BaseAs1st;
|
||||
fixed _Use_1stAs2nd;
|
||||
fixed _Is_LightColor_Base;
|
||||
float4 _MainTex_ST;
|
||||
float4 _1st_ShadeMap_ST;
|
||||
float4 _1st_ShadeColor;
|
||||
fixed _Is_LightColor_1st_Shade;
|
||||
float4 _2nd_ShadeMap_ST;
|
||||
float4 _2nd_ShadeColor;
|
||||
fixed _Is_LightColor_2nd_Shade;
|
||||
fixed _Is_NormalMapToBase;
|
||||
fixed _Set_SystemShadowsToBase;
|
||||
|
||||
float _Tweak_SystemShadowsLevel;
|
||||
float _ShadowBias;
|
||||
float _SDFShadowLevel;
|
||||
float _SDFSmoothGamma;
|
||||
float _SDFNoseHighlightCoef;
|
||||
float _SDFNoseHighlightSmoothRange;
|
||||
float _HairShadowDistance;
|
||||
float _HairShadowDistanceScaleFactor;
|
||||
float _HairShadowDepthBias;
|
||||
float _HairShadowFadeInDistance;
|
||||
float _HairShadowFadeOutDistance;
|
||||
float _EyeParallaxAmount;
|
||||
float _EyeBrowBlendingFactor;
|
||||
|
||||
float _BaseColor_Step;
|
||||
float _BaseShade_Feather;
|
||||
float4 _Set_1st_ShadePosition_ST;
|
||||
|
||||
float _ShadeColor_Step;
|
||||
float _1st2nd_Shades_Feather;
|
||||
float4 _Set_2nd_ShadePosition_ST;
|
||||
float4 _ShadingGradeMap_ST;
|
||||
|
||||
float _Tweak_ShadingGradeMapLevel;
|
||||
fixed _BlurLevelSGM;
|
||||
//
|
||||
float _1st_ShadeColor_Step;
|
||||
float _1st_ShadeColor_Feather;
|
||||
float _2nd_ShadeColor_Step;
|
||||
float _2nd_ShadeColor_Feather;
|
||||
|
||||
float4 _HighColor;
|
||||
float4 _HighColor_Tex_ST;
|
||||
fixed _Is_LightColor_HighColor;
|
||||
|
||||
fixed _Is_NormalMapToHighColor;
|
||||
float _HighColor_Power;
|
||||
fixed _Is_SpecularToHighColor;
|
||||
fixed _Is_BlendAddToHiColor;
|
||||
fixed _Is_BlendAddToRimColor;
|
||||
fixed _Is_UseTweakHighColorOnShadow;
|
||||
float _TweakHighColorOnShadow;
|
||||
float4 _Set_HighColorMask_ST;
|
||||
float _Tweak_HighColorMaskLevel;
|
||||
fixed _RimLight;
|
||||
float4 _RimLightColor;
|
||||
float _RimLight_Strength;
|
||||
fixed _Is_LightColor_RimLight;
|
||||
fixed _Is_NormalMapToRimLight;
|
||||
float _RimLight_Power;
|
||||
float _RimLight_InsideMask;
|
||||
fixed _RimLight_FeatherOff;
|
||||
fixed _LightDirection_MaskOn;
|
||||
float _Tweak_LightDirection_MaskLevel;
|
||||
fixed _Add_Antipodean_RimLight;
|
||||
float4 _Ap_RimLightColor;
|
||||
fixed _Is_LightColor_Ap_RimLight;
|
||||
float _Ap_RimLight_Power;
|
||||
fixed _Ap_RimLight_FeatherOff;
|
||||
float4 _Set_RimLightMask_ST;
|
||||
float _Tweak_RimLightMaskLevel;
|
||||
fixed _MatCap;
|
||||
float4 _MatCap_Sampler_ST;
|
||||
float4 _MatCapColor;
|
||||
fixed _Is_LightColor_MatCap;
|
||||
fixed _Is_BlendAddToMatCap;
|
||||
float _Tweak_MatCapUV;
|
||||
float _Rotate_MatCapUV;
|
||||
fixed _Is_NormalMapForMatCap;
|
||||
float4 _NormalMapForMatCap_ST;
|
||||
float _Rotate_NormalMapForMatCapUV;
|
||||
fixed _Is_UseTweakMatCapOnShadow;
|
||||
float _TweakMatCapOnShadow;
|
||||
float4 _Set_MatcapMask_ST;
|
||||
float _Tweak_MatcapMaskLevel;
|
||||
fixed _Is_Ortho;
|
||||
float _CameraRolling_Stabilizer;
|
||||
fixed _BlurLevelMatcap;
|
||||
fixed _Inverse_MatcapMask;
|
||||
float _BumpScale;
|
||||
float _BumpScaleMatcap;
|
||||
float4 _Emissive_Tex_ST;
|
||||
float4 _Emissive_Color;
|
||||
|
||||
fixed _Is_ViewCoord_Scroll;
|
||||
float _Rotate_EmissiveUV;
|
||||
float _Base_Speed;
|
||||
float _Scroll_EmissiveU;
|
||||
float _Scroll_EmissiveV;
|
||||
fixed _Is_PingPong_Base;
|
||||
float4 _ColorShift;
|
||||
float4 _ViewShift;
|
||||
float _ColorShift_Speed;
|
||||
fixed _Is_ColorShift;
|
||||
fixed _Is_ViewShift;
|
||||
float3 emissive;
|
||||
//
|
||||
float _Unlit_Intensity;
|
||||
|
||||
fixed _Is_Filter_HiCutPointLightColor;
|
||||
fixed _Is_Filter_LightColor;
|
||||
|
||||
float _StepOffset;
|
||||
fixed _Is_BLD;
|
||||
float _Offset_X_Axis_BLD;
|
||||
float _Offset_Y_Axis_BLD;
|
||||
fixed _Inverse_Z_Axis_BLD;
|
||||
|
||||
float4 _ClippingMask_ST;
|
||||
|
||||
fixed _IsBaseMapAlphaAsClippingMask;
|
||||
float _Clipping_Level;
|
||||
fixed _Inverse_Clipping;
|
||||
float _Tweak_transparency;
|
||||
fixed _AngelRing;
|
||||
float4 _AngelRing_Sampler_ST;
|
||||
|
||||
float _BaseColorVisible;
|
||||
float _BaseColorOverridden;
|
||||
float4 _BaseColorMaskColor;
|
||||
|
||||
float _FirstShadeVisible;
|
||||
float _FirstShadeOverridden;
|
||||
float4 _FirstShadeMaskColor;
|
||||
|
||||
float _SecondShadeVisible;
|
||||
float _SecondShadeOverridden;
|
||||
float4 _SecondShadeMaskColor;
|
||||
|
||||
float _HighlightVisible;
|
||||
float _HighlightOverridden;
|
||||
float4 _HighlightMaskColor;
|
||||
|
||||
float _AngelRingVisible;
|
||||
float _AngelRingOverridden;
|
||||
float4 _AngelRingMaskColor;
|
||||
|
||||
float _RimLightVisible;
|
||||
float _RimLightOverridden;
|
||||
float4 _RimLightMaskColor;
|
||||
|
||||
float _OutlineVisible;
|
||||
float _OutlineOverridden;
|
||||
float4 _OutlineMaskColor;
|
||||
|
||||
float _ComposerMaskMode;
|
||||
int _ClippingMatteMode;
|
||||
|
||||
float _GI_Intensity;
|
||||
float _Light_Intensity_Multiplier;
|
||||
|
||||
|
||||
float4 _AngelRing_Color;
|
||||
fixed _Is_LightColor_AR;
|
||||
float _AR_Intensity;
|
||||
float _AR_ShadowIntensity;
|
||||
float _AR_OffsetU;
|
||||
float _AR_OffsetV;
|
||||
fixed _ARSampler_AlphaOn;
|
||||
|
||||
// Unity Toon Shader Outline
|
||||
|
||||
float _Outline_Width;
|
||||
float _Outline_MaxWidth;
|
||||
float _Farthest_Distance;
|
||||
float _Nearest_Distance;
|
||||
float4 _Outline_Sampler_ST;
|
||||
float4 _Outline_Color;
|
||||
fixed _Is_BlendBaseColor;
|
||||
float _Offset_Z;
|
||||
float4 _OutlineTex_ST;
|
||||
fixed _Is_OutlineTex;
|
||||
float4 _BakedNormal_ST;
|
||||
fixed _Is_BakedNormal;
|
||||
fixed _UseSmoothedNormal;
|
||||
|
||||
float _ZOverDrawMode;
|
||||
//
|
||||
|
||||
#if defined(_UTS_TOON_EV_PER_MODEL)
|
||||
// not in materials
|
||||
int _ToonLightHiCutFilter;
|
||||
int _ToonEvAdjustmentCurve;
|
||||
float _ToonEvAdjustmentValueArray[128];
|
||||
float _ToonEvAdjustmentValueMin;
|
||||
float _ToonEvAdjustmentValueMax;
|
||||
float _ToonEvAdjustmentCompensation;
|
||||
#endif //#if !defined(_UTS_TOON_EV_PER_MODEL)
|
||||
|
||||
|
||||
float3 _ObjectCenter;
|
||||
float _BlendMode;
|
||||
9
Runtime/HDRP/Shaders/UtsUnityPerMaterial.hlsl.meta
Normal file
9
Runtime/HDRP/Shaders/UtsUnityPerMaterial.hlsl.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7efa59ca140c8c1448f8198e85ed27ec
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user