浏览代码

HDRenderLoop: First draft not working of depth pixel offset

/main
Sebastien Lagarde 8 年前
当前提交
39c9f7ed
共有 12 个文件被更改,包括 38 次插入11 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/Resources/DebugViewMaterialGBuffer.shader
  2. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Resources/Deferred.shader
  3. 21
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl
  4. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Builtin/BuiltinData.cs
  5. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Builtin/BuiltinData.cs.hlsl
  6. 3
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Builtin/BuiltinData.hlsl
  7. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitDepthPass.hlsl
  8. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitMetaPass.hlsl
  9. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitSharePass.hlsl
  10. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitVelocityPass.hlsl
  11. 5
      Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl
  12. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl

2
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/Resources/DebugViewMaterialGBuffer.shader


float4 Frag(Varyings input) : SV_Target
{
float4 unPositionSS = input.positionCS; // as input we have the vpos
float4 unPositionSS = input.positionCS; // input.positionCS is SV_Position
Coordinate coord = GetCoordinate(unPositionSS.xy, _ScreenSize.zw);
float depth = LOAD_TEXTURE2D(_CameraDepthTexture, coord.unPositionSS).x;

2
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Resources/Deferred.shader


float4 Frag(Varyings input) : SV_Target
{
float4 unPositionSS = input.positionCS; // as input we have the vpos
float4 unPositionSS = input.positionCS; // input.positionCS is SV_Position
Coordinate coord = GetCoordinate(unPositionSS.xy, _ScreenSize.zw);
// No need to manage inverse depth, this is handled by the projection matrix

21
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl


struct FragInput
{
float4 unPositionSS; // This is the position return by VPOS (That is name positionCS in PackedVarying), only xy is use
// Contain value return by SV_POSITION (That is name positionCS in PackedVarying).
// xy: unormalized screen position at pixel center, z: device depth, w: depth in view space
float4 unPositionSS; // In case depth offset is use, positionWS.w is equal to depth offset
float3 positionWS;
float2 texCoord0;
float2 texCoord1;

float4 vertexColor;
// For velocity
// Note: Z component is not use
float4 positionCS; // This is the clip spae position. Warning, do not confuse with the value of positionCS in PackedVarying which is VPOS and store in unPositionSS
// CAUTION: Only use with velocity currently, null else
// Note: Z component is not use currently
// This is the clip space position. Warning, do not confuse with the value of positionCS in PackedVarying which is SV_POSITION and store in unPositionSS
float4 positionCS;
// end velocity specific
float applyDepthOffsetToFragInput(float depthOffset, inout FragInput fragInput)
{
fragInput.unPositionSS.w += depthOffset;
fragInput.positionCS.w += depthOffset;
fragInput.previousPositionCS.w += depthOffset;
return
}
void GetVaryingsDataDebug(uint paramId, FragInput input, inout float3 result, inout bool needLinearToSRGB)
{

4
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Builtin/BuiltinData.cs


public Vector2 distortion;
[SurfaceDataAttributes("Distortion Blur")]
public float distortionBlur; // Define the color buffer mipmap level to use
// Depth
[SurfaceDataAttributes("Depth Offset")]
public float depthOffset; // define the depth in unity unit to add in Z forward direction
};
//-----------------------------------------------------------------------------

2
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Builtin/BuiltinData.cs.hlsl


#define DEBUGVIEW_BUILTIN_BUILTINDATA_VELOCITY (104)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION (105)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION_BLUR (106)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_DEPTH_OFFSET (107)
//
// UnityEngine.Experimental.ScriptableRenderLoop.Builtin.LighTransportData: static fields

float2 velocity;
float2 distortion;
float distortionBlur;
float depthOffset;
};
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.Builtin.LighTransportData

3
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Builtin/BuiltinData.hlsl


case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION_BLUR:
result = builtinData.distortionBlur.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DEPTH_OFFSET:
result = builtinData.depthOffset.xxx * 10.0; // * 10 assuming 1 unity unity is 1m
break;
}
}

2
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitDepthPass.hlsl


FragInput output;
ZERO_INITIALIZE(FragInput, output);
output.unPositionSS = input.positionCS; // as input we have the vpos
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position
#if NEED_TANGENT_TO_WORLD
output.positionWS.xyz = input.interpolators[0].xyz;

2
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitMetaPass.hlsl


FragInput output;
ZERO_INITIALIZE(FragInput, output);
output.unPositionSS = input.positionCS; // as input we have the vpos
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position
output.texCoord0 = input.interpolators[0].xy;
output.texCoord1 = input.interpolators[0].zw;

2
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitSharePass.hlsl


FragInput output;
ZERO_INITIALIZE(FragInput, output);
output.unPositionSS = input.positionCS; // as input we have the vpos
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position
output.positionWS.xyz = input.interpolators[0].xyz;
output.tangentToWorld[0] = input.interpolators[1].xyz;
output.tangentToWorld[1] = input.interpolators[2].xyz;

2
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitVelocityPass.hlsl


FragInput output;
ZERO_INITIALIZE(FragInput, output);
output.unPositionSS = input.positionCS; // as input we have the vpos
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position
output.positionCS = float4(input.interpolators[0].xy, 0.0, input.interpolators[0].z);
output.previousPositionCS = float4(input.interpolators[1].xy, 0.0, input.interpolators[1].z);

5
Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl


return glstate_matrix_modelview0;
}
float4x4 GetViewToProjectionMatrix()
{
//... return glstate_matrix_modelview0;
}
float3 TransformWorldToView(float3 positionWS)
{
return mul(GetWorldToViewMatrix(), float4(positionWS, 1.0)).xyz;

2
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


// This function is use to provide an easy way to sample into a screen texture, either from a pixel or a compute shaders.
// This allow to easily share code.
// If a compute shader call this function unPositionSS is an integer usually calculate like: uint2 unPositionSS = groupId.xy * BLOCK_SIZE + groupThreadId.xy
// else it is current unormalized screen coordinate like return by VPOS
// else it is current unormalized screen coordinate like return by SV_Position
Coordinate GetCoordinate(float2 unPositionSS, float2 invScreenSize)
{
Coordinate coord;

正在加载...
取消
保存