Flatkit 추가 및 설정

This commit is contained in:
2026-01-25 11:27:33 +09:00
parent 05233497e7
commit cf16910a32
1938 changed files with 408633 additions and 244 deletions

View File

@@ -0,0 +1,282 @@
#ifndef FLATKIT_LIGHTING_DR_INCLUDED
#define FLATKIT_LIGHTING_DR_INCLUDED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
inline half NdotLTransition(half3 normal, half3 lightDir, half selfShadingSize, half shadowEdgeSize, half flatness) {
const half NdotL = dot(normal, lightDir);
const half angleDiff = saturate((NdotL * 0.5 + 0.5) - selfShadingSize);
const half angleDiffTransition = smoothstep(0, shadowEdgeSize, angleDiff);
return lerp(angleDiff, angleDiffTransition, flatness);
}
inline half NdotLTransitionPrimary(half3 normal, half3 lightDir) {
return NdotLTransition(normal, lightDir, _SelfShadingSize, _ShadowEdgeSize, _Flatness);
}
#if defined(DR_CEL_EXTRA_ON)
inline half NdotLTransitionExtra(half3 normal, half3 lightDir) {
return NdotLTransition(normal, lightDir, _SelfShadingSizeExtra, _ShadowEdgeSizeExtra, _FlatnessExtra);
}
#endif
inline half NdotLTransitionTexture(half3 normal, half3 lightDir, sampler2D stepTex) {
const half NdotL = dot(normal, lightDir);
const half angleDiff = saturate((NdotL * 0.5 + 0.5) - _SelfShadingSize * 0.0);
const half4 rampColor = tex2D(stepTex, half2(angleDiff, 0.5));
// NOTE: The color channel here corresponds to the texture format in the shader editor script.
const half angleDiffTransition = rampColor.r;
return angleDiffTransition;
}
inline void ApplyLightToColor(Light light, inout half3 c) {
#if defined(_UNITYSHADOWMODE_MULTIPLY)
c *= lerp(1, light.shadowAttenuation, _UnityShadowPower);
#endif
#if defined(_UNITYSHADOWMODE_COLOR)
c = lerp(lerp(c, _UnityShadowColor.rgb, _UnityShadowColor.a), c, light.shadowAttenuation);
#endif
c.rgb *= light.color * light.distanceAttenuation;
}
half3 LightingPhysicallyBased_DSTRM(Light light, InputData inputData)
{
// If all light in the scene is baked, we use custom light direction for the cel shading.
#if defined(LIGHTMAP_ON)
light.direction = _LightmapDirection;
#else
light.direction = lerp(light.direction, _LightmapDirection, _OverrideLightmapDir);
#endif
half4 c = _BaseColor;
#if defined(_CELPRIMARYMODE_SINGLE)
const half NdotLTPrimary = NdotLTransitionPrimary(inputData.normalWS, light.direction);
c = lerp(_ColorDim, c, NdotLTPrimary);
#endif // _CELPRIMARYMODE_SINGLE
#if defined(_CELPRIMARYMODE_STEPS)
const half NdotLTSteps = NdotLTransitionTexture(inputData.normalWS, light.direction, _CelStepTexture);
c = lerp(_ColorDimSteps, c, NdotLTSteps);
#endif // _CELPRIMARYMODE_STEPS
#if defined(_CELPRIMARYMODE_CURVE)
const half NdotLTCurve = NdotLTransitionTexture(inputData.normalWS, light.direction, _CelCurveTexture);
c = lerp(_ColorDimCurve, c, NdotLTCurve);
#endif // _CELPRIMARYMODE_CURVE
#if defined(DR_CEL_EXTRA_ON)
const half NdotLTExtra = NdotLTransitionExtra(inputData.normalWS, light.direction);
c = lerp(_ColorDimExtra, c, NdotLTExtra);
#endif // DR_CEL_EXTRA_ON
#if defined(DR_GRADIENT_ON)
const float angleRadians = _GradientAngle / 180.0 * PI;
#if defined(_GRADIENTSPACE_WORLD)
const float2 position = inputData.positionWS.xy;
#else
const float2 position = TransformWorldToObject(inputData.positionWS).xy;
#endif
const float posGradRotated = (position.x - _GradientCenterX) * sin(angleRadians) +
(position.y - _GradientCenterY) * cos(angleRadians);
const half gradientFactor = saturate((_GradientSize * 0.5 - posGradRotated) / _GradientSize);
c = lerp(c, _ColorGradient, gradientFactor);
#endif // DR_GRADIENT_ON
const half NdotL = dot(inputData.normalWS, light.direction);
#if defined(DR_RIM_ON)
const float rim = 1.0 - dot(inputData.viewDirectionWS, inputData.normalWS);
const float rimSpread = 1.0 - _FlatRimSize - NdotL * _FlatRimLightAlign;
const float rimEdgeSmooth = _FlatRimEdgeSmoothness;
const float rimTransition = smoothstep(rimSpread - rimEdgeSmooth * 0.5, rimSpread + rimEdgeSmooth * 0.5, rim);
c.rgb = lerp(c.rgb, _FlatRimColor.rgb, rimTransition * _FlatRimColor.a);
#endif // DR_RIM_ON
#if defined(DR_SPECULAR_ON)
// Halfway between lighting direction and view vector.
const float3 halfVector = normalize(light.direction + inputData.viewDirectionWS);
const float NdotH = dot(inputData.normalWS, halfVector) * 0.5 + 0.5;
const float specular = saturate(pow(abs(NdotH), 100.0 * (1.0 - _FlatSpecularSize) * (1.0 - _FlatSpecularSize)));
const float specularTransition = smoothstep(0.5 - _FlatSpecularEdgeSmoothness * 0.1,
0.5 + _FlatSpecularEdgeSmoothness * 0.1, specular);
c = lerp(c, _FlatSpecularColor, specularTransition);
#endif // DR_SPECULAR_ON
#if defined(_UNITYSHADOW_OCCLUSION)
const float occludedAttenuation = smoothstep(0.25, 0.0, -min(NdotL, 0));
light.shadowAttenuation *= occludedAttenuation;
light.distanceAttenuation *= occludedAttenuation;
#endif
ApplyLightToColor(light, c.rgb);
return c.rgb;
}
void StylizeLight(inout Light light)
{
const half shadowAttenuation = saturate(light.shadowAttenuation * _UnityShadowSharpness);
light.shadowAttenuation = shadowAttenuation;
const float distanceAttenuation = smoothstep(0, _LightFalloffSize + 0.001, light.distanceAttenuation);
light.distanceAttenuation = distanceAttenuation;
/*
#if LIGHTMAP_ON
const half3 lightColor = 0;
#else
*/
const half3 lightColor = lerp(half3(1, 1, 1), light.color, _LightContribution);
/*
#endif
*/
light.color = lightColor;
}
half4 UniversalFragment_DSTRM(InputData inputData, SurfaceData surfaceData, float2 uv)
{
const half4 shadowMask = CalculateShadowMask(inputData);
#if VERSION_GREATER_EQUAL(10, 0)
Light mainLight = GetMainLight(inputData.shadowCoord, inputData.positionWS, shadowMask);
#else
Light mainLight = GetMainLight(inputData.shadowCoord);
#endif
#if UNITY_VERSION >= 202220
uint meshRenderingLayers = GetMeshRenderingLayer();
#elif VERSION_GREATER_EQUAL(12, 0)
uint meshRenderingLayers = GetMeshRenderingLightLayer();
#endif
#if LIGHTMAP_ON
mainLight.distanceAttenuation = 1.0;
#endif
StylizeLight(mainLight);
#if defined(_SCREEN_SPACE_OCCLUSION)
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(inputData.normalizedScreenSpaceUV);
mainLight.color *= aoFactor.directAmbientOcclusion;
inputData.bakedGI *= aoFactor.indirectAmbientOcclusion;
#endif
MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, shadowMask);
// Apply Flat Kit stylizing to `inputData.bakedGI` (which is half3).
#if LIGHTMAP_ON
// Apply cel shading. Can also separate modes by `#if defined(_CELPRIMARYMODE_SINGLE)` etc.
// length(inputData.bakedGI) can be replaced with inputData.bakedGI to use light map color more directly.
/*
float lighmapEdgeSize = saturate(_ShadowEdgeSize * 10.0);
inputData.bakedGI = lerp(_ColorDim.rgb, _BaseColor.rgb,
smoothstep(_SelfShadingSize - lighmapEdgeSize, _SelfShadingSize + lighmapEdgeSize, length(inputData.bakedGI)));
// Apply shadow modes
#if defined(_UNITYSHADOWMODE_MULTIPLY)
inputData.bakedGI = lerp(1, inputData.bakedGI, (1 - inputData.bakedGI) * _UnityShadowPower);
#endif
#if defined(_UNITYSHADOWMODE_COLOR)
inputData.bakedGI = lerp(inputData.bakedGI, _UnityShadowColor.rgb, _UnityShadowColor.a * inputData.bakedGI);
#endif
*/
#endif
const half4 albedo = half4(surfaceData.albedo + surfaceData.emission, surfaceData.alpha);
const float2 detailUV = TRANSFORM_TEX(uv, _DetailMap);
const half4 detail = SAMPLE_TEXTURE2D(_DetailMap, sampler_DetailMap, detailUV);
#if defined(_BASEMAP_PREMULTIPLY)
const half3 brdf = albedo.rgb;
#else
const half3 brdf = _BaseColor.rgb;
#endif
BRDFData brdfData;
InitializeBRDFData(brdf, 1.0 - 1.0 / kDielectricSpec.a, 0, 0, surfaceData.alpha, brdfData);
half3 color = GlobalIllumination(brdfData, inputData.bakedGI, 1.0, inputData.normalWS, inputData.viewDirectionWS);
#if VERSION_GREATER_EQUAL(12, 0)
#ifdef _LIGHT_LAYERS
if (IsMatchingLightLayer(mainLight.layerMask, meshRenderingLayers))
#endif
#endif
color += LightingPhysicallyBased_DSTRM(mainLight, inputData);
#if defined(_ADDITIONAL_LIGHTS)
uint pixelLightCount = GetAdditionalLightsCount();
#if USE_FORWARD_PLUS
for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++)
{
FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
Light light = GetAdditionalLight(lightIndex, inputData.positionWS, shadowMask);//, aoFactor);
StylizeLight(light);
#ifdef _LIGHT_LAYERS
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
#endif
{
color += LightingPhysicallyBased_DSTRM(light, inputData);
}
}
#endif
LIGHT_LOOP_BEGIN(pixelLightCount)
Light light = GetAdditionalLight(lightIndex, inputData.positionWS, shadowMask);//, aoFactor);
StylizeLight(light);
#ifdef _LIGHT_LAYERS
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
#endif
{
color += LightingPhysicallyBased_DSTRM(light, inputData);
}
LIGHT_LOOP_END
#endif
#ifdef _ADDITIONAL_LIGHTS_VERTEX
color += inputData.vertexLighting * brdfData.diffuse;
#endif
// Base map.
{
#if defined(_TEXTUREBLENDINGMODE_ADD)
color += lerp(half3(0.0f, 0.0f, 0.0f), albedo.rgb, _TextureImpact);
#else // _TEXTUREBLENDINGMODE_MULTIPLY
color *= lerp(half3(1.0f, 1.0f, 1.0f), albedo.rgb, _TextureImpact);
#endif
}
// Detail map.
{
#if defined(_DETAILMAPBLENDINGMODE_ADD)
color += lerp(0, _DetailMapColor.rgb, detail.rgb * _DetailMapImpact).rgb;
#endif
#if defined(_DETAILMAPBLENDINGMODE_MULTIPLY)
// color *= lerp(1, _DetailMapColor.rgb, detail.rgb * _DetailMapImpact).rgb;
color *= lerp(1, detail.rgb * _DetailMapColor.rgb, _DetailMapImpact).rgb;
#endif
#if defined(_DETAILMAPBLENDINGMODE_INTERPOLATE)
color = lerp(color, detail.rgb, _DetailMapImpact * _DetailMapColor.rgb * detail.a).rgb;
#endif
}
color += surfaceData.emission;
#ifdef _DBUFFER
// Modified `DBuffer.hlsl` function `ApplyDecalToBaseColor` to use light attenuation.
FETCH_DBUFFER(DBuffer, _DBufferTexture, int2(inputData.positionCS.xy));
DecalSurfaceData decalSurfaceData;
DECODE_FROM_DBUFFER(DBuffer, decalSurfaceData);
half3 decalColor = decalSurfaceData.baseColor.xyz;
ApplyLightToColor(mainLight, decalColor);
color.xyz = color.xyz * decalSurfaceData.baseColor.w + decalColor;
#endif
return half4(color, surfaceData.alpha);
}
#endif // FLATKIT_LIGHTING_DR_INCLUDED

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d645ee52b3eb44f2dacb6784216d7712
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,279 @@
#ifndef FLATKIT_LIGHT_PASS_DR_INCLUDED
#define FLATKIT_LIGHT_PASS_DR_INCLUDED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
// Check is needed because in Unity 2021 they use two different URP versions - 14 on desktop and 12 on mobile.
#if !VERSION_LOWER(13, 0)
#if defined(LOD_FADE_CROSSFADE)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"
#endif
#endif
#include "Lighting_DR.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float4 tangentOS : TANGENT;
float2 texcoord : TEXCOORD0;
float2 staticLightmapUV : TEXCOORD1;
float2 dynamicLightmapUV : TEXCOORD2;
#if defined(DR_VERTEX_COLORS_ON)
float4 color : COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float2 uv : TEXCOORD0;
float3 positionWS : TEXCOORD1; // xyz: posWS
#ifdef _NORMALMAP
float4 normalWS : TEXCOORD2; // xyz: normal, w: viewDir.x
float4 tangentWS : TEXCOORD3; // xyz: tangent, w: viewDir.y
float4 bitangentWS : TEXCOORD4; // xyz: bitangent, w: viewDir.z
#else
float3 normalWS : TEXCOORD2;
float3 viewDir : TEXCOORD3;
#endif
#ifdef _ADDITIONAL_LIGHTS_VERTEX
half4 fogFactorAndVertexLight : TEXCOORD5; // x: fogFactor, yzw: vertex light
#else
half fogFactor : TEXCOORD5;
#endif
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
float4 shadowCoord : TEXCOORD6;
#endif
DECLARE_LIGHTMAP_OR_SH(staticLightmapUV, vertexSH, 7);
#ifdef DYNAMICLIGHTMAP_ON
float2 dynamicLightmapUV : TEXCOORD8; // Dynamic lightmap UVs
#endif
float4 positionCS : SV_POSITION;
#if defined(DR_VERTEX_COLORS_ON)
float4 VertexColor : COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
/// ---------------------------------------------------------------------------
// Library/PackageCache/com.unity.render-pipelines.universal@16.0.5/Shaders/SimpleLitForwardPass.hlsl
void InitializeInputData_DR(Varyings input, half3 normalTS, out InputData inputData)
{
inputData = (InputData)0;
inputData.positionWS = input.positionWS;
inputData.positionCS = input.positionCS;
#ifdef _NORMALMAP
half3 viewDirWS = half3(input.normalWS.w, input.tangentWS.w, input.bitangentWS.w);
#if VERSION_GREATER_EQUAL(12, 0)
inputData.tangentToWorld = half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz);
inputData.normalWS = TransformTangentToWorld(normalTS, inputData.tangentToWorld);
#else
float sgn = input.tangentWS.w; // should be either +1 or -1
float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
inputData.normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz));
#endif
#else
half3 viewDirWS = GetWorldSpaceNormalizeViewDir(inputData.positionWS);
inputData.normalWS = input.normalWS;
#endif
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
viewDirWS = SafeNormalize(viewDirWS);
inputData.viewDirectionWS = viewDirWS;
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
inputData.shadowCoord = input.shadowCoord;
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
#endif
#ifdef _ADDITIONAL_LIGHTS_VERTEX
inputData.fogCoord = InitializeInputDataFog(float4(inputData.positionWS, 1.0), input.fogFactorAndVertexLight.x);
inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
#else
#if VERSION_GREATER_EQUAL(12, 0)
inputData.fogCoord = InitializeInputDataFog(float4(inputData.positionWS, 1.0), input.fogFactor);
#endif
inputData.vertexLighting = half3(0, 0, 0);
#endif
#if defined(DYNAMICLIGHTMAP_ON)
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.dynamicLightmapUV, input.vertexSH, inputData.normalWS);
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
#elif !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
#if UNITY_VERSION >= 60000012
inputData.bakedGI = SAMPLE_GI(input.vertexSH,
GetAbsolutePositionWS(inputData.positionWS),
inputData.normalWS,
inputData.viewDirectionWS,
input.positionCS.xy,
/* probeOcclusion */ 0,
inputData.shadowMask);
#else // UNITY_VERSION >= 60000012
inputData.bakedGI = SAMPLE_GI(input.vertexSH,
GetAbsolutePositionWS(inputData.positionWS),
inputData.normalWS,
inputData.viewDirectionWS,
input.positionCS.xy
);
#endif // UNITY_VERSION >= 60000012
#else // !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.vertexSH, inputData.normalWS);
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
#endif // !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
#if defined(DEBUG_DISPLAY)
#if defined(DYNAMICLIGHTMAP_ON)
inputData.dynamicLightmapUV = input.dynamicLightmapUV.xy;
#endif
#if defined(LIGHTMAP_ON)
inputData.staticLightmapUV = input.staticLightmapUV;
#else
inputData.vertexSH = input.vertexSH;
#endif
#endif
}
Varyings StylizedPassVertex(Attributes input)
{
#if defined(CURVEDWORLD_IS_INSTALLED) && !defined(CURVEDWORLD_DISABLED_ON)
#ifdef CURVEDWORLD_NORMAL_TRANSFORMATION_ON
CURVEDWORLD_TRANSFORM_VERTEX_AND_NORMAL(input.positionOS, input.normalOS, input.tangentOS)
#else
CURVEDWORLD_TRANSFORM_VERTEX(input.positionOS)
#endif
#endif
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
const VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
#if defined(_FOG_FRAGMENT)
half fogFactor = 0;
#else
half fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
#endif
output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
output.positionWS.xyz = vertexInput.positionWS;
output.positionCS = vertexInput.positionCS;
half3 viewDirWS = GetCameraPositionWS() - vertexInput.positionWS;
#ifdef _NORMALMAP
output.normalWS = half4(normalInput.normalWS, viewDirWS.x);
output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y);
output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z);
#else
output.normal = NormalizeNormalPerVertex(normalInput.normalWS);
output.viewDir = viewDirWS;
#endif
OUTPUT_LIGHTMAP_UV(input.staticLightmapUV, unity_LightmapST, output.staticLightmapUV);
#ifdef DYNAMICLIGHTMAP_ON
output.dynamicLightmapUV = input.dynamicLightmapUV.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
#endif
#if UNITY_VERSION >= 60000010
float4 probeOcclusion;
OUTPUT_SH4(vertexInput.positionWS, output.normalWS.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), output.vertexSH, probeOcclusion);
#elif UNITY_VERSION >= 202317
OUTPUT_SH4(vertexInput.positionWS, output.normalWS.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), output.vertexSH);
#elif UNITY_VERSION >= 202310
OUTPUT_SH(vertexInput.positionWS, output.normalWS.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), output.vertexSH);
#else
OUTPUT_SH(output.normalWS.xyz, output.vertexSH);
#endif
#ifdef _ADDITIONAL_LIGHTS_VERTEX
half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS);
output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
#else
output.fogFactor = fogFactor;
#endif
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
output.shadowCoord = GetShadowCoord(vertexInput);
#endif
#if defined(DR_VERTEX_COLORS_ON)
output.VertexColor = input.color;
#endif
return output;
}
half4 StylizedPassFragment(Varyings input) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
SurfaceData surfaceData;
InitializeSimpleLitSurfaceData(input.uv, surfaceData);
#if defined(LOD_FADE_CROSSFADE) && !VERSION_LOWER(13, 0)
LODFadeCrossFade(input.positionCS);
#endif
InputData inputData;
InitializeInputData_DR(input, surfaceData.normalTS, inputData);
#if UNITY_VERSION >= 202330
SETUP_DEBUG_TEXTURE_DATA(inputData, input.uv);
#elif UNITY_VERSION >= 202210
SETUP_DEBUG_TEXTURE_DATA(inputData, input.uv, _BaseMap);
#endif
// Apply vertex color before shading (default behavior). Remove the #if block and uncomment below to apply after
// shading.
#if defined(DR_VERTEX_COLORS_ON)
_BaseColor.rgb *= input.VertexColor.rgb;
#endif
// Computes direct light contribution.
half4 color = UniversalFragment_DSTRM(inputData, surfaceData, input.uv);
/*
#if defined(DR_VERTEX_COLORS_ON)
color.rgb *= input.VertexColor.rgb;
#endif
*/
color.rgb = MixFog(color.rgb, inputData.fogCoord);
#if UNITY_VERSION >= 202220
color.a = OutputAlpha(color.a, IsSurfaceTypeTransparent(_Surface));
#else
color.a = OutputAlpha(color.a, _Surface);
#endif
return color;
}
#endif // FLATKIT_LIGHT_PASS_DR_INCLUDED

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2126186b3a4f84079b81ce8d14b60126
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,215 @@
#ifndef FLAT_KIT_STYLIZED_INPUT_INCLUDED
#define FLAT_KIT_STYLIZED_INPUT_INCLUDED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
// NOTE: Do not ifdef the properties here as SRP batcher can not handle different layouts.
#ifndef FLATKIT_TERRAIN
#if _FORWARD_PLUS && UNITY_VERSION < 600000
CBUFFER_START(UnityPerMaterialNoBatching)
#else
CBUFFER_START(UnityPerMaterial)
#endif
#endif
// See `SimpleLitInput.hlsl` and `LitInput.hlsl` for reference
float4 _BaseMap_ST;
float4 _DetailMap_ST;
#ifndef FLATKIT_TERRAIN
half4 _BaseColor;
half _Cutoff;
half _Surface;
#endif
half4 _EmissionColor;
half4 _UnityShadowColor;
// --- _CELPRIMARYMODE_SINGLE
half4 _ColorDim;
// --- _CELPRIMARYMODE_SINGLE
// --- DR_SPECULAR_ON
half4 _FlatSpecularColor;
float _FlatSpecularSize;
float _FlatSpecularEdgeSmoothness;
// --- DR_SPECULAR_ON
// --- DR_RIM_ON
half4 _FlatRimColor;
float _FlatRimSize;
float _FlatRimEdgeSmoothness;
float _FlatRimLightAlign;
// --- DR_RIM_ON
// --- _CELPRIMARYMODE_STEPS
half4 _ColorDimSteps;
sampler2D _CelStepTexture;
// --- _CELPRIMARYMODE_STEPS
// --- _CELPRIMARYMODE_CURVE
half4 _ColorDimCurve;
sampler2D _CelCurveTexture;
// --- _CELPRIMARYMODE_CURVE
// --- DR_CEL_EXTRA_ON
half4 _ColorDimExtra;
half _SelfShadingSizeExtra;
half _ShadowEdgeSizeExtra;
half _FlatnessExtra;
// --- DR_CEL_EXTRA_ON
// --- DR_GRADIENT_ON
half4 _ColorGradient;
half _GradientCenterX;
half _GradientCenterY;
half _GradientSize;
half _GradientAngle;
// --- DR_GRADIENT_ON
half _TextureImpact;
half _SelfShadingSize;
half _ShadowEdgeSize;
half _LightContribution;
half _LightFalloffSize;
half _Flatness;
half _UnityShadowPower;
half _UnityShadowSharpness;
half _OverrideLightmapDir;
half3 _LightmapDirection;
half _DetailMapImpact;
half4 _DetailMapColor;
half4 _OutlineColor;
half _OutlineWidth;
half _OutlineScale;
half _OutlineDepthOffset;
half _CameraDistanceImpact;
#ifndef FLATKIT_TERRAIN
CBUFFER_END
#endif
#ifdef UNITY_DOTS_INSTANCING_ENABLED
UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata)
UNITY_DOTS_INSTANCED_PROP(float4, _BaseColor)
UNITY_DOTS_INSTANCED_PROP(float , _Cutoff)
UNITY_DOTS_INSTANCED_PROP(float , _Surface)
UNITY_DOTS_INSTANCED_PROP(float4, _EmissionColor)
UNITY_DOTS_INSTANCED_PROP(float4 , _UnityShadowColor)
UNITY_DOTS_INSTANCED_PROP(float4, _ColorDim)
UNITY_DOTS_INSTANCED_PROP(float4, _FlatSpecularColor)
UNITY_DOTS_INSTANCED_PROP(float , _FlatSpecularSize)
UNITY_DOTS_INSTANCED_PROP(float , _FlatSpecularEdgeSmoothness)
UNITY_DOTS_INSTANCED_PROP(float4, _FlatRimColor)
UNITY_DOTS_INSTANCED_PROP(float , _FlatRimSize)
UNITY_DOTS_INSTANCED_PROP(float , _FlatRimEdgeSmoothness)
UNITY_DOTS_INSTANCED_PROP(float , _FlatRimLightAlign)
UNITY_DOTS_INSTANCED_PROP(float4, _ColorDimSteps)
UNITY_DOTS_INSTANCED_PROP(float4, _ColorDimCurve)
UNITY_DOTS_INSTANCED_PROP(float4, _ColorDimExtra)
UNITY_DOTS_INSTANCED_PROP(float , _SelfShadingSizeExtra)
UNITY_DOTS_INSTANCED_PROP(float , _ShadowEdgeSizeExtra)
UNITY_DOTS_INSTANCED_PROP(float , _FlatnessExtra)
UNITY_DOTS_INSTANCED_PROP(float4, _ColorGradient)
UNITY_DOTS_INSTANCED_PROP(float , _GradientCenterX)
UNITY_DOTS_INSTANCED_PROP(float , _GradientCenterY)
UNITY_DOTS_INSTANCED_PROP(float , _GradientSize)
UNITY_DOTS_INSTANCED_PROP(float , _GradientAngle)
UNITY_DOTS_INSTANCED_PROP(float , _TextureImpact)
UNITY_DOTS_INSTANCED_PROP(float , _SelfShadingSize)
UNITY_DOTS_INSTANCED_PROP(float , _ShadowEdgeSize)
UNITY_DOTS_INSTANCED_PROP(float , _LightContribution)
UNITY_DOTS_INSTANCED_PROP(float , _LightFalloffSize)
UNITY_DOTS_INSTANCED_PROP(float , _Flatness)
UNITY_DOTS_INSTANCED_PROP(float , _UnityShadowPower)
UNITY_DOTS_INSTANCED_PROP(float , _UnityShadowSharpness)
UNITY_DOTS_INSTANCED_PROP(float , _OverrideLightmapDir)
UNITY_DOTS_INSTANCED_PROP(float3, _LightmapDirection)
UNITY_DOTS_INSTANCED_PROP(float , _DetailMapImpact)
UNITY_DOTS_INSTANCED_PROP(float4, _DetailMapColor)
UNITY_DOTS_INSTANCED_PROP(float4, _OutlineColor)
UNITY_DOTS_INSTANCED_PROP(float , _OutlineWidth)
UNITY_DOTS_INSTANCED_PROP(float , _OutlineScale)
UNITY_DOTS_INSTANCED_PROP(float , _OutlineDepthOffset)
UNITY_DOTS_INSTANCED_PROP(float , _CameraDistanceImpact)
UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)
#define _BaseColor UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _BaseColor)
#define _Cutoff UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _Cutoff)
#define _Surface UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _Surface)
#define _EmissionColor UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _EmissionColor)
#define _UnityShadowColor UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _UnityShadowColor)
#define _ColorDim UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _ColorDim)
#define _FlatSpecularColor UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _FlatSpecularColor)
#define _FlatSpecularSize UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _FlatSpecularSize)
#define _FlatSpecularEdgeSmoothness UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _FlatSpecularEdgeSmoothness)
#define _FlatRimColor UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _FlatRimColor)
#define _FlatRimSize UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _FlatRimSize)
#define _FlatRimEdgeSmoothness UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _FlatRimEdgeSmoothness)
#define _FlatRimLightAlign UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _FlatRimLightAlign)
#define _ColorDimSteps UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _ColorDimSteps)
#define _ColorDimCurve UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _ColorDimCurve)
#define _ColorDimExtra UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _ColorDimExtra)
#define _SelfShadingSizeExtra UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _SelfShadingSizeExtra)
#define _ShadowEdgeSizeExtra UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _ShadowEdgeSizeExtra)
#define _FlatnessExtra UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _FlatnessExtra)
#define _ColorGradient UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _ColorGradient)
#define _GradientCenterX UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _GradientCenterX)
#define _GradientCenterY UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _GradientCenterY)
#define _GradientSize UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _GradientSize)
#define _GradientAngle UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _GradientAngle)
#define _TextureImpact UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _TextureImpact)
#define _SelfShadingSize UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _SelfShadingSize)
#define _ShadowEdgeSize UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _ShadowEdgeSize)
#define _LightContribution UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _LightContribution)
#define _LightFalloffSize UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _LightFalloffSize)
#define _Flatness UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _Flatness)
#define _UnityShadowPower UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _UnityShadowPower)
#define _UnityShadowSharpness UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _UnityShadowSharpness)
#define _OverrideLightmapDir UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _OverrideLightmapDir)
#define _LightmapDirection UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float3 , _LightmapDirection)
#define _DetailMapImpact UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _DetailMapImpact)
#define _DetailMapColor UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _DetailMapColor)
#define _OutlineColor UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _OutlineColor)
#define _OutlineWidth UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _OutlineWidth)
#define _OutlineScale UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _OutlineScale)
#define _OutlineDepthOffset UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _OutlineDepthOffset)
#define _CameraDistanceImpact UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _CameraDistanceImpact)
#endif
inline void InitializeSimpleLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
{
outSurfaceData = (SurfaceData)0;
half4 albedo = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
outSurfaceData.alpha = albedo.a * _BaseColor.a;
AlphaDiscard(outSurfaceData.alpha, _Cutoff);
outSurfaceData.albedo = albedo.rgb;
#ifdef _ALPHAPREMULTIPLY_ON
outSurfaceData.albedo *= outSurfaceData.alpha;
#endif
outSurfaceData.metallic = 0.0; // unused
outSurfaceData.specular = 0.0; // unused
outSurfaceData.smoothness = 0.0; // unused
outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap));
outSurfaceData.occlusion = 1.0; // unused
outSurfaceData.emission = SampleEmission(uv, _EmissionColor.rgb, TEXTURE2D_ARGS(_EmissionMap, sampler_EmissionMap));
}
half4 SampleSpecularSmoothness(half2 uv, half alpha, half4 specColor, TEXTURE2D_PARAM(specMap, sampler_specMap))
{
half4 specularSmoothness = half4(0.0h, 0.0h, 0.0h, 1.0h);
return specularSmoothness;
}
#endif // FLAT_KIT_STYLIZED_INPUT_INCLUDED

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d3d750baac0e54925a4ad89a109d7561
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,154 @@
#ifndef FLATKIT_TERRAIN_LIT_PASSES_DR_INCLUDED
#define FLATKIT_TERRAIN_LIT_PASSES_DR_INCLUDED
#include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitPasses.hlsl"
#include "LibraryUrp/StylizedInput.hlsl"
#ifdef TERRAIN_GBUFFER
FragmentOutput SplatmapFragment_DSTRM(Varyings IN)
#else
half4 SplatmapFragment_DSTRM(Varyings IN) : SV_TARGET
#endif
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
#ifdef _ALPHATEST_ON
ClipHoles(IN.uvMainAndLM.xy);
#endif
half3 normalTS = half3(0.0h, 0.0h, 1.0h);
#ifdef TERRAIN_SPLAT_BASEPASS
half3 albedo = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uvMainAndLM.xy).rgb;
half smoothness = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uvMainAndLM.xy).a;
half metallic = SAMPLE_TEXTURE2D(_MetallicTex, sampler_MetallicTex, IN.uvMainAndLM.xy).r;
half alpha = 1;
half occlusion = 1;
#else
half4 hasMask = half4(_LayerHasMask0, _LayerHasMask1, _LayerHasMask2, _LayerHasMask3);
half4 masks[4];
ComputeMasks(masks, hasMask, IN);
float2 splatUV = (IN.uvMainAndLM.xy * (_Control_TexelSize.zw - 1.0f) + 0.5f) * _Control_TexelSize.xy;
half4 splatControl = SAMPLE_TEXTURE2D(_Control, sampler_Control, splatUV);
#ifdef _TERRAIN_BLEND_HEIGHT
// disable Height Based blend when there are more than 4 layers (multi-pass breaks the normalization)
if (_NumLayersCount <= 4)
HeightBasedSplatModify(splatControl, masks);
#endif
half weight;
half4 mixedDiffuse;
half4 defaultSmoothness;
SplatmapMix(IN.uvMainAndLM, IN.uvSplat01, IN.uvSplat23, splatControl, weight, mixedDiffuse, defaultSmoothness, normalTS);
half3 albedo = mixedDiffuse.rgb;
half4 defaultMetallic = half4(_Metallic0, _Metallic1, _Metallic2, _Metallic3);
half4 defaultOcclusion = half4(_MaskMapRemapScale0.g, _MaskMapRemapScale1.g, _MaskMapRemapScale2.g, _MaskMapRemapScale3.g) +
half4(_MaskMapRemapOffset0.g, _MaskMapRemapOffset1.g, _MaskMapRemapOffset2.g, _MaskMapRemapOffset3.g);
half4 maskSmoothness = half4(masks[0].a, masks[1].a, masks[2].a, masks[3].a);
defaultSmoothness = lerp(defaultSmoothness, maskSmoothness, hasMask);
half smoothness = dot(splatControl, defaultSmoothness);
half4 maskMetallic = half4(masks[0].r, masks[1].r, masks[2].r, masks[3].r);
defaultMetallic = lerp(defaultMetallic, maskMetallic, hasMask);
half metallic = dot(splatControl, defaultMetallic);
half4 maskOcclusion = half4(masks[0].g, masks[1].g, masks[2].g, masks[3].g);
defaultOcclusion = lerp(defaultOcclusion, maskOcclusion, hasMask);
half occlusion = dot(splatControl, defaultOcclusion);
half alpha = weight;
#endif
InputData inputData;
InitializeInputData(IN, normalTS, inputData);
// If lightmap is enabled, flip the normal if the lightmap is flipped.
/*
#if defined(LIGHTMAP_ON)
const half lightmapWorkaroundFlip = -1.0;
inputData.normalWS = lightmapWorkaroundFlip * inputData.normalWS;
#endif
*/
#if UNITY_VERSION > 202340
SETUP_DEBUG_TEXTURE_DATA_FOR_TEX(inputData, IN.uvMainAndLM.xy, _BaseMap);
#elif VERSION_GREATER_EQUAL(12, 1)
SETUP_DEBUG_TEXTURE_DATA(inputData, IN.uvMainAndLM.xy, _BaseMap);
#endif
#if defined(_DBUFFER)
half3 specular = half3(0.0h, 0.0h, 0.0h);
ApplyDecal(IN.clipPos,
albedo,
specular,
inputData.normalWS,
metallic,
occlusion,
smoothness);
#endif
#if UNITY_VERSION > 60000012 // Minor version not precise, somewhere between 6.0.4 and 6.0.23.
InitializeBakedGIData(IN, inputData);
#endif
#ifdef TERRAIN_GBUFFER
BRDFData brdfData;
InitializeBRDFData(albedo, metallic, /* specular */ half3(0.0h, 0.0h, 0.0h), smoothness, alpha, brdfData);
half4 color;
color.rgb = GlobalIllumination(brdfData, inputData.bakedGI, occlusion, inputData.normalWS, inputData.viewDirectionWS);
color.a = alpha;
SplatmapFinalColor(color, inputData.fogCoord);
return BRDFDataToGbuffer(brdfData, inputData, smoothness, color.rgb);
#else
{
_BaseColor.rgb *= albedo;
#ifdef _CELPRIMARYMODE_SINGLE
_ColorDim.rgb *= albedo;
#endif
#ifdef _CELPRIMARYMODE_STEPS
_ColorDimSteps.rgb *= albedo;
#endif
#ifdef _CELPRIMARYMODE_CURVE
_ColorDimCurve.rgb *= albedo;
#endif
#ifdef DR_CEL_EXTRA_ON
_ColorDimExtra.rgb *= albedo;
#endif
#ifdef DR_GRADIENT_ON
_ColorGradient.rgb *= albedo;
#endif
}
SurfaceData surfaceData;
surfaceData.albedo = albedo;
surfaceData.alpha = alpha;
surfaceData.emission = 0;
surfaceData.specular = 0;
surfaceData.smoothness = smoothness;
surfaceData.metallic = metallic;
surfaceData.occlusion = occlusion;
surfaceData.normalTS = normalTS;
surfaceData.clearCoatMask = 0;
surfaceData.clearCoatSmoothness = 0;
half4 color = UniversalFragment_DSTRM(inputData, surfaceData, IN.uvMainAndLM.xy);
SplatmapFinalColor(color, inputData.fogCoord);
return half4(color.rgb, 1.0h);
#endif
}
#endif // FLATKIT_TERRAIN_LIT_PASSES_DR_INCLUDED

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 5217ff6887a39405aa992142275ec2c0
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant: