From cc691f24bcd2db7f828699f5bed13d643559be13 Mon Sep 17 00:00:00 2001 From: notargs Date: Tue, 25 Apr 2023 13:10:53 +0900 Subject: [PATCH] =?UTF-8?q?Transform=E3=82=92URP=E3=81=AB=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vrmc_materials_mtoon_forward_vertex.hlsl | 10 +++++ .../vrmc_materials_mtoon_geometry_vertex.hlsl | 38 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_vertex.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_vertex.hlsl index 316e9b562..17c2984ad 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_vertex.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_vertex.hlsl @@ -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); diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_vertex.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_vertex.hlsl index 032ba2d42..0e8210fed 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_vertex.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_vertex.hlsl @@ -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 @@ -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; }