Separate compile-time define

This commit is contained in:
Masataka SUMI
2021-06-02 20:25:07 +09:00
parent e6d5b4d653
commit 2b8295d5d4
7 changed files with 50 additions and 40 deletions

View File

@@ -1,42 +1,6 @@
#ifndef VRMC_MATERIALS_MTOON_DEFINE_INCLUDED
#define VRMC_MATERIALS_MTOON_DEFINE_INCLUDED
// define
static const float PI_2 = 6.28318530718;
static const float EPS_COL = 0.00001;
inline half3 mtoon_linearstep(const half3 start, const half3 end, const half t)
{
return min(max((t - start) / (end - start), 0.0), 1.0);
}
inline bool MToon_IsPerspective()
{
return unity_OrthoParams.w != 1.0;
}
inline float3 MToon_GetWorldSpaceNormalizedViewDir(const float3 positionWS)
{
if (MToon_IsPerspective())
{
return normalize(_WorldSpaceCameraPos.xyz - positionWS);
}
else
{
return normalize(UNITY_MATRIX_V[2].xyz);
}
}
inline half3x3 MToon_GetTangentToWorld(const half3 normalWS, const half4 tangentWS)
{
const half3 normalizedNormalWS = normalize(normalWS);
const half3 normalizedTangentWS = normalize(tangentWS.xyz);
const half3 normalizedBitangentWS = normalize(tangentWS.w * cross(normalizedNormalWS, normalizedTangentWS));
return half3x3(normalizedTangentWS, normalizedBitangentWS, normalizedNormalWS);
}
// Compile-time constant
inline bool MToon_IsForwardBasePass()
{

View File

@@ -2,9 +2,8 @@
#define VRMC_MATERIALS_MTOON_FORWARD_FRAGMENT_INCLUDED
#include <UnityCG.cginc>
#include <AutoLight.cginc>
#include "./vrmc_materials_mtoon_define.hlsl"
#include "./vrmc_materials_mtoon_utility.hlsl"
#include "./vrmc_materials_mtoon_input.hlsl"
#include "./vrmc_materials_mtoon_attribute.hlsl"
#include "./vrmc_materials_mtoon_lighting.hlsl"

View File

@@ -3,8 +3,7 @@
#include <UnityCG.cginc>
#include <AutoLight.cginc>
#include "./vrmc_materials_mtoon_define.hlsl"
#include "./vrmc_materials_mtoon_utility.hlsl"
#include "./vrmc_materials_mtoon_input.hlsl"
#include "./vrmc_materials_mtoon_attribute.hlsl"

View File

@@ -1,7 +1,9 @@
#ifndef VRMC_MATERIALS_MTOON_LIGHTING_INCLUDED
#define VRMC_MATERIALS_MTOON_LIGHTING_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"

View File

@@ -4,6 +4,7 @@
#include <UnityCG.cginc>
#include <AutoLight.cginc>
#include <Lighting.cginc>
#include "./vrmc_materials_mtoon_utility.hlsl"
#include "./vrmc_materials_mtoon_input.hlsl"
#include "./vrmc_materials_mtoon_attribute.hlsl"

View File

@@ -0,0 +1,42 @@
#ifndef VRMC_MATERIALS_MTOON_UTILITY_INCLUDED
#define VRMC_MATERIALS_MTOON_UTILITY_INCLUDED
#include <UnityCG.cginc>
// define
static const float PI_2 = 6.28318530718;
static const float EPS_COL = 0.00001;
inline half3 mtoon_linearstep(const half3 start, const half3 end, const half t)
{
return min(max((t - start) / (end - start), 0.0), 1.0);
}
inline bool MToon_IsPerspective()
{
return unity_OrthoParams.w != 1.0;
}
inline float3 MToon_GetWorldSpaceNormalizedViewDir(const float3 positionWS)
{
if (MToon_IsPerspective())
{
return normalize(_WorldSpaceCameraPos.xyz - positionWS);
}
else
{
return normalize(UNITY_MATRIX_V[2].xyz);
}
}
inline half3x3 MToon_GetTangentToWorld(const half3 normalWS, const half4 tangentWS)
{
const half3 normalizedNormalWS = normalize(normalWS);
const half3 normalizedTangentWS = normalize(tangentWS.xyz);
const half3 normalizedBitangentWS = normalize(tangentWS.w * cross(normalizedNormalWS, normalizedTangentWS));
return half3x3(normalizedTangentWS, normalizedBitangentWS, normalizedNormalWS);
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 79a73f8bac4e45498341e9b6c1ea841e
timeCreated: 1622632833