浏览代码

Merge remote-tracking branch 'origin/master' into refactorentrypoint

/main
Tim Cooper 8 年前
当前提交
1ddcb9ee
共有 28 个文件被更改,包括 1313 次插入782 次删除
  1. 142
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/Editor/LayeredLitUI.cs
  2. 30
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/LayeredLit.shader
  3. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.shader
  4. 43
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitData.hlsl
  5. 52
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitSurfaceData.hlsl
  6. 143
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyParameters.cs
  7. 198
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyRenderer.cs
  8. 67
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl
  9. 43
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/SkyProcedural.shader
  10. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/GGXConvolve.shader
  11. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs
  12. 11
      Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
  13. 4
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  14. 15
      Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl
  15. 55
      Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl
  16. 26
      Assets/ScriptableRenderLoop/ShaderLibrary/Sampling.hlsl
  17. 24
      Assets/ScriptableRenderLoop/common/ShaderBase.h
  18. 137
      Assets/ScriptableRenderLoop/common/TextureCache.cs
  19. 4
      Assets/ScriptableRenderLoop/fptl/LightingTemplate.hlsl
  20. 10
      Assets/ScriptableRenderLoop/fptl/ReflectionTemplate.hlsl
  21. 2
      README.md
  22. 153
      Assets/ScriptableRenderLoop/ShaderLibrary/Fibonacci.hlsl
  23. 9
      Assets/ScriptableRenderLoop/ShaderLibrary/Fibonacci.hlsl.meta
  24. 424
      Assets/ScriptableRenderLoop/ShaderLibrary/Hammersley.hlsl
  25. 9
      Assets/ScriptableRenderLoop/ShaderLibrary/Hammersley.hlsl.meta
  26. 80
      Assets/ScriptableRenderLoop/common/CubeToSpherical.shader
  27. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/AtmosphericParameters.cs.meta
  28. 390
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/AtmosphericParameters.cs

142
Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/Editor/LayeredLitUI.cs


public readonly GUIContent layerTexWorldScaleText = new GUIContent("Tiling", "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 UVDetailText = new GUIContent("Detail UV Mapping", "Detail UV Mapping mode of the layer.");
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 heightOffsetText = new GUIContent("HeightOffset", "Height offset from the previous layer.");
public readonly GUIContent heightFactorText = new GUIContent("Height Multiplier", "Scale applied to the height of the layer.");
public readonly GUIContent blendSizeText = new GUIContent("Blend Size", "Thickness over which the layer will be blended with the previous one.");
}
static StylesLayer s_Styles = null;

MaterialProperty[] layerUVDetail = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerUVDetailsMappingMask = new MaterialProperty[kMaxLayerCount];
const string kUseHeightBasedBlend = "_UseHeightBasedBlend";
MaterialProperty[] useHeightBasedBlend = new MaterialProperty[kMaxLayerCount-1];
const string kHeightOffset = "_HeightOffset";
MaterialProperty[] heightOffset = new MaterialProperty[kMaxLayerCount-1];
const string kHeightFactor = "_HeightFactor";
MaterialProperty[] heightFactor = new MaterialProperty[kMaxLayerCount-1];
const string kBlendSize = "_BlendSize";
MaterialProperty[] blendSize = new MaterialProperty[kMaxLayerCount-1];
MaterialProperty layerEmissiveColor = null;
MaterialProperty layerEmissiveColorMap = null;
MaterialProperty layerEmissiveIntensity = null;

FindMaterialOptionProperties(props);
FindMaterialOptionProperties(props);
layerMaskMap = FindProperty(kLayerMaskMap, props);
layerMaskVertexColor = FindProperty(kLayerMaskVertexColor, props);

layerUVMappingPlanar[i] = FindProperty(string.Format("{0}{1}", kUVMappingPlanar, i), props);
layerUVDetail[i] = FindProperty(string.Format("{0}{1}", kUVDetail, i), props);
layerUVDetailsMappingMask[i] = FindProperty(string.Format("{0}{1}", kUVDetailsMappingMask, i), props);
if(i != 0)
{
useHeightBasedBlend[i-1] = FindProperty(string.Format("{0}{1}", kUseHeightBasedBlend, i), props);
heightOffset[i-1] = FindProperty(string.Format("{0}{1}", kHeightOffset, i), props);
heightFactor[i-1] = FindProperty(string.Format("{0}{1}", kHeightFactor, i), props);
blendSize[i-1] = FindProperty(string.Format("{0}{1}", kBlendSize, i), props);
}
}
layerEmissiveColor = FindProperty(kEmissiveColor, props);

void SynchronizeLayerProperties(int layerIndex)
{
string[] exclusionList = { kTexWorldScale, kUVBase, kUVMappingMask, kUVDetail, kUVDetailsMappingMask };
string[] exclusionList = { kTexWorldScale, kUVBase, kUVMappingMask, kUVDetail, kUVMappingPlanar, kUVDetailsMappingMask };
Material material = m_MaterialEditor.target as Material;
Material layerMaterial = m_MaterialLayers[layerIndex];

string propertyName = ShaderUtil.GetPropertyName(layerShader, i);
string layerPropertyName = propertyName + layerIndex;
if(!exclusionList.Contains(propertyName))
{
if (material.HasProperty(layerPropertyName))
{
ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(layerShader, i);
switch (type)
{
case ShaderUtil.ShaderPropertyType.Color:
{
material.SetColor(layerPropertyName, layerMaterial.GetColor(propertyName));
break;
}
case ShaderUtil.ShaderPropertyType.Float:
case ShaderUtil.ShaderPropertyType.Range:
{
material.SetFloat(layerPropertyName, layerMaterial.GetFloat(propertyName));
break;
}
case ShaderUtil.ShaderPropertyType.Vector:
{
material.SetVector(layerPropertyName, layerMaterial.GetVector(propertyName));
break;
}
case ShaderUtil.ShaderPropertyType.TexEnv:
{
material.SetTexture(layerPropertyName, layerMaterial.GetTexture(propertyName));
material.SetTextureOffset(layerPropertyName, layerMaterial.GetTextureOffset(propertyName));
material.SetTextureScale(layerPropertyName, layerMaterial.GetTextureScale(propertyName));
break;
}
}
}
}
}
}
if(!exclusionList.Contains(propertyName))
{
if (material.HasProperty(layerPropertyName))
{
ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(layerShader, i);
switch (type)
{
case ShaderUtil.ShaderPropertyType.Color:
{
material.SetColor(layerPropertyName, layerMaterial.GetColor(propertyName));
break;
}
case ShaderUtil.ShaderPropertyType.Float:
case ShaderUtil.ShaderPropertyType.Range:
{
material.SetFloat(layerPropertyName, layerMaterial.GetFloat(propertyName));
break;
}
case ShaderUtil.ShaderPropertyType.Vector:
{
material.SetVector(layerPropertyName, layerMaterial.GetVector(propertyName));
break;
}
case ShaderUtil.ShaderPropertyType.TexEnv:
{
material.SetTexture(layerPropertyName, layerMaterial.GetTexture(propertyName));
material.SetTextureOffset(layerPropertyName, layerMaterial.GetTextureOffset(propertyName));
material.SetTextureScale(layerPropertyName, layerMaterial.GetTextureScale(propertyName));
break;
}
}
}
}
}
}
}
void InitializeMaterialLayers(AssetImporter materialImporter)

m_MaterialEditor.ShaderProperty(layerUVBase[layerIndex], styles.UVBaseText);
if (EditorGUI.EndChangeCheck())
{
SynchronizeLayerProperties(layerIndex);
SynchronizeLayerProperties(layerIndex);
result = true;
}
if (((LayerUVBaseMapping)layerUVBase[layerIndex].floatValue == LayerUVBaseMapping.Planar) ||

m_MaterialEditor.ShaderProperty(layerUVDetail[layerIndex], styles.UVDetailText);
if (EditorGUI.EndChangeCheck())
{
SynchronizeLayerProperties(layerIndex);
SynchronizeLayerProperties(layerIndex);
if(layerIndex > 0)
{
int heightParamIndex = layerIndex - 1;
EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = useHeightBasedBlend[heightParamIndex].hasMixedValue;
bool enabled = EditorGUILayout.Toggle(styles.useHeightBasedBlendText, useHeightBasedBlend[heightParamIndex].floatValue > 0.0f);
if(EditorGUI.EndChangeCheck())
{
useHeightBasedBlend[heightParamIndex].floatValue = enabled ? 1.0f : 0.0f;
}
if(enabled)
{
m_MaterialEditor.ShaderProperty(heightOffset[heightParamIndex], styles.heightOffsetText);
m_MaterialEditor.ShaderProperty(heightFactor[heightParamIndex], styles.heightFactorText);
m_MaterialEditor.ShaderProperty(blendSize[heightParamIndex], styles.blendSizeText);
}
}
EditorGUI.indentLevel--;
return result;

return layerChanged;
}
protected override void SetupMaterialKeywords(Material material)
protected override void SetupMaterialKeywords(Material material)
SetupCommonOptionsKeywords(material);
SetupLayersKeywords(material);
SetupCommonOptionsKeywords(material);
SetupLayersKeywords(material);
// Find first non null layer
int i = 0;

SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap + i));
SetKeyword(material, "_SPECULAROCCLUSIONMAP", material.GetTexture(kSpecularOcclusionMap + i));
SetKeyword(material, "_HEIGHTMAP", material.GetTexture(kHeightMap + i));
SetKeyword(material, "_DETAIL_MAP", material.GetTexture(kDetailMap + i));
SetKeyword(material, "_DETAIL_MAP", material.GetTexture(kDetailMap + i));
SetKeyword(material, "_DETAIL_MAP_WITH_NORMAL", ((DetailMapMode)material.GetFloat(kDetailMapMode)) == DetailMapMode.DetailWithNormal);
SetKeyword(material, "_HEIGHTMAP_AS_DISPLACEMENT", ((HeightmapMode)material.GetFloat(kHeightMapMode)) == HeightmapMode.Displacement);
SetKeyword(material, "_NORMALMAP_TANGENT_SPACE", ((NormalMapSpace)material.GetFloat(kNormalMapSpace)) == NormalMapSpace.TangentSpace);
SetKeyword(material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", ((SmoothnessMapChannel)material.GetFloat(kSmoothnessTextureChannel)) == SmoothnessMapChannel.AlbedoAlpha);
}
SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));

SetKeyword(material, "_REQUIRE_UV2_OR_UV3", UV2orUV3needed);
}
void SetupLayersKeywords(Material material)
void SetupLayersKeywords(Material material)
{
if (numLayer == 4)
{

foreach (var obj in m_MaterialEditor.targets)
{
SetupMaterialKeywords((Material)obj);
SetupMaterialKeywords((Material)obj);
}
SaveMaterialLayers(materialImporter);

if (layerChanged)
{
materialImporter.SaveAndReimport();
}
}
}
} // namespace UnityEditor

30
Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/LayeredLit.shader


_LayerMaskMap("LayerMaskMap", 2D) = "white" {}
[ToggleOff] _LayerMaskVertexColor("Use Vertex Color Mask", Float) = 0.0
// Height based blend (layer 0 does not need it)
_UseHeightBasedBlend1("UseHeightBasedBlend1", Float) = 0.0
_UseHeightBasedBlend2("UseHeightBasedBlend2", Float) = 0.0
_UseHeightBasedBlend3("UseHeightBasedBlend3", Float) = 0.0
_HeightOffset1("_HeightOffset1", Range(-0.3, 0.3)) = 0.0
_HeightOffset2("_HeightOffset2", Range(-0.3, 0.3)) = 0.0
_HeightOffset3("_HeightOffset3", Range(-0.3, 0.3)) = 0.0
_HeightFactor1("_HeightFactor1", Range(0, 5)) = 1
_HeightFactor2("_HeightFactor2", Range(0, 5)) = 1
_HeightFactor3("_HeightFactor3", Range(0, 5)) = 1
_BlendSize1("_BlendSize1", Range(0, 0.05)) = 0.0
_BlendSize2("_BlendSize2", Range(0, 0.05)) = 0.0
_BlendSize3("_BlendSize3", Range(0, 0.05)) = 0.0
_DistortionVectorMap("DistortionVectorMap", 2D) = "black" {}
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0)

TEXTURE2D(_LayerMaskMap);
SAMPLER2D(sampler_LayerMaskMap);
float _UseHeightBasedBlend1;
float _UseHeightBasedBlend2;
float _UseHeightBasedBlend3;
float _HeightOffset1;
float _HeightOffset2;
float _HeightOffset3;
float _HeightFactor1;
float _HeightFactor2;
float _HeightFactor3;
float _BlendSize1;
float _BlendSize2;
float _BlendSize3;
float3 _EmissiveColor;
TEXTURE2D(_EmissiveColorMap);

2
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.shader


_DetailMask("DetailMask", 2D) = "white" {}
_DetailAlbedoScale("_DetailAlbedoScale", Range(-2.0, 2.0)) = 1
_DetailNormalScale("_DetailNormalScale", Range(0.0, 2.0)) = 1
_DetailSmoothnessScale("_DetailSmoothnessScale", Range(-2.0, 2.0)) = 0.01
_DetailSmoothnessScale("_DetailSmoothnessScale", Range(-2.0, 2.0)) = 1
_DetailHeightScale("_DetailHeightScale", Range(-2.0, 2.0)) = 1
_DetailAOScale("_DetailAOScale", Range(-2.0, 2.0)) = 1

43
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitData.hlsl


return result;
}
float ApplyHeightBasedBlend(inout float inputFactor, float previousLayerHeight, float layerHeight, float heightOffset, float heightFactor, float edgeBlendStrength)
{
float finalLayerHeight = layerHeight * heightFactor + heightOffset;
edgeBlendStrength = max(0.001, edgeBlendStrength);
float heightThreshold = previousLayerHeight + edgeBlendStrength;
if (previousLayerHeight >= finalLayerHeight)
{
inputFactor = 0.0;
}
else if (finalLayerHeight > previousLayerHeight && finalLayerHeight < previousLayerHeight + edgeBlendStrength)
{
inputFactor = inputFactor * pow((finalLayerHeight - previousLayerHeight) / edgeBlendStrength, 0.5);
}
return max(finalLayerHeight, previousLayerHeight);
}
#define SURFACEDATA_BLEND_COLOR(surfaceData, name, mask) BlendLayeredColor(surfaceData##0.##name, surfaceData##1.##name, surfaceData##2.##name, surfaceData##3.##name, mask);
#define SURFACEDATA_BLEND_NORMAL(surfaceData, name, mask) BlendLayeredNormal(surfaceData##0.##name, surfaceData##1.##name, surfaceData##2.##name, surfaceData##3.##name, mask);
#define SURFACEDATA_BLEND_SCALAR(surfaceData, name, mask) BlendLayeredScalar(surfaceData##0.##name, surfaceData##1.##name, surfaceData##2.##name, surfaceData##3.##name, mask);

// Transform view vector in tangent space
float3 viewDirTS = TransformWorldToTangent(V, input.tangentToWorld);
ApplyDisplacement0(input, viewDirTS, layerTexCoord);
ApplyDisplacement1(input, viewDirTS, layerTexCoord);
ApplyDisplacement2(input, viewDirTS, layerTexCoord);
ApplyDisplacement3(input, viewDirTS, layerTexCoord);
float height0 = ApplyDisplacement0(input, viewDirTS, layerTexCoord);
float height1 = ApplyDisplacement1(input, viewDirTS, layerTexCoord);
float height2 = ApplyDisplacement2(input, viewDirTS, layerTexCoord);
float height3 = ApplyDisplacement3(input, viewDirTS, layerTexCoord);
float depthOffset = 0.0;
#ifdef _DEPTHOFFSET_ON

#if defined(_LAYER_MASK_VERTEX_COLOR)
maskValues *= input.vertexColor.rgb;
#endif
float baseLayerHeight = height0;
if (_UseHeightBasedBlend1 > 0.0f)
{
baseLayerHeight = ApplyHeightBasedBlend(maskValues.r, baseLayerHeight, height1, _HeightOffset1, _HeightFactor1, _BlendSize1);
}
if (_UseHeightBasedBlend2 > 0.0f)
{
baseLayerHeight = ApplyHeightBasedBlend(maskValues.g, baseLayerHeight, height2, _HeightOffset2 + _HeightOffset1, _HeightFactor2, _BlendSize2);
}
if (_UseHeightBasedBlend3 > 0.0f)
{
ApplyHeightBasedBlend(maskValues.b, baseLayerHeight, height3, _HeightOffset3 + _HeightOffset2 + _HeightOffset1, _HeightFactor3, _BlendSize3);
}
float weights[_MAX_LAYER];
ComputeMaskWeights(maskValues, weights);

52
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitSurfaceData.hlsl


ADD_IDX(layerTexCoord.details).uvXY = TRANSFORM_TEX(uvXY, ADD_IDX(_DetailMap));
}
void ADD_IDX(ApplyDisplacement)(inout FragInputs input, float3 viewDirTS, inout LayerTexCoord layerTexCoord)
float ADD_IDX(ApplyDisplacement)(inout FragInputs input, float3 viewDirTS, inout LayerTexCoord layerTexCoord)
float height = 0.0f;
#ifndef _HEIGHTMAP_AS_DISPLACEMENT
float height = SAMPLE_LAYER_TEXTURE2D(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), ADD_IDX(layerTexCoord.base)).r * ADD_IDX(_HeightScale) + ADD_IDX(_HeightBias);
float2 offset = ParallaxOffset(viewDirTS, height);
height = SAMPLE_LAYER_TEXTURE2D(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), ADD_IDX(layerTexCoord.base)).r * ADD_IDX(_HeightScale) + ADD_IDX(_HeightBias);
ADD_IDX(layerTexCoord.base).uv += offset;
ADD_IDX(layerTexCoord.base).uvYZ += offset;
ADD_IDX(layerTexCoord.base).uvZX += offset;
ADD_IDX(layerTexCoord.base).uvXY += offset;
//#ifndef _HEIGHTMAP_AS_DISPLACEMENT
// //height = SAMPLE_LAYER_TEXTURE2D(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), ADD_IDX(layerTexCoord.base)).r * ADD_IDX(_HeightScale) + ADD_IDX(_HeightBias);
// float2 offset = ParallaxOffset(viewDirTS, height);
ADD_IDX(layerTexCoord.details).uv += offset;
ADD_IDX(layerTexCoord.details).uvYZ += offset;
ADD_IDX(layerTexCoord.details).uvZX += offset;
ADD_IDX(layerTexCoord.details).uvXY += offset;
// ADD_IDX(layerTexCoord.base).uv += offset;
// ADD_IDX(layerTexCoord.base).uvYZ += offset;
// ADD_IDX(layerTexCoord.base).uvZX += offset;
// ADD_IDX(layerTexCoord.base).uvXY += offset;
// Only modify texcoord for first layer, this will be use by for builtin data (like lightmap)
if (LAYER_INDEX == 0)
{
input.texCoord0 += offset;
input.texCoord1 += offset;
input.texCoord2 += offset;
input.texCoord3 += offset;
}
#endif
// ADD_IDX(layerTexCoord.details).uv += offset;
// ADD_IDX(layerTexCoord.details).uvYZ += offset;
// ADD_IDX(layerTexCoord.details).uvZX += offset;
// ADD_IDX(layerTexCoord.details).uvXY += offset;
// // Only modify texcoord for first layer, this will be use by for builtin data (like lightmap)
// if (LAYER_INDEX == 0)
// {
// input.texCoord0 += offset;
// input.texCoord1 += offset;
// input.texCoord2 += offset;
// input.texCoord3 += offset;
// }
// // Need to refetch for the right parallaxed height for layer blending to behave correctly...
// height = SAMPLE_LAYER_TEXTURE2D(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), ADD_IDX(layerTexCoord.base)).r * ADD_IDX(_HeightScale) + ADD_IDX(_HeightBias);
// #endif
return height;
}
// Return opacity

143
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyParameters.cs


{
[ExecuteInEditMode]
[DisallowMultipleComponent]
public class ProceduralSkyParameters
: SkyParameters
public class ProceduralSkyParameters : SkyParameters
public enum OcclusionSamples { x64 = 0, x164 = 1, x244 = 2 }
public enum DepthTexture { Enable, Disable/*, Ignore*/ } // 'Ignore' appears to be currently unused.
public enum ScatterDebugMode { None, Scattering, Occlusion, OccludedScattering, Rayleigh, Mie, Height }
public enum OcclusionSamples { x64 = 0, x164 = 1, x244 = 2 }
public enum ScatterDebugMode { None, Scattering, Occlusion, OccludedScattering, Rayleigh, Mie, Height }
public Gradient worldRayleighColorRamp = null;
public float worldRayleighColorIntensity = 1f;
public float worldRayleighDensity = 10f;
public float worldRayleighExtinctionFactor = 1.1f;
public float worldRayleighIndirectScatter = 0.33f;
public Gradient worldMieColorRamp = null;
public float worldMieColorIntensity = 1f;
public float worldMieDensity = 15f;
public float worldMieExtinctionFactor = 0f;
public float worldMiePhaseAnisotropy = 0.9f;
public float worldNearScatterPush = 0f;
public float worldNormalDistance = 1000f;
public float worldMieColorIntensity = 1f;
public Gradient worldMieColorRamp = null;
public float worldMieDensity = 15f;
public float worldMieExtinctionFactor = 0f;
public float worldMiePhaseAnisotropy = 0.9f;
public float worldNearScatterPush = 0f;
public float worldNormalDistance = 1000f;
public float worldRayleighColorIntensity = 1f;
public Gradient worldRayleighColorRamp = null;
public float worldRayleighDensity = 10f;
public float worldRayleighExtinctionFactor = 1.1f;
public float worldRayleighIndirectScatter = 0.33f;
public Color heightRayleighColor = Color.white;
public float heightRayleighIntensity = 1f;
public float heightRayleighDensity = 10f;
public float heightMieDensity = 0f;
public float heightExtinctionFactor = 1.1f;
public float heightSeaLevel = 0f;
public float heightDistance = 50f;
public Vector3 heightPlaneShift = Vector3.zero;
public float heightNearScatterPush = 0f;
public float heightNormalDistance = 1000f;
[Header("Sky Dome")]
public Vector3 skyDomeRotation = Vector3.zero;
public bool skyDomeVerticalFlip = false;
public Cubemap skyDomeCubemap = null;
public float skyDomeExposure = 1f;
public Color skyDomeTint = Color.white;
public Transform skyDomeTrackedYawRotation = null;
public float heightDistance = 50f;
public float heightExtinctionFactor = 1.1f;
public float heightMieDensity = 0f;
public float heightNearScatterPush = 0f;
public float heightNormalDistance = 1000f;
public Vector3 heightPlaneShift = Vector3.zero;
public Color heightRayleighColor = Color.white;
public float heightRayleighDensity = 10f;
public float heightRayleighIntensity = 1f;
public float heightSeaLevel = 0f;
public bool occlusionFullSky = false;
public bool occlusionDepthFixup = true;
public float occlusionBiasIndirect = 0.6f;
public float occlusionBiasIndirect = 0.6f;
public float occlusionBiasSkyMie = 0.4f;
public float occlusionBiasSkyRayleigh = 0.2f;
public float occlusionDepthThreshold = 25f;
public bool occlusionDepthFixup = true;
public float occlusionDepthThreshold = 25f;
public bool occlusionFullSky = false;
public float occlusionBiasSkyRayleigh = 0.2f;
public float occlusionBiasSkyMie = 0.4f;
public Shader atmosphericShader = null;
// public Shader occlusionShader = null;
public float worldScaleExponent = 1.0f;
// public bool forcePerPixel = true;
// public bool forcePostEffect = true;
// [Tooltip("Soft clouds need depth values. Ignore means externally controlled.")]
public DepthTexture depthTexture = DepthTexture.Enable;
public ScatterDebugMode debugMode = ScatterDebugMode.None;
public Cubemap skyHDRI = null;
// public Shader atmosphericShader = null;
// public Shader occlusionShader = null;
public float worldScaleExponent = 1.0f;
public ScatterDebugMode debugMode = ScatterDebugMode.None;
void Awake()
{
if (worldRayleighColorRamp == null)
{
worldRayleighColorRamp = new Gradient();
worldRayleighColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.3f, 0.4f, 0.6f), 0f),
new GradientColorKey(new Color(0.5f, 0.6f, 0.8f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
if (worldMieColorRamp == null)
{
worldMieColorRamp = new Gradient();
worldMieColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.95f, 0.75f, 0.5f), 0f),
new GradientColorKey(new Color(1f, 0.9f, 8.0f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
}
worldScaleExponent = Mathf.Clamp(worldScaleExponent, 1f, 2f);
worldNormalDistance = Mathf.Clamp(worldNormalDistance, 1f, 10000f);
worldNearScatterPush = Mathf.Clamp(worldNearScatterPush, -200f, 300f);
worldRayleighDensity = Mathf.Clamp(worldRayleighDensity, 0, 1000f);
worldMieDensity = Mathf.Clamp(worldMieDensity, 0f, 1000f);
worldMieDensity = Mathf.Clamp(worldMieDensity, 0f, 1000f);
worldMiePhaseAnisotropy = Mathf.Clamp01(worldMiePhaseAnisotropy);
worldNearScatterPush = Mathf.Clamp(worldNearScatterPush, -200f, 300f);
worldNormalDistance = Mathf.Clamp(worldNormalDistance, 1f, 10000f);
worldRayleighDensity = Mathf.Clamp(worldRayleighDensity, 0, 1000f);
worldMiePhaseAnisotropy = Mathf.Clamp01(worldMiePhaseAnisotropy);
heightMieDensity = Mathf.Clamp(heightMieDensity, 0, 1000f);
heightNearScatterPush = Mathf.Clamp(heightNearScatterPush, -200f, 300f);
heightNormalDistance = Mathf.Clamp(heightNormalDistance, 1f, 10000f);
heightRayleighDensity = Mathf.Clamp(heightRayleighDensity, 0, 1000f);
heightNormalDistance = Mathf.Clamp(heightNormalDistance, 1f, 10000f);
heightNearScatterPush = Mathf.Clamp(heightNearScatterPush, -200f, 300f);
heightRayleighDensity = Mathf.Clamp(heightRayleighDensity, 0, 1000f);
heightMieDensity = Mathf.Clamp(heightMieDensity, 0, 1000f);
worldScaleExponent = Mathf.Clamp(worldScaleExponent, 1f, 2f);
occlusionBias = Mathf.Clamp01(occlusionBias);
occlusionBiasIndirect = Mathf.Clamp01(occlusionBiasIndirect);
occlusionBiasClouds = Mathf.Clamp01(occlusionBiasClouds);
occlusionBiasSkyRayleigh = Mathf.Clamp01(occlusionBiasSkyRayleigh);
occlusionBiasSkyMie = Mathf.Clamp01(occlusionBiasSkyMie);
occlusionBias = Mathf.Clamp01(occlusionBias);
occlusionBiasClouds = Mathf.Clamp01(occlusionBiasClouds);
occlusionBiasIndirect = Mathf.Clamp01(occlusionBiasIndirect);
occlusionBiasSkyMie = Mathf.Clamp01(occlusionBiasSkyMie);
occlusionBiasSkyRayleigh = Mathf.Clamp01(occlusionBiasSkyRayleigh);
skyDomeExposure = Mathf.Clamp(skyDomeExposure, 0f, 8f);
}
}
}

198
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyRenderer.cs


: SkyRenderer<ProceduralSkyParameters>
{
Material m_ProceduralSkyMaterial = null; // Renders a cubemap into a render texture (can be cube or 2D)
Gradient m_DefaultWorldRayleighColorRamp = null;
Gradient m_DefaultWorldMieColorRamp = null;
if (m_DefaultWorldRayleighColorRamp == null)
{
m_DefaultWorldRayleighColorRamp = new Gradient();
m_DefaultWorldRayleighColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.3f, 0.4f, 0.6f), 0f),
new GradientColorKey(new Color(0.5f, 0.6f, 0.8f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
if (m_DefaultWorldMieColorRamp == null)
{
m_DefaultWorldMieColorRamp = new Gradient();
m_DefaultWorldMieColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.95f, 0.75f, 0.5f), 0f),
new GradientColorKey(new Color(1f, 0.9f, 8.0f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
}
override public void Cleanup()

//ProceduralSkyParameters proceduralSkyParams = GetParameters(skyParameters);
return true; // TODO: See with Evgenii what makes it valid or invalid.
ProceduralSkyParameters allParams = GetParameters(skyParameters);
return allParams.skyHDRI != null &&
allParams.worldMieColorRamp != null &&
allParams.worldRayleighColorRamp != null;
void UpdateKeywords(bool enable, ProceduralSkyParameters param)
void SetKeywords(BuiltinSkyParameters builtinParams, ProceduralSkyParameters param)
// Ensure that all preprocessor symbols are initially undefined.
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_PER_PIXEL");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_DEBUG");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_DEBUG");
m_ProceduralSkyMaterial.DisableKeyword("PERFORM_SKY_OCCLUSION_TEST");
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_PER_PIXEL");
/*
if (useOcclusion)
{
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION");
if(occlusionDepthFixup && occlusionDownscale != OcclusionDownscale.x1)
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION_EDGE_FIXUP");
if(occlusionFullSky)
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
}
*/
if (enable)
// Expected to be valid for the sky pass, and invalid for the cube map generation pass.
if (builtinParams.depthBuffer != BuiltinSkyParameters.invalidRTI)
/*
if (useOcclusion)
{
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION");
if(occlusionDepthFixup && occlusionDownscale != OcclusionDownscale.x1)
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION_EDGE_FIXUP");
if(occlusionFullSky)
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
}
*/
m_ProceduralSkyMaterial.EnableKeyword("PERFORM_SKY_OCCLUSION_TEST");
}
if (param.debugMode != ProceduralSkyParameters.ScatterDebugMode.None)
{
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_DEBUG");
}
if (param.debugMode != ProceduralSkyParameters.ScatterDebugMode.None)
{
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_DEBUG");
void UpdateStaticUniforms(ProceduralSkyParameters param)
void SetUniforms(BuiltinSkyParameters builtinParams, ProceduralSkyParameters param)
m_ProceduralSkyMaterial.SetTexture("_SkyDomeCubemap", param.skyDomeCubemap);
m_ProceduralSkyMaterial.SetFloat("_SkyDomeExposure", param.skyDomeExposure);
m_ProceduralSkyMaterial.SetColor("_SkyDomeTint", param.skyDomeTint);
m_ProceduralSkyMaterial.SetTexture("_Cubemap", param.skyHDRI);
m_ProceduralSkyMaterial.SetVector("_SkyParam", new Vector4(param.exposure, param.multiplier, param.rotation, 0.0f));
m_ProceduralSkyMaterial.SetMatrix("_ViewProjMatrix", builtinParams.viewProjMatrix);
m_ProceduralSkyMaterial.SetMatrix("_InvViewProjMatrix", builtinParams.invViewProjMatrix);
m_ProceduralSkyMaterial.SetVector("_CameraPosWS", builtinParams.cameraPosWS);
m_ProceduralSkyMaterial.SetVector("_ScreenSize", builtinParams.screenSize);
m_ProceduralSkyMaterial.SetInt("_AtmosphericsDebugMode", (int)param.debugMode);
Vector3 sunDirection = (builtinParams.sunLight != null) ? -builtinParams.sunLight.transform.forward : Vector3.zero;
m_ProceduralSkyMaterial.SetVector("_SunDirection", sunDirection);
/*
m_ProceduralSkyMaterial.SetFloat("_ShadowBias", useOcclusion ? occlusionBias : 1f);

m_ProceduralSkyMaterial.SetFloat("_OcclusionDepthThreshold", occlusionDepthThreshold);
m_ProceduralSkyMaterial.SetVector("_OcclusionTexture_TexelSize", ???);
m_ProceduralSkyMaterial.SetFloat("_WorldScaleExponent", param.worldScaleExponent);
var pixelRect = new Rect(0f, 0f, builtinParams.screenSize.x, builtinParams.screenSize.y);
var scale = 1.0f; //(float)(int)occlusionDownscale;
var depthTextureScaledTexelSize = new Vector4(scale / pixelRect.width,
scale / pixelRect.height,
-scale / pixelRect.width,
-scale / pixelRect.height);
m_ProceduralSkyMaterial.SetVector("_DepthTextureScaledTexelSize", depthTextureScaledTexelSize);
m_ProceduralSkyMaterial.SetFloat("_WorldScaleExponent", param.worldScaleExponent);
m_ProceduralSkyMaterial.SetFloat("_MiePhaseAnisotropy", param.worldMiePhaseAnisotropy);
m_ProceduralSkyMaterial.SetVector("_RayleighInScatterPct", new Vector4(1f - param.worldRayleighIndirectScatter, param.worldRayleighIndirectScatter, 0f, 0f));
m_ProceduralSkyMaterial.SetFloat("_HeightNormalDistanceRcp", 1f / param.heightNormalDistance);
m_ProceduralSkyMaterial.SetFloat("_HeightNearScatterPush", -Mathf.Pow(Mathf.Abs(param.heightNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.heightNearScatterPush));
m_ProceduralSkyMaterial.SetFloat("_HeightRayleighDensity", -param.heightRayleighDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_WorldMieDensity", -param.worldMieDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_HeightSeaLevel", param.heightSeaLevel);
m_ProceduralSkyMaterial.SetFloat("_HeightDistanceRcp", 1f / param.heightDistance);
m_ProceduralSkyMaterial.SetVector("_HeightPlaneShift", param.heightPlaneShift);
m_ProceduralSkyMaterial.SetVector("_HeightRayleighColor", (Vector4)param.heightRayleighColor * param.heightRayleighIntensity);
m_ProceduralSkyMaterial.SetFloat("_HeightExtinctionFactor", param.heightExtinctionFactor);
m_ProceduralSkyMaterial.SetFloat("_RayleighExtinctionFactor", param.worldRayleighExtinctionFactor);
m_ProceduralSkyMaterial.SetFloat("_MieExtinctionFactor", param.worldMieExtinctionFactor);
Gradient worldRayleighColorRamp = param.worldRayleighColorRamp != null ? param.worldRayleighColorRamp : m_DefaultWorldRayleighColorRamp;
Gradient worldMieColorRamp = param.worldMieColorRamp != null ? param.worldMieColorRamp : m_DefaultWorldMieColorRamp;
var rayleighColorM20 = worldRayleighColorRamp.Evaluate(0.00f);
var rayleighColorM10 = worldRayleighColorRamp.Evaluate(0.25f);
var rayleighColorO00 = worldRayleighColorRamp.Evaluate(0.50f);
var rayleighColorP10 = worldRayleighColorRamp.Evaluate(0.75f);
var rayleighColorP20 = worldRayleighColorRamp.Evaluate(1.00f);
var rayleighColorM20 = param.worldRayleighColorRamp.Evaluate(0.00f);
var rayleighColorM10 = param.worldRayleighColorRamp.Evaluate(0.25f);
var rayleighColorO00 = param.worldRayleighColorRamp.Evaluate(0.50f);
var rayleighColorP10 = param.worldRayleighColorRamp.Evaluate(0.75f);
var rayleighColorP20 = param.worldRayleighColorRamp.Evaluate(1.00f);
var mieColorM20 = worldMieColorRamp.Evaluate(0.00f);
var mieColorO00 = worldMieColorRamp.Evaluate(0.50f);
var mieColorP20 = worldMieColorRamp.Evaluate(1.00f);
var mieColorM20 = param.worldMieColorRamp.Evaluate(0.00f);
var mieColorO00 = param.worldMieColorRamp.Evaluate(0.50f);
var mieColorP20 = param.worldMieColorRamp.Evaluate(1.00f);
m_ProceduralSkyMaterial.SetVector("_RayleighColorM20", (Vector4)rayleighColorM20 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorM10", (Vector4)rayleighColorM10 * param.worldRayleighColorIntensity);

m_ProceduralSkyMaterial.SetVector("_MieColorO00", (Vector4)mieColorO00 * param.worldMieColorIntensity);
m_ProceduralSkyMaterial.SetVector("_MieColorP20", (Vector4)mieColorP20 * param.worldMieColorIntensity);
m_ProceduralSkyMaterial.SetInt("_AtmosphericsDebugMode", (int)param.debugMode);
}
m_ProceduralSkyMaterial.SetFloat("_HeightNormalDistanceRcp", 1f / param.heightNormalDistance);
m_ProceduralSkyMaterial.SetFloat("_HeightNearScatterPush", -Mathf.Pow(Mathf.Abs(param.heightNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.heightNearScatterPush));
m_ProceduralSkyMaterial.SetFloat("_HeightRayleighDensity", -param.heightRayleighDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_HeightMieDensity", -param.heightMieDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_HeightSeaLevel", param.heightSeaLevel);
m_ProceduralSkyMaterial.SetVector("_HeightPlaneShift", param.heightPlaneShift);
m_ProceduralSkyMaterial.SetFloat("_HeightDistanceRcp", 1f / param.heightDistance);
m_ProceduralSkyMaterial.SetVector("_HeightRayleighColor", (Vector4)param.heightRayleighColor * param.heightRayleighIntensity);
m_ProceduralSkyMaterial.SetFloat("_HeightExtinctionFactor", param.heightExtinctionFactor);
void UpdateDynamicUniforms(BuiltinSkyParameters builtinParams, ProceduralSkyParameters param)
{
/* For now, we only use the directional light we are attached to, and the current camera. */
m_ProceduralSkyMaterial.SetVector("_RayleighInScatterPct", new Vector4(1f - param.worldRayleighIndirectScatter, param.worldRayleighIndirectScatter, 0f, 0f));
m_ProceduralSkyMaterial.SetFloat("_RayleighExtinctionFactor", param.worldRayleighExtinctionFactor);
var trackedYaw = param.skyDomeTrackedYawRotation ? param.skyDomeTrackedYawRotation.eulerAngles.y : 0f;
m_ProceduralSkyMaterial.SetMatrix("_SkyDomeRotation",
Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(param.skyDomeRotation.x, 0f, 0f), Vector3.one)
* Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, param.skyDomeRotation.y - trackedYaw, 0f), Vector3.one)
* Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1f, param.skyDomeVerticalFlip ? -1f : 1f, 1f))
);
m_ProceduralSkyMaterial.SetFloat("_MiePhaseAnisotropy", param.worldMiePhaseAnisotropy);
m_ProceduralSkyMaterial.SetFloat("_MieExtinctionFactor", param.worldMieExtinctionFactor);
Vector3 sunDirection = (builtinParams.sunLight != null) ? -builtinParams.sunLight.transform.forward : Vector3.zero;
m_ProceduralSkyMaterial.SetVector("_SunDirection", sunDirection);
m_ProceduralSkyMaterial.SetFloat("_WorldMieDensity", -param.worldMieDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_HeightMieDensity", -param.heightMieDensity / 100000f);
//var pixelRect = Camera.current ? Camera.current.pixelRect
// : new Rect(0f, 0f, Screen.width, Screen.height);
var pixelRect = new Rect(0f, 0f, builtinParams.screenSize.x, builtinParams.screenSize.y);
var scale = 1.0f; //(float)(int)occlusionDownscale;
var depthTextureScaledTexelSize = new Vector4(scale / pixelRect.width,
scale / pixelRect.height,
-scale / pixelRect.width,
-scale / pixelRect.height);
m_ProceduralSkyMaterial.SetVector("_DepthTextureScaledTexelSize", depthTextureScaledTexelSize);
m_ProceduralSkyMaterial.SetMatrix("_InvViewProjMatrix", builtinParams.invViewProjMatrix);
}
override public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters)

// Define select preprocessor symbols.
UpdateKeywords(true, proceduralSkyParams);
// Julien: what is it supposed to do?
if (proceduralSkyParams.depthTexture == ProceduralSkyParameters.DepthTexture.Disable)
{
// Disable depth texture rendering.
Camera.current.depthTextureMode = DepthTextureMode.None;
}
SetKeywords(builtinParams, proceduralSkyParams);
UpdateStaticUniforms(proceduralSkyParams);
UpdateDynamicUniforms(builtinParams, proceduralSkyParams);
m_ProceduralSkyMaterial.SetTexture("_Cubemap", proceduralSkyParams.skyDomeCubemap);
m_ProceduralSkyMaterial.SetVector("_SkyParam", new Vector4(proceduralSkyParams.exposure, proceduralSkyParams.multiplier, proceduralSkyParams.rotation, 0.0f));
SetUniforms(builtinParams, proceduralSkyParams);
if (builtinParams.depthBuffer != BuiltinSkyParameters.invalidRTI)
{
cmd.SetGlobalTexture("_CameraDepthTexture", builtinParams.depthBuffer);
}
cmd.DrawMesh(builtinParams.skyMesh, Matrix4x4.identity, m_ProceduralSkyMaterial);
builtinParams.renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();

67
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl


uniform float _ShadowBias;
uniform float _ShadowBiasIndirect;
uniform float _ShadowBiasClouds;
uniform float2 _ShadowBiasSkyRayleighMie;
uniform float _OcclusionDepthThreshold;
uniform float4 _OcclusionTexture_TexelSize;

uniform float _HeightSeaLevel;
uniform float3 _HeightPlaneShift;
uniform float _HeightDistanceRcp;
uniform float4 _HeightRayleighColor;
uniform float _HeightExtinctionFactor;
uniform float _RayleighCoeffScale;
uniform float3 _RayleighSunTintIntensity;
uniform float _RayleighExtinctionFactor;
uniform float _MieCoeffScale;
uniform float3 _MieSunTintIntensity;
uniform float _HeightExtinctionFactor;
uniform float _RayleighExtinctionFactor;
uniform float4 _HeightRayleighColor;
SAMPLER2D(sampler_CameraDepthTexture)
#define SRL_BilinearSampler sampler_CameraDepthTexture // Used for all textures

void VolundTransferScatter(float3 worldPos, out float4 coords1, out float4 coords2, out float4 coords3) {
const float3 scaledWorldPos = WorldScale(worldPos);
const float3 worldCamPos = WorldScale(_WorldSpaceCameraPos.xyz);
const float3 worldCamPos = WorldScale(_CameraPosWS.xyz);
const float c_MieScaleHeight = 1200.f;
const float worldRayleighDensity = 1.f;

const float worldVecLen = length(worldVec);
const float3 worldDir = worldVec / worldVecLen;
const float3 worldDirUnscaled = normalize(worldPos - _WorldSpaceCameraPos.xyz);
const float3 worldDirUnscaled = normalize(worldPos - _CameraPosWS.xyz);
const float viewSunCos = dot(worldDirUnscaled, _SunDirection);
const float rayleighPh = min(1.f, RayleighPhase(viewSunCos) * 12.f);

coords2.a = mieScatter;
}
void VolundTransferScatter(float3 scaledWorldPos, out float4 coords1) {
float4 c1, c2, c3;
VolundTransferScatter(scaledWorldPos, c1, c2, c3);
void VolundTransferScatter(float3 worldPos, out float4 coords1) {
float4 c1, c2, c3;
VolundTransferScatter(worldPos, c1, c2, c3);
#ifdef IS_RENDERING_SKY
coords1.rgb = c3.rgb;

}
float2 UVFromPos(float2 pos) {
return pos / _ScreenParams.xy;
#if defined(UNITY_PASS_FORWARDBASE)
return pos;
#else
return pos * _ScreenSize.zw;
#endif
}
float3 VolundApplyScatter(float4 coords1, float2 pos, float3 color) {

return color * coords1;
}
void VolundTransferScatterOcclusion(float3 scaledWorldPos, out float4 coords1, out float3 coords2) {
float4 c1, c2, c3;
VolundTransferScatter(scaledWorldPos, c1, c2, c3);
void VolundTransferScatterOcclusion(float3 worldPos, out float4 coords1, out float3 coords2) {
float4 c1, c2, c3;
VolundTransferScatter(worldPos, c1, c2, c3);
coords1.rgb = c1.rgb * _RayleighInScatterPct.x;
coords1.a = max(0.f, 1.f - c1.a * _RayleighExtinctionFactor - c3.a * _HeightExtinctionFactor);

float4 mfWeights = float4(fWeights.z * fWeights.y, fWeights.x * fWeights.y, fWeights.x * fWeights.w, fWeights.z * fWeights.w);
return dot(occ, mfWeights * maskDepth) / dot(mfWeights, maskDepth);
}
#endif //defined(ATMOSPHERICS_OCCLUSION_EDGE_FIXUP)
#else
return SAMPLE_TEXTURE2D(_OcclusionTexture, SRL_BilinearSampler, uv).r;
#endif
#else //defined(ATMOSPHERICS_OCCLUSION)
return 1.f;
#endif //defined(ATMOSPHERICS_OCCLUSION)

// Original vert/frag macros
#if defined(ATMOSPHERICS_OCCLUSION)
#define VOLUND_SCATTER_COORDS(idx1, idx2) float4 scatterCoords1 : TEXCOORD##idx1; float3 scatterCoords2 : TEXCOORD##idx2;
#define VOLUND_TRANSFER_SCATTER(pos, o) o.scatterCoords1 = pos.xyzz; o.scatterCoords2 = pos.xyz;
#define VOLUND_APPLY_SCATTER(i, color) VolundTransferScatterOcclusion(i.scatterCoords1.xyz, i.scatterCoords1, i.scatterCoords2); color = VolundApplyScatterOcclusion(i.scatterCoords1, i.scatterCoords2, i.pos.xy, color)
#define VOLUND_CLOUD_SCATTER(i, color) VolundTransferScatterOcclusion(i.scatterCoords1.xyz, i.scatterCoords1, i.scatterCoords2); color = VolundApplyCloudScatterOcclusion(i.scatterCoords1, i.scatterCoords2, i.pos.xy, color)
#if defined(ATMOSPHERICS_PER_PIXEL)
#define VOLUND_TRANSFER_SCATTER(pos, o) o.scatterCoords1 = pos.xyzz; o.scatterCoords2 = pos.xyz;
#define VOLUND_APPLY_SCATTER(i, color) VolundTransferScatterOcclusion(i.scatterCoords1.xyz, i.scatterCoords1, i.scatterCoords2); color = VolundApplyScatterOcclusion(i.scatterCoords1, i.scatterCoords2, i.pos.xy, color)
#define VOLUND_CLOUD_SCATTER(i, color) VolundTransferScatterOcclusion(i.scatterCoords1.xyz, i.scatterCoords1, i.scatterCoords2); color = VolundApplyCloudScatterOcclusion(i.scatterCoords1, i.scatterCoords2, i.pos.xy, color)
#else
#define VOLUND_TRANSFER_SCATTER(pos, o) VolundTransferScatterOcclusion(pos, o.scatterCoords1, o.scatterCoords2)
#define VOLUND_APPLY_SCATTER(i, color) color = VolundApplyScatterOcclusion(i.scatterCoords1, i.scatterCoords2, i.pos.xy, color)
#define VOLUND_CLOUD_SCATTER(i, color) color = VolundApplyCloudScatterOcclusion(i.scatterCoords1, i.scatterCoords2, i.pos.xy, color)
#endif
#define VOLUND_TRANSFER_SCATTER(pos, o) o.scatterCoords1 = pos.xyzz;
#define VOLUND_APPLY_SCATTER(i, color) VolundTransferScatter(i.scatterCoords1.xyz, i.scatterCoords1); color = VolundApplyScatter(i.scatterCoords1, i.pos.xy, color);
#define VOLUND_CLOUD_SCATTER(i, color) VolundTransferScatter(i.scatterCoords1.xyz, i.scatterCoords1); color = VolundApplyCloudScatter(i.scatterCoords1, color);
#if defined(ATMOSPHERICS_PER_PIXEL)
#define VOLUND_TRANSFER_SCATTER(pos, o) o.scatterCoords1 = pos.xyzz;
#define VOLUND_APPLY_SCATTER(i, color) VolundTransferScatter(i.scatterCoords1.xyz, i.scatterCoords1); color = VolundApplyScatter(i.scatterCoords1, i.pos.xy, color);
#define VOLUND_CLOUD_SCATTER(i, color) VolundTransferScatter(i.scatterCoords1.xyz, i.scatterCoords1); color = VolundApplyCloudScatter(i.scatterCoords1, color);
#else
#define VOLUND_TRANSFER_SCATTER(pos, o) VolundTransferScatter(pos, o.scatterCoords1)
#define VOLUND_APPLY_SCATTER(i, color) color = VolundApplyScatter(i.scatterCoords1, i.pos.xy, color)
#define VOLUND_CLOUD_SCATTER(i, color) color = VolundApplyCloudScatter(i.scatterCoords1, color)
#endif
#define SURFACE_SCATTER_COORDS float3 scaledWorldPos; float4 scatterCoords1; float3 scatterCoords2;
#define SURFACE_SCATTER_COORDS float3 worldPos; float4 scatterCoords1; float3 scatterCoords2;
#define SURFACE_SCATTER_APPLY(i, color) color += (i.scaledWorldPos + i.scatterCoords1.xyz + i.scatterCoords2.xyz) * 0.000001f
#define SURFACE_SCATTER_APPLY(i, color) color += (i.worldPos + i.scatterCoords1.xyz + i.scatterCoords2.xyz) * 0.000001f
#endif
#endif //FILE_ATMOSPHERICSCATTERING

43
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/SkyProcedural.shader


{
ZWrite Off
ZTest LEqual
Blend One Zero
Blend One OneMinusSrcAlpha, Zero One
HLSLPROGRAM
#pragma target 5.0

#pragma fragment Frag
#pragma multi_compile _ ATMOSPHERICS_DEBUG
#pragma multi_compile _ ATMOSPHERICS_OCCLUSION_FULLSKY
#ifndef PERFORM_SKY_OCCLUSION_TEST
#define IS_RENDERING_SKY
#endif
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "AtmosphericScattering.hlsl"
float4 _SkyParam; // x exposure, y multiplier, z rotation
// x exposure, y multiplier, z rotation
float4 _SkyParam;
// x = width, y = height, z = 1.0/width, w = 1.0/height
float4 _ScreenSize;
float4 _CameraPosWS;
float4x4 _InvViewProjMatrix;
float4x4 _ViewProjMatrix;
#define IS_RENDERING_SKY
#include "AtmosphericScattering.hlsl"
struct Attributes
{

// input.positionCS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw);
const float skyDepth = 0.01;
const float skyDepth = 0.002;
#ifdef PERFORM_SKY_OCCLUSION_TEST
// Determine whether the sky is occluded by the scene geometry.

}
#endif
float3 skyColor = ClampToFloat16Max(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb * exp2(_SkyParam.x) * _SkyParam.y);
float3 skyColor = float3(0.0, 0.0, 0.0);
float opacity = extinction;
if (skyTexWeight == 1.0)
{
skyColor = SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb;
skyColor *= exp2(_SkyParam.x) * _SkyParam.y;
opacity = 1.0; // Fully overwrite unoccluded scene regions.
}
// Apply extinction to the scene color when performing alpha-blending.
return float4(skyColor * (skyTexWeight * extinction) + scatter, extinction);
float3 atmosphereColor = ClampToFloat16Max(skyColor * extinction + scatter);
// Apply the atmosphere on top of the scene using premultiplied alpha blending.
return float4(atmosphereColor, opacity);
}
ENDHLSL

2
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/GGXConvolve.shader


PerceptualRoughnessToRoughness(perceptualRoughness),
_MipMapCount,
_InvOmegaP,
64,
55, // Matches the size of the precomputed Fibonacci point set
true);
return val;

8
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs


{
public Matrix4x4 viewProjMatrix;
public Matrix4x4 invViewProjMatrix;
public Vector3 cameraPosWS;
public Vector4 screenSize;
public Mesh skyMesh;
public ScriptableRenderContext renderLoop;

public static RenderTargetIdentifier invalidRTI = -1;
}
public class SkyManager

m_UpdateRequired = true; // Special case. Even if update mode is set to OnDemand, we need to regenerate the environment after destroying the texture.
}
if (m_SkyboxCubemapRT == null)
{
m_SkyboxCubemapRT = new RenderTexture(resolution, resolution, 1, RenderTextureFormat.ARGBHalf);

builtinParams.screenSize = m_CubemapScreenSize;
builtinParams.skyMesh = m_CubemapFaceMesh[i];
builtinParams.colorBuffer = target;
builtinParams.depthBuffer = new RenderTargetIdentifier();
builtinParams.depthBuffer = BuiltinSkyParameters.invalidRTI;
m_Renderer.RenderSky(builtinParams, skyParameters);
}
}

m_BuiltinParameters.sunLight = sunLight;
m_BuiltinParameters.invViewProjMatrix = camera.invViewProjectionMatrix;
m_BuiltinParameters.viewProjMatrix = camera.viewProjectionMatrix;
m_BuiltinParameters.cameraPosWS = camera.camera.transform.position;
m_BuiltinParameters.screenSize = camera.screenSize;
m_BuiltinParameters.skyMesh = BuildSkyMesh(camera.camera.GetComponent<Transform>().position, m_BuiltinParameters.invViewProjMatrix, false);
m_BuiltinParameters.colorBuffer = colorBuffer;

11
Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl


return INV_PI * D_GGXNoPI(NdotH, roughness);
}
float D_GGX_Inverse(float NdotH, float roughness)
{
roughness = max(roughness, UNITY_MIN_ROUGHNESS);
float a2 = roughness * roughness;
float f = (NdotH * a2 - NdotH) * NdotH + 1.0;
float g = (f * f) / a2;
return PI * g;
}
// Ref: http://jcgt.org/published/0003/02/03/paper.pdf
float V_SmithJointGGX(float NdotL, float NdotV, float roughness)
{

4
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


float GetShiftedNdotV(inout float3 N, float3 V, bool twoSided)
{
float NdotV = dot(N, V);
float limit = 1e-6;
float limit = 1e-4;
if (!twoSided && NdotV < limit)
{
// We do not renormalize the normal because { abs(length(N) - 1.0) < limit }.

15
Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl


return dot(v, v) - v2.x * v2.y - v2.y * v2.z - v2.z * v2.x + v2.x * v2.y * v2.z;
}
// texelArea = 4.0 / (resolution * resolution).
// Ref: http://bpeers.com/blog/?itemid=1017
float ComputeCubemapTexelSolidAngle(float3 L, float texelArea)
{
// Stretch 'L' by (1/d) so that it points at a side of a [-1, 1]^2 cube.
float d = Max3(abs(L.x), abs(L.y), abs(L.z));
// Since 'L' is a unit vector, we can directly compute its
// new (inverse) length without dividing 'L' by 'd' first.
float invDist = d;
// dw = dA * cosTheta / (dist * dist), cosTheta = 1.0 / dist,
// where 'dA' is the area of the cube map texel.
return texelArea * invDist * invDist * invDist;
}
//-----------------------------------------------------------------------------
// Attenuation functions
//-----------------------------------------------------------------------------

55
Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl


out float3 L)
{
// Cosine sampling - ref: http://www.rorydriscoll.com/2009/01/07/better-sampling/
float cosTheta = sqrt(max(0.0, 1.0 - u.x));
float cosTheta = sqrt(saturate(1.0 - u.x));
float sinTheta = sqrt(u.x);
float phi = TWO_PI * u.y;

{
// GGX NDF sampling
float cosThetaH = sqrt((1.0 - u.x) / (1.0 + (roughness * roughness - 1.0) * u.x));
float sinThetaH = sqrt(max(0.0, 1.0 - cosThetaH * cosThetaH));
float sinThetaH = sqrt(saturate(1.0 - cosThetaH * cosThetaH));
float phiH = TWO_PI * u.y;
// Transform from spherical into cartesian

// Convert sample from half angle to incident angle
L = 2.0 * dot(V, H) * H - V;
}
// Special case of ImportanceSampleGGXDir() where N == V.
// Approximates GGX with a BRDF which is isotropic for all viewing angles.
void ImportanceSampleGGXViewIndDir(float2 u,
float3 N,
float3 tangentX,
float3 tangentY,
float roughness,
out float3 L,
out float NdotH)
{
// GGX NDF sampling
float cosThetaH = sqrt((1.0 - u.x) / (1.0 + (roughness * roughness - 1.0) * u.x));
float sinThetaH = sqrt(saturate(1.0 - cosThetaH * cosThetaH));
float phiH = TWO_PI * u.y;
// Transform from spherical into Cartesian.
float3 localH = float3(sinThetaH * cos(phiH), sinThetaH * sin(phiH), cosThetaH);
// localN == localV == float3(0.0, 0.0, 1.0).
NdotH = localH.z;
// Compute { L = reflect(-localV, localH) }.
float VdotH = NdotH;
L = float3(0.0, 0.0, -1.0) + 2.0 * VdotH * localH;
// Local to world
L = tangentX * L.x + tangentY * L.y + N * L.z;
}
// ref: http://blog.selfshadow.com/publications/s2012-shading-course/burley/s2012_pbs_disney_brdf_notes_v3.pdf p26

float roughness,
float mipmapcount,
float invOmegaP,
uint sampleCount,
uint sampleCount, // Matches the size of the precomputed Fibonacci point set
float3 acc = float3(0.0, 0.0, 0.0);
float accWeight = 0;
float3 acc = float3(0.0, 0.0, 0.0);
float accWeight = 0;
float2 randNum = InitRandom(V.xy * 0.5 + 0.5);

for (uint i = 0; i < sampleCount; ++i)
{
float2 u = Hammersley2d(i, sampleCount);
u = frac(u + randNum + 0.5);
float2 u = k_Fibonacci2dSeq55[i];
u = frac(u + randNum);
float3 H;
ImportanceSampleGGXDir(u, V, N, tangentX, tangentY, roughness, H, L);
float NdotH;
ImportanceSampleGGXViewIndDir(u, N, tangentX, tangentY, roughness, L, NdotH);
float NdotL = saturate(dot(N,L));
float NdotL = saturate(dot(N, L));
float mipLevel;

// - OmegaS : Solid angle associated to a sample
// - OmegaP : Solid angle associated to a pixel of the cubemap
float NdotH = saturate(dot(N, H));
float pdf = D_GGX(NdotH, roughness) * 0.25;
float omegaS = 1.0 / (sampleCount * pdf); // Solid angle associated with the sample
float invPdf = D_GGX_Inverse(NdotH, roughness) * 4.0;
float omegaS = rcp(sampleCount) * invPdf; // Solid angle associated with the sample
// invOmegaP is precomputed on CPU and provide as a parameter of the function
// float omegaP = FOUR_PI / (6.0f * cubemapWidth * cubemapWidth); // Solid angle associated with the pixel of the cubemap
mipLevel = 0.5 * log2(omegaS * invOmegaP) + 1.0; // Clamp is not necessary as the hardware will do it

26
Assets/ScriptableRenderLoop/ShaderLibrary/Sampling.hlsl


// Sample generator
//-----------------------------------------------------------------------------
// Ref: http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
uint ReverseBits32(uint bits)
{
#if 1 // Shader model 5
return reversebits(bits);
#else
bits = (bits << 16) | (bits >> 16);
bits = ((bits & 0x00ff00ff) << 8) | ((bits & 0xff00ff00) >> 8);
bits = ((bits & 0x0f0f0f0f) << 4) | ((bits & 0xf0f0f0f0) >> 4);
bits = ((bits & 0x33333333) << 2) | ((bits & 0xcccccccc) >> 2);
bits = ((bits & 0x55555555) << 1) | ((bits & 0xaaaaaaaa) >> 1);
return bits;
#endif
}
float RadicalInverse_VdC(uint bits)
{
return float(ReverseBits32(bits)) * 2.3283064365386963e-10; // 0x100000000
}
float2 Hammersley2d(uint i, uint maxSampleCount)
{
return float2(float(i) / float(maxSampleCount), RadicalInverse_VdC(i));
}
#include "Fibonacci.hlsl"
#include "Hammersley.hlsl"
float Hash(uint s)
{

24
Assets/ScriptableRenderLoop/common/ShaderBase.h


#ifndef __SHADERBASE_H__
#define __SHADERBASE_H__
//#define CUBE_ARRAY_NOT_SUPPORTED
half2 DirectionToSphericalTexCoordinate(half3 dir)
{
// coordinate frame is (-Z,X) meaning negative Z is primary axis and X is secondary axis.
float recipPi = 1.0/3.1415926535897932384626433832795;
return half2( 1.0-0.5*recipPi*atan2(dir.x, -dir.z), asin(dir.y)*recipPi+0.5 );
}
#ifdef CUBE_ARRAY_NOT_SUPPORTED
#define UNITY_DECLARE_ABSTRACT_CUBE_ARRAY UNITY_DECLARE_TEX2DARRAY
#define UNITY_PASS_ABSTRACT_CUBE_ARRAY UNITY_PASS_TEX2DARRAY
#define UNITY_ARGS_ABSTRACT_CUBE_ARRAY UNITY_ARGS_TEX2DARRAY
#define UNITY_SAMPLE_ABSTRACT_CUBE_ARRAY_LOD(tex,coord,lod) UNITY_SAMPLE_TEX2DARRAY_LOD(tex, float3(DirectionToSphericalTexCoordinate((coord).xyz), (coord).w), lod)
#else
#define UNITY_DECLARE_ABSTRACT_CUBE_ARRAY UNITY_DECLARE_TEXCUBEARRAY
#define UNITY_PASS_ABSTRACT_CUBE_ARRAY UNITY_PASS_TEXCUBEARRAY
#define UNITY_ARGS_ABSTRACT_CUBE_ARRAY UNITY_ARGS_TEXCUBEARRAY
#define UNITY_SAMPLE_ABSTRACT_CUBE_ARRAY_LOD(tex,coord,lod) UNITY_SAMPLE_TEXCUBEARRAY_LOD(tex,coord,lod)
#endif
// can't use UNITY_REVERSED_Z since it's not enabled in compute shaders
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
#define REVERSE_ZBUF

137
Assets/ScriptableRenderLoop/common/TextureCache.cs


{
private CubemapArray m_Cache;
// alternative panorama path intended for mobile
// the member variables below are only in use when m_IsNoCubeArray is true.
private bool m_IsNoCubeArray = false;
private Texture2DArray m_CacheNoCubeArray;
private RenderTexture[] m_StagingRTs;
private int m_NumPanoMipLevels;
private Material m_CubeBlitMaterial;
private int m_CubeMipLevelPropName;
private int m_cubeSrcTexPropName;
// alternative panorama path intended for mobile
// the member variables below are only in use when m_IsNoCubeArray is true.
var mismatch = (m_Cache.width != texture.width) || (m_Cache.height != texture.height);
if (texture is Cubemap)
if(m_IsNoCubeArray)
TransferToPanoCache(sliceIndex, texture);
else
mismatch |= (m_Cache.format != (texture as Cubemap).format);
}
var mismatch = (m_Cache.width != texture.width) || (m_Cache.height != texture.height);
if (mismatch)
{
bool failed = false;
if (texture is Cubemap)
{
mismatch |= (m_Cache.format != (texture as Cubemap).format);
}
for (int f = 0; f < 6; f++)
if (mismatch)
if (!Graphics.ConvertTexture(texture, f, m_Cache, 6 * sliceIndex + f))
bool failed = false;
for (int f = 0; f < 6; f++)
{
if (!Graphics.ConvertTexture(texture, f, m_Cache, 6 * sliceIndex + f))
{
failed = true;
break;
}
}
if (failed)
failed = true;
break;
Debug.LogErrorFormat(texture, "Unable to convert texture \"{0}\" to match renderloop settings ({1}x{2} {3})",
texture.name, m_Cache.width, m_Cache.height, m_Cache.format);
if (failed)
else
Debug.LogErrorFormat(texture, "Unable to convert texture \"{0}\" to match renderloop settings ({1}x{2} {3})",
texture.name, m_Cache.width, m_Cache.height, m_Cache.format);
for (int f = 0; f < 6; f++)
Graphics.CopyTexture(texture, f, m_Cache, 6 * sliceIndex + f);
else
{
for (int f = 0; f < 6; f++)
Graphics.CopyTexture(texture, f, m_Cache, 6 * sliceIndex + f);
}
return m_Cache;
return m_IsNoCubeArray ? (Texture) m_CacheNoCubeArray : m_Cache;
var res = AllocTextureArray(6 * numCubeMaps);
m_NumMipLevels = GetNumMips(width, width);
var res = AllocTextureArray(numCubeMaps);
m_NumMipLevels = GetNumMips(width, width); // will calculate same way whether we have cube array or not
if(m_IsNoCubeArray)
{
if(!m_CubeBlitMaterial) m_CubeBlitMaterial = new Material(Shader.Find("Hidden/CubeToPano"));
int panoWidthTop = 4*width;
int panoHeightTop = 2*width;
// create panorama 2D array. Hardcoding the render target for now when m_IsNoCubeArray is true. No convenient way atm. to
// map from TextureFormat to RenderTextureFormat and don't want to deal with sRGB issues for now.
m_CacheNoCubeArray = new Texture2DArray(panoWidthTop, panoHeightTop, numCubeMaps, TextureFormat.RGBAHalf, isMipMapped)
{
hideFlags = HideFlags.HideAndDontSave,
wrapMode = TextureWrapMode.Repeat,
filterMode = FilterMode.Trilinear,
anisoLevel = 0
};
m_Cache = new CubemapArray(width, numCubeMaps, format, isMipMapped)
m_NumPanoMipLevels = isMipMapped ? GetNumMips(panoWidthTop, panoHeightTop) : 1;
m_StagingRTs = new RenderTexture[m_NumPanoMipLevels];
for(int m=0; m<m_NumPanoMipLevels; m++)
{
m_StagingRTs[m] = new RenderTexture(Mathf.Max(1,panoWidthTop>>m), Mathf.Max(1,panoHeightTop>>m), 0, RenderTextureFormat.ARGBHalf);
}
if(m_CubeBlitMaterial)
{
m_CubeMipLevelPropName = Shader.PropertyToID("_cubeMipLvl");
m_cubeSrcTexPropName = Shader.PropertyToID("_srcCubeTexture");
}
}
else
hideFlags = HideFlags.HideAndDontSave,
wrapMode = TextureWrapMode.Clamp,
filterMode = FilterMode.Trilinear,
anisoLevel = 0 // It is important to set 0 here, else unity force anisotropy filtering
};
m_Cache = new CubemapArray(width, numCubeMaps, format, isMipMapped)
{
hideFlags = HideFlags.HideAndDontSave,
wrapMode = TextureWrapMode.Clamp,
filterMode = FilterMode.Trilinear,
anisoLevel = 0 // It is important to set 0 here, else unity force anisotropy filtering
};
}
return res;
}

Texture.DestroyImmediate(m_Cache); // do I need this?
if(m_IsNoCubeArray)
{
Texture.DestroyImmediate(m_CacheNoCubeArray);
for(int m=0; m<m_NumPanoMipLevels; m++)
{
m_StagingRTs[m].Release();
}
m_StagingRTs=null;
if(m_CubeBlitMaterial) Material.DestroyImmediate(m_CubeBlitMaterial);
}
else Texture.DestroyImmediate(m_Cache);
}
private void TransferToPanoCache(int sliceIndex, Texture texture)
{
m_CubeBlitMaterial.SetTexture(m_cubeSrcTexPropName, texture);
for(int m=0; m<m_NumPanoMipLevels; m++)
{
m_CubeBlitMaterial.SetInt(m_CubeMipLevelPropName, Mathf.Min(m_NumMipLevels-1,m) );
Graphics.SetRenderTarget(m_StagingRTs[m]);
Graphics.Blit(null, m_CubeBlitMaterial, 0);
}
for(int m=0; m<m_NumPanoMipLevels; m++)
Graphics.CopyTexture(m_StagingRTs[m], 0, 0, m_CacheNoCubeArray, sliceIndex, m);
}
}

4
Assets/ScriptableRenderLoop/fptl/LightingTemplate.hlsl


//UNITY_DECLARE_TEX2D(_LightTextureB0);
sampler2D _LightTextureB0;
UNITY_DECLARE_TEX2DARRAY(_spotCookieTextures);
UNITY_DECLARE_TEXCUBEARRAY(_pointCookieTextures);
UNITY_DECLARE_ABSTRACT_CUBE_ARRAY(_pointCookieTextures);
StructuredBuffer<DirectionalLight> g_dirLightData;

[branch]if(bHasCookie)
{
float3 cookieCoord = -float3(dot(vL, lgtDat.lightAxisX.xyz), dot(vL, lgtDat.lightAxisY.xyz), dot(vL, lgtDat.lightAxisZ.xyz)); // negate to make vL a fromLight vector
cookieColor = UNITY_SAMPLE_TEXCUBEARRAY_LOD(_pointCookieTextures, float4(cookieCoord, lgtDat.sliceIndex), 0.0);
cookieColor = UNITY_SAMPLE_ABSTRACT_CUBE_ARRAY_LOD(_pointCookieTextures, float4(cookieCoord, lgtDat.sliceIndex), 0.0);
atten *= cookieColor.w;
}

10
Assets/ScriptableRenderLoop/fptl/ReflectionTemplate.hlsl


#include "UnityPBSLighting.cginc"
UNITY_DECLARE_TEXCUBEARRAY(_reflCubeTextures);
UNITY_DECLARE_ABSTRACT_CUBE_ARRAY(_reflCubeTextures);
UNITY_DECLARE_TEXCUBE(_reflRootCubeTexture);
//uniform int _reflRootSliceIndex;
uniform float _reflRootHdrDecodeMult;

half3 Unity_GlossyEnvironment (UNITY_ARGS_TEXCUBEARRAY(tex), int sliceIndex, half4 hdr, Unity_GlossyEnvironmentData glossIn);
half3 Unity_GlossyEnvironment (UNITY_ARGS_ABSTRACT_CUBE_ARRAY(tex), int sliceIndex, half4 hdr, Unity_GlossyEnvironmentData glossIn);
half3 distanceFromAABB(half3 p, half3 aabbMin, half3 aabbMax)
{

g.roughness = percRoughness;
g.reflUVW = sampleDir;
half3 env0 = Unity_GlossyEnvironment(UNITY_PASS_TEXCUBEARRAY(_reflCubeTextures), lgtDat.sliceIndex, float4(lgtDat.lightIntensity, lgtDat.decodeExp, 0.0, 0.0), g);
half3 env0 = Unity_GlossyEnvironment(UNITY_PASS_ABSTRACT_CUBE_ARRAY(_reflCubeTextures), lgtDat.sliceIndex, float4(lgtDat.lightIntensity, lgtDat.decodeExp, 0.0, 0.0), g);
UnityIndirect ind;

}
half3 Unity_GlossyEnvironment (UNITY_ARGS_TEXCUBEARRAY(tex), int sliceIndex, half4 hdr, Unity_GlossyEnvironmentData glossIn)
half3 Unity_GlossyEnvironment (UNITY_ARGS_ABSTRACT_CUBE_ARRAY(tex), int sliceIndex, half4 hdr, Unity_GlossyEnvironmentData glossIn)
{
#if UNITY_GLOSS_MATCHES_MARMOSET_TOOLBAG2 && (SHADER_TARGET >= 30)
// TODO: remove pow, store cubemap mips differently

half mip = perceptualRoughness * UNITY_SPECCUBE_LOD_STEPS;
half4 rgbm = UNITY_SAMPLE_TEXCUBEARRAY_LOD(tex, float4(glossIn.reflUVW.xyz, sliceIndex), mip);
half4 rgbm = UNITY_SAMPLE_ABSTRACT_CUBE_ARRAY_LOD(tex, float4(glossIn.reflUVW.xyz, sliceIndex), mip);
return DecodeHDR(rgbm, hdr);
}

2
README.md


## For Unity 5.6 beta users
* Unity 5.6 beta 1 should use an older revision of this project, [tagged unity-5.6.0b1](../../releases/tag/unity-5.6.0b1) (commit `acc230b` on 2016 Nov 23). "BasicRenderLoopScene" scene is the basic example, with the scriptable render loop defaulting to off; enable it by enabling the component on the camera. All the other scenes may or might not work. Use of Windows/DX11 is preferred.
* Unity 5.6 beta 1 and beta 2 should use an older revision of this project, [tagged unity-5.6.0b1](../../releases/tag/unity-5.6.0b1) (commit `acc230b` on 2016 Nov 23). "BasicRenderLoopScene" scene is the basic example, with the scriptable render loop defaulting to off; enable it by enabling the component on the camera. All the other scenes may or might not work. Use of Windows/DX11 is preferred.

153
Assets/ScriptableRenderLoop/ShaderLibrary/Fibonacci.hlsl


#ifndef UNITY_FIBONACCI_INCLUDED
#define UNITY_FIBONACCI_INCLUDED
// Computes a point using the Fibonacci sequence of length N.
// Input: Fib[N - 1], Fib[N - 2], and the index 'i' of the point.
// Ref: Integration of nonperiodic functions of two variables by Fibonacci lattice rules
float2 Fibonacci2dSeq(float fibN1, float fibN2, int i)
{
// 3 cycles on GCN if 'fibN1' and 'fibN2' are known at compile time.
return float2(i / fibN1, frac(i * (fibN2 / fibN1)));
}
static const int k_FibonacciSeq[] = {
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377
};
static const float2 k_Fibonacci2dSeq21[] = {
float2(0.00000000, 0.00000000),
float2(0.04761905, 0.61904764),
float2(0.09523810, 0.23809528),
float2(0.14285715, 0.85714293),
float2(0.19047619, 0.47619057),
float2(0.23809524, 0.09523821),
float2(0.28571430, 0.71428585),
float2(0.33333334, 0.33333349),
float2(0.38095239, 0.95238113),
float2(0.42857143, 0.57142878),
float2(0.47619048, 0.19047642),
float2(0.52380955, 0.80952406),
float2(0.57142860, 0.42857170),
float2(0.61904764, 0.04761887),
float2(0.66666669, 0.66666698),
float2(0.71428573, 0.28571510),
float2(0.76190478, 0.90476227),
float2(0.80952382, 0.52380943),
float2(0.85714287, 0.14285755),
float2(0.90476191, 0.76190567),
float2(0.95238096, 0.38095284)
};
static const float2 k_Fibonacci2dSeq34[] = {
float2(0.00000000, 0.00000000),
float2(0.02941176, 0.61764705),
float2(0.05882353, 0.23529410),
float2(0.08823530, 0.85294116),
float2(0.11764706, 0.47058821),
float2(0.14705883, 0.08823538),
float2(0.17647059, 0.70588231),
float2(0.20588236, 0.32352924),
float2(0.23529412, 0.94117641),
float2(0.26470590, 0.55882359),
float2(0.29411766, 0.17647076),
float2(0.32352942, 0.79411745),
float2(0.35294119, 0.41176462),
float2(0.38235295, 0.02941132),
float2(0.41176471, 0.64705849),
float2(0.44117647, 0.26470566),
float2(0.47058824, 0.88235283),
float2(0.50000000, 0.50000000),
float2(0.52941179, 0.11764717),
float2(0.55882353, 0.73529434),
float2(0.58823532, 0.35294151),
float2(0.61764705, 0.97058773),
float2(0.64705884, 0.58823490),
float2(0.67647058, 0.20588207),
float2(0.70588237, 0.82352924),
float2(0.73529410, 0.44117641),
float2(0.76470590, 0.05882263),
float2(0.79411763, 0.67646980),
float2(0.82352942, 0.29411697),
float2(0.85294116, 0.91176414),
float2(0.88235295, 0.52941132),
float2(0.91176468, 0.14705849),
float2(0.94117647, 0.76470566),
float2(0.97058821, 0.38235283)
};
static const float2 k_Fibonacci2dSeq55[] = {
float2(0.00000000, 0.00000000),
float2(0.01818182, 0.61818182),
float2(0.03636364, 0.23636365),
float2(0.05454545, 0.85454547),
float2(0.07272727, 0.47272730),
float2(0.09090909, 0.09090900),
float2(0.10909091, 0.70909095),
float2(0.12727273, 0.32727289),
float2(0.14545454, 0.94545460),
float2(0.16363636, 0.56363630),
float2(0.18181819, 0.18181801),
float2(0.20000000, 0.80000019),
float2(0.21818182, 0.41818190),
float2(0.23636363, 0.03636360),
float2(0.25454545, 0.65454578),
float2(0.27272728, 0.27272701),
float2(0.29090908, 0.89090919),
float2(0.30909091, 0.50909138),
float2(0.32727271, 0.12727261),
float2(0.34545454, 0.74545479),
float2(0.36363637, 0.36363602),
float2(0.38181818, 0.98181820),
float2(0.40000001, 0.60000038),
float2(0.41818181, 0.21818161),
float2(0.43636364, 0.83636379),
float2(0.45454547, 0.45454597),
float2(0.47272727, 0.07272720),
float2(0.49090910, 0.69090843),
float2(0.50909090, 0.30909157),
float2(0.52727270, 0.92727280),
float2(0.54545456, 0.54545403),
float2(0.56363636, 0.16363716),
float2(0.58181816, 0.78181839),
float2(0.60000002, 0.39999962),
float2(0.61818182, 0.01818275),
float2(0.63636363, 0.63636398),
float2(0.65454543, 0.25454521),
float2(0.67272729, 0.87272835),
float2(0.69090909, 0.49090958),
float2(0.70909089, 0.10909081),
float2(0.72727275, 0.72727203),
float2(0.74545455, 0.34545517),
float2(0.76363635, 0.96363640),
float2(0.78181821, 0.58181763),
float2(0.80000001, 0.20000076),
float2(0.81818181, 0.81818199),
float2(0.83636361, 0.43636322),
float2(0.85454547, 0.05454636),
float2(0.87272727, 0.67272758),
float2(0.89090908, 0.29090881),
float2(0.90909094, 0.90909195),
float2(0.92727274, 0.52727318),
float2(0.94545454, 0.14545441),
float2(0.96363634, 0.76363754),
float2(0.98181820, 0.38181686)
};
// Loads elements from one of the precomputed tables for sequence lengths of 9, 10, 11.
// Computes the values at runtime otherwise.
// For sampling, the size of the point set is given by { k_FibonacciSeq[sequenceLength - 1] }.
float2 Fibonacci2d(uint i, uint sequenceLength)
{
int fibN1 = k_FibonacciSeq[sequenceLength - 1];
int fibN2 = k_FibonacciSeq[sequenceLength - 2];
switch (fibN1)
{
case 21: return k_Fibonacci2dSeq21[i];
case 34: return k_Fibonacci2dSeq34[i];
case 55: return k_Fibonacci2dSeq55[i];
default: Fibonacci2dSeq(fibN1, fibN2, i);
}
}
#endif // UNITY_FIBONACCI_INCLUDED

9
Assets/ScriptableRenderLoop/ShaderLibrary/Fibonacci.hlsl.meta


fileFormatVersion: 2
guid: 63275e6ba7e477f43a376217dc2e147f
timeCreated: 1482325231
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

424
Assets/ScriptableRenderLoop/ShaderLibrary/Hammersley.hlsl


#ifndef UNITY_HAMMERSLEY_INCLUDED
#define UNITY_HAMMERSLEY_INCLUDED
// Ref: http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
uint ReverseBits32(uint bits)
{
#if 1 // Shader model 5
return reversebits(bits);
#else
bits = (bits << 16) | (bits >> 16);
bits = ((bits & 0x00ff00ff) << 8) | ((bits & 0xff00ff00) >> 8);
bits = ((bits & 0x0f0f0f0f) << 4) | ((bits & 0xf0f0f0f0) >> 4);
bits = ((bits & 0x33333333) << 2) | ((bits & 0xcccccccc) >> 2);
bits = ((bits & 0x55555555) << 1) | ((bits & 0xaaaaaaaa) >> 1);
return bits;
#endif
}
float RadicalInverse_VdC(uint bits)
{
return float(ReverseBits32(bits)) * 2.3283064365386963e-10; // 0x100000000
}
float2 Hammersley2dSeq(uint i, uint sequenceLength)
{
return float2(float(i) / float(sequenceLength), RadicalInverse_VdC(i));
}
static const float2 k_Hammersley2dSeq16[] = {
float2(0.00000000, 0.00000000),
float2(0.06250000, 0.50000000),
float2(0.12500000, 0.25000000),
float2(0.18750000, 0.75000000),
float2(0.25000000, 0.12500000),
float2(0.31250000, 0.62500000),
float2(0.37500000, 0.37500000),
float2(0.43750000, 0.87500000),
float2(0.50000000, 0.06250000),
float2(0.56250000, 0.56250000),
float2(0.62500000, 0.31250000),
float2(0.68750000, 0.81250000),
float2(0.75000000, 0.18750000),
float2(0.81250000, 0.68750000),
float2(0.87500000, 0.43750000),
float2(0.93750000, 0.93750000)
};
static const float2 k_Hammersley2dSeq32[] = {
float2(0.00000000, 0.00000000),
float2(0.03125000, 0.50000000),
float2(0.06250000, 0.25000000),
float2(0.09375000, 0.75000000),
float2(0.12500000, 0.12500000),
float2(0.15625000, 0.62500000),
float2(0.18750000, 0.37500000),
float2(0.21875000, 0.87500000),
float2(0.25000000, 0.06250000),
float2(0.28125000, 0.56250000),
float2(0.31250000, 0.31250000),
float2(0.34375000, 0.81250000),
float2(0.37500000, 0.18750000),
float2(0.40625000, 0.68750000),
float2(0.43750000, 0.43750000),
float2(0.46875000, 0.93750000),
float2(0.50000000, 0.03125000),
float2(0.53125000, 0.53125000),
float2(0.56250000, 0.28125000),
float2(0.59375000, 0.78125000),
float2(0.62500000, 0.15625000),
float2(0.65625000, 0.65625000),
float2(0.68750000, 0.40625000),
float2(0.71875000, 0.90625000),
float2(0.75000000, 0.09375000),
float2(0.78125000, 0.59375000),
float2(0.81250000, 0.34375000),
float2(0.84375000, 0.84375000),
float2(0.87500000, 0.21875000),
float2(0.90625000, 0.71875000),
float2(0.93750000, 0.46875000),
float2(0.96875000, 0.96875000)
};
static const float2 k_Hammersley2dSeq64[] = {
float2(0.00000000, 0.00000000),
float2(0.01562500, 0.50000000),
float2(0.03125000, 0.25000000),
float2(0.04687500, 0.75000000),
float2(0.06250000, 0.12500000),
float2(0.07812500, 0.62500000),
float2(0.09375000, 0.37500000),
float2(0.10937500, 0.87500000),
float2(0.12500000, 0.06250000),
float2(0.14062500, 0.56250000),
float2(0.15625000, 0.31250000),
float2(0.17187500, 0.81250000),
float2(0.18750000, 0.18750000),
float2(0.20312500, 0.68750000),
float2(0.21875000, 0.43750000),
float2(0.23437500, 0.93750000),
float2(0.25000000, 0.03125000),
float2(0.26562500, 0.53125000),
float2(0.28125000, 0.28125000),
float2(0.29687500, 0.78125000),
float2(0.31250000, 0.15625000),
float2(0.32812500, 0.65625000),
float2(0.34375000, 0.40625000),
float2(0.35937500, 0.90625000),
float2(0.37500000, 0.09375000),
float2(0.39062500, 0.59375000),
float2(0.40625000, 0.34375000),
float2(0.42187500, 0.84375000),
float2(0.43750000, 0.21875000),
float2(0.45312500, 0.71875000),
float2(0.46875000, 0.46875000),
float2(0.48437500, 0.96875000),
float2(0.50000000, 0.01562500),
float2(0.51562500, 0.51562500),
float2(0.53125000, 0.26562500),
float2(0.54687500, 0.76562500),
float2(0.56250000, 0.14062500),
float2(0.57812500, 0.64062500),
float2(0.59375000, 0.39062500),
float2(0.60937500, 0.89062500),
float2(0.62500000, 0.07812500),
float2(0.64062500, 0.57812500),
float2(0.65625000, 0.32812500),
float2(0.67187500, 0.82812500),
float2(0.68750000, 0.20312500),
float2(0.70312500, 0.70312500),
float2(0.71875000, 0.45312500),
float2(0.73437500, 0.95312500),
float2(0.75000000, 0.04687500),
float2(0.76562500, 0.54687500),
float2(0.78125000, 0.29687500),
float2(0.79687500, 0.79687500),
float2(0.81250000, 0.17187500),
float2(0.82812500, 0.67187500),
float2(0.84375000, 0.42187500),
float2(0.85937500, 0.92187500),
float2(0.87500000, 0.10937500),
float2(0.89062500, 0.60937500),
float2(0.90625000, 0.35937500),
float2(0.92187500, 0.85937500),
float2(0.93750000, 0.23437500),
float2(0.95312500, 0.73437500),
float2(0.96875000, 0.48437500),
float2(0.98437500, 0.98437500)
};
static const float2 k_Hammersley2dSeq256[] = {
float2(0.00000000, 0.00000000),
float2(0.00390625, 0.50000000),
float2(0.00781250, 0.25000000),
float2(0.01171875, 0.75000000),
float2(0.01562500, 0.12500000),
float2(0.01953125, 0.62500000),
float2(0.02343750, 0.37500000),
float2(0.02734375, 0.87500000),
float2(0.03125000, 0.06250000),
float2(0.03515625, 0.56250000),
float2(0.03906250, 0.31250000),
float2(0.04296875, 0.81250000),
float2(0.04687500, 0.18750000),
float2(0.05078125, 0.68750000),
float2(0.05468750, 0.43750000),
float2(0.05859375, 0.93750000),
float2(0.06250000, 0.03125000),
float2(0.06640625, 0.53125000),
float2(0.07031250, 0.28125000),
float2(0.07421875, 0.78125000),
float2(0.07812500, 0.15625000),
float2(0.08203125, 0.65625000),
float2(0.08593750, 0.40625000),
float2(0.08984375, 0.90625000),
float2(0.09375000, 0.09375000),
float2(0.09765625, 0.59375000),
float2(0.10156250, 0.34375000),
float2(0.10546875, 0.84375000),
float2(0.10937500, 0.21875000),
float2(0.11328125, 0.71875000),
float2(0.11718750, 0.46875000),
float2(0.12109375, 0.96875000),
float2(0.12500000, 0.01562500),
float2(0.12890625, 0.51562500),
float2(0.13281250, 0.26562500),
float2(0.13671875, 0.76562500),
float2(0.14062500, 0.14062500),
float2(0.14453125, 0.64062500),
float2(0.14843750, 0.39062500),
float2(0.15234375, 0.89062500),
float2(0.15625000, 0.07812500),
float2(0.16015625, 0.57812500),
float2(0.16406250, 0.32812500),
float2(0.16796875, 0.82812500),
float2(0.17187500, 0.20312500),
float2(0.17578125, 0.70312500),
float2(0.17968750, 0.45312500),
float2(0.18359375, 0.95312500),
float2(0.18750000, 0.04687500),
float2(0.19140625, 0.54687500),
float2(0.19531250, 0.29687500),
float2(0.19921875, 0.79687500),
float2(0.20312500, 0.17187500),
float2(0.20703125, 0.67187500),
float2(0.21093750, 0.42187500),
float2(0.21484375, 0.92187500),
float2(0.21875000, 0.10937500),
float2(0.22265625, 0.60937500),
float2(0.22656250, 0.35937500),
float2(0.23046875, 0.85937500),
float2(0.23437500, 0.23437500),
float2(0.23828125, 0.73437500),
float2(0.24218750, 0.48437500),
float2(0.24609375, 0.98437500),
float2(0.25000000, 0.00781250),
float2(0.25390625, 0.50781250),
float2(0.25781250, 0.25781250),
float2(0.26171875, 0.75781250),
float2(0.26562500, 0.13281250),
float2(0.26953125, 0.63281250),
float2(0.27343750, 0.38281250),
float2(0.27734375, 0.88281250),
float2(0.28125000, 0.07031250),
float2(0.28515625, 0.57031250),
float2(0.28906250, 0.32031250),
float2(0.29296875, 0.82031250),
float2(0.29687500, 0.19531250),
float2(0.30078125, 0.69531250),
float2(0.30468750, 0.44531250),
float2(0.30859375, 0.94531250),
float2(0.31250000, 0.03906250),
float2(0.31640625, 0.53906250),
float2(0.32031250, 0.28906250),
float2(0.32421875, 0.78906250),
float2(0.32812500, 0.16406250),
float2(0.33203125, 0.66406250),
float2(0.33593750, 0.41406250),
float2(0.33984375, 0.91406250),
float2(0.34375000, 0.10156250),
float2(0.34765625, 0.60156250),
float2(0.35156250, 0.35156250),
float2(0.35546875, 0.85156250),
float2(0.35937500, 0.22656250),
float2(0.36328125, 0.72656250),
float2(0.36718750, 0.47656250),
float2(0.37109375, 0.97656250),
float2(0.37500000, 0.02343750),
float2(0.37890625, 0.52343750),
float2(0.38281250, 0.27343750),
float2(0.38671875, 0.77343750),
float2(0.39062500, 0.14843750),
float2(0.39453125, 0.64843750),
float2(0.39843750, 0.39843750),
float2(0.40234375, 0.89843750),
float2(0.40625000, 0.08593750),
float2(0.41015625, 0.58593750),
float2(0.41406250, 0.33593750),
float2(0.41796875, 0.83593750),
float2(0.42187500, 0.21093750),
float2(0.42578125, 0.71093750),
float2(0.42968750, 0.46093750),
float2(0.43359375, 0.96093750),
float2(0.43750000, 0.05468750),
float2(0.44140625, 0.55468750),
float2(0.44531250, 0.30468750),
float2(0.44921875, 0.80468750),
float2(0.45312500, 0.17968750),
float2(0.45703125, 0.67968750),
float2(0.46093750, 0.42968750),
float2(0.46484375, 0.92968750),
float2(0.46875000, 0.11718750),
float2(0.47265625, 0.61718750),
float2(0.47656250, 0.36718750),
float2(0.48046875, 0.86718750),
float2(0.48437500, 0.24218750),
float2(0.48828125, 0.74218750),
float2(0.49218750, 0.49218750),
float2(0.49609375, 0.99218750),
float2(0.50000000, 0.00390625),
float2(0.50390625, 0.50390625),
float2(0.50781250, 0.25390625),
float2(0.51171875, 0.75390625),
float2(0.51562500, 0.12890625),
float2(0.51953125, 0.62890625),
float2(0.52343750, 0.37890625),
float2(0.52734375, 0.87890625),
float2(0.53125000, 0.06640625),
float2(0.53515625, 0.56640625),
float2(0.53906250, 0.31640625),
float2(0.54296875, 0.81640625),
float2(0.54687500, 0.19140625),
float2(0.55078125, 0.69140625),
float2(0.55468750, 0.44140625),
float2(0.55859375, 0.94140625),
float2(0.56250000, 0.03515625),
float2(0.56640625, 0.53515625),
float2(0.57031250, 0.28515625),
float2(0.57421875, 0.78515625),
float2(0.57812500, 0.16015625),
float2(0.58203125, 0.66015625),
float2(0.58593750, 0.41015625),
float2(0.58984375, 0.91015625),
float2(0.59375000, 0.09765625),
float2(0.59765625, 0.59765625),
float2(0.60156250, 0.34765625),
float2(0.60546875, 0.84765625),
float2(0.60937500, 0.22265625),
float2(0.61328125, 0.72265625),
float2(0.61718750, 0.47265625),
float2(0.62109375, 0.97265625),
float2(0.62500000, 0.01953125),
float2(0.62890625, 0.51953125),
float2(0.63281250, 0.26953125),
float2(0.63671875, 0.76953125),
float2(0.64062500, 0.14453125),
float2(0.64453125, 0.64453125),
float2(0.64843750, 0.39453125),
float2(0.65234375, 0.89453125),
float2(0.65625000, 0.08203125),
float2(0.66015625, 0.58203125),
float2(0.66406250, 0.33203125),
float2(0.66796875, 0.83203125),
float2(0.67187500, 0.20703125),
float2(0.67578125, 0.70703125),
float2(0.67968750, 0.45703125),
float2(0.68359375, 0.95703125),
float2(0.68750000, 0.05078125),
float2(0.69140625, 0.55078125),
float2(0.69531250, 0.30078125),
float2(0.69921875, 0.80078125),
float2(0.70312500, 0.17578125),
float2(0.70703125, 0.67578125),
float2(0.71093750, 0.42578125),
float2(0.71484375, 0.92578125),
float2(0.71875000, 0.11328125),
float2(0.72265625, 0.61328125),
float2(0.72656250, 0.36328125),
float2(0.73046875, 0.86328125),
float2(0.73437500, 0.23828125),
float2(0.73828125, 0.73828125),
float2(0.74218750, 0.48828125),
float2(0.74609375, 0.98828125),
float2(0.75000000, 0.01171875),
float2(0.75390625, 0.51171875),
float2(0.75781250, 0.26171875),
float2(0.76171875, 0.76171875),
float2(0.76562500, 0.13671875),
float2(0.76953125, 0.63671875),
float2(0.77343750, 0.38671875),
float2(0.77734375, 0.88671875),
float2(0.78125000, 0.07421875),
float2(0.78515625, 0.57421875),
float2(0.78906250, 0.32421875),
float2(0.79296875, 0.82421875),
float2(0.79687500, 0.19921875),
float2(0.80078125, 0.69921875),
float2(0.80468750, 0.44921875),
float2(0.80859375, 0.94921875),
float2(0.81250000, 0.04296875),
float2(0.81640625, 0.54296875),
float2(0.82031250, 0.29296875),
float2(0.82421875, 0.79296875),
float2(0.82812500, 0.16796875),
float2(0.83203125, 0.66796875),
float2(0.83593750, 0.41796875),
float2(0.83984375, 0.91796875),
float2(0.84375000, 0.10546875),
float2(0.84765625, 0.60546875),
float2(0.85156250, 0.35546875),
float2(0.85546875, 0.85546875),
float2(0.85937500, 0.23046875),
float2(0.86328125, 0.73046875),
float2(0.86718750, 0.48046875),
float2(0.87109375, 0.98046875),
float2(0.87500000, 0.02734375),
float2(0.87890625, 0.52734375),
float2(0.88281250, 0.27734375),
float2(0.88671875, 0.77734375),
float2(0.89062500, 0.15234375),
float2(0.89453125, 0.65234375),
float2(0.89843750, 0.40234375),
float2(0.90234375, 0.90234375),
float2(0.90625000, 0.08984375),
float2(0.91015625, 0.58984375),
float2(0.91406250, 0.33984375),
float2(0.91796875, 0.83984375),
float2(0.92187500, 0.21484375),
float2(0.92578125, 0.71484375),
float2(0.92968750, 0.46484375),
float2(0.93359375, 0.96484375),
float2(0.93750000, 0.05859375),
float2(0.94140625, 0.55859375),
float2(0.94531250, 0.30859375),
float2(0.94921875, 0.80859375),
float2(0.95312500, 0.18359375),
float2(0.95703125, 0.68359375),
float2(0.96093750, 0.43359375),
float2(0.96484375, 0.93359375),
float2(0.96875000, 0.12109375),
float2(0.97265625, 0.62109375),
float2(0.97656250, 0.37109375),
float2(0.98046875, 0.87109375),
float2(0.98437500, 0.24609375),
float2(0.98828125, 0.74609375),
float2(0.99218750, 0.49609375),
float2(0.99609375, 0.99609375)
};
// Loads elements from one of the precomputed tables for sequence lengths of 16, 32, 64, 256.
// Computes the values at runtime otherwise.
// For sampling, the size of the point set is the same as the sequence length.
float2 Hammersley2d(uint i, uint sequenceLength)
{
switch (sequenceLength)
{
case 16: return k_Hammersley2dSeq16[i];
case 32: return k_Hammersley2dSeq32[i];
case 64: return k_Hammersley2dSeq64[i];
case 256: return k_Hammersley2dSeq256[i];
default: return Hammersley2dSeq(i, sequenceLength);
}
}
#endif // UNITY_HAMMERSLEY_INCLUDED

9
Assets/ScriptableRenderLoop/ShaderLibrary/Hammersley.hlsl.meta


fileFormatVersion: 2
guid: aa5e319c8b8499f4fba1c3ecdd133545
timeCreated: 1482325231
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

80
Assets/ScriptableRenderLoop/common/CubeToSpherical.shader


Shader "Hidden/CubeToPano" {
Properties {
_SrcBlend ("", Float) = 1
_DstBlend ("", Float) = 1
}
SubShader {
Pass
{
ZWrite Off
ZTest Always
Cull Off
Blend Off
CGPROGRAM
#pragma target 4.5
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
UNITY_DECLARE_TEXCUBE(_srcCubeTexture);
uniform int _cubeMipLvl;
struct v2f {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
v2f vert (float4 vertex : POSITION, float2 texcoord : TEXCOORD0)
{
v2f o;
o.vertex = UnityObjectToClipPos(vertex);
o.texcoord = texcoord.xy;
return o;
}
half2 DirectionToSphericalTexCoordinate(half3 dir) // use this for the lookup
{
// coordinate frame is (-Z,X) meaning negative Z is primary axis and X is secondary axis.
float recipPi = 1.0/3.1415926535897932384626433832795;
return half2( 1.0-0.5*recipPi*atan2(dir.x, -dir.z), asin(dir.y)*recipPi+0.5 );
}
half3 SphericalTexCoordinateToDirection(half2 sphTexCoord)
{
float pi = 3.1415926535897932384626433832795;
float theta = (1-sphTexCoord.x) * (pi*2);
float phi = (sphTexCoord.y-0.5) * pi;
float csTh, siTh, csPh, siPh;
sincos(theta, siTh, csTh);
sincos(phi, siPh, csPh);
// theta is 0 at negative Z (backwards). Coordinate frame is (-Z,X) meaning negative Z is primary axis and X is secondary axis.
return float3(siTh*csPh, siPh, -csTh*csPh);
}
half4 frag (v2f i) : SV_Target
{
uint2 pixCoord = ((uint2) i.vertex.xy);
half3 dir = SphericalTexCoordinateToDirection(i.texcoord.xy);
half3 res = UNITY_SAMPLE_TEXCUBE_LOD(_srcCubeTexture, dir, (float) _cubeMipLvl).xyz;
return half4(res,1.0);
}
ENDCG
}
}
Fallback Off
}

12
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/AtmosphericParameters.cs.meta


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

390
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/AtmosphericParameters.cs


using UnityEngine;
[ExecuteInEditMode]
public class AtmosphericParameters : MonoBehaviour
{
public enum OcclusionDownscale { x1 = 1, x2 = 2, x4 = 4 }
public enum OcclusionSamples { x64 = 0, x164 = 1, x244 = 2 }
public enum DepthTexture { Enable, Disable/*, Ignore*/ } // 'Ignore' appears to be currently unused.
public enum ScatterDebugMode { None, Scattering, Occlusion, OccludedScattering, Rayleigh, Mie, Height }
[Header("Global Settings")]
public Gradient worldRayleighColorRamp = null;
public float worldRayleighColorIntensity = 1f;
public float worldRayleighDensity = 10f;
public float worldRayleighExtinctionFactor = 1.1f;
public float worldRayleighIndirectScatter = 0.33f;
public Gradient worldMieColorRamp = null;
public float worldMieColorIntensity = 1f;
public float worldMieDensity = 15f;
public float worldMieExtinctionFactor = 0f;
public float worldMiePhaseAnisotropy = 0.9f;
public float worldNearScatterPush = 0f;
public float worldNormalDistance = 1000f;
[Header("Height Settings")]
public Color heightRayleighColor = Color.white;
public float heightRayleighIntensity = 1f;
public float heightRayleighDensity = 10f;
public float heightMieDensity = 0f;
public float heightExtinctionFactor = 1.1f;
public float heightSeaLevel = 0f;
public float heightDistance = 50f;
public Vector3 heightPlaneShift = Vector3.zero;
public float heightNearScatterPush = 0f;
public float heightNormalDistance = 1000f;
[Header("Sky Dome")]
/*public*/ Vector3 skyDomeScale = new Vector3(1f, 1f, 1f);
/*public*/ Vector3 skyDomeRotation = Vector3.zero;
/*public*/ Transform skyDomeTrackedYawRotation = null;
/*public*/ bool skyDomeVerticalFlip = false;
/*public*/ Cubemap skyDomeCube = null;
/*public*/ float skyDomeExposure = 1f;
/*public*/ Color skyDomeTint = Color.white;
/*public*/ Vector3 skyDomeOffset = Vector3.zero;
/*
[Header("Scatter Occlusion")]
public bool useOcclusion = false;
public float occlusionBias = 0f;
public float occlusionBiasIndirect = 0.6f;
public float occlusionBiasClouds = 0.3f;
public OcclusionDownscale occlusionDownscale = OcclusionDownscale.x2;
public OcclusionSamples occlusionSamples = OcclusionSamples.x64;
public bool occlusionDepthFixup = true;
public float occlusionDepthThreshold = 25f;
public bool occlusionFullSky = false;
public float occlusionBiasSkyRayleigh = 0.2f;
public float occlusionBiasSkyMie = 0.4f;
*/
[Header("Other")]
public Shader atmosphericShaderOverride = null;
// public Shader occlusionShaderOverride = null;
public float worldScaleExponent = 1.0f;
// public bool forcePerPixel = true;
// public bool forcePostEffect = true;
[Tooltip("Soft clouds need depth values. Ignore means externally controlled.")]
public DepthTexture depthTexture = DepthTexture.Enable;
public ScatterDebugMode debugMode = ScatterDebugMode.None;
// [HideInInspector] public Shader occlusionShaderOverride;
// Camera m_currentCamera;
// UnityEngine.Rendering.CommandBuffer m_occlusionCmdAfterShadows, m_occlusionCmdBeforeScreen;
Material m_atmosphericMaterial = null;
// Material m_occlusionMaterial = null;
bool m_isAwake = false;
public static AtmosphericParameters instance { get; private set; }
void Awake()
{
if (worldRayleighColorRamp == null)
{
worldRayleighColorRamp = new Gradient();
worldRayleighColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.3f, 0.4f, 0.6f), 0f),
new GradientColorKey(new Color(0.5f, 0.6f, 0.8f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
if (worldMieColorRamp == null)
{
worldMieColorRamp = new Gradient();
worldMieColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.95f, 0.75f, 0.5f), 0f),
new GradientColorKey(new Color(1f, 0.9f, 8.0f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
if (atmosphericShaderOverride != null)
{
// Override the default shader.
m_atmosphericMaterial = new Material(atmosphericShaderOverride);
m_atmosphericMaterial.hideFlags = HideFlags.HideAndDontSave;
}
/*
if (occlusionShaderOverride != null)
{
// Override the default shader.
m_occlusionMaterial = new Material(occlusionShaderOverride);
m_occlusionMaterial.hideFlags = HideFlags.HideAndDontSave;
}
*/
m_isAwake = true;
}
public void OnValidate()
{
if (!m_isAwake) return;
Light light = gameObject.GetComponentInParent<Light>();
if (light == null || light.type != LightType.Directional)
{
Debug.LogErrorFormat("Unexpected: AtmosphericParameters is not attached to a directional light.");
return;
}
worldScaleExponent = Mathf.Clamp(worldScaleExponent, 1f, 2f);
worldNormalDistance = Mathf.Clamp(worldNormalDistance, 1f, 10000f);
worldNearScatterPush = Mathf.Clamp(worldNearScatterPush, -200f, 300f);
worldRayleighDensity = Mathf.Clamp(worldRayleighDensity, 0, 1000f);
worldMieDensity = Mathf.Clamp(worldMieDensity, 0f, 1000f);
worldRayleighIndirectScatter = Mathf.Clamp(worldRayleighIndirectScatter, 0f, 1f);
worldMiePhaseAnisotropy = Mathf.Clamp01(worldMiePhaseAnisotropy);
heightNormalDistance = Mathf.Clamp(heightNormalDistance, 1f, 10000f);
heightNearScatterPush = Mathf.Clamp(heightNearScatterPush, -200f, 300f);
heightRayleighDensity = Mathf.Clamp(heightRayleighDensity, 0, 1000f);
heightMieDensity = Mathf.Clamp(heightMieDensity, 0, 1000f);
/*
occlusionBias = Mathf.Clamp01(occlusionBias);
occlusionBiasIndirect = Mathf.Clamp01(occlusionBiasIndirect);
occlusionBiasClouds = Mathf.Clamp01(occlusionBiasClouds);
occlusionBiasSkyRayleigh = Mathf.Clamp01(occlusionBiasSkyRayleigh);
occlusionBiasSkyMie = Mathf.Clamp01(occlusionBiasSkyMie);
*/
skyDomeExposure = Mathf.Clamp(skyDomeExposure, 0f, 8f);
if (instance == this)
{
// TODO: what's the point of doing this?
Cleanup();
OnEnable();
}
// TODO: why would I want to do that here?
// #if UNITY_EDITOR
// UnityEditor.SceneView.RepaintAll();
// #endif
}
void OnEnable()
{
if (!m_isAwake) return;
// Define select preprocessor symbols.
UpdateKeywords(true);
if (depthTexture == DepthTexture.Disable)
{
// Disable depth texture rendering.
Camera.current.depthTextureMode = DepthTextureMode.None;
}
// Set shader constants.
UpdateStaticUniforms();
UpdateDynamicUniforms();
if (instance && instance != this)
{
Debug.LogErrorFormat("Unexpected: AtmosphericParameters.instance already set (to: {0}). Still overriding with: {1}.", instance.name, name);
}
instance = this;
}
void Cleanup()
{
// Undefine all preprocessor symbols.
UpdateKeywords(false);
if (instance && instance != this)
{
Debug.LogErrorFormat("Unexpected: AtmosphericParameters.instance set to: {0}, not to: {1}. Leaving alone.", instance.name, name);
}
else
{
instance = null;
}
}
void UpdateKeywords(bool enable)
{
Shader.DisableKeyword("ATMOSPHERICS_OCCLUSION");
Shader.DisableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
Shader.DisableKeyword("ATMOSPHERICS_OCCLUSION_EDGE_FIXUP");
Shader.DisableKeyword("ATMOSPHERICS_SUNRAYS");
Shader.DisableKeyword("ATMOSPHERICS_DEBUG");
if (enable)
{
/*
if (useOcclusion)
{
Shader.EnableKeyword("ATMOSPHERICS_OCCLUSION");
if(occlusionDepthFixup && occlusionDownscale != OcclusionDownscale.x1)
Shader.EnableKeyword("ATMOSPHERICS_OCCLUSION_EDGE_FIXUP");
if(occlusionFullSky)
Shader.EnableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
}
*/
if (debugMode != ScatterDebugMode.None)
{
Shader.EnableKeyword("ATMOSPHERICS_DEBUG");
}
}
}
void UpdateStaticUniforms()
{
Shader.SetGlobalVector("_SkyDomeOffset", skyDomeOffset);
Shader.SetGlobalVector("_SkyDomeScale", skyDomeScale);
Shader.SetGlobalTexture("_SkyDomeCube", skyDomeCube);
Shader.SetGlobalFloat("_SkyDomeExposure", skyDomeExposure);
Shader.SetGlobalColor("_SkyDomeTint", skyDomeTint);
/*
Shader.SetGlobalFloat("_ShadowBias", useOcclusion ? occlusionBias : 1f);
Shader.SetGlobalFloat("_ShadowBiasIndirect", useOcclusion ? occlusionBiasIndirect : 1f);
Shader.SetGlobalFloat("_ShadowBiasClouds", useOcclusion ? occlusionBiasClouds : 1f);
Shader.SetGlobalVector("_ShadowBiasSkyRayleighMie", useOcclusion ? new Vector4(occlusionBiasSkyRayleigh, occlusionBiasSkyMie, 0f, 0f) : Vector4.zero);
Shader.SetGlobalFloat("_OcclusionDepthThreshold", occlusionDepthThreshold);
*/
Shader.SetGlobalFloat("_WorldScaleExponent", worldScaleExponent);
Shader.SetGlobalFloat("_WorldNormalDistanceRcp", 1f/worldNormalDistance);
Shader.SetGlobalFloat("_WorldNearScatterPush", -Mathf.Pow(Mathf.Abs(worldNearScatterPush), worldScaleExponent) * Mathf.Sign(worldNearScatterPush));
Shader.SetGlobalFloat("_WorldRayleighDensity", -worldRayleighDensity / 100000f);
Shader.SetGlobalFloat("_MiePhaseAnisotropy", worldMiePhaseAnisotropy);
Shader.SetGlobalVector("_RayleighInScatterPct", new Vector4(1f - worldRayleighIndirectScatter, worldRayleighIndirectScatter, 0f, 0f));
Shader.SetGlobalFloat("_HeightNormalDistanceRcp", 1f/heightNormalDistance);
Shader.SetGlobalFloat("_HeightNearScatterPush", -Mathf.Pow(Mathf.Abs(heightNearScatterPush), worldScaleExponent) * Mathf.Sign(heightNearScatterPush));
Shader.SetGlobalFloat("_HeightRayleighDensity", -heightRayleighDensity / 100000f);
Shader.SetGlobalFloat("_HeightSeaLevel", heightSeaLevel);
Shader.SetGlobalFloat("_HeightDistanceRcp", 1f/heightDistance);
Shader.SetGlobalVector("_HeightPlaneShift", heightPlaneShift);
Shader.SetGlobalVector("_HeightRayleighColor", (Vector4)heightRayleighColor * heightRayleighIntensity);
Shader.SetGlobalFloat("_HeightExtinctionFactor", heightExtinctionFactor);
Shader.SetGlobalFloat("_RayleighExtinctionFactor", worldRayleighExtinctionFactor);
Shader.SetGlobalFloat("_MieExtinctionFactor", worldMieExtinctionFactor);
var rayleighColorM20 = worldRayleighColorRamp.Evaluate(0.00f);
var rayleighColorM10 = worldRayleighColorRamp.Evaluate(0.25f);
var rayleighColorO00 = worldRayleighColorRamp.Evaluate(0.50f);
var rayleighColorP10 = worldRayleighColorRamp.Evaluate(0.75f);
var rayleighColorP20 = worldRayleighColorRamp.Evaluate(1.00f);
var mieColorM20 = worldMieColorRamp.Evaluate(0.00f);
var mieColorO00 = worldMieColorRamp.Evaluate(0.50f);
var mieColorP20 = worldMieColorRamp.Evaluate(1.00f);
Shader.SetGlobalVector("_RayleighColorM20", (Vector4)rayleighColorM20 * worldRayleighColorIntensity);
Shader.SetGlobalVector("_RayleighColorM10", (Vector4)rayleighColorM10 * worldRayleighColorIntensity);
Shader.SetGlobalVector("_RayleighColorO00", (Vector4)rayleighColorO00 * worldRayleighColorIntensity);
Shader.SetGlobalVector("_RayleighColorP10", (Vector4)rayleighColorP10 * worldRayleighColorIntensity);
Shader.SetGlobalVector("_RayleighColorP20", (Vector4)rayleighColorP20 * worldRayleighColorIntensity);
Shader.SetGlobalVector("_MieColorM20", (Vector4)mieColorM20 * worldMieColorIntensity);
Shader.SetGlobalVector("_MieColorO00", (Vector4)mieColorO00 * worldMieColorIntensity);
Shader.SetGlobalVector("_MieColorP20", (Vector4)mieColorP20 * worldMieColorIntensity);
Shader.SetGlobalInt("_AtmosphericsDebugMode", (int)debugMode);
}
void OnWillRenderObject()
{
/*
if (!m_isAwake) return;
// For now, we only use the directional light we are attached to, and the current camera.
if (depthTexture == DepthTexture.Disable)
{
// Disable depth texture rendering.
Camera.current.depthTextureMode = DepthTextureMode.None;
}
// Set shader constants.
UpdateDynamicUniforms();
if (useOcclusion) {
var camRgt = m_currentCamera.transform.right;
var camUp = m_currentCamera.transform.up;
var camFwd = m_currentCamera.transform.forward;
var dy = Mathf.Tan(m_currentCamera.fieldOfView * 0.5f * Mathf.Deg2Rad);
var dx = dy * m_currentCamera.aspect;
var vpCenter = camFwd * m_currentCamera.farClipPlane;
var vpRight = camRgt * dx * m_currentCamera.farClipPlane;
var vpUp = camUp * dy * m_currentCamera.farClipPlane;
m_occlusionMaterial.SetVector("_CameraPosition", m_currentCamera.transform.position);
m_occlusionMaterial.SetVector("_ViewportCorner", vpCenter - vpRight - vpUp);
m_occlusionMaterial.SetVector("_ViewportRight", vpRight * 2f);
m_occlusionMaterial.SetVector("_ViewportUp", vpUp * 2f);
var farDist = m_currentCamera ? m_currentCamera.farClipPlane : 1000f;
var refDist = (Mathf.Min(farDist, QualitySettings.shadowDistance) - 1f) / farDist;
m_occlusionMaterial.SetFloat("_OcclusionSkyRefDistance", refDist);
var srcRect = m_currentCamera.pixelRect;
var downscale = 1f / (float)(int)occlusionDownscale;
var occWidth = Mathf.RoundToInt(srcRect.width * downscale);
var occHeight = Mathf.RoundToInt(srcRect.height * downscale);
var occlusionId = Shader.PropertyToID("_OcclusionTexture");
m_occlusionCmdBeforeScreen.Clear();
m_occlusionCmdBeforeScreen.GetTemporaryRT(occlusionId, occWidth, occHeight, 0, FilterMode.Bilinear, RenderTextureFormat.R8, RenderTextureReadWrite.sRGB);
m_occlusionCmdBeforeScreen.Blit(
null,
occlusionId,
m_occlusionMaterial,
(int)occlusionSamples
);
m_occlusionCmdBeforeScreen.SetGlobalTexture(occlusionId, occlusionId);
}
*/
}
void UpdateDynamicUniforms()
{
/* For now, we only use the directional light we are attached to, and the current camera. */
var trackedYaw = skyDomeTrackedYawRotation ? skyDomeTrackedYawRotation.eulerAngles.y : 0f;
Shader.SetGlobalMatrix("_SkyDomeRotation",
Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(skyDomeRotation.x, 0f, 0f), Vector3.one)
* Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, skyDomeRotation.y - trackedYaw, 0f), Vector3.one)
* Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1f, skyDomeVerticalFlip ? -1f : 1f, 1f))
);
Shader.SetGlobalVector("_SunDirection", -transform.forward);
Shader.SetGlobalFloat("_WorldMieDensity", -worldMieDensity / 100000f);
Shader.SetGlobalFloat("_HeightMieDensity", -heightMieDensity / 100000f);
var pixelRect = Camera.current ? Camera.current.pixelRect
: new Rect(0f, 0f, Screen.width, Screen.height);
var scale = 1.0f; //(float)(int)occlusionDownscale;
var depthTextureScaledTexelSize = new Vector4(scale / pixelRect.width,
scale / pixelRect.height,
-scale / pixelRect.width,
-scale / pixelRect.height);
Shader.SetGlobalVector("_DepthTextureScaledTexelSize", depthTextureScaledTexelSize);
}
void OnRenderObject()
{
/* This component is not rendered directly. */
}
}
正在加载...
取消
保存