mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-07-18 16:21:50 -05:00
lighting, MTOON_FOG_AND_LIGHTING_COORDSからURP対応に関する知識を剥がす
This commit is contained in:
parent
d59342fb17
commit
8527fdd511
|
|
@ -25,19 +25,7 @@ struct Varyings
|
|||
#endif
|
||||
float3 viewDirWS : TEXCOORD4;
|
||||
|
||||
#ifdef MTOON_URP
|
||||
half4 fogFactorAndVertexLight : TEXCOORD5; // x: fogFactor, yzw: vertex light
|
||||
|
||||
#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
|
||||
MTOON_FOG_AND_LIGHTING_COORDS(5, 6, 7)
|
||||
|
||||
float4 pos : SV_POSITION; // UnityCG macro specified name. Accurately "positionCS"
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
|
|
|
|||
|
|
@ -1,12 +1,7 @@
|
|||
#ifndef VRMC_MATERIALS_MTOON_LIGHTING_MTOON_INCLUDED
|
||||
#define VRMC_MATERIALS_MTOON_LIGHTING_MTOON_INCLUDED
|
||||
|
||||
#ifdef MTOON_URP
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#else
|
||||
#include <UnityShaderVariables.cginc>
|
||||
#endif
|
||||
|
||||
#include "./vrmc_materials_mtoon_render_pipeline.hlsl"
|
||||
#include "./vrmc_materials_mtoon_define.hlsl"
|
||||
#include "./vrmc_materials_mtoon_utility.hlsl"
|
||||
#include "./vrmc_materials_mtoon_input.hlsl"
|
||||
|
|
@ -25,16 +20,9 @@ inline half GetMToonLighting_Reflectance_ShadingShift(const MToonInput input)
|
|||
{
|
||||
if (MToon_IsParameterMapOn())
|
||||
{
|
||||
#ifdef MTOON_URP
|
||||
return SAMPLE_TEXTURE2D(_ShadingShiftTex, sampler_ShadingShiftTex, input.uv).r * _ShadingShiftTexScale + _ShadingShiftFactor;
|
||||
#else
|
||||
return UNITY_SAMPLE_TEX2D(_ShadingShiftTex, input.uv).r * _ShadingShiftTexScale + _ShadingShiftFactor;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
return _ShadingShiftFactor;
|
||||
return MTOON_SAMPLE_TEXTURE2D(_ShadingShiftTex, input.uv).r * _ShadingShiftTexScale + _ShadingShiftFactor;
|
||||
}
|
||||
return _ShadingShiftFactor;
|
||||
}
|
||||
|
||||
inline half GetMToonLighting_DotNL(const UnityLighting lighting, const MToonInput input)
|
||||
|
|
@ -87,11 +75,7 @@ inline half GetMToonLighting_Shadow(const UnityLighting lighting, const half dot
|
|||
|
||||
inline half3 GetMToonLighting_DirectLighting(const UnityLighting unityLight, const MToonInput input, const half shade, const half shadow)
|
||||
{
|
||||
#ifdef MTOON_URP
|
||||
const half3 shadeColor = SAMPLE_TEXTURE2D(_ShadeTex, sampler_ShadeTex, input.uv).rgb * _ShadeColor.rgb;
|
||||
#else
|
||||
const half3 shadeColor = UNITY_SAMPLE_TEX2D(_ShadeTex, input.uv).rgb * _ShadeColor.rgb;
|
||||
#endif
|
||||
const half3 shadeColor = MTOON_SAMPLE_TEXTURE2D(_ShadeTex, input.uv).rgb * _ShadeColor.rgb;
|
||||
const half3 albedo = lerp(shadeColor, input.litColor, shade);
|
||||
|
||||
return albedo * unityLight.directLightColor * shadow;
|
||||
|
|
@ -115,21 +99,11 @@ inline half3 GetMToonLighting_Emissive(const MToonInput input)
|
|||
{
|
||||
if (MToon_IsEmissiveMapOn())
|
||||
{
|
||||
#ifdef MTOON_URP
|
||||
return SAMPLE_TEXTURE2D(_EmissionMap, sampler_EmissionMap, input.uv).rgb * _EmissionColor.rgb;
|
||||
#else
|
||||
return UNITY_SAMPLE_TEX2D(_EmissionMap, input.uv).rgb * _EmissionColor.rgb;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
return _EmissionColor.rgb;
|
||||
return MTOON_SAMPLE_TEXTURE2D(_EmissionMap, input.uv).rgb * _EmissionColor.rgb;
|
||||
}
|
||||
return _EmissionColor.rgb;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline half3 GetMToonLighting_Rim_Matcap(const MToonInput input)
|
||||
|
|
@ -142,16 +116,9 @@ inline half3 GetMToonLighting_Rim_Matcap(const MToonInput input)
|
|||
const half3 matcapUpAxisWS = normalize(cross(matcapRightAxisWS, input.viewDirWS));
|
||||
const half2 matcapUv = float2(dot(matcapRightAxisWS, input.normalWS), dot(matcapUpAxisWS, input.normalWS)) * 0.5 + 0.5;
|
||||
|
||||
#ifdef MTOON_URP
|
||||
return _MatcapColor.rgb * SAMPLE_TEXTURE2D(_MatcapTex, sampler_MatcapTex, matcapUv).rgb;
|
||||
#else
|
||||
return _MatcapColor.rgb * UNITY_SAMPLE_TEX2D(_MatcapTex, matcapUv).rgb;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
return _MatcapColor.rgb;
|
||||
return _MatcapColor.rgb * MTOON_SAMPLE_TEXTURE2D(_MatcapTex, matcapUv).rgb;
|
||||
}
|
||||
return _MatcapColor.rgb;
|
||||
}
|
||||
|
||||
inline half3 GetMToonLighting_Rim(const UnityLighting unityLight, const MToonInput input, const half shadow)
|
||||
|
|
@ -174,16 +141,9 @@ inline half3 GetMToonLighting_Rim(const UnityLighting unityLight, const MToonInp
|
|||
|
||||
if (MToon_IsRimMapOn())
|
||||
{
|
||||
#ifdef MTOON_URP
|
||||
return (matcapFactor + parametricRimFactor) * rimLightingFactor * SAMPLE_TEXTURE2D(_RimTex, sampler_RimTex, input.uv).rgb;
|
||||
#else
|
||||
return (matcapFactor + parametricRimFactor) * rimLightingFactor * UNITY_SAMPLE_TEX2D(_RimTex, input.uv).rgb;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
return (matcapFactor + parametricRimFactor) * rimLightingFactor;
|
||||
return (matcapFactor + parametricRimFactor) * rimLightingFactor * MTOON_SAMPLE_TEXTURE2D(_RimTex, input.uv).rgb;
|
||||
}
|
||||
return (matcapFactor + parametricRimFactor) * rimLightingFactor;
|
||||
}
|
||||
|
||||
half4 GetMToonLighting(const UnityLighting unityLight, const MToonInput input)
|
||||
|
|
@ -205,10 +165,7 @@ half4 GetMToonLighting(const UnityLighting unityLight, const MToonInput input)
|
|||
const half3 outlineCol = _OutlineColor.rgb * lerp(half3(1, 1, 1), baseCol, _OutlineLightingMix);
|
||||
return half4(outlineCol, input.alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
return half4(baseCol, input.alpha);
|
||||
}
|
||||
return half4(baseCol, input.alpha);
|
||||
}
|
||||
|
||||
#ifdef MTOON_URP
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef VRMC_MATERIALS_MTOON_RENDER_PIPELINE_INCLUDED
|
||||
#define VRMC_MATERIALS_MTOON_RENDER_PIPELINE_INCLUDED
|
||||
|
||||
// Include
|
||||
#ifdef MTOON_URP
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
|
||||
|
|
@ -12,6 +13,7 @@
|
|||
#include <UnityShaderVariables.cginc>
|
||||
#endif
|
||||
|
||||
// Texture
|
||||
#ifdef MTOON_URP
|
||||
#define MTOON_DECLARE_TEX2D(tex) TEXTURE2D_FLOAT(tex); SAMPLER(sampler##tex);
|
||||
#define MTOON_DECLARE_TEX2D_FLOAT(tex) TEXTURE2D(tex); SAMPLER(sampler##tex);
|
||||
|
|
@ -22,6 +24,31 @@
|
|||
#define MTOON_SAMPLE_TEXTURE2D(tex, uv) UNITY_SAMPLE_TEX2D(tex, uv)
|
||||
#endif
|
||||
|
||||
// Fog and lighting
|
||||
#ifdef MTOON_URP
|
||||
|
||||
#ifdef REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR
|
||||
|
||||
#define MTOON_FOG_AND_LIGHTING_COORDS(idx1, idx2, idx3) \
|
||||
half4 fogFactorAndVertexLight : TEXCOORD##idx1; \
|
||||
float4 shadowCoord : TEXCOORD##idx2; \
|
||||
DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, idx3);
|
||||
|
||||
#else
|
||||
|
||||
#define MTOON_FOG_AND_LIGHTING_COORDS(idx1, idx2, idx3) \
|
||||
half4 fogFactorAndVertexLight : TEXCOORD##idx1; \
|
||||
DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, idx);
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define MTOON_FOG_AND_LIGHTING_COORDS(idx1, idx2, idx3) \
|
||||
UNITY_FOG_COORDS(5) \
|
||||
UNITY_LIGHTING_COORDS(6,7)
|
||||
#endif
|
||||
|
||||
// Transform
|
||||
inline float3 MToon_TransformObjectToWorldNormal(float3 normalOS)
|
||||
{
|
||||
#ifdef MTOON_URP
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user