mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-14 14:29:52 -05:00
Refactoring
This commit is contained in:
parent
2b8295d5d4
commit
fd52ae2af4
|
|
@ -24,4 +24,14 @@ inline bool MToon_IsUvAnimationOn()
|
|||
#endif
|
||||
}
|
||||
|
||||
// Compile-time constant
|
||||
inline bool MToon_IsNormalMapOn()
|
||||
{
|
||||
#if defined(_NORMALMAP)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,14 +6,15 @@
|
|||
#include "./vrmc_materials_mtoon_utility.hlsl"
|
||||
#include "./vrmc_materials_mtoon_input.hlsl"
|
||||
#include "./vrmc_materials_mtoon_attribute.hlsl"
|
||||
#include "./vrmc_materials_mtoon_lighting.hlsl"
|
||||
#include "./vrmc_materials_mtoon_uv.hlsl"
|
||||
#include "./vrmc_materials_mtoon_unity_lighting.hlsl"
|
||||
#include "./vrmc_materials_mtoon_geometry_uv.hlsl"
|
||||
#include "./vrmc_materials_mtoon_geometry_normal.hlsl"
|
||||
#include "./vrmc_materials_mtoon_lighting_unity.hlsl"
|
||||
#include "./vrmc_materials_mtoon_lighting_mtoon.hlsl"
|
||||
|
||||
half4 MToonFragment(const Varyings input) : SV_Target
|
||||
{
|
||||
// Get MToon UV (with UVAnimation)
|
||||
const float2 uv = GetMToonUv(input.uv);
|
||||
const float2 uv = GetMToonGeometry_Uv(input.uv);
|
||||
|
||||
// Get LitColor with Alpha
|
||||
const half4 litColor = UNITY_SAMPLE_TEX2D(_MainTex, uv) * _Color;
|
||||
|
|
@ -31,13 +32,8 @@ half4 MToonFragment(const Varyings input) : SV_Target
|
|||
const half alpha = 1.0;
|
||||
#endif
|
||||
|
||||
// Get Normal in WorldSpace from Normalmap if available
|
||||
#if defined(_NORMALMAP)
|
||||
const half3 normalTS = normalize(UnpackNormalWithScale(UNITY_SAMPLE_TEX2D(_BumpMap, uv), _BumpScale));
|
||||
const half3 normalWS = normalize(mul(normalTS, MToon_GetTangentToWorld(input.normalWS, input.tangentWS)));
|
||||
#else
|
||||
const half3 normalWS = normalize(input.normalWS);
|
||||
#endif
|
||||
// Get Normal
|
||||
const float3 normalWS = GetMToonGeometry_Normal(input, uv);
|
||||
|
||||
// Get Unity Lighting
|
||||
const UnityLighting unityLighting = GetUnityLighting(input, normalWS);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef VRMC_MATERIALS_MTOON_GEOMETRY_NORMAL_INCLUDED
|
||||
#define VRMC_MATERIALS_MTOON_GEOMETRY_NORMAL_INCLUDED
|
||||
|
||||
#include <UnityCG.cginc>
|
||||
#include "./vrmc_materials_mtoon_define.hlsl"
|
||||
#include "./vrmc_materials_mtoon_utility.hlsl"
|
||||
#include "./vrmc_materials_mtoon_input.hlsl"
|
||||
|
||||
inline float3 GetMToonGeometry_NormalWithoutNormalMap(const half3 normalWS)
|
||||
{
|
||||
return normalize(normalWS);
|
||||
}
|
||||
|
||||
inline float3 GetMToonGeometry_Normal(const Varyings input, const float2 mtoonUv)
|
||||
{
|
||||
#if defined(_NORMALMAP)
|
||||
// Get Normal in WorldSpace from Normalmap if available
|
||||
const half3 normalTS = normalize(UnpackNormalWithScale(UNITY_SAMPLE_TEX2D(_BumpMap, mtoonUv), _BumpScale));
|
||||
return normalize(mul(normalTS, MToon_GetTangentToWorld(input.normalWS, input.tangentWS)));
|
||||
#else
|
||||
return GetMToonGeometry_NormalWithoutNormalMap(input.normalWS);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5ddfcfc47ee84eed9365b902bf76ce75
|
||||
timeCreated: 1622633324
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
#ifndef VRMC_MATERIALS_MTOON_UV_INCLUDED
|
||||
#define VRMC_MATERIALS_MTOON_UV_INCLUDED
|
||||
#ifndef VRMC_MATERIALS_MTOON_GEOMETRY_UV_INCLUDED
|
||||
#define VRMC_MATERIALS_MTOON_GEOMETRY_UV_INCLUDED
|
||||
|
||||
#include <UnityCG.cginc>
|
||||
#include "./vrmc_materials_mtoon_define.hlsl"
|
||||
#include "./vrmc_materials_mtoon_utility.hlsl"
|
||||
#include "./vrmc_materials_mtoon_input.hlsl"
|
||||
|
||||
float2 GetMToonUv(const float2 geometryUv)
|
||||
float2 GetMToonGeometry_Uv(const float2 geometryUv)
|
||||
{
|
||||
// get raw uv with _MainTex_ST
|
||||
const float2 uvRaw = TRANSFORM_TEX(geometryUv, _MainTex);
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
#ifndef VRMC_MATERIALS_MTOON_LIGHTING_INCLUDED
|
||||
#define VRMC_MATERIALS_MTOON_LIGHTING_INCLUDED
|
||||
#ifndef VRMC_MATERIALS_MTOON_LIGHTING_MTOON_INCLUDED
|
||||
#define VRMC_MATERIALS_MTOON_LIGHTING_MTOON_INCLUDED
|
||||
|
||||
#include <UnityShaderVariables.cginc>
|
||||
#include "./vrmc_materials_mtoon_define.hlsl"
|
||||
#include "./vrmc_materials_mtoon_utility.hlsl"
|
||||
#include "./vrmc_materials_mtoon_input.hlsl"
|
||||
#include "./vrmc_materials_mtoon_unity_lighting.hlsl"
|
||||
#include "./vrmc_materials_mtoon_lighting_unity.hlsl"
|
||||
|
||||
struct MToonInput
|
||||
{
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef VRMC_MATERIALS_MTOON_UNITY_LIGHTING_INCLUDED
|
||||
#define VRMC_MATERIALS_MTOON_UNITY_LIGHTING_INCLUDED
|
||||
#ifndef VRMC_MATERIALS_MTOON_LIGHTING_UNITY_INCLUDED
|
||||
#define VRMC_MATERIALS_MTOON_LIGHTING_UNITY_INCLUDED
|
||||
|
||||
#include <UnityCG.cginc>
|
||||
#include <AutoLight.cginc>
|
||||
#include <Lighting.cginc>
|
||||
#include "./vrmc_materials_mtoon_utility.hlsl"
|
||||
#include "./vrmc_materials_mtoon_define.hlsl"
|
||||
#include "./vrmc_materials_mtoon_input.hlsl"
|
||||
#include "./vrmc_materials_mtoon_attribute.hlsl"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user