赞
踩
float depth = LoadCameraDepth ( varyings . positionCS . xy ) ; PositionInputs posInput = GetPositionInput ( varyings . positionCS . xy , _ScreenSize . zw , depth , UNITY_MATRIX_I_VP , UNITY_MATRIX_V ) ;
-
-
-
- posInput
-
- .
-
- positionSS
-
- =
-
-
-
- uint2
-
- (
-
- positionSS
-
- )
-
- ;
-
-
-
-
- // The PositionInputs struct allow you to retrieve a lot of useful information for your fullScreenShader:
-
-
-
-
- // struct PositionInputs
-
-
-
-
- // {
-
-
-
-
- // float3 positionWS; // World space position (could be camera-relative)
-
-
-
-
- // float2 positionNDC; // Normalized screen coordinates within the viewport : [0, 1) (with the half-pixel offset)
-
-
-
-
- // uint2 positionSS; // Screen space pixel coordinates : [0, NumPixels)
-
-
-
-
- // uint2 tileCoord; // Screen tile coordinates : [0, NumTiles)
-
-
-
-
- // float deviceDepth; // Depth from the depth buffer : [0, 1] (typically reversed)
-
-
-
-
- // float linearDepth; // View space Z coordinate : [Near, Far]
-
-
-
-
- // };
-
-
-
-
- float4
-
- color
-
- =
-
-
-
- float4
-
- (
-
- 0.0
-
- ,
-
-
-
- 0.0
-
- ,
-
-
-
- 0.0
-
- ,
-
-
-
- 0.0
-
- )
-
- ;
-
-
-
-
-
- // Load the camera color buffer at the mip 0 if we're not at the before rendering injection point
-
-
-
- if
-
-
-
- (
-
- _CustomPassInjectionPoint
-
- !=
-
- CUSTOMPASSINJECTIONPOINT_BEFORE_RENDERING
-
- )
-
-
- color
-
- =
-
-
-
- float4
-
- (
-
- CustomPassLoadCameraColor
-
- (
-
- varyings
-
- .
-
- positionCS
-
- .
-
- xy
-
- ,
-
-
-
- 0
-
- )
-
- ,
-
-
-
- 1
-
- )
-
- ;
-
-
-
- // get color method 1
-
-
- finalColor
-
- =
-
- color
-
- ;
-
-
-
-
-
-
-
- // get color method 2
-
-
-
-
- // Load the camera color buffer at the mip 0 if we're not at the before rendering injection point
-
-
-
-
- if
-
-
-
- (
-
- _CustomPassInjectionPoint
-
- !=
-
- CUSTOMPASSINJECTIONPOINT_BEFORE_RENDERING
-
- )
-
-
- color
-
- =
-
-
-
- float4
-
- (
-
- CustomPassSampleCameraColor
-
- (
-
- varyings
-
- .
-
- positionCS
-
- .
-
- xy
-
- *
-
- _ScreenSize
-
- .
-
- zw
-
- ,
-
-
-
- 0
-
- )
-
- ,
-
-
-
- 1
-
- )
-
- ;
-
-
- finalColor
-
- =
-
- color
-
- ;
-
- //finalColor = color;
-
-
-
-
-
- // get device depth method 1
-
-
- deviceDepth
-
- =
-
- depth
-
- ;
-
-
-
-
- // get device depth method 2
-
-
- deviceDepth
-
- =
-
- posInput
-
- .
-
- deviceDepth
-
- ;
-
-
-
-
- // get device depth method 3
-
-
- deviceDepth
-
- =
-
-
-
- SampleCameraDepth
-
- (
-
- varyings
-
- .
-
- positionCS
-
- .
-
- xy
-
- *
-
- _ScreenSize
-
- .
-
- zw
-
- )
-
- ;
-
-
-
-
- // Incorrect result
-
-
-
-
- float
-
-
-
- SampleCameraDepthSK
-
- (
-
- float2
-
- uv
-
- )
-
-
-
-
- {
-
-
-
-
- return
-
-
-
- SAMPLE_TEXTURE2D_X_LOD
-
- (
-
- _CameraDepthTexture
-
- ,
-
- sampler_CameraDepthTexture
-
- ,
-
- uv
-
- *
-
- _RTHandleScaleHistory
-
- .
-
- xy
-
- ,
-
-
-
- 0
-
- )
-
- .
-
- r
-
- ;
-
-
-
-
- }
-
-
-
-
- // get device depth method 4 (Incorrect result)
-
-
- deviceDepth
-
- =
-
-
-
- SampleCameraDepthSK
-
- (
-
- varyings
-
- .
-
- positionCS
-
- .
-
- xy
-
- *
-
- _ScreenSize
-
- .
-
- zw
-
- )
-
- ;
-
-
-
-
- float
-
-
-
- SampleCameraDepth
-
- (
-
- float2
-
- uv
-
- )
-
-
-
-
- {
-
-
-
-
- return
-
-
-
- LoadCameraDepth
-
- (
-
- uint2
-
- (
-
- uv
-
- *
-
- _ScreenSize
-
- .
-
- xy
-
- )
-
- )
-
- ;
-
-
-
-
- }
-
-
-
-
- // Note: To sample camera depth in HDRP we provide these utils functions because the way we store the depth mips can change
-
-
-
-
- // Currently it's an atlas and it's layout can be found at ComputePackedMipChainInfo in HDUtils.cs
-
-
-
-
- float
-
-
-
- LoadCameraDepth
-
- (
-
- uint2
-
- pixelCoords
-
- )
-
-
-
-
- {
-
-
-
-
- return
-
-
-
- LOAD_TEXTURE2D_X_LOD
-
- (
-
- _CameraDepthTexture
-
- ,
-
- pixelCoords
-
- ,
-
-
-
- 0
-
- )
-
- .
-
- r
-
- ;
-
-
-
-
- }
-
-
-
-
- // We pack all MIP levels into the top MIP level to avoid the Pow2 MIP chain restriction.
-
-
-
-
- // We compute the required size iteratively.
-
-
-
-
- // This function is NOT fast, but it is illustrative, and can be optimized later.
-
-
-
-
- public
-
-
-
- void
-
-
-
- ComputePackedMipChainInfo
-
- (
-
- Vector2Int
-
- viewportSize
-
- )
-
float depth = LoadCameraDepth ( varyings . positionCS . xy ) ; PositionInputs posInput = GetPositionInput ( varyings . positionCS . xy , _ScreenSize . zw , depth , UNITY_MATRIX_I_VP , UNITY_MATRIX_V ) ; float linearDepth = posInput . linearDepth ; `
float depth = LoadCameraDepth ( varyings . positionCS . xy ) ; PositionInputs posInput = GetPositionInput ( varyings . positionCS . xy , _ScreenSize . zw , depth , UNITY_MATRIX_I_VP , UNITY_MATRIX_V ) ; float3 positionWS = posInput . positionWS ; positionWS = GetAbsolutePositionWS ( positionWS ) ;
-
-
-
- // This function always return the absolute position in WS
-
-
-
-
- float3
-
-
-
- GetAbsolutePositionWS
-
- (
-
- float3
-
- positionRWS
-
- )
-
-
-
-
- {
-
-
-
-
- #
-
- if
-
- (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
-
-
- positionRWS
-
- +=
-
- _WorldSpaceCameraPos
-
- ;
-
-
-
-
- #
-
- endif
-
-
-
-
- return
-
- positionRWS
-
- ;
-
-
-
-
- }
-
-
-
-
- NormalData
-
- normalData
-
- ;
-
-
-
-
- // get world normal method 1
-
-
-
-
- DecodeFromNormalBuffer
-
- (
-
- posInput
-
- .
-
- positionSS
-
- ,
-
- normalData
-
- )
-
- ;
-
-
-
-
- float3
-
- normal
-
- =
-
- normalData
-
- .
-
- normalWS
-
- ;
-
-
-
-
- #include
-
- "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl"
-
-
-
-
- SAMPLER
-
- (
-
- sampler_NormalBufferTexture
-
- )
-
- ;
-
-
-
-
- void
-
-
-
- DecodeFromNormalBufferNDC
-
- (
-
- float2
-
- positionNDC
-
- ,
-
-
-
- out
-
-
-
- NormalData
-
- normalData
-
- )
-
-
-
-
- {
-
-
-
-
- float4
-
- normalBuffer
-
- =
-
-
-
- SAMPLE_TEXTURE2D_X
-
- (
-
- _NormalBufferTexture
-
- ,
-
- sampler_NormalBufferTexture
-
- ,
-
- positionNDC
-
- )
-
- ;
-
-
-
-
- DecodeFromNormalBuffer
-
- (
-
- normalBuffer
-
- ,
-
- positionNDC
-
- ,
-
- normalData
-
- )
-
- ;
-
-
-
-
- }
-
-
-
-
- NormalData
-
- normalData
-
- ;
-
-
-
-
- // get world normal method 2
-
-
-
-
- DecodeFromNormalBufferNDC
-
- (
-
- posInput
-
- .
-
- positionNDC
-
- ,
-
- normalData
-
- )
-
- ;
-
-
-
-
- float3
-
- normal
-
- =
-
- normalData
-
- .
-
- normalWS
-
- ;
-
-
-
-
- // get positionNDC[0, 1)
-
-
-
-
- float2
-
- positionNDC
-
- =
-
- posInput
-
- .
-
- positionNDC
-
- ;
-
-
- finalColor
-
- =
-
-
-
- float4
-
- (
-
- positionNDC
-
- ,
-
- 0
-
- ,
-
- 1
-
- )
-
- ;
-
float4 positionCS = ComputeClipSpacePosition ( posInput . positionNDC , posInput . deviceDepth ) ;
-
-
-
- // get UNITY_MATRIX_I_VP
-
-
-
-
- if
-
- (
-
- posInput
-
- .
-
- positionNDC
-
- .
-
- x
-
- <
-
-
-
- 0.5
-
-
-
- &&
-
- posInput
-
- .
-
- positionNDC
-
- .
-
- y
-
- <
-
-
-
- 0.5
-
- )
-
-
- finalColor
-
- =
-
- UNITY_MATRIX_I_VP
-
- [
-
- 0
-
- ]
-
- ;
-
-
-
-
-
- if
-
- (
-
- posInput
-
- .
-
- positionNDC
-
- .
-
- x
-
- >
-
-
-
- 0.5
-
-
-
- &&
-
- posInput
-
- .
-
- positionNDC
-
- .
-
- y
-
- <
-
-
-
- 0.5
-
- )
-
-
- finalColor
-
- =
-
- UNITY_MATRIX_I_VP
-
- [
-
- 1
-
- ]
-
- ;
-
-
-
-
-
- if
-
- (
-
- posInput
-
- .
-
- positionNDC
-
- .
-
- x
-
- <
-
-
-
- 0.5
-
-
-
- &&
-
- posInput
-
- .
-
- positionNDC
-
- .
-
- y
-
- >
-
-
-
- 0.5
-
- )
-
-
- finalColor
-
- =
-
- UNITY_MATRIX_I_VP
-
- [
-
- 2
-
- ]
-
- ;
-
-
-
-
-
- if
-
- (
-
- posInput
-
- .
-
- positionNDC
-
- .
-
- x
-
- >
-
-
-
- 0.5
-
-
-
- &&
-
- posInput
-
- .
-
- positionNDC
-
- .
-
- y
-
- >
-
-
-
- 0.5
-
- )
-
-
- finalColor
-
- =
-
- UNITY_MATRIX_I_VP
-
- [
-
- 3
-
- ]
-
- ;
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。