Sebastien Lagarde
7 年前
当前提交
14274ef1
共有 28 个文件被更改,包括 2428 次插入 和 0 次删除
-
10ScriptableRenderPipeline/HDRenderPipeline/Material/Character.meta
-
60ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Character.cs
-
147ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Character.cs.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Character.cs.hlsl.meta
-
12ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Character.cs.meta
-
539ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Character.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Character.hlsl.meta
-
150ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Character.shader
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Character.shader.meta
-
418ScriptableRenderPipeline/HDRenderPipeline/Material/Character/CharacterData.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Character/CharacterData.hlsl.meta
-
424ScriptableRenderPipeline/HDRenderPipeline/Material/Character/CharacterDebug.mat
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Character/CharacterDebug.mat.meta
-
67ScriptableRenderPipeline/HDRenderPipeline/Material/Character/CharacterProperties.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Character/CharacterProperties.hlsl.meta
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Editor.meta
-
245ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Editor/BaseCharacterUI.cs
-
12ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Editor/BaseCharacterUI.cs.meta
-
145ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Editor/CharacterUI.cs
-
12ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Editor/CharacterUI.cs.meta
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Character/ShaderPass.meta
-
63ScriptableRenderPipeline/HDRenderPipeline/Material/Character/ShaderPass/CharacterDepthPass.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Character/ShaderPass/CharacterDepthPass.hlsl.meta
-
34ScriptableRenderPipeline/HDRenderPipeline/Material/Character/ShaderPass/CharacterSharePass.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Character/ShaderPass/CharacterSharePass.hlsl.meta
|
|||
fileFormatVersion: 2 |
|||
guid: e358ae90302a03e409bc067e832525c5 |
|||
folderAsset: yes |
|||
timeCreated: 1509071155 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public partial class Character : RenderPipelineMaterial |
|||
{ |
|||
[GenerateHLSL(PackingRules.Exact)] |
|||
public enum CharacterMaterialID |
|||
{ |
|||
Skin = 0, |
|||
Hair = 1, |
|||
Eye = 2 |
|||
}; |
|||
|
|||
//TODO: Feature Flags
|
|||
|
|||
[GenerateHLSL(PackingRules.Exact, false, true, 4000)] |
|||
public struct SurfaceData |
|||
{ |
|||
[SurfaceDataAttributes("Diffuse Color", false, true)] |
|||
public Vector3 diffuseColor; |
|||
[SurfaceDataAttributes("Specular Occlusion")] |
|||
public float specularOcclusion; |
|||
[SurfaceDataAttributes("Normal", true)] |
|||
public Vector3 normalWS; |
|||
[SurfaceDataAttributes("Smoothness")] |
|||
public float perceptualSmoothness; |
|||
[SurfaceDataAttributes("Ambient Occlusion")] |
|||
public float ambientOcclusion; |
|||
|
|||
//Character Material ID Attributes
|
|||
[SurfaceDataAttributes("Tangent", true)] |
|||
public Vector3 tangentWS; |
|||
[SurfaceDataAttributes("Anisotropy")] |
|||
public float anisotropy; |
|||
} |
|||
|
|||
[GenerateHLSL(PackingRules.Exact, false, true, 4030)] |
|||
public struct BSDFData |
|||
{ |
|||
[SurfaceDataAttributes("", false, true)] |
|||
public Vector3 diffuseColor; |
|||
public Vector3 fresnel0; |
|||
public float specularOcclusion; |
|||
|
|||
[SurfaceDataAttributes("", true)] |
|||
public Vector3 normalWS; |
|||
public float perceptualRoughness; |
|||
public float roughness; |
|||
|
|||
[SurfaceDataAttributes("", true)] |
|||
public Vector3 tangentWS; |
|||
[SurfaceDataAttributes("", true)] |
|||
public Vector3 bitangentWS; |
|||
public float roughnessT; |
|||
public float roughnessB; |
|||
public float anisotropy; |
|||
} |
|||
} |
|||
} |
|
|||
// |
|||
// This file was automatically generated from Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Character.cs. Please don't edit by hand. |
|||
// |
|||
|
|||
#ifndef CHARACTER_CS_HLSL |
|||
#define CHARACTER_CS_HLSL |
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Character+CharacterMaterialID: static fields |
|||
// |
|||
#define CHARACTERMATERIALID_SKIN (0) |
|||
#define CHARACTERMATERIALID_HAIR (1) |
|||
#define CHARACTERMATERIALID_EYE (2) |
|||
|
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Character+SurfaceData: static fields |
|||
// |
|||
#define DEBUGVIEW_CHARACTER_SURFACEDATA_DIFFUSE_COLOR (4000) |
|||
#define DEBUGVIEW_CHARACTER_SURFACEDATA_SPECULAR_OCCLUSION (4001) |
|||
#define DEBUGVIEW_CHARACTER_SURFACEDATA_NORMAL_WS (4002) |
|||
#define DEBUGVIEW_CHARACTER_SURFACEDATA_PERCEPTUAL_SMOOTHNESS (4003) |
|||
#define DEBUGVIEW_CHARACTER_SURFACEDATA_AMBIENT_OCCLUSION (4004) |
|||
#define DEBUGVIEW_CHARACTER_SURFACEDATA_TANGENT_WS (4005) |
|||
#define DEBUGVIEW_CHARACTER_SURFACEDATA_ANISOTROPY (4006) |
|||
|
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Character+BSDFData: static fields |
|||
// |
|||
#define DEBUGVIEW_CHARACTER_BSDFDATA_DIFFUSE_COLOR (4030) |
|||
#define DEBUGVIEW_CHARACTER_BSDFDATA_FRESNEL0 (4031) |
|||
#define DEBUGVIEW_CHARACTER_BSDFDATA_SPECULAR_OCCLUSION (4032) |
|||
#define DEBUGVIEW_CHARACTER_BSDFDATA_NORMAL_WS (4033) |
|||
#define DEBUGVIEW_CHARACTER_BSDFDATA_PERCEPTUAL_ROUGHNESS (4034) |
|||
#define DEBUGVIEW_CHARACTER_BSDFDATA_ROUGHNESS (4035) |
|||
#define DEBUGVIEW_CHARACTER_BSDFDATA_TANGENT_WS (4036) |
|||
#define DEBUGVIEW_CHARACTER_BSDFDATA_BITANGENT_WS (4037) |
|||
#define DEBUGVIEW_CHARACTER_BSDFDATA_ROUGHNESS_T (4038) |
|||
#define DEBUGVIEW_CHARACTER_BSDFDATA_ROUGHNESS_B (4039) |
|||
#define DEBUGVIEW_CHARACTER_BSDFDATA_ANISOTROPY (4040) |
|||
|
|||
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Character+SurfaceData |
|||
// PackingRules = Exact |
|||
struct SurfaceData |
|||
{ |
|||
float3 diffuseColor; |
|||
float specularOcclusion; |
|||
float3 normalWS; |
|||
float perceptualSmoothness; |
|||
float ambientOcclusion; |
|||
float3 tangentWS; |
|||
float anisotropy; |
|||
}; |
|||
|
|||
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Character+BSDFData |
|||
// PackingRules = Exact |
|||
struct BSDFData |
|||
{ |
|||
float3 diffuseColor; |
|||
float3 fresnel0; |
|||
float specularOcclusion; |
|||
float3 normalWS; |
|||
float perceptualRoughness; |
|||
float roughness; |
|||
float3 tangentWS; |
|||
float3 bitangentWS; |
|||
float roughnessT; |
|||
float roughnessB; |
|||
float anisotropy; |
|||
}; |
|||
|
|||
// |
|||
// Debug functions |
|||
// |
|||
void GetGeneratedSurfaceDataDebug(uint paramId, SurfaceData surfacedata, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_CHARACTER_SURFACEDATA_DIFFUSE_COLOR: |
|||
result = surfacedata.diffuseColor; |
|||
needLinearToSRGB = true; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_SURFACEDATA_SPECULAR_OCCLUSION: |
|||
result = surfacedata.specularOcclusion.xxx; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_SURFACEDATA_NORMAL_WS: |
|||
result = surfacedata.normalWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_SURFACEDATA_PERCEPTUAL_SMOOTHNESS: |
|||
result = surfacedata.perceptualSmoothness.xxx; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_SURFACEDATA_AMBIENT_OCCLUSION: |
|||
result = surfacedata.ambientOcclusion.xxx; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_SURFACEDATA_TANGENT_WS: |
|||
result = surfacedata.tangentWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_SURFACEDATA_ANISOTROPY: |
|||
result = surfacedata.anisotropy.xxx; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
// |
|||
// Debug functions |
|||
// |
|||
void GetGeneratedBSDFDataDebug(uint paramId, BSDFData bsdfdata, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_CHARACTER_BSDFDATA_DIFFUSE_COLOR: |
|||
result = bsdfdata.diffuseColor; |
|||
needLinearToSRGB = true; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_BSDFDATA_FRESNEL0: |
|||
result = bsdfdata.fresnel0; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_BSDFDATA_SPECULAR_OCCLUSION: |
|||
result = bsdfdata.specularOcclusion.xxx; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_BSDFDATA_NORMAL_WS: |
|||
result = bsdfdata.normalWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_BSDFDATA_PERCEPTUAL_ROUGHNESS: |
|||
result = bsdfdata.perceptualRoughness.xxx; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_BSDFDATA_ROUGHNESS: |
|||
result = bsdfdata.roughness.xxx; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_BSDFDATA_TANGENT_WS: |
|||
result = bsdfdata.tangentWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_BSDFDATA_BITANGENT_WS: |
|||
result = bsdfdata.bitangentWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_BSDFDATA_ROUGHNESS_T: |
|||
result = bsdfdata.roughnessT.xxx; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_BSDFDATA_ROUGHNESS_B: |
|||
result = bsdfdata.roughnessB.xxx; |
|||
break; |
|||
case DEBUGVIEW_CHARACTER_BSDFDATA_ANISOTROPY: |
|||
result = bsdfdata.anisotropy.xxx; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
#endif |
|
|||
fileFormatVersion: 2 |
|||
guid: 5a999ec24f8ae2a43b0ba802a738ad40 |
|||
timeCreated: 1495317694 |
|||
licenseType: Free |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ed51bb658d603a943b119b9a5e0c87be |
|||
timeCreated: 1495116014 |
|||
licenseType: Free |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#include "Character.cs.hlsl" |
|||
|
|||
SamplerState ltc_linear_clamp_sampler; |
|||
// TODO: This one should be set into a constant Buffer at pass frequency (with _Screensize) |
|||
TEXTURE2D(_PreIntegratedFGD); |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Helper functions/variable specific to this material |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// For image based lighting, a part of the BSDF is pre-integrated. |
|||
// This is done both for specular and diffuse (in case of DisneyDiffuse) |
|||
void GetPreIntegratedFGD(float NdotV, float perceptualRoughness, float3 fresnel0, out float3 specularFGD, out float diffuseFGD) |
|||
{ |
|||
// Pre-integrate GGX FGD |
|||
// _PreIntegratedFGD.x = Gv * (1 - Fc) with Fc = (1 - H.L)^5 |
|||
// _PreIntegratedFGD.y = Gv * Fc |
|||
// Pre integrate DisneyDiffuse FGD: |
|||
// _PreIntegratedFGD.z = DisneyDiffuse |
|||
float3 preFGD = SAMPLE_TEXTURE2D_LOD(_PreIntegratedFGD, ltc_linear_clamp_sampler, float2(NdotV, perceptualRoughness), 0).xyz; |
|||
|
|||
// f0 * Gv * (1 - Fc) + Gv * Fc |
|||
specularFGD = fresnel0 * preFGD.x + preFGD.y; |
|||
diffuseFGD = 1.0; |
|||
} |
|||
|
|||
void ApplyDebugToBSDFData(inout BSDFData bsdfData) |
|||
{ |
|||
#ifdef DEBUG_DISPLAY |
|||
if (_DebugLightingMode == DEBUGLIGHTINGMODE_SPECULAR_LIGHTING) |
|||
{ |
|||
bool overrideSmoothness = _DebugLightingSmoothness.x != 0.0; |
|||
float overrideSmoothnessValue = _DebugLightingSmoothness.y; |
|||
|
|||
if (overrideSmoothness) |
|||
{ |
|||
bsdfData.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(overrideSmoothnessValue); |
|||
bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness); |
|||
} |
|||
} |
|||
|
|||
if (_DebugLightingMode == DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING) |
|||
{ |
|||
bsdfData.diffuseColor = _DebugLightingAlbedo.xyz; |
|||
} |
|||
#endif |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// conversion function for forward |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
BSDFData ConvertSurfaceDataToBSDFData(SurfaceData surfaceData) |
|||
{ |
|||
BSDFData bsdfData; |
|||
ZERO_INITIALIZE(BSDFData, bsdfData); |
|||
|
|||
bsdfData.diffuseColor = surfaceData.diffuseColor; |
|||
bsdfData.specularOcclusion = surfaceData.specularOcclusion; |
|||
bsdfData.normalWS = surfaceData.normalWS; |
|||
bsdfData.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness); |
|||
bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness); |
|||
|
|||
bsdfData.fresnel0 = 0.04; |
|||
|
|||
bsdfData.tangentWS = surfaceData.tangentWS; |
|||
bsdfData.bitangentWS = cross(surfaceData.normalWS, surfaceData.tangentWS); |
|||
ConvertAnisotropyToRoughness(bsdfData.roughness, surfaceData.anisotropy, bsdfData.roughnessT, bsdfData.roughnessB); |
|||
bsdfData.anisotropy = surfaceData.anisotropy; |
|||
|
|||
ApplyDebugToBSDFData(bsdfData); |
|||
|
|||
return bsdfData; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Debug method (use to display values) |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
void GetSurfaceDataDebug(uint paramId, SurfaceData surfaceData, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
GetGeneratedSurfaceDataDebug(paramId, surfaceData, result, needLinearToSRGB); |
|||
} |
|||
|
|||
void GetBSDFDataDebug(uint paramId, BSDFData bsdfData, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
GetGeneratedBSDFDataDebug(paramId, bsdfData, result, needLinearToSRGB); |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// PreLightData |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// Precomputed lighting data to send to the various lighting functions |
|||
struct PreLightData |
|||
{ |
|||
float NdotV; |
|||
|
|||
// Aniso |
|||
float TdotV; |
|||
float BdotV; |
|||
|
|||
float3 iblDirWS; // Dominant specular direction, used for IBL in EvaluateBSDF_Env() |
|||
float iblMipLevel; |
|||
|
|||
float3 specularFGD; // Store preconvole BRDF for both specular and diffuse |
|||
float diffuseFGD; |
|||
}; |
|||
|
|||
PreLightData GetPreLightData(float3 V, PositionInputs posInput, BSDFData bsdfData) |
|||
{ |
|||
PreLightData preLightData; |
|||
|
|||
// We have handle the case of NdotV being negative in GetData() function with GetShiftedNdotV. |
|||
// So we don't need to saturate or take the abs here. |
|||
// In case a material use negative normal for double sided lighting like speedtree this will be handle in the GetData() code too. |
|||
preLightData.NdotV = dot(bsdfData.normalWS, V); |
|||
|
|||
float iblNdotV = preLightData.NdotV; |
|||
float3 iblNormalWS = bsdfData.normalWS; |
|||
|
|||
// Precompute anisotropy |
|||
preLightData.TdotV = dot(bsdfData.tangentWS, V); |
|||
preLightData.BdotV = dot(bsdfData.bitangentWS, V); |
|||
// Tangent = highlight stretch (anisotropy) direction. Bitangent = grain (brush) direction. |
|||
iblNormalWS = GetAnisotropicModifiedNormal(bsdfData.bitangentWS, bsdfData.normalWS, V, bsdfData.anisotropy); |
|||
|
|||
// NOTE: If we follow the theory we should use the modified normal for the different calculation implying a normal (like NDotV) and use iblNormalWS |
|||
// into function like GetSpecularDominantDir(). However modified normal is just a hack. The goal is just to stretch a cubemap, no accuracy here. |
|||
// With this in mind and for performance reasons we chose to only use modified normal to calculate R. |
|||
|
|||
GetPreIntegratedFGD(iblNdotV, bsdfData.perceptualRoughness, bsdfData.fresnel0, preLightData.specularFGD, preLightData.diffuseFGD); |
|||
|
|||
// We need to take into account the modified normal for faking anisotropic here. |
|||
float3 iblR = reflect(-V, iblNormalWS); |
|||
preLightData.iblDirWS = GetSpecularDominantDir(bsdfData.normalWS, iblR, bsdfData.roughness, preLightData.NdotV); |
|||
|
|||
preLightData.iblMipLevel = PerceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness); |
|||
|
|||
return preLightData; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// bake lighting function |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// GetBakedDiffuseLigthing function compute the bake lighting + emissive color to be store in emissive buffer (Deferred case) |
|||
// In forward it must be add to the final contribution. |
|||
// This function require the 3 structure surfaceData, builtinData, bsdfData because it may require both the engine side data, and data that will not be store inside the gbuffer. |
|||
float3 GetBakedDiffuseLigthing(SurfaceData surfaceData, BuiltinData builtinData, BSDFData bsdfData, PreLightData preLightData) |
|||
{ |
|||
// Premultiply bake diffuse lighting information with DisneyDiffuse pre-integration |
|||
return builtinData.bakeDiffuseLighting * preLightData.diffuseFGD * surfaceData.ambientOcclusion * bsdfData.diffuseColor + builtinData.emissiveColor; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// LightLoop related function (Only include if required) |
|||
// HAS_LIGHTLOOP is define in Lighting.hlsl |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
#ifdef HAS_LIGHTLOOP |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// BSDF share between directional light, punctual light and area light (reference) |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
void BSDF( float3 V, float3 L, float3 positionWS, PreLightData preLightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, |
|||
out float3 specularLighting) |
|||
{ |
|||
float NdotL = saturate(dot(bsdfData.normalWS, L)); |
|||
float NdotV = preLightData.NdotV; |
|||
float LdotV = dot(L, V); |
|||
float invLenLV = rsqrt(abs(2 + 2 * LdotV)); // invLenLV = rcp(length(L + V)) |
|||
float NdotH = saturate((NdotL + NdotV) * invLenLV); |
|||
float LdotH = saturate(invLenLV + invLenLV * LdotV); |
|||
|
|||
float3 F = F_Schlick(bsdfData.fresnel0, LdotH); |
|||
|
|||
float Vis; |
|||
float D; |
|||
// TODO: this way of handling aniso may not be efficient, or maybe with material classification, need to check perf here |
|||
// Maybe always using aniso maybe a win ? |
|||
|
|||
float3 H = (L + V) * invLenLV; |
|||
// For anisotropy we must not saturate these values |
|||
float TdotH = dot(bsdfData.tangentWS, H); |
|||
float TdotL = dot(bsdfData.tangentWS, L); |
|||
float BdotH = dot(bsdfData.bitangentWS, H); |
|||
float BdotL = dot(bsdfData.bitangentWS, L); |
|||
|
|||
bsdfData.roughnessT = ClampRoughnessForAnalyticalLights(bsdfData.roughnessT); |
|||
bsdfData.roughnessB = ClampRoughnessForAnalyticalLights(bsdfData.roughnessB); |
|||
|
|||
// TODO: Do comparison between this correct version and the one from isotropic and see if there is any visual difference |
|||
Vis = V_SmithJointGGXAniso( preLightData.TdotV, preLightData.BdotV, NdotV, TdotL, BdotL, NdotL, |
|||
bsdfData.roughnessT, bsdfData.roughnessB); |
|||
|
|||
D = D_GGXAniso(TdotH, BdotH, NdotH, bsdfData.roughnessT, bsdfData.roughnessB); |
|||
|
|||
specularLighting = F * (Vis * D); |
|||
|
|||
float diffuseTerm = Lambert(); |
|||
|
|||
diffuseLighting = bsdfData.diffuseColor * diffuseTerm; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Directional |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
void EvaluateBSDF_Directional( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, PreLightData preLightData, DirectionalLightData lightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, |
|||
out float3 specularLighting) |
|||
{ |
|||
float3 positionWS = posInput.positionWS; |
|||
|
|||
float3 L = -lightData.forward; // Lights are pointing backward in Unity |
|||
float illuminance = saturate(dot(bsdfData.normalWS, L)); |
|||
|
|||
diffuseLighting = float3(0.0, 0.0, 0.0); |
|||
specularLighting = float3(0.0, 0.0, 0.0); |
|||
float4 cookie = float4(1.0, 1.0, 1.0, 1.0); |
|||
float shadow = 1; |
|||
|
|||
[branch] if (lightData.shadowIndex >= 0) |
|||
{ |
|||
shadow = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, positionWS, bsdfData.normalWS, lightData.shadowIndex, L, posInput.unPositionSS); |
|||
illuminance *= shadow; |
|||
} |
|||
|
|||
[branch] if (lightData.cookieIndex >= 0) |
|||
{ |
|||
float3 lightToSurface = positionWS - lightData.positionWS; |
|||
|
|||
// Project 'lightToSurface' onto the light's axes. |
|||
float2 coord = float2(dot(lightToSurface, lightData.right), dot(lightToSurface, lightData.up)); |
|||
|
|||
// Compute the NDC coordinates (in [-1, 1]^2). |
|||
coord.x *= lightData.invScaleX; |
|||
coord.y *= lightData.invScaleY; |
|||
|
|||
if (lightData.tileCookie || (abs(coord.x) <= 1 && abs(coord.y) <= 1)) |
|||
{ |
|||
// Remap the texture coordinates from [-1, 1]^2 to [0, 1]^2. |
|||
coord = coord * 0.5 + 0.5; |
|||
|
|||
// Tile the texture if the 'repeat' wrap mode is enabled. |
|||
if (lightData.tileCookie) { coord = frac(coord); } |
|||
|
|||
cookie = SampleCookie2D(lightLoopContext, coord, lightData.cookieIndex); |
|||
} |
|||
else |
|||
{ |
|||
cookie = float4(0, 0, 0, 0); |
|||
} |
|||
|
|||
illuminance *= cookie.a; |
|||
} |
|||
|
|||
[branch] if (illuminance > 0.0) |
|||
{ |
|||
BSDF(V, L, positionWS, preLightData, bsdfData, diffuseLighting, specularLighting); |
|||
|
|||
diffuseLighting *= (cookie.rgb * lightData.color) * (illuminance * lightData.diffuseScale); |
|||
specularLighting *= (cookie.rgb * lightData.color) * (illuminance * lightData.specularScale); |
|||
} |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Punctual |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
void EvaluateBSDF_Punctual( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, PreLightData preLightData, LightData lightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, |
|||
out float3 specularLighting) |
|||
{ |
|||
float3 positionWS = posInput.positionWS; |
|||
|
|||
// All punctual light type in the same formula, attenuation is neutral depends on light type. |
|||
// light.positionWS is the normalize light direction in case of directional light and invSqrAttenuationRadius is 0 |
|||
// mean dot(unL, unL) = 1 and mean GetDistanceAttenuation() will return 1 |
|||
// For point light and directional GetAngleAttenuation() return 1 |
|||
|
|||
float3 unL = lightData.positionWS - positionWS; |
|||
float3 L = normalize(unL); |
|||
|
|||
float attenuation = GetDistanceAttenuation(unL, lightData.invSqrAttenuationRadius); |
|||
// Reminder: lights are ortiented backward (-Z) |
|||
attenuation *= GetAngleAttenuation(L, -lightData.forward, lightData.angleScale, lightData.angleOffset); |
|||
float illuminance = saturate(dot(bsdfData.normalWS, L)) * attenuation; |
|||
|
|||
diffuseLighting = float3(0.0, 0.0, 0.0); |
|||
specularLighting = float3(0.0, 0.0, 0.0); |
|||
float4 cookie = float4(1.0, 1.0, 1.0, 1.0); |
|||
float shadow = 1; |
|||
|
|||
// TODO: measure impact of having all these dynamic branch here and the gain (or not) of testing illuminace > 0 |
|||
|
|||
//[branch] if (lightData.IESIndex >= 0 && illuminance > 0.0) |
|||
//{ |
|||
// float3x3 lightToWorld = float3x3(lightData.right, lightData.up, lightData.forward); |
|||
// float2 sphericalCoord = GetIESTextureCoordinate(lightToWorld, L); |
|||
// illuminance *= SampleIES(lightLoopContext, lightData.IESIndex, sphericalCoord, 0).r; |
|||
//} |
|||
|
|||
[branch] if (lightData.shadowIndex >= 0) |
|||
{ |
|||
float3 offset = float3(0.0, 0.0, 0.0); // GetShadowPosOffset(nDotL, normal); |
|||
shadow = GetPunctualShadowAttenuation(lightLoopContext.shadowContext, positionWS + offset, bsdfData.normalWS, lightData.shadowIndex, L, posInput.unPositionSS); |
|||
shadow = lerp(1.0, shadow, lightData.shadowDimmer); |
|||
|
|||
illuminance *= shadow; |
|||
} |
|||
|
|||
[branch] if (lightData.cookieIndex >= 0) |
|||
{ |
|||
float3x3 lightToWorld = float3x3(lightData.right, lightData.up, lightData.forward); |
|||
|
|||
// Rotate 'L' into the light space. |
|||
// We perform the negation because lights are oriented backwards (-Z). |
|||
float3 coord = mul(-L, transpose(lightToWorld)); |
|||
|
|||
[branch] if (lightData.lightType == GPULIGHTTYPE_SPOT) |
|||
{ |
|||
// Perform the perspective projection of the hemisphere onto the disk. |
|||
coord.xy /= coord.z; |
|||
|
|||
// Rescale the projective coordinates to fit into the [-1, 1]^2 range. |
|||
float cotOuterHalfAngle = lightData.size.x; |
|||
coord.xy *= cotOuterHalfAngle; |
|||
|
|||
// Remap the texture coordinates from [-1, 1]^2 to [0, 1]^2. |
|||
coord.xy = coord.xy * 0.5 + 0.5; |
|||
|
|||
cookie = SampleCookie2D(lightLoopContext, coord.xy, lightData.cookieIndex); |
|||
} |
|||
else // GPULIGHTTYPE_POINT |
|||
{ |
|||
cookie = SampleCookieCube(lightLoopContext, coord, lightData.cookieIndex); |
|||
} |
|||
|
|||
illuminance *= cookie.a; |
|||
} |
|||
|
|||
[branch] if (illuminance > 0.0) |
|||
{ |
|||
BSDF(V, L, positionWS, preLightData, bsdfData, diffuseLighting, specularLighting); |
|||
|
|||
diffuseLighting *= (cookie.rgb * lightData.color) * (illuminance * lightData.diffuseScale); |
|||
specularLighting *= (cookie.rgb * lightData.color) * (illuminance * lightData.specularScale); |
|||
} |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Projector |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
void EvaluateBSDF_Projector(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, PreLightData preLightData, LightData lightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, |
|||
out float3 specularLighting) |
|||
{ |
|||
float3 positionWS = posInput.positionWS; |
|||
|
|||
// Translate and rotate 'positionWS' into the light space. |
|||
float3 positionLS = mul(positionWS - lightData.positionWS, |
|||
transpose(float3x3(lightData.right, lightData.up, lightData.forward))); |
|||
|
|||
if (lightData.lightType == GPULIGHTTYPE_PROJECTOR_PYRAMID) |
|||
{ |
|||
// Perform perspective division. |
|||
positionLS *= rcp(positionLS.z); |
|||
} |
|||
else |
|||
{ |
|||
// For orthographic projection, the Z coordinate plays no role. |
|||
positionLS.z = 0; |
|||
} |
|||
|
|||
// Compute the NDC position (in [-1, 1]^2). TODO: precompute the inverse? |
|||
float2 positionNDC = positionLS.xy * rcp(0.5 * lightData.size); |
|||
|
|||
// Perform clipping. |
|||
float clipFactor = ((positionLS.z >= 0) && (abs(positionNDC.x) <= 1 && abs(positionNDC.y) <= 1)) ? 1 : 0; |
|||
|
|||
float3 L = -lightData.forward; // Lights are pointing backward in Unity |
|||
float illuminance = saturate(dot(bsdfData.normalWS, L) * clipFactor); |
|||
|
|||
diffuseLighting = float3(0.0, 0.0, 0.0); |
|||
specularLighting = float3(0.0, 0.0, 0.0); |
|||
float4 cookie = float4(1.0, 1.0, 1.0, 1.0); |
|||
float shadow = 1; |
|||
|
|||
[branch] if (lightData.shadowIndex >= 0) |
|||
{ |
|||
shadow = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, positionWS, bsdfData.normalWS, lightData.shadowIndex, L, posInput.unPositionSS); |
|||
illuminance *= shadow; |
|||
} |
|||
|
|||
[branch] if (lightData.cookieIndex >= 0) |
|||
{ |
|||
// Compute the texture coordinates in [0, 1]^2. |
|||
float2 coord = positionNDC * 0.5 + 0.5; |
|||
|
|||
cookie = SampleCookie2D(lightLoopContext, coord, lightData.cookieIndex); |
|||
|
|||
illuminance *= cookie.a; |
|||
} |
|||
|
|||
[branch] if (illuminance > 0.0) |
|||
{ |
|||
BSDF(V, L, positionWS, preLightData, bsdfData, diffuseLighting, specularLighting); |
|||
|
|||
diffuseLighting *= (cookie.rgb * lightData.color) * (illuminance * lightData.diffuseScale); |
|||
specularLighting *= (cookie.rgb * lightData.color) * (illuminance * lightData.specularScale); |
|||
} |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Line - Approximation with Linearly Transformed Cosines |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
void EvaluateBSDF_Line(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, LightData lightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, out float3 specularLighting) |
|||
{ |
|||
diffuseLighting = float3(0.0, 0.0, 0.0); |
|||
specularLighting = float3(0.0, 0.0, 0.0); |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Area - Approximation with Linearly Transformed Cosines |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// #define ELLIPSOIDAL_ATTENUATION |
|||
|
|||
void EvaluateBSDF_Area(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, LightData lightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, out float3 specularLighting) |
|||
{ |
|||
diffuseLighting = float3(0.0, 0.0, 0.0); |
|||
specularLighting = float3(0.0, 0.0, 0.0); |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Env |
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
// _preIntegratedFGD and _CubemapLD are unique for each BRDF |
|||
void EvaluateBSDF_Env( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, PreLightData preLightData, EnvLightData lightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, out float3 specularLighting, out float2 weight) |
|||
{ |
|||
float3 positionWS = posInput.positionWS; |
|||
|
|||
// TODO: factor this code in common, so other material authoring don't require to rewrite everything, |
|||
// also think about how such a loop can handle 2 cubemap at the same time as old unity. Macro can allow to do that |
|||
// but we need to have UNITY_SAMPLE_ENV_LOD replace by a true function instead that is define by the lighting arcitecture. |
|||
// Also not sure how to deal with 2 intersection.... |
|||
// Box and sphere are related to light property (but we have also distance based roughness etc...) |
|||
|
|||
// TODO: test the strech from Tomasz |
|||
// float shrinkedRoughness = AnisotropicStrechAtGrazingAngle(bsdfData.roughness, bsdfData.perceptualRoughness, NdotV); |
|||
|
|||
// In this code we redefine a bit the behavior of the reflcetion proble. We separate the projection volume (the proxy of the scene) form the influence volume (what pixel on the screen is affected) |
|||
|
|||
// 1. First determine the projection volume |
|||
|
|||
// In Unity the cubemaps are capture with the localToWorld transform of the component. |
|||
// This mean that location and oritention matter. So after intersection of proxy volume we need to convert back to world. |
|||
|
|||
// CAUTION: localToWorld is the transform use to convert the cubemap capture point to world space (mean it include the offset) |
|||
// the center of the bounding box is thus in locals space: positionLS - offsetLS |
|||
// We use this formulation as it is the one of legacy unity that was using only AABB box. |
|||
|
|||
float3 R = preLightData.iblDirWS; |
|||
float3x3 worldToLocal = transpose(float3x3(lightData.right, lightData.up, lightData.forward)); // worldToLocal assume no scaling |
|||
float3 positionLS = positionWS - lightData.positionWS; |
|||
positionLS = mul(positionLS, worldToLocal).xyz - lightData.offsetLS; // We want to calculate the intersection from the center of the bounding box. |
|||
|
|||
if (lightData.envShapeType == ENVSHAPETYPE_BOX) |
|||
{ |
|||
float3 dirLS = mul(R, worldToLocal); |
|||
float3 boxOuterDistance = lightData.innerDistance + float3(lightData.blendDistance, lightData.blendDistance, lightData.blendDistance); |
|||
float dist = BoxRayIntersectSimple(positionLS, dirLS, -boxOuterDistance, boxOuterDistance); |
|||
|
|||
// No need to normalize for fetching cubemap |
|||
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.positionWS |
|||
R = (positionWS + dist * R) - lightData.positionWS; |
|||
|
|||
// TODO: add distance based roughness |
|||
} |
|||
else if (lightData.envShapeType == ENVSHAPETYPE_SPHERE) |
|||
{ |
|||
float3 dirLS = mul(R, worldToLocal); |
|||
float sphereOuterDistance = lightData.innerDistance.x + lightData.blendDistance; |
|||
float dist = SphereRayIntersectSimple(positionLS, dirLS, sphereOuterDistance); |
|||
|
|||
R = (positionWS + dist * R) - lightData.positionWS; |
|||
} |
|||
|
|||
// 2. Apply the influence volume (Box volume is used for culling whatever the influence shape) |
|||
// TODO: In the future we could have an influence volume inside the projection volume (so with a different transform, in this case we will need another transform) |
|||
weight.y = 1.0; |
|||
|
|||
if (lightData.envShapeType == ENVSHAPETYPE_SPHERE) |
|||
{ |
|||
float distFade = max(length(positionLS) - lightData.innerDistance.x, 0.0); |
|||
weight.y = saturate(1.0 - distFade / max(lightData.blendDistance, 0.0001)); // avoid divide by zero |
|||
} |
|||
else if (lightData.envShapeType == ENVSHAPETYPE_BOX || |
|||
lightData.envShapeType == ENVSHAPETYPE_NONE) |
|||
{ |
|||
// Calculate falloff value, so reflections on the edges of the volume would gradually blend to previous reflection. |
|||
float distFade = DistancePointBox(positionLS, -lightData.innerDistance, lightData.innerDistance); |
|||
weight.y = saturate(1.0 - distFade / max(lightData.blendDistance, 0.0001)); // avoid divide by zero |
|||
} |
|||
|
|||
// Smooth weighting |
|||
weight.x = 0.0; |
|||
weight.y = smoothstep01(weight.y); |
|||
|
|||
// TODO: we must always perform a weight calculation as due to tiled rendering we need to smooth out cubemap at boundaries. |
|||
// So goal is to split into two category and have an option to say if we parallax correct or not. |
|||
|
|||
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, preLightData.iblMipLevel); |
|||
specularLighting = preLD.rgb * preLightData.specularFGD; |
|||
|
|||
// Apply specular occlusion on it |
|||
specularLighting *= bsdfData.specularOcclusion; |
|||
diffuseLighting = float3(0.0, 0.0, 0.0); |
|||
} |
|||
|
|||
#endif // #ifdef HAS_LIGHTLOOP |
|
|||
fileFormatVersion: 2 |
|||
guid: 8874aea61c485944280b783651664575 |
|||
timeCreated: 1495117257 |
|||
licenseType: Free |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "HDRenderPipeline/ExperimentalSkin" |
|||
{ |
|||
Properties |
|||
{ |
|||
[Enum(Skin, 0, Hair, 1, Eye, 2)] _CharacterMaterialID("CharacterMaterialID", Int) = 0 |
|||
|
|||
_DiffuseColor("DiffuseColor", Color) = (1, 1, 1, 1) |
|||
_DiffuseColorMap("DiffuseColorMap", 2D) = "white" {} |
|||
|
|||
_NormalMap("NormalMap", 2D) = "bump" {} |
|||
|
|||
[HideInInspector] _BlendMode("__blendmode", Float) = 0.0 |
|||
[HideInInspector] _SrcBlend("__src", Float) = 1.0 |
|||
[HideInInspector] _DstBlend("__dst", Float) = 0.0 |
|||
[HideInInspector] _ZWrite("__zw", Float) = 1.0 |
|||
[HideInInspector] _CullMode("__cullmode", Float) = 2.0 |
|||
[HideInInspector] _ZTestMode("_ZTestMode", Int) = 8 |
|||
|
|||
//Skin |
|||
|
|||
//Hair |
|||
_HairSpecularShift("SpecularShift", Range(0, 1)) = 0.5 |
|||
_HairSpecularHighlight("SpecularHighlight", Color) = (1, 1, 1, 1) |
|||
_HairShadowStrength("ShadowStrength", Range(0, 1)) = 0.5 |
|||
|
|||
[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 1.0 |
|||
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
_AlphaCutoffShadow("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
[ToggleOff] _TransparentDepthWritePrepassEnable("Alpha Cutoff Enable", Float) = 1.0 |
|||
_AlphaCutoffPrepass("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
_AlphaCutoffOpacityThreshold("Alpha Cutoff", Range(0.0, 1.0)) = 0.99 |
|||
|
|||
//Eye |
|||
} |
|||
|
|||
HLSLINCLUDE |
|||
|
|||
#pragma target 4.5 |
|||
#pragma only_renderers d3d11 ps4 metal |
|||
|
|||
//--------------------------------- |
|||
//Variant |
|||
//--------------------------------- |
|||
#pragma shader_feature _ALPHATEST_ON |
|||
#pragma shader_feature _DOUBLESIDED_ON |
|||
|
|||
|
|||
//--------------------------------- |
|||
//Define |
|||
//--------------------------------- |
|||
|
|||
#define UNITY_MATERIAL_CHARACTER |
|||
#define SURFACE_GRADIENT |
|||
|
|||
//--------------------------------- |
|||
//Include |
|||
//--------------------------------- |
|||
#include "../../../ShaderLibrary/Common.hlsl" |
|||
#include "../../../ShaderLibrary/Wind.hlsl" |
|||
#include "../../ShaderConfig.cs.hlsl" |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../ShaderPass/FragInputs.hlsl" |
|||
#include "../../ShaderPass/ShaderPass.cs.hlsl" |
|||
|
|||
//--------------------------------- |
|||
//Variable Decl |
|||
//--------------------------------- |
|||
#include "../../Material/Character/CharacterProperties.hlsl" |
|||
|
|||
|
|||
//NOTE: All shaders use same entry point names |
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader{ |
|||
|
|||
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" } |
|||
LOD 300 |
|||
|
|||
Pass{ |
|||
Name "ShadowCaster" |
|||
Tags { "LightMode"="ShadowCaster" } |
|||
} |
|||
|
|||
Pass{ |
|||
Name "DepthOnly" |
|||
Tags { "LightMode"="DepthOnly" } |
|||
|
|||
Cull [_CullMode] |
|||
ZWrite On |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define SHADERPASS SHADERPASS_DEPTH_ONLY |
|||
#include "../../Material/Material.hlsl" |
|||
#include "ShaderPass/CharacterDepthPass.hlsl" |
|||
#include "CharacterData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass{ |
|||
Name "Forward" |
|||
Tags { "LightMode"="Forward" } |
|||
|
|||
Blend [_SrcBlend] [_DstBlend] |
|||
ZWrite [_ZWrite] |
|||
Cull [_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define SHADERPASS SHADERPASS_FORWARD |
|||
#include "../../Lighting/Forward.hlsl" |
|||
#pragma multi_compile LIGHTLOOP_SINGLE_PASS LIGHTLOOP_TILE_PASS |
|||
|
|||
#include "../../Lighting/Lighting.hlsl" |
|||
#include "ShaderPass/CharacterSharePass.hlsl" |
|||
#include "CharacterData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassForward.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass{ |
|||
Name "TransparentDepthWrite" |
|||
Tags { "LightMode"="TransparentDepthWrite" } |
|||
|
|||
Cull [_CullMode] |
|||
ZWrite On |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define SHADERPASS SHADERPASS_DEPTH_ONLY |
|||
#define HAIR_TRANSPARENT_DEPTH_WRITE //TODO |
|||
#include "../../Material/Material.hlsl" |
|||
#include "ShaderPass/CharacterDepthPass.hlsl" |
|||
#include "CharacterData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl" |
|||
|
|||
ENDHLSL |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
CustomEditor "Experimental.Rendering.HDPipeline.CharacterGUI" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0ea49def0f338f3469b36324526446a9 |
|||
timeCreated: 1495116292 |
|||
licenseType: Free |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#include "ShaderLibrary/SampleUVMapping.hlsl" |
|||
#include "../MaterialUtilities.hlsl" |
|||
|
|||
void GetBuiltinData(FragInputs input, SurfaceData surfaceData, float alpha, float depthOffset, out BuiltinData builtinData) |
|||
{ |
|||
// Builtin Data |
|||
builtinData.opacity = alpha; |
|||
|
|||
// TODO: Sample lightmap/lightprobe/volume proxy |
|||
// This should also handle projective lightmap |
|||
// Note that data input above can be use to sample into lightmap (like normal) |
|||
builtinData.bakeDiffuseLighting = SampleBakedGI(input.positionWS, surfaceData.normalWS, input.texCoord1, input.texCoord2); |
|||
|
|||
// Emissive Intensity is only use here, but is part of BuiltinData to enforce UI parameters as we want the users to fill one color and one intensity |
|||
builtinData.emissiveIntensity = _EmissiveIntensity; // We still store intensity here so we can reuse it with debug code |
|||
|
|||
// If we chose an emissive color, we have a dedicated texture for it and don't use MaskMap |
|||
#ifdef _EMISSIVE_COLOR |
|||
#ifdef _EMISSIVE_COLOR_MAP |
|||
builtinData.emissiveColor = SAMPLE_TEXTURE2D(_EmissiveColorMap, sampler_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor * builtinData.emissiveIntensity; |
|||
#else |
|||
builtinData.emissiveColor = _EmissiveColor * builtinData.emissiveIntensity; |
|||
#endif |
|||
// If we have a MaskMap, use emissive slot as a mask on baseColor |
|||
#elif defined(_MASKMAP) && !defined(LAYERED_LIT_SHADER) // With layered lit we have no emissive mask option |
|||
builtinData.emissiveColor = surfaceData.baseColor * (SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, input.texCoord0).b * builtinData.emissiveIntensity).xxx; |
|||
#else |
|||
builtinData.emissiveColor = float3(0.0, 0.0, 0.0); |
|||
#endif |
|||
|
|||
builtinData.velocity = float2(0.0, 0.0); |
|||
|
|||
#ifdef _DISTORTION_ON |
|||
float3 distortion = SAMPLE_TEXTURE2D(_DistortionVectorMap, sampler_DistortionVectorMap, input.texCoord0).rgb; |
|||
builtinData.distortion = distortion.rg; |
|||
builtinData.distortionBlur = distortion.b; |
|||
#else |
|||
builtinData.distortion = float2(0.0, 0.0); |
|||
builtinData.distortionBlur = 0.0; |
|||
#endif |
|||
|
|||
builtinData.depthOffset = depthOffset; |
|||
} |
|||
|
|||
// Struct that gather UVMapping info of all layers + common calculation |
|||
// This is use to abstract the mapping that can differ on layers |
|||
struct LayerTexCoord |
|||
{ |
|||
UVMapping base; |
|||
UVMapping details; |
|||
|
|||
// Store information that will be share by all UVMapping |
|||
float3 vertexNormalWS; // TODO: store also object normal map for object triplanar |
|||
float3 triplanarWeights; |
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
// tangent basis for each UVSet - up to 4 for now |
|||
float3 vertexTangentWS0, vertexBitangentWS0; |
|||
float3 vertexTangentWS1, vertexBitangentWS1; |
|||
float3 vertexTangentWS2, vertexBitangentWS2; |
|||
float3 vertexTangentWS3, vertexBitangentWS3; |
|||
#endif |
|||
}; |
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
void GenerateLayerTexCoordBasisTB(FragInputs input, inout LayerTexCoord layerTexCoord) |
|||
{ |
|||
float3 vertexNormalWS = input.worldToTangent[2]; |
|||
|
|||
layerTexCoord.vertexTangentWS0 = input.worldToTangent[0]; |
|||
layerTexCoord.vertexBitangentWS0 = input.worldToTangent[1]; |
|||
|
|||
// TODO: We should use relative camera position here - This will be automatic when we will move to camera relative space. |
|||
float3 dPdx = ddx_fine(input.positionWS); |
|||
float3 dPdy = ddy_fine(input.positionWS); |
|||
|
|||
float3 sigmaX = dPdx - dot(dPdx, vertexNormalWS) * vertexNormalWS; |
|||
float3 sigmaY = dPdy - dot(dPdy, vertexNormalWS) * vertexNormalWS; |
|||
//float flipSign = dot(sigmaY, cross(nrmVertexNormal, sigmaX) ) ? -1.0 : 1.0; |
|||
float flipSign = dot(dPdy, cross(vertexNormalWS, dPdx)) < 0.0 ? -1.0 : 1.0; // gives same as the commented out line above |
|||
|
|||
// TODO: Optimize! The compiler will not be able to remove the tangent space that are not use because it can't know due to our UVMapping constant we use for both base and details |
|||
// To solve this we should track which UVSet is use for normal mapping... Maybe not as simple as it sounds |
|||
SurfaceGradientGenBasisTB(vertexNormalWS, sigmaX, sigmaY, flipSign, input.texCoord1, layerTexCoord.vertexTangentWS1, layerTexCoord.vertexBitangentWS1); |
|||
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3) |
|||
SurfaceGradientGenBasisTB(vertexNormalWS, sigmaX, sigmaY, flipSign, input.texCoord2, layerTexCoord.vertexTangentWS2, layerTexCoord.vertexBitangentWS2); |
|||
#endif |
|||
#if defined(_REQUIRE_UV3) |
|||
SurfaceGradientGenBasisTB(vertexNormalWS, sigmaX, sigmaY, flipSign, input.texCoord3, layerTexCoord.vertexTangentWS3, layerTexCoord.vertexBitangentWS3); |
|||
#endif |
|||
} |
|||
#endif |
|||
|
|||
#define SAMPLER_NORMALMAP_IDX sampler_NormalMap |
|||
#define SAMPLER_DETAILMASK_IDX sampler_DetailMask |
|||
#define SAMPLER_DETAILMAP_IDX sampler_DetailMap |
|||
#define SAMPLER_MASKMAP_IDX sampler_MaskMap |
|||
#define SAMPLER_SPECULAROCCLUSIONMAP_IDX sampler_SpecularOcclusionMap |
|||
#define SAMPLER_HEIGHTMAP_IDX sampler_HeightMap |
|||
|
|||
#define LAYER_INDEX 0 |
|||
#define ADD_IDX(Name) Name |
|||
#define ADD_ZERO_IDX(Name) Name |
|||
#ifdef _NORMALMAP |
|||
#define _NORMALMAP_IDX |
|||
#endif |
|||
#ifdef _NORMALMAP_TANGENT_SPACE |
|||
#define _NORMALMAP_TANGENT_SPACE_IDX |
|||
#endif |
|||
#ifdef _DETAIL_MAP |
|||
#define _DETAIL_MAP_IDX |
|||
#endif |
|||
#ifdef _MASKMAP |
|||
#define _MASKMAP_IDX |
|||
#endif |
|||
#ifdef _SPECULAROCCLUSIONMAP |
|||
#define _SPECULAROCCLUSIONMAP_IDX |
|||
#endif |
|||
|
|||
void ComputeLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3, |
|||
float3 positionWS, int mappingType, float worldScale, inout LayerTexCoord layerTexCoord, float additionalTiling = 1.0) |
|||
{ |
|||
// Handle uv0, uv1, uv2, uv3 based on _UVMappingMask weight (exclusif 0..1) |
|||
float2 uvBase = ADD_IDX(_UVMappingMask).x * texCoord0 + |
|||
ADD_IDX(_UVMappingMask).y * texCoord1 + |
|||
ADD_IDX(_UVMappingMask).z * texCoord2 + |
|||
ADD_IDX(_UVMappingMask).w * texCoord3; |
|||
|
|||
// Only used with layered, allow to have additional tiling |
|||
uvBase *= additionalTiling.xx; |
|||
|
|||
|
|||
float2 uvDetails = ADD_IDX(_UVDetailsMappingMask).x * texCoord0 + |
|||
ADD_IDX(_UVDetailsMappingMask).y * texCoord1 + |
|||
ADD_IDX(_UVDetailsMappingMask).z * texCoord2 + |
|||
ADD_IDX(_UVDetailsMappingMask).w * texCoord3; |
|||
|
|||
uvDetails *= additionalTiling.xx; |
|||
|
|||
// If base is planar/triplanar then detail map is forced to be planar/triplanar |
|||
ADD_IDX(layerTexCoord.details).mappingType = ADD_IDX(layerTexCoord.base).mappingType = mappingType; |
|||
ADD_IDX(layerTexCoord.details).normalWS = ADD_IDX(layerTexCoord.base).normalWS = layerTexCoord.vertexNormalWS; |
|||
// Copy data for the uvmapping |
|||
ADD_IDX(layerTexCoord.details).triplanarWeights = ADD_IDX(layerTexCoord.base).triplanarWeights = layerTexCoord.triplanarWeights; |
|||
|
|||
// TODO: Currently we only handle world planar/triplanar but we may want local planar/triplanar. |
|||
// In this case both position and normal need to be convert to object space. |
|||
|
|||
// planar/triplanar |
|||
float2 uvXZ; |
|||
float2 uvXY; |
|||
float2 uvZY; |
|||
GetTriplanarCoordinate(positionWS * worldScale, uvXZ, uvXY, uvZY); |
|||
|
|||
// Planar is just XZ of triplanar |
|||
if (mappingType == UV_MAPPING_PLANAR) |
|||
{ |
|||
uvBase = uvDetails = uvXZ; |
|||
} |
|||
|
|||
// Apply tiling options |
|||
ADD_IDX(layerTexCoord.base).uv = TRANSFORM_TEX(uvBase, ADD_IDX(_DiffuseColorMap)); |
|||
ADD_IDX(layerTexCoord.details).uv = TRANSFORM_TEX(uvDetails, ADD_IDX(_DetailMap)); |
|||
|
|||
ADD_IDX(layerTexCoord.base).uvXZ = TRANSFORM_TEX(uvXZ, ADD_IDX(_DiffuseColorMap)); |
|||
ADD_IDX(layerTexCoord.base).uvXY = TRANSFORM_TEX(uvXY, ADD_IDX(_DiffuseColorMap)); |
|||
ADD_IDX(layerTexCoord.base).uvZY = TRANSFORM_TEX(uvZY, ADD_IDX(_DiffuseColorMap)); |
|||
|
|||
ADD_IDX(layerTexCoord.details).uvXZ = TRANSFORM_TEX(uvXZ, ADD_IDX(_DetailMap)); |
|||
ADD_IDX(layerTexCoord.details).uvXY = TRANSFORM_TEX(uvXY, ADD_IDX(_DetailMap)); |
|||
ADD_IDX(layerTexCoord.details).uvZY = TRANSFORM_TEX(uvZY, ADD_IDX(_DetailMap)); |
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
// This part is only relevant for normal mapping with UV_MAPPING_UVSET |
|||
// Note: This code work only in pixel shader (as we rely on ddx), it should not be use in other context |
|||
ADD_IDX(layerTexCoord.base).tangentWS = ADD_IDX(_UVMappingMask).x * layerTexCoord.vertexTangentWS0 + |
|||
ADD_IDX(_UVMappingMask).y * layerTexCoord.vertexTangentWS1 + |
|||
ADD_IDX(_UVMappingMask).z * layerTexCoord.vertexTangentWS2 + |
|||
ADD_IDX(_UVMappingMask).w * layerTexCoord.vertexTangentWS3; |
|||
|
|||
ADD_IDX(layerTexCoord.base).bitangentWS = ADD_IDX(_UVMappingMask).x * layerTexCoord.vertexBitangentWS0 + |
|||
ADD_IDX(_UVMappingMask).y * layerTexCoord.vertexBitangentWS1 + |
|||
ADD_IDX(_UVMappingMask).z * layerTexCoord.vertexBitangentWS2 + |
|||
ADD_IDX(_UVMappingMask).w * layerTexCoord.vertexBitangentWS3; |
|||
|
|||
ADD_IDX(layerTexCoord.details).tangentWS = ADD_IDX(_UVDetailsMappingMask).x * layerTexCoord.vertexTangentWS0 + |
|||
ADD_IDX(_UVDetailsMappingMask).y * layerTexCoord.vertexTangentWS1 + |
|||
ADD_IDX(_UVDetailsMappingMask).z * layerTexCoord.vertexTangentWS2 + |
|||
ADD_IDX(_UVDetailsMappingMask).w * layerTexCoord.vertexTangentWS3; |
|||
|
|||
ADD_IDX(layerTexCoord.details).bitangentWS = ADD_IDX(_UVDetailsMappingMask).x * layerTexCoord.vertexBitangentWS0 + |
|||
ADD_IDX(_UVDetailsMappingMask).y * layerTexCoord.vertexBitangentWS1 + |
|||
ADD_IDX(_UVDetailsMappingMask).z * layerTexCoord.vertexBitangentWS2 + |
|||
ADD_IDX(_UVDetailsMappingMask).w * layerTexCoord.vertexBitangentWS3; |
|||
#endif |
|||
} |
|||
|
|||
// This maybe call directly by tessellation (domain) shader, thus all part regarding surface gradient must be done |
|||
// in function with FragInputs input as parameters |
|||
// layerTexCoord must have been initialize to 0 outside of this function |
|||
void GetLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3, |
|||
float3 positionWS, float3 vertexNormalWS, inout LayerTexCoord layerTexCoord) |
|||
{ |
|||
layerTexCoord.vertexNormalWS = vertexNormalWS; |
|||
layerTexCoord.triplanarWeights = ComputeTriplanarWeights(vertexNormalWS); |
|||
|
|||
int mappingType = UV_MAPPING_UVSET; |
|||
#if defined(_MAPPING_PLANAR) |
|||
mappingType = UV_MAPPING_PLANAR; |
|||
#elif defined(_MAPPING_TRIPLANAR) |
|||
mappingType = UV_MAPPING_TRIPLANAR; |
|||
#endif |
|||
|
|||
// Be sure that the compiler is aware that we don't use UV1 to UV3 for main layer so it can optimize code |
|||
_UVMappingMask = float4(1.0, 0.0, 0.0, 0.0); |
|||
ComputeLayerTexCoord(texCoord0, texCoord1, texCoord2, texCoord3, |
|||
positionWS, mappingType, _TexWorldScale, layerTexCoord); |
|||
} |
|||
|
|||
// This is call only in this file |
|||
// layerTexCoord must have been initialize to 0 outside of this function |
|||
void GetLayerTexCoord(FragInputs input, inout LayerTexCoord layerTexCoord) |
|||
{ |
|||
#ifdef SURFACE_GRADIENT |
|||
GenerateLayerTexCoordBasisTB(input, layerTexCoord); |
|||
#endif |
|||
|
|||
GetLayerTexCoord(input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3, |
|||
input.positionWS, input.worldToTangent[2].xyz, layerTexCoord); |
|||
} |
|||
|
|||
float3 GetNormalTS(FragInputs input, LayerTexCoord layerTexCoord, float3 detailNormalTS, float detailMask, bool useBias, float bias) |
|||
{ |
|||
float3 normalTS; |
|||
|
|||
#ifdef _NORMALMAP_IDX |
|||
#ifdef _NORMALMAP_TANGENT_SPACE_IDX |
|||
if (useBias) |
|||
{ |
|||
normalTS = SAMPLE_UVMAPPING_NORMALMAP_BIAS(ADD_IDX(_NormalMap), SAMPLER_NORMALMAP_IDX, ADD_IDX(layerTexCoord.base), ADD_IDX(_NormalScale), bias); |
|||
} |
|||
else |
|||
{ |
|||
normalTS = SAMPLE_UVMAPPING_NORMALMAP(ADD_IDX(_NormalMap), SAMPLER_NORMALMAP_IDX, ADD_IDX(layerTexCoord.base), ADD_IDX(_NormalScale)); |
|||
} |
|||
#else // Object space |
|||
// to be able to combine object space normal with detail map or to apply a "scale" we transform it to tangent space (object space normal composition is complex operation). |
|||
// then later we will re-transform it to world space. |
|||
// Note: There is no such a thing like triplanar with object space normal, so we call directly 2D function |
|||
if (useBias) |
|||
{ |
|||
#ifdef SURFACE_GRADIENT |
|||
// /We need to decompress the normal ourselve here as UnpackNormalRGB will return a surface gradient |
|||
float3 normalOS = SAMPLE_TEXTURE2D_BIAS(ADD_IDX(_NormalMap), SAMPLER_NORMALMAP_IDX, ADD_IDX(layerTexCoord.base).uv, bias).xyz * 2.0 - 1.0; |
|||
// normalize(normalOS) // TO CHECK: SurfaceGradientFromPerturbedNormal doesn't require normalOS to be normalize, to check |
|||
normalTS = SurfaceGradientFromPerturbedNormal(input.worldToTangent[2], normalOS); |
|||
normalTS *= ADD_IDX(_NormalScale); |
|||
#else |
|||
float3 normalOS = UnpackNormalRGB(SAMPLE_TEXTURE2D_BIAS(ADD_IDX(_NormalMap), SAMPLER_NORMALMAP_IDX, ADD_IDX(layerTexCoord.base).uv, bias), 1.0); |
|||
normalTS = TransformObjectToTangent(normalOS, input.worldToTangent); |
|||
normalTS.xy *= ADD_IDX(_NormalScale); // Scale in tangent space |
|||
normalTS = (normalTS); |
|||
#endif |
|||
} |
|||
else |
|||
{ |
|||
#ifdef SURFACE_GRADIENT |
|||
// /We need to decompress the normal ourselve here as UnpackNormalRGB will return a surface gradient |
|||
float3 normalOS = SAMPLE_TEXTURE2D(ADD_IDX(_NormalMap), SAMPLER_NORMALMAP_IDX, ADD_IDX(layerTexCoord.base).uv).xyz * 2.0 - 1.0; |
|||
// normalize(normalOS) // TO CHECK: SurfaceGradientFromPerturbedNormal doesn't require normalOS to be normalize, to check |
|||
normalTS = SurfaceGradientFromPerturbedNormal(input.worldToTangent[2], normalOS); |
|||
normalTS *= ADD_IDX(_NormalScale); |
|||
#else |
|||
float3 normalOS = UnpackNormalRGB(SAMPLE_TEXTURE2D(ADD_IDX(_NormalMap), SAMPLER_NORMALMAP_IDX, ADD_IDX(layerTexCoord.base).uv), 1.0); |
|||
normalTS = TransformObjectToTangent(normalOS, input.worldToTangent); |
|||
normalTS.xy *= ADD_IDX(_NormalScale); // Scale in tangent space |
|||
normalTS = (normalTS); |
|||
#endif |
|||
} |
|||
#endif |
|||
|
|||
#ifdef _DETAIL_MAP_IDX |
|||
#ifdef SURFACE_GRADIENT |
|||
normalTS += detailNormalTS; |
|||
#else |
|||
normalTS = lerp(normalTS, BlendNormalRNM(normalTS, detailNormalTS), detailMask); |
|||
#endif |
|||
#endif |
|||
#else |
|||
#ifdef SURFACE_GRADIENT |
|||
normalTS = float3(0.0, 0.0, 0.0); // No gradient |
|||
#else |
|||
normalTS = float3(0.0, 0.0, 1.0); |
|||
#endif |
|||
#endif |
|||
|
|||
return normalTS; |
|||
} |
|||
|
|||
float GetSurfaceData(FragInputs input, LayerTexCoord layerTexCoord, out SurfaceData surfaceData, out float3 normalTS) |
|||
{ |
|||
float alpha = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_DiffuseColorMap), ADD_ZERO_IDX(sampler_DiffuseColorMap), ADD_IDX(layerTexCoord.base)).a * ADD_IDX(_DiffuseColor).a; |
|||
|
|||
// Perform alha test very early to save performance (a killed pixel will not sample textures) |
|||
#if defined(_ALPHATEST_ON) && !defined(LAYERED_LIT_SHADER) |
|||
#ifdef HAIR_SHADOW |
|||
clip(alpha - _AlphaCutoffShadow); // Let artists make hair shadow thiner |
|||
#elif defined(HAIR_TRANSPARENT_DEPTH_WRITE) |
|||
alpha = alpha > _AlphaCutoffOpacityThreshold ? 1.0 : alpha; |
|||
clip(alpha - _AlphaCutoffPrepass); // Let artists make prepass cutout thinner |
|||
#else |
|||
clip(alpha - _AlphaCutoff); |
|||
#endif |
|||
#endif |
|||
|
|||
float3 detailNormalTS = float3(0.0, 0.0, 0.0); |
|||
float detailMask = 0.0; |
|||
#ifdef _DETAIL_MAP_IDX |
|||
detailMask = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_DetailMask), SAMPLER_DETAILMASK_IDX, ADD_IDX(layerTexCoord.base)).g; |
|||
float2 detailAlbedoAndSmoothness = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_DetailMap), SAMPLER_DETAILMAP_IDX, ADD_IDX(layerTexCoord.details)).rb; |
|||
float detailAlbedo = detailAlbedoAndSmoothness.r; |
|||
float detailSmoothness = detailAlbedoAndSmoothness.g; |
|||
// Resample the detail map but this time for the normal map. This call should be optimize by the compiler |
|||
// We split both call due to trilinear mapping |
|||
detailNormalTS = SAMPLE_UVMAPPING_NORMALMAP_AG(ADD_IDX(_DetailMap), SAMPLER_DETAILMAP_IDX, ADD_IDX(layerTexCoord.details), ADD_ZERO_IDX(_DetailNormalScale)); |
|||
#endif |
|||
|
|||
surfaceData.diffuseColor = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_DiffuseColorMap), ADD_ZERO_IDX(sampler_DiffuseColorMap), ADD_IDX(layerTexCoord.base)).rgb * ADD_IDX(_DiffuseColor).rgb; |
|||
#ifdef _DETAIL_MAP_IDX |
|||
surfaceData.diffuseColor *= LerpWhiteTo(2.0 * saturate(detailAlbedo * ADD_IDX(_DetailAlbedoScale)), detailMask); |
|||
#endif |
|||
|
|||
#ifdef _SPECULAROCCLUSIONMAP_IDX |
|||
// TODO: Do something. For now just take alpha channel |
|||
surfaceData.specularOcclusion = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_SpecularOcclusionMap), SAMPLER_SPECULAROCCLUSIONMAP_IDX, ADD_IDX(layerTexCoord.base)).a; |
|||
#else |
|||
// The specular occlusion will be perform outside the internal loop |
|||
surfaceData.specularOcclusion = 1.0; |
|||
#endif |
|||
surfaceData.normalWS = float3(0.0, 0.0, 0.0); // Need to init this to keep quiet the compiler, but this is overriden later (0, 0, 0) so if we forget to override the compiler may comply. |
|||
|
|||
// TODO: think about using BC5 |
|||
normalTS = ADD_IDX(GetNormalTS)(input, layerTexCoord, detailNormalTS, detailMask, false, 0.0); |
|||
|
|||
#if defined(_MASKMAP_IDX) |
|||
surfaceData.perceptualSmoothness = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).a; |
|||
#else |
|||
surfaceData.perceptualSmoothness = 1.0; |
|||
#endif |
|||
surfaceData.perceptualSmoothness *= ADD_IDX(_Smoothness); |
|||
#ifdef _DETAIL_MAP_IDX |
|||
surfaceData.perceptualSmoothness *= LerpWhiteTo(2.0 * saturate(detailSmoothness * ADD_IDX(_DetailSmoothnessScale)), detailMask); |
|||
#endif |
|||
|
|||
// MaskMap is RGBA: Metallic, Ambient Occlusion (Optional), emissive Mask (Optional), Smoothness |
|||
#ifdef _MASKMAP_IDX |
|||
surfaceData.ambientOcclusion = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).g; |
|||
#else |
|||
surfaceData.ambientOcclusion = 1.0; |
|||
#endif |
|||
|
|||
// TODO: think about using BC5 |
|||
#ifdef _TANGENTMAP |
|||
#ifdef _NORMALMAP_TANGENT_SPACE_IDX // Normal and tangent use same space |
|||
float3 tangentTS = SAMPLE_UVMAPPING_NORMALMAP(_TangentMap, sampler_TangentMap, layerTexCoord.base, 1.0); |
|||
surfaceData.tangentWS = TransformTangentToWorld(tangentTS, input.worldToTangent); |
|||
#else // Object space |
|||
// Note: There is no such a thing like triplanar with object space normal, so we call directly 2D function |
|||
float3 tangentOS = UnpackNormalRGB(SAMPLE_TEXTURE2D(_TangentMap, sampler_TangentMap, layerTexCoord.base.uv), 1.0); |
|||
surfaceData.tangentWS = TransformObjectToWorldDir(tangentOS); |
|||
#endif |
|||
#else |
|||
#ifdef SURFACE_GRADIENT |
|||
surfaceData.tangentWS = normalize(input.worldToTangent[0].xyz); // The tangent is not normalize in worldToTangent when using surface gradient |
|||
#else |
|||
surfaceData.tangentWS = input.worldToTangent[0].xyz; |
|||
#endif |
|||
#endif |
|||
|
|||
#ifdef _ANISOTROPYMAP |
|||
surfaceData.anisotropy = SAMPLE_UVMAPPING_TEXTURE2D(_AnisotropyMap, sampler_AnisotropyMap, layerTexCoord.base).b; |
|||
#else |
|||
surfaceData.anisotropy = 1.0; |
|||
#endif |
|||
surfaceData.anisotropy *= ADD_IDX(_Anisotropy); |
|||
|
|||
return alpha; |
|||
} |
|||
|
|||
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group |
|||
LODDitheringTransition(posInput.unPositionSS, unity_LODFade.y); // Note that we pass the quantized value of LOD fade |
|||
#endif |
|||
|
|||
//ApplyDoubleSidedFlipOrMirror(input); // flipping is not working, so comment this off for hair( Temp ) |
|||
|
|||
LayerTexCoord layerTexCoord; |
|||
ZERO_INITIALIZE(LayerTexCoord, layerTexCoord); |
|||
GetLayerTexCoord(input, layerTexCoord); |
|||
|
|||
float depthOffset = 0.0; |
|||
|
|||
#ifdef _DEPTHOFFSET_ON |
|||
ApplyDepthOffsetPositionInput(GetCameraForwardDir(), depthOffset, GetWorldToHClipMatrix(), posInput); |
|||
#endif |
|||
|
|||
// We perform the conversion to world of the normalTS outside of the GetSurfaceData |
|||
// so it allow us to correctly deal with detail normal map and optimize the code for the layered shaders |
|||
float3 normalTS; |
|||
float alpha = GetSurfaceData(input, layerTexCoord, surfaceData, normalTS); |
|||
GetNormalAndTangentWS(input, V, normalTS, surfaceData.normalWS, surfaceData.tangentWS); |
|||
// Done one time for all layered - cumulate with spec occ alpha for now |
|||
surfaceData.specularOcclusion *= GetHorizonOcclusion(V, surfaceData.normalWS, input.worldToTangent[2].xyz, _HorizonFade); |
|||
|
|||
// Caution: surfaceData must be fully initialize before calling GetBuiltinData |
|||
GetBuiltinData(input, surfaceData, alpha, depthOffset, builtinData); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 05d099d939fe1f04ca8d8af2ac6ab6fd |
|||
timeCreated: 1495405721 |
|||
licenseType: Free |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_Name: CharacterDebug |
|||
m_Shader: {fileID: 4800000, guid: 2c7b95d356a29c442b067f59d3fb9fc4, type: 3} |
|||
m_ShaderKeywords: _ALPHATEST_ON _DEPTHOFFSETENABLE_OFF _DISTORTIONDEPTHTEST_OFF |
|||
_DISTORTIONENABLE_OFF _DISTORTIONONLY_OFF _DOUBLESIDED_ON _ENABLEPERPIXELDISPLACEMENT_OFF |
|||
_ENABLEWIND_OFF _NORMALMAP_TANGENT_SPACE _NORMALMAP_TANGENT_SPACE0 _NORMALMAP_TANGENT_SPACE1 |
|||
_NORMALMAP_TANGENT_SPACE2 _NORMALMAP_TANGENT_SPACE3 _OBJECTSCALEAFFECTTILE_OFF |
|||
_USEDENSITYMODE_OFF _USEHEIGHTBASEDBLEND_OFF _USEMAINLAYERINFLUENCE_OFF |
|||
m_LightmapFlags: 4 |
|||
m_EnableInstancingVariants: 0 |
|||
m_CustomRenderQueue: 3000 |
|||
stringTagMap: |
|||
LIGHTMODE: Forward |
|||
RenderType: Transparent |
|||
disabledShaderPasses: |
|||
- DistortionVectors |
|||
- SHADOWCASTER |
|||
m_SavedProperties: |
|||
serializedVersion: 3 |
|||
m_TexEnvs: |
|||
- _AnisotropyMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _BaseColorMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _BaseColorMap0: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _BaseColorMap1: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _BaseColorMap2: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _BaseColorMap3: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _BumpMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailAlbedoMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMap0: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMap1: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMap2: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMap3: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMask: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMask0: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMask1: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMask2: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMask3: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailNormalMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DiffuseColorMap: |
|||
m_Texture: {fileID: 2800000, guid: 8d789775a75c5e94fa4007f289b19a1e, type: 3} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DistortionVectorMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _EmissionMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _EmissiveColorMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _HeightMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _HeightMap0: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _HeightMap1: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _HeightMap2: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _HeightMap3: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _LayerMaskMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MainTex: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MaskMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MaskMap0: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MaskMap1: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MaskMap2: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MaskMap3: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MetallicGlossMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _NormalMap: |
|||
m_Texture: {fileID: 2800000, guid: 5b28d7ada5320cf41ac398cbc0a64475, type: 3} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _NormalMap0: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _NormalMap1: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _NormalMap2: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _NormalMap3: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _OcclusionMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _ParallaxMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _SpecularColorMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _SpecularOcclusionMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _SpecularOcclusionMap0: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _SpecularOcclusionMap1: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _SpecularOcclusionMap2: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _SpecularOcclusionMap3: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _SubsurfaceRadiusMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _TangentMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _ThicknessMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
m_Floats: |
|||
- _AlphaCutoff: 0.5 |
|||
- _AlphaCutoffEnable: 1 |
|||
- _AlphaCutoffOpacityThreshold: 0.99 |
|||
- _AlphaCutoffPrepass: 0.5 |
|||
- _AlphaCutoffShadow: 0.362 |
|||
- _Anisotropy: 0 |
|||
- _BlendMode: 0 |
|||
- _BlendUsingHeight1: 0 |
|||
- _BlendUsingHeight2: 0 |
|||
- _BlendUsingHeight3: 0 |
|||
- _BumpScale: 1 |
|||
- _CharacterMaterialID: 1 |
|||
- _CullMode: 0 |
|||
- _Cutoff: 0.5 |
|||
- _DepthOffsetEnable: 0 |
|||
- _DetailAlbedoScale: 1 |
|||
- _DetailAlbedoScale0: 1 |
|||
- _DetailAlbedoScale1: 1 |
|||
- _DetailAlbedoScale2: 1 |
|||
- _DetailAlbedoScale3: 1 |
|||
- _DetailNormalMapScale: 1 |
|||
- _DetailNormalScale: 1 |
|||
- _DetailNormalScale0: 1 |
|||
- _DetailNormalScale1: 1 |
|||
- _DetailNormalScale2: 1 |
|||
- _DetailNormalScale3: 1 |
|||
- _DetailSmoothnessScale: 1 |
|||
- _DetailSmoothnessScale0: 1 |
|||
- _DetailSmoothnessScale1: 1 |
|||
- _DetailSmoothnessScale2: 1 |
|||
- _DetailSmoothnessScale3: 1 |
|||
- _DistortionDepthTest: 0 |
|||
- _DistortionEnable: 0 |
|||
- _DistortionOnly: 0 |
|||
- _DoubleSidedEnable: 1 |
|||
- _DoubleSidedMirrorEnable: 1 |
|||
- _Drag: 1 |
|||
- _DstBlend: 10 |
|||
- _EmissiveColorMode: 1 |
|||
- _EmissiveIntensity: 0 |
|||
- _EnablePerPixelDisplacement: 0 |
|||
- _EnableWind: 0 |
|||
- _GlossMapScale: 1 |
|||
- _Glossiness: 0.5 |
|||
- _GlossyReflections: 1 |
|||
- _HairShadowStrength: 0.678 |
|||
- _HairSpecularShift: 0.272 |
|||
- _HeightAmplitude: 0.01 |
|||
- _HeightAmplitude0: 1 |
|||
- _HeightAmplitude1: 1 |
|||
- _HeightAmplitude2: 1 |
|||
- _HeightAmplitude3: 1 |
|||
- _HeightCenter: 0.5 |
|||
- _HeightCenter0: 0 |
|||
- _HeightCenter1: 0 |
|||
- _HeightCenter2: 0 |
|||
- _HeightCenter3: 0 |
|||
- _HeightCenterOffset0: 0 |
|||
- _HeightCenterOffset1: 0 |
|||
- _HeightCenterOffset2: 0 |
|||
- _HeightCenterOffset3: 0 |
|||
- _HeightFactor0: 1 |
|||
- _HeightFactor1: 1 |
|||
- _HeightFactor2: 1 |
|||
- _HeightFactor3: 1 |
|||
- _HorizonFade: 1.02 |
|||
- _InheritBaseColor1: 0 |
|||
- _InheritBaseColor2: 0 |
|||
- _InheritBaseColor3: 0 |
|||
- _InheritBaseColorThreshold1: 1 |
|||
- _InheritBaseColorThreshold2: 1 |
|||
- _InheritBaseColorThreshold3: 1 |
|||
- _InheritBaseHeight1: 0 |
|||
- _InheritBaseHeight2: 0 |
|||
- _InheritBaseHeight3: 0 |
|||
- _InheritBaseNormal1: 0 |
|||
- _InheritBaseNormal2: 0 |
|||
- _InheritBaseNormal3: 0 |
|||
- _InitialBend: 1 |
|||
- _LayerCenterOffset0: 0 |
|||
- _LayerCenterOffset1: 0 |
|||
- _LayerCenterOffset2: 0 |
|||
- _LayerCenterOffset3: 0 |
|||
- _LayerCount: 2 |
|||
- _LayerHeightAmplitude0: 1 |
|||
- _LayerHeightAmplitude1: 1 |
|||
- _LayerHeightAmplitude2: 1 |
|||
- _LayerHeightAmplitude3: 1 |
|||
- _LayerTiling0: 1 |
|||
- _LayerTiling1: 1 |
|||
- _LayerTiling2: 1 |
|||
- _LayerTiling3: 1 |
|||
- _LayerTilingBlendMask: 1 |
|||
- _MaterialID: 1 |
|||
- _Metallic: 1 |
|||
- _Metallic0: 0 |
|||
- _Metallic1: 0 |
|||
- _Metallic2: 0 |
|||
- _Metallic3: 0 |
|||
- _MinimumOpacity0: 1 |
|||
- _MinimumOpacity1: 1 |
|||
- _MinimumOpacity2: 1 |
|||
- _MinimumOpacity3: 1 |
|||
- _Mode: 0 |
|||
- _NormalMapSpace: 0 |
|||
- _NormalMapSpace0: 0 |
|||
- _NormalMapSpace1: 0 |
|||
- _NormalMapSpace2: 0 |
|||
- _NormalMapSpace3: 0 |
|||
- _NormalScale: 1 |
|||
- _NormalScale0: 1 |
|||
- _NormalScale1: 1 |
|||
- _NormalScale2: 1 |
|||
- _NormalScale3: 1 |
|||
- _ObjectScaleAffectTile: 0 |
|||
- _OcclusionStrength: 1 |
|||
- _OpacityAsDensity0: 0 |
|||
- _OpacityAsDensity1: 0 |
|||
- _OpacityAsDensity2: 0 |
|||
- _OpacityAsDensity3: 0 |
|||
- _PPDLodThreshold: 5 |
|||
- _PPDMaxSamples: 15 |
|||
- _PPDMinSamples: 5 |
|||
- _Parallax: 0.02 |
|||
- _ShiverDirectionality: 0.5 |
|||
- _ShiverDrag: 0.2 |
|||
- _Smoothness: 0.693 |
|||
- _Smoothness0: 1 |
|||
- _Smoothness1: 1 |
|||
- _Smoothness2: 1 |
|||
- _Smoothness3: 1 |
|||
- _SmoothnessTextureChannel: 0 |
|||
- _SpecularHighlights: 1 |
|||
- _SrcBlend: 5 |
|||
- _StencilRef: 2 |
|||
- _Stiffness: 1 |
|||
- _SubsurfaceProfile: 0 |
|||
- _SubsurfaceRadius: 1 |
|||
- _SurfaceType: 1 |
|||
- _TexWorldScale: 1 |
|||
- _TexWorldScale0: 1 |
|||
- _TexWorldScale1: 1 |
|||
- _TexWorldScale2: 1 |
|||
- _TexWorldScale3: 1 |
|||
- _TexWorldScaleBlendMask: 1 |
|||
- _Thickness: 1 |
|||
- _TransparentDepthWritePrepassEnable: 1 |
|||
- _UVBase: 0 |
|||
- _UVBase0: 0 |
|||
- _UVBase1: 0 |
|||
- _UVBase2: 0 |
|||
- _UVBase3: 0 |
|||
- _UVBlendMask: 0 |
|||
- _UVDetail: 0 |
|||
- _UVDetail0: 0 |
|||
- _UVDetail1: 0 |
|||
- _UVDetail2: 0 |
|||
- _UVDetail3: 0 |
|||
- _UVSec: 0 |
|||
- _UseDensityMode: 0 |
|||
- _UseHeightBasedBlend: 0 |
|||
- _UseMainLayerInfluence: 0 |
|||
- _VertexColorMode: 0 |
|||
- _ZTestMode: 8 |
|||
- _ZWrite: 0 |
|||
m_Colors: |
|||
- _BaseColor: {r: 1, g: 1, b: 1, a: 1} |
|||
- _BaseColor0: {r: 1, g: 1, b: 1, a: 1} |
|||
- _BaseColor1: {r: 1, g: 1, b: 1, a: 1} |
|||
- _BaseColor2: {r: 1, g: 1, b: 1, a: 1} |
|||
- _BaseColor3: {r: 1, g: 1, b: 1, a: 1} |
|||
- _Color: {r: 1, g: 1, b: 1, a: 1} |
|||
- _DiffuseColor: {r: 1, g: 1, b: 1, a: 1} |
|||
- _DoubleSidedConstants: {r: 1, g: 1, b: -1, a: 0} |
|||
- _EmissionColor: {r: 1, g: 1, b: 1, a: 1} |
|||
- _EmissiveColor: {r: 0, g: 0, b: 0, a: 1} |
|||
- _HairSpecularHighlight: {r: 0.7058823, g: 0.44117644, b: 0.44117644, a: 1} |
|||
- _SpecularColor: {r: 0.9411765, g: 0.783391, b: 0.5467128, a: 1} |
|||
- _UVDetailsMappingMask: {r: 1, g: 0, b: 0, a: 0} |
|||
- _UVDetailsMappingMask0: {r: 1, g: 0, b: 0, a: 0} |
|||
- _UVDetailsMappingMask1: {r: 1, g: 0, b: 0, a: 0} |
|||
- _UVDetailsMappingMask2: {r: 1, g: 0, b: 0, a: 0} |
|||
- _UVDetailsMappingMask3: {r: 1, g: 0, b: 0, a: 0} |
|||
- _UVMappingMask: {r: 1, g: 0, b: 0, a: 0} |
|||
- _UVMappingMask0: {r: 1, g: 0, b: 0, a: 0} |
|||
- _UVMappingMask1: {r: 1, g: 0, b: 0, a: 0} |
|||
- _UVMappingMask2: {r: 1, g: 0, b: 0, a: 0} |
|||
- _UVMappingMask3: {r: 1, g: 0, b: 0, a: 0} |
|
|||
fileFormatVersion: 2 |
|||
guid: dc1f86b7739f2ee4b924291035b09c35 |
|||
timeCreated: 1495118465 |
|||
licenseType: Free |
|||
NativeFormatImporter: |
|||
mainObjectFileID: 2100000 |
|||
userData: '{"GUIDArray":["","","",""]}' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// shared constant between lit and layered lit |
|||
float _AlphaCutoff; |
|||
float _AlphaCutoffShadow; |
|||
float _AlphaCutoffPrepass; |
|||
float _AlphaCutoffOpacityThreshold; |
|||
|
|||
float4 _DoubleSidedConstants; |
|||
|
|||
float _HorizonFade; |
|||
|
|||
TEXTURE2D(_DiffuseLightingMap); |
|||
SAMPLER2D(sampler_DiffuseLightingMap); |
|||
|
|||
float3 _EmissiveColor; |
|||
TEXTURE2D(_EmissiveColorMap); |
|||
SAMPLER2D(sampler_EmissiveColorMap); |
|||
float _EmissiveIntensity; |
|||
|
|||
// Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor" |
|||
// value that exist to identify if the GI emission need to be enabled. |
|||
// In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it. |
|||
// TODO: Fix the code in legacy unity so we can customize the beahvior for GI |
|||
float3 _EmissionColor; |
|||
|
|||
// Wind |
|||
float _InitialBend; |
|||
float _Stiffness; |
|||
float _Drag; |
|||
float _ShiverDrag; |
|||
float _ShiverDirectionality; |
|||
|
|||
// Set of users variables |
|||
float4 _DiffuseColor; |
|||
TEXTURE2D(_DiffuseColorMap); |
|||
SAMPLER2D(sampler_DiffuseColorMap); |
|||
float4 _DiffuseColorMap_ST; |
|||
|
|||
float _Metallic; |
|||
float _Smoothness; |
|||
TEXTURE2D(_MaskMap); |
|||
SAMPLER2D(sampler_MaskMap); |
|||
TEXTURE2D(_SpecularOcclusionMap); |
|||
SAMPLER2D(sampler_SpecularOcclusionMap); |
|||
|
|||
TEXTURE2D(_NormalMap); |
|||
SAMPLER2D(sampler_NormalMap); |
|||
float _NormalScale; |
|||
|
|||
TEXTURE2D(_DetailMask); |
|||
SAMPLER2D(sampler_DetailMask); |
|||
TEXTURE2D(_DetailMap); |
|||
SAMPLER2D(sampler_DetailMap); |
|||
float4 _DetailMap_ST; |
|||
float _DetailAlbedoScale; |
|||
float _DetailNormalScale; |
|||
float _DetailSmoothnessScale; |
|||
|
|||
TEXTURE2D(_TangentMap); |
|||
SAMPLER2D(sampler_TangentMap); |
|||
|
|||
float _Anisotropy; |
|||
TEXTURE2D(_AnisotropyMap); |
|||
SAMPLER2D(sampler_AnisotropyMap); |
|||
|
|||
float _TexWorldScale; |
|||
float4 _UVMappingMask; |
|||
float4 _UVDetailsMappingMask; |
|
|||
fileFormatVersion: 2 |
|||
guid: 78efab98031ed094bb64bfeb6567d2c7 |
|||
timeCreated: 1495118621 |
|||
licenseType: Free |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 481a89365c6b2f440874035f0b10671a |
|||
folderAsset: yes |
|||
timeCreated: 1495115985 |
|||
licenseType: Free |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
using UnityEditor.AnimatedValues; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public abstract class BaseCharacterGUI : ShaderGUI |
|||
{ |
|||
protected MaterialEditor m_MaterialEditor; |
|||
|
|||
protected Shader hairShader; |
|||
|
|||
protected AnimBool animSkin; |
|||
protected AnimBool animHair; |
|||
protected AnimBool animEye; |
|||
private void SubstanceAnim(Character.CharacterMaterialID id) { //Works for now
|
|||
switch (id) |
|||
{ |
|||
case Character.CharacterMaterialID.Skin: |
|||
animSkin.valueChanged.AddListener(m_MaterialEditor.Repaint); |
|||
animSkin.target = true; animHair.target = false; animEye.target = false; |
|||
break; |
|||
case Character.CharacterMaterialID.Hair: |
|||
animHair.valueChanged.AddListener(m_MaterialEditor.Repaint); |
|||
animSkin.target = false; animHair.target = true; animEye.target = false; |
|||
break; |
|||
case Character.CharacterMaterialID.Eye: |
|||
animEye.valueChanged.AddListener(m_MaterialEditor.Repaint); |
|||
animSkin.target = false; animHair.target = false; animEye.target = true; |
|||
break; |
|||
} |
|||
} |
|||
public BaseCharacterGUI() { |
|||
animSkin = new AnimBool(false); |
|||
animHair = new AnimBool(false); |
|||
animEye = new AnimBool(false); |
|||
|
|||
hairShader = Shader.Find("HDRenderPipeline/ExperimentalHair"); |
|||
} |
|||
|
|||
static public void SetKeyword(Material m, string keyword, bool state) |
|||
{ |
|||
if (state) |
|||
m.EnableKeyword(keyword); |
|||
else |
|||
m.DisableKeyword(keyword); |
|||
} |
|||
|
|||
//---------------------------------------------------------
|
|||
//
|
|||
//---------------------------------------------------------
|
|||
protected abstract void CharacterSkinGUI(Material material); |
|||
protected abstract void CharacterHairGUI(Material material); |
|||
protected abstract void CharacterEyeGUI (Material material); |
|||
|
|||
protected abstract void CharacterSkinKeywordAndPass(Material material); |
|||
protected abstract void CharacterHairKeywordAndPass(Material material); |
|||
protected abstract void CharacterEyeKeywordAndPass (Material material); |
|||
|
|||
//---------------------------------------------------------
|
|||
//GUI Text
|
|||
//---------------------------------------------------------
|
|||
protected static class Styles |
|||
{ |
|||
public static GUIContent characterMaterialIDText = new GUIContent(); |
|||
public static GUIContent characterDiffuseText = new GUIContent("Diffuse Map"); |
|||
public static GUIContent characterNormalText = new GUIContent("Normal Map"); |
|||
|
|||
//TODO: move
|
|||
public static GUIContent hairRoughnessText = new GUIContent("Roughness", ""); |
|||
public static GUIContent hairDetailMap = new GUIContent("Detail Map", ""); |
|||
public static GUIContent hairPrimarySpecText = new GUIContent("Primary Spec", ""); |
|||
public static GUIContent hairSecondarySpecText = new GUIContent("Secondary Spec", ""); |
|||
public static GUIContent hairPrimarySpecShiftText = new GUIContent("Primary Spec Shift", ""); |
|||
public static GUIContent hairSecondarySpecShiftText = new GUIContent("Secondary Spec Shift", ""); |
|||
public static GUIContent hairSpecTintText = new GUIContent("Spec Tint", ""); |
|||
public static GUIContent hairScatterText = new GUIContent("Scatter", ""); |
|||
public static GUIContent hairAlphaCutoffEnableText = new GUIContent("Alpha Cutoff Enable", ""); |
|||
public static GUIContent hairAlphaCutoffText = new GUIContent("Alpha Cutoff", ""); |
|||
public static GUIContent hairAlphaCutoffShadowText = new GUIContent("Alpha Cutoff Shadow", ""); |
|||
public static GUIContent hairTransparentDepthWriteEnableText = new GUIContent("Transparent Depth Write", ""); |
|||
public static GUIContent hairAlphaCutoffPrepass = new GUIContent("Alpha Cutoff Prepass", ""); |
|||
public static GUIContent hairAlphaCutoffOpacityThreshold = new GUIContent("Alpha Cutoff Opacity Threshold", ""); |
|||
|
|||
} |
|||
|
|||
//----------------------------------------------------------
|
|||
//Properties
|
|||
//----------------------------------------------------------
|
|||
protected MaterialProperty materialID = null; |
|||
protected const string kMaterialID = "_CharacterMaterialID"; |
|||
|
|||
protected MaterialProperty diffuseColor = null; |
|||
protected const string kDiffuseColor = "_DiffuseColor"; |
|||
|
|||
protected MaterialProperty diffuseMap = null; |
|||
protected const string kDiffuseMap = "_DiffuseColorMap"; |
|||
|
|||
protected MaterialProperty normalMap = null; |
|||
protected const string kNormalMap = "_NormalMap"; |
|||
|
|||
protected MaterialProperty normalMapScale = null; |
|||
protected const string kNormalMapScale = "_NormalScale"; |
|||
|
|||
//TODO: Move
|
|||
protected MaterialProperty hairRoughness = null; |
|||
protected const string kHairRoughness = "_Smoothness"; //Note, in the shader code we don't invert.
|
|||
|
|||
protected MaterialProperty hairDetailMap = null; |
|||
protected const string kHairDetailMap = "_DetailMap"; |
|||
|
|||
protected MaterialProperty hairPrimarySpec = null; |
|||
protected const string kHairPrimarySpec = "_PrimarySpecular"; |
|||
|
|||
protected MaterialProperty hairSecondarySpec = null; |
|||
protected const string kHairSecondarySpec = "_SecondarySpecular"; |
|||
|
|||
protected MaterialProperty hairPrimarySpecShift = null; |
|||
protected const string kHairPrimarySpecShift = "_PrimarySpecularShift"; |
|||
|
|||
protected MaterialProperty hairSecondarySpecShift = null; |
|||
protected const string kHairSecondarySpecShift = "_SecondarySpecularShift"; |
|||
|
|||
protected MaterialProperty hairSpecTint = null; |
|||
protected const string kHairSpecTint = "_SpecularTint"; |
|||
|
|||
protected MaterialProperty hairScatter = null; |
|||
protected const string kHairScatter = "_Scatter"; |
|||
|
|||
protected MaterialProperty hairAlphaCutoffEnable = null; |
|||
protected const string kHairAlphaCutoffEnable = "_AlphaCutoffEnable"; |
|||
|
|||
protected MaterialProperty hairAlphaCutoff = null; |
|||
protected const string kHairAlphaCutoff = "_AlphaCutoff"; |
|||
|
|||
protected MaterialProperty hairAlphaCutoffShadow = null; |
|||
protected const string kHairAlphaCutoffShadow = "_AlphaCutoffShadow"; |
|||
|
|||
protected MaterialProperty hairTransparentDepthWriteEnable = null; |
|||
protected const string kHairTransparentDepthWriteEnable = "_TransparentDepthPrepassEnable"; |
|||
|
|||
protected MaterialProperty hairCutoffPrepass = null; |
|||
protected const string kHairCutoffPrepass = "_AlphaCutoffPrepass"; |
|||
|
|||
//----------------------------------------------------------
|
|||
//GUI Layout
|
|||
//----------------------------------------------------------
|
|||
public void ShaderPropertiesGUI(Material material) |
|||
{ |
|||
EditorGUIUtility.labelWidth = 0f; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
{ |
|||
EditorGUILayout.LabelField("Substance Type", EditorStyles.largeLabel); |
|||
|
|||
GUI.color = new Color(0.7f, 0.7f, 0.7f); //NOTE: EditorGUIUtility.isProSkin
|
|||
m_MaterialEditor.ShaderProperty(materialID, Styles.characterMaterialIDText); |
|||
GUI.color = Color.white; |
|||
|
|||
EditorGUI.indentLevel++; |
|||
switch((Character.CharacterMaterialID)materialID.floatValue) |
|||
{ |
|||
case Character.CharacterMaterialID.Skin: |
|||
CharacterSkinGUI(material); |
|||
break; |
|||
case Character.CharacterMaterialID.Hair: |
|||
CharacterHairGUI(material); |
|||
break; |
|||
case Character.CharacterMaterialID.Eye: |
|||
CharacterEyeGUI(material); |
|||
break; |
|||
default: |
|||
Debug.Assert(false, "Unsupported Character MaterialID!"); |
|||
break; |
|||
} |
|||
EditorGUI.indentLevel--; |
|||
|
|||
EditorGUILayout.Separator(); |
|||
|
|||
GUILayout.Label("General", EditorStyles.boldLabel); |
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.characterDiffuseText, diffuseMap, diffuseColor); |
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.characterNormalText, normalMap, normalMapScale); |
|||
} |
|||
|
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
//TODO: Common Keywords
|
|||
|
|||
//TODO: Unique Flag Sets
|
|||
int matID = material.GetInt(kMaterialID); |
|||
switch ((Character.CharacterMaterialID)materialID.floatValue) |
|||
{ |
|||
case Character.CharacterMaterialID.Skin: |
|||
CharacterSkinKeywordAndPass(material); |
|||
break; |
|||
case Character.CharacterMaterialID.Hair: |
|||
CharacterHairKeywordAndPass(material); |
|||
break; |
|||
case Character.CharacterMaterialID.Eye: |
|||
CharacterEyeKeywordAndPass(material); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public void FindProperties(MaterialProperty[] props) |
|||
{ |
|||
materialID = FindProperty(kMaterialID, props, false); |
|||
diffuseColor = FindProperty(kDiffuseColor, props); |
|||
diffuseMap = FindProperty(kDiffuseMap, props); |
|||
normalMap = FindProperty(kNormalMap, props); |
|||
normalMapScale = FindProperty(kNormalMapScale, props); |
|||
|
|||
hairRoughness = FindProperty(kHairRoughness, props); |
|||
hairDetailMap = FindProperty(kHairDetailMap, props); |
|||
hairPrimarySpec = FindProperty(kHairPrimarySpec, props); |
|||
hairSecondarySpec = FindProperty(kHairSecondarySpec, props); |
|||
hairPrimarySpecShift = FindProperty(kHairPrimarySpecShift, props); |
|||
hairSecondarySpecShift = FindProperty(kHairSecondarySpecShift, props); |
|||
hairSpecTint = FindProperty(kHairSpecTint, props); |
|||
hairScatter = FindProperty(kHairScatter, props); |
|||
|
|||
hairAlphaCutoffEnable = FindProperty(kHairAlphaCutoffEnable, props); |
|||
hairAlphaCutoff = FindProperty(kHairAlphaCutoff, props); |
|||
hairAlphaCutoffShadow = FindProperty(kHairAlphaCutoffShadow, props); |
|||
hairCutoffPrepass = FindProperty(kHairCutoffPrepass, props); |
|||
hairTransparentDepthWriteEnable = FindProperty(kHairTransparentDepthWriteEnable, props); |
|||
} |
|||
|
|||
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) |
|||
{ |
|||
m_MaterialEditor = materialEditor; |
|||
m_MaterialEditor.serializedObject.Update(); |
|||
|
|||
FindProperties(props); //TODO: Only Base properties here
|
|||
Material material = materialEditor.target as Material; |
|||
SubstanceAnim((Character.CharacterMaterialID)materialID.floatValue); |
|||
ShaderPropertiesGUI(material); |
|||
|
|||
m_MaterialEditor.serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1dc33c157a245764799a419ae38220a3 |
|||
timeCreated: 1495116984 |
|||
licenseType: Free |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
using UnityEditor.AnimatedValues; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
class CharacterGUI : BaseCharacterGUI |
|||
{ |
|||
//-----------------------------------------------------------------------------
|
|||
//GUI
|
|||
//-----------------------------------------------------------------------------
|
|||
protected override void CharacterSkinGUI(Material material) |
|||
{ |
|||
if (EditorGUILayout.BeginFadeGroup(animSkin.faded)) |
|||
{ |
|||
//Skin GUI
|
|||
//------------------------------------------------
|
|||
EditorGUILayout.LabelField("TODO: Skin Parameters", EditorStyles.miniBoldLabel); |
|||
} |
|||
EditorGUILayout.EndFadeGroup(); |
|||
} |
|||
|
|||
protected override void CharacterHairGUI(Material material) |
|||
{ |
|||
|
|||
if (EditorGUILayout.BeginFadeGroup(animHair.faded)) |
|||
{ |
|||
//Hair GUI
|
|||
//--------------------------------------------------
|
|||
m_MaterialEditor.ShaderProperty(hairRoughness, Styles.hairRoughnessText); |
|||
|
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.hairDetailMap, hairDetailMap); |
|||
m_MaterialEditor.TextureScaleOffsetProperty(hairDetailMap); |
|||
|
|||
m_MaterialEditor.ShaderProperty(hairPrimarySpec, Styles.hairPrimarySpecText); |
|||
|
|||
EditorGUI.indentLevel++; |
|||
m_MaterialEditor.ShaderProperty(hairPrimarySpecShift, Styles.hairPrimarySpecShiftText); |
|||
EditorGUI.indentLevel--; |
|||
|
|||
m_MaterialEditor.ShaderProperty(hairSpecTint, Styles.hairSpecTintText); |
|||
|
|||
m_MaterialEditor.ShaderProperty(hairSecondarySpec, Styles.hairSecondarySpecText); |
|||
|
|||
EditorGUI.indentLevel++; |
|||
m_MaterialEditor.ShaderProperty(hairSecondarySpecShift, Styles.hairSecondarySpecShiftText); |
|||
EditorGUI.indentLevel--; |
|||
|
|||
m_MaterialEditor.ShaderProperty(hairScatter, Styles.hairScatterText); |
|||
|
|||
EditorGUILayout.Space(); |
|||
|
|||
m_MaterialEditor.ShaderProperty(hairAlphaCutoffEnable, Styles.hairAlphaCutoffEnableText); |
|||
if(hairAlphaCutoffEnable.floatValue == 1.0f) |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
|
|||
m_MaterialEditor.ShaderProperty(hairAlphaCutoff, Styles.hairAlphaCutoffText); |
|||
if(hairAlphaCutoffShadow != null) |
|||
{ |
|||
m_MaterialEditor.ShaderProperty(hairAlphaCutoffShadow, Styles.hairAlphaCutoffShadowText); |
|||
m_MaterialEditor.ShaderProperty(hairTransparentDepthWriteEnable, Styles.hairTransparentDepthWriteEnableText); |
|||
|
|||
EditorGUI.indentLevel++; |
|||
if(hairTransparentDepthWriteEnable != null && hairTransparentDepthWriteEnable.floatValue == 1.0f) |
|||
{ |
|||
m_MaterialEditor.ShaderProperty(hairCutoffPrepass, Styles.hairAlphaCutoffPrepass); |
|||
} |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
|
|||
EditorGUI.indentLevel--; |
|||
} |
|||
} |
|||
EditorGUILayout.EndFadeGroup(); |
|||
} |
|||
|
|||
protected override void CharacterEyeGUI(Material material) |
|||
{ |
|||
if (EditorGUILayout.BeginFadeGroup(animEye.faded)) |
|||
{ |
|||
//Eye GUI
|
|||
//----------------------------------------------------
|
|||
EditorGUILayout.LabelField("TODO: Eye Parameters", EditorStyles.miniBoldLabel); |
|||
} |
|||
EditorGUILayout.EndFadeGroup(); |
|||
} |
|||
|
|||
//-----------------------------------------------------------------------------
|
|||
//Keyword + Pass
|
|||
//-----------------------------------------------------------------------------
|
|||
protected override void CharacterSkinKeywordAndPass(Material material) |
|||
{ |
|||
material.SetShaderPassEnabled("ShadowCaster", false); |
|||
material.SetShaderPassEnabled("Forward", false); |
|||
material.SetShaderPassEnabled(HDShaderPassNames.s_TransparentDepthPrepassStr, false); |
|||
} |
|||
|
|||
protected override void CharacterHairKeywordAndPass(Material material) |
|||
{ |
|||
//Shader/Pass
|
|||
//------------------------
|
|||
m_MaterialEditor.SetShader(hairShader, true); //NOTE: Do this beforehand
|
|||
material.SetShaderPassEnabled("ShadowCaster", true); |
|||
material.SetShaderPassEnabled("Forward", true); |
|||
|
|||
if (material.HasProperty(kHairTransparentDepthWriteEnable)) |
|||
{ |
|||
bool depthWriteEnable = material.GetFloat(kHairTransparentDepthWriteEnable) > 0.0f; |
|||
if (depthWriteEnable) |
|||
{ |
|||
material.SetShaderPassEnabled(HDShaderPassNames.s_TransparentDepthPrepassStr, true); |
|||
} |
|||
else |
|||
{ |
|||
material.SetShaderPassEnabled(HDShaderPassNames.s_TransparentDepthPrepassStr, false); |
|||
} |
|||
} |
|||
|
|||
//Keywords
|
|||
//------------------------
|
|||
material.SetOverrideTag("RenderType", "Transparent"); |
|||
material.SetInt("_ZWrite", 0); |
|||
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; |
|||
|
|||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); //Blend: Lerp
|
|||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); |
|||
|
|||
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Off); //Double Side Enabled
|
|||
SetKeyword(material, "_DOUBLESIDED_ON", true); |
|||
SetKeyword(material, "_ALPHATEST_ON", material.GetFloat(kHairAlphaCutoffEnable) > 0.0f); |
|||
SetKeyword(material, "_DETAIL_MAP", material.GetTexture(kHairDetailMap)); |
|||
|
|||
} |
|||
|
|||
protected override void CharacterEyeKeywordAndPass(Material material) |
|||
{ |
|||
material.SetShaderPassEnabled("ShadowCaster", false); |
|||
material.SetShaderPassEnabled("Forward", false); |
|||
material.SetShaderPassEnabled(HDShaderPassNames.s_TransparentDepthPrepassStr, false); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bfe595b6d5352554291ab7253d16f869 |
|||
timeCreated: 1495266615 |
|||
licenseType: Free |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: efefa63c6d00406439f41d787cfa8741 |
|||
folderAsset: yes |
|||
timeCreated: 1495115990 |
|||
licenseType: Free |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
// Attributes |
|||
#define REQUIRE_UV_FOR_TESSELATION (defined(TESSELLATION_ON) && (defined(_TESSELLATION_DISPLACEMENT) || defined(_TESSELLATION_DISPLACEMENT_PHONG))) |
|||
#define REQUIRE_VERTEX_COLOR_FOR_TESSELATION REQUIRE_UV_FOR_TESSELATION |
|||
#define REQUIRE_TANGENT_TO_WORLD (defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT)) |
|||
|
|||
// This first set of define allow to say which attributes will be use by the mesh in the vertex and domain shader (for tesselation) |
|||
|
|||
// Tesselation require normal |
|||
#if defined(TESSELLATION_ON) || REQUIRE_TANGENT_TO_WORLD |
|||
#define ATTRIBUTES_NEED_NORMAL |
|||
#endif |
|||
#if REQUIRE_TANGENT_TO_WORLD |
|||
#define ATTRIBUTES_NEED_TANGENT |
|||
#endif |
|||
|
|||
// About UV |
|||
// If we have a lit shader, only the UV0 is available for opacity or heightmap |
|||
// If we have a layered shader, any UV can be use for this. To reduce the number of variant we groupt UV0/UV1 and UV2/UV3 instead of having variant for UV0/UV1/UV2/UV3 |
|||
// When UVX is present, we assume that UVX - 1 ... UV0 is present |
|||
|
|||
#if REQUIRE_UV_FOR_TESSELATION || REQUIRE_TANGENT_TO_WORLD || defined(_ALPHATEST_ON) |
|||
#define ATTRIBUTES_NEED_TEXCOORD0 |
|||
#ifdef LAYERED_LIT_SHADER |
|||
#define ATTRIBUTES_NEED_TEXCOORD1 |
|||
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3) |
|||
#define ATTRIBUTES_NEED_TEXCOORD2 |
|||
#endif |
|||
#if defined(_REQUIRE_UV3) |
|||
#define ATTRIBUTES_NEED_TEXCOORD3 |
|||
#endif |
|||
#endif |
|||
#endif |
|||
|
|||
#if REQUIRE_VERTEX_COLOR_FOR_TESSELATION |
|||
#define ATTRIBUTES_NEED_COLOR |
|||
#endif |
|||
|
|||
// Varying - Use for pixel shader |
|||
// This second set of define allow to say which varyings will be output in the vertex (no more tesselation) |
|||
#if REQUIRE_TANGENT_TO_WORLD |
|||
#define VARYINGS_NEED_POSITION_WS // Required to get view vector |
|||
#define VARYINGS_NEED_TANGENT_TO_WORLD |
|||
#endif |
|||
|
|||
#if REQUIRE_TANGENT_TO_WORLD || defined(_ALPHATEST_ON) |
|||
#define VARYINGS_NEED_TEXCOORD0 |
|||
#ifdef LAYERED_LIT_SHADER |
|||
#define VARYINGS_NEED_TEXCOORD1 |
|||
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3) |
|||
#define VARYINGS_NEED_TEXCOORD2 |
|||
#endif |
|||
#if defined(_REQUIRE_UV3) |
|||
#define VARYINGS_NEED_TEXCOORD3 |
|||
#endif |
|||
#endif |
|||
#endif |
|||
|
|||
// This include will define the various Attributes/Varyings structure |
|||
#include "../../ShaderPass/VaryingMesh.hlsl" |
|
|||
fileFormatVersion: 2 |
|||
guid: c142213b565950144974a796e528d22b |
|||
timeCreated: 1495405737 |
|||
licenseType: Free |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
#define ATTRIBUTES_NEED_NORMAL |
|||
#define ATTRIBUTES_NEED_TANGENT |
|||
#define ATTRIBUTES_NEED_TEXCOORD0 |
|||
#define ATTRIBUTES_NEED_TEXCOORD1 |
|||
#define ATTRIBUTES_NEED_COLOR |
|||
|
|||
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3) || defined(DYNAMICLIGHTMAP_ON) || defined(DEBUG_DISPLAY) |
|||
#define ATTRIBUTES_NEED_TEXCOORD2 |
|||
#endif |
|||
#if defined(_REQUIRE_UV3) || defined(DEBUG_DISPLAY) |
|||
#define ATTRIBUTES_NEED_TEXCOORD3 |
|||
#endif |
|||
|
|||
#define VARYINGS_NEED_POSITION_WS |
|||
#define VARYINGS_NEED_TANGENT_TO_WORLD |
|||
#define VARYINGS_NEED_TEXCOORD0 |
|||
#define VARYINGS_NEED_TEXCOORD1 |
|||
#ifdef ATTRIBUTES_NEED_TEXCOORD2 |
|||
#define VARYINGS_NEED_TEXCOORD2 |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_TEXCOORD3 |
|||
#define VARYINGS_NEED_TEXCOORD3 |
|||
#endif |
|||
#define VARYINGS_NEED_COLOR |
|||
|
|||
#ifdef _DOUBLESIDED_ON |
|||
#define VARYINGS_NEED_CULLFACE |
|||
#endif |
|||
|
|||
#include "../../ShaderPass/VaryingMesh.hlsl" |
|
|||
fileFormatVersion: 2 |
|||
guid: db3b8d1aaf09431448daffa27cb64546 |
|||
timeCreated: 1495407650 |
|||
licenseType: Free |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue