From caf02458737f93b20978f41613ad5b56e074e154 Mon Sep 17 00:00:00 2001 From: yum Date: Wed, 12 Feb 2025 01:24:49 -0800 Subject: Add a bunch of features * stereo instancing * outlines * shadows (casting & receiving) * unity fog * blend modes * wrapped lighting (generalized half lambertian) * diffuse & specular have independent knobs Also: * fix bug where shadow caster wouldn't clip in cutout mode. * remove a bunch of unused params * use ifex to minimize size of locked materials (more to be done probably) * improve formatting --- 2ner.cginc | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to '2ner.cginc') diff --git a/2ner.cginc b/2ner.cginc index 656e79f..47ff710 100644 --- a/2ner.cginc +++ b/2ner.cginc @@ -4,6 +4,7 @@ #include "UnityCG.cginc" #include "UnityLightingCommon.cginc" +#include "features.cginc" #include "globals.cginc" #include "interpolators.cginc" #include "poi.cginc" @@ -14,31 +15,63 @@ v2f vert (appdata v) { v2f o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#if defined(OUTLINE_PASS) +#if defined(_OUTLINE_MASK) + float thickness = _Outline_Mask.SampleLevel(linear_repeat_s, v.uv, 0); +#else + float thickness = 1; +#endif + v.vertex.xyz += _Outline_Width * v.normal * thickness; + v.normal *= -1; + v.tangent *= -1; +#endif // OUTLINE_PASS o.pos = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); o.worldPos = mul(unity_ObjectToWorld, v.vertex); + o.eyeVec.xyz = normalize(o.worldPos - _WorldSpaceCameraPos); // Calculate TBN matrix o.normal = UnityObjectToWorldNormal(v.normal); o.tangent = UnityObjectToWorldDir(v.tangent.xyz); o.bitangent = cross(o.normal, o.tangent) * v.tangent.w; + UNITY_TRANSFER_LIGHTING(o, v.uv1); + UNITY_TRANSFER_FOG_COMBINED_WITH_EYE_VEC(o, o.pos); +#if defined(SHADOW_CASTER_PASS) + TRANSFER_SHADOW_CASTER_NORMALOFFSET(o); +#endif return o; } float4 frag (v2f i) : SV_Target { + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + YumPbr pbr = GetYumPbr(i); UNITY_BRANCH - if (_Mode == 1) { - clip(pbr.albedo.a - _Clip); - } + if (_Mode == 1) { + clip(pbr.albedo.a - _Clip); + pbr.albedo.a = 1; + } +#if defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS) || defined(OUTLINE_PASS) YumLighting l = GetYumLighting(i, pbr); float4 lit = YumBRDF(i, l, pbr); + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG(_unity_fogCoord, lit.rgb); return lit; +#elif defined(SHADOW_CASTER_PASS) + return 0; +#endif } #endif // __2NER_INC -- cgit v1.2.3