From 0f0c8bba9439e6bab832f5dcd756f2d2f97be4b4 Mon Sep 17 00:00:00 2001 From: notargs Date: Wed, 26 Apr 2023 11:07:27 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=A9=E3=82=A4=E3=83=88=E3=81=AE=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=82=92URP=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VRM10/vrmc_materials_mtoon_attribute.hlsl | 13 +++++++--- .../vrmc_materials_mtoon_forward_vertex.hlsl | 16 +++++++++--- .../vrmc_materials_mtoon_lighting_unity.hlsl | 26 +++++++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_attribute.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_attribute.hlsl index ca16186de..564cafca8 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_attribute.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_attribute.hlsl @@ -30,12 +30,19 @@ struct Varyings #endif float3 viewDirWS : TEXCOORD4; - #ifdef MTOON_URP +#ifdef MTOON_URP half4 fogFactorAndVertexLight : TEXCOORD5; // x: fogFactor, yzw: vertex light - #else + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD6; + #endif + + DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 7); + +#else UNITY_FOG_COORDS(5) UNITY_LIGHTING_COORDS(6,7) - #endif +#endif float4 pos : SV_POSITION; // UnityCG macro specified name. Accurately "positionCS" UNITY_VERTEX_INPUT_INSTANCE_ID 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 2420d9971..3419a1113 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 @@ -57,14 +57,24 @@ Varyings MToonVertex(const Attributes v) // v is UnityCG macro specified name. output.tangentWS = half4(UnityObjectToWorldDir(v.tangentOS), tangentSign); #endif - #ifdef MTOON_URP +#ifdef MTOON_URP + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + + OUTPUT_LIGHTMAP_UV(input.texcoord1, unity_LightmapST, output.lightmapUV); + OUTPUT_SH(output.normalWS.xyz, output.vertexSH); + half3 vertexLight = VertexLighting(output.positionWS, output.normalWS); half fogFactor = ComputeFogFactor(output.pos.z); output.fogFactorAndVertexLight = half4(fogFactor, vertexLight); - #else + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + output.shadowCoord = GetShadowCoord(vertexInput); + #endif + +#else UNITY_TRANSFER_FOG(output, output.pos); UNITY_TRANSFER_LIGHTING(output, v.texcoord1.xy); - #endif +#endif return output; } diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_unity.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_unity.hlsl index 9d3e8c9eb..b2cae2c93 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_unity.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_unity.hlsl @@ -3,6 +3,7 @@ #ifdef MTOON_URP #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" +#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" #else #include #include @@ -24,16 +25,41 @@ struct UnityLighting UnityLighting GetUnityLighting(const Varyings input, const half3 normalWS) { +#ifdef MTOON_URP + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord = input.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + float4 shadowCoord = TransformWorldToShadowCoord(inputData.positionWS); + #else + float4 shadowCoord = float4(0, 0, 0, 0); + #endif + + float shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV); + Light mainLight = GetMainLight(shadowCoord, input.positionWS, shadowMask); + + const half3 lightDir = mainLight.direction; + const half3 lightColor = mainLight.color.rgb; + + float atten = mainLight.shadowAttenuation; + +#else UNITY_LIGHT_ATTENUATION(atten, input, input.positionWS); const half3 lightDir = normalize(UnityWorldSpaceLightDir(input.positionWS)); const half3 lightColor = _LightColor0.rgb; +#endif + if (MToon_IsForwardBasePass()) { UnityLighting output; +#ifdef MTOON_URP + output.indirectLight = SampleSH(normalWS); + output.indirectLightEqualized = (SampleSH(half3(0, 1, 0)) + SampleSH(half3(0, -1, 0))) * 0.5; +#else output.indirectLight = ShadeSH9(half4(normalWS, 1)); output.indirectLightEqualized = (ShadeSH9(half4(0, 1, 0, 1)) + ShadeSH9(half4(0, -1, 0, 1))) * 0.5; +#endif output.directLightColor = lightColor; output.directLightDirection = lightDir; output.directLightAttenuation = atten;