mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-26 04:39:51 -05:00
fix view vector is zero
This commit is contained in:
@@ -25,7 +25,7 @@ struct Varyings
|
||||
half4 tangentWS : TEXCOORD3;
|
||||
#endif
|
||||
float3 viewDirWS : TEXCOORD4;
|
||||
half outlineFactor : TEXCOORD5;
|
||||
// half outlineFactor : TEXCOORD5;
|
||||
UNITY_FOG_COORDS(6)
|
||||
UNITY_LIGHTING_COORDS(7,8)
|
||||
float4 pos : SV_POSITION; // UnityCG macro specified name. Accurately "positionCS"
|
||||
|
||||
@@ -47,10 +47,10 @@ half4 MToonFragment(const Varyings input) : SV_Target
|
||||
MToonInput mtoonInput;
|
||||
mtoonInput.uv = uv;
|
||||
mtoonInput.normalWS = normalWS;
|
||||
mtoonInput.viewDirWS = input.viewDirWS;
|
||||
mtoonInput.viewDirWS = normalize(input.viewDirWS);
|
||||
mtoonInput.litColor = litColor.rgb;
|
||||
mtoonInput.alpha = alpha;
|
||||
mtoonInput.outlineFactor = input.outlineFactor;
|
||||
// mtoonInput.outlineFactor = input.outlineFactor;
|
||||
const half4 col = GetMToonLighting(unityLighting, mtoonInput);
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, col);
|
||||
|
||||
@@ -17,16 +17,15 @@ Varyings MToonVertex(const Attributes v) // v is UnityCG macro specified name.
|
||||
UNITY_TRANSFER_INSTANCE_ID(v, output);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
output.uv = TRANSFORM_TEX(v.texcoord0, _MainTex);
|
||||
output.viewDirWS = MToon_GetWorldSpaceNormalizedViewDir(output.positionWS);
|
||||
|
||||
if (MToon_IsOutlinePass())
|
||||
{
|
||||
output.normalWS = UnityObjectToWorldNormal(-v.normalOS);
|
||||
const VertexPositionInfo position = MToon_GetOutlineVertex(v.vertex.xyz, normalize(v.normalOS), output.uv);
|
||||
output.pos = position.positionCS;
|
||||
output.positionWS = position.positionWS;
|
||||
output.outlineFactor = 1;
|
||||
output.viewDirWS = MToon_GetWorldSpaceNormalizedViewDir(output.positionWS);
|
||||
output.uv = TRANSFORM_TEX(v.texcoord0, _MainTex);
|
||||
// output.outlineFactor = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -34,7 +33,9 @@ Varyings MToonVertex(const Attributes v) // v is UnityCG macro specified name.
|
||||
const VertexPositionInfo position = MToon_GetVertex(v.vertex.xyz);
|
||||
output.pos = position.positionCS;
|
||||
output.positionWS = position.positionWS;
|
||||
output.outlineFactor = 0;
|
||||
output.viewDirWS = MToon_GetWorldSpaceNormalizedViewDir(output.positionWS);
|
||||
output.uv = TRANSFORM_TEX(v.texcoord0, _MainTex);
|
||||
// output.outlineFactor = 0;
|
||||
}
|
||||
|
||||
#if defined(_NORMALMAP)
|
||||
|
||||
@@ -14,7 +14,7 @@ struct MToonInput
|
||||
half3 viewDirWS;
|
||||
half3 litColor;
|
||||
half alpha;
|
||||
half outlineFactor;
|
||||
// half outlineFactor;
|
||||
};
|
||||
|
||||
inline half GetMToonLighting_Reflectance_ShadingShift(const MToonInput input)
|
||||
@@ -62,7 +62,6 @@ inline half3 GetMToonLighting_GlobalIllumination(const UnityLighting unityLight,
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline half3 GetMToonLighting_Emissive(const MToonInput input)
|
||||
@@ -94,12 +93,12 @@ inline half3 GetMToonLighting_Rim_Matcap(const MToonInput input)
|
||||
}
|
||||
}
|
||||
|
||||
inline half3 GetMToonLighting_Rim(const MToonInput input, const half3 lighting)
|
||||
inline half3 GetMToonLighting_Rim(const MToonInput input, const half3 reflectance)
|
||||
{
|
||||
if (MToon_IsForwardBasePass())
|
||||
{
|
||||
const half3 parametricRimFactor = pow(saturate(1.0 - dot(input.normalWS, input.viewDirWS) + _RimLift), _RimFresnelPower) * _RimColor.rgb;
|
||||
const half3 rimLightingFactor = lerp(half3(1, 1, 1), lighting, _RimLightingMix);
|
||||
const half3 rimLightingFactor = lerp(half3(1, 1, 1), reflectance, _RimLightingMix);
|
||||
const half3 matcapFactor = GetMToonLighting_Rim_Matcap(input);
|
||||
|
||||
if (MToon_IsRimMapOn())
|
||||
@@ -125,14 +124,19 @@ half4 GetMToonLighting(const UnityLighting unityLight, const MToonInput input)
|
||||
const half3 indirect = GetMToonLighting_GlobalIllumination(unityLight, input);
|
||||
const half3 lighting = direct + indirect;
|
||||
const half3 emissive = GetMToonLighting_Emissive(input);
|
||||
const half3 rim = GetMToonLighting_Rim(input, lighting);
|
||||
const half3 rim = GetMToonLighting_Rim(input, reflectance);
|
||||
|
||||
const half3 baseCol = lighting + emissive + rim;
|
||||
const half3 outlineCol = _OutlineColor.rgb * lerp(half3(1, 1, 1), baseCol, _OutlineLightingMix);
|
||||
|
||||
const half3 col = lerp(baseCol, outlineCol, input.outlineFactor);
|
||||
|
||||
return half4(col, input.alpha);
|
||||
if (MToon_IsOutlinePass())
|
||||
{
|
||||
const half3 outlineCol = _OutlineColor.rgb * lerp(half3(1, 1, 1), baseCol, _OutlineLightingMix);
|
||||
return half4(outlineCol, input.alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
return half4(baseCol, input.alpha);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user