浏览代码

HDRenderLoop LayeredLit: Added a Layer Mask texture and fixed a few compiling errors.

/main
Julien Ignace 8 年前
当前提交
ef4c9761
共有 3 个文件被更改,包括 35 次插入13 次删除
  1. 3
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LayeredLit.shader
  2. 29
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LayeredLitTemplate.hlsl
  3. 16
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LayeredLitUI.cs

3
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LayeredLit.shader


_EmissiveIntensity2("EmissiveIntensity2", Float) = 0
_EmissiveIntensity3("EmissiveIntensity3", Float) = 0
_LayerMaskMap("LayerMaskMap", 2D) = "white" {}
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0
[ToggleOff] _DistortionDepthTest("Distortion Only", Float) = 0.0

#pragma shader_feature _EMISSIVE_COLOR_MAP
#pragma shader_feature _HEIGHTMAP
#pragma shader_feature _HEIGHTMAP_AS_DISPLACEMENT
#pragma shader_feature _LAYERMASKMAP
#include "LayeredLitTemplate.hlsl"

29
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LayeredLitTemplate.hlsl


PROP_DECL(float, _EmissiveIntensity);
float _AlphaCutoff;
sampler2D _LayerMaskMap;
//-------------------------------------------------------------------------------------
// Lighting architecture

float3 BlendLayeredNormal(float3 normal0, float3 normal1, float3 normal2, float3 normal3, float weight[4])
{
// TODO : real normal map blending function
return normal0 * weight[0] + normal1 * weight[1] + normal2 * weight[2] + normal3 * weight[3];
}

void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{
float4 maskValues = input.vertexColor;
float4 maskValues = float4(1.0, 1.0, 1.0, 1.0);// input.vertexColor;
#ifdef _LAYERMASKMAP
float4 maskMap = tex2D(_LayerMaskMap, input.texCoord0);
maskValues *= maskMap;
#endif
float weights[MAX_LAYER];
ComputeMaskWeights(maskValues, weights);

builtinData.opacity = alpha;
PROP_DECL(float, specularOcclusion);
#ifdef _SPECULAROCCLUSIONMAP
// TODO: Do something. For now just take alpha channel

#ifdef _NORMALMAP
#ifdef _NORMALMAP_TANGENT_SPACE
float3 normalTS0 = UnpackNormalDXT5nm(tex2D(_NormalMap0, input.texCoord0));
float3 normalTS1 = UnpackNormalDXT5nm(tex2D(_NormalMap1, input.texCoord0));
float3 normalTS2 = UnpackNormalDXT5nm(tex2D(_NormalMap2, input.texCoord0));
float3 normalTS3 = UnpackNormalDXT5nm(tex2D(_NormalMap3, input.texCoord0));
float3 normalTS0 = UnpackNormalAG(tex2D(_NormalMap0, input.texCoord0));
float3 normalTS1 = UnpackNormalAG(tex2D(_NormalMap1, input.texCoord0));
float3 normalTS2 = UnpackNormalAG(tex2D(_NormalMap2, input.texCoord0));
float3 normalTS3 = UnpackNormalAG(tex2D(_NormalMap3, input.texCoord0));
float3 normalTS = BlendLayeredNormal(normal0, normal1, normal2, normal3, weights);
float3 normalTS = BlendLayeredNormal(normalTS0, normalTS1, normalTS2, normalTS3, weights);
surfaceData.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld);
#else // Object space (TODO: We need to apply the world rotation here!)

PROP_DECL(float, perceptualSmoothness);
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
PROP_SAMPLE(perceptualSmoothness, _BaseColorMap0, input.texCoord0, a);
PROP_SAMPLE(perceptualSmoothness, _BaseColorMap, input.texCoord0, a);
PROP_SAMPLE(perceptualSmoothness, _MaskMap0, input.texCoord0, a);
PROP_SAMPLE(perceptualSmoothness, _MaskMap, input.texCoord0, a);
#else
PROP_ASSIGN_VALUE(perceptualSmoothness, 1.0);
#endif

PROP_DECL(float, metalic);
PROP_DECL(float, ambientOcclusion);
#ifdef _MASKMAP
PROP_SAMPLE(metalic, _MaskMap0, input.texCoord0, a);
PROP_SAMPLE(ambientOcclusion, _MaskMap0, input.texCoord0, g);
PROP_SAMPLE(metalic, _MaskMap, input.texCoord0, a);
PROP_SAMPLE(ambientOcclusion, _MaskMap, input.texCoord0, g);
#else
PROP_ASSIGN_VALUE(metalic, 1.0);
PROP_ASSIGN_VALUE(ambientOcclusion, 1.0);

16
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LayeredLitUI.cs


};
public readonly GUIContent syncButton = new GUIContent("Sync", "Re-synchronize this layer's properties with the referenced Material");
public readonly GUIContent layers = new GUIContent("Layers");
public readonly GUIContent layerMapMask = new GUIContent("LayerMask", "Layer mask (multiplied by vertex color)");
}
static Styles s_Styles = null;

public string[] GUIDArray;
}
private int kSyncButtonWidth = 58;
private int kSyncButtonWidth = 58;
private string kLayerMaskMap = "_LayerMaskMap";
MaterialProperty layerMaskMap = null;
void SynchronizeLayerProperties(int layerIndex)
{

string layerPropertyName = propertyName + layerIndex;
if(material.HasProperty(layerPropertyName))
{
switch(ShaderUtil.GetPropertyType(layerShader, i))
ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(layerShader, i);
switch (type)
{
case ShaderUtil.ShaderPropertyType.Color:
{

case ShaderUtil.ShaderPropertyType.Float:
case ShaderUtil.ShaderPropertyType.Range:
{
material.SetFloat(layerPropertyName, layerMaterial.GetFloat(propertyName));
break;

EditorGUI.indentLevel++;
GUILayout.Label(styles.layers, EditorStyles.boldLabel);
m_MaterialEditor.TexturePropertySingleLine(styles.layerMapMask, layerMaskMap);
for (int i = 0; i < m_MaterialLayers.Length; i++)
{
EditorGUILayout.BeginHorizontal();

SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap + i));
SetKeyword(material, "_HEIGHTMAP", material.GetTexture(kHeightMap + i));
}
SetKeyword(material, "_LAYERMASKMAP", material.GetTexture(kLayerMaskMap));
layerMaskMap = FindProperty(kLayerMaskMap, props);
m_MaterialEditor = materialEditor;

正在加载...
取消
保存