summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--2ner.cginc20
-rw-r--r--2ner.shader2
-rw-r--r--interpolators.cginc3
-rw-r--r--tessellation.cginc1
-rw-r--r--yum_lighting.cginc51
5 files changed, 73 insertions, 4 deletions
diff --git a/2ner.cginc b/2ner.cginc
index 861cd16..1e6af31 100644
--- a/2ner.cginc
+++ b/2ner.cginc
@@ -198,6 +198,24 @@ v2f vert(appdata v) {
// Vertex color
o.color = v.color;
+
+ // Calculate vertex lights
+ #ifdef VERTEXLIGHT_ON
+ #if defined(_WRAPPED_LIGHTING)
+ o.vertexLight = Shade4PointLightsWrapped(
+ unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
+ unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
+ unity_4LightAtten0, o.worldPos, o.normal, _Wrap_NoL_Diffuse_Strength);
+ #else
+ o.vertexLight = Shade4PointLights(
+ unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
+ unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
+ unity_4LightAtten0, o.worldPos, o.normal);
+ #endif
+ #else
+ o.vertexLight = 0;
+ #endif
+
return o;
}
@@ -495,7 +513,7 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace
#ifdef LOD_FADE_CROSSFADE
UnityApplyDitherCrossFade(i.pos.xy);
#endif
-
+
// Output proper shadow data
SHADOW_CASTER_FRAGMENT(i)
#elif defined(MASKED_STENCIL1_PASS) || defined(MASKED_STENCIL2_PASS) || defined(MASKED_STENCIL3_PASS) || defined(MASKED_STENCIL4_PASS) || defined(DEPTH_PREPASS)
diff --git a/2ner.shader b/2ner.shader
index b769dff..71ff21a 100644
--- a/2ner.shader
+++ b/2ner.shader
@@ -2,7 +2,7 @@ Shader "yum_food/2ner"
{
// Certain parts of the Properties below are derived from Poiyomi's toon
// shader. The license is available in this repository at the top of
- // poi.cginc. C.
+ // poi.cginc.
Properties
{
[HideInInspector] shader_master_label("<color=#de719bff>2ner</color>", Float) = 0
diff --git a/interpolators.cginc b/interpolators.cginc
index 3a776df..e897e53 100644
--- a/interpolators.cginc
+++ b/interpolators.cginc
@@ -30,7 +30,8 @@ struct v2f {
float3 binormal : TEXCOORD6;
float4 eyeVec : TEXCOORD7; // eyeVec.xyz | fogCoord
float4 color : TEXCOORD8;
- UNITY_LIGHTING_COORDS(9,10)
+ float3 vertexLight : TEXCOORD9;
+ UNITY_LIGHTING_COORDS(10,11)
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
diff --git a/tessellation.cginc b/tessellation.cginc
index 24d53ab..a89ca66 100644
--- a/tessellation.cginc
+++ b/tessellation.cginc
@@ -171,6 +171,7 @@ v2f domain(
o.uv01 = DOMAIN_INTERP(uv01);
o.uv23 = DOMAIN_INTERP(uv23);
o.color = DOMAIN_INTERP(color);
+ o.vertexLight = DOMAIN_INTERP(vertexLight);
#if defined(_TESSELLATION) && defined(_SHATTER_WAVE)
#if defined(OUTLINE_PASS)
diff --git a/yum_lighting.cginc b/yum_lighting.cginc
index 423f4cf..80b1f66 100644
--- a/yum_lighting.cginc
+++ b/yum_lighting.cginc
@@ -11,6 +11,7 @@
#include "LightVolumes.cginc"
#include "poi.cginc"
#include "yum_pbr.cginc"
+#include "math.cginc"
// fucking kill me
#ifndef __LTCGI_INC
@@ -44,6 +45,54 @@ void ltcgi_cb_specular(inout ltcgi_acc acc, in ltcgi_output output) {
#endif // __LTCGI_INC
+float3 Shade4PointLightsWrapped(
+ float4 lightPosX, float4 lightPosY, float4 lightPosZ,
+ float3 lightColor0, float3 lightColor1, float3 lightColor2, float3 lightColor3,
+ float4 lightAttenSq,
+ float3 pos, float3 normal, float wrapStrength)
+{
+ // to light vectors
+ float4 toLightX = lightPosX - pos.x;
+ float4 toLightY = lightPosY - pos.y;
+ float4 toLightZ = lightPosZ - pos.z;
+
+ // squared lengths
+ float4 lengthSq = 0;
+ lengthSq += toLightX * toLightX;
+ lengthSq += toLightY * toLightY;
+ lengthSq += toLightZ * toLightZ;
+
+ // NdotL
+ float4 ndotl = 0;
+ ndotl += toLightX * normal.x;
+ ndotl += toLightY * normal.y;
+ ndotl += toLightZ * normal.z;
+
+ // correct NdotL
+ float4 corr = rsqrt(lengthSq);
+ ndotl = ndotl * corr;
+
+ // Apply wrapped lighting
+ float4 wrappedNdotl;
+ wrappedNdotl.x = saturate(wrapNoL(ndotl.x, wrapStrength));
+ wrappedNdotl.y = saturate(wrapNoL(ndotl.y, wrapStrength));
+ wrappedNdotl.z = saturate(wrapNoL(ndotl.z, wrapStrength));
+ wrappedNdotl.w = saturate(wrapNoL(ndotl.w, wrapStrength));
+
+ // attenuation
+ float4 atten = 1.0 / (1.0 + lengthSq * lightAttenSq);
+ float4 diff = wrappedNdotl * atten;
+
+ // final color
+ float3 col = 0;
+ col += lightColor0 * diff.x;
+ col += lightColor1 * diff.y;
+ col += lightColor2 * diff.z;
+ col += lightColor3 * diff.w;
+
+ return col;
+}
+
struct YumLighting {
float3 view_dir;
float3 dir;
@@ -300,7 +349,7 @@ YumLighting GetYumLighting(v2f i, YumPbr pbr) {
light.diffuse.gb = light.diffuse.r;
#endif
#else
- light.diffuse = getIndirectDiffuse(i, 0, light);
+ light.diffuse = getIndirectDiffuse(i, float4(i.vertexLight, 0), light);
light.occlusion = 1;
#endif