mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-14 14:29:52 -05:00
ライトの取得をURPに対応
This commit is contained in:
parent
89431f6451
commit
0f0c8bba94
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <UnityCG.cginc>
|
||||
#include <AutoLight.cginc>
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user