fixes shaders. fixed ai. fixed project size

This commit is contained in:
dddushesss 2022-01-17 11:26:35 +03:00
parent 0ba3d39df9
commit 3304c858d0
75 changed files with 5777 additions and 19 deletions

View File

@ -83,7 +83,7 @@ public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPoint
FormatInput();
HandleInput(input.magnitude, input.normalized, radius, cam);
handle.anchoredPosition = input * radius * handleRange;
OnDrug.Invoke(Direction);
OnDrug?.Invoke(Direction);
}
protected virtual void HandleInput(float magnitude, Vector2 normalised, Vector2 radius, Camera cam)

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 521f7a978705f5541a78542d8ac78b5b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,364 @@
//////////////////////////////////////////////////////
// MK Toon Common //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_COMMON
#define MK_TOON_COMMON
#if defined(MK_URP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#elif defined(MK_LWRP)
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl"
#else
#include "UnityCG.cginc"
#endif
#include "Config.hlsl"
#include "Pipeline.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// COMMON
/////////////////////////////////////////////////////////////////////////////////////////////
inline float Stutter(float t, float f)
{
return frac(SafeDivide(round(t * f), f));
}
inline float2 Stutter(float t, float2 f)
{
return frac(SafeDivide(round(t * f), f));
}
inline float3 Stutter(float t, float3 f)
{
return frac(SafeDivide(round(t * f), f));
}
inline half SoftFade(float near, float far, float4 ndc)
{
//near OR far has to be > 0.0
float sceneDepth = ComputeLinearDepth(SampleDepth(SafeDivide(ndc.xy,ndc.w)));
float depth = ComputeLinearDepth(SafeDivide(ndc.z, ndc.w));
//Remap to 0 - 1
far = Rcp(far - near);
return saturate(far * ((sceneDepth - near) - depth));
}
inline half CameraFade(float near, float far, float4 ndc)
{
float depth = ComputeLinearDepth(SafeDivide(ndc.z, ndc.w));
//Remap to 0 - 1
far = Rcp(far - near);
return saturate((depth - near) * far);
}
inline void MixAlbedoDetail(inout half3 albedo, DECLARE_TEXTURE_2D_ARGS(tex, samplerTex), float2 uv, float3 blendUV)
{
half4 detail = SAMPLE_TEX2D_FLIPBOOK(tex, samplerTex, uv, blendUV);
detail.rgb *= _DetailColor.rgb;
#if defined(MK_DETAIL_BLEND_MIX)
albedo = lerp(albedo, detail.rgb, _DetailMix * detail.a);
#elif defined(MK_DETAIL_BLEND_ADD)
albedo += lerp(0.0h, detail.rgb, _DetailMix * detail.a);
#else //MK_DETAIL_BLEND_MULTIPLY
albedo *= lerp(1.0h, detail.rgb, _DetailMix * detail.a);
#endif
}
inline half2 Parallax(half3 viewTangent, half height, half parallax, half bias)
{
return SafeDivide(viewTangent.xy, viewTangent.z + bias) * (height * parallax - parallax * 0.5);
}
inline half3 UnpackRawNormal(half4 rawNormal, half bumpiness)
{
half3 unpackedNormal;
#if defined(UNITY_NO_DXT5nm)
unpackedNormal = rawNormal.rgb * 2.0 - 1.0;
#else
rawNormal.r *= rawNormal.a;
unpackedNormal = half3(2.0 * rawNormal.a - 1.0, 2.0 * rawNormal.g - 1.0, 0.0);
#endif
unpackedNormal.xy *= bumpiness;
#if !defined(UNITY_NO_DXT5nm)
//unpackedNormal.z = sqrt(1.0 - dot(unpackedNormal.xy, unpackedNormal.xy));
unpackedNormal.z = 1.0 - 0.5 * dot(unpackedNormal.xy, unpackedNormal.xy); //approximation
#endif
return unpackedNormal;
}
inline half2 UnpackDudv(DECLARE_TEXTURE_2D_ARGS(dudvMap, samplerTex), float2 uv, float3 blendUV)
{
//somehow a range of [-1, 1] is not possible unless the texture is packed as a normal map
//therefore its encoded as a normal map and should also be imported as a normal map
//Normal map or Dudv map can be used
return UnpackRawNormal(SAMPLE_TEX2D_FLIPBOOK(dudvMap, samplerTex, uv, blendUV), 1).rg;
}
inline half3 UnpackNormalMap(DECLARE_TEXTURE_2D_ARGS(normalMap, samplerTex), float2 uv, float3 blendUV, half bumpiness)
{
half4 rawNormal = SAMPLE_TEX2D_FLIPBOOK(normalMap, samplerTex, uv, blendUV);
return UnpackRawNormal(rawNormal, bumpiness);
}
inline half3 UnpackNormalMap(DECLARE_TEXTURE_2D_ARGS(normalMap, samplerTex), float2 uv, half bumpiness)
{
half4 rawNormal = SampleTex2D(PASS_TEXTURE_2D(normalMap, samplerTex), uv);
return UnpackRawNormal(rawNormal, bumpiness);
}
inline half3 NormalMappingWorld(DECLARE_TEXTURE_2D_ARGS(normalMap, samplerTex), float2 uv, float3 blendUV, half bumpiness, half3x3 tbn)
{
return SafeNormalize(mul(UnpackNormalMap(PASS_TEXTURE_2D(normalMap, samplerTex), uv, blendUV, bumpiness), tbn));
}
inline half3 NormalMappingWorld(DECLARE_TEXTURE_2D_ARGS(normalMap, samplerTex), float2 uvMain, float3 blendUV, half bumpiness, DECLARE_TEXTURE_2D_ARGS(detailNormalMap, samplerTex2), float2 uvDetail, half bumpinessDetail, half3x3 tbn)
{
half3 normalTangent = UnpackNormalMap(PASS_TEXTURE_2D(normalMap, samplerTex), uvMain, blendUV, bumpiness);
half3 normalDetailTangent = UnpackNormalMap(PASS_TEXTURE_2D(detailNormalMap, samplerTex2), uvDetail, blendUV, bumpinessDetail);
return SafeNormalize(mul(SafeNormalize(half3(normalTangent.xy + normalDetailTangent.xy, lerp(normalTangent.z, normalDetailTangent.z, 0.5))), tbn));
}
//threshold based lighting type
inline half Cel(half threshold, half smoothnessMin, half smoothnessMax, half value)
{
#if SHADER_TARGET >= 35
half ddxy = fwidth(value);
return smoothstep(threshold - smoothnessMin - ddxy, threshold + smoothnessMax + ddxy, value);
#else
return smoothstep(threshold - smoothnessMin, threshold + smoothnessMax, value);
#endif
}
/*
inline half SmoothFloor(half v, half smoothness, half threshold)
{
threshold = 1.0 - threshold;
return ((cos(max((frac(v + threshold) - (1 - smoothness)) / smoothness, 0.5) * PI_TWO) + 1) * 0.5) + floor(v + threshold);
}
*/
//level based lighting type
inline half Banding(half v, half levels, half smoothnessMin, half smoothnessMax, half threshold, half fade)
{
/*
levels--;
half banding = v * lerp(1, 3, fade);
return saturate(SafeDivide(SmoothFloor(banding * levels, smoothnessMin + smoothnessMax, threshold), levels));
*/
levels--;
threshold = lerp(threshold, threshold * levels, fade);
half vl = v * lerp(1, levels, fade);
half levelStep = Rcp(levels);
half bands = Cel(threshold, smoothnessMin, smoothnessMax, vl);
bands += Cel(levelStep + threshold, smoothnessMin, smoothnessMax, vl);
bands += Cel(levelStep * 2 + threshold, smoothnessMin, smoothnessMax, vl) * step(3, levels);
bands += Cel(levelStep * 3 + threshold, smoothnessMin, smoothnessMax, vl) * step(4, levels);
bands += Cel(levelStep * 4 + threshold, smoothnessMin, smoothnessMax, vl) * step(5, levels);
bands += Cel(levelStep * 5 + threshold, smoothnessMin, smoothnessMax, vl) * step(6, levels);
return bands * levelStep;
//return lerp(bands, Cel(threshold, smoothnessMin, smoothnessMax, v), smoothnessMin + smoothnessMax); // * step(threshold, 0)
//return ceil(v * levels) / levels;
}
//Rampcolor when dissolving
inline half3 DissolveRamp(half dissolveValue, DECLARE_TEXTURE_2D_ARGS(dissolveBorderRampTex, samplerTex), half4 dissolveBorderColor, half dissolveBorderSize, half dissolveAmount, half2 uv, half3 baseCol)
{
half sv = dissolveBorderSize * dissolveAmount;
return lerp(baseCol, dissolveBorderColor.rgb * SampleTex2D(PASS_TEXTURE_2D(dissolveBorderRampTex, samplerTex), half2(dissolveValue * Rcp(sv), T_V)).rgb, dissolveBorderColor.a * step(dissolveValue, sv));
}
//Color when dissolving
inline half3 DissolveColor(half dissolveValue, half4 dissolveBorderColor, half dissolveBorderSize, half dissolveAmount, half3 baseCol)
{
return lerp(baseCol, dissolveBorderColor.rgb, dissolveBorderColor.a * step(dissolveValue, dissolveBorderSize * dissolveAmount));
}
//Contrast - Saturation - Brightness
inline half3 ColorGrading(half3 color, half brightness, half saturation, half contrast)
{
half3 bc = color * brightness;
half i = dot(bc, REL_LUMA);
#ifdef MK_FORWARD_ADD_PASS
color = lerp(half3(0.0, 0.0, 0.0), lerp(half3(i, i, i), bc, saturation), contrast);
#else
color = lerp(half3(0.5, 0.5, 0.5), lerp(half3(i, i, i), bc, saturation), contrast);
#endif
return color;
}
inline float NoiseSimple(float3 v)
{
return frac(sin( dot(v, REL_LUMA * 123456.54321)) * 987654.56789);
}
inline half Drawn(half value, half artistic, half artisticClampMin, half artisticClampMax)
{
//currently implemented as soft pattern, see repo for hard pattern prototype
#if SHADER_TARGET >= 35
half ddxy = fwidth(value);
return lerp(artisticClampMin, 1, value) * smoothstep(artistic - HALF_MIN - ddxy, artistic + ddxy, clamp(value, artisticClampMin, artisticClampMax));
//return lerp(artisticClampMin, 1, value) * smoothstep(artistic - T_H - ddxy, artistic, clamp(value, artisticClampMin, artisticClampMax));
#else
return lerp(artisticClampMin, 1, value) * smoothstep(artistic - HALF_MIN, artistic, clamp(value, artisticClampMin, artisticClampMax));
#endif
}
inline half Drawn(half value, half artistic, half artisticClampMax)
{
return Drawn(value, artistic, 0, artisticClampMax);
}
inline half Hatching(half3 dark, half3 bright, half value, half threshold)
{
//value of 0 = black, no strokes visible
half stepMax = clamp(value, threshold, 1.0h) * 6.0h;
half3 darkCoeff, brightCoeff;
#if SHADER_TARGET >= 35
half ddxy = fwidth(value);
darkCoeff = saturate(stepMax - half3(0, 1, 2) - ddxy); //half3(0, 1, 2)); 7 step
brightCoeff = saturate(stepMax - half3(3, 4, 5) - ddxy);
#else
darkCoeff = saturate(stepMax - half3(0, 1, 2)); //half3(0, 1, 2)); 7 step
brightCoeff = saturate(stepMax - half3(3, 4, 5));
#endif
//step wise coeff
darkCoeff.xy -= darkCoeff.yz;
darkCoeff.z -= brightCoeff.x;
brightCoeff.xy -= brightCoeff.yz;
//last step = 0 (7max)
//lerped coeff
//darkCoeff = lerp(darkCoeff, half3(darkCoeff.yz, brightCoeff.x), 0.5);
//brightCoeff = lerp(brightCoeff, half3(brightCoeff.yz, 0), 0.5);
half3 d = dark * darkCoeff;
half3 b = bright * brightCoeff;
return d.b + d.g + d.r + b.b + b.g + b.r + bright.r * max(0, value - 1.0);
}
inline half Sketch(half vMin, half vMax, half value)
{
#if SHADER_TARGET >= 35
half ddxy = fwidth(value);
return max(lerp(vMin - T_V - ddxy, vMax, value), 0);
#else
return max(lerp(vMin - T_V, vMax, value), 0);
#endif
}
inline half Sketch(half vMax, half value)
{
return lerp(0, vMax, value);
}
//Half Lambert - Valve
inline half HalfWrap(half value, half wrap)
{
return FastPow2(value * wrap + (1.0 - wrap));
}
inline half HalfWrap(half value)
{
return FastPow2(value * 0.5 + 0.5);
}
//Unity based HSV - RGB
inline half3 RGBToHSV(half3 c)
{
const half4 K = half4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
half4 p = lerp(half4(c.bg, K.wz), half4(c.gb, K.xy), step(c.b, c.g));
half4 q = lerp(half4(p.xyw, c.r), half4(c.r, p.yzx), step(p.x, c.r));
half d = q.x - min(q.w, q.y);
const half e = 1.0e-4;
return half3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
inline half3 HSVToRGB(half3 c)
{
const half4 K = half4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
half3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, saturate(p - K.xxx), c.y);
}
inline float3 VertexAnimationSine(float3 positionObject, half intensity, half3 frequency)
{
#ifdef MK_VERTEX_ANIMATION_STUTTER
positionObject += sin((positionObject.zxx + Stutter(_Time.y, frequency.zyx)) * frequency.zyx) * intensity;
#else
positionObject += sin((positionObject.zxx + _Time.y) * frequency.zyx) * intensity;
#endif
return positionObject;
}
inline float3 VertexAnimationPulse(float3 positionObject, half3 normalObject, half intensity, half3 frequency)
{
#ifdef MK_VERTEX_ANIMATION_STUTTER
//positionObject += SafeNormalizenormalObject * sin(Stutter(_Time.y, frequency.xyz) * frequency.xyz) * intensity;
float3 scaleAnimation = 1.0 + sin(Stutter(_Time.y, frequency.xyz) * frequency.xyz) * intensity;
float3x3 scale = float3x3
(
scaleAnimation.x, 0, 0,
0, scaleAnimation.y, 0,
0, 0, scaleAnimation.z
);
positionObject = mul(scale, positionObject.xyz);
#else
//positionObject += normalObject * sin((_Time.y) * frequency.xyz) * intensity;
float3 scaleAnimation = 1.0 + sin((_Time.y) * frequency.xyz) * intensity;
float3x3 scale = float3x3
(
scaleAnimation.x, 0, 0,
0, scaleAnimation.y, 0,
0, 0, scaleAnimation.z
);
positionObject = mul(scale, positionObject.xyz);
#endif
return positionObject;
}
inline float3 VertexAnimationNoise(float3 positionObject, half3 normalObject, half intensity, half3 frequency)
{
#ifdef MK_VERTEX_ANIMATION_STUTTER
positionObject += normalObject * sin(Stutter(NoiseSimple(positionObject) * _Time.y, frequency.xyz) * frequency.xyz) * intensity;
#else
positionObject += normalObject * sin((NoiseSimple(positionObject) * _Time.y) * frequency.xyz) * intensity;
#endif
return positionObject;
}
#if !defined(MK_VERTEX_ANIMATION_SINE)
#define PASS_VERTEX_ANIMATION_ARG(vertexAnimationMap, uv, intensity, frequency, positionObject, normalObject) vertexAnimationMap, uv, intensity, frequency, positionObject, normalObject
#else
#define PASS_VERTEX_ANIMATION_ARG(vertexAnimationMap, uv, intensity, frequency, positionObject, normalObject) vertexAnimationMap, uv, intensity, frequency, positionObject
#endif
inline float3 VertexAnimation
(
sampler2D vertexAnimationMap
, float2 uv
, half intensity
, float3 frequency
, float3 positionObject
#ifndef MK_VERTEX_ANIMATION_SINE
, half3 normalObject
#endif
)
{
#ifdef MK_VERTEX_ANIMATION_MAP
intensity *= tex2Dlod(vertexAnimationMap, float4(uv, 0, 0)).r;
#endif
#if defined(MK_VERTEX_ANIMATION_PULSE)
return VertexAnimationPulse(positionObject, normalObject, intensity, frequency);
#elif defined(MK_VERTEX_ANIMATION_NOISE)
return VertexAnimationNoise(positionObject, normalObject, intensity, frequency);
#else
return VertexAnimationSine(positionObject, intensity, frequency);
#endif
}
#endif

View File

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

View File

@ -0,0 +1,97 @@
//////////////////////////////////////////////////////
// MK Toon Composite //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_COMPOSITE
#define MK_TOON_COMPOSITE
#include "Core.hlsl"
#include "Surface.hlsl"
#include "Lighting.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// Composite Final Output
/////////////////////////////////////////////////////////////////////////////////////////////
inline void Composite(inout Surface surface, in MKSurfaceData surfaceData, in MKPBSData pbsData)
{
#ifdef MK_LIT
#ifdef MK_VERTEX_LIGHTING
surface.direct.rgb += surfaceData.vertexLighting * pbsData.diffuseRadiance;
#endif
#ifdef MK_OCCLUSION_MAP
surface.direct.rgb *= surface.occlusion.g;
#endif
#if defined(MK_FORWARD_BASE_PASS) && defined(MK_INDIRECT)
surface.final.rgb = surface.indirect + surface.direct.rgb;
#elif defined(MK_FORWARD_BASE_PASS) && !defined(MK_INDIRECT)
surface.final.rgb = surface.direct.rgb;
#elif defined(MK_FORWARD_ADD_PASS)
surface.final.rgb = surface.direct.rgb;
#else
surface.final.rgb = surface.albedo;
#endif
#ifdef MK_IRIDESCENCE_DEFAULT
surface.iridescence = Iridescence(_IridescenceSize, surfaceData.OneMinusVoN, _IridescenceSmoothness * 0.5, surface);
surface.final.rgb = lerp(surface.final.rgb, surface.iridescence.rgb, surface.iridescence.a * _IridescenceColor.a);
#endif
#if defined(MK_RIM_DEFAULT)
surface.rim = RimRawEverything(_RimSize, surfaceData.OneMinusVoN, _RimSmoothness * 0.5, surface);
surface.final.rgb = lerp(surface.final.rgb, _RimColor.rgb, surface.rim.rgb * _RimColor.a);
#elif defined(MK_RIM_SPLIT)
surface.rim = saturate(surface.rim);
#if defined(MK_FORWARD_BASE_PASS)
half4 rimDark = RimRawEverything(_RimSize, surfaceData.OneMinusVoN, _RimSmoothness * 0.5, surface);
rimDark -= surface.rim;
surface.final.rgb = lerp(surface.final.rgb, _RimDarkColor.rgb, rimDark.rgb * _RimDarkColor.a);
#endif
surface.final.rgb = lerp(surface.final.rgb, _RimBrightColor.rgb, surface.rim.rgb * _RimBrightColor.a);
//surface.final.rgb = lerp(surface.final.rgb, _RimBrightColor.rgb, surface.rimBright.rgb * _RimBrightColor.a);
//surface.final.rgb = lerp(surface.final.rgb, _RimDarkColor.rgb, surface.rimDark.rgb * _RimDarkColor.a);
#endif
/*
#if defined(MK_ALPHA_LOOKUP)
surface.direct.a = saturate(surface.direct.a);
#endif
surface.final.a = lerp(surface.goochDark.a, surface.goochBright.a, surface.direct.a);
#if defined(MK_ALPHA_CLIPPING)
Clip0(surface.final.a - _AlphaCutoff);
#endif
*/
surface.final.a = surface.alpha;
#else
//non lit color output
surface.final.rgb = surface.albedo;
surface.final.a = surface.alpha;
#endif
#if defined(MK_FORWARD_BASE_PASS) || defined(MK_UNIVERSAL2D_PASS)
#if defined(MK_DISSOLVE_BORDER_RAMP)
//apply color for dissolving
surface.final.rgb = DissolveRamp(surfaceData.dissolveClip, PASS_TEXTURE_2D(_DissolveBorderRamp, SAMPLER_REPEAT_MAIN), _DissolveBorderColor, _DissolveBorderSize, _DissolveAmount, surfaceData.baseUV.xy, surface.final.rgb);
#elif defined(MK_DISSOLVE_BORDER_COLOR)
surface.final.rgb = DissolveColor(surfaceData.dissolveClip, _DissolveBorderColor, _DissolveBorderSize, _DissolveAmount, surface.final.rgb);
#endif
#endif
#ifdef MK_COLOR_GRADING_FINAL_OUTPUT
surface.final.rgb = ColorGrading(surface.final.rgb, _Brightness, _Saturation, _Contrast);
#endif
#ifdef MK_FOG
ApplyFog(surface.final.rgb, surfaceData.fogFactor);
#endif
}
#endif

View File

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

View File

@ -0,0 +1,949 @@
//////////////////////////////////////////////////////
// MK Toon Config //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_DEFINES
#define MK_TOON_DEFINES
/////////////////////////////////////////////////////////////////////////////////////////////
// Custom User Config
/////////////////////////////////////////////////////////////////////////////////////////////
/*
//Enable vertex colors be combined with the albedo map
#ifndef MK_COMBINE_VERTEX_COLOR_WITH_ALBEDO_MAP
#define MK_COMBINE_VERTEX_COLOR_WITH_ALBEDO_MAP
#endif
*/
/*
//Enable outline distance based fading
//Also set compile directive on project window: MK_TOON_OUTLINE_FADE
#ifndef MK_OUTLINE_FADE
#define MK_OUTLINE_FADE
#endif
*/
/*
//Enable Point Filtering instead of Bilinear
//This can't be customized by the user in any other way, since sampler objects has to be are hardcoded
#ifndef MK_POINT_FILTERING
#define MK_POINT_FILTERING
#endif
*/
//Enable screen spaced dissolve instead of tangent spaced
/*
#ifndef MK_DISSOLVE_PROJECTION_SCREEN_SPACE
#define MK_DISSOLVE_PROJECTION_SCREEN_SPACE
#endif
*/
// ------------------------------------------------------------------------------------------
#if defined(MK_URP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#elif defined(MK_LWRP)
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl"
#else
#include "UnityCG.cginc"
#endif
// ------------------------------------------------------------------------------------------
// Note: Every define should have a "MK" prefix to avoid compile issues when using external funtions
// ------------------------------------------------------------------------------------------
// because of maximum of interpolators / graphics API operations some features are dependent of Shader Models
// Aniso Spec, Normal Mapping, Heightmapping, Vertex Animation Map are foreced to required SM30+
// Flipbook requires SM35+
// the following maps are skipped on < SM35: Depth => SoftFade, Occlusion, DetailNormal, Normal, DissolveBorder, Height, PBS1, Gooch Bright and Dark, Thickness
/////////////////////////////////////////////////////////////////////////////////////////////
// Basic setup
/////////////////////////////////////////////////////////////////////////////////////////////
//SRP's dont accept fixed variables, switched to half instead while defining pipeline
#if defined(MK_URP) || defined(MK_LWRP)
#ifndef autoLP
#define autoLP half
#endif
#ifndef autoLP2
#define autoLP2 half2
#endif
#ifndef autoLP3
#define autoLP3 half3
#endif
#ifndef autoLP4
#define autoLP4 half4
#endif
#else
#ifndef autoLP
#define autoLP fixed
#endif
#ifndef autoLP2
#define autoLP2 fixed2
#endif
#ifndef autoLP3
#define autoLP3 fixed3
#endif
#ifndef autoLP4
#define autoLP4 fixed4
#endif
#endif
//Just a safety thing, not supported on every device
#if defined(UNITY_COMPILER_HLSL) || defined(SHADER_API_PSSL) || defined(UNITY_COMPILER_HLSLCC)
#define INITIALIZE_STRUCT(type, name) name = (type)0;
#else
#define INITIALIZE_STRUCT(type, name)
#endif
#if defined(MK_PARTICLES)
#else //Standard
#ifndef MK_STANDARD
#define MK_STANDARD
#endif
#endif
#ifdef MK_LEGACY_RP
#ifndef MK_PARTICLES
//handle particles instancing on legacy rp
#include "UnityStandardParticleInstancing.cginc"
#endif
#endif
#if !defined(MK_PBS) && !defined(MK_SIMPLE) && !defined(MK_UNLIT)
#ifndef MK_UNLIT
#define MK_UNLIT
#endif
#endif
#if defined(MK_PBS) || defined(MK_SIMPLE)
#ifndef MK_LIT
#define MK_LIT
#endif
#endif
#ifdef MK_PBS
#if defined(_MK_WORKFLOW_SPECULAR)
#ifndef MK_WORKFLOW_SPECULAR
#define MK_WORKFLOW_SPECULAR
#endif
#elif defined(_MK_WORKFLOW_ROUGHNESS)
#ifndef MK_WORKFLOW_ROUGHNESS
#define MK_WORKFLOW_ROUGHNESS
#endif
#else
#ifndef MK_WORKFLOW_METALLIC
#define MK_WORKFLOW_METALLIC
#endif
#endif
#endif
#if defined(MK_WORKFLOW_METALLIC) || defined(MK_WORKFLOW_SPECULAR) || defined(MK_WORKFLOW_ROUGHNESS)
#ifndef MK_WORKFLOW_PBS
#define MK_WORKFLOW_PBS
#endif
#endif
#ifdef MK_WORKFLOW_PBS
#ifdef _MK_PBS_MAP_0
#ifndef MK_PBS_MAP_0
#define MK_PBS_MAP_0
#endif
#endif
#if defined(_MK_PBS_MAP_1) && SHADER_TARGET >= 35
#ifndef MK_PBS_MAP_1
#define MK_PBS_MAP_1
#endif
#endif
#else
#ifdef _MK_PBS_MAP_0
#ifndef MK_PBS_MAP_0
#define MK_PBS_MAP_0
#endif
#endif
#endif
#ifdef _MK_SURFACE_TYPE_TRANSPARENT
#ifndef MK_SURFACE_TYPE_TRANSPARENT
#define MK_SURFACE_TYPE_TRANSPARENT
#endif
#else
#ifndef MK_SURFACE_TYPE_OPAQUE
#define MK_SURFACE_TYPE_OPAQUE
#endif
#endif
#ifdef _MK_ALPHA_CLIPPING
#ifndef MK_ALPHA_CLIPPING
#define MK_ALPHA_CLIPPING
#endif
#endif
#if defined(MK_ALPHA_CLIPPING) || defined(MK_SURFACE_TYPE_TRANSPARENT)
#ifndef MK_ALPHA_LOOKUP
#define MK_ALPHA_LOOKUP
#endif
#endif
#if defined(_MK_FLIPBOOK) && SHADER_TARGET >= 35
//flipbook can only be used if > 10 interpolators are available
#ifndef MK_FLIPBOOK
#define MK_FLIPBOOK
#endif
#endif
#ifdef MK_SURFACE_TYPE_TRANSPARENT
#if defined(_MK_BLEND_PREMULTIPLY)
#ifndef MK_BLEND_PREMULTIPLY
#define MK_BLEND_PREMULTIPLY
#endif
// Premul and additive results in the same keyword but different blend => premul
#elif defined(_MK_BLEND_ADDITIVE)
#ifndef MK_BLEND_ADDITIVE
#define MK_BLEND_ADDITIVE
#endif
#elif defined(_MK_BLEND_MULTIPLY)
#ifndef MK_BLEND_MULTIPLY
#define MK_BLEND_MULTIPLY
#endif
#else
#ifndef MK_BLEND_ALPHA
#define MK_BLEND_ALPHA
#endif
#endif
#ifdef MK_PARTICLES
#if defined(_MK_COLOR_BLEND_ADDITIVE)
#ifndef MK_COLOR_BLEND_ADDITIVE
#define MK_COLOR_BLEND_ADDITIVE
#endif
#elif defined(_MK_COLOR_BLEND_SUBTRACTIVE)
#ifndef MK_COLOR_BLEND_SUBTRACTIVE
#define MK_COLOR_BLEND_SUBTRACTIVE
#endif
#elif defined(_MK_COLOR_BLEND_OVERLAY)
#ifndef MK_COLOR_BLEND_OVERLAY
#define MK_COLOR_BLEND_OVERLAY
#endif
#elif defined(_MK_COLOR_BLEND_COLOR)
#ifndef MK_COLOR_BLEND_COLOR
#define MK_COLOR_BLEND_COLOR
#endif
#elif defined(_MK_COLOR_BLEND_DIFFERENCE)
#ifndef MK_COLOR_BLEND_DIFFERENCE
#define MK_COLOR_BLEND_DIFFERENCE
#endif
#else
#ifndef MK_COLOR_BLEND_MULTIPLY
#define MK_COLOR_BLEND_MULTIPLY
#endif
#endif
#endif
#if defined(MK_COLOR_BLEND_ADDITIVE) || defined(MK_COLOR_BLEND_SUBTRACTIVE) || defined(MK_COLOR_BLEND_OVERLAY) || defined(MK_COLOR_BLEND_COLOR) || defined(MK_COLOR_BLEND_DIFFERENCE) || defined(MK_COLOR_BLEND_MULTIPLY)
#ifndef MK_COLOR
#define MK_COLOR
#endif
#endif
#if defined(_MK_SOFT_FADE) && SHADER_TARGET >= 35
#ifndef MK_SOFT_FADE
#define MK_SOFT_FADE
#endif
#endif
#ifdef _MK_CAMERA_FADE
#ifndef MK_CAMERA_FADE
#define MK_CAMERA_FADE
#endif
#endif
#endif
#ifdef _MK_ALBEDO_MAP
#ifndef MK_ALBEDO_MAP
#define MK_ALBEDO_MAP
#endif
#endif
#ifdef _MK_DETAIL_MAP
#ifndef MK_DETAIL_MAP
#define MK_DETAIL_MAP
#endif
#endif
#ifdef MK_DETAIL_MAP
#if defined(_MK_DETAIL_BLEND_MIX)
#ifndef MK_DETAIL_BLEND_MIX
#define MK_DETAIL_BLEND_MIX
#endif
#elif defined(_MK_DETAIL_BLEND_ADD)
#ifndef MK_DETAIL_BLEND_ADD
#define MK_DETAIL_BLEND_ADD
#endif
#else
#ifndef MK_DETAIL_BLEND_MULTIPLY
#define MK_DETAIL_BLEND_MULTIPLY
#endif
#endif
#endif
#if defined(_MK_DETAIL_NORMAL_MAP) && SHADER_TARGET >= 35
#ifndef MK_DETAIL_NORMAL_MAP
#define MK_DETAIL_NORMAL_MAP
#endif
#endif
#if defined(MK_ALBEDO_MAP)
#ifndef MK_TEXCLR
#define MK_TEXCLR
#endif
#else
#ifndef MK_VERTCLR
#define MK_VERTCLR
#endif
#endif
#ifdef MK_COMBINE_VERTEX_COLOR_WITH_ALBEDO_MAP
#ifndef MK_VERTCLR
#define MK_VERTCLR
#endif
#endif
#ifdef MK_LIT
#ifdef _MK_RECEIVE_SHADOWS
#ifndef MK_RECEIVE_SHADOWS
#define MK_RECEIVE_SHADOWS
#endif
#endif
#ifdef _MK_THRESHOLD_MAP
#ifndef MK_THRESHOLD_MAP
#define MK_THRESHOLD_MAP
#endif
#endif
#ifdef MK_FORWARD_BASE_PASS
#if defined(MK_URP) && defined(_ADDITIONAL_LIGHTS_VERTEX) || defined(MK_LWRP) && defined(_ADDITIONAL_LIGHTS_VERTEX) || defined(MK_LEGACY_RP) && defined(VERTEXLIGHT_ON)
#ifndef MK_VERTEX_LIGHTING
#define MK_VERTEX_LIGHTING
#endif
#endif
#endif
#if defined(_MK_NORMAL_MAP) && SHADER_TARGET >= 35
#ifndef MK_NORMAL_MAP
#define MK_NORMAL_MAP
#endif
#endif
#ifdef _MK_LIGHT_TRANSMISSION_TRANSLUCENT
#ifndef MK_LIGHT_TRANSMISSION_TRANSLUCENT
#define MK_LIGHT_TRANSMISSION_TRANSLUCENT
#endif
#endif
#ifdef _MK_LIGHT_TRANSMISSION_SUB_SURFACE_SCATTERING
#ifndef MK_LIGHT_TRANSMISSION_SUB_SURFACE_SCATTERING
#define MK_LIGHT_TRANSMISSION_SUB_SURFACE_SCATTERING
#endif
#endif
#if defined(_MK_THICKNESS_MAP) && SHADER_TARGET >= 35
#ifndef MK_THICKNESS_MAP
#define MK_THICKNESS_MAP
#endif
#endif
#if defined(MK_LIGHT_TRANSMISSION_TRANSLUCENT) || defined(MK_LIGHT_TRANSMISSION_SUB_SURFACE_SCATTERING)
#ifndef MK_LightTransmission
#define MK_LightTransmission
#endif
#endif
#if defined(_MK_HEIGHT_MAP) && SHADER_TARGET >= 35
#ifndef MK_HEIGHT_MAP
#define MK_HEIGHT_MAP
#endif
#endif
#if defined(_MK_OCCLUSION_MAP) && SHADER_TARGET >= 35
#ifndef MK_OCCLUSION_MAP
#define MK_OCCLUSION_MAP
#endif
#endif
#if defined(_MK_LIGHT_CEL)
#ifndef MK_LIGHT_CEL
#define MK_LIGHT_CEL
#endif
#elif defined(_MK_LIGHT_BANDED)
#ifndef MK_LIGHT_BANDED
#define MK_LIGHT_BANDED
#endif
#elif defined(_MK_LIGHT_RAMP)
#ifndef MK_LIGHT_RAMP
#define MK_LIGHT_RAMP
#endif
#else
#ifndef MK_LIGHT_BUILTIN
#define MK_LIGHT_BUILTIN
#endif
#endif
#if defined(_MK_ARTISTIC_DRAWN)
#ifndef MK_ARTISTIC_DRAWN
#define MK_ARTISTIC_DRAWN
#endif
#elif defined(_MK_ARTISTIC_HATCHING)
#ifndef MK_ARTISTIC_HATCHING
#define MK_ARTISTIC_HATCHING
#endif
#elif defined(_MK_ARTISTIC_SKETCH)
#ifndef MK_ARTISTIC_SKETCH
#define MK_ARTISTIC_SKETCH
#endif
#else
#ifndef MK_ARTISTIC_OFF
#define MK_ARTISTIC_OFF
#endif
#endif
#if defined(_MK_ARTISTIC_DRAWN) || defined(MK_ARTISTIC_HATCHING) || defined(MK_ARTISTIC_SKETCH)
#ifndef MK_ARTISTIC
#define MK_ARTISTIC
#endif
#endif
#if defined(MK_ARTISTIC)
#if defined(_MK_ARTISTIC_PROJECTION_SCREEN_SPACE)
#ifndef MK_ARTISTIC_PROJECTION_SCREEN_SPACE
#define MK_ARTISTIC_PROJECTION_SCREEN_SPACE
#endif
#else
#ifndef MK_ARTISTIC_PROJECTION_TANGENT_SPACE
#define MK_ARTISTIC_PROJECTION_TANGENT_SPACE
#endif
#endif
#if defined(_MK_ARTISTIC_ANIMATION_STUTTER)
#ifndef MK_ARTISTIC_ANIMATION_STUTTER
#define MK_ARTISTIC_ANIMATION_STUTTER
#endif
#endif
#endif
#if defined(_MK_GOOCH_RAMP)
#ifndef MK_GOOCH_RAMP
#define MK_GOOCH_RAMP
#endif
#endif
#if defined(_MK_GOOCH_BRIGHT_MAP) && SHADER_TARGET >= 35
#ifndef MK_GOOCH_BRIGHT_MAP
#define MK_GOOCH_BRIGHT_MAP
#endif
#endif
#if defined(_MK_GOOCH_DARK_MAP) && SHADER_TARGET >= 35
#ifndef MK_GOOCH_DARK_MAP
#define MK_GOOCH_DARK_MAP
#endif
#endif
#if defined(MK_GOOCH_BRIGHT_MAP) && defined(MK_GOOCH_DARK_MAP)
#ifndef MK_GOOCH_BRIGHT_AND_DARK_MAP
#define MK_GOOCH_BRIGHT_AND_DARK_MAP
#endif
#endif
#if defined(MK_GOOCH_BRIGHT_MAP) || defined(MK_GOOCH_DARK_MAP) || defined(MK_GOOCH_BRIGHT_AND_DARK_MAP)
#ifndef MK_GOOCH_MAP
#define MK_GOOCH_MAP
#endif
#endif
#if defined(MK_FORWARD_BASE_PASS)
#if defined(_MK_RIM_DEFAULT)
#ifndef MK_RIM_DEFAULT
#define MK_RIM_DEFAULT
#endif
#elif defined(_MK_RIM_SPLIT)
#ifndef MK_RIM_SPLIT
#define MK_RIM_SPLIT
#endif
#endif
#endif
#if defined(MK_RIM_DEFAULT) || defined(MK_RIM_SPLIT)
#ifndef MK_RIM
#define MK_RIM
#endif
#endif
#if defined(MK_FORWARD_BASE_PASS)
#ifdef _MK_IRIDESCENCE_DEFAULT
#ifndef MK_IRIDESCENCE_DEFAULT
#define MK_IRIDESCENCE_DEFAULT
#endif
#endif
#ifdef MK_IRIDESCENCE_DEFAULT
#ifndef MK_IRIDESCENCE
#define MK_IRIDESCENCE
#endif
#endif
#endif
#if (defined(MK_META_PASS) || defined(MK_FORWARD_BASE_PASS))
#ifdef _MK_EMISSION
#ifndef MK_EMISSION
#define MK_EMISSION
#endif
#endif
#ifdef _MK_EMISSION_MAP
#ifndef MK_EMISSION_MAP
#define MK_EMISSION_MAP
#endif
#endif
#endif
#if defined(_MK_DIFFUSE_OREN_NAYAR)
#ifndef MK_DIFFUSE_OREN_NAYAR
#define MK_DIFFUSE_OREN_NAYAR
#endif
#elif defined(_MK_DIFFUSE_MINNAERT)
#ifndef MK_DIFFUSE_MINNAERT
#define MK_DIFFUSE_MINNAERT
#endif
#else
#ifndef MK_DIFFUSE_LAMBERT
#define MK_DIFFUSE_LAMBERT
#endif
#endif
#if defined(_MK_WRAPPED_DIFFUSE)
#ifndef MK_WRAPPED_DIFFUSE
#define MK_WRAPPED_DIFFUSE
#endif
#endif
#if defined(_MK_SPECULAR_ISOTROPIC)
#ifndef MK_SPECULAR_ISOTROPIC
#define MK_SPECULAR_ISOTROPIC
#endif
#elif defined(_MK_SPECULAR_ANISOTROPIC) && SHADER_TARGET >= 30
#ifndef MK_SPECULAR_ANISOTROPIC
#define MK_SPECULAR_ANISOTROPIC
#endif
#endif
#if defined(MK_SPECULAR_ISOTROPIC) || defined(MK_SPECULAR_ANISOTROPIC)
#ifndef MK_SPECULAR
#define MK_SPECULAR
#endif
#endif
#if defined(MK_FORWARD_BASE_PASS)
#if defined(_MK_ENVIRONMENT_REFLECTIONS_ADVANCED)
#ifndef MK_ENVIRONMENT_REFLECTIONS_ADVANCED
#define MK_ENVIRONMENT_REFLECTIONS_ADVANCED
#endif
#elif defined(_MK_ENVIRONMENT_REFLECTIONS_AMBIENT)
#ifndef MK_ENVIRONMENT_REFLECTIONS_AMBIENT
#define MK_ENVIRONMENT_REFLECTIONS_AMBIENT
#endif
#else
#ifndef MK_ENVIRONMENT_REFLECTIONS_OFF
#define MK_ENVIRONMENT_REFLECTIONS_OFF
#endif
#endif
#if defined(MK_ENVIRONMENT_REFLECTIONS_ADVANCED) || defined(MK_ENVIRONMENT_REFLECTIONS_AMBIENT)
#ifndef MK_ENVIRONMENT_REFLECTIONS
#define MK_ENVIRONMENT_REFLECTIONS
#endif
#endif
#endif
#if defined(MK_FORWARD_BASE_PASS) && defined(MK_ENVIRONMENT_REFLECTIONS)
#ifdef _MK_FRESNEL_HIGHLIGHTS
#ifndef MK_FRESNEL_HIGHLIGHTS
#define MK_FRESNEL_HIGHLIGHTS
#endif
#endif
#endif
#if defined(MK_ENVIRONMENT_REFLECTIONS) || defined(MK_EMISSION) || defined(MK_FRESNEL_HIGHLIGHTS)
#ifndef MK_INDIRECT
#define MK_INDIRECT
#endif
#endif
#endif
#if defined(_MK_COLOR_GRADING_ALBEDO)
#ifndef MK_COLOR_GRADING_ALBEDO
#define MK_COLOR_GRADING_ALBEDO
#endif
#elif defined(_MK_COLOR_GRADING_FINAL_OUTPUT)
#ifndef MK_COLOR_GRADING_FINAL_OUTPUT
#define MK_COLOR_GRADING_FINAL_OUTPUT
#endif
#endif
#if defined(MK_COLOR_GRADING_ALBEDO) || defined(MK_COLOR_GRADING_FINAL_OUTPUT)
#ifndef MK_COLOR_GRADING
#define MK_COLOR_GRADING
#endif
#endif
#if defined(_MK_VERTEX_ANIMATION_SINE)
#ifndef MK_VERTEX_ANIMATION_SINE
#define MK_VERTEX_ANIMATION_SINE
#endif
#elif defined(_MK_VERTEX_ANIMATION_PULSE)
#ifndef MK_VERTEX_ANIMATION_PULSE
#define MK_VERTEX_ANIMATION_PULSE
#endif
#elif defined(_MK_VERTEX_ANIMATION_NOISE)
#ifndef MK_VERTEX_ANIMATION_NOISE
#define MK_VERTEX_ANIMATION_NOISE
#endif
#endif
#if defined(MK_VERTEX_ANIMATION_SINE) || defined(MK_VERTEX_ANIMATION_PULSE) || defined(MK_VERTEX_ANIMATION_NOISE)
#ifndef MK_VERTEX_ANIMATION
#define MK_VERTEX_ANIMATION
#endif
#endif
#if defined(MK_VERTEX_ANIMATION)
#if defined(_MK_VERTEX_ANIMATION_MAP) && SHADER_TARGET >= 30
#ifndef MK_VERTEX_ANIMATION_MAP
#define MK_VERTEX_ANIMATION_MAP
#endif
#endif
#if defined(_MK_VERTEX_ANIMATION_STUTTER)
#ifndef MK_VERTEX_ANIMATION_STUTTER
#define MK_VERTEX_ANIMATION_STUTTER
#endif
#endif
#if defined(MK_VERTEX_ANIMATION_MAP)
#define PASS_VERTEX_ANIMATION_UV(uv) uv
#else
#define PASS_VERTEX_ANIMATION_UV(uv) 0
#endif
#endif
#if defined(_MK_DISSOLVE_DEFAULT)
#ifndef MK_DISSOLVE_DEFAULT
#define MK_DISSOLVE_DEFAULT
#endif
#elif defined(_MK_DISSOLVE_BORDER_COLOR)
#ifndef MK_DISSOLVE_BORDER_COLOR
#define MK_DISSOLVE_BORDER_COLOR
#endif
#elif defined(_MK_DISSOLVE_BORDER_RAMP) && SHADER_TARGET >= 35
#ifndef MK_DISSOLVE_BORDER_RAMP
#define MK_DISSOLVE_BORDER_RAMP
#endif
#endif
#if defined(MK_DISSOLVE_DEFAULT) || defined(MK_DISSOLVE_BORDER_COLOR) || defined(MK_DISSOLVE_BORDER_RAMP)
#ifndef MK_DISSOLVE
#define MK_DISSOLVE
#endif
#endif
#ifdef MK_OUTLINE_PASS
#if defined(_MK_OUTLINE_HULL_ORIGIN)
#ifndef MK_OUTLINE_HULL_ORIGIN
#define MK_OUTLINE_HULL_ORIGIN
#endif
#elif defined(_MK_OUTLINE_HULL_CLIP)
#ifndef MK_OUTLINE_HULL_CLIP
#define MK_OUTLINE_HULL_CLIP
#endif
#else
#ifndef MK_OUTLINE_HULL_OBJECT
#define MK_OUTLINE_HULL_OBJECT
#endif
#endif
#if defined(_MK_OUTLINE_DATA_UV7)
#ifndef MK_OUTLINE_DATA_UV7
#define MK_OUTLINE_DATA_UV7
#endif
#else
#ifndef MK_OUTLINE_DATA_NORMAL
#define MK_OUTLINE_DATA_NORMAL
#endif
#endif
#if defined(_MK_OUTLINE_NOISE)
#ifndef MK_OUTLINE_NOISE
#define MK_OUTLINE_NOISE
#endif
#else
#ifndef MK_OUTLINE_NOISE_OFF
#define MK_OUTLINE_NOISE_OFF
#endif
#endif
#if defined(_MK_OUTLINE_MAP)
#ifndef MK_OUTLINE_MAP
#define MK_OUTLINE_MAP
#endif
#endif
#endif
#ifdef MK_REFRACTION
#ifdef _MK_REFRACTION_DISTORTION_MAP
#ifndef MK_REFRACTION_DISTORTION_MAP
#define MK_REFRACTION_DISTORTION_MAP
#endif
#endif
#ifdef _MK_INDEX_OF_REFRACTION
#ifndef MK_INDEX_OF_REFRACTION
#define MK_INDEX_OF_REFRACTION
#endif
#endif
#endif
#if defined(MK_LIT) || defined(MK_INDEX_OF_REFRACTION) || defined(MK_VERTEX_ANIMATION_PULSE) || defined(MK_VERTEX_ANIMATION_NOISE)
#ifndef MK_NORMAL
#define MK_NORMAL
#endif
#endif
/////////////////////////////////////////////////////////////////////////////////////////////
// Constants
/////////////////////////////////////////////////////////////////////////////////////////////
#ifndef OUTLINE_OBJECT_SCALE
#define OUTLINE_OBJECT_SCALE 0.00000025
#endif
#ifndef OUTLINE_ORIGIN_SCALE
#define OUTLINE_ORIGIN_SCALE 0.0015
#endif
#ifndef K_SPEC_DIELECTRIC_MIN
#define K_SPEC_DIELECTRIC_MIN 0.04
#endif
#ifndef K_SPEC_DIELECTRIC_MAX
#define K_SPEC_DIELECTRIC_MAX 0.96
#endif
#ifndef HALF_MIN
#define HALF_MIN 6.10e-5
#endif
#ifndef ONE_MINUS_HALF_MIN
#define ONE_MINUS_HALF_MIN 0.999939
#endif
#ifndef T_Q
#define T_Q 0.125
#endif
#ifndef T_H
#define T_H 0.25
#endif
#ifndef T_V
#define T_V 0.5
#endif
#ifndef THRESHOLD_OFFSET_NORMALIZER
#define THRESHOLD_OFFSET_NORMALIZER 0.125
#endif
/*
#ifndef SHINE_MULT
//approximately URP smoothness base
#define SHINE_MULT 1024
#endif
*/
#ifndef PI
#define PI 3.141592
#endif
#ifndef PI_TWO
#define PI_TWO 6.283185
#endif
#ifndef PI_H
#define PI_H 1.570796
#endif
#ifndef PI_P2
#define PI_P2 9.869604
#endif
#ifndef INV_PI
#define INV_PI 0.318309
#endif
#ifndef REL_LUMA
#define REL_LUMA half3(0.2126,0.7152,0.0722)
#endif
#ifndef REFRACTION_DISTORTION_SCALE
#define REFRACTION_DISTORTION_SCALE 0.1
#endif
#ifndef HALF3_ONE
#define HALF3_ONE half3(1.0h, 1.0h, 1.0h)
#endif
#ifndef REFERENCE_RESOLUTION
#define REFERENCE_RESOLUTION half2(3840, 2160)
#endif
#ifndef REFERENCE_ASPECT
#define REFERENCE_ASPECT half2(1.777778, 0.5625)
#endif
/////////////////////////////////////////////////////////////////////////////////////////////
// Input dependent defines
/////////////////////////////////////////////////////////////////////////////////////////////
#if defined(MK_POLYBRUSH) || defined(MK_OUTLINE_MAP) || defined(MK_VERTEX_ANIMATION_MAP) || defined(MK_THRESHOLD_MAP) || defined(MK_PARTICLES) || defined(MK_ALBEDO_MAP) || defined(MK_DISSOLVE) || defined(MK_GOOCH_MAP) || defined(MK_LightTransmission) || defined(MK_NORMAL_MAP) || defined(MK_DETAIL_NORMAL_MAP) || defined(MK_EMISSION_MAP) || defined(MK_OCCLUSION_MAP) || defined(MK_ARTISTIC_HATCHING) || defined(MK_ARTISTIC_DRAWN) || defined(MK_ARTISTIC_SKETCH) || defined(MK_REFRACTION_DISTORTION_MAP)
#ifndef MK_TCM
#define MK_TCM
#endif
#endif
#if defined(MK_DETAIL_MAP) || defined(MK_DETAIL_NORMAL_MAP)
#ifndef MK_TCD
#define MK_TCD
#endif
#endif
#if defined(MK_LIT) && (defined(MK_TCM) || defined(MK_TCD)) && defined(MK_HEIGHT_MAP) && defined(_MK_PARALLAX) && SHADER_TARGET >= 30
#ifndef MK_PARALLAX
#define MK_PARALLAX
#endif
#endif
#if defined(MK_PARALLAX)
#ifndef MK_VD_O
#define MK_VD_O
#endif
#endif
#if defined(MK_NORMAL_MAP) || defined(MK_DETAIL_NORMAL_MAP) || defined(MK_VD_O) || defined(MK_SPECULAR_ANISOTROPIC)
#ifndef MK_TBN
#define MK_TBN
#endif
#else
#ifndef MK_WN
#define MK_WN
#endif
#endif
#if defined(MK_REFRACTION) || defined(MK_IRIDESCENCE) || defined(MK_LightTransmission) || defined(MK_RIM) || defined(MK_SPECULAR) || defined(LIGHTMAP_ON) || defined(UNITY_SHOULD_SAMPLE_SH) || defined(DYNAMICLIGHTMAP_ON) || defined(DIRLIGHTMAP_COMBINED) || defined(MK_RIM) || defined(MK_ENVIRONMENT_REFLECTIONS_ADVANCED) || defined(MK_FRESNEL_HIGHLIGHTS) || defined(MK_DIFFUSE_MINNAERT) || defined(MK_DIFFUSE_OREN_NAYAR)
#ifndef MK_VD
#define MK_VD
#endif
#endif
#if defined(MK_ARTISTIC) && defined(MK_ARTISTIC_PROJECTION_SCREEN_SPACE) || defined(MK_DISSOLVE_PROJECTION_SCREEN_SPACE)
#ifndef MK_NORMALIZED_SCREEN_UV
#define MK_NORMALIZED_SCREEN_UV
#endif
#endif
#if defined(MK_REFRACTION) || defined(MK_SOFT_FADE) || defined(MK_CAMERA_FADE) || defined(MK_NORMALIZED_SCREEN_UV)
#ifndef MK_SCREEN_UV
#define MK_SCREEN_UV
#endif
#endif
#if defined(MK_NORMALIZED_SCREEN_UV)
#ifndef MK_POS_NULL_CLIP
#define MK_POS_NULL_CLIP
#endif
#endif
#if defined(MK_POS_NULL_CLIP) || defined(MK_REFRACTION) || defined(MK_SOFT_FADE) || defined(MK_CAMERA_FADE)
#ifndef MK_POS_CLIP
#define MK_POS_CLIP
#endif
#endif
#ifdef MK_LIT
#ifndef MK_N_DOT_L
#define MK_N_DOT_L
#endif
#endif
#if defined(MK_IRIDESCENCE) || defined(MK_FRESNEL_HIGHLIGHTS) || defined(MK_SPECULAR) || defined(MK_DIFFUSE_MINNAERT) || defined(MK_DIFFUSE_OREN_NAYAR) || defined(MK_RIM)
#ifndef MK_V_DOT_N
#define MK_V_DOT_N
#endif
#endif
#ifdef MK_DIFFUSE_OREN_NAYAR
#ifndef MK_V_DOT_L
#define MK_V_DOT_L
#endif
#endif
#if defined(MK_SPECULAR)
#ifdef MK_SPECULAR_ANISOTROPIC
#ifndef MK_T_DOT_HV
#define MK_T_DOT_HV
#endif
#ifndef MK_B_DOT_HV
#define MK_B_DOT_HV
#endif
#endif
#ifndef MK_HV
#define MK_HV
#endif
#ifndef MK_N_DOT_HV
#define MK_N_DOT_HV
#endif
//used for C.Sch Fresnel, if switched back to Schlick this should be disabled
#ifndef MK_L_DOT_HV
#define MK_L_DOT_HV
#endif
/*
//used for Schlick Fresnel
#ifndef MK_V_DOT_HV
#define MK_V_DOT_HV
#endif
*/
#endif
#ifdef MK_LightTransmission
#ifndef MK_LND
#define MK_LND
#endif
#ifndef MK_V_DOT_LND
#define MK_V_DOT_LND
#endif
#endif
/*
#ifdef MK_LIGHTMODEL_PHONG
#ifndef MK_ML_REF_N
#define MK_ML_REF_N
#endif
#endif
*/
#ifdef MK_ENVIRONMENT_REFLECTIONS_ADVANCED
#ifndef MK_MV_REF_N
#define MK_MV_REF_N
#endif
#endif
/*
#if defined(MK_TLD) || defined(MK_TLM)
#ifndef MK_ML_DOT_V
#define MK_ML_DOT_V
#endif
#endif
*/
/*
#ifdef MK_LIGHTMODEL_PHONG
#ifndef MK_ML_REF_N_DOT_V
#define MK_ML_REF_N_DOT_V
#endif
#endif
*/
#if defined(MK_TBN) || defined(MK_FLIPBOOK) || defined(MK_TCM) || defined(MK_TCD) || defined(MK_T_DOT_HV) || defined(MK_B_DOT_HV) || defined(MK_WORKFLOW_PBS) || defined(MK_ML_REF_N_DOT_V) || defined(MK_ML_DOT_V) || defined(MK_MV_REF_N) || defined(MK_ML_REF_N) || defined(MK_N_DOT_HV) || defined(MK_HV) || defined(MK_N_DOT_L) || defined(MK_V_DOT_L) || defined(MK_V_DOT_N) || defined(MK_LIT) || defined(MK_DISSOLVE) || defined(MK_REFRACTION)
#ifndef MK_SURFACE_DATA_REQUIRED
#define MK_SURFACE_DATA_REQUIRED
#endif
#endif
#if defined(MK_LIT) || defined(MK_VD)
#ifndef MK_POS_WORLD
#define MK_POS_WORLD
#endif
#endif
#if defined(MK_FORWARD_BASE_PASS) || defined(MK_OUTLINE_PASS)
#ifndef MK_FOG
#define MK_FOG
#endif
#endif
#endif

View File

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

View File

@ -0,0 +1,25 @@
//////////////////////////////////////////////////////
// MK Toon Core //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_CORE
#define MK_TOON_CORE
#if defined(MK_URP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#elif defined(MK_LWRP)
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl"
#else
#include "UnityCG.cginc"
#endif
#include "Config.hlsl"
#include "Pipeline.hlsl"
#include "Uniform.hlsl"
#include "Common.hlsl"
#endif

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c018d10d88d3b744ab93891451aa468b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,56 @@
//////////////////////////////////////////////////////
// MK Toon DepthOnly Data //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_DEPTH_ONLY_IO
#define MK_TOON_DEPTH_ONLY_IO
#include "../Core.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// INPUT
/////////////////////////////////////////////////////////////////////////////////////////////
struct VertexInputDepthOnly
{
float4 vertex : POSITION;
#if defined(MK_VERTEX_ANIMATION_PULSE) || defined(MK_VERTEX_ANIMATION_NOISE) || defined(MK_PARALLAX)
half3 normal : NORMAL;
#endif
#if defined(MK_VERTCLR) || defined(MK_POLYBRUSH)
autoLP4 color : COLOR0;
#endif
#ifdef MK_TCM
float2 texcoord0 : TEXCOORD0;
#endif
#if defined(MK_PARALLAX)
half4 tangent : TANGENT;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
/////////////////////////////////////////////////////////////////////////////////////////////
// OUTPUT
/////////////////////////////////////////////////////////////////////////////////////////////
struct VertexOutputDepthOnly
{
float4 svPositionClip : SV_POSITION;
#if defined(MK_VERTCLR) || defined(MK_POLYBRUSH)
autoLP4 color : COLOR0;
#endif
#ifdef MK_TCM
float2 uv : TEXCOORD0;
#endif
#if defined(MK_PARALLAX)
half3 viewTangent : TEXCOORD1;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
#endif

View File

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

View File

@ -0,0 +1,77 @@
//////////////////////////////////////////////////////
// MK Toon Depth Only Program //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_DEPTH_ONLY
#define MK_TOON_DEPTH_ONLY
#include "../Core.hlsl"
#include "Data.hlsl"
#include "../Surface.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// VERTEX SHADER
/////////////////////////////////////////////////////////////////////////////////////////////
VertexOutputDepthOnly DepthOnlyVert(VertexInputDepthOnly vertexInput)
{
UNITY_SETUP_INSTANCE_ID(vertexInput);
VertexOutputDepthOnly vertexOutput;
INITIALIZE_STRUCT(VertexOutputDepthOnly, vertexOutput);
UNITY_TRANSFER_INSTANCE_ID(vertexInput, vertexOutput);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(vertexOutput);
#ifdef MK_VERTEX_ANIMATION
vertexInput.vertex.xyz = VertexAnimation(PASS_VERTEX_ANIMATION_ARG(_VertexAnimationMap, PASS_VERTEX_ANIMATION_UV(vertexInput.texcoord0.xy), _VertexAnimationIntensity, _VertexAnimationFrequency.xyz, vertexInput.vertex.xyz, vertexInput.normal));
#endif
vertexOutput.svPositionClip = mul(MATRIX_MVP, float4(vertexInput.vertex.xyz, 1.0));
#if defined(MK_VERTCLR) || defined(MK_POLYBRUSH)
vertexOutput.color = vertexInput.color;
#endif
//texcoords
#if defined(MK_TCM)
vertexOutput.uv = vertexInput.texcoord0.xy;
#endif
#if defined(MK_PARALLAX)
vertexOutput.viewTangent = ComputeViewTangent(ComputeViewObject(vertexInput.vertex.xyz), vertexInput.normal, vertexInput.tangent, cross(vertexInput.normal, vertexInput.tangent.xyz) * vertexInput.tangent.w * unity_WorldTransformParams.w);
#endif
return vertexOutput;
}
/////////////////////////////////////////////////////////////////////////////////////////////
// FRAGMENT SHADER
/////////////////////////////////////////////////////////////////////////////////////////////
half4 DepthOnlyFrag(VertexOutputDepthOnly vertexOutput) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(vertexOutput);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(vertexOutput);
MKSurfaceData surfaceData = ComputeSurfaceData
(
PASS_POSITION_WORLD_ARG(0)
PASS_FOG_FACTOR_WORLD_ARG(0)
PASS_BASE_UV_ARG(float4(vertexOutput.uv, 0, 0))
PASS_LIGHTMAP_UV_ARG(0)
PASS_VERTEX_COLOR_ARG(vertexOutput.color)
PASS_NORMAL_WORLD_ARG(1)
PASS_VERTEX_LIGHTING_ARG(0)
PASS_TANGENT_WORLD_ARG(1)
PASS_VIEW_TANGENT_ARG(vertexOutput.viewTangent)
PASS_BITANGENT_WORLD_ARG(1)
PASS_POSITION_CLIP_ARG(0)
PASS_NULL_CLIP_ARG(0)
PASS_FLIPBOOK_UV_ARG(0)
);
Surface surface = InitSurface(surfaceData, PASS_TEXTURE_2D(_AlbedoMap, SAMPLER_REPEAT_MAIN), _AlbedoColor);
return 0;
}
#endif

View File

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

View File

@ -0,0 +1,26 @@
//////////////////////////////////////////////////////
// MK Toon Depth Only Setup //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_DEPTH_ONLY_SETUP
#define MK_TOON_DEPTH_ONLY_SETUP
#ifndef MK_DEPTH_ONLY_PASS
#define MK_DEPTH_ONLY_PASS
#endif
#include "../Core.hlsl"
//Hightmap is only needed if a UV is required
#if !defined(MK_TEXCLR) && !defined(MK_DISSOLVE)
#ifdef MK_PARALLAX
#undef MK_PARALLAX
#endif
#endif
#include "ProgramDepthOnly.hlsl"
#endif

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 89bd1e54e0216f541870d62d8158ce01
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,19 @@
//////////////////////////////////////////////////////
// MK Toon Forward Add Setup //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_FORWARD_ADD_SETUP
#define MK_TOON_FORWARD_ADD_SETUP
#ifndef MK_FORWARD_ADD_PASS
#define MK_FORWARD_ADD_PASS
#endif
#include "../Core.hlsl"
#include "ProgramForward.hlsl"
#endif

View File

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

View File

@ -0,0 +1,50 @@
//////////////////////////////////////////////////////
// MK Toon Forward Base Setup //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_FORWARD_BASE_SETUP
#define MK_TOON_FORWARD_BASE_SETUP
#ifndef MK_FORWARD_BASE_PASS
#define MK_FORWARD_BASE_PASS
#endif
//Internal keyword for environment reflections
#if !defined(_MK_ENVIRONMENT_REFLECTIONS_ADVANCED)
#if defined(MK_URP)
#ifndef _ENVIRONMENTREFLECTIONS_OFF
#define _ENVIRONMENTREFLECTIONS_OFF
#endif
#else
//Legay & LWRP
#ifndef _GLOSSYREFLECTIONS_OFF
#define _GLOSSYREFLECTIONS_OFF
#endif
#endif
#endif
//if particles are used disable dynamic lightmap
#if defined(DYNAMICLIGHTMAP_ON) && defined(MK_PARTICLES)
#undef DYNAMICLIGHTMAP_ON
#endif
#if defined(MK_URP) || defined(MK_LWRP)
#ifdef _MK_RECEIVE_SHADOWS
#ifdef _RECEIVE_SHADOWS_OFF
#undef _RECEIVE_SHADOWS_OFF
#endif
#else
#ifndef _RECEIVE_SHADOWS_OFF
#define _RECEIVE_SHADOWS_OFF
#endif
#endif
#endif
#include "../Core.hlsl"
#include "ProgramForward.hlsl"
#endif

View File

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

View File

@ -0,0 +1,113 @@
//////////////////////////////////////////////////////
// MK Toon Forward Data //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_IO_FORWARD
#define MK_TOON_IO_FORWARD
#include "../Core.hlsl"
#include "../Lighting.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// INPUT
/////////////////////////////////////////////////////////////////////////////////////////////
struct VertexInputForward
{
#if defined(MK_VERTCLR) || defined(MK_PARTICLES) || defined(MK_POLYBRUSH)
//use vertexcolors if required
autoLP4 color : COLOR0;
#endif
//vertex position - always needed
float4 vertex : POSITION;
#if defined(MK_TCM) || defined(MK_TCD)
//texcoords0 if needed
#if defined(MK_FLIPBOOK)// && !defined(UNITY_PARTICLE_INSTANCING_ENABLED)
float4 texcoord0 : TEXCOORD0;
float texcoordBlend : TEXCOORD3;
#else
float2 texcoord0 : TEXCOORD0;
#endif
#endif
#if defined(MK_FORWARD_BASE_PASS) && defined(DYNAMICLIGHTMAP_ON)
//dynammic lightmap uv
DECLARE_DYNAMIC_LIGHTMAP_INPUT(2)
#endif
#ifdef MK_NORMAL
half3 normal : NORMAL;
#endif
#ifdef MK_LIT
#ifdef MK_FORWARD_BASE_PASS
//static lightmap uv
DECLARE_STATIC_LIGHTMAP_INPUT(1);
#endif
//use tangents only if tbn matrix is required
#if defined(MK_TBN)
half4 tangent : TANGENT;
#endif
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
/////////////////////////////////////////////////////////////////////////////////////////////
// OUTPUT
/////////////////////////////////////////////////////////////////////////////////////////////
//If no parallax is used, then a 3 component tbn is enough
#ifdef MK_PARALLAX
#ifndef TBN_TYPE
#define TBN_TYPE half4
#endif
#else
#ifndef TBN_TYPE
#define TBN_TYPE half3
#endif
#endif
//Output Setup
struct VertexOutputForward
{
#if defined(MK_TCM) || defined(MK_TCD)
float4 uv : TEXCOORD0;
#endif
#if defined(MK_VERTCLR) || defined(MK_PARTICLES) || defined(MK_POLYBRUSH)
autoLP4 color : COLOR0;
#endif
//WorldPos + Fog
#if defined(MK_POS_WORLD) || defined(MK_FOG)
float4 positionWorld : TEXCOORD1; //posWorld XYZ Fog W
#endif
#ifdef MK_NORMAL
TBN_TYPE normalWorld : TEXCOORD2;
#endif
#ifdef MK_LIT
#if defined(MK_TBN)
TBN_TYPE tangentWorld : TEXCOORD8;
TBN_TYPE bitangentWorld : TEXCOORD9;
#endif
//Interplators 5,6,7 + C1 are reserved for lighting stuff
#endif
#ifdef MK_POS_CLIP
float4 positionClip : TEXCOORD3;
#endif
#ifdef MK_POS_NULL_CLIP
float4 nullClip : TEXCOORD4;
#endif
#ifdef MK_FLIPBOOK
float3 flipbookUV : TEXCOORD10;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
#endif

View File

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

View File

@ -0,0 +1,192 @@
//////////////////////////////////////////////////////
// MK Toon Forward Program //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_FORWARD
#define MK_TOON_FORWARD
#include "../Forward/Data.hlsl"
#include "../Surface.hlsl"
#include "../Lighting.hlsl"
#include "../Composite.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// VERTEX SHADER
/////////////////////////////////////////////////////////////////////////////////////////////
void ForwardVert (VertexInputForward VERTEX_INPUT, out VertexOutputForward vertexOutput, out VertexOutputLight vertexOutputLight)
{
UNITY_SETUP_INSTANCE_ID(VERTEX_INPUT);
INITIALIZE_STRUCT(VertexOutputForward, vertexOutput);
INITIALIZE_STRUCT(VertexOutputLight, vertexOutputLight);
UNITY_TRANSFER_INSTANCE_ID(VERTEX_INPUT, vertexOutput);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(vertexOutput);
#ifdef MK_VERTEX_ANIMATION
VERTEX_INPUT.vertex.xyz = VertexAnimation(PASS_VERTEX_ANIMATION_ARG(_VertexAnimationMap, PASS_VERTEX_ANIMATION_UV(VERTEX_INPUT.texcoord0.xy), _VertexAnimationIntensity, _VertexAnimationFrequency.xyz, VERTEX_INPUT.vertex.xyz, VERTEX_INPUT.normal));
#endif
//Clip Pos
#ifdef MK_POS_WORLD
vertexOutput.positionWorld.xyz = ComputeObjectToWorldSpace(VERTEX_INPUT.vertex.xyz);
#else
vertexOutput.positionWorld.xyz = 0;
#endif
vertexOutputLight.SV_CLIP_POS = ComputeObjectToClipSpace(VERTEX_INPUT.vertex.xyz);
//vertex positions
#ifdef MK_NORMAL
vertexOutput.normalWorld.xyz = ComputeNormalWorld(VERTEX_INPUT.normal);
#endif
#ifdef MK_LIT
#if defined(MK_TBN)
vertexOutput.tangentWorld.xyz = ComputeTangentWorld(VERTEX_INPUT.tangent.xyz);
vertexOutput.bitangentWorld.xyz = ComputeBitangentWorld(vertexOutput.normalWorld.xyz, vertexOutput.tangentWorld.xyz, VERTEX_INPUT.tangent.w * unity_WorldTransformParams.w);
#endif
#endif
//texcoords
#if defined(MK_TCM) || defined(MK_TCD)
#if defined(MK_TCM)
//XY always RAW Coords
//interpolated in pixel shader, artistic UV would take an additional texcoord, could be optimized some day...
vertexOutput.uv.xy = VERTEX_INPUT.texcoord0.xy;
#else
vertexOutput.uv.xy = 0;
#endif
#if defined(MK_TCD)
vertexOutput.uv.zw = VERTEX_INPUT.texcoord0.xy * _DetailMap_ST.xy + _DetailMap_ST.zw;
#else
vertexOutput.uv.zw = 0;
#endif
#endif
#ifdef MK_PARALLAX
half3 viewTangent = ComputeViewTangent(ComputeViewWorld(vertexOutput.positionWorld.xyz), vertexOutput.normalWorld.xyz, vertexOutput.tangentWorld.xyz, vertexOutput.bitangentWorld.xyz);
vertexOutput.normalWorld.w = viewTangent.x;
vertexOutput.tangentWorld.w = viewTangent.y;
vertexOutput.bitangentWorld.w = viewTangent.z;
#endif
#if defined(MK_VERTCLR) || defined(MK_PARTICLES) || defined(MK_POLYBRUSH)
vertexOutput.color = VERTEX_INPUT.color;
#endif
#ifdef MK_LIT
#ifdef MK_FORWARD_BASE_PASS
#ifdef MK_VERTEX_LIGHTING
// Approximated illumination from non-important point lights
vertexOutputLight.vertexLighting = ComputeVertexLighting(vertexOutput.positionWorld.xyz, vertexOutput.normalWorld.xyz);
#endif
#ifdef MK_ENVIRONMENT_REFLECTIONS
vertexOutputLight.lightmapUV = 0;
#if defined(MK_URP) || defined(MK_LWRP)
#if defined(LIGHTMAP_ON)
vertexOutputLight.lightmapUV.xy = ComputeStaticLightmapUV(VERTEX_INPUT.staticLightmapUV.xy);
#else
vertexOutputLight.lightmapUV.rgb = ComputeSHVertex(vertexOutput.normalWorld.xyz);
#endif
#else
//lightmaps and ambient
//Static lightmaps
#if defined(LIGHTMAP_ON)
vertexOutputLight.lightmapUV.xy = ComputeStaticLightmapUV(VERTEX_INPUT.staticLightmapUV.xy);
//If no lightmaps used, do vertex lit if enabled
#elif defined(UNITY_SHOULD_SAMPLE_SH)
vertexOutputLight.lightmapUV.rgb = ComputeSHVertex(vertexOutput.normalWorld.xyz);
#endif
#endif
#ifdef DYNAMICLIGHTMAP_ON
vertexOutputLight.lightmapUV.zw = ComputeDynamicLightmapUV(VERTEX_INPUT.dynamicLightmapUV.xy);
#endif
#endif
#endif
//transform lighting coords
TRANSFORM_WORLD_TO_SHADOW_COORDS(vertexOutput, VERTEX_INPUT, vertexOutputLight)
#endif
#ifdef MK_POS_CLIP
vertexOutput.positionClip = vertexOutputLight.SV_CLIP_POS;
#endif
#ifdef MK_POS_NULL_CLIP
vertexOutput.nullClip = ComputeObjectToClipSpace(0);
#endif
//vertex fog
#ifdef MK_FOG
vertexOutput.positionWorld.w = FogFactorVertex(vertexOutputLight.SV_CLIP_POS.z);
#endif
#ifdef MK_FLIPBOOK
vertexOutput.flipbookUV.xy = VERTEX_INPUT.texcoord0.zw;
vertexOutput.flipbookUV.z = VERTEX_INPUT.texcoordBlend;
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////
// FRAGMENT SHADER
/////////////////////////////////////////////////////////////////////////////////////////////
half4 ForwardFrag(in VertexOutputForward vertexOutput, in VertexOutputLight vertexOutputLight) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(vertexOutput);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(vertexOutput);
MKSurfaceData surfaceData = ComputeSurfaceData
(
PASS_POSITION_WORLD_ARG(vertexOutput.positionWorld.xyz)
PASS_FOG_FACTOR_WORLD_ARG(vertexOutput.positionWorld.w)
PASS_BASE_UV_ARG(vertexOutput.uv)
PASS_LIGHTMAP_UV_ARG(vertexOutputLight.lightmapUV)
PASS_VERTEX_COLOR_ARG(vertexOutput.color)
PASS_NORMAL_WORLD_ARG(vertexOutput.normalWorld.xyz)
PASS_VERTEX_LIGHTING_ARG(vertexOutputLight.vertexLighting)
PASS_TANGENT_WORLD_ARG(vertexOutput.tangentWorld.xyz)
PASS_VIEW_TANGENT_ARG(half3(vertexOutput.normalWorld.w, vertexOutput.tangentWorld.w, vertexOutput.bitangentWorld.w))
PASS_BITANGENT_WORLD_ARG(vertexOutput.bitangentWorld.xyz)
PASS_POSITION_CLIP_ARG(vertexOutput.positionClip)
PASS_NULL_CLIP_ARG(vertexOutput.nullClip)
PASS_FLIPBOOK_UV_ARG(vertexOutput.flipbookUV)
);
Surface surface = InitSurface(surfaceData, PASS_TEXTURE_2D(_AlbedoMap, SAMPLER_REPEAT_MAIN), _AlbedoColor);
MKPBSData pbsData = ComputePBSData(surface, surfaceData);
#ifdef MK_LIT
//Init per light data
MKLight light = ComputeMainLight(surfaceData, vertexOutputLight);
//return light.attenuation;
MKLightData lightData = ComputeLightData(light, surfaceData);
//Do per pass light
LightingIndirect(surface, surfaceData, pbsData, light, lightData);
LightingDirect(surface, surfaceData, pbsData, light, lightData, surface.direct);
#if defined(MK_URP) || defined(MK_LWRP)
#ifdef _ADDITIONAL_LIGHTS
surface.goochDark = 0;
uint lightCount = GetAdditionalLightsCount();
half4 additionalDirect = 0;
for (uint lightIndex = 0u; lightIndex < lightCount; lightIndex++)
{
MKLight additionalLight = ComputeAdditionalLight(lightIndex, surfaceData, vertexOutputLight);
MKLightData additionalLightData = ComputeLightData(additionalLight, surfaceData);
LightingDirectAdditional(surface, surfaceData, pbsData, additionalLight, additionalLightData, additionalDirect);
surface.direct += additionalDirect;
}
#endif
#endif
#endif
//Finalize the output
Composite(surface, surfaceData, pbsData);
return surface.final;
}
#endif

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4958ce82ebf376b42a531cc529cbda4e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,71 @@
//////////////////////////////////////////////////////
// MK Toon Meta Common //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_META_COMMON
#define MK_TOON_META_COMMON
#if defined(MK_URP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl"
#elif defined(MK_LWRP)
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/MetaInput.hlsl"
#else
#include "UnityMetaPass.cginc"
#endif
#include "../Core.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// Meta Common
/////////////////////////////////////////////////////////////////////////////////////////////
struct MKMetaData
{
half3 albedo;
half3 emission;
half3 specular;
#ifdef EDITOR_VISUALIZATION
float2 vizUV;
float4 lightCoords;
#endif
};
inline float4 ComputeMetaPosition(float4 vertexPosObject, float2 staticLightmapUV, float2 dynamicLightmapUV, float4 staticLightmapST, float4 dynLightmapST)
{
#if defined(MK_URP)
return MetaVertexPosition(vertexPosObject, staticLightmapUV, dynamicLightmapUV, staticLightmapST, dynLightmapST);
#elif defined(MK_LWRP)
return MetaVertexPosition(vertexPosObject, staticLightmapUV, dynamicLightmapUV, staticLightmapST);
#else
return UnityMetaVertexPosition(vertexPosObject, staticLightmapUV, dynamicLightmapUV, staticLightmapST, dynLightmapST);
#endif
}
inline half4 ComputeMetaOutput(MKMetaData mkMetaData)
{
#if defined(MK_URP) || defined(MK_LWRP)
MetaInput metaInput;
metaInput.Albedo = mkMetaData.albedo;
metaInput.Emission = mkMetaData.emission;
metaInput.SpecularColor = mkMetaData.specular;
return MetaFragment(metaInput);
#else
UnityMetaInput untiyMetaInput;
untiyMetaInput.Albedo = mkMetaData.albedo;
untiyMetaInput.Emission = mkMetaData.emission;
untiyMetaInput.SpecularColor = mkMetaData.specular;
#ifdef EDITOR_VISUALIZATION
untiyMetaInput.VizUV = mkMetaData.vizUV;
untiyMetaInput.LightCoord = mkMetaData.lightCoords;
#endif
return UnityMetaFragment(untiyMetaInput);
#endif
}
#endif

View File

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

View File

@ -0,0 +1,67 @@
//////////////////////////////////////////////////////
// MK Toon Meta Data //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_META_IO
#define MK_TOON_META_IO
#ifndef UNITY_PASS_META
#define UNITY_PASS_META
#endif
#if defined(MK_URP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl"
#elif defined(MK_LWRP)
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/MetaInput.hlsl"
#else
#include "UnityMetaPass.cginc"
#endif
#include "../Core.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// INPUT
/////////////////////////////////////////////////////////////////////////////////////////////
struct VertexInputMeta
{
#if defined(MK_VERTCLR) || defined(MK_POLYBRUSH)
half4 color : COLOR;
#endif
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
float2 staticLightmapUV : TEXCOORD1;
#if defined(DYNAMICLIGHTMAP_ON) || defined(UNITY_PASS_META)
float2 dynamicLightmapUV : TEXCOORD2;
#endif
#if defined(MK_PARALLAX)
half4 tangent : TANGENT;
half3 normal : NORMAL;
#endif
};
/////////////////////////////////////////////////////////////////////////////////////////////
// OUTPUT
/////////////////////////////////////////////////////////////////////////////////////////////
struct VertexOutputMeta
{
#ifdef MK_TCM
float4 uv : TEXCOORD0;
#endif
float4 svPositionClip : SV_POSITION;
#if defined(MK_VERTCLR) || defined(MK_POLYBRUSH)
autoLP4 color : COLOR;
#endif
#ifdef EDITOR_VISUALIZATION
float2 vizUV : TEXCOORD1;
float4 lightCoords : TEXCOORD2;
#endif
#if defined(MK_PARALLAX)
half3 viewTangent : TEXCOORD3;
#endif
};
#endif

View File

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

View File

@ -0,0 +1,130 @@
//////////////////////////////////////////////////////
// MK Toon Meta Program //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_META
#define MK_TOON_META
#if defined(MK_URP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl"
#elif defined(MK_LWRP)
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/MetaInput.hlsl"
#else
#include "UnityMetaPass.cginc"
#endif
#include "../Core.hlsl"
#include "Common.hlsl"
#include "Data.hlsl"
#include "../Surface.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// VERTEX SHADER
/////////////////////////////////////////////////////////////////////////////////////////////
VertexOutputMeta MetaVert(VertexInputMeta vertexInput)
{
VertexOutputMeta vertexOutput;
INITIALIZE_STRUCT(VertexOutputMeta, vertexOutput);
//vertexposition
vertexOutput.svPositionClip = ComputeMetaPosition(vertexInput.vertex, vertexInput.staticLightmapUV.xy, vertexInput.dynamicLightmapUV.xy, unity_LightmapST, unity_DynamicLightmapST);
//texcoords
#if defined(MK_TCM) || defined(MK_TCD)
vertexOutput.uv = 0;
#endif
#if defined(MK_TCM)
vertexOutput.uv.xy = vertexInput.texcoord0.xy * _AlbedoMap_ST.xy + _AlbedoMap_ST.zw;
#endif
#if defined(MK_TCD)
vertexOutput.uv.zw = vertexOutput.uv.xy = vertexInput.texcoord0.xy * _DetailMap_ST.xy + _DetailMap_ST.zw;
#endif
#if defined(MK_VERTCLR) || defined(MK_POLYBRUSH)
vertexOutput.color = vertexInput.color;
#endif
#ifdef EDITOR_VISUALIZATION
vertexOutput.vizUV = 0;
vertexOutput.lightCoords = 0;
if (unity_VisualizationMode == EDITORVIZ_TEXTURE)
vertexOutput.vizUV = UnityMetaVizUV(unity_EditorViz_UVIndex, vertexInput.texcoord0.xy, vertexInput.staticLightmapUV.xy, vertexInput.dynamicLightmapUV.xy, unity_EditorViz_Texture_ST);
else if (unity_VisualizationMode == EDITORVIZ_SHOWLIGHTMASK)
{
vertexOutput.vizUV = vertexInput.staticLightmapUV.xy * unity_LightmapST.xy + unity_LightmapST.zw;
vertexOutput.lightCoords = mul(unity_EditorViz_WorldToLight, mul(unity_ObjectToWorld, float4(vertexInput.vertex.xyz, 1)));
}
#endif
#if defined(MK_PARALLAX)
vertexOutput.viewTangent = ComputeViewTangent(ComputeViewObject(vertexInput.vertex.xyz), vertexInput.normal, vertexInput.tangent, cross(vertexInput.normal, vertexInput.tangent.xyz) * vertexInput.tangent.w * unity_WorldTransformParams.w);
#endif
return vertexOutput;
}
/////////////////////////////////////////////////////////////////////////////////////////////
// FRAGMENT SHADER
/////////////////////////////////////////////////////////////////////////////////////////////
half4 MetaFrag (VertexOutputMeta vertexOutput) : SV_Target
{
MKMetaData mkMetaData;
INITIALIZE_STRUCT(MKMetaData, mkMetaData);
MKSurfaceData surfaceData = ComputeSurfaceData
(
PASS_POSITION_WORLD_ARG(0)
PASS_FOG_FACTOR_WORLD_ARG(0)
PASS_BASE_UV_ARG(float4(vertexOutput.uv.xy, 0, 0))
PASS_LIGHTMAP_UV_ARG(0)
PASS_VERTEX_COLOR_ARG(vertexOutput.color)
PASS_NORMAL_WORLD_ARG(1)
PASS_VERTEX_LIGHTING_ARG(0)
PASS_TANGENT_WORLD_ARG(1)
PASS_VIEW_TANGENT_ARG(vertexOutput.viewTangent)
PASS_BITANGENT_WORLD_ARG(1)
PASS_POSITION_CLIP_ARG(0)
PASS_NULL_CLIP_ARG(0)
PASS_FLIPBOOK_UV_ARG(0)
);
Surface surface = InitSurface(surfaceData, PASS_TEXTURE_2D(_AlbedoMap, SAMPLER_REPEAT_MAIN), _AlbedoColor);
#ifdef MK_LIT
MKPBSData mkPBSData;
mkPBSData = ComputePBSData(surface, surfaceData);
#ifdef EDITOR_VISUALIZATION
mkMetaData.albedo = mkPBSData.diffuseRadiance;
mkMetaData.vizUV = vertexOutput.vizUV;
mkMetaData.lightCoords = vertexOutput.lightCoords;
#else
mkMetaData.albedo = mkPBSData.diffuseRadiance + mkPBSData.specularRadiance * mkPBSData.roughness * 0.5;
#endif
mkMetaData.specular = mkPBSData.specularRadiance;
#else
#ifdef EDITOR_VISUALIZATION
mkMetaData.albedo = surface.albedo;
mkMetaData.vizUV = vertexOutput.vizUV;
mkMetaData.lightCoords = vertexOutput.lightCoords;
#else
mkMetaData.albedo = surface.albedo;
#endif
mkMetaData.specular = 0;
#endif
#ifdef MK_EMISSION
#if defined(MK_EMISSION_MAP)
mkMetaData.emission = _EmissionColor * SampleTex2D(PASS_TEXTURE_2D(_EmissionMap, SAMPLER_REPEAT_MAIN), vertexOutput.uv).rgb;
#else
mkMetaData.emission = _EmissionColor;
#endif
#else
mkMetaData.emission = 0;
#endif
return ComputeMetaOutput(mkMetaData);
}
#endif

View File

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

View File

@ -0,0 +1,26 @@
//////////////////////////////////////////////////////
// MK Toon Meta Setup //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_META_SETUP
#define MK_TOON_META_SETUP
#ifndef MK_META_PASS
#define MK_META_PASS
#endif
#include "../Core.hlsl"
//Hightmap is only needed if a UV is required
#if !defined(MK_TEXCLR) && !defined(MK_DISSOLVE)
#ifdef MK_PARALLAX
#undef MK_PARALLAX
#endif
#endif
#include "ProgramMeta.hlsl"
#endif

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e90a788dc4be92d45940d10d17c1673c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,80 @@
//////////////////////////////////////////////////////
// MK Toon Outline Data //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_OUTLINE_ONLY_IO
#define MK_TOON_OUTLINE_ONLY_IO
#include "../Core.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// INPUT
/////////////////////////////////////////////////////////////////////////////////////////////
#if defined(MK_OUTLINE_DATA_UV7)
#define OUTLINE_INPUT half3 normalBaked : TEXCOORD7;
#else
#define OUTLINE_INPUT
#endif
struct VertexInputOutlineOnly
{
float4 vertex : POSITION;
#if defined(MK_OUTLINE_DATA_NORMAL) || defined(MK_PARALLAX) || defined(MK_VERTEX_ANIMATION_PULSE) || defined(MK_VERTEX_ANIMATION_NOISE)
half3 normal : NORMAL;
#endif
#if defined(MK_VERTCLR) || defined(MK_POLYBRUSH)
autoLP4 color : COLOR0;
#endif
#ifdef MK_TCM
//texcoords0 if needed
float2 texcoord0 : TEXCOORD0;
#endif
#if defined(MK_PARALLAX)
half4 tangent : TANGENT;
#endif
OUTLINE_INPUT
UNITY_VERTEX_INPUT_INSTANCE_ID
};
/////////////////////////////////////////////////////////////////////////////////////////////
// OUTPUT
/////////////////////////////////////////////////////////////////////////////////////////////
struct VertexOutputOutlineOnly
{
float4 svPositionClip : SV_POSITION;
#if defined(MK_VERTCLR) || defined(MK_POLYBRUSH)
autoLP4 color : COLOR0;
#endif
#ifdef MK_TCM
float2 uv : TEXCOORD0;
#endif
#ifdef MK_FOG
float fogFactor : TEXCOORD1;
#endif
#if defined(MK_PARALLAX)
half3 viewTangent : TEXCOORD2;
#endif
#ifdef MK_POS_CLIP
float4 positionClip : TEXCOORD3;
#endif
#ifdef MK_POS_NULL_CLIP
float4 nullClip : TEXCOORD4;
#endif
#ifdef MK_FLIPBOOK
float3 flipbookUV : TEXCOORD10;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
#endif

View File

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

View File

@ -0,0 +1,144 @@
//////////////////////////////////////////////////////
// MK Toon Outline Program //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_OUTLINE_ONLY_BASE
#define MK_TOON_OUTLINE_ONLY_BASE
#include "../Core.hlsl"
#include "Data.hlsl"
#include "../Surface.hlsl"
#include "../Composite.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// VERTEX SHADER
/////////////////////////////////////////////////////////////////////////////////////////////
VertexOutputOutlineOnly OutlineVert(VertexInputOutlineOnly vertexInput)
{
UNITY_SETUP_INSTANCE_ID(vertexInput);
VertexOutputOutlineOnly vertexOutput;
INITIALIZE_STRUCT(VertexOutputOutlineOnly, vertexOutput);
UNITY_TRANSFER_INSTANCE_ID(vertexInput, vertexOutput);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(vertexOutput);
//texcoords
#if defined(MK_TCM)
vertexOutput.uv = vertexInput.texcoord0;
#endif
#ifdef MK_OUTLINE_MAP
_OutlineSize *= tex2Dlod(_OutlineMap, float4(vertexOutput.uv, 0, 0)).r;
#endif
#ifdef MK_OUTLINE_NOISE
_OutlineSize = lerp(_OutlineSize, _OutlineSize * NoiseSimple(normalize(vertexInput.vertex.xyz)), _OutlineNoise);
#endif
#ifdef MK_VERTEX_ANIMATION
vertexInput.vertex.xyz = VertexAnimation(PASS_VERTEX_ANIMATION_ARG(_VertexAnimationMap, PASS_VERTEX_ANIMATION_UV(vertexOutput.uv), _VertexAnimationIntensity, _VertexAnimationFrequency.xyz, vertexInput.vertex.xyz, vertexInput.normal));
#endif
#ifdef MK_OUTLINE_FADE
float dist = distance(CAMERA_POSITION_WORLD , mul(MATRIX_M, float4(vertexInput.vertex.xyz, 1.0)).xyz);
_OutlineSize *= saturate((dist - _OutlineFadeMin) / (_OutlineFadeMax - _OutlineFadeMin));
#endif
#if defined(MK_OUTLINE_HULL_ORIGIN)
//float4x4 modelMatrix = MATRIX_M;
//vertexInput.vertex.xyz += SafeNormalize(vertexInput.vertex.xyz) * _OutlineSize * OUTLINE_ORIGIN_SCALE;
//float3 positionWorld = mul(modelMatrix, float4(vertexInput.vertex.xyz, 1.0)).xyz;
float3 scaleOrigin = 1 + _OutlineSize * OUTLINE_ORIGIN_SCALE;
float3x3 scale = float3x3
(
scaleOrigin.x, 0, 0,
0, scaleOrigin.y, 0,
0, 0, scaleOrigin.z
);
float3 positionWorld = mul(scale, vertexInput.vertex.xyz);
positionWorld = mul(MATRIX_M, float4(positionWorld, 1.0)).xyz;
#elif defined(MK_OUTLINE_HULL_OBJECT)
#if defined(MK_OUTLINE_DATA_UV7)
vertexInput.vertex.xyz += vertexInput.normalBaked * _OutlineSize * OUTLINE_OBJECT_SCALE;
#else
vertexInput.vertex.xyz += vertexInput.normal * _OutlineSize * OUTLINE_OBJECT_SCALE;
#endif
#endif
#if defined(MK_OUTLINE_HULL_ORIGIN)
vertexOutput.svPositionClip = ComputeWorldToClipSpace(positionWorld);
#else
//Make it pixel perfect and SCALED on different aspects and resolutions
half scaledAspect = SafeDivide(REFERENCE_ASPECT.x, SafeDivide(_ScreenParams.x, _ScreenParams.y));
half scaledResolution = SafeDivide(_ScreenParams.x, REFERENCE_RESOLUTION.x);
vertexOutput.svPositionClip = ComputeObjectToClipSpace(vertexInput.vertex.xyz);
#if defined(MK_OUTLINE_DATA_UV7)
half3 normalBakedClip = ComputeNormalObjectToClipSpace(vertexInput.normalBaked.xyz);
vertexOutput.svPositionClip.xy += 2 * _OutlineSize * SafeDivide(normalBakedClip.xy, _ScreenParams.xy) * scaledAspect * scaledResolution;
#else
half3 normalClip = ComputeNormalObjectToClipSpace(vertexInput.normal.xyz);
vertexOutput.svPositionClip.xy += 2 * _OutlineSize * SafeDivide(normalClip.xy, _ScreenParams.xy) * scaledAspect * scaledResolution;
#endif
#endif
#if defined(MK_VERTCLR) || defined(MK_POLYBRUSH)
vertexOutput.color = vertexInput.color;
#endif
#if defined(MK_PARALLAX)
vertexOutput.viewTangent = ComputeViewTangent(ComputeViewObject(vertexInput.vertex.xyz), vertexInput.normal, vertexInput.tangent, cross(vertexInput.normal, vertexInput.tangent.xyz) * vertexInput.tangent.w * unity_WorldTransformParams.w);
#endif
#ifdef MK_FOG
vertexOutput.fogFactor = FogFactorVertex(vertexOutput.svPositionClip.z);
#endif
#ifdef MK_POS_CLIP
vertexOutput.positionClip = vertexOutput.svPositionClip;
#endif
#ifdef MK_POS_NULL_CLIP
vertexOutput.nullClip = ComputeObjectToClipSpace(0);
#endif
#ifdef MK_FLIPBOOK
vertexOutput.flipbookUV.xy = VERTEX_INPUT.texcoord0.zw;
vertexOutput.flipbookUV.z = VERTEX_INPUT.texcoordBlend;
#endif
return vertexOutput;
}
/////////////////////////////////////////////////////////////////////////////////////////////
// FRAGMENT SHADER
/////////////////////////////////////////////////////////////////////////////////////////////
half4 OutlineFrag(VertexOutputOutlineOnly vertexOutput) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(vertexOutput);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(vertexOutput);
MKSurfaceData surfaceData = ComputeSurfaceData
(
PASS_POSITION_WORLD_ARG(0)
PASS_FOG_FACTOR_WORLD_ARG(vertexOutput.fogFactor)
PASS_BASE_UV_ARG(float4(vertexOutput.uv.xy, 0, 0))
PASS_LIGHTMAP_UV_ARG(0)
PASS_VERTEX_COLOR_ARG(vertexOutput.color)
PASS_NORMAL_WORLD_ARG(1)
PASS_VERTEX_LIGHTING_ARG(0)
PASS_TANGENT_WORLD_ARG(1)
PASS_VIEW_TANGENT_ARG(vertexOutput.viewTangent)
PASS_BITANGENT_WORLD_ARG(1)
PASS_POSITION_CLIP_ARG(vertexOutput.positionClip)
PASS_NULL_CLIP_ARG(vertexOutput.nullClip)
PASS_FLIPBOOK_UV_ARG(vertexOutput.flipbookUV)
);
Surface surface = InitSurface(surfaceData, PASS_TEXTURE_2D(_AlbedoMap, SAMPLER_REPEAT_MAIN), autoLP4(_OutlineColor.rgb, _AlbedoColor.a));
MKPBSData pbsData = ComputePBSData(surface, surfaceData);
Composite(surface, surfaceData, pbsData);
return surface.final;
}
#endif

View File

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

View File

@ -0,0 +1,26 @@
//////////////////////////////////////////////////////
// MK Toon Outline Setup //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_OUTLINE_SETUP
#define MK_TOON_OUTLINE_SETUP
#ifndef MK_OUTLINE_PASS
#define MK_OUTLINE_PASS
#endif
#include "../Core.hlsl"
//Hightmap is only needed if a UV is required
#if !defined(MK_TEXCLR) && !defined(MK_DISSOLVE)
#ifdef MK_PARALLAX
#undef MK_PARALLAX
#endif
#endif
#include "ProgramOutline.hlsl"
#endif

View File

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

View File

@ -0,0 +1,552 @@
//////////////////////////////////////////////////////
// MK Toon Pipeline //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_PIPELINE
#define MK_TOON_PIPELINE
#include "Config.hlsl"
#if defined(MK_URP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#elif defined(MK_LWRP)
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Lighting.hlsl"
#else
#include "AutoLight.cginc"
#include "UnityGlobalIllumination.cginc"
#endif
/////////////////////////////////////////////////////////////////////////////////////////////
// Helpers
/////////////////////////////////////////////////////////////////////////////////////////////
//Somehow on Metal overloaded methods (with different types) cause a redefinition compiler issue
//therefore force float only on Metal here
#ifndef SHADER_API_METAL
half SafeDivide(half v, half d)
{
return v / (d + HALF_MIN);
}
half2 SafeDivide(half2 v, half d)
{
return v / (d + HALF_MIN);
}
half2 SafeDivide(half2 v, half2 d)
{
return v / (d + HALF_MIN);
}
half3 SafeDivide(half3 v, half d)
{
return v / (d + HALF_MIN);
}
half3 SafeDivide(half3 v, half3 d)
{
return v / (d + HALF_MIN);
}
half4 SafeDivide(half4 v, half d)
{
return v / (d + HALF_MIN);
}
half4 SafeDivide(half4 v, half4 d)
{
return v / (d + HALF_MIN);
}
#endif
float SafeDivide(float v, float d)
{
return v / (d + HALF_MIN);
}
float2 SafeDivide(float2 v, float d)
{
return v / (d + HALF_MIN);
}
float2 SafeDivide(float2 v, float2 d)
{
return v / (d + HALF_MIN);
}
float3 SafeDivide(float3 v, float d)
{
return v / (d + HALF_MIN);
}
float3 SafeDivide(float3 v, float3 d)
{
return v / (d + HALF_MIN);
}
float4 SafeDivide(float4 v, float d)
{
return v / (d + HALF_MIN);
}
float4 SafeDivide(float4 v, float4 d)
{
return v / (d + HALF_MIN);
}
half SafeNormalize(half v)
{
return normalize(v + HALF_MIN);
}
half2 SafeNormalize(half2 v)
{
return normalize(v + HALF_MIN);
}
half3 SafeNormalize(half3 v)
{
return normalize(v + HALF_MIN);
}
half4 SafeNormalize(half4 v)
{
return normalize(v + HALF_MIN);
}
inline half FastPow2(half v)
{
return v * v;
}
inline half FastPow3(half v)
{
return v * v * v;
}
inline half FastPow4(half v)
{
return v * v * v * v;
}
inline half FastPow5(half v)
{
return v * v * v * v * v;
}
//Single Component Reciprocal
inline half Rcp(half v)
{
#if SHADER_TARGET >= 50
return rcp(v);
#else
//avoid division by 0
return SafeDivide(1.0, v);
#endif
}
//modified clip function for a complete discard when input equal zero oder smaller
inline void Clip0(half c)
{
//if(any(c < 0.0)) discard;
clip(c + HALF_MIN);
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Sampling
/////////////////////////////////////////////////////////////////////////////////////////////
#if SHADER_TARGET >= 35
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
#define UNIFORM_TEXTURE_2D_AUTO(textureName) uniform Texture2DArray<half4> textureName;
#define UNIFORM_SAMPLER_AND_TEXTURE_2D_AUTO(textureName) uniform Texture2DArray<half4> textureName; uniform SamplerState sampler##textureName;
#define DECLARE_TEXTURE_2D_ARGS_AUTO(textureName, samplerName) Texture2DArray<half4> textureName, SamplerState samplerName
#define UNIFORM_SAMPLER_AND_TEXTURE_2D_AUTO_HP(textureName) uniform Texture2DArray<float4> textureName; uniform SamplerState sampler##textureName;
#define DECLARE_TEXTURE_2D_ARGS_AUTO_HP(textureName, samplerName) Texture2DArray<float4> textureName, SamplerState samplerName
#else
#define UNIFORM_TEXTURE_2D_AUTO(textureName) uniform Texture2D<half4> textureName;
#define UNIFORM_SAMPLER_AND_TEXTURE_2D_AUTO(textureName) uniform Texture2D<half4> textureName; uniform SamplerState sampler##textureName;
#define DECLARE_TEXTURE_2D_ARGS_AUTO(textureName, samplerName) Texture2D<half4> textureName, SamplerState samplerName
#define UNIFORM_SAMPLER_AND_TEXTURE_2D_AUTO_HP(textureName) uniform Texture2D<float4> textureName; uniform SamplerState sampler##textureName;
#define DECLARE_TEXTURE_2D_ARGS_AUTO_HP(textureName, samplerName) Texture2D<float4> textureName, SamplerState samplerName
#endif
#define DECLARE_TEXTURE_2D_ARGS(textureName, samplerName) Texture2D<half4> textureName, SamplerState samplerName
#define UNIFORM_SAMPLER(samplerName) uniform SamplerState sampler##samplerName;
#define UNIFORM_TEXTURE_2D(textureName) uniform Texture2D<half4> textureName;
#define PASS_TEXTURE_2D(textureName, samplerName) textureName, samplerName
#else
#define UNIFORM_TEXTURE_2D_AUTO(textureName) uniform sampler2D textureName;
#define UNIFORM_SAMPLER_AND_TEXTURE_2D_AUTO(textureName) uniform sampler2D textureName;
#define DECLARE_TEXTURE_2D_ARGS_AUTO(textureName, samplerName) sampler2D textureName
#define UNIFORM_SAMPLER_AND_TEXTURE_2D_AUTO_HP(textureName) uniform sampler2D textureName;
#define DECLARE_TEXTURE_2D_ARGS_AUTO_HP(textureName, samplerName) sampler2D textureName
#define DECLARE_TEXTURE_2D_ARGS(textureName, samplerName) sampler2D textureName
#define UNIFORM_SAMPLER(samplerName)
#define UNIFORM_TEXTURE_2D(textureName) uniform sampler2D textureName;
#define PASS_TEXTURE_2D(textureName, samplerName) textureName
#endif
#ifdef MK_POINT_FILTERING
UNIFORM_SAMPLER(_point_repeat_Main)
#else
UNIFORM_SAMPLER(_linear_repeat_Main)
#endif
UNIFORM_SAMPLER(_point_clamp_Main)
#if SHADER_TARGET >= 35
#ifdef MK_POINT_FILTERING
#ifndef SAMPLER_REPEAT_MAIN
#define SAMPLER_REPEAT_MAIN sampler_point_repeat_Main
#endif
#else
#ifndef SAMPLER_REPEAT_MAIN
#define SAMPLER_REPEAT_MAIN sampler_linear_repeat_Main
#endif
#endif
#ifndef SAMPLER_CLAMPED_MAIN
#define SAMPLER_CLAMPED_MAIN sampler_point_clamp_Main
#endif
#else
#ifndef SAMPLER_REPEAT_MAIN
#define SAMPLER_REPEAT_MAIN 0
#endif
#ifndef SAMPLER_CLAMPED_MAIN
#define SAMPLER_CLAMPED_MAIN 0
#endif
#endif
inline half4 SampleTex2DAuto(DECLARE_TEXTURE_2D_ARGS_AUTO(tex, samplerTex), float2 uv)
{
#if SHADER_TARGET >= 35
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
return tex.SampleLevel(samplerTex, float3((uv).xy, (float)unity_StereoEyeIndex), 0);
#else
return tex.SampleLevel(samplerTex, UnityStereoTransformScreenSpaceTex(uv), 0);
#endif
#else
return tex2D(tex, UnityStereoTransformScreenSpaceTex(uv));
#endif
}
inline float4 SampleTex2DAutoHP(DECLARE_TEXTURE_2D_ARGS_AUTO_HP(tex, samplerTex), float2 uv)
{
#if SHADER_TARGET >= 35
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
return tex.SampleLevel(samplerTex, float3((uv).xy, (float)unity_StereoEyeIndex), 0);
#else
return tex.SampleLevel(samplerTex, UnityStereoTransformScreenSpaceTex(uv), 0);
#endif
#else
return tex2D(tex, UnityStereoTransformScreenSpaceTex(uv));
#endif
}
inline half4 SampleTex2D(DECLARE_TEXTURE_2D_ARGS(tex, samplerTex), float2 uv)
{
#if SHADER_TARGET >= 35
return tex.Sample(samplerTex, uv);
#else
return tex2D(tex, uv);
#endif
}
//Clamped ramp samplings
/*
inline half4 SampleRamp1D(DECLARE_TEXTURE_2D_ARGS(ramp, samplerTex), half value)
{
#if SHADER_TARGET >= 35
return ramp.Sample(samplerTex, float2(clamp(value, HALF_MIN, ONE_MINUS_HALF_MIN), 0.5));
#else
return SampleTex2D(PASS_TEXTURE_2D(ramp, samplerTex), float2(clamp(value, HALF_MIN, ONE_MINUS_HALF_MIN), 0.5));
#endif
}
inline half4 SampleRamp2D(DECLARE_TEXTURE_2D_ARGS(ramp, samplerTex), half2 value)
{
#if SHADER_TARGET >= 35
return ramp.Sample(samplerTex, clamp(value, HALF_MIN, ONE_MINUS_HALF_MIN));
#else
return SampleTex2D(PASS_TEXTURE_2D(ramp, samplerTex), clamp(value, HALF_MIN, ONE_MINUS_HALF_MIN));
#endif
}
*/
//saturated ramp samplings
inline half4 SampleRamp1D(DECLARE_TEXTURE_2D_ARGS(ramp, samplerTex), half value)
{
#if SHADER_TARGET >= 35
return ramp.Sample(samplerTex, float2(saturate(value), 0.5));
#else
return SampleTex2D(PASS_TEXTURE_2D(ramp, samplerTex), float2(saturate(value), 0.5));
#endif
}
inline half4 SampleRamp2D(DECLARE_TEXTURE_2D_ARGS(ramp, samplerTex), half2 value)
{
#if SHADER_TARGET >= 35
return ramp.Sample(samplerTex, saturate(value));
#else
return SampleTex2D(PASS_TEXTURE_2D(ramp, samplerTex), saturate(value));
#endif
}
/*
//unclamped ramp samplings
inline half4 SampleRamp1D(DECLARE_TEXTURE_2D_ARGS(ramp, samplerTex), half value)
{
#if SHADER_TARGET >= 35
return ramp.Sample(samplerTex, float2(value, 0.5));
#else
return SampleTex2D(PASS_TEXTURE_2D(ramp, samplerTex), float2(value, 0.5));
#endif
}
inline half4 SampleRamp2D(DECLARE_TEXTURE_2D_ARGS(ramp, samplerTex), half2 value)
{
#if SHADER_TARGET >= 35
return ramp.Sample(samplerTex, value);
#else
return SampleTex2D(PASS_TEXTURE_2D(ramp, samplerTex), value);
#endif
}
*/
#ifdef MK_FLIPBOOK
#define SAMPLE_TEX2D_FLIPBOOK(tex, samplerTex, uv, blendUV) SampleTex2DFlipbook(PASS_TEXTURE_2D(tex, samplerTex), uv, blendUV)
#else
#define SAMPLE_TEX2D_FLIPBOOK(tex, samplerTex, uv, blendUV) SampleTex2D(PASS_TEXTURE_2D(tex, SAMPLER_REPEAT_MAIN), uv)
#endif
/*
#ifdef MK_FLIPBOOK
#if SHADER_TARGET >= 35
#define SAMPLE_TEX2D_FLIPBOOK(tex, samplerTex, uv, blendUV) SampleTex2DFlipbook(PASS_TEXTURE_2D(tex, samplerTex), uv, blendUV)
#else
#define SAMPLE_TEX2D_FLIPBOOK(tex, uv, blendUV) SampleTex2DFlipbook(PASS_TEXTURE_2D(tex, SAMPLER_REPEAT_MAIN), uv, blendUV)
#endif
#else
#if SHADER_TARGET >= 35
#define SAMPLE_TEX2D_FLIPBOOK(tex, samplerTex, uv, blendUV) SampleTex2D(PASS_TEXTURE_2D(tex, samplerTex), uv)
#else
#define SAMPLE_TEX2D_FLIPBOOK(tex, uv, blendUV) SampleTex2D(PASS_TEXTURE_2D(tex, SAMPLER_REPEAT_MAIN), uv)
#endif
#endif
*/
inline half4 SampleTex2DFlipbook(DECLARE_TEXTURE_2D_ARGS(tex, samplerTex), float2 uv, float3 blendUV)
{
#ifdef MK_FLIPBOOK
half4 color0 = SampleTex2D(PASS_TEXTURE_2D(tex, samplerTex), uv);
half4 color1 = SampleTex2D(PASS_TEXTURE_2D(tex, samplerTex), blendUV.xy);
return lerp(color0, color1, blendUV.z);
#else
return SampleTex2D(PASS_TEXTURE_2D(tex, samplerTex), uv);
#endif
}
struct TriplanarUV
{
float2 x, y, z;
half3 weights;
};
inline TriplanarUV UVTriplanar(float3 position, float scale, half blend, half3 normal)
{
TriplanarUV uv;
float3 uvp = position * scale;
uv.x = uvp.zy;
uv.y = uvp.xz;
uv.z = uvp.xy;
uv.x.y += 0.5;
uv.z.x += 0.5;
uv.weights = pow(abs(normal), blend);
uv.weights = SafeDivide(uv.weights, uv.weights.x + uv.weights.y + uv.weights.z);
return uv;
}
inline half4 SampleTriplanar(DECLARE_TEXTURE_2D_ARGS(texX, samplerX), DECLARE_TEXTURE_2D_ARGS(texY, samplerY), DECLARE_TEXTURE_2D_ARGS(texZ, samplerZ), TriplanarUV uv)
{
half4 colorX = SampleTex2D(PASS_TEXTURE_2D(texX, samplerX), uv.x);
half4 colorY = SampleTex2D(PASS_TEXTURE_2D(texY, samplerY), uv.y);
half4 colorZ = SampleTex2D(PASS_TEXTURE_2D(texZ, samplerZ), uv.z);
return colorX * uv.weights.x + colorY * uv.weights.y + colorZ * uv.weights.z;
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Transformations
/////////////////////////////////////////////////////////////////////////////////////////////
#define CAMERA_POSITION_WORLD _WorldSpaceCameraPos
#define MATRIX_VP UNITY_MATRIX_VP
#define MATRIX_MVP UNITY_MATRIX_MVP
#if defined(MK_URP) || defined(MK_LWRP)
#define MATRIX_M UNITY_MATRIX_M
#define MATRIX_I_M UNITY_MATRIX_I_M
#define VERTEX_INPUT vertexInput
#define SV_CLIP_POS svPositionClip
#else
#define MATRIX_M unity_ObjectToWorld
#define MATRIX_I_M unity_WorldToObject
#define VERTEX_INPUT v
#define SV_CLIP_POS pos
#endif
#define Z_BUFFER_PARAMS _ZBufferParams
inline float4 ComputeObjectToClipSpace(float3 positionObject)
{
return mul(MATRIX_VP, mul(MATRIX_M, float4(positionObject, 1.0)));
//return mul(MATRIX_MVP, float4(positionObject, 1.0));
}
inline float3 ComputeObjectToWorldSpace(float3 positionObject)
{
return mul(MATRIX_M, float4(positionObject, 1.0)).xyz;
}
inline float4 ComputeWorldToClipSpace(float3 positionWorld)
{
return mul(MATRIX_VP, float4(positionWorld, 1.0));
}
inline half3 ComputeNormalWorld(half3 normalDirectionObject)
{
#ifdef UNITY_ASSUME_UNIFORM_SCALING
return SafeNormalize(mul((float3x3) MATRIX_M, normalDirectionObject));
#else
// Normal need to be multiply by inverse transpose
return SafeNormalize(mul(normalDirectionObject, (float3x3) MATRIX_I_M));
#endif
}
inline half3 ComputeNormalObjectToClipSpace(half3 normalDirectionObject)
{
#ifdef UNITY_ASSUME_UNIFORM_SCALING
return SafeNormalize(mul((float3x3) UNITY_MATRIX_VP, mul((float3x3) MATRIX_M, normalDirectionObject)));
#else
// Normal need to be multiply by inverse transpose
return SafeNormalize(mul((float3x3) UNITY_MATRIX_VP, mul(normalDirectionObject, (float3x3) MATRIX_I_M)));
#endif
}
inline half3 ComputeTangentWorld(half3 tangentObject)
{
return SafeNormalize(mul((float3x3) MATRIX_M, tangentObject));
}
inline half3 ComputeBitangentWorld(half3 normalWorld, half3 tangentWorld, half scale)
{
return SafeNormalize(cross(normalWorld, tangentWorld)) * scale;
}
inline half3 ComputeViewWorld(float3 positionWorld)
{
return SafeNormalize(CAMERA_POSITION_WORLD - positionWorld);
}
inline half3 ComputeViewObject(float3 positionObject)
{
return SafeNormalize(mul(MATRIX_I_M, float4(CAMERA_POSITION_WORLD, 1)).xyz - positionObject);
}
inline half3 ComputeViewTangent(half3 view, half3 normal, half3 tangent, half3 bitangent)
{
return SafeNormalize(mul(half3x3(tangent, bitangent, normal), view));
}
inline float ComputeLinearDepth(float depth)
{
return Rcp(Z_BUFFER_PARAMS.z * depth + Z_BUFFER_PARAMS.w);
}
inline float4 ComputeNDC(float4 positionClip)
{
float4 ndc;
ndc = positionClip * 0.5;
ndc.xy = float2(ndc.x, ndc.y * _ProjectionParams.x) + ndc.w;
ndc.zw = positionClip.zw;
/*
#if defined(UNITY_SINGLE_PASS_STEREO)
ndc.xy = TransformStereoScreenSpaceTex(ndc.xy, ndc.w);
#endif
*/
ndc.xyz = SafeDivide(ndc.xyz, ndc.w);
return ndc;
}
inline float2 ComputeNormalizedScreenUV(float4 ndc, float4 nullNdc, float scale)
{
//Orthographic camera is hard to handle => no ability to get "size"
//therefore ortho view differs from perspective view
//NDC offset
ndc.xy -= nullNdc.xy;
//Scale based on rendertarget size
#if defined(UNITY_SINGLE_PASS_STEREO)
half aspect = SafeDivide(_ScreenParams.x, _ScreenParams.y);
#else
half aspect = SafeDivide(_ScreenParams.x, _ScreenParams.y);
#endif
ndc.x *= aspect;
ndc.xy *= scale;
ndc.xy *= nullNdc.w;
return ndc.xy;
};
/////////////////////////////////////////////////////////////////////////////////////////////
// Fog
/////////////////////////////////////////////////////////////////////////////////////////////
inline float FogFactorVertex(float zClipSpace)
{
#if defined(MK_URP) || defined(MK_LWRP)
return ComputeFogFactor(zClipSpace);
#else
#if (SHADER_TARGET < 30) || defined(SHADER_API_MOBILE)
UNITY_CALC_FOG_FACTOR(zClipSpace);
return unityFogFactor;
#else
return zClipSpace;
#endif
#endif
}
inline void ApplyFog(inout half3 color, float fogFactor)
{
#if defined(MK_URP) || defined(MK_LWRP)
color = MixFog(color, fogFactor);
#else
#if defined(MK_FORWARD_BASE_PASS) || defined(MK_OUTLINE_PASS)
UNITY_APPLY_FOG_COLOR(fogFactor, color, unity_FogColor);
#elif defined(MK_FORWARD_ADD_PASS)
UNITY_APPLY_FOG_COLOR(fogFactor, color, half4(0,0,0,0));
#endif
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Refraction
/////////////////////////////////////////////////////////////////////////////////////////////
#if defined(MK_URP) || defined(MK_LWRP)
UNIFORM_TEXTURE_2D_AUTO(_CameraOpaqueTexture)
#else
UNIFORM_TEXTURE_2D_AUTO(_MKToonRefraction)
#endif
inline half3 SampleRefraction(float2 uv)
{
#if defined(MK_URP) || defined(MK_LWRP)
return SampleTex2DAuto(PASS_TEXTURE_2D(_CameraOpaqueTexture, SAMPLER_CLAMPED_MAIN), uv).rgb;
#else
return SampleTex2DAuto(PASS_TEXTURE_2D(_MKToonRefraction, SAMPLER_CLAMPED_MAIN), uv).rgb;
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Depth
/////////////////////////////////////////////////////////////////////////////////////////////
UNIFORM_SAMPLER_AND_TEXTURE_2D_AUTO_HP(_CameraDepthTexture)
inline float SampleDepth(float2 uv)
{
return SampleTex2DAutoHP(PASS_TEXTURE_2D(_CameraDepthTexture, SAMPLER_CLAMPED_MAIN), uv).r;
}
#endif

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8642f7715b526534786aa1255b9c16f1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,53 @@
//////////////////////////////////////////////////////
// MK Toon ShadowCaster Data //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_SHADOWCASTER_IO
#define MK_TOON_SHADOWCASTER_IO
#include "../Core.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// INPUT
/////////////////////////////////////////////////////////////////////////////////////////////
struct VertexInputShadowCaster
{
float4 vertex : POSITION;
half3 normal : NORMAL;
#ifdef MK_PARALLAX
half4 tangent : TANGENT;
#endif
#if defined(MK_VERTCLR) || defined(MK_POLYBRUSH)
autoLP4 color : COLOR0;
#endif
#ifdef MK_TCM
float2 texcoord0 : TEXCOORD0;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
/////////////////////////////////////////////////////////////////////////////////////////////
// OUTPUT
/////////////////////////////////////////////////////////////////////////////////////////////
struct VertexOutputShadowCaster
{
#ifdef MK_LEGACY_RP
V2F_SHADOW_CASTER_NOPOS
#endif
#if defined(MK_VERTCLR) || defined(MK_POLYBRUSH)
autoLP4 color : COLOR0;
#endif
#ifdef MK_PARALLAX
half3 viewTangent : TEXCOORD6;
#endif
#ifdef MK_TCM
float2 uv : TEXCOORD7;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
#endif

View File

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

View File

@ -0,0 +1,157 @@
//////////////////////////////////////////////////////
// MK Toon ShadowCaster Program //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_SHADOWCASTER
#define MK_TOON_SHADOWCASTER
#include "../Core.hlsl"
#if defined(MK_URP)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
#elif defined(MK_LWRP)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Shadows.hlsl"
#endif
#include "../Surface.hlsl"
#include "Data.hlsl"
//This should be excluded from the CBuffer
uniform float3 _LightDirection;
/////////////////////////////////////////////////////////////////////////////////////////////
// VERTEX SHADER
/////////////////////////////////////////////////////////////////////////////////////////////
void ShadowCasterVert
(
VertexInputShadowCaster VERTEX_INPUT,
out VertexOutputShadowCaster vertexOutput
,out float4 svPositionClip : SV_POSITION
)
{
UNITY_SETUP_INSTANCE_ID(VERTEX_INPUT);
INITIALIZE_STRUCT(VertexOutputShadowCaster, vertexOutput);
UNITY_TRANSFER_INSTANCE_ID(VERTEX_INPUT, vertexOutput);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(vertexOutput);
#ifdef MK_VERTEX_ANIMATION
VERTEX_INPUT.vertex.xyz = VertexAnimation(PASS_VERTEX_ANIMATION_ARG(_VertexAnimationMap, PASS_VERTEX_ANIMATION_UV(VERTEX_INPUT.texcoord0.xy), _VertexAnimationIntensity, _VertexAnimationFrequency.xyz, VERTEX_INPUT.vertex.xyz, VERTEX_INPUT.normal));
#endif
#if defined(MK_VERTCLR) || defined(MK_POLYBRUSH)
vertexOutput.color = VERTEX_INPUT.color;
#endif
#if defined(MK_TCM)
vertexOutput.uv = VERTEX_INPUT.texcoord0.xy * _AlbedoMap_ST.xy + _AlbedoMap_ST.zw;
#endif
#if defined(MK_URP) || defined(MK_LWRP)
half3 normalWorld = ComputeNormalWorld(VERTEX_INPUT.normal);
#endif
#ifdef MK_PARALLAX
half3 viewTangent = ComputeViewTangent(ComputeViewObject(VERTEX_INPUT.vertex.xyz), VERTEX_INPUT.normal, VERTEX_INPUT.tangent, cross(VERTEX_INPUT.normal, VERTEX_INPUT.tangent.xyz) * VERTEX_INPUT.tangent.w * unity_WorldTransformParams.w);
#endif
#if defined(MK_URP)
float3 positionWorld = mul(MATRIX_M, float4(VERTEX_INPUT.vertex.xyz, 1.0)).xyz;
svPositionClip = mul(MATRIX_VP, float4(ApplyShadowBias(positionWorld, normalWorld, _LightDirection), 1.0));
#if UNITY_REVERSED_Z
svPositionClip.z = min(svPositionClip.z, svPositionClip.w * UNITY_NEAR_CLIP_VALUE);
#else
svPositionClip.z = max(svPositionClip.z, svPositionClip.w * UNITY_NEAR_CLIP_VALUE);
#endif
#elif defined(MK_LWRP)
float3 positionWorld = mul(MATRIX_M, float4(VERTEX_INPUT.vertex.xyz, 1.0)).xyz;
float invNdotL = 1.0 - saturate(dot(_LightDirection, normalWorld));
float scale = invNdotL * _ShadowBias.y;
positionWorld = _LightDirection * _ShadowBias.xxx + positionWorld;
positionWorld = normalWorld * scale.xxx + positionWorld;
svPositionClip = mul(MATRIX_VP, float4(positionWorld, 1));
#if UNITY_REVERSED_Z
svPositionClip.z = min(svPositionClip.z, svPositionClip.w * UNITY_NEAR_CLIP_VALUE);
#else
svPositionClip.z = max(svPositionClip.z, svPositionClip.w * UNITY_NEAR_CLIP_VALUE);
#endif
#else
TRANSFER_SHADOW_CASTER_NOPOS(vertexOutput, svPositionClip)
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////
// FRAGMENT SHADER
/////////////////////////////////////////////////////////////////////////////////////////////
half4 ShadowCasterFrag
(
VertexOutputShadowCaster vertexOutput
#ifdef MK_LEGACY_RP
#if UNITY_VERSION >= 20171
,UNITY_POSITION(vpos)
#else
,UNITY_VPOS_TYPE vpos : VPOS
#endif
#endif
) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(vertexOutput);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(vertexOutput);
MKSurfaceData surfaceData = ComputeSurfaceData
(
PASS_POSITION_WORLD_ARG(0)
PASS_FOG_FACTOR_WORLD_ARG(0)
PASS_BASE_UV_ARG(float4(vertexOutput.uv.xy, 0, 0))
PASS_LIGHTMAP_UV_ARG(0)
PASS_VERTEX_COLOR_ARG(vertexOutput.color)
PASS_NORMAL_WORLD_ARG(1)
PASS_VERTEX_LIGHTING_ARG(0)
PASS_TANGENT_WORLD_ARG(1)
PASS_VIEW_TANGENT_ARG(vertexOutput.viewTangent)
PASS_BITANGENT_WORLD_ARG(1)
PASS_POSITION_CLIP_ARG(0)
PASS_NULL_CLIP_ARG(0)
PASS_FLIPBOOK_UV_ARG(0)
);
Surface surface = InitSurface(surfaceData, PASS_TEXTURE_2D(_AlbedoMap, SAMPLER_REPEAT_MAIN), _AlbedoColor);
#if defined(MK_URP) || defined(MK_LWRP)
return 0;
#else
#ifdef MK_SURFACE_TYPE_TRANSPARENT
#ifdef MK_TOON_DITHER_MASK
/*
#ifdef LOD_FADE_CROSSFADE
#define _LOD_FADE_ON_ALPHA
alpha *= unity_LODFade.y;
#endif
*/
// dither mask alpha blending
half alphaRef = tex3D(_DitherMaskLOD, float3(vpos.xy*0.25,surface.alpha*0.9375)).a;
Clip0(alphaRef);
#else
Clip0(surface.alpha - 0.5);
#endif
/*
//Disabled for now
#ifdef LOD_FADE_CROSSFADE
#ifdef _LOD_FADE_ON_ALPHA
#undef _LOD_FADE_ON_ALPHA
#else
UnityApplyDitherCrossFade(vpos.xy);
#endif
#endif
*/
#endif
SHADOW_CASTER_FRAGMENT(vertexOutput)
#endif
}
#endif

View File

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

View File

@ -0,0 +1,32 @@
//////////////////////////////////////////////////////
// MK Toon ShadowCaster Setup //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_SHADOWCASTER_SETUP
#define MK_TOON_SHADOWCASTER_SETUP
#ifndef MK_SHADOWCASTER_PASS
#define MK_SHADOWCASTER_PASS
#endif
#include "../Core.hlsl"
#if defined(MK_SURFACE_TYPE_TRANSPARENT) && SHADER_TARGET > 30
#ifndef MK_TOON_DITHER_MASK
#define MK_TOON_DITHER_MASK
#endif
#endif
//Hightmap is only needed if a UV is required
#if !defined(MK_TEXCLR) && !defined(MK_DISSOLVE)
#ifdef MK_PARALLAX
#undef MK_PARALLAX
#endif
#endif
#include "ProgramShadowCaster.hlsl"
#endif

View File

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

View File

@ -0,0 +1,798 @@
//////////////////////////////////////////////////////
// MK Toon Surface //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_SURFACE
#define MK_TOON_SURFACE
#include "Core.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// Surface Data
/////////////////////////////////////////////////////////////////////////////////////////////
//Dynamic precalc struct
struct MKSurfaceData
{
#ifdef MK_NORMAL
half3 vertexNormalWorld;
#endif
#ifdef MK_LIT
#ifdef MK_ENVIRONMENT_REFLECTIONS
float4 lightmapUV;
#endif
#ifdef MK_VERTEX_LIGHTING
half3 vertexLighting;
#endif
half3 normalWorld;
#ifdef MK_TBN
half3 tangentWorld;
half3 bitangentWorld;
#endif
#ifdef MK_PARALLAX
half height;
#endif
#endif
#ifdef MK_VD
half3 viewWorld;
#endif
#ifdef MK_VD_O
half3 viewTangent;
#endif
#ifdef MK_POS_WORLD
float3 positionWorld;
#endif
#ifdef MK_FOG
float fogFactor;
#endif
#if defined(MK_VERTCLR) || defined(MK_PARTICLES) || defined(MK_POLYBRUSH)
autoLP4 vertexColor;
#endif
#if defined(MK_TCM) || defined(MK_TCD)
float4 baseUV;
#endif
#ifdef MK_THRESHOLD_MAP
float2 thresholdUV;
#endif
#if defined(MK_SCREEN_UV)
float4 screenUV;
#endif
#if defined(MK_REFRACTION)
float2 refractionUV;
#endif
#ifdef MK_ARTISTIC
float2 artisticUV;
#endif
#ifdef MK_FLIPBOOK
float3 flipbookUV;
#endif
#ifdef MK_DISSOLVE
half dissolveClip;
#endif
#ifdef MK_V_DOT_N
half VoN;
half OneMinusVoN;
#endif
#ifdef MK_MV_REF_N
half3 MVrN;
#endif
};
struct MKPBSData
{
half reflectivity;
half oneMinusReflectivity;
half roughness;
#if defined(MK_ENVIRONMENT_REFLECTIONS) || defined(MK_SPECULAR) || defined(MK_DIFFUSE_OREN_NAYAR) || defined(MK_DIFFUSE_MINNAERT)
half roughnessPow2;
#endif
#if defined(MK_ENVIRONMENT_REFLECTIONS) || defined(MK_SPECULAR)
half roughnessPow4;
#endif
half smoothness;
half3 diffuseRadiance;
half3 specularRadiance;
#ifdef MK_FRESNEL_HIGHLIGHTS
half3 fresnel;
#endif
};
//dynamic surface struct
struct Surface
{
half4 final;
half3 albedo;
half alpha;
#ifdef MK_REFRACTION
half3 refraction;
#endif
// RGB - RAW
#if defined(MK_LIT)
#ifdef MK_THRESHOLD_MAP
half thresholdOffset;
#endif
half4 goochBright;
half4 goochDark;
half2 occlusion;
#ifdef MK_EMISSION
half3 emission;
#endif
#ifdef MK_INDIRECT
half3 indirect;
#endif
half4 direct;
#ifdef MK_ARTISTIC
#if defined(MK_ARTISTIC_DRAWN) || defined(MK_ARTISTIC_SKETCH)
half artistic0;
#elif defined(MK_ARTISTIC_HATCHING)
half3 artistic0;
half3 artistic1;
#endif
#endif
#ifdef MK_THICKNESS_MAP
half thickness;
#endif
#if defined(MK_RIM)
half4 rim;
#endif
#ifdef MK_IRIDESCENCE
half4 iridescence;
#endif
#endif
};
half3 FresnelSchlickGGXIBL(half oneMinusVoN, half3 f0, half smoothness)
{
return FastPow5(oneMinusVoN) * (max(smoothness, f0) - f0) + f0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Header macros
/////////////////////////////////////////////////////////////////////////////////////////////
#ifdef MK_PBS
#define PASS_BLENDING_ARG(surface, surfaceData, pbsData) surface, surfaceData, pbsData
#else
#define PASS_BLENDING_ARG(surface, surfaceData, pbsData) surface, surfaceData
#endif
#ifdef MK_FLIPBOOK
#define SURFACE_FLIPBOOK_UV surfaceData.flipbookUV
#else
#define SURFACE_FLIPBOOK_UV 0
#endif
#ifdef MK_POS_WORLD
#define PASS_POSITION_WORLD_ARG(positionWorld) positionWorld
#else
#define PASS_POSITION_WORLD_ARG(positionWorld) 0
#endif
#ifdef MK_FOG
#define PASS_FOG_FACTOR_WORLD_ARG(fogFacor) ,fogFacor
#else
#define PASS_FOG_FACTOR_WORLD_ARG(fogFacor)
#endif
#if defined(MK_TCM) || defined(MK_TCD)
#define PASS_BASE_UV_ARG(baseUV) ,baseUV
#else
#define PASS_BASE_UV_ARG(baseUV)
#endif
#if defined(MK_VERTCLR) || defined(MK_PARTICLES) || defined(MK_POLYBRUSH)
#define PASS_VERTEX_COLOR_ARG(vertexColor) ,vertexColor
#else
#define PASS_VERTEX_COLOR_ARG(vertexColor)
#endif
#if defined(MK_NORMAL)
#define PASS_NORMAL_WORLD_ARG(normalWorld) ,normalWorld
#else
#define PASS_NORMAL_WORLD_ARG(normalWorld)
#endif
#if defined(MK_VERTEX_LIGHTING)
#define PASS_VERTEX_LIGHTING_ARG(vertexLighting) ,vertexLighting
#else
#define PASS_VERTEX_LIGHTING_ARG(vertexLighting)
#endif
#if defined(MK_TBN)
#define PASS_TANGENT_WORLD_ARG(tangentWorld) ,tangentWorld
#define PASS_BITANGENT_WORLD_ARG(bitangentWorld) ,bitangentWorld
#else
#define PASS_TANGENT_WORLD_ARG(bitangentWorld)
#define PASS_BITANGENT_WORLD_ARG(bitangentWorld)
#endif
#ifdef MK_ENVIRONMENT_REFLECTIONS
#define PASS_LIGHTMAP_UV_ARG(lightmapUV) ,lightmapUV
#else
#define PASS_LIGHTMAP_UV_ARG(lightmapUV)
#endif
#if defined(MK_PARALLAX)
#define PASS_VIEW_TANGENT_ARG(viewTangent) ,viewTangent
#else
#define PASS_VIEW_TANGENT_ARG(viewTangent)
#endif
#ifdef MK_POS_CLIP
#define PASS_POSITION_CLIP_ARG(positionClip) ,positionClip
#else
#define PASS_POSITION_CLIP_ARG(positionClip)
#endif
#ifdef MK_POS_NULL_CLIP
#define PASS_NULL_CLIP_ARG(nullClip) ,nullClip
#else
#define PASS_NULL_CLIP_ARG(nullClip)
#endif
#ifdef MK_FLIPBOOK
#define PASS_FLIPBOOK_UV_ARG(flipbookUV) ,flipbookUV
#else
#define PASS_FLIPBOOK_UV_ARG(flipbookUV)
#endif
//Texture color
inline void SurfaceColor(out half3 albedo, out half alpha, DECLARE_TEXTURE_2D_ARGS(albedoMap, samplerTex), float2 uv, float3 blendUV, autoLP4 color)
{
half4 c;
#ifdef MK_OUTLINE_PASS
c = half4(color.rgb, SAMPLE_TEX2D_FLIPBOOK(albedoMap, SAMPLER_REPEAT_MAIN, uv, blendUV).a * color.a);
#else
c = SAMPLE_TEX2D_FLIPBOOK(albedoMap, SAMPLER_REPEAT_MAIN, uv, blendUV) * color;
#endif
albedo = c.rgb;
#if defined(MK_ALPHA_LOOKUP)
alpha = c.a;
#else
alpha = 1.0h;
#endif
}
inline void SurfaceColor(out half3 albedo, out half alpha, DECLARE_TEXTURE_2D_ARGS(albedoMap, samplerTex), DECLARE_TEXTURE_2D_ARGS(albedoMap1, samplerTex1), DECLARE_TEXTURE_2D_ARGS(albedoMap2, samplerTex2), DECLARE_TEXTURE_2D_ARGS(albedoMap3, samplerTex3), float2 uv, autoLP4 blendColor, float3 blendUV, autoLP4 color)
{
half4 c0, c1, c2, c3;
#ifdef MK_OUTLINE_PASS
c0 = half4(color.rgb, SAMPLE_TEX2D_FLIPBOOK(albedoMap, SAMPLER_REPEAT_MAIN, uv, blendUV).a * color.a);
c1 = half4(color.rgb, SAMPLE_TEX2D_FLIPBOOK(albedoMap1, SAMPLER_REPEAT_MAIN, uv, blendUV).a) * blendColor.g;
c2 = half4(color.rgb, SAMPLE_TEX2D_FLIPBOOK(albedoMap2, SAMPLER_REPEAT_MAIN, uv, blendUV).a) * blendColor.b;
c3 = half4(color.rgb, SAMPLE_TEX2D_FLIPBOOK(albedoMap3, SAMPLER_REPEAT_MAIN, uv, blendUV).a) * blendColor.a;
#else
c0 = SAMPLE_TEX2D_FLIPBOOK(albedoMap, SAMPLER_REPEAT_MAIN, uv, blendUV) * color;
c1 = SAMPLE_TEX2D_FLIPBOOK(albedoMap1, SAMPLER_REPEAT_MAIN, uv, blendUV) * blendColor.y;
c2 = SAMPLE_TEX2D_FLIPBOOK(albedoMap2, SAMPLER_REPEAT_MAIN, uv, blendUV) * blendColor.z;
c3 = SAMPLE_TEX2D_FLIPBOOK(albedoMap3, SAMPLER_REPEAT_MAIN, uv, blendUV) * blendColor.w;
#endif
half4 mixedColor = lerp(lerp(lerp(c0, c1, blendColor.g), c2, blendColor.b), c3, blendColor.a);
albedo = mixedColor.rgb;
#if defined(MK_ALPHA_LOOKUP)
alpha = mixedColor.a;
#else
alpha = 1.0h;
#endif
}
//Non texture color
inline void SurfaceColor(out half3 albedo, out half alpha, autoLP4 vertexColor, autoLP4 color)
{
half4 c = vertexColor * color;
albedo = c.rgb;
#if defined(MK_ALPHA_LOOKUP)
alpha = c.a;
#else
alpha = 1.0h;
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Initialize
/////////////////////////////////////////////////////////////////////////////////////////////
inline MKSurfaceData ComputeSurfaceData
(
//#ifdef MK_POS_WORLD
in float3 positionWorld
//#endif
#ifdef MK_FOG
, in float fogFactor
#endif
#if defined(MK_TCM) || defined(MK_TCD)
, in float4 baseUV
#endif
#ifdef MK_ENVIRONMENT_REFLECTIONS
, in float4 lightmapUV
#endif
#if defined(MK_VERTCLR) || defined(MK_PARTICLES) || defined(MK_POLYBRUSH)
, in autoLP4 vertexColor
#endif
#ifdef MK_NORMAL
, in half3 normalWorld
#endif
#ifdef MK_VERTEX_LIGHTING
, in autoLP3 vertexLighting
#endif
#if defined(MK_TBN)
, in half3 tangentWorld
#endif
#if defined(MK_PARALLAX)
, in half3 viewTangent
#endif
#if defined(MK_TBN)
, in half3 bitangentWorld
#endif
#ifdef MK_POS_CLIP
, in float4 positionClip
#endif
#ifdef MK_POS_NULL_CLIP
, in float4 nullClip
#endif
#ifdef MK_FLIPBOOK
, in float3 flipbookUV
#endif
)
{
MKSurfaceData surfaceData;
INITIALIZE_STRUCT(MKSurfaceData, surfaceData);
#ifdef MK_POS_WORLD
surfaceData.positionWorld = positionWorld;
#endif
#ifdef MK_FOG
surfaceData.fogFactor = fogFactor;
#endif
#if defined(MK_VERTCLR) || defined(MK_PARTICLES) || defined(MK_POLYBRUSH)
surfaceData.vertexColor = vertexColor;
#endif
#if defined(MK_TCM) || defined(MK_TCD)
surfaceData.baseUV = 0;
#endif
#if defined(MK_TCM)
surfaceData.baseUV.xy = baseUV.xy * _AlbedoMap_ST.xy + _AlbedoMap_ST.zw;
#endif
#if defined(MK_TCD)
surfaceData.baseUV.zw = baseUV.zw;
#endif
#ifdef MK_FLIPBOOK
SURFACE_FLIPBOOK_UV = flipbookUV;
#endif
#ifdef MK_VD
surfaceData.viewWorld = SafeNormalize(CAMERA_POSITION_WORLD - surfaceData.positionWorld);
#endif
#ifdef MK_VD_O
surfaceData.viewTangent = SafeNormalize(viewTangent);
#endif
#ifdef MK_PARALLAX
surfaceData.height = SAMPLE_TEX2D_FLIPBOOK(_HeightMap, SAMPLER_REPEAT_MAIN, surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV).r;
float2 parallaxUVOffset = Parallax(surfaceData.viewTangent, surfaceData.height, _Parallax, 0.42);
#if defined(MK_TCM)
surfaceData.baseUV.xy += parallaxUVOffset;
#endif
#if defined(MK_TCD)
surfaceData.baseUV.zw += parallaxUVOffset;
#endif
#endif
#ifdef MK_THRESHOLD_MAP
surfaceData.thresholdUV = surfaceData.baseUV.xy * _ThresholdMapScale;
#endif
#if defined(MK_SCREEN_UV)
surfaceData.screenUV = ComputeNDC(positionClip);
#endif
#if defined(MK_ARTISTIC)
#if defined(MK_ARTISTIC_DRAWN)
#if defined(MK_ARTISTIC_PROJECTION_SCREEN_SPACE)
surfaceData.artisticUV = ComputeNormalizedScreenUV(surfaceData.screenUV, ComputeNDC(nullClip), _DrawnMapScale);
#else
surfaceData.artisticUV = surfaceData.baseUV.xy * _DrawnMapScale;
#endif
#elif defined(MK_ARTISTIC_HATCHING)
#if defined(MK_ARTISTIC_PROJECTION_SCREEN_SPACE)
surfaceData.artisticUV = ComputeNormalizedScreenUV(surfaceData.screenUV, ComputeNDC(nullClip), _HatchingMapScale);
#else
surfaceData.artisticUV = surfaceData.baseUV.xy * _HatchingMapScale;
#endif
#elif defined(MK_ARTISTIC_SKETCH)
#if defined(MK_ARTISTIC_PROJECTION_SCREEN_SPACE)
surfaceData.artisticUV = ComputeNormalizedScreenUV(surfaceData.screenUV, ComputeNDC(nullClip), _SketchMapScale);
#else
surfaceData.artisticUV = surfaceData.baseUV.xy * _SketchMapScale;
#endif
#endif
#ifdef MK_ARTISTIC_ANIMATION_STUTTER
surfaceData.artisticUV.xy += Stutter(_Time.y, _ArtisticFrequency);
#endif
#endif
//dissolve could be moved above the screen uv to safe some instructions while clipping
#ifdef MK_DISSOLVE
float2 dissolveUV;
#ifdef MK_DISSOLVE_PROJECTION_SCREEN_SPACE
dissolveUV = ComputeNormalizedScreenUV(surfaceData.screenUV, ComputeNDC(nullClip), _DissolveMapScale);
#else
dissolveUV = surfaceData.baseUV.xy;
#endif
surfaceData.dissolveClip = SAMPLE_TEX2D_FLIPBOOK(_DissolveMap, SAMPLER_REPEAT_MAIN, dissolveUV, SURFACE_FLIPBOOK_UV).r - _DissolveAmount;
Clip0(surfaceData.dissolveClip);
#endif
#ifdef MK_NORMAL
surfaceData.vertexNormalWorld = SafeNormalize(normalWorld);
#endif
#ifdef MK_TBN
surfaceData.tangentWorld = SafeNormalize(tangentWorld);
surfaceData.bitangentWorld = SafeNormalize(bitangentWorld);
#endif
#if defined(MK_LIT)
//get normal direction
#ifdef MK_TBN
//Normalmap extraction
#if defined(MK_NORMAL_MAP) && !defined(MK_DETAIL_NORMAL_MAP)
surfaceData.normalWorld = NormalMappingWorld(PASS_TEXTURE_2D(_NormalMap, SAMPLER_REPEAT_MAIN), surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV, _NormalMapIntensity, half3x3(surfaceData.tangentWorld, surfaceData.bitangentWorld, surfaceData.vertexNormalWorld));
#elif defined(MK_NORMAL_MAP) && defined(MK_DETAIL_NORMAL_MAP)
surfaceData.normalWorld = NormalMappingWorld(PASS_TEXTURE_2D(_NormalMap, SAMPLER_REPEAT_MAIN), surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV, _NormalMapIntensity, PASS_TEXTURE_2D(_DetailNormalMap, SAMPLER_REPEAT_MAIN), surfaceData.baseUV.zw, _DetailNormalMapIntensity, half3x3(surfaceData.tangentWorld, surfaceData.bitangentWorld, surfaceData.vertexNormalWorld));
#elif !defined(MK_NORMAL_MAP) && defined(MK_DETAIL_NORMAL_MAP)
surfaceData.normalWorld = NormalMappingWorld(PASS_TEXTURE_2D(_DetailNormalMap, SAMPLER_REPEAT_MAIN), surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV, _DetailNormalMapIntensity, half3x3(surfaceData.tangentWorld, surfaceData.bitangentWorld, surfaceData.vertexNormalWorld));
#else
surfaceData.normalWorld = surfaceData.vertexNormalWorld;
#endif
#ifdef MK_SPECULAR_ANISOTROPIC
//rebuild tangent and bitangent
surfaceData.tangentWorld = SafeNormalize(cross(surfaceData.normalWorld, half3(0.0, 1.0, 0.0)));
surfaceData.bitangentWorld = SafeNormalize(cross(surfaceData.normalWorld, surfaceData.tangentWorld));
#endif
#else
surfaceData.normalWorld = surfaceData.vertexNormalWorld;
#endif
#ifdef MK_VERTEX_LIGHTING
surfaceData.vertexLighting = vertexLighting;
#endif
#ifdef MK_ENVIRONMENT_REFLECTIONS
surfaceData.lightmapUV = lightmapUV;
#endif
#endif
#if defined(MK_REFRACTION)
#ifdef MK_INDEX_OF_REFRACTION
float3 ssY = float3(UNITY_MATRIX_V[1][0], UNITY_MATRIX_V[1][1], UNITY_MATRIX_V[1][2]);
float3 ssX = normalize( cross(surfaceData.viewWorld, ssY));
float4x4 ssView = float4x4
(
ssX.x, ssX.y, ssX.z, 0,
ssY.x, ssY.y, ssY.z, 0,
surfaceData.viewWorld, 0,
0,0,0,1
);
float2 ssIOR = mul(ssView, float4(surfaceData.vertexNormalWorld, 0.0)).xy;
ssIOR.x *= SafeDivide(_ScreenParams.y, _ScreenParams.x);
ssIOR *= (1.0 - saturate(dot(surfaceData.vertexNormalWorld, surfaceData.viewWorld))) * _IndexOfRefraction;
surfaceData.refractionUV = surfaceData.screenUV.xy - ssIOR;
#else
surfaceData.refractionUV = surfaceData.screenUV.xy;
#endif
#endif
#ifdef MK_V_DOT_N
surfaceData.VoN = saturate(dot(surfaceData.viewWorld, surfaceData.normalWorld));
surfaceData.OneMinusVoN = 1.0 - surfaceData.VoN;
#endif
#ifdef MK_MV_REF_N
surfaceData.MVrN = reflect(-surfaceData.viewWorld, surfaceData.normalWorld);
#endif
return surfaceData;
}
inline void ComputeBlending
(
inout Surface surface
, in MKSurfaceData surfaceData
#ifdef MK_PBS
, inout MKPBSData pbsData
#endif
)
{
#if defined(MK_BLEND_PREMULTIPLY) || defined(MK_BLEND_ADDITIVE)
#if defined(MK_PBS)
pbsData.diffuseRadiance *= surface.alpha;
half premulGISpec;
#ifdef MK_FRESNEL_HIGHLIGHTS
premulGISpec = dot(pbsData.fresnel, REL_LUMA);
#else
premulGISpec = pbsData.specularRadiance;
#endif
surface.alpha = surface.alpha * pbsData.oneMinusReflectivity + premulGISpec;
#else
surface.albedo *= surface.alpha;
#endif
#elif defined(MK_BLEND_MULTIPLY)
#if defined(MK_PBS)
surface.albedo = lerp(HALF3_ONE, surface.albedo, surface.alpha);
pbsData.diffuseRadiance = lerp(HALF3_ONE, pbsData.diffuseRadiance, surface.alpha * pbsData.oneMinusReflectivity + pbsData.reflectivity);
#else
surface.albedo = lerp(HALF3_ONE, surface.albedo, surface.alpha);
#endif
#endif
#ifdef MK_SOFT_FADE
#if defined(MK_BLEND_PREMULTIPLY) || defined(MK_BLEND_ADDITIVE)
surface.albedo *= SoftFade(_SoftFadeNearDistance, _SoftFadeFarDistance, surfaceData.screenUV);
#else
surface.alpha *= SoftFade(_SoftFadeNearDistance, _SoftFadeFarDistance, surfaceData.screenUV);
#endif
#endif
#ifdef MK_CAMERA_FADE
#if defined(MK_BLEND_PREMULTIPLY) || defined(MK_BLEND_ADDITIVE)
surface.albedo *= CameraFade(_CameraFadeNearDistance, _CameraFadeFarDistance, surfaceData.screenUV);
#else
surface.alpha *= CameraFade(_CameraFadeNearDistance, _CameraFadeFarDistance, surfaceData.screenUV);
#endif
#endif
#ifdef MK_LIT
#if defined(MK_ALPHA_LOOKUP)
surface.goochBright.a *= surface.alpha;
surface.goochDark.a *= surface.alpha;
#endif
#endif
}
inline MKPBSData ComputePBSData(inout Surface surface, in MKSurfaceData surfaceData)
{
MKPBSData pbsData;
INITIALIZE_STRUCT(MKPBSData, pbsData);
half4 pbsInput;
#if defined(MK_WORKFLOW_METALLIC)
#ifdef MK_PBS_MAP_0
pbsInput = SAMPLE_TEX2D_FLIPBOOK(_MetallicMap, SAMPLER_REPEAT_MAIN, surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV).rrra;
pbsInput.a *= _Smoothness;
#else
pbsInput.rgb = _Metallic;
pbsInput.a = _Smoothness;
#endif
#elif defined(MK_WORKFLOW_ROUGHNESS)
#ifdef MK_PBS_MAP_0
pbsInput.rgb = SAMPLE_TEX2D_FLIPBOOK(_MetallicMap, SAMPLER_REPEAT_MAIN, surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV).rrr;
#else
pbsInput.rgb = _Metallic;
#endif
#ifdef MK_PBS_MAP_1
pbsInput.a = 1.0 - SAMPLE_TEX2D_FLIPBOOK(_RoughnessMap, SAMPLER_REPEAT_MAIN, surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV).r;
#else
pbsInput.a = 1.0 - _Roughness;
#endif
#else //MK_WORKFLOW_SPECULAR / Simple
#ifdef MK_PBS_MAP_0
pbsInput = SAMPLE_TEX2D_FLIPBOOK(_SpecularMap, SAMPLER_REPEAT_MAIN, surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV);
pbsInput.a *= _Smoothness;
#else
pbsInput.rgb = _SpecularColor.rgb;
pbsInput.a = _Smoothness;
#endif
#endif
#if defined(MK_WORKFLOW_METALLIC)
pbsData.smoothness = pbsInput.a;
pbsData.oneMinusReflectivity = K_SPEC_DIELECTRIC_MAX - pbsInput.r * K_SPEC_DIELECTRIC_MAX;
pbsData.reflectivity = 1.0 - pbsData.oneMinusReflectivity;
pbsData.specularRadiance = lerp(K_SPEC_DIELECTRIC_MIN, surface.albedo, pbsInput.r);
pbsData.diffuseRadiance = surface.albedo * (pbsData.oneMinusReflectivity * (1.0 - pbsData.specularRadiance));//surface.albedo * pbsData.oneMinusReflectivity;
#elif defined(MK_WORKFLOW_ROUGHNESS)
pbsData.smoothness = pbsInput.a;
pbsData.oneMinusReflectivity = K_SPEC_DIELECTRIC_MAX - pbsInput.r * K_SPEC_DIELECTRIC_MAX;
pbsData.reflectivity = 1.0 - pbsData.oneMinusReflectivity;
pbsData.specularRadiance = lerp(K_SPEC_DIELECTRIC_MIN, surface.albedo, pbsInput.r);
pbsData.diffuseRadiance = surface.albedo * ((1.0 - pbsData.specularRadiance) * pbsData.oneMinusReflectivity);
#elif defined(MK_WORKFLOW_SPECULAR)
pbsData.reflectivity = max(max(pbsInput.r, pbsInput.g), pbsInput.b);
pbsData.smoothness = pbsInput.a;
pbsData.oneMinusReflectivity = 1.0 - pbsData.reflectivity;
pbsData.specularRadiance = pbsInput.rgb;
pbsData.diffuseRadiance = surface.albedo * (half3(1.0, 1.0, 1.0) - pbsInput.rgb);
#else //Simple
pbsData.reflectivity = 0;
pbsData.smoothness = pbsInput.a;
pbsData.oneMinusReflectivity = 1.0 - pbsData.reflectivity;
pbsData.diffuseRadiance = surface.albedo;
pbsData.specularRadiance = pbsInput.rgb;
#endif
pbsData.roughness = 1.0 - pbsData.smoothness;
#if defined(MK_ENVIRONMENT_REFLECTIONS) || defined(MK_SPECULAR) || defined(MK_DIFFUSE_OREN_NAYAR) || defined(MK_DIFFUSE_MINNAERT)
pbsData.roughnessPow2 = FastPow2(pbsData.roughness);
#endif
#if defined(MK_ENVIRONMENT_REFLECTIONS) || defined(MK_SPECULAR)
pbsData.roughnessPow4 = FastPow2(pbsData.roughnessPow2);
#endif
#ifdef MK_FRESNEL_HIGHLIGHTS
pbsData.fresnel = FresnelSchlickGGXIBL(surfaceData.OneMinusVoN, pbsData.specularRadiance, pbsData.smoothness);
#endif
#ifdef MK_PBS
ComputeBlending(PASS_BLENDING_ARG(surface, surfaceData, pbsData));
#endif
return pbsData;
}
inline Surface InitSurface(in MKSurfaceData surfaceData, DECLARE_TEXTURE_2D_ARGS(albedoMap, samplerTex), inout half4 albedoTint)
{
//Init Surface
Surface surface;
INITIALIZE_STRUCT(Surface, surface);
#ifdef MK_ARTISTIC
#if defined(MK_ARTISTIC_DRAWN)
surface.artistic0 = 1.0 - SampleTex2D(PASS_TEXTURE_2D(_DrawnMap, SAMPLER_REPEAT_MAIN), surfaceData.artisticUV).r;
#elif defined(MK_ARTISTIC_SKETCH)
surface.artistic0 = SampleTex2D(PASS_TEXTURE_2D(_SketchMap, SAMPLER_REPEAT_MAIN), surfaceData.artisticUV).r;
#elif defined(MK_ARTISTIC_HATCHING)
surface.artistic0 = SampleTex2D(PASS_TEXTURE_2D(_HatchingDarkMap, SAMPLER_REPEAT_MAIN), surfaceData.artisticUV).rgb;
surface.artistic1 = SampleTex2D(PASS_TEXTURE_2D(_HatchingBrightMap, SAMPLER_REPEAT_MAIN), surfaceData.artisticUV).rgb;
#endif
#endif
//init surface color
#if defined(MK_TEXCLR)
#if defined(MK_PARTICLES) || defined(MK_COMBINE_VERTEX_COLOR_WITH_ALBEDO_MAP)
albedoTint *= surfaceData.vertexColor;
#endif
SurfaceColor(surface.albedo, surface.alpha, PASS_TEXTURE_2D(albedoMap, samplerTex), surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV, albedoTint);
#elif defined(MK_POLYBRUSH)
SurfaceColor(surface.albedo, surface.alpha, PASS_TEXTURE_2D(albedoMap, samplerTex), PASS_TEXTURE_2D(_AlbedoMap1, samplerTex), PASS_TEXTURE_2D(_AlbedoMap2, samplerTex), PASS_TEXTURE_2D(_AlbedoMap3, samplerTex), surfaceData.baseUV.xy, surfaceData.vertexColor, SURFACE_FLIPBOOK_UV, albedoTint);
#else
SurfaceColor(surface.albedo, surface.alpha, surfaceData.vertexColor, albedoTint);
#endif
//add detail
#ifdef MK_DETAIL_MAP
MixAlbedoDetail(surface.albedo, PASS_TEXTURE_2D(_DetailMap, SAMPLER_REPEAT_MAIN), surfaceData.baseUV.zw, SURFACE_FLIPBOOK_UV);
#endif
#if defined(MK_ALPHA_CLIPPING)
Clip0(surface.alpha - _AlphaCutoff);
#endif
#ifdef MK_REFRACTION
half2 refractionDir;
#ifdef MK_REFRACTION_DISTORTION_MAP
refractionDir = (_RefractionDistortion * REFRACTION_DISTORTION_SCALE * surface.alpha) * UnpackDudv(PASS_TEXTURE_2D(_RefractionDistortionMap, SAMPLER_REPEAT_MAIN), surfaceData.baseUV.xy * _RefractionDistortionMapScale, SURFACE_FLIPBOOK_UV);
#else
//currently disabled if no normal mapping is set, could be optimized using a procedural noise
refractionDir = 0;
#endif
surface.refraction = SampleRefraction(surfaceData.refractionUV + refractionDir);
surface.albedo.rgb = lerp(surface.refraction.rgb, surface.albedo.rgb, saturate(surface.alpha - _RefractionDistortionFade));
#endif
#ifdef MK_COLOR_GRADING_ALBEDO
surface.albedo = ColorGrading(surface.albedo, _Brightness, _Saturation, _Contrast);
#endif
#ifdef MK_LIT
#ifdef MK_THRESHOLD_MAP
surface.thresholdOffset = SAMPLE_TEX2D_FLIPBOOK(_ThresholdMap, SAMPLER_REPEAT_MAIN, surfaceData.thresholdUV, SURFACE_FLIPBOOK_UV).r;
#endif
surface.direct = 0;
surface.goochBright = _GoochBrightColor;
#ifdef MK_LEGACY_RP
#ifdef USING_DIRECTIONAL_LIGHT
surface.goochDark = _GoochDarkColor;
#else
surface.goochDark = 0;
#endif
#else
surface.goochDark = _GoochDarkColor;
#endif
#if defined(MK_GOOCH_BRIGHT_MAP)
surface.goochBright *= SAMPLE_TEX2D_FLIPBOOK(_GoochBrightMap, SAMPLER_REPEAT_MAIN, surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV);
#endif
#if defined(MK_GOOCH_DARK_MAP)
#ifdef MK_LEGACY_RP
#ifdef USING_DIRECTIONAL_LIGHT
surface.goochDark *= SAMPLE_TEX2D_FLIPBOOK(_GoochDarkMap, SAMPLER_REPEAT_MAIN, surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV);
#endif
#else
surface.goochDark *= SAMPLE_TEX2D_FLIPBOOK(_GoochDarkMap, SAMPLER_REPEAT_MAIN, surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV);
#endif
#endif
#ifdef MK_INDIRECT
surface.indirect = 0;
#endif
#ifdef MK_THICKNESS_MAP
surface.thickness = SAMPLE_TEX2D_FLIPBOOK(_ThicknessMap, SAMPLER_REPEAT_MAIN, surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV).r;
#endif
#if defined(MK_RIM)
surface.rim = 0;
#endif
#ifdef MK_IRIDESCENCE
surface.iridescence = 0;
#endif
#ifdef MK_OCCLUSION_MAP
surface.occlusion = (1.0 - _OcclusionMapIntensity) + SAMPLE_TEX2D_FLIPBOOK(_OcclusionMap, SAMPLER_REPEAT_MAIN, surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV).rg * _OcclusionMapIntensity;
#else
surface.occlusion = 1.0;
#endif
#ifdef MK_EMISSION
#if defined(MK_EMISSION_MAP)
surface.emission = _EmissionColor * SAMPLE_TEX2D_FLIPBOOK(_EmissionMap, SAMPLER_REPEAT_MAIN, surfaceData.baseUV.xy, SURFACE_FLIPBOOK_UV).rgb;
#else
surface.emission = _EmissionColor;
#endif
#endif
#endif
#ifdef MK_COLOR
#if defined(MK_COLOR_BLEND_ADDITIVE)
surface.albedo = surface.albedo + surfaceData.vertexColor;
surface.alpha *= surfaceData.vertexColor.a;
#elif defined(MK_COLOR_BLEND_SUBTRACTIVE)
surface.albedo = surface.albedo + surfaceData.vertexColor * (-1.0h);
surface.alpha *= surfaceData.vertexColor.a;
#elif defined(MK_COLOR_BLEND_OVERLAY)
surface.albedo = lerp(1 - 2 * (1 - surface.albedo) * (1 - surface.albedo), 2 * surface.albedo * surfaceData.vertexColor.rgb, step(surface.albedo, 0.5));
surface.alpha *= surfaceData.vertexColor.a;
#elif defined(MK_COLOR_BLEND_COLOR)
half3 aHSL = RGBToHSV(surface.albedo);
half3 bHSL = RGBToHSV(surfaceData.vertexColor.rgb);
half3 rHSL = half3(bHSL.x, bHSL.y, aHSL.z);
surface.albedo = HSVToRGB(rHSL);
surface.alpha = surface.alpha * surfaceData.vertexColor.a;
#elif defined(MK_COLOR_BLEND_DIFFERENCE)
surface.albedo = abs(surface.albedo + surfaceData.vertexColor * (-1.0h));
surface.alpha *= surfaceData.vertexColor.a;
#else
surface.albedo *= surfaceData.vertexColor.rgb;
surface.alpha *= surfaceData.vertexColor.a;
#endif
#endif
//avoid not initialized value
surface.final = 0;
#ifndef MK_PBS
ComputeBlending(PASS_BLENDING_ARG(surface, surfaceData, 0));
#endif
return surface;
}
#endif

View File

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

View File

@ -0,0 +1,154 @@
//////////////////////////////////////////////////////
// MK Toon Uniform //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_UNIFORM
#define MK_TOON_UNIFORM
#if defined(MK_URP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#elif defined(MK_LWRP)
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl"
#else
#include "UnityCG.cginc"
#endif
#include "Pipeline.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// UNIFORM VARIABLES
/////////////////////////////////////////////////////////////////////////////////////////////
// The compiler should optimized the code by stripping away unused uniforms
// This way its also possible to avoid an inconsistent buffer size error and
// use the SRP Batcher, while compile different variants of the shader
// Every PerDraw (builtin engine variables) should accessed via the builtin include files
// Its not clear if a block based setup for the srp batcher is required,
// therefore all uniforms are grouped this way:
//
// fixed | fixed2 | fixed3 | fixed4
// half | half2 | half3 | half4
// float | float2 | float3 | float4
// Sampler2D | Sampler3D
CBUFFER_START(UnityPerMaterial)
uniform autoLP _AlphaCutoff;
uniform autoLP _Metallic;
uniform autoLP _Smoothness;
uniform autoLP _Roughness;
uniform autoLP _Anisotropy;
uniform autoLP _LightTransmissionDistortion;
uniform autoLP _LightBandsScale;
uniform autoLP _LightThreshold;
uniform autoLP _DrawnClampMin;
uniform autoLP _DrawnClampMax;
uniform autoLP _Contrast;
uniform autoLP _Saturation;
uniform autoLP _Brightness;
uniform autoLP _DiffuseSmoothness;
uniform autoLP _DiffuseThresholdOffset;
uniform autoLP _SpecularSmoothness;
uniform autoLP _SpecularThresholdOffset;
uniform autoLP _RimSmoothness;
uniform autoLP _RimThresholdOffset;
uniform autoLP _IridescenceSmoothness;
uniform autoLP _IridescenceThresholdOffset;
uniform autoLP _LightTransmissionSmoothness;
uniform autoLP _LightTransmissionThresholdOffset;
uniform autoLP _RimSize;
uniform autoLP _IridescenceSize;
uniform autoLP _DissolveAmount;
uniform autoLP _DissolveBorderSize;
uniform autoLP _OutlineNoise;
uniform autoLP _DiffuseWrap;
uniform autoLP _DetailMix;
uniform autoLP _RefractionDistortionFade;
uniform autoLP _GoochRampIntensity;
uniform autoLP _VertexAnimationIntensity;
uniform autoLP3 _DetailColor;
uniform autoLP3 _SpecularColor;
uniform autoLP3 _LightTransmissionColor;
uniform autoLP4 _AlbedoColor;
uniform autoLP4 _DissolveBorderColor;
uniform autoLP4 _OutlineColor;
uniform autoLP4 _IridescenceColor;
uniform autoLP4 _RimColor;
uniform autoLP4 _RimBrightColor;
uniform autoLP4 _RimDarkColor;
uniform autoLP4 _GoochDarkColor;
uniform autoLP4 _GoochBrightColor;
uniform autoLP4 _VertexAnimationFrequency;
uniform half _DetailNormalMapIntensity;
uniform half _NormalMapIntensity;
uniform half _Parallax;
uniform half _OcclusionMapIntensity;
uniform half _LightBands;
uniform half _ThresholdMapScale;
uniform half _ArtisticFrequency;
uniform half _DissolveMapScale;
uniform half _DrawnMapScale;
uniform half _SketchMapScale;
uniform half _HatchingMapScale;
uniform half _OutlineSize;
uniform half _SpecularIntensity;
uniform half _LightTransmissionIntensity;
uniform half _RefractionDistortionMapScale;
uniform half _IndexOfRefraction;
uniform half _RefractionDistortion;
uniform half3 _EmissionColor;
uniform float _SoftFadeNearDistance;
uniform float _SoftFadeFarDistance;
uniform float _CameraFadeNearDistance;
uniform float _CameraFadeFarDistance;
uniform float _OutlineFadeMin;
uniform float _OutlineFadeMax;
uniform float4 _AlbedoMap_ST;
uniform float4 _MainTex_ST;
uniform float4 _DetailMap_ST;
CBUFFER_END
UNIFORM_TEXTURE_2D(_AlbedoMap); //1
UNIFORM_TEXTURE_2D(_AlbedoMap1);
UNIFORM_TEXTURE_2D(_AlbedoMap2);
UNIFORM_TEXTURE_2D(_AlbedoMap3);
UNIFORM_TEXTURE_2D(_RefractionDistortionMap); //2
UNIFORM_TEXTURE_2D(_SpecularMap); //3
UNIFORM_TEXTURE_2D(_RoughnessMap); //3
UNIFORM_TEXTURE_2D(_MetallicMap); //3
UNIFORM_TEXTURE_2D(_DetailMap); //4
UNIFORM_TEXTURE_2D(_DetailNormalMap); //5
UNIFORM_TEXTURE_2D(_NormalMap); //6
UNIFORM_TEXTURE_2D(_HeightMap); //7
UNIFORM_TEXTURE_2D(_ThicknessMap); //8
UNIFORM_TEXTURE_2D(_OcclusionMap); //9
UNIFORM_TEXTURE_2D(_ThresholdMap); //10
UNIFORM_TEXTURE_2D(_GoochRamp); //11
UNIFORM_TEXTURE_2D(_DiffuseRamp); //12
UNIFORM_TEXTURE_2D(_SpecularRamp); //13
UNIFORM_TEXTURE_2D(_RimRamp); //14
UNIFORM_TEXTURE_2D(_LightTransmissionRamp); //15
UNIFORM_TEXTURE_2D(_IridescenceRamp); //16
UNIFORM_TEXTURE_2D(_SketchMap); //17
UNIFORM_TEXTURE_2D(_DrawnMap); //17
UNIFORM_TEXTURE_2D(_HatchingBrightMap); //17
UNIFORM_TEXTURE_2D(_HatchingDarkMap); //18
UNIFORM_TEXTURE_2D(_GoochBrightMap); //19
UNIFORM_TEXTURE_2D(_GoochDarkMap); //20
UNIFORM_TEXTURE_2D(_DissolveMap); //21
UNIFORM_TEXTURE_2D(_DissolveBorderRamp); //22
UNIFORM_TEXTURE_2D(_EmissionMap); //23
uniform sampler2D _VertexAnimationMap; //24
//Depth //25
//Refraction //26
uniform sampler2D _OutlineMap; // Only Outline
uniform sampler3D _DitherMaskLOD; // Only Shadows
#endif

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b934913f864dfdb43b9fcf8830288133
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,49 @@
//////////////////////////////////////////////////////
// MK Toon Universal2D Data //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_UNIVERSAL2D_IO
#define MK_TOON_UNIVERSAL2D_IO
#include "../Core.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// INPUT
/////////////////////////////////////////////////////////////////////////////////////////////
struct VertexInputUniversal2D
{
float4 vertex : POSITION;
#if defined(MK_VERTEX_ANIMATION_PULSE) || defined(MK_VERTEX_ANIMATION_NOISE)
half3 normal : NORMAL;
#endif
#if defined(MK_VERTCLR) || defined(MK_PARTICLES) || defined(MK_POLYBRUSH)
autoLP4 color : COLOR0;
#endif
#ifdef MK_TCM
float2 texcoord0 : TEXCOORD0;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
/////////////////////////////////////////////////////////////////////////////////////////////
// OUTPUT
/////////////////////////////////////////////////////////////////////////////////////////////
struct VertexOutputUniversal2D
{
float4 svPositionClip : SV_POSITION;
#if defined(MK_VERTCLR) || defined(MK_PARTICLES) || defined(MK_POLYBRUSH)
autoLP4 color : COLOR0;
#endif
#ifdef MK_TCM
float2 uv : TEXCOORD0;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
#endif

View File

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

View File

@ -0,0 +1,75 @@
//////////////////////////////////////////////////////
// MK Toon Universal2D Program //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_UNIVERSAL2D
#define MK_TOON_UNIVERSAL2D
#include "../Core.hlsl"
#include "Data.hlsl"
#include "../Surface.hlsl"
#include "../Composite.hlsl"
/////////////////////////////////////////////////////////////////////////////////////////////
// VERTEX SHADER
/////////////////////////////////////////////////////////////////////////////////////////////
VertexOutputUniversal2D Universal2DVert(VertexInputUniversal2D vertexInput)
{
UNITY_SETUP_INSTANCE_ID(vertexInput);
VertexOutputUniversal2D vertexOutput;
INITIALIZE_STRUCT(VertexOutputUniversal2D, vertexOutput);
UNITY_TRANSFER_INSTANCE_ID(vertexInput, vertexOutput);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(vertexOutput);
#ifdef MK_VERTEX_ANIMATION
vertexInput.vertex.xyz = VertexAnimation(PASS_VERTEX_ANIMATION_ARG(_VertexAnimationMap, PASS_VERTEX_ANIMATION_UV(vertexInput.texcoord0.xy), _VertexAnimationIntensity, _VertexAnimationFrequency.xyz, vertexInput.vertex.xyz, vertexInput.normal));
#endif
vertexOutput.svPositionClip = mul(MATRIX_MVP, float4(vertexInput.vertex.xyz, 1.0));
#if defined(MK_VERTCLR) || defined(MK_PARTICLES) || defined(MK_POLYBRUSH)
vertexOutput.color = vertexInput.color;
#endif
//texcoords
#if defined(MK_TCM)
vertexOutput.uv = vertexInput.texcoord0 * _AlbedoMap_ST.xy + _AlbedoMap_ST.zw;
#endif
return vertexOutput;
}
/////////////////////////////////////////////////////////////////////////////////////////////
// FRAGMENT SHADER
/////////////////////////////////////////////////////////////////////////////////////////////
half4 Universal2DFrag(VertexOutputUniversal2D vertexOutput) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(vertexOutput);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(vertexOutput);
MKSurfaceData surfaceData = ComputeSurfaceData
(
PASS_POSITION_WORLD_ARG(0)
PASS_FOG_FACTOR_WORLD_ARG(0)
PASS_BASE_UV_ARG(float4(vertexOutput.uv.xy, 0, 0))
PASS_LIGHTMAP_UV_ARG(0)
PASS_VERTEX_COLOR_ARG(vertexOutput.color)
PASS_NORMAL_WORLD_ARG(1)
PASS_VERTEX_LIGHTING_ARG(0)
PASS_TANGENT_WORLD_ARG(1)
PASS_VIEW_TANGENT_ARG(1)
PASS_BITANGENT_WORLD_ARG(1)
PASS_POSITION_CLIP_ARG(0)
PASS_NULL_CLIP_ARG(0)
PASS_FLIPBOOK_UV_ARG(0)
);
Surface surface = InitSurface(surfaceData, PASS_TEXTURE_2D(_AlbedoMap, SAMPLER_REPEAT_MAIN), _AlbedoColor);
MKPBSData pbsData = ComputePBSData(surface, surfaceData);
Composite(surface, surfaceData, pbsData);
return 0;
}
#endif

View File

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

View File

@ -0,0 +1,19 @@
//////////////////////////////////////////////////////
// MK Toon Universal2D Setup //
// //
// Created by Michael Kremmel //
// www.michaelkremmel.de //
// Copyright © 2021 All rights reserved. //
//////////////////////////////////////////////////////
#ifndef MK_TOON_UNIVERSAL2D_SETUP
#define MK_TOON_UNIVERSAL2D_SETUP
#ifndef MK_UNIVERSAL2D_PASS
#define MK_UNIVERSAL2D_PASS
#endif
#include "../Core.hlsl"
#include "ProgramUniversal2D.hlsl"
#endif

View File

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

View File

@ -97,10 +97,8 @@ LightmapSettings:
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 112000000, guid: f66706ca7d892da4e9352c5cdc0b2932,
type: 2}
m_LightingSettings: {fileID: 4890085278179872738, guid: 82adcc5c04b15af44afe569caa21fa7e,
type: 2}
m_LightingDataAsset: {fileID: 112000000, guid: f66706ca7d892da4e9352c5cdc0b2932, type: 2}
m_LightingSettings: {fileID: 4890085278179872738, guid: 82adcc5c04b15af44afe569caa21fa7e, type: 2}
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
@ -173,10 +171,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_UiScaleMode: 1
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ReferenceResolution: {x: 1080, y: 1920}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
@ -236,6 +234,7 @@ GameObject:
m_Component:
- component: {fileID: 963194228}
- component: {fileID: 963194227}
- component: {fileID: 963194226}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
@ -243,6 +242,23 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &963194226
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8b9a305e18de0c04dbd257a21cd47087, type: 3}
m_Name:
m_EditorClassIdentifier:
sharedProfile: {fileID: 11400000, guid: 2de9544b84ed15540888b484d269757d, type: 2}
isGlobal: 0
blendDistance: 0
weight: 1
priority: 0
--- !u!20 &963194227
Camera:
m_ObjectHideFlags: 0

View File

@ -15,7 +15,7 @@ namespace AI
{
return;
}
while (foundPathIter < 3 && currentTile == null)
while (foundPathIter < 3 && currentTile != null)
{
if (currentTile.coordinates.Z == endTile.coordinates.Z)

View File

@ -16,7 +16,7 @@ public class MusicController
Instance ??= this;
_sources = new Dictionary<GameObject, AudioSource>();
}
public void SetMusicData(MusicData data)
{
_data = data;
@ -31,9 +31,11 @@ public class MusicController
public void PlayRandomClip(List<AudioClip> clips, GameObject source)
{
_sources[source].clip = clips[Random.Range(0, clips.Count - 1)];
_sources[source].volume = _data.Settings.sfxVolume;
_sources[source].Play();
if (!_sources.TryGetValue(source, out var value)) return;
value.clip = clips[Random.Range(0, clips.Count - 1)];
value.volume = _data.Settings.sfxVolume;
value.Play();
}
public void AddAudioListener(GameObject gameObject)
@ -49,7 +51,7 @@ public class MusicController
public void RemoveAudioSource(GameObject gameObject)
{
if(_sources.ContainsKey(gameObject))
if (_sources.ContainsKey(gameObject))
_sources.Remove(gameObject);
}
}

View File

@ -92,11 +92,9 @@ namespace Units
public void Move(HexDirection direction)
{
if (!_cell.GetNeighbor(direction) || _isBusy || _cell.GetNeighbor(direction).Color != UnitColor.GREY &&
HexManager.UnitCurrentCell[_cell.GetNeighbor(direction).Color].cell ==
_cell.GetNeighbor(direction)) return;
if (_data.isPlayer)
Debug.Log("Player");
(!HexManager.UnitCurrentCell.TryGetValue(_cell.GetNeighbor(direction).Color, out var value)
|| value.cell == _cell.GetNeighbor(direction))) return;
_unitView.StopHardCapture();
if (_cell.GetNeighbor(direction).Color == _data.color)
{

View File

@ -8,6 +8,7 @@
"com.unity.ide.rider": "2.0.7",
"com.unity.ide.visualstudio": "2.0.11",
"com.unity.ide.vscode": "1.2.3",
"com.unity.postprocessing": "3.1.1",
"com.unity.purchasing": "3.2.2",
"com.unity.test-framework": "1.1.27",
"com.unity.textmeshpro": "3.0.6",

View File

@ -78,6 +78,15 @@
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.postprocessing": {
"version": "3.1.1",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.modules.physics": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.purchasing": {
"version": "3.2.2",
"depth": 0,

View File

@ -617,7 +617,19 @@ PlayerSettings:
webGLThreadsSupport: 0
webGLDecompressionFallback: 0
scriptingDefineSymbols:
7: AH_SCRIPT_ALLOW
1: UNITY_POST_PROCESSING_STACK_V2
7: AH_SCRIPT_ALLOW;UNITY_POST_PROCESSING_STACK_V2
13: UNITY_POST_PROCESSING_STACK_V2
14: UNITY_POST_PROCESSING_STACK_V2
19: UNITY_POST_PROCESSING_STACK_V2
21: UNITY_POST_PROCESSING_STACK_V2
25: UNITY_POST_PROCESSING_STACK_V2
27: UNITY_POST_PROCESSING_STACK_V2
28: UNITY_POST_PROCESSING_STACK_V2
29: UNITY_POST_PROCESSING_STACK_V2
30: UNITY_POST_PROCESSING_STACK_V2
32: UNITY_POST_PROCESSING_STACK_V2
33: UNITY_POST_PROCESSING_STACK_V2
additionalCompilerArguments: {}
platformArchitecture: {}
scriptingBackend: {}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long