mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-14 06:19:47 -05:00
TransformをURPに対応
This commit is contained in:
parent
31e57de03b
commit
cc691f24bc
|
|
@ -29,14 +29,24 @@ Varyings MToonVertex(const Attributes v) // v is UnityCG macro specified name.
|
|||
const VertexPositionInfo position = MToon_GetOutlineVertex(v.vertex.xyz, normalize(v.normalOS), output.uv);
|
||||
output.pos = position.positionCS;
|
||||
output.positionWS = position.positionWS;
|
||||
|
||||
#ifdef MTOON_URP
|
||||
output.normalWS = TransformObjectToWorldNormal(-v.normalOS);
|
||||
#else
|
||||
output.normalWS = UnityObjectToWorldNormal(-v.normalOS);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
const VertexPositionInfo position = MToon_GetVertex(v.vertex.xyz);
|
||||
output.pos = position.positionCS;
|
||||
output.positionWS = position.positionWS;
|
||||
|
||||
#ifdef MTOON_URP
|
||||
output.normalWS = TransformObjectToWorldNormal(v.normalOS);
|
||||
#else
|
||||
output.normalWS = UnityObjectToWorldNormal(v.normalOS);
|
||||
#endif
|
||||
}
|
||||
|
||||
output.viewDirWS = MToon_GetWorldSpaceNormalizedViewDir(output.positionWS);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define VRMC_MATERIALS_MTOON_GEOMETRY_VERTEX_INCLUDED
|
||||
|
||||
#ifdef MTOON_URP
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#else
|
||||
#include <UnityCG.cginc>
|
||||
|
|
@ -54,12 +55,25 @@ inline VertexPositionInfo MToon_GetOutlineVertex(const float3 positionOS, const
|
|||
if (MToon_IsOutlineModeWorldCoordinates())
|
||||
{
|
||||
const float3 positionWS = mul(unity_ObjectToWorld, float4(positionOS, 1)).xyz;
|
||||
|
||||
#ifdef MTOON_URP
|
||||
const half3 normalWS = TransformObjectToWorldNormal(normalOS);
|
||||
#else
|
||||
const half3 normalWS = UnityObjectToWorldNormal(normalOS);
|
||||
#endif
|
||||
|
||||
const half outlineWidth = MToon_GetOutlineVertex_OutlineWidth(uv);
|
||||
|
||||
VertexPositionInfo output;
|
||||
output.positionWS = float4(positionWS + normalWS * outlineWidth, 1);
|
||||
|
||||
#ifdef MTOON_URP
|
||||
output.positionCS = TransformWorldToHClip(output.positionWS);
|
||||
#else
|
||||
output.positionCS = UnityWorldToClipPos(output.positionWS);
|
||||
#endif
|
||||
|
||||
|
||||
return output;
|
||||
}
|
||||
else if (MToon_IsOutlineModeScreenCoordinates())
|
||||
|
|
@ -70,9 +84,20 @@ inline VertexPositionInfo MToon_GetOutlineVertex(const float3 positionOS, const
|
|||
const float4 nearUpperRight = mul(unity_CameraInvProjection, float4(1, 1, UNITY_NEAR_CLIP_VALUE, _ProjectionParams.y));
|
||||
const half aspect = abs(nearUpperRight.y / nearUpperRight.x);
|
||||
|
||||
#ifdef MTOON_URP
|
||||
const float4 positionCS = TransformObjectToHClip(positionOS);
|
||||
#else
|
||||
const float4 positionCS = UnityObjectToClipPos(positionOS);
|
||||
#endif
|
||||
|
||||
const half3 normalVS = MToon_GetObjectToViewNormal(normalOS);
|
||||
|
||||
#ifdef MTOON_URP
|
||||
const half3 normalWS = TransformObjectToWorldNormal(normalOS.xyz);
|
||||
const half3 normalCS = TransformWorldToHClipDir(normalWS.xyz);
|
||||
#else
|
||||
const half3 normalCS = TransformViewToProjection(normalVS.xyz);
|
||||
#endif
|
||||
|
||||
half2 normalProjectedCS = normalize(normalCS.xy);
|
||||
const float clipSpaceHeight = 2.0f;
|
||||
|
|
@ -90,7 +115,13 @@ inline VertexPositionInfo MToon_GetOutlineVertex(const float3 positionOS, const
|
|||
{
|
||||
VertexPositionInfo output;
|
||||
output.positionWS = mul(unity_ObjectToWorld, float4(positionOS * 0.001, 1));
|
||||
|
||||
#ifdef MTOON_URP
|
||||
output.positionCS = TransformWorldToHClip(output.positionWS);
|
||||
#else
|
||||
output.positionCS = UnityWorldToClipPos(output.positionWS);
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
|
@ -99,7 +130,14 @@ inline VertexPositionInfo MToon_GetVertex(const float3 positionOS)
|
|||
{
|
||||
VertexPositionInfo output;
|
||||
output.positionWS = mul(unity_ObjectToWorld, float4(positionOS, 1));
|
||||
|
||||
#ifdef MTOON_URP
|
||||
output.positionCS = TransformWorldToHClip(output.positionWS);
|
||||
#else
|
||||
output.positionCS = UnityWorldToClipPos(output.positionWS);
|
||||
#endif
|
||||
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user