浏览代码

Merge HDRP/staging

/main
Antoine Lelievre 6 年前
当前提交
89fdc601
共有 24 个文件被更改,包括 306 次插入33 次删除
  1. 1
      com.unity.render-pipelines.high-definition/CHANGELOG.md
  2. 3
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDAssetFactory.cs
  3. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/HDRISky/HDRISkyEditor.cs
  4. 10
      com.unity.render-pipelines.high-definition/HDRP/HDRenderPipelineAsset.asset
  5. 14
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs
  6. 9
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/HDAdditionalReflectionData.cs
  7. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/HDProbe.cs
  8. 4
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/ProbeWrapper.cs
  9. 1
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset
  10. 1
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/RenderPipelineResources.cs
  11. 11
      com.unity.render-pipelines.high-definition/HDRP/Sky/HDRISky/IntegrateHDRISky.shader
  12. 3
      com.unity.render-pipelines.high-definition/HDRP/Sky/VisualEnvironment.cs
  13. 8
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky.meta
  14. 8
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky.meta
  15. 42
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky/GradientSkyEditor.cs
  16. 11
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky/GradientSkyEditor.cs.meta
  17. 32
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.cs
  18. 11
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.cs.meta
  19. 9
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.shader.meta
  20. 63
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSkyRenderer.cs
  21. 11
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSkyRenderer.cs.meta
  22. 81
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.shader

1
com.unity.render-pipelines.high-definition/CHANGELOG.md


- Added the possibility to add an override transform on the camera for volume interpolation
- Added desired lux intensity and auto multiplier for HDRI sky
- Added an option to disable light by type in the debug menu
- Added gradient sky
### Fixed
- Fixed an issue with PreIntegratedFGD texture being sometimes destroyed and not regenerated causing rendering to break

3
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDAssetFactory.cs


newAsset.buildProbabilityTables = Load<ComputeShader>(HDRenderPipelinePath + "Material/GGXConvolution/BuildProbabilityTables.compute");
newAsset.computeGgxIblSampleData = Load<ComputeShader>(HDRenderPipelinePath + "Material/GGXConvolution/ComputeGgxIblSampleData.compute");
newAsset.GGXConvolve = Load<Shader>(HDRenderPipelinePath + "Material/GGXConvolution/GGXConvolve.shader");
newAsset.opaqueAtmosphericScattering = Load<Shader>(HDRenderPipelinePath + "Sky/OpaqueAtmosphericScattering.shader");
newAsset.opaqueAtmosphericScattering = Load<Shader>(HDRenderPipelinePath + "Lighting/AtmosphericScattering/OpaqueAtmosphericScattering.shader");
newAsset.gradientSky = Load<Shader>(HDRenderPipelinePath + "Sky/GradientSky/GradientSky.shader");
// Skybox/Cubemap is a builtin shader, must use Sahder.Find to access it. It is fine because we are in the editor
newAsset.skyboxCubemap = Shader.Find("Skybox/Cubemap");

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/HDRISky/HDRISkyEditor.cs


if (hdri == null)
return;
float omegaP = (Mathf.PI * 4) / (6.0f * hdri.width * hdri.width);
m_IntegrateHDRISkyMaterial.SetFloat(HDShaderIDs._InvOmegaP, 1.0f / omegaP);
Graphics.Blit(Texture2D.whiteTexture, m_IntensityTexture.rt, m_IntegrateHDRISkyMaterial);

base.CommonSkySettingsGUI();
}
}
}
}

10
com.unity.render-pipelines.high-definition/HDRP/HDRenderPipelineAsset.asset


m_FrameSettings:
enableShadow: 1
enableContactShadows: 1
enableShadowMask: 1
enableSSR: 1
enableSSAO: 1
enableSubsurfaceScattering: 1

enableLightLayers: 1
diffuseGlobalDimmer: 1
specularGlobalDimmer: 1
enableForwardRenderingOnly: 0

enableOpaqueObjects: 1
enableTransparentObjects: 1
enableMSAA: 0
enableShadowMask: 1
lightLoopSettings:
enableTileAndCluster: 1
enableComputeLightEvaluation: 1

supportSSR: 1
supportSSAO: 1
supportSubsurfaceScattering: 1
supportOnlyForward: 0
supportRuntimeDebugDisplay: 1
supportDitheringCrossFade: 1
supportLightLayers: 0
supportOnlyForward: 0
supportRuntimeDebugDisplay: 1
supportDitheringCrossFade: 1
lightLoopSettings:
cookieSize: 128
cookieTexArraySize: 16

14
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs


s_LightVolumeDataBuffer.SetData(m_lightList.lightVolumes);
}
HDAdditionalReflectionData GetHDAdditionalReflectionData(VisibleReflectionProbe probe)
{
var add = probe.probe.GetComponent<HDAdditionalReflectionData>();
if (add == null)
{
add = HDUtils.s_DefaultHDAdditionalReflectionData;
Vector3 distance = Vector3.one * probe.blendDistance;
add.influenceVolume.boxBlendDistancePositive = distance;
add.influenceVolume.boxBlendDistanceNegative = distance;
add.influenceVolume.shape = Shape.Box;
}
return add;
}
HDAdditionalLightData GetHDAdditionalLightData(VisibleLight light)
{
var add = light.light.GetComponent<HDAdditionalLightData>();

9
com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/HDAdditionalReflectionData.cs


Current = Max - 1
}
const int currentVersion = (int)Version.Current;
[SerializeField, FormerlySerializedAs("version")]
int m_Version;

public void OnAfterDeserialize()
{
if (m_Version != currentVersion)
if (m_Version != (int)Version.Current)
{
// Add here data migration code that use other component
// Note impossible to access other component at deserialization time

needMigrateToUseInfluenceVolume = true;
}
else
{
{
m_Version = currentVersion;
m_Version = (int)Version.Current;
}
}
}

influenceVolume.boxSideFadePositive = boxSideFadePositive;
influenceVolume.boxSideFadeNegative = boxSideFadeNegative;
#pragma warning restore CS0618 // Type or member is obsolete
m_Version = (int)Version.HDProbeChild;
m_Version = (int)Version.UseInfluenceVolume;
needMigrateToUseInfluenceVolume = false;
OnAfterDeserialize(); //continue migrating if needed

2
com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/HDProbe.cs


set { m_RefreshMode = value; }
}
void Awake()
internal void Awake()
{
if (influenceVolume == null)
influenceVolume = new InfluenceVolume(this);

4
com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/ProbeWrapper.cs


if (add == null)
{
add = HDUtils.s_DefaultHDAdditionalReflectionData;
if (add.influenceVolume == null)
{
add.Awake();
}
Vector3 distance = Vector3.one * probe.blendDistance;
add.influenceVolume.boxBlendDistancePositive = distance;
add.influenceVolume.boxBlendDistanceNegative = distance;

1
com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset


integrateHdriSky: {fileID: 4800000, guid: 48db2705cf2856d4e893eb30a6892d1b, type: 3}
proceduralSky: {fileID: 4800000, guid: ec63f47fd265df243a7b1d40f9ef7fe7, type: 3}
skyboxCubemap: {fileID: 103, guid: 0000000000000000f000000000000000, type: 0}
gradientSky: {fileID: 4800000, guid: 2b5d4f1b26f03dc4a873b093e0c4adb1, type: 3}
preIntegratedFGD_GGXDisneyDiffuse: {fileID: 4800000, guid: 123f13d52852ef547b2962de4bd9eaad, type: 3}
preIntegratedFGD_CharlieClothLambert: {fileID: 4800000, guid: 3b3bf235775cf8b4baae7f3306787ab0, type: 3}
encodeBC6HCS: {fileID: 7200000, guid: aa922d239de60304f964e24488559eeb, type: 3}

1
com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/RenderPipelineResources.cs


public Shader integrateHdriSky;
public Shader proceduralSky;
public Shader skyboxCubemap;
public Shader gradientSky;
// Material
public Shader preIntegratedFGD_GGXDisneyDiffuse;

11
com.unity.render-pipelines.high-definition/HDRP/Sky/HDRISky/IntegrateHDRISky.shader


{
[HideInInspector]
_Cubemap ("", CUBE) = "white" {}
_InvOmegaP ("", Float) = 0
}
SubShader

};
TextureCube<float4> _Cubemap;
float _InvOmegaP;
Varyings Vert(Attributes input)
{

}
// Spherical integration of the upper hemisphere
// With HDRI that have a large range (including the sun) it can be challenging to
// compute the lux value without multiple importance sampling.
// We instead use a brute force Uniforme Spherical integration of the upper hemisphere
// with a large number of sample. This is fine as this happen in the editor.
real GetUpperHemisphereLuxValue(TEXTURECUBE_ARGS(skybox, sampler_skybox), real3 N)
{
float sum = 0.0;

{
for (float theta = 0; theta < PI / 2.0; theta += dtheta)
{
// SphericalToCartesian function is for Z up, lets move to Y up with TransformGLtoDX
float3 L = TransformGLtoDX(SphericalToCartesian(phi, cos(theta)));
real val = Luminance(SAMPLE_TEXTURECUBE_LOD(skybox, sampler_skybox, L, 0).rgb);
sum += cos(theta) * sin(theta) * val;

float4 Frag(Varyings input) : SV_Target
{
// Integrate upper hemisphere (Y up)
float3 N = float3(0.0, 1.0, 0.0);
float intensity = GetUpperHemisphereLuxValue(TEXTURECUBE_PARAM(_Cubemap, s_trilinear_clamp_sampler), N);

}
}
Fallback Off
}
}

3
com.unity.render-pipelines.high-definition/HDRP/Sky/VisualEnvironment.cs


public enum SkyType
{
HDRISky = 1,
ProceduralSky = 2
ProceduralSky = 2,
Gradient = 3,
}
// Keep this class first in the file. Otherwise it seems that the script type is not registered properly.

8
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky.meta


fileFormatVersion: 2
guid: d02d7d4257904854f91435453078fd44
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky.meta


fileFormatVersion: 2
guid: 4eaf64d2d64c8fb45b1e85eefff62dd7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

42
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky/GradientSkyEditor.cs


using UnityEngine;
using UnityEditor;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
[CanEditMultipleObjects]
[VolumeComponentEditor(typeof(GradientSky))]
public class GradientSkySettingsEditor : SkySettingsEditor
{
SerializedDataParameter m_Bottom;
SerializedDataParameter m_Middle;
SerializedDataParameter m_Top;
SerializedDataParameter m_GradientMultiplier;
public override void OnEnable()
{
base.OnEnable();
var o = new PropertyFetcher<GradientSky>(serializedObject);
m_Bottom = Unpack(o.Find(x => x.bottom));
m_Middle = Unpack(o.Find(x => x.middle));
m_Top = Unpack(o.Find(x => x.top));
m_GradientMultiplier = Unpack(o.Find(x => x.gradientDiffusion));
}
public override void OnInspectorGUI()
{
PropertyField(m_Top);
PropertyField(m_Middle);
PropertyField(m_Bottom);
PropertyField(m_GradientMultiplier);
EditorGUILayout.Space();
m_CommonUIElementsMask = (uint)SkySettingsUIElement.UpdateMode;
base.CommonSkySettingsGUI();
}
}
}

11
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky/GradientSkyEditor.cs.meta


fileFormatVersion: 2
guid: 8d9ef3fb3b5232a4abaebf916d7a1108
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

32
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[SkyUniqueID((int)SkyType.Gradient)]
public class GradientSky : SkySettings
{
public ColorParameter top = new ColorParameter(Color.blue, true, false, true);
public ColorParameter middle = new ColorParameter(new Color(0.3f, 0.7f, 1f), true, false, true);
public ColorParameter bottom = new ColorParameter(Color.white, true, false, true);
public FloatParameter gradientDiffusion = new FloatParameter(1);
public override SkyRenderer CreateRenderer()
{
return new GradientSkyRenderer(this);
}
public override int GetHashCode()
{
int hash = base.GetHashCode();
unchecked
{
hash = 13;
hash = hash * 23 + bottom.GetHashCode();
hash = hash * 23 + top.GetHashCode();
hash = hash * 23 + middle.GetHashCode();
hash = hash * 23 + gradientDiffusion.GetHashCode();
}
return hash;
}
}
}

11
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.cs.meta


fileFormatVersion: 2
guid: a81bcacc415a1f743bfdf703afc52027
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.shader.meta


fileFormatVersion: 2
guid: 2b5d4f1b26f03dc4a873b093e0c4adb1
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

63
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSkyRenderer.cs


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class GradientSkyRenderer : SkyRenderer
{
Material m_GradientSkyMaterial; // Renders a cubemap into a render texture (can be cube or 2D)
MaterialPropertyBlock m_PropertyBlock;
GradientSky m_GradientSkyParams;
readonly int _GradientBottom = Shader.PropertyToID("_GradientBottom");
readonly int _GradientMiddle = Shader.PropertyToID("_GradientMiddle");
readonly int _GradientTop = Shader.PropertyToID("_GradientTop");
readonly int _GradientDiffusion = Shader.PropertyToID("_GradientDiffusion");
public GradientSkyRenderer(GradientSky GradientSkyParams)
{
m_GradientSkyParams = GradientSkyParams;
m_PropertyBlock = new MaterialPropertyBlock();
}
public override void Build()
{
var hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;
m_GradientSkyMaterial = CoreUtils.CreateEngineMaterial(hdrp.renderPipelineResources.gradientSky);
}
public override void Cleanup()
{
CoreUtils.Destroy(m_GradientSkyMaterial);
}
public override void SetRenderTargets(BuiltinSkyParameters builtinParams)
{
if (builtinParams.depthBuffer == BuiltinSkyParameters.nullRT)
{
HDUtils.SetRenderTarget(builtinParams.commandBuffer, builtinParams.hdCamera, builtinParams.colorBuffer);
}
else
{
HDUtils.SetRenderTarget(builtinParams.commandBuffer, builtinParams.hdCamera, builtinParams.colorBuffer, builtinParams.depthBuffer);
}
}
public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap, bool renderSunDisk)
{
m_GradientSkyMaterial.SetColor(_GradientBottom, m_GradientSkyParams.bottom);
m_GradientSkyMaterial.SetColor(_GradientMiddle, m_GradientSkyParams.middle);
m_GradientSkyMaterial.SetColor(_GradientTop, m_GradientSkyParams.top);
m_GradientSkyMaterial.SetFloat(_GradientDiffusion, m_GradientSkyParams.gradientDiffusion);
// This matrix needs to be updated at the draw call frequency.
m_PropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix);
CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_GradientSkyMaterial, m_PropertyBlock, renderForCubemap ? 0 : 1);
}
public override bool IsValid()
{
return m_GradientSkyParams != null && m_GradientSkyMaterial != null;
}
}
}

11
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSkyRenderer.cs.meta


fileFormatVersion: 2
guid: 932fb63537938154fbe7249e1bbeb2e3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

81
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.shader


Shader "Hidden/HDRenderPipeline/Sky/GradientSky"
{
HLSLINCLUDE
#pragma vertex Vert
#pragma fragment Frag
#pragma target 4.5
#pragma only_renderers d3d11 ps4 xboxone vulkan metal
#include "CoreRP/ShaderLibrary/Common.hlsl"
#include "CoreRP/ShaderLibrary/Color.hlsl"
#include "CoreRP/ShaderLibrary/CommonLighting.hlsl"
#include "HDRP/ShaderVariables.hlsl"
float4x4 _PixelCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4
float4 _GradientBottom;
float4 _GradientMiddle;
float4 _GradientTop;
float _GradientDiffusion;
struct Attributes
{
uint vertexID : SV_VertexID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
};
Varyings Vert(Attributes input)
{
Varyings output;
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID, UNITY_RAW_FAR_CLIP_VALUE);
return output;
}
float4 Frag(Varyings input) : SV_Target
{
float3 viewDirWS = normalize(mul(float3(input.positionCS.xy, 1.0), (float3x3)_PixelCoordToViewDirWS));
float verticalGradient = viewDirWS.y * _GradientDiffusion;
float topLerpFactor = saturate(-verticalGradient);
float bottomLerpFactor = saturate(verticalGradient);
float3 color = lerp(_GradientMiddle.xyz, _GradientBottom.xyz, bottomLerpFactor);
color = lerp(color, _GradientTop.xyz, topLerpFactor);
return float4 (color, 1.0);
}
ENDHLSL
SubShader
{
Pass
{
ZWrite Off
ZTest Always
Blend Off
Cull Off
HLSLPROGRAM
ENDHLSL
}
Pass
{
ZWrite Off
ZTest LEqual
Blend Off
Cull Off
HLSLPROGRAM
ENDHLSL
}
}
Fallback Off
}
正在加载...
取消
保存