From a54b415ab89302cf1f74f78360595ec0eff8fc7b Mon Sep 17 00:00:00 2001 From: yum Date: Tue, 20 Jan 2026 22:15:09 -0800 Subject: Push eyeVec into fragment --- 2ner.cginc | 10 +++++----- fog.cginc | 4 ++-- glitter.cginc | 4 ++-- interpolators.cginc | 11 ++++++----- matcaps.cginc | 8 ++++---- tessellation.cginc | 2 -- yum_lighting.cginc | 2 +- yum_pbr.cginc | 4 ++-- 8 files changed, 22 insertions(+), 23 deletions(-) diff --git a/2ner.cginc b/2ner.cginc index 5439556..736210f 100644 --- a/2ner.cginc +++ b/2ner.cginc @@ -187,8 +187,6 @@ v2f vert(appdata v) { #endif o.worldPos = mul(unity_ObjectToWorld, v.vertex); o.objPos = v.vertex; - o.eyeVec.xyz = o.worldPos - _WorldSpaceCameraPos; - o.eyeVec.w = 1; // These are used to convert normals from tangent space to world space. o.normal = v.normal; @@ -294,6 +292,8 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace f2f f = (f2f) 0; f.binormal = cross(i.tangent, i.normal); + f.eyeVec = i.worldPos - _WorldSpaceCameraPos; + f.viewDir = normalize(f.eyeVec); #if defined(_RAYMARCHED_FOG) { @@ -343,7 +343,7 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace _Raymarched_Fog_Density_Exponent, #endif }; - FogResult fog_result = raymarched_fog(i, fog_params); + FogResult fog_result = raymarched_fog(i, f, fog_params); depth = fog_result.depth; return fog_result.color; } @@ -441,7 +441,7 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace float2 debug; ssao = get_ssao(i, tangentToWorld, debug); #endif - YumPbr pbr = GetYumPbr(i, tangentToWorld); + YumPbr pbr = GetYumPbr(i, f, tangentToWorld); pbr.albedo.rgb *= ssao; #if defined(META_PASS) @@ -526,7 +526,7 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace YumLighting l = GetYumLighting(i, f, pbr); #if defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS) - applyMatcapsAndRimLighting(i, pbr, l); + applyMatcapsAndRimLighting(i, f, pbr, l); l.diffuse = max(0, l.diffuse); l.specular = max(0, l.specular); #endif diff --git a/fog.cginc b/fog.cginc index 1dd91d4..82a373d 100644 --- a/fog.cginc +++ b/fog.cginc @@ -110,10 +110,10 @@ float3 aces_filmic(float3 x) { return saturate((x*(a*x+b))/(x*(c*x+d)+e)); } -FogResult raymarched_fog(v2f i, FogParams p) +FogResult raymarched_fog(v2f i, f2f f, FogParams p) { float3 ro = _WorldSpaceCameraPos; - float3 rd = normalize(i.eyeVec.xyz); + float3 rd = f.viewDir; const float ro_epsilon = 1E-3; ro += rd * ro_epsilon; diff --git a/glitter.cginc b/glitter.cginc index e8df133..dc353df 100644 --- a/glitter.cginc +++ b/glitter.cginc @@ -35,7 +35,7 @@ static const float2 glitter_offset_vectors[6] = { }; -float4 getGlitter(v2f i, GlitterParams params, float3 normal) { +float4 getGlitter(v2f i, f2f f, GlitterParams params, float3 normal) { float c_acc = 0; [loop] for (uint layer_i = 0; layer_i < params.layers; layer_i++) { @@ -71,7 +71,7 @@ float4 getGlitter(v2f i, GlitterParams params, float3 normal) { c_acc = c + (1 - c) * c_acc; } #if defined(_GLITTER_ANGLE_LIMIT) - float VdotN = dot(-normalize(i.eyeVec.xyz), normal); + float VdotN = dot(-f.viewDir, normal); float angle_mask = smoothstep( cos(params.angle_limit * PI), cos(params.angle_limit * (1 - params.angle_limit_transition_width) * PI), diff --git a/interpolators.cginc b/interpolators.cginc index 9449de7..bb08c4e 100644 --- a/interpolators.cginc +++ b/interpolators.cginc @@ -27,16 +27,15 @@ struct v2f { float3 worldPos : TEXCOORD3; float3 normal : TEXCOORD4; float3 tangent : TEXCOORD5; - float4 eyeVec : TEXCOORD6; // eyeVec.xyz | fogCoord - float4 vertexLight : TEXCOORD7; // vertexLight.xyz | furLayer - UNITY_LIGHTING_COORDS(8,9) + float4 vertexLight : TEXCOORD6; // vertexLight.xyz | furLayer + UNITY_LIGHTING_COORDS(7,8) #if defined(V2F_ORIG_POS) - float3 orig_pos : TEXCOORD10; + float3 orig_pos : TEXCOORD9; #endif #if defined(V2F_COLOR) - float4 color : TEXCOORD11; + float4 color : TEXCOORD10; #endif UNITY_VERTEX_INPUT_INSTANCE_ID @@ -46,6 +45,8 @@ struct v2f { // Fragment shader common data (fragment 2 fragment) struct f2f { float3 binormal; + float3 eyeVec; + float3 viewDir; }; #endif // __INTERPOLATORS_INC diff --git a/matcaps.cginc b/matcaps.cginc index 6c84e54..067e322 100644 --- a/matcaps.cginc +++ b/matcaps.cginc @@ -8,9 +8,9 @@ #include "yum_pbr.cginc" #if defined(_MATCAP0) || defined(_MATCAP1) || defined(_MATCAP2) || defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1) || defined(_RIM_LIGHTING2) || defined(_RIM_LIGHTING3) -float2 getMatcapUV(v2f i, inout YumPbr pbr) { +float2 getMatcapUV(v2f i, f2f f, inout YumPbr pbr) { const float3 cam_normal = normalize(mul(UNITY_MATRIX_V, float4(pbr.normal, 0))); - const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(-i.eyeVec.xyz, 0))); + const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(-f.eyeVec, 0))); const float3 cam_refl = -reflect(cam_view_dir, cam_normal); float m = 2.0 * sqrt( cam_refl.x * cam_refl.x + @@ -68,9 +68,9 @@ float getAngleAttenuation(float2 muv, float2 target_vector, float power) { return pow(NoL, power); } -void applyMatcapsAndRimLighting(v2f i, inout YumPbr pbr, inout YumLighting l) { +void applyMatcapsAndRimLighting(v2f i, f2f f, inout YumPbr pbr, inout YumLighting l) { #if defined(_MATCAP0) || defined(_MATCAP1) || defined(_MATCAP2) || defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1) || defined(_RIM_LIGHTING2) || defined(_RIM_LIGHTING3) - float2 muv = getMatcapUV(i, pbr); + float2 muv = getMatcapUV(i, f, pbr); #endif #if defined(_MATCAP0) #if defined(_MATCAP0_QUANTIZATION) diff --git a/tessellation.cginc b/tessellation.cginc index e3bccb2..a80bf9c 100644 --- a/tessellation.cginc +++ b/tessellation.cginc @@ -195,8 +195,6 @@ v2f domain( o.pos = UnityObjectToClipPos(o.objPos); o.worldPos = mul(unity_ObjectToWorld, o.objPos).xyz; - o.eyeVec.xyz = o.worldPos - _WorldSpaceCameraPos; - o.eyeVec.w = 1; //UNITY_TRANSFER_LIGHTING(o, v); UNITY_TRANSFER_INSTANCE_ID(patch[0], o); diff --git a/yum_lighting.cginc b/yum_lighting.cginc index 846775c..64c3c1d 100644 --- a/yum_lighting.cginc +++ b/yum_lighting.cginc @@ -337,7 +337,7 @@ YumLighting GetYumLighting(v2f i, f2f f, YumPbr pbr) { YumLighting light = (YumLighting) 0; // normalize has no visibile impact in test scene - light.view_dir = -normalize(i.eyeVec.xyz); + light.view_dir = -f.viewDir; light.dir = getDirectLightDirection(i); diff --git a/yum_pbr.cginc b/yum_pbr.cginc index e19c931..ef07553 100644 --- a/yum_pbr.cginc +++ b/yum_pbr.cginc @@ -137,7 +137,7 @@ void applySeaFoam(v2f i, inout YumPbr pbr) { } #endif -YumPbr GetYumPbr(v2f i, float3x3 tangentToWorld) { +YumPbr GetYumPbr(v2f i, f2f f, float3x3 tangentToWorld) { YumPbr result = (YumPbr)0; #if defined(_FUR) @@ -293,7 +293,7 @@ YumPbr GetYumPbr(v2f i, float3x3 tangentToWorld) { #if defined(_GLITTER_MASK) glitter_p.mask = _Glitter_Mask.SampleLevel(linear_repeat_s, i.uv01.xy, 0); #endif - float4 glitter_albedo = getGlitter(i, glitter_p, result.normal); + float4 glitter_albedo = getGlitter(i, f, glitter_p, result.normal); result.albedo = alphaBlend(result.albedo, glitter_albedo); result.emission += glitter_albedo.rgb * glitter_albedo.a * _Glitter_Emission; -- cgit v1.2.3