浏览代码

Merge branch 'master' into movecs

/RenderPassXR_Sandbox
Thomas Hourdel 8 年前
当前提交
4acdd75e
共有 33 个文件被更改,包括 3029 次插入86 次删除
  1. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  2. 54
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  3. 7
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Deferred.shader
  4. 11
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  5. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  6. 60
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader
  7. 2
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipeline.shader
  8. 33
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc
  9. 2
      Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl
  10. 36
      Assets/ScriptableRenderPipeline/ShaderLibrary/CommonLighting.hlsl
  11. 4
      Assets/ScriptableRenderPipeline/ShaderLibrary/Shadow/ShadowSampling.hlsl
  12. 9
      Assets/LegacyLayered.meta
  13. 9
      Assets/LegacyLayered/Editor.meta
  14. 736
      Assets/LegacyLayered/Editor/LayeredPhotogrammetryUI.cs
  15. 12
      Assets/LegacyLayered/Editor/LayeredPhotogrammetryUI.cs.meta
  16. 603
      Assets/LegacyLayered/LayeredPhotogrammetry.shader
  17. 9
      Assets/LegacyLayered/LayeredPhotogrammetry.shader.meta
  18. 140
      Assets/LegacyLayered/LayeredPhotogrammetryDataInternal.cginc
  19. 9
      Assets/LegacyLayered/LayeredPhotogrammetryDataInternal.cginc.meta
  20. 91
      Assets/LegacyLayered/LayeredPhotogrammetrySampleUVMapping.cginc
  21. 9
      Assets/LegacyLayered/LayeredPhotogrammetrySampleUVMapping.cginc.meta
  22. 48
      Assets/LegacyLayered/LayeredPhotogrammetrySampleUVMappingInternal.cginc
  23. 9
      Assets/LegacyLayered/LayeredPhotogrammetrySampleUVMappingInternal.cginc.meta
  24. 1001
      Assets/LegacyLayered/UnityLayeredPhotogrammetryCore.cginc
  25. 9
      Assets/LegacyLayered/UnityLayeredPhotogrammetryCore.cginc.meta
  26. 20
      Assets/LegacyLayered/UnityLayeredPhotogrammetryCoreForward.cginc
  27. 9
      Assets/LegacyLayered/UnityLayeredPhotogrammetryCoreForward.cginc.meta
  28. 75
      Assets/LegacyLayered/UnityLayeredPhotogrammetryInput.cginc
  29. 9
      Assets/LegacyLayered/UnityLayeredPhotogrammetryInput.cginc.meta
  30. 82
      Assets/LegacyLayered/UnityLayeredPhotogrammetryMeta.cginc
  31. 9
      Assets/LegacyLayered/UnityLayeredPhotogrammetryMeta.cginc.meta

6
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


EditorGUI.BeginChangeCheck();
// Old SSS Model >>>
EditorGUI.BeginChangeCheck();
if (EditorGUI.EndChangeCheck())
{
HDRenderPipeline hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
hdPipeline.CreateSssMaterials(m_UseDisneySSS.boolValue);
}
// <<< Old SSS Model
EditorGUILayout.PropertyField(m_NumProfiles, styles.sssNumProfiles);

54
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


readonly GBufferManager m_gbufferManager = new GBufferManager();
// Various set of material use in render loop
readonly Material m_FilterAndCombineSubsurfaceScattering;
Material m_FilterAndCombineSubsurfaceScattering;
readonly Material m_FilterSubsurfaceScattering;
Material m_FilterSubsurfaceScattering;
// <<< Old SSS Model
Material m_CameraMotionVectorsMaterial;

// Various buffer
readonly int m_CameraColorBuffer;
readonly int m_CameraSubsurfaceBuffer;
// Old SSS Model >>>
// <<< Old SSS Model
readonly int m_VelocityBuffer;
readonly int m_DistortionBuffer;

m_CameraColorBuffer = Shader.PropertyToID("_CameraColorTexture");
m_CameraSubsurfaceBuffer = Shader.PropertyToID("_CameraSubsurfaceTexture");
m_CameraFilteringBuffer = Shader.PropertyToID("_CameraFilteringBuffer");
m_FilterAndCombineSubsurfaceScattering = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/CombineSubsurfaceScattering");
m_CameraFilteringBuffer = Shader.PropertyToID("_CameraFilteringBuffer");
m_FilterSubsurfaceScattering = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/CombineSubsurfaceScattering");
m_FilterSubsurfaceScattering.DisableKeyword("SSS_FILTER_HORIZONTAL_AND_COMBINE");
m_FilterSubsurfaceScattering.SetFloat("_DstBlend", (float)BlendMode.Zero);
m_FilterAndCombineSubsurfaceScattering.EnableKeyword("SSS_FILTER_HORIZONTAL_AND_COMBINE");
m_FilterAndCombineSubsurfaceScattering.SetFloat("_DstBlend", (float)BlendMode.One);
CreateSssMaterials(sssSettings.useDisneySSS);
// <<< Old SSS Model
m_CameraMotionVectorsMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/CameraMotionVectors");

m_DebugFullScreen = Utilities.CreateEngineMaterial(m_Asset.renderPipelineResources.debugFullScreenShader);
}
// Old SSS Model >>>
public void CreateSssMaterials(bool useDisneySSS)
{
Utilities.Destroy(m_FilterSubsurfaceScattering);
m_FilterSubsurfaceScattering = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/CombineSubsurfaceScattering");
Utilities.SelectKeyword(m_FilterSubsurfaceScattering, "SSS_MODEL_DISNEY", "SSS_MODEL_BASIC", useDisneySSS);
m_FilterSubsurfaceScattering.DisableKeyword("SSS_FILTER_HORIZONTAL_AND_COMBINE");
m_FilterSubsurfaceScattering.SetFloat("_DstBlend", (float)BlendMode.Zero);
Utilities.Destroy(m_FilterAndCombineSubsurfaceScattering);
m_FilterAndCombineSubsurfaceScattering = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/CombineSubsurfaceScattering");
Utilities.SelectKeyword(m_FilterAndCombineSubsurfaceScattering, "SSS_MODEL_DISNEY", "SSS_MODEL_BASIC", useDisneySSS);
m_FilterAndCombineSubsurfaceScattering.EnableKeyword("SSS_FILTER_HORIZONTAL_AND_COMBINE");
m_FilterAndCombineSubsurfaceScattering.SetFloat("_DstBlend", (float)BlendMode.One);
}
// <<< Old SSS Model
public void OnSceneLoad()
{
// Recreate the textures which went NULL

Shader.SetGlobalInt( "_TexturingModeFlags", (int)sssParameters.texturingModeFlags);
Shader.SetGlobalInt( "_TransmissionFlags", (int)sssParameters.transmissionFlags);
cmd.SetGlobalFloatArray( "_ThicknessRemaps", sssParameters.thicknessRemaps);
cmd.SetGlobalVectorArray("_ShapeParams", sssParameters.shapeParams);
// We are currently supporting two different SSS mode: Jimenez (with 2-Gaussian profile) and Disney
// We have added the ability to switch between each other for subsurface scattering, but for transmittance this is more tricky as we need to add
// shader variant for forward, gbuffer and deferred shader. We want to avoid this.
// So for transmittance we use Disney profile formulation (that we know is more correct) in both case, and in the case of Jimenez we hack the parameters with 2-Gaussian parameters (Ideally we should fit but haven't find good fit) so it approximately match.
// Note: Jimenez SSS is in cm unit whereas Disney is in mm unit making an inconsistency here to compare model side by side
cmd.SetGlobalVectorArray("_ShapeParams", sssParameters.useDisneySSS ? sssParameters.shapeParams : sssParameters.halfRcpWeightedVariances);
cmd.SetGlobalVectorArray("_TransmissionTints", sssParameters.transmissionTints);
renderContext.ExecuteCommandBuffer(cmd);

if (sssSettings.useDisneySSS)
{
Utilities.SelectKeyword(m_FilterAndCombineSubsurfaceScattering, "SSS_MODEL_DISNEY", "SSS_MODEL_BASIC", true);
cmd.SetGlobalTexture("_IrradianceSource", m_CameraSubsurfaceBufferRT); // Cannot set a RT on a material
m_FilterAndCombineSubsurfaceScattering.SetFloatArray("_WorldScales", sssParameters.worldScales);
m_FilterAndCombineSubsurfaceScattering.SetFloatArray("_FilterKernelsNearField", sssParameters.filterKernelsNearField);

}
else
{
Utilities.SelectKeyword(m_FilterSubsurfaceScattering, "SSS_MODEL_DISNEY", "SSS_MODEL_BASIC", false);
Utilities.SelectKeyword(m_FilterAndCombineSubsurfaceScattering, "SSS_MODEL_DISNEY", "SSS_MODEL_BASIC", false);
cmd.SetGlobalTexture("_IrradianceSource", m_CameraSubsurfaceBufferRT); // Cannot set a RT on a material
cmd.SetGlobalTexture("_IrradianceSource", m_CameraSubsurfaceBufferRT);
context.ExecuteCommandBuffer(cmd); // Does not work if I don't execute the command buffer in between the draws.
cmd.SetGlobalTexture("_IrradianceSource", m_CameraFilteringBufferRT); // Cannot set a RT on a material
cmd.SetGlobalTexture("_IrradianceSource", m_CameraFilteringBufferRT);
Utilities.DrawFullScreen(cmd, m_FilterAndCombineSubsurfaceScattering, hdCamera, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT);
}

cmd.GetTemporaryRT(m_CameraColorBuffer, w, h, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear, 1, true); // Enable UAV
cmd.GetTemporaryRT(m_CameraSubsurfaceBuffer, w, h, 0, FilterMode.Point, RenderTextureFormat.RGB111110Float, RenderTextureReadWrite.Linear, 1, true); // Enable UAV
// Old SSS Model >>>
// <<< Old SSS Model
if (!m_Asset.renderingSettings.ShouldUseForwardRenderingOnly())
{

Utilities.SetRenderTarget(renderContext, m_CameraSubsurfaceBufferRT, m_CameraDepthStencilBufferRT, ClearFlag.ClearColor, Color.black);
}
// Old SSS Model >>>
// <<< Old SSS Model
// TEMP: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.

7
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Deferred.shader


outputs.specularLighting = float4(specularLighting, 1.0);
outputs.diffuseLighting = diffuseLighting;
#if defined(LIGHTLOOP_TILE_INDIRECT) || defined(LIGHTLOOP_TILE_ALL)
// Force non-0 indirect lighting to avoid SSS artifacts.
outputs.diffuseLighting.r = max(outputs.diffuseLighting.r, 0.000001);
// We SSSSS is enabled with use split lighting.
// SSSSS algorithm need to know which pixels contribute to SSS and which doesn't. We could use the stencil for that but it mean that it will increase the cost of SSSSS
// A simpler solution is to add a slight contribution here that isn't visible (here we chose fp16 min (which is also fp11 and fp10 min).
// The SSSSS algorithm will check if diffuse lighting is black and discard the pixel if it is the case
outputs.diffuseLighting.r = max(outputs.diffuseLighting.r, HFLT_MIN);
#endif
#else
outputs.combinedLighting = float4(diffuseLighting + specularLighting, 1.0);

11
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


// Subsurface
public static GUIContent subsurfaceProfileText = new GUIContent("Subsurface profile", "A profile determines the shape of the blur filter.");
public static GUIContent subsurfaceRadiusText = new GUIContent("Subsurface radius", "Determines the range of the blur.");
public static GUIContent subsurfaceRadiusMapText = new GUIContent("Subsurface radius map", "Determines the range of the blur.");
public static GUIContent subsurfaceRadiusMapText = new GUIContent("Subsurface radius map (R)", "Determines the range of the blur.");
public static GUIContent thicknessMapText = new GUIContent("Thickness map", "If subsurface scattering is enabled, low values allow some light to be transmitted through the object.");
public static GUIContent thicknessMapText = new GUIContent("Thickness map (R)", "If subsurface scattering is enabled, low values allow some light to be transmitted through the object.");
// Specular color
public static GUIContent specularColorText = new GUIContent("Specular Color", "Specular color (RGB)");

EditorGUI.indentLevel++;
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap, baseColor);
m_MaterialEditor.ShaderProperty(metallic, Styles.metallicText);
if ((Lit.MaterialId)materialID.floatValue == Lit.MaterialId.LitStandard)
{
m_MaterialEditor.ShaderProperty(metallic, Styles.metallicText);
}
m_MaterialEditor.ShaderProperty(smoothness, Styles.smoothnessText);
if (useEmissiveMask)

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl


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));
detailNormalTS = SAMPLE_UVMAPPING_NORMALMAP_AG(ADD_IDX(_DetailMap), SAMPLER_DETAILMAP_IDX, ADD_IDX(layerTexCoord.details), ADD_IDX(_DetailNormalScale));
#endif
surfaceData.baseColor = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_BaseColorMap), ADD_ZERO_IDX(sampler_BaseColorMap), ADD_IDX(layerTexCoord.base)).rgb * ADD_IDX(_BaseColor).rgb;

60
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader


}
// Computes F(x)/P(x), s.t. x = sqrt(r^2 + t^2).
float3 ComputeBilateralWeight(float3 S, float r, float t, float rcpDistScale, float rcpPdf)
float3 ComputeBilateralWeight(float3 S, float r, float t, float rcpPdf)
// Reducing the integration distance is equivalent to stretching the integration axis.
float3 val = KernelValCircle(sqrt(r * r + t * t) * rcpDistScale, S);
float3 val = KernelValCircle(sqrt(r * r + t * t), S);
// Rescaling of the PDF is handled via 'totalWeight'.
// Rescaling of the PDF is handled by 'totalWeight'.
millimPerUnit, scaledPixPerMm, rcpDistScale, totalIrradiance, totalWeight) \
millimPerUnit, pixelsPerMm, totalIrradiance, totalWeight) \
{ \
float r = kernel[profileID][i][0]; \
/* The relative sample position is known at compile time. */ \

float2 position = centerPosUnSS + vec * scaledPixPerMm; \
float2 position = centerPosUnSS + vec * pixelsPerMm; \
float3 irradiance = LOAD_TEXTURE2D(_IrradianceSource, position).rgb; \
\
/* TODO: see if making this a [branch] improves performance. */ \

float d = LinearEyeDepth(z, _ZBufferParams); \
float t = millimPerUnit * d - (millimPerUnit * centerDepthVS); \
float p = kernel[profileID][i][1]; \
float3 w = ComputeBilateralWeight(shapeParam, r, t, rcpDistScale, p); \
float3 w = ComputeBilateralWeight(shapeParam, r, t, p); \
\
totalIrradiance += w * irradiance; \
totalWeight += w; \

/* Our blur is energy-preserving, so 'centerWeight' should be set to 0. */ \
/* We do not terminate the loop since we want to gather the contribution */ \
/* of the remaining samples (e.g. in case of hair covering skin). */ \
/* Note: See comment in the output of deferred.shader */ \
millimPerUnit, scaledPixPerMm, rcpDistScale, totalIrradiance, totalWeight) \
millimPerUnit, pixelsPerMm, totalIrradiance, totalWeight) \
{ \
float centerRcpPdf = kernel[profileID][0][1]; \
float3 centerWeight = KernelValCircle(0, shapeParam) * centerRcpPdf; \

for (uint i = 1; i < n; i++) \
{ \
SSS_ITER(i, n, kernel, profileID, shapeParam, centerPosUnSS, centerDepthVS, \
millimPerUnit, scaledPixPerMm, rcpDistScale, totalIrradiance, totalWeight) \
millimPerUnit, pixelsPerMm, totalIrradiance, totalWeight) \
} \
}

float3 cornerPosVS = ComputeViewSpacePosition(cornerPosSS, centerDepth, _InvProjMatrix);
// Compute the view-space dimensions of the pixel as a quad projected onto geometry.
float2 unitsPerPixel = 2 * (cornerPosVS.xy - centerPosVS.xy);
float2 unitsPerPixel = 2 * abs(cornerPosVS.xy - centerPosVS.xy);
float metersPerUnit = _WorldScales[profileID];
float millimPerUnit = MILLIMETERS_PER_METER * metersPerUnit;
float2 scaledPixPerMm = distScale * rcp(millimPerUnit * unitsPerPixel);
// Rescaling the filter is equivalent to inversely scaling the world.
float metersPerUnit = _WorldScales[profileID] / distScale;
float millimPerUnit = MILLIMETERS_PER_METER * metersPerUnit;
float2 pixelsPerMm = rcp(millimPerUnit * unitsPerPixel);
// Take the first (central) sample.
// TODO: copy its neighborhood into LDS.

float maxDistInPixels = maxDistance * max(scaledPixPerMm.x, scaledPixPerMm.y);
float maxDistInPixels = maxDistance * max(pixelsPerMm.x, pixelsPerMm.y);
[branch]
if (distScale == 0 || maxDistInPixels < 1)
{

#else
SSS_LOOP(SSS_N_SAMPLES_FAR_FIELD, _FilterKernelsFarField,
profileID, shapeParam, centerPosition, centerPosVS.z,
millimPerUnit, scaledPixPerMm, rcp(distScale),
totalIrradiance, totalWeight)
millimPerUnit, pixelsPerMm, totalIrradiance, totalWeight)
#endif
}
else

#else
SSS_LOOP(SSS_N_SAMPLES_NEAR_FIELD, _FilterKernelsNearField,
profileID, shapeParam, centerPosition, centerPosVS.z,
millimPerUnit, scaledPixPerMm, rcp(distScale),
totalIrradiance, totalWeight)
millimPerUnit, pixelsPerMm, totalIrradiance, totalWeight)
float metersPerUnit = _WorldScales[profileID] * SSS_BASIC_DISTANCE_SCALE;
float centimPerUnit = CENTIMETERS_PER_METER * metersPerUnit;
float2 scaledPixPerCm = distScale * rcp(centimPerUnit * unitsPerPixel);
float unitScale = centimPerUnit / distScale;
// Rescaling the filter is equivalent to inversely scaling the world.
float metersPerUnit = _WorldScales[profileID] / distScale * SSS_BASIC_DISTANCE_SCALE;
float centimPerUnit = CENTIMETERS_PER_METER * metersPerUnit;
float2 pixelsPerCm = rcp(centimPerUnit * unitsPerPixel);
float scaledStepSize = scaledPixPerCm.x;
float2 unitDirection = float2(1, 0);
float2 unitDirection = float2(1, 0);
float scaledStepSize = scaledPixPerCm.y;
float2 unitDirection = float2(0, 1);
float2 unitDirection = float2(0, 1);
float2 scaledDirection = scaledPixPerCm * unitDirection;
float2 scaledDirection = pixelsPerCm * unitDirection;
#if (RBG_BILATERAL_WEIGHTS != 0)
#if RBG_BILATERAL_WEIGHTS
float3 halfRcpVariance = _HalfRcpWeightedVariances[profileID].rgb;
#else
float halfRcpVariance = _HalfRcpWeightedVariances[profileID].a;

// We perform point sampling. Therefore, we can avoid the cost
// of filtering if we stay within the bounds of the current pixel.
// We use the value of 1 instead of 0.5 as an optimization.
float maxDistInPixels = scaledStepSize * maxDistance;
float maxDistInPixels = maxDistance * max(pixelsPerCm.x, pixelsPerCm.y);
[branch]
if (distScale == 0 || maxDistInPixels < 1)

[flatten]
if (any(sampleIrradiance))
{
#if SSS_BILATERAL
float zDistance = unitScale * sampleDepth - (unitScale * centerPosVS.z);
float zDistance = centimPerUnit * sampleDepth - (centimPerUnit * centerPosVS.z);
#endif
totalIrradiance += sampleWeight * sampleIrradiance;
totalWeight += sampleWeight;

2
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipeline.shader


half4 frag(v2f i) : SV_Target
{
half4 diffuseAlpha = tex2D(_MainTex, i.uv01.xy);
half4 diffuseAlpha = Tex2DLinearRGBA(_MainTex, i.uv01.xy);
half3 diffuse = diffuseAlpha.rgb * _Color.rgb;
half alpha = diffuseAlpha.a * _Color.a;

33
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc


#define _SHADOW_CASCADES
#endif
#if (defined(UNITY_COLORSPACE_GAMMA) || SHADER_TARGET < 30) && defined(LIGHTWEIGHT_FORCE_LINEAR)
// Ideally we want an approximation of gamma curve 2.0 to save ALU on GPU but as off now it won't match the GammaToLinear conversion of props in engine
//#define LIGHTWEIGHT_GAMMA_TO_LINEAR(gammaColor) gammaColor * gammaColor
//#define LIGHTWEIGHT_LINEAR_TO_GAMMA(linColor) sqrt(color)
#define LIGHTWEIGHT_GAMMA_TO_LINEAR(sRGB) sRGB * (sRGB * (sRGB * 0.305306011h + 0.682171111h) + 0.012522878h)
#define LIGHTWEIGHT_LINEAR_TO_GAMMA(linRGB) max(1.055h * pow(max(linRGB, 0.h), 0.416666667h) - 0.055h, 0.h)
#else
#define LIGHTWEIGHT_GAMMA_TO_LINEAR(color) color
#define LIGHTWEIGHT_LINEAR_TO_GAMMA(color) color
#endif
struct LightInput
{
half4 pos;

#include "LightweightPipelineShadows.cginc"
#endif
inline half3 Tex2DLinearRGB(sampler2D s, half2 uv)
{
return LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(s, uv).rgb);
}
inline half4 Tex2DLinearRGBA(sampler2D s, half2 uv)
{
half4 color = tex2D(s, uv);
return half4(LIGHTWEIGHT_GAMMA_TO_LINEAR(color.rgb), color.a);
}
inline void NormalMap(v2f i, out half3 normal)
{
#if _NORMALMAP

inline void SpecularGloss(half2 uv, half alpha, out half4 specularGloss)
{
#ifdef _SPECGLOSSMAP
specularGloss = tex2D(_SpecGlossMap, uv) * _SpecColor;
specularGloss = Tex2DLinearRGBA(_SpecGlossMap, uv) * _SpecColor;
specularGloss = tex2D(_SpecGlossMap, uv) * _SpecColor;
specularGloss = Tex2DLinearRGBA(_SpecGlossMap, uv) * _SpecColor;
specularGloss.a = alpha;
#else
specularGloss = _SpecColor;

inline void Emission(half2 uv, inout half3 color)
{
#ifdef _EMISSION
color += tex2D(_EmissionMap, uv) * _EmissionColor;
color += Tex2DLinearRGB(_EmissionMap, uv) * _EmissionColor;
#else
color += _EmissionColor;
#endif

{
#ifdef _ALPHABLEND_ON
return half4(color, alpha);
return LIGHTWEIGHT_LINEAR_TO_GAMMA(half4(color, alpha));
return half4(color, 1);
return half4(LIGHTWEIGHT_LINEAR_TO_GAMMA(color), 1);
#endif
}

2
Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl


#define FLT_MIN 1.175494351e-38 // Minimum representable positive floating-point number
#define FLT_MAX 3.402823466e+38 // Maximum representable floating-point number
#define HFLT_MIN 0.00006103515625 // 2^14 it is the same for 10, 11 and 16bit float. ref: https://www.khronos.org/opengl/wiki/Small_Float_Formats
float DegToRad(float deg)
{
return deg * PI / 180.0;

36
Assets/ScriptableRenderPipeline/ShaderLibrary/CommonLighting.hlsl


return N;
}
// Generates an orthonormal basis from a unit vector.
// Generates an orthonormal right-handed basis from a unit vector.
// Ref: http://marc-b-reynolds.github.io/quaternions/2016/07/06/Orthonormal.html
float3 upVector = abs(localZ.z) < 0.999 ? float3(0.0, 0.0, 1.0) : float3(1.0, 0.0, 0.0);
float3 localX = normalize(cross(upVector, localZ));
float3 localY = cross(localZ, localX);
return float3x3(localX, localY, localZ);
}
float x = localZ.x;
float y = localZ.y;
float z = localZ.z;
float sz = z >= 0 ? 1 : -1;
float a = 1 / (sz + z);
float ya = y * a;
float b = x * ya;
float c = x * sz;
// TODO: test
/*
// http://orbit.dtu.dk/files/57573287/onb_frisvad_jgt2012.pdf
void GetLocalFrame(float3 N, out float3 tangentX, out float3 tangentY)
{
if (N.z < -0.999) // Handle the singularity
{
tangentX = float3(0.0, -1.0, 0.0);
tangentY = float3(-1.0, 0.0, 0.0);
return ;
}
float3 localX = float3(c * x * a - 1, sz * b, c);
float3 localY = float3(b, y * ya - sz, y);
float a = 1.0 / (1.0 + N.z);
float b = -N.x * N.y * a;
tangentX = float3(1.0 - N.x * N.x * a , b, -N.x);
tangentY = float3(b, 1.0 - N.y * N.y * a, -N.y);
return float3x3(localX, localY, localZ);
*/
#endif // UNITY_COMMON_LIGHTING_INCLUDED

4
Assets/ScriptableRenderPipeline/ShaderLibrary/Shadow/ShadowSampling.hlsl


float depthBias = params.z;
float bpp16 = params.w;
#if UNITY_REVERSED_Z
float depth = (1.0 - tcs.z) + depthBias;
float depth = (1.0 - tcs.z) - depthBias;
#else
float depth = tcs.z + depthBias;
#endif

float depthBias = params.z;
float bpp16 = params.w;
#if UNITY_REVERSED_Z
float depth = (1.0 - tcs.z) + depthBias;
float depth = (1.0 - tcs.z) - depthBias;
#else
float depth = tcs.z + depthBias;
#endif

9
Assets/LegacyLayered.meta


fileFormatVersion: 2
guid: 78d15b13b40de7a4891eb491afc04d28
folderAsset: yes
timeCreated: 1497255974
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/LegacyLayered/Editor.meta


fileFormatVersion: 2
guid: 5676a938b6eb98341a6a6c5b52ca30e1
folderAsset: yes
timeCreated: 1497279200
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

736
Assets/LegacyLayered/Editor/LayeredPhotogrammetryUI.cs


using System;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEditor;
using System.Linq;
//namespace UnityEditor.Experimental.Rendering.HDPipeline
//{
internal class LayeredPhotogrammetryGUI : ShaderGUI//LitGUI
{
protected const string kUVBase = "_UVBase";
protected const string kTexWorldScale = "_TexWorldScale";
protected const string kUVMappingMask = "_UVMappingMask";
protected const string kBaseColor = "_BaseColor";
protected const string kBaseColorMap = "_BaseColorMap";
protected const string kMetallic = "_Metallic";
protected const string kSmoothness = "_Smoothness";
protected const string kMaskMap = "_MaskMap";
protected const string kNormalMap = "_NormalMap";
protected const string kNormalScale = "_NormalScale";
protected const string kHeightMap = "_HeightMap";
protected const string kHeightAmplitude = "_LayerHeightAmplitude";
protected const string kHeightCenter = "_LayerHeightCenter";
protected const string kUVDetail = "_UVDetail";
protected const string kUVDetailsMappingMask = "_UVDetailsMappingMask";
protected const string kDetailMap = "_DetailMap";
protected const string kDetailMask = "_DetailMask";
protected const string kDetailAlbedoScale = "_DetailAlbedoScale";
protected const string kDetailNormalScale = "_DetailNormalScale";
protected const string kDetailSmoothnessScale = "_DetailSmoothnessScale";
protected MaterialProperty alphaCutoffEnable = null;
protected const string kAlphaCutoffEnabled = "_AlphaCutoffEnable";
protected MaterialProperty alphaCutoff = null;
protected const string kAlphaCutoff = "_AlphaCutoff";
protected MaterialEditor m_MaterialEditor;
public enum LayerUVBaseMapping
{
UV0,
UV1,
UV2,
UV3,
Planar,
}
public enum VertexColorMode
{
None,
Multiply,
Add
}
public enum UVBaseMapping
{
UV0,
Planar,
}
public enum HeightmapMode
{
Parallax,
Displacement,
}
public enum UVDetailMapping
{
UV0,
UV1,
UV2,
UV3
}
public enum EmissiveColorMode
{
UseEmissiveColor,
UseEmissiveMask,
}
private class StylesLayer
{
public readonly GUIContent[] layerLabels =
{
new GUIContent("Main layer"),
new GUIContent("Layer 1"),
new GUIContent("Layer 2"),
new GUIContent("Layer 3"),
};
public readonly GUIStyle[] layerLabelColors =
{
new GUIStyle(EditorStyles.label),
new GUIStyle(EditorStyles.label),
new GUIStyle(EditorStyles.label),
new GUIStyle(EditorStyles.label)
};
public readonly GUIContent layersText = new GUIContent("Inputs");
public readonly GUIContent emissiveText = new GUIContent("Emissive");
public readonly GUIContent layerMapMaskText = new GUIContent("Layer Mask", "Layer mask");
public readonly GUIContent vertexColorModeText = new GUIContent("Vertex Color Mode", "Mode multiply: vertex color is multiply with the mask. Mode additive: vertex color values are remapped between -1 and 1 and added to the mask (neutral at 0.5 vertex color).");
public readonly GUIContent layerCountText = new GUIContent("Layer Count", "Number of layers.");
public readonly GUIContent layerTilingBlendMaskText = new GUIContent("Tiling", "Tiling for the blend mask.");
public readonly GUIContent objectScaleAffectTileText = new GUIContent("Tiling 0123 follow object Scale", "Tiling will be affected by the object scale.");
public readonly GUIContent objectScaleAffectTileText2 = new GUIContent("Tiling 123 follow object Scale", "Tiling will be affected by the object scale.");
public readonly GUIContent layerBaseColor = new GUIContent("Base Color");
public readonly GUIContent layerMetallic = new GUIContent("Metallic");
public readonly GUIContent layerMask = new GUIContent("Mask Map - M(R), AO(G), S(A)", "Mask map");
public readonly GUIContent layerSmoothness = new GUIContent("Smoothness");
public readonly GUIContent layerNormalMap = new GUIContent("Normal Map");
public readonly GUIContent layerHeightMapText = new GUIContent("Height Map (R)", "Height Map");
public readonly GUIContent layerHeightMapAmplitudeText = new GUIContent("Height Map Amplitude", "Height Map amplitude in world units.");
public readonly GUIContent layerHeightMapCenterText = new GUIContent("Height Map Center", "Center of the heightmap in the texture (between 0 and 1)");
public readonly GUIContent layerTilingText = new GUIContent("Tiling", "Tiling factor applied to UVSet.");
public readonly GUIContent layerTexWorldScaleText = new GUIContent("World Scale", "Tiling factor applied to Planar/Trilinear mapping");
public readonly GUIContent UVBaseText = new GUIContent("Base UV Mapping", "Base UV Mapping mode of the layer.");
public readonly GUIContent UVBlendMaskText = new GUIContent("BlendMask UV Mapping", "Base UV Mapping mode of the layer.");
public readonly GUIContent UVDetailText = new GUIContent("Detail UV Mapping", "Detail UV Mapping mode of the layer.");
public readonly GUIContent mainLayerInfluenceText = new GUIContent("Main layer influence", "Main layer influence.");
public readonly GUIContent densityOpacityInfluenceText = new GUIContent("Density / Opacity", "Density / Opacity");
public readonly GUIContent useHeightBasedBlendText = new GUIContent("Use Height Based Blend", "Layer will be blended with the underlying layer based on the height.");
public readonly GUIContent useDensityModeModeText = new GUIContent("Use Density Mode", "Enable density mode");
public readonly GUIContent useMainLayerInfluenceModeText = new GUIContent("Main Layer Influence", "Switch between regular layers mode and base/layers mode");
public readonly GUIContent heightControlText = new GUIContent("Height control");
public readonly GUIContent layerDetailMapNormalText = new GUIContent("Detail Map A(R) Ny(G) S(B) Nx(A)", "Detail Map");
public readonly GUIContent layerDetailMaskText = new GUIContent("Detail Mask (G)", "Mask for detailMap");
public readonly GUIContent layerDetailAlbedoScaleText = new GUIContent("Detail AlbedoScale", "Detail Albedo Scale factor");
public readonly GUIContent layerDetailNormalScaleText = new GUIContent("Detail NormalScale", "Normal Scale factor");
public readonly GUIContent layerDetailSmoothnessScaleText = new GUIContent("Detail SmoothnessScale", "Smoothness Scale factor");
public readonly GUIContent blendUsingHeight = new GUIContent("Blend Using Height", "Blend Layers using height.");
public readonly GUIContent inheritBaseColorThresholdText = new GUIContent("Threshold", "Inherit the base color from the base layer.");
public readonly GUIContent minimumOpacityText = new GUIContent("Minimum Opacity", "Minimum Opacity.");
public readonly GUIContent opacityAsDensityText = new GUIContent("Use Opacity as Density", "Use Opacity as Density.");
public readonly GUIContent inheritBaseNormalText = new GUIContent("Normal influence", "Inherit the normal from the base layer.");
public readonly GUIContent inheritBaseHeightText = new GUIContent("Heightmap influence", "Inherit the height from the base layer.");
public readonly GUIContent inheritBaseColorText = new GUIContent("BaseColor influence", "Inherit the base color from the base layer.");
public static GUIContent alphaCutoffEnableText = new GUIContent("Alpha Cutoff Enable", "Threshold for alpha cutoff");
public static GUIContent alphaCutoffText = new GUIContent("Alpha Cutoff", "Threshold for alpha cutoff");
public static string advancedText = "Advanced Options";
public StylesLayer()
{
layerLabelColors[0].normal.textColor = Color.white;
layerLabelColors[1].normal.textColor = Color.red;
layerLabelColors[2].normal.textColor = Color.green;
layerLabelColors[3].normal.textColor = Color.blue;
}
}
static StylesLayer s_Styles = null;
private static StylesLayer styles { get { if (s_Styles == null) s_Styles = new StylesLayer(); return s_Styles; } }
// Needed for json serialization to work
[Serializable]
internal struct SerializeableGUIDs
{
public string[] GUIDArray;
}
const int kMaxLayerCount = 4;
// Layer options
MaterialProperty layerCount = null;
const string kLayerCount = "_LayerCount";
MaterialProperty layerMaskMap = null;
const string kLayerMaskMap = "_LayerMaskMap";
MaterialProperty vertexColorMode = null;
const string kVertexColorMode = "_VertexColorMode";
MaterialProperty objectScaleAffectTile = null;
const string kObjectScaleAffectTile = "_ObjectScaleAffectTile";
MaterialProperty UVBlendMask = null;
const string kUVBlendMask = "_UVBlendMask";
MaterialProperty layerTilingBlendMask = null;
const string kLayerTilingBlendMask = "_LayerTilingBlendMask";
MaterialProperty texWorldScaleBlendMask = null;
const string kTexWorldScaleBlendMask = "_TexWorldScaleBlendMask";
MaterialProperty useMainLayerInfluence = null;
const string kkUseMainLayerInfluence = "_UseMainLayerInfluence";
MaterialProperty useHeightBasedBlend = null;
const string kUseHeightBasedBlend = "_UseHeightBasedBlend";
// Lit properties
MaterialProperty[] layerBaseColor = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerBaseColorMap = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerSmoothness = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerMetallic = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerNormalMap = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerNormalScale = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerMask = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerHeightMap = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerHeightAmplitude = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerHeightCenter = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerDetailMask = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerDetailMap = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerDetailAlbedoScale = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerDetailNormalScale = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerDetailSmoothnessScale = new MaterialProperty[kMaxLayerCount];
// Properties for multiple layers inherit from referenced lit materials
MaterialProperty[] layerTexWorldScale = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerUVBase = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerUVMappingMask = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerUVDetail = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerUVDetailsMappingMask = new MaterialProperty[kMaxLayerCount];
// This one is specific to layer lit
MaterialProperty[] layerTiling = new MaterialProperty[kMaxLayerCount];
const string kLayerTiling = "_LayerTiling";
// Density/opacity mode
MaterialProperty useDensityMode = null;
const string kUseDensityMode = "_UseDensityMode";
MaterialProperty[] opacityAsDensity = new MaterialProperty[kMaxLayerCount];
const string kOpacityAsDensity = "_OpacityAsDensity";
MaterialProperty[] minimumOpacity = new MaterialProperty[kMaxLayerCount];
const string kMinimumOpacity = "_MinimumOpacity";
// HeightmapMode control
MaterialProperty[] blendUsingHeight = new MaterialProperty[kMaxLayerCount - 1]; // Only in case of influence mode
const string kBlendUsingHeight = "_BlendUsingHeight";
// Influence
MaterialProperty[] inheritBaseNormal = new MaterialProperty[kMaxLayerCount - 1];
const string kInheritBaseNormal = "_InheritBaseNormal";
MaterialProperty[] inheritBaseHeight = new MaterialProperty[kMaxLayerCount - 1];
const string kInheritBaseHeight = "_InheritBaseHeight";
MaterialProperty[] inheritBaseColor = new MaterialProperty[kMaxLayerCount - 1];
const string kInheritBaseColor = "_InheritBaseColor";
MaterialProperty[] inheritBaseColorThreshold = new MaterialProperty[kMaxLayerCount - 1];
const string kInheritBaseColorThreshold = "_InheritBaseColorThreshold";
protected void FindMaterialProperties(MaterialProperty[] props)
{
// Inherit from LitUI
layerCount = FindProperty(kLayerCount, props);
layerMaskMap = FindProperty(kLayerMaskMap, props);
vertexColorMode = FindProperty(kVertexColorMode, props);
objectScaleAffectTile = FindProperty(kObjectScaleAffectTile, props);
UVBlendMask = FindProperty(kUVBlendMask, props);
layerTilingBlendMask = FindProperty(kLayerTilingBlendMask, props);
texWorldScaleBlendMask = FindProperty(kTexWorldScaleBlendMask, props);
useMainLayerInfluence = FindProperty(kkUseMainLayerInfluence, props);
useHeightBasedBlend = FindProperty(kUseHeightBasedBlend, props);
useDensityMode = FindProperty(kUseDensityMode, props);
for (int i = 0; i < kMaxLayerCount; ++i)
{
layerBaseColor[i] = FindProperty(string.Format("{0}{1}", kBaseColor, i), props);
layerBaseColorMap[i] = FindProperty(string.Format("{0}{1}", kBaseColorMap, i), props);
layerSmoothness[i] = FindProperty(string.Format("{0}{1}", kSmoothness, i), props);
layerMetallic[i] = FindProperty(string.Format("{0}{1}", kMetallic, i), props);
layerNormalMap[i] = FindProperty(string.Format("{0}{1}", kNormalMap, i), props);
layerNormalScale[i] = FindProperty(string.Format("{0}{1}", kNormalScale, i), props);
layerMask[i] = FindProperty(string.Format("{0}{1}", kMaskMap, i), props);
layerHeightMap[i] = FindProperty(string.Format("{0}{1}", kHeightMap, i), props);
layerTexWorldScale[i] = FindProperty(string.Format("{0}{1}", kTexWorldScale, i), props);
layerUVBase[i] = FindProperty(string.Format("{0}{1}", kUVBase, i), props);
layerUVMappingMask[i] = FindProperty(string.Format("{0}{1}", kUVMappingMask, i), props);
layerUVDetail[i] = FindProperty(string.Format("{0}{1}", kUVDetail, i), props);
layerUVDetailsMappingMask[i] = FindProperty(string.Format("{0}{1}", kUVDetailsMappingMask, i), props);
layerTiling[i] = FindProperty(string.Format("{0}{1}", kLayerTiling, i), props);
layerDetailMap[i] = FindProperty(string.Format("{0}{1}", kDetailMap, i), props);
layerDetailMask[i] = FindProperty(string.Format("{0}{1}", kDetailMask, i), props);
layerDetailAlbedoScale[i] = FindProperty(string.Format("{0}{1}", kDetailAlbedoScale, i), props);
layerDetailNormalScale[i] = FindProperty(string.Format("{0}{1}", kDetailNormalScale, i), props);
layerDetailSmoothnessScale[i] = FindProperty(string.Format("{0}{1}", kDetailSmoothnessScale, i), props);
// Density/opacity mode
opacityAsDensity[i] = FindProperty(string.Format("{0}{1}", kOpacityAsDensity, i), props);
minimumOpacity[i] = FindProperty(string.Format("{0}{1}", kMinimumOpacity, i), props);
layerHeightAmplitude[i] = FindProperty(string.Format("{0}{1}", kHeightAmplitude, i), props);
layerHeightCenter[i] = FindProperty(string.Format("{0}{1}", kHeightCenter, i), props);
if (i != 0)
{
blendUsingHeight[i - 1] = FindProperty(string.Format("{0}{1}", kBlendUsingHeight, i), props);
// Influence
inheritBaseNormal[i - 1] = FindProperty(string.Format("{0}{1}", kInheritBaseNormal, i), props);
inheritBaseHeight[i - 1] = FindProperty(string.Format("{0}{1}", kInheritBaseHeight, i), props);
inheritBaseColor[i - 1] = FindProperty(string.Format("{0}{1}", kInheritBaseColor, i), props);
inheritBaseColorThreshold[i - 1] = FindProperty(string.Format("{0}{1}", kInheritBaseColorThreshold, i), props);
}
}
// Reuse property from LitUI.cs
//emissiveColor = FindProperty(kEmissiveColor, props);
//emissiveColorMap = FindProperty(kEmissiveColorMap, props);
//emissiveIntensity = FindProperty(kEmissiveIntensity, props);
}
int numLayer
{
set { layerCount.floatValue = (float)value; }
get { return (int)layerCount.floatValue; }
}
bool DoLayerGUI(AssetImporter materialImporter, int layerIndex)
{
bool result = false;
Material material = m_MaterialEditor.target as Material;
bool mainLayerInfluenceEnable = useMainLayerInfluence.floatValue > 0.0f;
EditorGUILayout.LabelField(styles.layerLabels[layerIndex], styles.layerLabelColors[layerIndex]);
m_MaterialEditor.TexturePropertySingleLine(styles.layerBaseColor, layerBaseColorMap[layerIndex], layerBaseColor[layerIndex]);
m_MaterialEditor.ShaderProperty(layerMetallic[layerIndex], styles.layerMetallic);
m_MaterialEditor.ShaderProperty(layerSmoothness[layerIndex], styles.layerSmoothness);
m_MaterialEditor.TexturePropertySingleLine(styles.layerMask, layerMask[layerIndex]);
m_MaterialEditor.TexturePropertySingleLine(styles.layerNormalMap, layerNormalMap[layerIndex], layerNormalScale[layerIndex]);
m_MaterialEditor.TexturePropertySingleLine(styles.layerHeightMapText, layerHeightMap[layerIndex]);
if (!layerHeightMap[layerIndex].hasMixedValue && layerHeightMap[layerIndex].textureValue != null)
{
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(layerHeightAmplitude[layerIndex], styles.layerHeightMapAmplitudeText);
m_MaterialEditor.ShaderProperty(layerHeightCenter[layerIndex], styles.layerHeightMapCenterText);
EditorGUI.showMixedValue = false;
EditorGUI.indentLevel--;
}
EditorGUI.BeginChangeCheck();
m_MaterialEditor.ShaderProperty(layerUVBase[layerIndex], styles.UVBaseText);
if (EditorGUI.EndChangeCheck())
{
result = true;
}
if (((LayerUVBaseMapping)layerUVBase[layerIndex].floatValue == LayerUVBaseMapping.Planar))
{
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(layerTexWorldScale[layerIndex], styles.layerTexWorldScaleText);
EditorGUI.indentLevel--;
}
else
{
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(layerTiling[layerIndex], styles.layerTilingText);
EditorGUI.indentLevel--;
}
m_MaterialEditor.TextureScaleOffsetProperty(layerBaseColorMap[layerIndex]);
m_MaterialEditor.TexturePropertySingleLine(styles.layerDetailMaskText, layerDetailMask[layerIndex]);
m_MaterialEditor.TexturePropertySingleLine(styles.layerDetailMapNormalText, layerDetailMap[layerIndex]);
if (((LayerUVBaseMapping)layerUVBase[layerIndex].floatValue == LayerUVBaseMapping.Planar))
{
GUILayout.Label(" " + styles.UVDetailText.text + ": Planar");
}
else
{
EditorGUI.BeginChangeCheck();
m_MaterialEditor.ShaderProperty(layerUVDetail[layerIndex], styles.UVDetailText);
if (EditorGUI.EndChangeCheck())
{
result = true;
}
}
m_MaterialEditor.TextureScaleOffsetProperty(layerDetailMap[layerIndex]);
m_MaterialEditor.ShaderProperty(layerDetailAlbedoScale[layerIndex], styles.layerDetailAlbedoScaleText);
m_MaterialEditor.ShaderProperty(layerDetailNormalScale[layerIndex], styles.layerDetailNormalScaleText);
m_MaterialEditor.ShaderProperty(layerDetailSmoothnessScale[layerIndex], styles.layerDetailSmoothnessScaleText);
// We setup the masking map based on the enum for each layer.
// using mapping mask allow to reduce the number of generated combination for a very small increase in ALU
LayerUVBaseMapping layerUVBaseMapping = (LayerUVBaseMapping)layerUVBase[layerIndex].floatValue;
float X, Y, Z, W;
X = (layerUVBaseMapping == LayerUVBaseMapping.UV0) ? 1.0f : 0.0f;
Y = (layerUVBaseMapping == LayerUVBaseMapping.UV1) ? 1.0f : 0.0f;
Z = (layerUVBaseMapping == LayerUVBaseMapping.UV2) ? 1.0f : 0.0f;
W = (layerUVBaseMapping == LayerUVBaseMapping.UV3) ? 1.0f : 0.0f;
layerUVMappingMask[layerIndex].colorValue = (layerIndex == 0) ? new Color(1.0f, 0.0f, 0.0f, 0.0f) : new Color(X, Y, Z, W); // Special case for Main Layer and Blend Mask, only UV0. As Layer0 is share by both here, need to force X to 1.0 in all case
UVDetailMapping layerUVDetailMapping = (UVDetailMapping)layerUVDetail[layerIndex].floatValue;
X = (layerUVDetailMapping == UVDetailMapping.UV0) ? 1.0f : 0.0f;
Y = (layerUVDetailMapping == UVDetailMapping.UV1) ? 1.0f : 0.0f;
Z = (layerUVDetailMapping == UVDetailMapping.UV2) ? 1.0f : 0.0f;
W = (layerUVDetailMapping == UVDetailMapping.UV3) ? 1.0f : 0.0f;
layerUVDetailsMappingMask[layerIndex].colorValue = new Color(X, Y, Z, W);
bool useDensityModeEnable = useDensityMode.floatValue != 0.0f;
if (useDensityModeEnable)
{
EditorGUILayout.LabelField(styles.densityOpacityInfluenceText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(opacityAsDensity[layerIndex], styles.opacityAsDensityText);
m_MaterialEditor.ShaderProperty(minimumOpacity[layerIndex], styles.minimumOpacityText);
EditorGUI.indentLevel--;
}
// Display height control if they have a meaning
//if ((tessellationMode != null && ((TessellationMode)tessellationMode.floatValue == TessellationMode.Displacement || (TessellationMode)tessellationMode.floatValue == TessellationMode.DisplacementPhong))
// || (enablePerPixelDisplacement.floatValue > 0.0f)
// || (useHeightBasedBlend.floatValue > 0.0f)
// )
//if (useHeightBasedBlend.floatValue > 0.0f)
//{
// EditorGUILayout.LabelField(styles.heightControlText, EditorStyles.boldLabel);
// EditorGUI.indentLevel++;
// m_MaterialEditor.ShaderProperty(heightFactor[layerIndex], styles.heightFactorText);
// layerHeightAmplitude[layerIndex].floatValue = material.GetFloat(kHeightAmplitude + layerIndex) * heightFactor[layerIndex].floatValue;
// m_MaterialEditor.ShaderProperty(heightCenterOffset[layerIndex], styles.heightCenterOffsetText);
// layerCenterOffset[layerIndex].floatValue = material.GetFloat(kHeightCenter + layerIndex) + heightCenterOffset[layerIndex].floatValue;
// EditorGUI.indentLevel--;
//}
// influence
if (layerIndex > 0)
{
int paramIndex = layerIndex - 1;
bool heightBasedBlendEnable = useHeightBasedBlend.floatValue > 0.0f;
if (heightBasedBlendEnable)
{
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(blendUsingHeight[paramIndex], styles.blendUsingHeight);
EditorGUI.indentLevel--;
}
if (mainLayerInfluenceEnable)
{
EditorGUILayout.LabelField(styles.mainLayerInfluenceText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(inheritBaseColor[paramIndex], styles.inheritBaseColorText);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(inheritBaseColorThreshold[paramIndex], styles.inheritBaseColorThresholdText);
EditorGUI.indentLevel--;
m_MaterialEditor.ShaderProperty(inheritBaseNormal[paramIndex], styles.inheritBaseNormalText);
// Main height influence is only available if the shader use the heightmap for displacement (per vertex or per level)
// We always display it as it can be tricky to know when per pixel displacement is enabled or not
m_MaterialEditor.ShaderProperty(inheritBaseHeight[paramIndex], styles.inheritBaseHeightText);
EditorGUI.indentLevel--;
}
}
if (layerIndex == 0)
EditorGUILayout.Space();
return result;
}
bool DoLayersGUI(AssetImporter materialImporter)
{
Material material = m_MaterialEditor.target as Material;
bool layerChanged = false;
GUI.changed = false;
GUILayout.Label(styles.layersText, EditorStyles.boldLabel);
EditorGUI.showMixedValue = layerCount.hasMixedValue;
EditorGUI.BeginChangeCheck();
int newLayerCount = EditorGUILayout.IntSlider(styles.layerCountText, (int)layerCount.floatValue, 2, 4);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(material, "Change layer count");
layerCount.floatValue = (float)newLayerCount;
layerChanged = true;
}
m_MaterialEditor.TexturePropertySingleLine(styles.layerMapMaskText, layerMaskMap);
m_MaterialEditor.ShaderProperty(UVBlendMask, styles.UVBlendMaskText);
if (((LayerUVBaseMapping)UVBlendMask.floatValue == LayerUVBaseMapping.Planar))
{
m_MaterialEditor.ShaderProperty(texWorldScaleBlendMask, styles.layerTexWorldScaleText);
}
else
{
m_MaterialEditor.ShaderProperty(layerTilingBlendMask, styles.layerTilingBlendMaskText);
}
m_MaterialEditor.ShaderProperty(vertexColorMode, styles.vertexColorModeText);
EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = useMainLayerInfluence.hasMixedValue;
bool mainLayerModeInfluenceEnable = EditorGUILayout.Toggle(styles.useMainLayerInfluenceModeText, useMainLayerInfluence.floatValue > 0.0f);
if (EditorGUI.EndChangeCheck())
{
useMainLayerInfluence.floatValue = mainLayerModeInfluenceEnable ? 1.0f : 0.0f;
}
EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = useDensityMode.hasMixedValue;
bool useDensityModeEnable = EditorGUILayout.Toggle(styles.useDensityModeModeText, useDensityMode.floatValue > 0.0f);
if (EditorGUI.EndChangeCheck())
{
useDensityMode.floatValue = useDensityModeEnable ? 1.0f : 0.0f;
}
EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = useHeightBasedBlend.hasMixedValue;
bool enabled = EditorGUILayout.Toggle(styles.useHeightBasedBlendText, useHeightBasedBlend.floatValue > 0.0f);
if (EditorGUI.EndChangeCheck())
{
useHeightBasedBlend.floatValue = enabled ? 1.0f : 0.0f;
}
m_MaterialEditor.ShaderProperty(objectScaleAffectTile, mainLayerModeInfluenceEnable ? styles.objectScaleAffectTileText2 : styles.objectScaleAffectTileText);
EditorGUILayout.Space();
for (int i = 0; i < numLayer; i++)
{
layerChanged |= DoLayerGUI(materialImporter, i);
}
layerChanged |= GUI.changed;
GUI.changed = false;
return layerChanged;
}
protected void SetupMaterialKeywordsAndPassInternal(Material material)
{
SetupMaterialKeywordsAndPass(material);
}
static public void SetKeyword(Material m, string keyword, bool state)
{
if (state)
m.EnableKeyword(keyword);
else
m.DisableKeyword(keyword);
}
static public void SetupLayersMappingKeywords(Material material)
{
// object scale affect tile
SetKeyword(material, "_LAYER_TILING_COUPLED_WITH_UNIFORM_OBJECT_SCALE", material.GetFloat(kObjectScaleAffectTile) > 0.0f);
// Blend mask
LayerUVBaseMapping UVBlendMaskMapping = (LayerUVBaseMapping)material.GetFloat(kUVBlendMask);
SetKeyword(material, "_LAYER_MAPPING_PLANAR_BLENDMASK", UVBlendMaskMapping == LayerUVBaseMapping.Planar);
int numLayer = (int)material.GetFloat(kLayerCount);
// Layer
if (numLayer == 4)
{
SetKeyword(material, "_LAYEREDLIT_4_LAYERS", true);
SetKeyword(material, "_LAYEREDLIT_3_LAYERS", false);
}
else if (numLayer == 3)
{
SetKeyword(material, "_LAYEREDLIT_4_LAYERS", false);
SetKeyword(material, "_LAYEREDLIT_3_LAYERS", true);
}
else
{
SetKeyword(material, "_LAYEREDLIT_4_LAYERS", false);
SetKeyword(material, "_LAYEREDLIT_3_LAYERS", false);
}
const string kLayerMappingPlanar = "_LAYER_MAPPING_PLANAR";
// We have to check for each layer if the UV2 or UV3 is needed.
bool needUV3 = false;
bool needUV2 = false;
for (int i = 0; i < numLayer; ++i)
{
string layerUVBaseParam = string.Format("{0}{1}", kUVBase, i);
LayerUVBaseMapping layerUVBaseMapping = (LayerUVBaseMapping)material.GetFloat(layerUVBaseParam);
string currentLayerMappingPlanar = string.Format("{0}{1}", kLayerMappingPlanar, i);
SetKeyword(material, currentLayerMappingPlanar, layerUVBaseMapping == LayerUVBaseMapping.Planar);
string uvBase = string.Format("{0}{1}", kUVBase, i);
string uvDetail = string.Format("{0}{1}", kUVDetail, i);
if (((UVDetailMapping)material.GetFloat(uvDetail) == UVDetailMapping.UV2) ||
((LayerUVBaseMapping)material.GetFloat(uvBase) == LayerUVBaseMapping.UV2))
{
needUV2 = true;
}
if (((UVDetailMapping)material.GetFloat(uvDetail) == UVDetailMapping.UV3) ||
((LayerUVBaseMapping)material.GetFloat(uvBase) == LayerUVBaseMapping.UV3))
{
needUV3 = true;
break; // If we find it UV3 let's early out
}
}
if (needUV3)
{
material.DisableKeyword("_REQUIRE_UV2");
material.EnableKeyword("_REQUIRE_UV3");
}
else if (needUV2)
{
material.EnableKeyword("_REQUIRE_UV2");
material.DisableKeyword("_REQUIRE_UV3");
}
else
{
material.DisableKeyword("_REQUIRE_UV2");
material.DisableKeyword("_REQUIRE_UV3");
}
}
static public void SetupBaseUnlitKeywords(Material material)
{
bool alphaTestEnable = material.GetFloat(kAlphaCutoffEnabled) > 0.0f;
material.SetOverrideTag("RenderType", alphaTestEnable ? "TransparentCutout" : "");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
material.renderQueue = alphaTestEnable ? (int)UnityEngine.Rendering.RenderQueue.AlphaTest : -1;
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Back);
SetKeyword(material, "_ALPHATEST_ON", alphaTestEnable);
}
// All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if code change
static public void SetupMaterialKeywordsAndPass(Material material)
{
SetupBaseUnlitKeywords(material);
SetupLayersMappingKeywords(material);
for (int i = 0; i < kMaxLayerCount; ++i)
{
SetKeyword(material, "_NORMALMAP" + i, material.GetTexture(kNormalMap + i) || material.GetTexture(kDetailMap + i));
SetKeyword(material, "_MASKMAP" + i, material.GetTexture(kMaskMap + i));
SetKeyword(material, "_DETAIL_MAP" + i, material.GetTexture(kDetailMap + i));
SetKeyword(material, "_HEIGHTMAP" + i, material.GetTexture(kHeightMap + i));
}
SetKeyword(material, "_MAIN_LAYER_INFLUENCE_MODE", material.GetFloat(kkUseMainLayerInfluence) != 0.0f);
VertexColorMode VCMode = (VertexColorMode)material.GetFloat(kVertexColorMode);
if (VCMode == VertexColorMode.Multiply)
{
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", true);
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
}
else if (VCMode == VertexColorMode.Add)
{
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", true);
}
else
{
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
}
bool useHeightBasedBlend = material.GetFloat(kUseHeightBasedBlend) != 0.0f;
SetKeyword(material, "_HEIGHT_BASED_BLEND", useHeightBasedBlend);
bool useDensityModeEnable = material.GetFloat(kUseDensityMode) != 0.0f;
SetKeyword(material, "_DENSITY_MODE", useDensityModeEnable);
}
protected void FindBaseMaterialProperties(MaterialProperty[] props)
{
alphaCutoffEnable = FindProperty(kAlphaCutoffEnabled, props);
alphaCutoff = FindProperty(kAlphaCutoff, props);
}
protected void BaseMaterialPropertiesGUI()
{
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(alphaCutoffEnable, StylesLayer.alphaCutoffEnableText);
if (alphaCutoffEnable.floatValue == 1.0f)
{
m_MaterialEditor.ShaderProperty(alphaCutoff, StylesLayer.alphaCutoffText);
}
}
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
{
FindBaseMaterialProperties(props);
FindMaterialProperties(props);
m_MaterialEditor = materialEditor;
// We should always do this call at the beginning
m_MaterialEditor.serializedObject.Update();
Material material = m_MaterialEditor.target as Material;
AssetImporter materialImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(material.GetInstanceID()));
bool optionsChanged = false;
EditorGUI.BeginChangeCheck();
{
BaseMaterialPropertiesGUI();
EditorGUILayout.Space();
}
if (EditorGUI.EndChangeCheck())
{
optionsChanged = true;
}
bool layerChanged = DoLayersGUI(materialImporter);
EditorGUI.indentLevel--;
m_MaterialEditor.EnableInstancingField();
if (layerChanged || optionsChanged)
{
foreach (var obj in m_MaterialEditor.targets)
{
SetupMaterialKeywordsAndPassInternal((Material)obj);
}
}
// We should always do this call at the end
m_MaterialEditor.serializedObject.ApplyModifiedProperties();
}
}
//} // namespace UnityEditor

12
Assets/LegacyLayered/Editor/LayeredPhotogrammetryUI.cs.meta


fileFormatVersion: 2
guid: a3bb4d5be7ed5bc4fa8e72c75b21ef1b
timeCreated: 1497279201
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

603
Assets/LegacyLayered/LayeredPhotogrammetry.shader


Shader "LayeredPhotogrammetry"
{
Properties
{
_BaseColor0("BaseColor0", Color) = (1, 1, 1, 1)
_BaseColor1("BaseColor1", Color) = (1, 1, 1, 1)
_BaseColor2("BaseColor2", Color) = (1, 1, 1, 1)
_BaseColor3("BaseColor3", Color) = (1, 1, 1, 1)
_BaseColorMap0("BaseColorMap0", 2D) = "white" {}
_BaseColorMap1("BaseColorMap1", 2D) = "white" {}
_BaseColorMap2("BaseColorMap2", 2D) = "white" {}
_BaseColorMap3("BaseColorMap3", 2D) = "white" {}
_Metallic0("Metallic0", Range(0.0, 1.0)) = 0
_Metallic1("Metallic1", Range(0.0, 1.0)) = 0
_Metallic2("Metallic2", Range(0.0, 1.0)) = 0
_Metallic3("Metallic3", Range(0.0, 1.0)) = 0
_Smoothness0("Smoothness0", Range(0.0, 1.0)) = 1.0
_Smoothness1("Smoothness1", Range(0.0, 1.0)) = 1.0
_Smoothness2("Smoothness2", Range(0.0, 1.0)) = 1.0
_Smoothness3("Smoothness3", Range(0.0, 1.0)) = 1.0
_MaskMap0("MaskMap0", 2D) = "white" {}
_MaskMap1("MaskMap1", 2D) = "white" {}
_MaskMap2("MaskMap2", 2D) = "white" {}
_MaskMap3("MaskMap3", 2D) = "white" {}
_NormalMap0("NormalMap0", 2D) = "bump" {}
_NormalMap1("NormalMap1", 2D) = "bump" {}
_NormalMap2("NormalMap2", 2D) = "bump" {}
_NormalMap3("NormalMap3", 2D) = "bump" {}
_NormalScale0("_NormalScale0", Range(0.0, 2.0)) = 1
_NormalScale1("_NormalScale1", Range(0.0, 2.0)) = 1
_NormalScale2("_NormalScale2", Range(0.0, 2.0)) = 1
_NormalScale3("_NormalScale3", Range(0.0, 2.0)) = 1
_HeightMap0("HeightMap0", 2D) = "black" {}
_HeightMap1("HeightMap1", 2D) = "black" {}
_HeightMap2("HeightMap2", 2D) = "black" {}
_HeightMap3("HeightMap3", 2D) = "black" {}
_DetailMap0("DetailMap0", 2D) = "black" {}
_DetailMap1("DetailMap1", 2D) = "black" {}
_DetailMap2("DetailMap2", 2D) = "black" {}
_DetailMap3("DetailMap3", 2D) = "black" {}
_DetailMask0("DetailMask0", 2D) = "white" {}
_DetailMask1("DetailMask1", 2D) = "white" {}
_DetailMask2("DetailMask2", 2D) = "white" {}
_DetailMask3("DetailMask3", 2D) = "white" {}
_DetailAlbedoScale0("_DetailAlbedoScale0", Range(-2.0, 2.0)) = 1
_DetailAlbedoScale1("_DetailAlbedoScale1", Range(-2.0, 2.0)) = 1
_DetailAlbedoScale2("_DetailAlbedoScale2", Range(-2.0, 2.0)) = 1
_DetailAlbedoScale3("_DetailAlbedoScale3", Range(-2.0, 2.0)) = 1
_DetailNormalScale0("_DetailNormalScale0", Range(0.0, 2.0)) = 1
_DetailNormalScale1("_DetailNormalScale1", Range(0.0, 2.0)) = 1
_DetailNormalScale2("_DetailNormalScale2", Range(0.0, 2.0)) = 1
_DetailNormalScale3("_DetailNormalScale3", Range(0.0, 2.0)) = 1
_DetailSmoothnessScale0("_DetailSmoothnessScale0", Range(-2.0, 2.0)) = 1
_DetailSmoothnessScale1("_DetailSmoothnessScale1", Range(-2.0, 2.0)) = 1
_DetailSmoothnessScale2("_DetailSmoothnessScale2", Range(-2.0, 2.0)) = 1
_DetailSmoothnessScale3("_DetailSmoothnessScale3", Range(-2.0, 2.0)) = 1
// Layer blending options
_LayerMaskMap("LayerMaskMap", 2D) = "white" {}
[ToggleOff] _UseHeightBasedBlend("UseHeightBasedBlend", Float) = 0.0
[ToggleOff] _UseHeightBasedBlend("UseHeightBasedBlend", Float) = 0.0
// Layer blending options V2
[ToggleOff] _UseDensityMode("Use Density mode", Float) = 0.0
[ToggleOff] _UseMainLayerInfluence("UseMainLayerInfluence", Float) = 0.0
// Store result of combination of _HeightFactor and _HeightAmplitude0
_LayerHeightAmplitude0("_LayerHeightAmplitude0", Float) = 1
_LayerHeightAmplitude1("_LayerHeightAmplitude1", Float) = 1
_LayerHeightAmplitude2("_LayerHeightAmplitude2", Float) = 1
_LayerHeightAmplitude3("_LayerHeightAmplitude3", Float) = 1
// Store result of combination of _HeightCenterOffset0 and _HeightCenter0
_LayerHeightCenter0("_LayerOffset0", Float) = 0.0
_LayerHeightCenter1("_LayerOffset1", Float) = 0.0
_LayerHeightCenter2("_LayerOffset2", Float) = 0.0
_LayerHeightCenter3("_LayerOffset3", Float) = 0.0
_BlendUsingHeight1("_BlendUsingHeight1", Float) = 0.0
_BlendUsingHeight2("_BlendUsingHeight2", Float) = 0.0
_BlendUsingHeight3("_BlendUsingHeight3", Float) = 0.0
_InheritBaseNormal1("_InheritBaseNormal1", Range(0, 1.0)) = 0.0
_InheritBaseNormal2("_InheritBaseNormal2", Range(0, 1.0)) = 0.0
_InheritBaseNormal3("_InheritBaseNormal3", Range(0, 1.0)) = 0.0
_InheritBaseHeight1("_InheritBaseHeight1", Range(0, 1.0)) = 0.0
_InheritBaseHeight2("_InheritBaseHeight2", Range(0, 1.0)) = 0.0
_InheritBaseHeight3("_InheritBaseHeight3", Range(0, 1.0)) = 0.0
_InheritBaseColor1("_InheritBaseColor1", Range(0, 1.0)) = 0.0
_InheritBaseColor2("_InheritBaseColor2", Range(0, 1.0)) = 0.0
_InheritBaseColor3("_InheritBaseColor3", Range(0, 1.0)) = 0.0
_InheritBaseColorThreshold1("_InheritBaseColorThreshold1", Range(0, 1.0)) = 1.0
_InheritBaseColorThreshold2("_InheritBaseColorThreshold2", Range(0, 1.0)) = 1.0
_InheritBaseColorThreshold3("_InheritBaseColorThreshold3", Range(0, 1.0)) = 1.0
_MinimumOpacity0("_MinimumOpacity0", Range(0, 1.0)) = 1.0
_MinimumOpacity1("_MinimumOpacity1", Range(0, 1.0)) = 1.0
_MinimumOpacity2("_MinimumOpacity2", Range(0, 1.0)) = 1.0
_MinimumOpacity3("_MinimumOpacity3", Range(0, 1.0)) = 1.0
_OpacityAsDensity0("_OpacityAsDensity0", Range(0, 1.0)) = 0.0
_OpacityAsDensity1("_OpacityAsDensity1", Range(0, 1.0)) = 0.0
_OpacityAsDensity2("_OpacityAsDensity2", Range(0, 1.0)) = 0.0
_OpacityAsDensity3("_OpacityAsDensity3", Range(0, 1.0)) = 0.0
_LayerTilingBlendMask("_LayerTilingBlendMask", Float) = 1
_LayerTiling0("_LayerTiling0", Float) = 1
_LayerTiling1("_LayerTiling1", Float) = 1
_LayerTiling2("_LayerTiling2", Float) = 1
_LayerTiling3("_LayerTiling3", Float) = 1
[HideInInspector] _LayerCount("_LayerCount", Float) = 2.0
[Enum(None, 0, Multiply, 1, Add, 2)] _VertexColorMode("Vertex color mode", Float) = 0
[ToggleOff] _ObjectScaleAffectTile("_ObjectScaleAffectTile", Float) = 0.0
[Enum(UV0, 0, Planar, 4)] _UVBlendMask("UV Set for blendMask", Float) = 0
_TexWorldScaleBlendMask("Tiling", Float) = 1.0
[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_TexWorldScale0("Tiling", Float) = 1.0
_TexWorldScale1("Tiling", Float) = 1.0
_TexWorldScale2("Tiling", Float) = 1.0
_TexWorldScale3("Tiling", Float) = 1.0
[Enum(UV0, 0, Planar, 4)] _UVBase0("UV Set for base0", Float) = 0 // no UV1/2/3 for main layer
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4)] _UVBase1("UV Set for base1", Float) = 0
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4)] _UVBase2("UV Set for base2", Float) = 0
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4)] _UVBase3("UV Set for base3", Float) = 0
[HideInInspector] _UVMappingMask0("_UVMappingMask0", Color) = (1, 0, 0, 0)
[HideInInspector] _UVMappingMask1("_UVMappingMask1", Color) = (1, 0, 0, 0)
[HideInInspector] _UVMappingMask2("_UVMappingMask2", Color) = (1, 0, 0, 0)
[HideInInspector] _UVMappingMask3("_UVMappingMask3", Color) = (1, 0, 0, 0)
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _UVDetail0("UV Set for detail0", Float) = 0
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _UVDetail1("UV Set for detail1", Float) = 0
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _UVDetail2("UV Set for detail2", Float) = 0
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _UVDetail3("UV Set for detail3", Float) = 0
[HideInInspector] _UVDetailsMappingMask0("_UVDetailsMappingMask0", Color) = (1, 0, 0, 0)
[HideInInspector] _UVDetailsMappingMask1("_UVDetailsMappingMask1", Color) = (1, 0, 0, 0)
[HideInInspector] _UVDetailsMappingMask2("_UVDetailsMappingMask2", Color) = (1, 0, 0, 0)
[HideInInspector] _UVDetailsMappingMask3("_UVDetailsMappingMask3", Color) = (1, 0, 0, 0)
}
CGINCLUDE
// Define feature
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _LAYER_TILING_COUPLED_WITH_UNIFORM_OBJECT_SCALE
#pragma shader_feature _ _LAYER_MAPPING_PLANAR_BLENDMASK
#pragma shader_feature _ _LAYER_MAPPING_PLANAR0
#pragma shader_feature _ _LAYER_MAPPING_PLANAR1
#pragma shader_feature _ _LAYER_MAPPING_PLANAR2
#pragma shader_feature _ _LAYER_MAPPING_PLANAR3
#pragma shader_feature _ _REQUIRE_UV2 _REQUIRE_UV3
#pragma shader_feature _NORMALMAP0
#pragma shader_feature _NORMALMAP1
#pragma shader_feature _NORMALMAP2
#pragma shader_feature _NORMALMAP3
#pragma shader_feature _MASKMAP0
#pragma shader_feature _MASKMAP1
#pragma shader_feature _MASKMAP2
#pragma shader_feature _MASKMAP3
#pragma shader_feature _HEIGHTMAP0
#pragma shader_feature _HEIGHTMAP1
#pragma shader_feature _HEIGHTMAP2
#pragma shader_feature _HEIGHTMAP3
#pragma shader_feature _DETAIL_MAP0
#pragma shader_feature _DETAIL_MAP1
#pragma shader_feature _DETAIL_MAP2
#pragma shader_feature _DETAIL_MAP3
#pragma shader_feature _ _LAYER_MASK_VERTEX_COLOR_MUL _LAYER_MASK_VERTEX_COLOR_ADD
#pragma shader_feature _MAIN_LAYER_INFLUENCE_MODE
#pragma shader_feature _DENSITY_MODE
#pragma shader_feature _HEIGHT_BASED_BLEND
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED
#pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
#define _MAX_LAYER 4
#if defined(_LAYEREDLIT_4_LAYERS)
# define _LAYER_COUNT 4
#elif defined(_LAYEREDLIT_3_LAYERS)
# define _LAYER_COUNT 3
#else
# define _LAYER_COUNT 2
#endif
#define MERGE_NAME(X, Y) X##Y
#define PROP_DECL(type, name) type name##0, name##1, name##2, name##3
// sampler are share by texture type inside a layered material but we need to support that a particualr layer have no texture, so we take the first sampler of available texture as the share one
// mean we must declare all sampler
#define PROP_DECL_TEX2D(name)\
UNITY_DECLARE_TEX2D(MERGE_NAME(name, 0)); \
UNITY_DECLARE_TEX2D(MERGE_NAME(name, 1)); \
UNITY_DECLARE_TEX2D(MERGE_NAME(name, 2)); \
UNITY_DECLARE_TEX2D(MERGE_NAME(name, 3))
float _AlphaCutoff;
// Set of users variables
PROP_DECL(float4, _BaseColor);
PROP_DECL_TEX2D(_BaseColorMap);
float4 _BaseColorMap0_ST;
float4 _BaseColorMap1_ST;
float4 _BaseColorMap2_ST;
float4 _BaseColorMap3_ST;
PROP_DECL(float, _Metallic);
PROP_DECL(float, _Smoothness);
PROP_DECL_TEX2D(_MaskMap);
PROP_DECL_TEX2D(_NormalMap);
PROP_DECL(float, _NormalScale);
float4 _NormalMap0_TexelSize; // Unity facility. This will provide the size of the base normal to the shader
PROP_DECL_TEX2D(_HeightMap);
float4 _HeightMap0_TexelSize;
float4 _HeightMap1_TexelSize;
float4 _HeightMap2_TexelSize;
float4 _HeightMap3_TexelSize;
PROP_DECL_TEX2D(_DetailMask);
PROP_DECL_TEX2D(_DetailMap);
float4 _DetailMap0_ST;
float4 _DetailMap1_ST;
float4 _DetailMap2_ST;
float4 _DetailMap3_ST;
PROP_DECL(float, _UVDetail);
PROP_DECL(float, _DetailAlbedoScale);
PROP_DECL(float, _DetailNormalScale);
PROP_DECL(float, _DetailSmoothnessScale);
PROP_DECL(float, _LayerHeightAmplitude);
PROP_DECL(float, _LayerHeightCenter);
PROP_DECL(float, _MinimumOpacity);
UNITY_DECLARE_TEX2D(_LayerMaskMap);
float _BlendUsingHeight1;
float _BlendUsingHeight2;
float _BlendUsingHeight3;
PROP_DECL(float, _OpacityAsDensity);
float _InheritBaseNormal1;
float _InheritBaseNormal2;
float _InheritBaseNormal3;
float _InheritBaseHeight1;
float _InheritBaseHeight2;
float _InheritBaseHeight3;
float _InheritBaseColor1;
float _InheritBaseColor2;
float _InheritBaseColor3;
float _InheritBaseColorThreshold1;
float _InheritBaseColorThreshold2;
float _InheritBaseColorThreshold3;
float _LayerTilingBlendMask;
PROP_DECL(float, _LayerTiling);
float _TexWorldScaleBlendMask;
PROP_DECL(float, _TexWorldScale);
PROP_DECL(float4, _UVMappingMask);
PROP_DECL(float4, _UVDetailsMappingMask);
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3) || defined(DYNAMICLIGHTMAP_ON)
#define ATTRIBUTES_NEED_TEXCOORD2
#endif
#if defined(_REQUIRE_UV3)
#define ATTRIBUTES_NEED_TEXCOORD3
#endif
ENDCG
SubShader
{
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
LOD 300
// ------------------------------------------------------------------
// Base forward pass (directional light, emission, lightmaps, ...)
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
Blend One Zero
ZWrite On
CGPROGRAM
#pragma target 3.0
// -------------------------------------
//#pragma shader_feature _NORMALMAP
//#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
//#pragma shader_feature _EMISSION
//#pragma shader_feature _METALLICGLOSSMAP
//#pragma shader_feature ___ _DETAIL_MULX2
//#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
//#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
//#pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
//#pragma shader_feature _PARALLAXMAP
#pragma multi_compile_fwdbase
#pragma multi_compile_fog
#pragma multi_compile_instancing
// Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes.
//#pragma multi_compile _ LOD_FADE_CROSSFADE
#pragma vertex vertBase
#pragma fragment fragBase
#include "UnityLayeredPhotogrammetryCoreForward.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Additive forward pass (one light per pass)
Pass
{
Name "FORWARD_DELTA"
Tags { "LightMode" = "ForwardAdd" }
Blend One One
Fog { Color (0,0,0,0) } // in additive pass fog should be black
ZWrite Off
ZTest LEqual
CGPROGRAM
#pragma target 3.0
// -------------------------------------
//#pragma shader_feature _NORMALMAP
//#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
//#pragma shader_feature _METALLICGLOSSMAP
//#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
//#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
//#pragma shader_feature ___ _DETAIL_MULX2
//#pragma shader_feature _PARALLAXMAP
#pragma multi_compile_fwdadd_fullshadows
#pragma multi_compile_fog
// Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes.
//#pragma multi_compile _ LOD_FADE_CROSSFADE
#pragma vertex vertAdd
#pragma fragment fragAdd
#include "UnityLayeredPhotogrammetryCoreForward.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Shadow rendering pass
Pass {
Name "ShadowCaster"
Tags { "LightMode" = "ShadowCaster" }
ZWrite On ZTest LEqual
CGPROGRAM
#pragma target 3.0
// -------------------------------------
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _PARALLAXMAP
#pragma multi_compile_shadowcaster
#pragma multi_compile_instancing
// Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes.
//#pragma multi_compile _ LOD_FADE_CROSSFADE
#pragma vertex vertShadowCaster
#pragma fragment fragShadowCaster
#include "UnityStandardShadow.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Deferred pass
Pass
{
Name "DEFERRED"
Tags { "LightMode" = "Deferred" }
CGPROGRAM
#pragma target 3.0
#pragma exclude_renderers nomrt
// -------------------------------------
//#pragma shader_feature _NORMALMAP
//#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
//#pragma shader_feature _EMISSION
//#pragma shader_feature _METALLICGLOSSMAP
//#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
//#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
//#pragma shader_feature ___ _DETAIL_MULX2
//#pragma shader_feature _PARALLAXMAP
#pragma multi_compile_prepassfinal
#pragma multi_compile_instancing
// Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes.
//#pragma multi_compile _ LOD_FADE_CROSSFADE
#pragma vertex vertDeferred
#pragma fragment fragDeferred
#include "UnityLayeredPhotogrammetryCore.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Extracts information for lightmapping, GI (emission, albedo, ...)
// This pass it not used during regular rendering.
Pass
{
Name "META"
Tags { "LightMode"="Meta" }
Cull Off
CGPROGRAM
#pragma vertex vert_meta
#pragma fragment frag_meta
//#pragma shader_feature _EMISSION
//#pragma shader_feature _METALLICGLOSSMAP
//#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
//#pragma shader_feature ___ _DETAIL_MULX2
//#pragma shader_feature EDITOR_VISUALIZATION
#include "UnityLayeredPhotogrammetryMeta.cginc"
ENDCG
}
}
SubShader
{
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
LOD 150
// ------------------------------------------------------------------
// Base forward pass (directional light, emission, lightmaps, ...)
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
Blend One Zero
ZWrite On
CGPROGRAM
#pragma target 2.0
//#pragma shader_feature _NORMALMAP
//#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
//#pragma shader_feature _EMISSION
//#pragma shader_feature _METALLICGLOSSMAP
//#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
//#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
//#pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
// SM2.0: NOT SUPPORTED shader_feature ___ _DETAIL_MULX2
// SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP
#pragma skip_variants SHADOWS_SOFT DIRLIGHTMAP_COMBINED
#pragma multi_compile_fwdbase
#pragma multi_compile_fog
#pragma vertex vertBase
#pragma fragment fragBase
#include "UnityLayeredPhotogrammetryCoreForward.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Additive forward pass (one light per pass)
Pass
{
Name "FORWARD_DELTA"
Tags { "LightMode" = "ForwardAdd" }
Blend One One
Fog { Color (0,0,0,0) } // in additive pass fog should be black
ZWrite Off
ZTest LEqual
CGPROGRAM
#pragma target 2.0
//#pragma shader_feature _NORMALMAP
//#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
//#pragma shader_feature _METALLICGLOSSMAP
//#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
//#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
//#pragma shader_feature ___ _DETAIL_MULX2
// SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP
#pragma skip_variants SHADOWS_SOFT
#pragma multi_compile_fwdadd_fullshadows
#pragma multi_compile_fog
#pragma vertex vertAdd
#pragma fragment fragAdd
#include "UnityLayeredPhotogrammetryCoreForward.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Shadow rendering pass
Pass {
Name "ShadowCaster"
Tags { "LightMode" = "ShadowCaster" }
ZWrite On ZTest LEqual
CGPROGRAM
#pragma target 2.0
//#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
//#pragma shader_feature _METALLICGLOSSMAP
//#pragma skip_variants SHADOWS_SOFT
#pragma multi_compile_shadowcaster
#pragma vertex vertShadowCaster
#pragma fragment fragShadowCaster
#include "UnityStandardShadow.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Extracts information for lightmapping, GI (emission, albedo, ...)
// This pass it not used during regular rendering.
Pass
{
Name "META"
Tags { "LightMode"="Meta" }
Cull Off
CGPROGRAM
#pragma vertex vert_meta
#pragma fragment frag_meta
//#pragma shader_feature _EMISSION
//#pragma shader_feature _METALLICGLOSSMAP
//#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
//#pragma shader_feature ___ _DETAIL_MULX2
//#pragma shader_feature EDITOR_VISUALIZATION
#include "UnityLayeredPhotogrammetryMeta.cginc"
ENDCG
}
}
FallBack "VertexLit"
CustomEditor "LayeredPhotogrammetryGUI"
}

9
Assets/LegacyLayered/LayeredPhotogrammetry.shader.meta


fileFormatVersion: 2
guid: f90795f547a374942a9e5c53acbe0784
timeCreated: 1497256144
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

140
Assets/LegacyLayered/LayeredPhotogrammetryDataInternal.cginc


void ADD_IDX(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;
// 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(_BaseColorMap));
ADD_IDX(layerTexCoord.details).uv = TRANSFORM_TEX(uvDetails, ADD_IDX(_DetailMap));
}
float3 ADD_IDX(GetNormalTS)(FragInputs input, LayerTexCoord layerTexCoord, float3 detailNormalTS, float detailMask, bool useBias, float bias)
{
float3 normalTS;
#ifdef _NORMALMAP_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));
}
#ifdef _DETAIL_MAP_IDX
normalTS = lerp(normalTS, BlendNormalRNM(normalTS, detailNormalTS), detailMask);
#endif
#else
normalTS = float3(0.0, 0.0, 1.0);
#endif
return normalTS;
}
// Return opacity
float ADD_IDX(GetSurfaceData)(FragInputs input, LayerTexCoord layerTexCoord, out SurfaceData surfaceData, out float3 normalTS)
{
float alpha = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_BaseColorMap), ADD_ZERO_IDX(sampler_BaseColorMap), ADD_IDX(layerTexCoord.base)).a * ADD_IDX(_BaseColor).a;
// Perform alha test very early to save performance (a killed pixel will not sample textures)
#if defined(_ALPHATEST_ON) && !defined(LAYERED_LIT_SHADER)
clip(alpha - _AlphaCutoff);
#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_IDX(_DetailNormalScale));
#endif
surfaceData.baseColor = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_BaseColorMap), ADD_ZERO_IDX(sampler_BaseColorMap), ADD_IDX(layerTexCoord.base)).rgb * ADD_IDX(_BaseColor).rgb;
#ifdef _DETAIL_MAP_IDX
surfaceData.baseColor *= 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.
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.metallic = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).r;
surfaceData.ambientOcclusion = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).g;
#else
surfaceData.metallic = 1.0;
surfaceData.ambientOcclusion = 1.0;
#endif
surfaceData.metallic *= ADD_IDX(_Metallic);
// Mandatory to setup value to keep compiler quiet
// Layered shader only supports the standard material
surfaceData.materialId = 1; // MaterialId.LitStandard
// All these parameters are ignore as they are re-setup outside of the layers function
surfaceData.tangentWS = float3(0.0, 0.0, 0.0);
surfaceData.anisotropy = 0.0;
surfaceData.specular = 0.0;
surfaceData.subsurfaceRadius = 0.0;
surfaceData.thickness = 0.0;
surfaceData.subsurfaceProfile = 0;
surfaceData.specularColor = float3(0.0, 0.0, 0.0);
return alpha;
}

9
Assets/LegacyLayered/LayeredPhotogrammetryDataInternal.cginc.meta


fileFormatVersion: 2
guid: 7fa7bc071bd7d1b4ba005beb70f1dd93
timeCreated: 1497270844
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

91
Assets/LegacyLayered/LayeredPhotogrammetrySampleUVMapping.cginc


// This structure abstract uv mapping inside one struct.
// It represent a mapping of any uv (with its associated tangent space for derivative if SurfaceGradient mode) - UVSet0 to 4, planar, triplanar
#define UV_MAPPING_UVSET 0
#define UV_MAPPING_PLANAR 1
// Planar/Triplanar convention for Unity in world space
void GetTriplanarCoordinate(float3 position, out float2 uvXZ, out float2 uvXY, out float2 uvZY)
{
// Caution: This must follow the same rule as what is use for SurfaceGradient triplanar
// TODO: Currently the normal mapping looks wrong without SURFACE_GRADIENT option because we don't handle corretly the tangent space
uvXZ = float2(position.z, position.x);
uvXY = float2(position.x, position.y);
uvZY = float2(position.z, position.y);
}
struct UVMapping
{
int mappingType;
float2 uv; // Current uv or planar uv
float3 normalWS; // vertex normal
};
#define TEXTURE2D_ARGS(textureName, samplerName) Texture2D textureName, SamplerState samplerName
#define TEXTURE2D_PARAM(textureName, samplerName) textureName, samplerName
#define UNITY_SAMPLE_TEX2D_SAMPLER(tex,samplertex,coord) tex.Sample (samplertex,coord)
#define UNITY_SAMPLE_TEX2D_LOD_SAMPLER(tex,samplertex,coord, lod) tex.SampleLevel (samplertex,coord, lod)
#define UNITY_SAMPLE_TEX2D_BIAS_SAMPLER(tex,samplertex,coord, bias) tex.SampleBias (samplertex,coord, bias)
float3 UnpackNormalRGB(float4 packedNormal, float scale = 1.0)
{
float3 normal;
normal.xyz = packedNormal.rgb * 2.0 - 1.0;
normal.xy *= scale;
return normalize(normal);
}
float3 UnpackNormalAG(float4 packedNormal, float scale = 1.0)
{
float3 normal;
normal.xy = packedNormal.wy * 2.0 - 1.0;
normal.xy *= scale;
normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
return normal;
}
float3 UnpackNormalmapRGorAG(float4 packedNormal, float scale = 1.0)
{
// This do the trick
packedNormal.w *= packedNormal.x;
return UnpackNormalAG(packedNormal, scale);
}
// Regular sampling functions
#define ADD_FUNC_SUFFIX(Name) Name
#define SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping, unused) UNITY_SAMPLE_TEX2D_SAMPLER(textureName, samplerName, uvMapping)
#include "LayeredPhotogrammetrySampleUVMappingInternal.cginc"
#undef ADD_FUNC_SUFFIX
#undef SAMPLE_TEXTURE_FUNC
// Lod sampling functions
#define ADD_FUNC_SUFFIX(Name) Name##Lod
#define SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping, lod) UNITY_SAMPLE_TEX2D_LOD_SAMPLER(textureName, samplerName, uvMapping, lod)
#include "LayeredPhotogrammetrySampleUVMappingInternal.cginc"
#undef ADD_FUNC_SUFFIX
#undef SAMPLE_TEXTURE_FUNC
// Bias sampling functions
#define ADD_FUNC_SUFFIX(Name) Name##Bias
#define SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping, bias) UNITY_SAMPLE_TEX2D_BIAS_SAMPLER(textureName, samplerName, uvMapping, bias)
#include "LayeredPhotogrammetrySampleUVMappingInternal.cginc"
#undef ADD_FUNC_SUFFIX
#undef SAMPLE_TEXTURE_FUNC
// Macro to improve readibility of surface data
#define SAMPLE_UVMAPPING_TEXTURE2D(textureName, samplerName, uvMapping) SampleUVMapping(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, 0.0) // Last 0.0 is unused
#define SAMPLE_UVMAPPING_TEXTURE2D_LOD(textureName, samplerName, uvMapping, lod) SampleUVMappingLod(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, lod)
#define SAMPLE_UVMAPPING_TEXTURE2D_BIAS(textureName, samplerName, uvMapping, bias) SampleUVMappingBias(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, bias)
#define SAMPLE_UVMAPPING_NORMALMAP(textureName, samplerName, uvMapping, scale) SampleUVMappingNormal(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, 0.0)
#define SAMPLE_UVMAPPING_NORMALMAP_LOD(textureName, samplerName, uvMapping, scale, lod) SampleUVMappingNormalLod(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, lod)
#define SAMPLE_UVMAPPING_NORMALMAP_BIAS(textureName, samplerName, uvMapping, scale, bias) SampleUVMappingNormalBias(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, bias)
#define SAMPLE_UVMAPPING_NORMALMAP_AG(textureName, samplerName, uvMapping, scale) SampleUVMappingNormalAG(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, 0.0)
#define SAMPLE_UVMAPPING_NORMALMAP_AG_LOD(textureName, samplerName, uvMapping, scale, lod) SampleUVMappingNormalAGLod(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, lod)
#define SAMPLE_UVMAPPING_NORMALMAP_AG_BIAS(textureName, samplerName, uvMapping, scale, bias) SampleUVMappingNormalAGBias(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, bias)
#define SAMPLE_UVMAPPING_NORMALMAP_RGB(textureName, samplerName, uvMapping, scale) SampleUVMappingNormalRGB(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, 0.0)
#define SAMPLE_UVMAPPING_NORMALMAP_RGB_LOD(textureName, samplerName, uvMapping, scale, lod) SampleUVMappingNormalRGBLod(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, lod)
#define SAMPLE_UVMAPPING_NORMALMAP_RGB_BIAS(textureName, samplerName, uvMapping, scale, bias) SampleUVMappingNormalRGBBias(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, bias)

9
Assets/LegacyLayered/LayeredPhotogrammetrySampleUVMapping.cginc.meta


fileFormatVersion: 2
guid: 821dcc02e404ef641a35f02b724b3eac
timeCreated: 1497271217
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

48
Assets/LegacyLayered/LayeredPhotogrammetrySampleUVMappingInternal.cginc


// These functions are use to hide the handling of triplanar mapping
// Normal need a specific treatment as they use special encoding for both base and detail map
// Also we use multiple inclusion to handle the various variation for lod and bias
// param can be unused, lod or bias
float4 ADD_FUNC_SUFFIX(SampleUVMapping)(TEXTURE2D_ARGS(textureName, samplerName), UVMapping uvMapping, float param)
{
{
return SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uv, param);
}
}
// Nested multiple includes of the file to handle all variations of normal map (AG, RG or RGB)
// This version is use for the base normal map (BC5 or DXT5nm)
#define ADD_NORMAL_FUNC_SUFFIX(Name) Name
#if defined(UNITY_NO_DXT5nm)
#define UNPACK_NORMAL_FUNC UnpackNormalRGB
#else
#define UNPACK_NORMAL_FUNC UnpackNormalmapRGorAG
#endif
float3 ADD_FUNC_SUFFIX(ADD_NORMAL_FUNC_SUFFIX(SampleUVMappingNormal))(TEXTURE2D_ARGS(textureName, samplerName), UVMapping uvMapping, float scale, float param)
{
return UNPACK_NORMAL_FUNC(SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uv, param), scale);
}
#undef ADD_NORMAL_FUNC_SUFFIX
#undef UNPACK_NORMAL_FUNC
// This version is for normalmap with AG encoding only. Use with details map encoded with others properties (like smoothness).
#define ADD_NORMAL_FUNC_SUFFIX(Name) Name##AG
#define UNPACK_NORMAL_FUNC UnpackNormalAG
float3 ADD_FUNC_SUFFIX(ADD_NORMAL_FUNC_SUFFIX(SampleUVMappingNormal))(TEXTURE2D_ARGS(textureName, samplerName), UVMapping uvMapping, float scale, float param)
{
return UNPACK_NORMAL_FUNC(SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uv, param), scale);
}
#undef ADD_NORMAL_FUNC_SUFFIX
#undef UNPACK_NORMAL_FUNC
// This version is for normalmap with RGB encoding only, i.e uncompress or BC7.
#define ADD_NORMAL_FUNC_SUFFIX(Name) Name##RGB
#define UNPACK_NORMAL_FUNC UnpackNormalRGB
float3 ADD_FUNC_SUFFIX(ADD_NORMAL_FUNC_SUFFIX(SampleUVMappingNormal))(TEXTURE2D_ARGS(textureName, samplerName), UVMapping uvMapping, float scale, float param)
{
return UNPACK_NORMAL_FUNC(SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uv, param), scale);
}
#undef ADD_NORMAL_FUNC_SUFFIX
#undef UNPACK_NORMAL_FUNC

9
Assets/LegacyLayered/LayeredPhotogrammetrySampleUVMappingInternal.cginc.meta


fileFormatVersion: 2
guid: fbb4ef2b52866d84186e0d38ddae61e6
timeCreated: 1497271217
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/LegacyLayered/UnityLayeredPhotogrammetryCore.cginc
文件差异内容过多而无法显示
查看文件

9
Assets/LegacyLayered/UnityLayeredPhotogrammetryCore.cginc.meta


fileFormatVersion: 2
guid: dac69be6f6996b14e824a03121d9e8c6
timeCreated: 1497256143
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

20
Assets/LegacyLayered/UnityLayeredPhotogrammetryCoreForward.cginc


#ifndef UNITY_STANDARD_CORE_FORWARD_INCLUDED
#define UNITY_STANDARD_CORE_FORWARD_INCLUDED
#if defined(UNITY_NO_FULL_STANDARD_SHADER)
# define UNITY_STANDARD_SIMPLE 1
#endif
#include "UnityStandardConfig.cginc"
#if UNITY_STANDARD_SIMPLE
# error
#else
#include "UnityLayeredPhotogrammetryCore.cginc"
VertexOutputForwardBase vertBase (VertexInput v) { return vertForwardBase(v); }
VertexOutputForwardAdd vertAdd (VertexInput v) { return vertForwardAdd(v); }
half4 fragBase (VertexOutputForwardBase i) : SV_Target { return fragForwardBaseInternal(i); }
half4 fragAdd (VertexOutputForwardAdd i) : SV_Target { return fragForwardAddInternal(i); }
#endif
#endif // UNITY_STANDARD_CORE_FORWARD_INCLUDED

9
Assets/LegacyLayered/UnityLayeredPhotogrammetryCoreForward.cginc.meta


fileFormatVersion: 2
guid: 3509fad5b0da8fe409cca366ceb504c5
timeCreated: 1497256457
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

75
Assets/LegacyLayered/UnityLayeredPhotogrammetryInput.cginc


#ifndef UNITY_STANDARD_INPUT_INCLUDED
#define UNITY_STANDARD_INPUT_INCLUDED
#include "UnityCG.cginc"
#include "UnityStandardConfig.cginc"
#include "UnityPBSLighting.cginc" // TBD: remove
#include "UnityStandardUtils.cginc"
//---------------------------------------
// Directional lightmaps & Parallax require tangent space too
#if (_NORMALMAP || DIRLIGHTMAP_COMBINED || _PARALLAXMAP)
#define _TANGENT_TO_WORLD 1
#endif
#if defined(_NORMALMAP0) || defined(_NORMALMAP1) || defined(_NORMALMAP2) || defined(_NORMALMAP3)
#define _TANGENT_TO_WORLD 1
#endif
#if (_DETAIL_MULX2 || _DETAIL_MUL || _DETAIL_ADD || _DETAIL_LERP)
#define _DETAIL 1
#endif
// ref http://blog.selfshadow.com/publications/blending-in-detail/
// ref https://gist.github.com/selfshadow/8048308
// Reoriented Normal Mapping
// Blending when n1 and n2 are already 'unpacked' and normalised
// assume compositing in tangent space
float3 BlendNormalRNM(float3 n1, float3 n2)
{
float3 t = n1.xyz + float3(0.0, 0.0, 1.0);
float3 u = n2.xyz * float3(-1.0, -1.0, 1.0);
float3 r = (t / t.z) * dot(t, u) - u;
return r;
}
//-------------------------------------------------------------------------------------
// Input functions
struct VertexInput
{
float4 vertex : POSITION;
half3 normal : NORMAL;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
#if defined(DYNAMICLIGHTMAP_ON) || defined(UNITY_PASS_META)
float2 uv2 : TEXCOORD2;
#endif
// BEGIN LAYERED_PHOTOGRAMMETRY
half4 color : COLOR;
float2 uv3 : TEXCOORD3;
// END LAYERED_PHOTOGRAMMETRY
#ifdef _TANGENT_TO_WORLD
half4 tangent : TANGENT;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
float4 TexCoords(VertexInput v)
{
//float4 texcoord;
//texcoord.xy = TRANSFORM_TEX(v.uv0, _MainTex); // Always source from uv0
//texcoord.zw = TRANSFORM_TEX(((_UVSec == 0) ? v.uv0 : v.uv1), _DetailAlbedoMap);
//return texcoord;
float4 texcoord;
texcoord.xy = v.uv0;
texcoord.zw = v.uv1;
return texcoord;
}
#endif // UNITY_STANDARD_INPUT_INCLUDED

9
Assets/LegacyLayered/UnityLayeredPhotogrammetryInput.cginc.meta


fileFormatVersion: 2
guid: 36a92757d8b2b4c4880665c56d4b0dec
timeCreated: 1497258005
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

82
Assets/LegacyLayered/UnityLayeredPhotogrammetryMeta.cginc


#ifndef UNITY_STANDARD_META_INCLUDED
#define UNITY_STANDARD_META_INCLUDED
// Functionality for Standard shader "meta" pass
// (extracts albedo/emission for lightmapper etc.)
// define meta pass before including other files; they have conditions
// on that in some places
#define UNITY_PASS_META 1
#include "UnityCG.cginc"
#include "UnityMetaPass.cginc"
#include "UnityLayeredPhotogrammetryCore.cginc"
#include "UnityLayeredPhotogrammetryInput.cginc"
struct v2f_meta
{
float4 uv : TEXCOORD0;
float4 uv2 : TEXCOORD1;
half4 tangentToWorldAndPackedData[3] : TEXCOORD2; // [3x3:tangentToWorld | 1x3:viewDirForParallax or worldPos]
float4 pos : SV_POSITION;
float4 color : COLOR;
#if UNITY_REQUIRE_FRAG_WORLDPOS && !UNITY_PACK_WORLDPOS_WITH_TANGENT
float3 posWorld : TEXCOORD8;
#endif
};
v2f_meta vert_meta (VertexInput v)
{
v2f_meta o;
o.pos = UnityMetaVertexPosition(v.vertex, v.uv1.xy, v.uv2.xy, unity_LightmapST, unity_DynamicLightmapST);
o.uv = TexCoords(v);
o.uv2 = float4(v.uv2, v.uv3); // JIG CHECK UV SCALE
o.color = v.color;
float4 posWorld = mul(unity_ObjectToWorld, v.vertex);
#if UNITY_REQUIRE_FRAG_WORLDPOS
#if UNITY_PACK_WORLDPOS_WITH_TANGENT
o.tangentToWorldAndPackedData[0].w = posWorld.x;
o.tangentToWorldAndPackedData[1].w = posWorld.y;
o.tangentToWorldAndPackedData[2].w = posWorld.z;
#else
o.posWorld = posWorld.xyz;
#endif
#endif
return o;
}
// Albedo for lightmapping should basically be diffuse color.
// But rough metals (black diffuse) still scatter quite a lot of light around, so
// we want to take some of that into account too.
half3 UnityLightmappingAlbedo (half3 diffuse, half3 specular, half smoothness)
{
half roughness = SmoothnessToRoughness(smoothness);
half3 res = diffuse;
res += specular * roughness * 0.5;
return res;
}
float4 frag_meta (v2f_meta i) : SV_Target
{
// we're interested in diffuse & specular colors,
// and surface roughness to produce final albedo.
FragmentCommonData data = FragmentSetupLayeredPhotogrammetry(i.pos, i.uv, i.uv2, i.color, float3(0.0, 0.0, 0.0), i.tangentToWorldAndPackedData, IN_WORLDPOS(i));
UnityMetaInput o;
UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o);
#if defined(EDITOR_VISUALIZATION)
o.Albedo = data.diffColor;
#else
o.Albedo = UnityLightmappingAlbedo (data.diffColor, data.specColor, data.smoothness);
#endif
o.SpecularColor = data.specColor;
o.Emission = float3(0.0, 0.0, 0.0);// Emission(i.uv.xy);
return UnityMetaFragment(o);
}
#endif // UNITY_STANDARD_META_INCLUDED

9
Assets/LegacyLayered/UnityLayeredPhotogrammetryMeta.cginc.meta


fileFormatVersion: 2
guid: b84d19b0baf3bcb4bbbb3cc8204bcade
timeCreated: 1497258005
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存