浏览代码

Update to latest from Yibing project

/stochastic_alpha_test
sebastienlagarde 7 年前
当前提交
8814c0c9
共有 7 个文件被更改,包括 41 次插入24 次删除
  1. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Character.shader
  2. 17
      ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Editor/BaseCharacterUI.cs
  3. 8
      ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Editor/CharacterUI.cs
  4. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Hair/Editor/HairUI.cs
  5. 10
      ScriptableRenderPipeline/HDRenderPipeline/Material/Hair/Hair.hlsl
  6. 5
      ScriptableRenderPipeline/HDRenderPipeline/Material/Hair/Hair.shader
  7. 22
      ScriptableRenderPipeline/HDRenderPipeline/Material/Hair/HairData.hlsl

1
ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Character.shader


//Skin
//Hair
[ToggleOff] _HairSprays("Hair Sprays", Float) = 0.0
_HairSpecularShift("SpecularShift", Range(0, 1)) = 0.5
_HairSpecularHighlight("SpecularHighlight", Color) = (1, 1, 1, 1)
_HairShadowStrength("ShadowStrength", Range(0, 1)) = 0.5

17
ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Editor/BaseCharacterUI.cs


//TODO: move
public static GUIContent hairRoughnessText = new GUIContent("Roughness", "");
public static GUIContent hairDetailMap = new GUIContent("Detail Map", "");
public static GUIContent hairDetailMap = new GUIContent("Detail Map A(R) Scatter(G)", "");
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 hairAlphaCutoffEnableText = new GUIContent("Alpha Cutoff Enable", "");
public static GUIContent hairAlphaCutoffText = new GUIContent("Alpha Cutoff", "");
public static GUIContent hairSpraysText = new GUIContent("Hair Sprays", "");
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", "");

//----------------------------------------------------------
//Properties
//----------------------------------------------------------
protected MaterialProperty materialID = null;
protected MaterialProperty hairSprays = null;
protected const string kHairSprays = "_HairSprays";
protected MaterialProperty materialID = null;
protected const string kMaterialID = "_CharacterMaterialID";
protected MaterialProperty diffuseColor = null;

hairSpecTint = FindProperty(kHairSpecTint, props);
hairScatter = FindProperty(kHairScatter, props);
hairAlphaCutoffEnable = FindProperty(kHairAlphaCutoffEnable, props);
hairAlphaCutoff = FindProperty(kHairAlphaCutoff, props);
hairSprays = FindProperty(kHairSprays, props);
hairAlphaCutoffEnable = FindProperty(kHairAlphaCutoffEnable, props);
hairAlphaCutoff = FindProperty(kHairAlphaCutoff, props);
hairAlphaCutoffShadow = FindProperty(kHairAlphaCutoffShadow, props);
hairCutoffPrepass = FindProperty(kHairCutoffPrepass, props);
hairTransparentDepthWriteEnable = FindProperty(kHairTransparentDepthWriteEnable, props);

8
ScriptableRenderPipeline/HDRenderPipeline/Material/Character/Editor/CharacterUI.cs


{
//Hair GUI
//--------------------------------------------------
m_MaterialEditor.ShaderProperty(hairRoughness, Styles.hairRoughnessText);
m_MaterialEditor.ShaderProperty(hairSprays, Styles.hairSpraysText);
m_MaterialEditor.ShaderProperty(hairRoughness, Styles.hairRoughnessText);
m_MaterialEditor.TexturePropertySingleLine(Styles.hairDetailMap, hairDetailMap);
m_MaterialEditor.TextureScaleOffsetProperty(hairDetailMap);

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));
SetKeyword(material, "_HAIRSPRAYS_ON", material.GetFloat(kHairSprays) > 0.0f);
SetKeyword(material, "_ALPHATEST_ON", material.GetFloat(kHairAlphaCutoffEnable) > 0.0f);
SetKeyword(material, "_DETAIL_MAP", material.GetTexture(kHairDetailMap));
}

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Hair/Editor/HairUI.cs


// Details
public static string detailText = "Inputs Detail";
public static GUIContent UVDetailMappingText = new GUIContent("Detail UV mapping", "");
public static GUIContent detailMapNormalText = new GUIContent("Detail Map A(R) Ny(G) S(B) Nx(A)", "Detail Map");
public static GUIContent detailMapNormalText = new GUIContent("Detail Map A(R) Ny(G) S(B) Nx(A)", "Detail Map A(R) Ny(G) S(B) Nx(A)");
public static GUIContent detailMaskText = new GUIContent("Detail Mask (G)", "Mask for detailMap");
public static GUIContent detailAlbedoScaleText = new GUIContent("Detail AlbedoScale", "Detail Albedo Scale factor");
public static GUIContent detailNormalScaleText = new GUIContent("Detail NormalScale", "Normal Scale factor");

10
ScriptableRenderPipeline/HDRenderPipeline/Material/Hair/Hair.hlsl


float invLenLV = rsqrt(abs(2 + 2 * LdotV)); // invLenLV = rcp(length(L + V))
float NdotH = saturate((NdotL + NdotV) * invLenLV);
float LdotH = saturate(invLenLV + invLenLV * LdotV);
float invVdotL = saturate(dot(V,-L));
float3 scatterL = L+bsdfData.normalWS*0.3;
float scatterInvVdotL = saturate(dot(V,-scatterL));
//float3 F = F_Schlick(bsdfData.fresnel0, LdotH);

float3 hairSpec2 = _SecondarySpecular*KajiyaKaySpecular(H, V, bsdfData.normalWS, B2, _SecondarySpecularShift, bsdfData.roughness)*lerp(bsdfData.diffuseColor,_SpecularTint,0.5);
specularLighting = 0.15*bsdfData.perceptualRoughness*(hairSpec1 + hairSpec2);
specularLighting *= (bsdfData.isFrontFace ? 1.0 : 0.0); //Disable backfacing specular for now. Look into having a flipped normal entirely.
float scatterFresnel = 30*pow(invVdotL,9)*(1.0 - NdotV)*(1.0 - NdotL)+ 5*pow((1-NdotV),9);
float scatterFresnel;
#if defined(_HAIRSPRAYS_ON)
scatterFresnel = 5*scatterInvVdotL*(1.0 - NdotV)*(1.0 - NdotL)+ 2*(1-NdotV)*(1-NdotV);
#else
scatterFresnel = 30*pow(scatterInvVdotL,9)*(1.0 - NdotV)*(1.0 - NdotL)+ 5*pow((1-NdotV),9);
#endif
float scatterAmount = _Scatter*scatterFresnel;
float3 transColor = 2*saturate(scatterAmount * float3(1, 0.6, 0.26)*bsdfData.specularOcclusion*bsdfData.specularOcclusion);
float diffuseTerm = Lambert();

5
ScriptableRenderPipeline/HDRenderPipeline/Material/Hair/Hair.shader


// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.
// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear
_DiffuseColor("DiffuseColor", Color) = (1,1,1,1)
[ToggleOff] _HairSprays("Hair Sprays", Float) = 0.0
_DiffuseColor("DiffuseColor", Color) = (1,1,1,1)
_DiffuseColorMap("DiffuseColorMap", 2D) = "white" {}
_Smoothness("Smoothness", Range(0.0, 1.0)) = 1.0

#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _DEPTHOFFSET_ON
#pragma shader_feature _DOUBLESIDED_ON
#pragma shader_feature _HAIRSPRAYS_ON
#pragma shader_feature _ _MAPPING_PLANAR _MAPPING_TRIPLANAR
#pragma shader_feature _NORMALMAP_TANGENT_SPACE

22
ScriptableRenderPipeline/HDRenderPipeline/Material/Hair/HairData.hlsl


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 detailSmoothness = detailAlbedoAndSmoothness.g;
surfaceData.specularOcclusion = detailAlbedoAndSmoothness.g;
float2 detailAoSmoothness = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_DetailMap), SAMPLER_DETAILMAP_IDX, ADD_IDX(layerTexCoord.details)).rg;
float detailSmoothness = detailAoSmoothness.r;
surfaceData.ambientOcclusion = detailSmoothness;
surfaceData.specularOcclusion = detailAoSmoothness.g;
surfaceData.specularOcclusion = 1;
surfaceData.ambientOcclusion = 1;
surfaceData.specularOcclusion = 1;
#endif
surfaceData.diffuseColor = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_DiffuseColorMap), ADD_ZERO_IDX(sampler_DiffuseColorMap), ADD_IDX(layerTexCoord.base)).rgb * ADD_IDX(_DiffuseColor).rgb;

#endif
surfaceData.perceptualSmoothness *= ADD_IDX(_Smoothness);
#ifdef _DETAIL_MAP_IDX
surfaceData.perceptualSmoothness *= 2.0 * saturate(detailSmoothness * ADD_IDX(_DetailSmoothnessScale));
// Use overlay blend mode for detail abledo: (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))
float smoothnessOverlay = (detailSmoothness < 0.5) ?
surfaceData.perceptualSmoothness * PositivePow(2.0 * detailSmoothness, ADD_IDX(_DetailSmoothnessScale)) :
1.0 - (1.0 - surfaceData.perceptualSmoothness) * PositivePow(2.0 * (1.0 - detailSmoothness), ADD_IDX(_DetailSmoothnessScale));
surfaceData.perceptualSmoothness = saturate(smoothnessOverlay);
#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

正在加载...
取消
保存