浏览代码

Add a null VolumetricLighting shader

/sample_game
Evgenii Golubev 7 年前
当前提交
824c6f37
共有 11 个文件被更改,包括 217 次插入11 次删除
  1. 46
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 47
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/HomogeneousFog.cs
  3. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset
  4. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs
  5. 10
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics.meta
  6. 38
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/HomogeneousFog.cs.hlsl
  7. 10
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/HomogeneousFog.cs.hlsl.meta
  8. 10
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources.meta
  9. 53
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources/VolumetricLighting.compute
  10. 10
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources/VolumetricLighting.compute.meta

46
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


Material m_SssHorizontalFilterAndCombinePass;
// <<< Old SSS Model
ComputeShader m_VolumetricLightingCS { get { return m_Asset.renderPipelineResources.volumetricLightingCS; } }
int m_VolumetricLightingKernel;
static ComputeBuffer s_UnboundedVolumeData = null;
Material m_CameraMotionVectorsMaterial;
Material m_DebugViewMaterialGBuffer;

m_DebugDisplaySettings.RegisterDebug();
m_DebugFullScreenTempRT = HDShaderIDs._DebugFullScreenTexture;
m_VolumetricLightingKernel = m_VolumetricLightingCS.FindKernel("VolumetricLighting");
s_UnboundedVolumeData = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(VolumeProperties)));
}
void InitializeDebugMaterials()

m_SkyManager.Cleanup();
m_SsaoEffect.Cleanup();
Utilities.SafeRelease(s_UnboundedVolumeData);
#if UNITY_EDITOR
SupportedRenderingFeatures.active = SupportedRenderingFeatures.Default;

RenderForward(m_CullResults, camera, renderContext, cmd, true); // Render deferred or forward opaque
RenderForwardOnlyOpaque(m_CullResults, camera, renderContext, cmd);
VolumetricLightingPass(hdCamera, cmd);
RenderLightingDebug(hdCamera, cmd, m_CameraColorBufferRT, m_DebugDisplaySettings);
// If full forward rendering, we did just rendered everything, so we can copy the depth buffer

cmd.SetComputeTextureParam(m_SubsurfaceScatteringCS, m_SubsurfaceScatteringKernel, HDShaderIDs._CameraFilteringBuffer, m_CameraFilteringBufferRT);
// Perform the SSS filtering pass which fills 'm_CameraFilteringBufferRT'.
//
cmd.DispatchCompute(m_SubsurfaceScatteringCS, m_SubsurfaceScatteringKernel, ((int)hdCamera.screenSize.x + 15) / 16, ((int)hdCamera.screenSize.y + 15) / 16, 1);
cmd.SetGlobalTexture(HDShaderIDs._IrradianceSource, m_CameraFilteringBufferRT); // Cannot set a RT on a material

RenderTransparentRenderList(cullResults, camera, renderContext, cmd, passName, Utilities.kRendererConfigurationBakedLighting);
}
}
}
void VolumetricLightingPass(HDCamera hdCamera, CommandBuffer cmd)
{
HomogeneousFog[] fogComponents = Object.FindObjectsOfType(typeof(HomogeneousFog)) as HomogeneousFog[];
HomogeneousFog unboundedFogComponent = null;
foreach (HomogeneousFog fogComponent in fogComponents)
{
if (fogComponent.volumeParameters.IsVolumeUnbounded())
{
unboundedFogComponent = fogComponent;
break;
}
}
if (unboundedFogComponent == null) { return; }
List<VolumeProperties> unboundedVolumeProperties = new List<VolumeProperties>();
unboundedVolumeProperties.Add(unboundedFogComponent.volumeParameters.GetProperties());
// TODO: probably unnecessary to update the buffer every frame.
s_UnboundedVolumeData.SetData<VolumeProperties>(unboundedVolumeProperties);
hdCamera.SetupComputeShader(m_VolumetricLightingCS, cmd);
// TODO: replace strings with nameIDs.
cmd.SetComputeBufferParam( m_VolumetricLightingCS, m_VolumetricLightingKernel, "_UnboundedVolume", s_UnboundedVolumeData);
cmd.SetComputeTextureParam(m_VolumetricLightingCS, m_VolumetricLightingKernel, "_LightingTexture", m_CameraColorBufferRT);
cmd.SetComputeTextureParam(m_VolumetricLightingCS, m_VolumetricLightingKernel, HDShaderIDs._DepthTexture, GetDepthTexture());
// Perform the SSS filtering pass which fills 'm_CameraFilteringBufferRT'.
cmd.DispatchCompute(m_VolumetricLightingCS, m_VolumetricLightingKernel, ((int)hdCamera.screenSize.x + 15) / 16, ((int)hdCamera.screenSize.y + 15) / 16, 1);
}
// Render material that are forward opaque only (like eye), this include unlit material

47
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/HomogeneousFog.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[GenerateHLSL]
public struct VolumeProperties
{
public Vector3 scattering;
public float anisotropy;
public Vector3 extinction;
public float unused;
}
[Serializable]
public class VolumeParameters
{

public bool IsVolumeUnbounded()
{
return bounds.size == Vector3.positiveInfinity;
return bounds.size.x == float.PositiveInfinity &&
bounds.size.y == float.PositiveInfinity &&
bounds.size.z == float.PositiveInfinity;
public Vector3 AbsorptionCoefficient()
public Vector3 GetAbsorptionCoefficient()
return Vector3.Max(ExtinctionCoefficient() - ScatteringCoefficient(), Vector3.zero);
return Vector3.Max(GetExtinctionCoefficient() - GetScatteringCoefficient(), Vector3.zero);
public Vector3 ScatteringCoefficient()
public Vector3 GetScatteringCoefficient()
public Vector3 ExtinctionCoefficient()
public Vector3 GetExtinctionCoefficient()
{
return new Vector3(1.0f / meanFreePath.x, 1.0f / meanFreePath.y, 1.0f / meanFreePath.z);
}

meanFreePath = new Vector3(1.0f / extinction.x, 1.0f / extinction.y, 1.0f / extinction.z);
albedo = new Vector3(scattering.x * meanFreePath.x, scattering.y * meanFreePath.y, scattering.z * meanFreePath.z);
ConstrainParameters();
Constrain();
public void ConstrainParameters()
public void Constrain()
{
bounds.size = Vector3.Max(bounds.size, Vector3.zero);

meanFreePath.z = Mathf.Max(meanFreePath.z, 0.01f);
anisotropy = Mathf.Clamp(anisotropy, -1.0f, 1.0f);
}
public VolumeProperties GetProperties()
{
VolumeProperties properties = new VolumeProperties();
properties.scattering = GetScatteringCoefficient();
properties.anisotropy = anisotropy;
properties.extinction = GetExtinctionCoefficient();
return properties;
}
}

{
public VolumeParameters volumeParameters;
void Awake()
private void Awake()
{
if (volumeParameters == null)
{

{
}
void OnDisable()
private void OnDisable()
{
}
private void Update()
void Update()
private void OnValidate()
volumeParameters.Constrain();
}
void OnDrawGizmos()

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset


type: 3}
subsurfaceScatteringCS: {fileID: 7200000, guid: b06a7993621def248addd55d0fe931b1,
type: 3}
volumetricLightingCS: {fileID: 7200000, guid: 799166e2ee6a4b041bba9e74f6942097,
type: 3}
clearDispatchIndirectShader: {fileID: 7200000, guid: fc1f553acb80a6446a32d33e403d0656,
type: 3}
buildDispatchIndirectShader: {fileID: 7200000, guid: 4eb1b418be7044c40bb5200496c50f14,

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs


instance.deferredShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Deferred.Shader");
instance.screenSpaceAmbientOcclusionShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.Shader");
instance.subsurfaceScatteringCS = UnityEditor.AssetDatabase.LoadAssetAtPath<ComputeShader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/SubsurfaceScattering.compute");
instance.volumetricLightingCS = UnityEditor.AssetDatabase.LoadAssetAtPath<ComputeShader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources/VolumetricLighting.compute");
instance.clearDispatchIndirectShader = UnityEditor.AssetDatabase.LoadAssetAtPath<ComputeShader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/cleardispatchindirect.compute");
instance.buildDispatchIndirectShader = UnityEditor.AssetDatabase.LoadAssetAtPath<ComputeShader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/builddispatchindirect.compute");

public Shader deferredShader;
public Shader screenSpaceAmbientOcclusionShader;
public ComputeShader subsurfaceScatteringCS;
public ComputeShader volumetricLightingCS;
// Lighting tile pass resources
public ComputeShader clearDispatchIndirectShader;

10
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics.meta


fileFormatVersion: 2
guid: 1fe4fc72895e4bb4f90ff44b47e76051
folderAsset: yes
timeCreated: 1503411233
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

38
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/HomogeneousFog.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/HomogeneousFog.cs. Please don't edit by hand.
//
#ifndef HOMOGENEOUSFOG_CS_HLSL
#define HOMOGENEOUSFOG_CS_HLSL
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.VolumeProperties
// PackingRules = Exact
struct VolumeProperties
{
float3 scattering;
float anisotropy;
float3 extinction;
float unused;
};
//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.VolumeProperties
//
float3 GetScattering(VolumeProperties value)
{
return value.scattering;
}
float GetAnisotropy(VolumeProperties value)
{
return value.anisotropy;
}
float3 GetExtinction(VolumeProperties value)
{
return value.extinction;
}
float GetUnused(VolumeProperties value)
{
return value.unused;
}
#endif

10
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/HomogeneousFog.cs.hlsl.meta


fileFormatVersion: 2
guid: af39a96c040c8ec4da47ed13c6455ffe
timeCreated: 1503567986
licenseType: Pro
ShaderImporter:
externalObjects: {}
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

10
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources.meta


fileFormatVersion: 2
guid: 333b470add5766f44a744f476efc19a8
folderAsset: yes
timeCreated: 1503591964
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

53
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources/VolumetricLighting.compute


//--------------------------------------------------------------------------------------------------
// Definitions
//--------------------------------------------------------------------------------------------------
// #pragma enable_d3d11_debug_symbols
#define GROUP_SIZE_1D 16
#define GROUP_SIZE_2D (GROUP_SIZE_1D * GROUP_SIZE_1D)
//--------------------------------------------------------------------------------------------------
// Included headers
//--------------------------------------------------------------------------------------------------
#include "../HomogeneousFog.cs.hlsl"
#include "../../../../Core/ShaderLibrary/Common.hlsl"
#include "../../../../Core/ShaderLibrary/SpaceFillingCurves.hlsl"
#include "../../../ShaderVariables.hlsl"
//--------------------------------------------------------------------------------------------------
// Inputs & outputs
//--------------------------------------------------------------------------------------------------
TEXTURE2D(_DepthTexture); // Z-buffer
RW_TEXTURE2D(float4, _LightingTexture); // Updated texture
// Unity does not support structures inside constant buffers,
// so we are forced to use a structured buffer instead.
StructuredBuffer<VolumeProperties> _UnboundedVolume;
//--------------------------------------------------------------------------------------------------
// Implementation
//--------------------------------------------------------------------------------------------------
#pragma kernel VolumetricLighting
[numthreads(GROUP_SIZE_2D, 1, 1)]
void VolumetricLighting(uint2 groupId : SV_GroupID,
uint groupThreadId : SV_GroupThreadID)
{
// Note: any factor of 64 is a suitable wave size for our algorithm.
uint waveIndex = groupThreadId / 64;
uint laneIndex = groupThreadId % 64;
uint quadIndex = laneIndex / 4;
// Arrange threads in the Morton order to optimally match the memory layout of GCN tiles.
uint mortonCode = groupThreadId;
uint2 localCoord = DecodeMorton2D(mortonCode);
uint2 tileAnchor = groupId * GROUP_SIZE_1D;
uint2 pixelCoord = tileAnchor + localCoord;
// In-place UAV updates do not work on Intel GPUs.
_LightingTexture[pixelCoord] += float4(0.25, 0.25, 0.25, 0);
}

10
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources/VolumetricLighting.compute.meta


fileFormatVersion: 2
guid: 799166e2ee6a4b041bba9e74f6942097
timeCreated: 1503570390
licenseType: Pro
ComputeShaderImporter:
externalObjects: {}
currentAPIMask: 4
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存