浏览代码

Ray marching WIP

/sample_game
Evgenii Golubev 7 年前
当前提交
ad1c0846
共有 2 个文件被更改,包括 38 次插入9 次删除
  1. 15
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 32
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources/VolumetricLighting.compute

15
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


m_DebugDisplaySettings.RegisterDebug();
m_DebugFullScreenTempRT = HDShaderIDs._DebugFullScreenTexture;
m_VolumetricLightingKernel = m_VolumetricLightingCS.FindKernel("VolumetricLighting");
if (asset.tileSettings.enableClustered)
{
Debug.Assert(asset.tileSettings.enableTileAndCluster);
m_VolumetricLightingKernel = m_VolumetricLightingCS.FindKernel("VolumetricLightingClustered");
}
else
{
m_VolumetricLightingKernel = m_VolumetricLightingCS.FindKernel("VolumetricLightingAllLights");
}
s_UnboundedVolumeData = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(VolumeProperties)));
}

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

// Render all type of transparent forward (unlit, lit, complex (hair...)) to keep the sorting between transparent objects.
RenderForward(m_CullResults, camera, renderContext, cmd, false);
// Render fog.
VolumetricLightingPass(hdCamera, cmd);
PushFullScreenDebugTexture(cmd, m_CameraColorBuffer, camera, renderContext, FullScreenDebugMode.NanTracker);

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


// Definitions
//--------------------------------------------------------------------------------------------------
// #pragma enable_d3d11_debug_symbols
#pragma kernel VolumetricLightingAllLights VolumetricLighting=VolumetricLightingAllLights LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingClustered VolumetricLighting=VolumetricLightingClustered LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma enable_d3d11_debug_symbols
#define GROUP_SIZE_1D 16
#define GROUP_SIZE_2D (GROUP_SIZE_1D * GROUP_SIZE_1D)

//--------------------------------------------------------------------------------------------------
#include "../HomogeneousFog.cs.hlsl"
#include "../HomogeneousFog.cs.hlsl"
#define UNITY_MATERIAL_LIT // Need to be defined before including Material.hlsl
#include "../../../Lighting/Lighting.hlsl" // This includes Material.hlsl
//--------------------------------------------------------------------------------------------------
// Inputs & outputs

// Implementation
//--------------------------------------------------------------------------------------------------
#pragma kernel VolumetricLighting
struct Ray
{
float3 originWS;
float3 directionWS; // Not normalized
float maxLength;
};
// Integrates the volume along the ray to
float3 IntegrateVolume() {return 0;}
[numthreads(GROUP_SIZE_2D, 1, 1)]
void VolumetricLighting(uint2 groupId : SV_GroupID,

uint2 pixelCoord = tileAnchor + localCoord;
PositionInputs posInput = GetPositionInput(pixelCoord, _ScreenSize.zw);
UpdatePositionInput(LOAD_TEXTURE2D(_DepthTexture, pixelCoord).r, _InvViewProjMatrix, _ViewProjMatrix, posInput);
float z = LOAD_TEXTURE2D(_DepthTexture, pixelCoord).r;
float t = length(ComputeViewSpacePosition(posInput.positionSS, z, _InvProjMatrix));
Ray ray;
float3 transmittance = Transmittance(OpticalDepthHomogeneous(_UnboundedVolume[0].extinction, t));
// Note: the camera ray does not start on the the near (image) plane.
// While this is not correct (strictly speaking), the introduced error is small.
ray.originWS = GetCurrentViewPosition();
ray.directionWS = posInput.positionWS - ray.originWS;
ray.maxLength = length(ray.directionWS);
float3 transmittance = Transmittance(OpticalDepthHomogeneous(_UnboundedVolume[0].extinction, ray.maxLength));
// In-place UAV updates do not work on Intel GPUs.
_LightingTexture[pixelCoord] = float4(transmittance * _LightingTexture[pixelCoord].rgb, _LightingTexture[pixelCoord].a);
正在加载...
取消
保存