浏览代码

HDRenderLoop: Fixed issue with velocity pass + fix shader warning

- GBuffer velocity can't work as we miss prevPosition Attribute in
GBuffer pass
- #define can't be include in C# from another file...
/main
Sebastien Lagarde 8 年前
当前提交
7443a077
共有 6 个文件被更改,包括 42 次插入28 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset.meta
  2. 11
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  3. 39
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLitDefault.shader
  4. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitVelocityPass.hlsl
  5. 7
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl
  6. 3
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderConfig.cs

2
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset.meta


fileFormatVersion: 2
guid: 2400b74f5ce370c4481e5dc417d03703
timeCreated: 1478740672
timeCreated: 1478744315
licenseType: Pro
NativeFormatImporter:
userData:

11
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


// Must be in sync with ShaderConfig.cs
//#define VELOCITY_IN_GBUFFER
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using System.Collections.Generic;

// In forward we still name the buffer as if they were gbuffer, it doesn't matter
for (int gbufferIndex = 0; gbufferIndex < m_BuiltinRenderLoop.GetGBufferCount(); ++gbufferIndex)
{
m_gbufferManager.SetBufferDescription(m_gbufferManager.gbufferCount + gbufferIndex, "_CameraGBufferTexture" + gbufferIndex, m_BuiltinRenderLoop.RTFormat[gbufferIndex], m_BuiltinRenderLoop.RTReadWrite[gbufferIndex]);
int textureIndex = m_gbufferManager.gbufferCount + gbufferIndex;
m_gbufferManager.SetBufferDescription(textureIndex, "_CameraGBufferTexture" + textureIndex, m_BuiltinRenderLoop.RTFormat[gbufferIndex], m_BuiltinRenderLoop.RTReadWrite[gbufferIndex]);
// Caution velocity texture name must match with Macro in Material.hlsl
s_VelocityBuffer = Shader.PropertyToID("_VelocityTexture");
#if VELOCITY_IN_GBUFFER
m_gbufferManager.SetBufferDescription(m_gbufferManager.gbufferCount, "_VelocityTexture", m_BuiltinRenderLoop.GetVelocityBufferFormat(), m_BuiltinRenderLoop.GetVelocityBufferReadWrite());

// but when they are forward they should render a second time here in velocity pass... Maybe we should enable MRT during forward pass ?
// TODO: implement MRT velocity buffer as an option in case of forward
// Render as late as possible to benefit from an up to date depth buffer (TODO: could use equal depth test ?)
#if VELOCITY_IN_GBUFFER
#if VELOCITY_IN_GBUFFER
#endif
#endif
RenderVelocity(cullResults, camera, renderLoop);
FinalPass(renderLoop);

39
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLitDefault.shader


Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
LOD 300
// ------------------------------------------------------------------
// Deferred pass
Pass
Pass
{
Name "GBuffer" // Name is not used
Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index

ENDHLSL
}
// ------------------------------------------------------------------
// Debug pass
Pass
{
Name "Debug"

ENDHLSL
}
// ------------------------------------------------------------------
// ------------------------------------------------------------------
Pass
{
Name "META"

ENDHLSL
}
// ------------------------------------------------------------------
// Depth only
// ------------------------------------------------------------------
Pass
{
Name "Motion Vectors"
Tags{ "LightMode" = "MotionVectors" } // Caution, this need to be call like this to setup the correct parameters by C++ (legacy Unity)
Cull[_CullMode]
ZTest LEqual
ZWrite Off // TODO: Test Z equal here.
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#define SHADERPASS SHADERPASS_VELOCITY
#define LAYERED_LIT_SHADER
#include "../../Material/Material.hlsl"
#include "../Lit/LitData.hlsl"
#include "../Lit/LitVelocityPass.hlsl"
#include "../../ShaderPass/ShaderPassVelocity.hlsl"
ENDHLSL
}
Pass
{
Name "ShadowCaster"

ENDHLSL
}
// ------------------------------------------------------------------
// forward pass
Pass
{
Name "Forward" // Name is not used

8
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitVelocityPass.hlsl


{
PackedVaryings output;
output.positionCS = input.positionCS;
output.interpolators[0].xyz = float4(input.transferPositionCS.xyw, 0.0);
output.interpolators[1].xyz = float4(input.transferPreviousPositionCS.xyw, 0.0);
output.interpolators[0] = float4(input.transferPositionCS.xyw, 0.0);
output.interpolators[1] = float4(input.transferPreviousPositionCS.xyw, 0.0);
#if NEED_TANGENT_TO_WORLD
output.interpolators[0].w = input.texCoord0.x;

output.positionCS = TransformWorldToHClip(positionWS);
// TODO: Clean this code, put in function ?
output.transferPositionCS = mul(_NonJitteredVP, mul(unity_ObjectToWorld, input.positionOS));
output.transferPreviousPositionCS = mul(_PreviousVP, mul(_PreviousM, _HasLastPositionData ? float4(input.previousPositionOS, 1.0) : input.positionOS));
output.transferPositionCS = mul(_NonJitteredVP, mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)));
output.transferPreviousPositionCS = mul(_PreviousVP, mul(_PreviousM, _HasLastPositionData ? float4(input.previousPositionOS, 1.0) : float4(input.positionOS, 1.0)));
#if NEED_TEXCOORD0
output.texCoord0 = input.uv0;

7
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl


#endif // #ifdef GBUFFERMATERIAL_COUNT
// Decode velocity need to be accessible in both forward and deferred
#ifdef VELOCITY_IN_GBUFFER
#define DECODE_VELOCITY_BUFFER(NAME) DecodeVelocity(GBUFFER_VELOCITY_NAME(NAME))
#else
#define DECODE_VELOCITY_BUFFER(NAME) DecodeVelocity(GBUFFER_VELOCITY_NAME(NAME))
#endif
#endif // UNITY_MATERIAL_INCLUDED

3
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderConfig.cs


// #define DIFFUSE_LAMBERT_BRDF
// #define USE_BSDF_PRE_LAMBDAV
// Caution: If you change one of the define below you need to regenerate the hlsl code (Push Generate Shader Includes)
// Note: C# define can't be reuse in another C# file and ideally we would like that these define are present both on C# and HLSL side... How to do that ?
// For now sync by hand within HDRenderLoop.cs file and this one
// TODO: Currently it is not yet possible to use this feature, we need to provide previousPositionCS to the vertex shader as part of Attribute for GBuffer pass
//#define VELOCITY_IN_GBUFFER
正在加载...
取消
保存