Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

[SOLVED] Porting full-screen raymarching to Post Process V2 stack

Discussion in 'Graphics Experimental Previews' started by hvent90, Jan 21, 2019.

  1. hvent90

    hvent90

    Joined:
    Jun 18, 2018
    Posts:
    19
    UPDATE: I GOT IT! Solution posted below, and I compiled my findings into an article.

    Hi, wonderful wizards of the shader world!

    I've seen a few tutorials featuring the use of Raymarching via the older
    OnRenderImage
    function, however that is no longer called in the new stack (what is the correct terminology -- is it SRP? Post Processing V2? HDRP?). The intention is to eventually add depth into the rendering so the raymarched objects can be culled/occluded in object space.

    Anyways, here is my attempt at rendering a simple sphere. The issue here is the sphere is not being drawn until the camera is physically touching the sphere, at which point the entire viewport is drawing the sphere's color.


    Post Process script
    Code (CSharp):
    1.  
    2. using System;
    3. using UnityEngine;
    4. using UnityEngine.Rendering;
    5. using UnityEngine.Rendering.PostProcessing;
    6. [Serializable]
    7. [PostProcess(typeof(DebugRenderer), PostProcessEvent.AfterStack, "Custom/Debug")]
    8. public sealed class Debug : PostProcessEffectSettings
    9. {
    10.     public IntParameter maxIterations = new IntParameter { value = 64 };
    11.     public FloatParameter maxDistance = new FloatParameter { value = 100f };
    12.     public FloatParameter minDistance = new FloatParameter { value = 0.01f };
    13.     public DepthTextureMode GetCameraFlags()
    14.     {
    15.         return DepthTextureMode.Depth; //| DepthTextureMode.DepthNormals;
    16.     }
    17. }
    18. public sealed class DebugRenderer : PostProcessEffectRenderer<Debug>
    19. {
    20.     //public override DepthTextureMode GetCameraFlags()
    21.     //{
    22.     //    return DepthTextureMode.Depth;
    23.     //}
    24.     [SerializeField]
    25.     private Shader _shader;
    26.     public Material _raymarchMaterial
    27.     {
    28.         get
    29.         {
    30.             if (!_raymarchMat && _shader)
    31.             {
    32.                 _raymarchMat = new Material(_shader);
    33.                 _raymarchMat.hideFlags = HideFlags.HideAndDontSave;
    34.             }
    35.             return _raymarchMat;
    36.         }
    37.     }
    38.     private Material _raymarchMat;
    39.     public Camera _camera
    40.     {
    41.         get
    42.         {
    43.             if (!_cam)
    44.             {
    45.                 _cam = Camera.main;
    46.             }
    47.             return _cam;
    48.         }
    49.     }
    50.     private Camera _cam;
    51.     public override void Render(PostProcessRenderContext context)
    52.     {
    53.         if (!_cam)
    54.         {
    55.             _cam = Camera.main;
    56.         }
    57.         var sheet = context.propertySheets.Get(Shader.Find("Hidden/Debug"));
    58.         sheet.properties.SetMatrix("_CamFrustum", FrustumCorners(_cam));
    59.         sheet.properties.SetMatrix("_CamToWorld", _cam.cameraToWorldMatrix);
    60.         sheet.properties.SetVector("_CamWorldSpace", _cam.transform.position);
    61.         sheet.properties.SetInt("_MaxIterations", settings.maxIterations);
    62.         sheet.properties.SetFloat("_MaxDistance", settings.maxDistance);
    63.         sheet.properties.SetFloat("_MinDistance", settings.minDistance);
    64.         context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
    65.     }
    66.     private Matrix4x4 FrustumCorners(Camera cam)
    67.     {
    68.         Transform camtr = cam.transform;
    69.         Vector3[] frustumCorners = new Vector3[4];
    70.         cam.CalculateFrustumCorners(new Rect(0, 0, 1, 1), cam.farClipPlane, cam.stereoActiveEye, frustumCorners);
    71.         var bottomLeft = camtr.TransformVector(frustumCorners[0]);
    72.         var topLeft = camtr.TransformVector(frustumCorners[1]);
    73.         var topRight = camtr.TransformVector(frustumCorners[2]);
    74.         var bottomRight = camtr.TransformVector(frustumCorners[3]);
    75.         Matrix4x4 frustumCornersArray = Matrix4x4.identity;
    76.         frustumCornersArray.SetRow(0, bottomLeft);
    77.         frustumCornersArray.SetRow(1, bottomRight);
    78.         frustumCornersArray.SetRow(2, topLeft);
    79.         frustumCornersArray.SetRow(3, topRight);
    80.         return frustumCornersArray;
    81.     }
    82. }
    83.  
    84.  
    Shader
    Code (Boo):
    1. Shader "Hidden/Debug"
    2. {
    3.  
    4.     SubShader
    5.     {
    6.         Cull Off ZWrite Off ZTest Always
    7.  
    8.         Pass
    9.         {
    10.             HLSLPROGRAM
    11.  
    12.             #pragma target 3.5
    13.  
    14.             #pragma vertex vert
    15.             #pragma fragment frag
    16.  
    17.             //#include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl"
    18.             //#include "HLSLSupport.cginc"
    19.             #include "UnityCG.cginc"
    20.  
    21.             //TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex);
    22.             uniform sampler2D _MainTex;
    23.             uniform sampler2D_float _CameraDepthTexture;
    24.             half4 _MainTex_ST;
    25.             uniform float4 _CamWorldSpace;
    26.             uniform float4x4 _CamFrustum,  _CamToWorld;
    27.             uniform int _MaxIterations;
    28.             uniform float _MaxDistance;
    29.             uniform float _MinDistance;
    30.             float4 _Tint;
    31.  
    32.             uniform float4 _MainTex_TexelSize;
    33.  
    34.             struct AttributesDefault
    35.             {
    36.                 float3 vertex : POSITION;
    37.                 half2 texcoord : TEXCOORD0;
    38.             };
    39.             struct VaryingsDefault
    40.             {
    41.                 float4 pos : SV_POSITION;
    42.                 float2 uv : TEXCOORD0;
    43.                 //float2 uvStereo : TEXCOORD1;
    44.                 float2 uv_depth : TEXCOORD1;
    45.                 float4 interpolatedRay : TEXCOORD2;
    46.             };
    47.  
    48.             float LinearEyeDepth135( float z )
    49.             {
    50.                 return LinearEyeDepth( z );
    51.             }
    52.             // Vertex manipulation
    53.             float2 TransformTriangleVertexToUV(float2 vertex)
    54.             {
    55.                 float2 uv = (vertex + 1.0) * 0.5;
    56.                 return uv;
    57.             }
    58.  
    59.             VaryingsDefault vert(AttributesDefault v  )
    60.             {
    61.                 VaryingsDefault o;
    62.                 v.vertex.z = 0.1;
    63.                 o.pos = float4(v.vertex.xy, 0.0, 1.0);
    64.                 o.uv = TransformTriangleVertexToUV(v.vertex.xy);
    65.                 o.uv_depth = v.texcoord.xy;
    66.                 #if UNITY_UV_STARTS_AT_TOP
    67.                     o.uv = o.uv * float2(1.0, -1.0) + float2(0.0, 1.0);
    68.                 #endif
    69.  
    70.                 //o.uvStereo = TransformStereoScreenSpaceTex(o.uv, 1.0);
    71.                 #if UNITY_UV_STARTS_AT_TOP
    72.                     if (_MainTex_TexelSize.y < 0)
    73.                         o.uv.y = 1 - o.uv.y;
    74.                 #endif
    75.                 int frustumIndex = v.texcoord.x + (2 * o.uv.y);
    76.                 o.interpolatedRay = _CamFrustum[frustumIndex];
    77.                 o.interpolatedRay.w = frustumIndex;
    78.                 return o;
    79.             }
    80.  
    81.             float sdSphere(float3 position, float3 origin, float radius)
    82.             {
    83.                 return distance(position, origin) - radius;
    84.             }
    85.  
    86.             fixed4 raymarching(float3 ro, float3 rd) {
    87.                 fixed4 result = float4(1, 1, 1, 1);
    88.                 float t = 0; // Distance Traveled from ray origin (ro) along the ray direction (rd)
    89.  
    90.                 for (int i = 0; i < _MaxIterations; i++)
    91.                 {
    92.                     if (t > _MaxDistance)
    93.                     {
    94.                         result = float4(rd, 1); // color backround from ray direction for debugging
    95.                         break;
    96.                     }
    97.  
    98.                     float3 p = ro + rd * t;    // This is our current position
    99.                     float d = sdSphere(ro, float3(0, 0, 0), 1); // should be a sphere at (0, 0, 0) with a radius of 1
    100.                     if (d <= _MinDistance) // We have hit something
    101.                     {
    102.                         // shading
    103.                         result = float4(1, 1, 0, 1); // yellow sphere should be drawn at (0, 0, 0)
    104.                         break;
    105.                     }
    106.  
    107.                     t += d;
    108.                 }
    109.  
    110.                 return result;
    111.             }
    112.  
    113.             float4 frag(VaryingsDefault i) : SV_Target
    114.             {
    115.                 float4 wsDir = normalize(i.interpolatedRay);
    116.                 float4 wsPos = _CamWorldSpace;
    117.                 fixed4 result = raymarching(wsPos, wsDir);
    118.                 return result;
    119.             }
    120.  
    121.             ENDHLSL
    122.         }
    123.     }
    124. }
    For reference, I am converting the C# script and shader from Peer Play's tutorial video to the SRP.

    Anyways, thanks for reading, and please let me know if I can provide any more information.

    Cheers!

    *Edit* I think the issue may be in the
    vert
    function as I am not handling
    v.vertex
    and
    o.vertex
    the same as in the video. This clashes with my limited understanding of what is going on in the
    VertDefault
    function found in
    PostProcessing/StdLib.hlsl
     
    Last edited: Jan 23, 2019
  2. hvent90

    hvent90

    Joined:
    Jun 18, 2018
    Posts:
    19
    Last edited: Jan 22, 2019
  3. hvent90

    hvent90

    Joined:
    Jun 18, 2018
    Posts:
    19
    I GOT IT. I FREAKING GOT IT. HERE IS THE WORKING, NOT-GLORIOUS CODE:

    C# script
    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.Rendering;
    4. using UnityEngine.Rendering.PostProcessing;
    5.  
    6. [Serializable]
    7. [PostProcess(typeof(DebugRenderer), PostProcessEvent.AfterStack, "Custom/Debug")]
    8. public sealed class Debug : PostProcessEffectSettings
    9. {
    10.     public IntParameter maxIterations = new IntParameter { value = 64 };
    11.     public FloatParameter maxDistance = new FloatParameter { value = 100f };
    12.     public FloatParameter minDistance = new FloatParameter { value = 0.01f };
    13.  
    14.     public DepthTextureMode GetCameraFlags()
    15.     {
    16.         return DepthTextureMode.Depth; //| DepthTextureMode.DepthNormals;
    17.     }
    18. }
    19.  
    20. public sealed class DebugRenderer : PostProcessEffectRenderer<Debug>
    21. {
    22.     public override void Render(PostProcessRenderContext context)
    23.     {
    24.         Camera _cam = context.camera;
    25.  
    26.         var sheet = context.propertySheets.Get(Shader.Find("Hidden/Debug"));
    27.         sheet.properties.SetMatrix("_CamFrustum", FrustumCorners2(_cam));
    28.         sheet.properties.SetMatrix("_CamToWorld", _cam.cameraToWorldMatrix);
    29.         sheet.properties.SetVector("_CamWorldSpace", _cam.transform.position);
    30.         sheet.properties.SetInt("_MaxIterations", settings.maxIterations);
    31.         sheet.properties.SetFloat("_MaxDistance", settings.maxDistance);
    32.         sheet.properties.SetFloat("_MinDistance", settings.minDistance);
    33.  
    34.         context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
    35.     }
    36.  
    37.     private Matrix4x4 CamFrustum(Camera cam)
    38.     {
    39.         Matrix4x4 frustum = Matrix4x4.identity;
    40.         float fov = Mathf.Tan((cam.fieldOfView * 0.5f) * Mathf.Deg2Rad);
    41.  
    42.         Vector3 goUp = Vector3.up * fov;
    43.         Vector3 goRight = Vector3.right * fov * cam.aspect;
    44.  
    45.         Vector3 TL = (-Vector3.forward - goRight + goUp);
    46.         Vector3 TR = (-Vector3.forward + goRight + goUp);
    47.         Vector3 BR = (-Vector3.forward + goRight - goUp);
    48.         Vector3 BL = (-Vector3.forward - goRight - goUp);
    49.  
    50.         frustum.SetRow(0, TL);
    51.         frustum.SetRow(1, TR);
    52.         frustum.SetRow(2, BR);
    53.         frustum.SetRow(3, BL);
    54.  
    55.         return frustum;
    56.     }
    57.  
    58.     private Matrix4x4 GetFrustumCorners(Camera cam)
    59.     {
    60.         float camFov = cam.fieldOfView;
    61.         float camAspect = cam.aspect;
    62.  
    63.         Matrix4x4 frustumCorners = Matrix4x4.identity;
    64.  
    65.         float fovWHalf = camFov * 0.5f;
    66.  
    67.         float tan_fov = Mathf.Tan(fovWHalf * Mathf.Deg2Rad);
    68.  
    69.         Vector3 toRight = Vector3.right * tan_fov * camAspect;
    70.         Vector3 toTop = Vector3.up * tan_fov;
    71.  
    72.         Vector3 topLeft = (-Vector3.forward - toRight + toTop);
    73.         Vector3 topRight = (-Vector3.forward + toRight + toTop);
    74.         Vector3 bottomRight = (-Vector3.forward + toRight - toTop);
    75.         Vector3 bottomLeft = (-Vector3.forward - toRight - toTop);
    76.  
    77.         frustumCorners.SetRow(0, topLeft);
    78.         frustumCorners.SetRow(1, topRight);
    79.         frustumCorners.SetRow(2, bottomRight);
    80.         frustumCorners.SetRow(3, bottomLeft);
    81.  
    82.         return frustumCorners;
    83.     }
    84.  
    85.     private Matrix4x4 FrustumCorners(Camera cam)
    86.     {
    87.         Transform camtr = cam.transform;
    88.         Vector3[] frustumCorners = new Vector3[4];
    89.         cam.CalculateFrustumCorners(new Rect(0, 0, 1, 1), cam.farClipPlane, cam.stereoActiveEye, frustumCorners);
    90.         var bottomLeft = camtr.TransformVector(frustumCorners[0]);
    91.         var topLeft = camtr.TransformVector(frustumCorners[1]);
    92.         var topRight = camtr.TransformVector(frustumCorners[2]);
    93.         var bottomRight = camtr.TransformVector(frustumCorners[3]);
    94.  
    95.         Matrix4x4 frustumCornersArray = Matrix4x4.identity;
    96.         frustumCornersArray.SetRow(0, bottomLeft);
    97.         frustumCornersArray.SetRow(1, bottomRight);
    98.         frustumCornersArray.SetRow(2, topLeft);
    99.         frustumCornersArray.SetRow(3, topRight);
    100.  
    101.         return frustumCornersArray;
    102.     }
    103.  
    104.     private Matrix4x4 FrustumCorners2(Camera cam)
    105.     {
    106.         Transform camtr = cam.transform;
    107.  
    108.         Vector3[] frustumCorners = new Vector3[4];
    109.         cam.CalculateFrustumCorners(new Rect(0, 0, 1, 1),
    110.          cam.farClipPlane, cam.stereoActiveEye, frustumCorners);
    111.         var bottomLeft = camtr.TransformVector(frustumCorners[1]);
    112.         var topLeft = camtr.TransformVector(frustumCorners[0]);
    113.         var bottomRight = camtr.TransformVector(frustumCorners[2]);
    114.  
    115.         Matrix4x4 frustumVectorsArray = Matrix4x4.identity;
    116.         frustumVectorsArray.SetRow(0, bottomLeft);
    117.         frustumVectorsArray.SetRow(1, bottomLeft + (bottomRight - bottomLeft) * 2);
    118.         frustumVectorsArray.SetRow(2, bottomLeft + (topLeft - bottomLeft) * 2);
    119.  
    120.         return frustumVectorsArray;
    121.     }
    122. }
    Shader
    Code (Boo):
    1. Shader "Hidden/Debug"
    2. {
    3.  
    4.     SubShader
    5.     {
    6.         Cull Off ZWrite Off ZTest Always
    7.  
    8.         Pass
    9.         {
    10.             HLSLPROGRAM
    11.  
    12.             #pragma target 3.5
    13.  
    14.             #pragma vertex vert
    15.             #pragma fragment frag
    16.  
    17.             //#include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl"
    18.             //#include "HLSLSupport.cginc"
    19.             #include "UnityCG.cginc"
    20.  
    21.             //TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex);
    22.             uniform sampler2D _MainTex;
    23.             uniform sampler2D_float _CameraDepthTexture, sampler_CameraDepthTexture;
    24.             half4 _MainTex_ST;
    25.             uniform float4 _CamWorldSpace;
    26.             uniform float4x4 _CamFrustum,  _CamToWorld;
    27.             uniform int _MaxIterations;
    28.             uniform float _MaxDistance;
    29.             uniform float _MinDistance;
    30.             float4 _Tint;
    31.  
    32.             uniform float4 _MainTex_TexelSize;
    33.  
    34.             struct AttributesDefault
    35.             {
    36.                 float3 vertex : POSITION;
    37.                 half2 texcoord : TEXCOORD0;
    38.             };
    39.             struct VaryingsDefault
    40.             {
    41.                 float4 pos : SV_POSITION;
    42.                 float2 uv : TEXCOORD0;
    43.                 float2 uvStereo : TEXCOORD4;
    44.                 //float2 uvStereo : TEXCOORD1;
    45.                 float2 uv_depth : TEXCOORD1;
    46.                 float4 interpolatedRay : TEXCOORD2;
    47.                 float3 wPos : TEXCOORD3;
    48.             };
    49.  
    50.             struct v2f
    51.             {
    52.              float4 vertex : SV_POSITION;
    53.              float2 texcoord : TEXCOORD0;
    54.              float2 texcoordStereo : TEXCOORD1;
    55.              float4 ray : TEXCOORD2;
    56.             };
    57.  
    58.             float LinearEyeDepth135( float z )
    59.             {
    60.                 return LinearEyeDepth( z );
    61.             }
    62.             // Vertex manipulation
    63.             float2 TransformTriangleVertexToUV(float2 vertex)
    64.             {
    65.                 float2 uv = (vertex + 1.0) * 0.5;
    66.                 return uv;
    67.             }
    68.  
    69.             //VaryingsDefault vert(AttributesDefault v  )
    70.             //{
    71.             //    VaryingsDefault o;
    72.             //    v.vertex.z = 0.1;
    73.             //    o.wPos =  mul(UNITY_MATRIX_VP, v.vertex);
    74.             //    o.pos = float4(v.vertex.xy, 0.0, 1.0);
    75.             //    o.uv = TransformTriangleVertexToUV(v.vertex.xy);
    76.             //    o.uv_depth = v.texcoord.xy;
    77.             //    #if UNITY_UV_STARTS_AT_TOP
    78.             //        o.uv = o.uv * float2(1.0, -1.0) + float2(0.0, 1.0);
    79.             //    #endif
    80.        
    81.             //    o.uvStereo = TransformStereoScreenSpaceTex(o.uv, 1.0);
    82.             //    #if UNITY_UV_STARTS_AT_TOP
    83.             //        if (_MainTex_TexelSize.y < 0)
    84.             //            o.uv.y = 1 - o.uv.y;
    85.             //    #endif
    86.             //    //int frustumIndex = v.texcoord.x + (2 * o.uv.y);
    87.             //    //o.interpolatedRay = _CamFrustum[frustumIndex];
    88.             //    //o.interpolatedRay.w = frustumIndex;
    89.  
    90.             //    int index = (o.uv.x / 2) + o.uv.y;
    91.             //    o.interpolatedRay = _CamFrustum[index];
    92.             //    //o.interpolatedRay /= abs(o.interpolatedRay.z);
    93.             //    //o.interpolatedRay = mul(_CamToWorld, o.interpolatedRay);
    94.             //    return o;
    95.             //}
    96.  
    97.             v2f vert(AttributesDefault v  )
    98.             {
    99.                 v2f o;
    100.                 v.vertex.z = 0.1;
    101.                 //o.vertex = mul(UNITY_MATRIX_VP, v.vertex);
    102.                 o.vertex = float4(v.vertex.xy, 0.0, 1.0);
    103.                 o.texcoord = TransformTriangleVertexToUV(v.vertex.xy);
    104.                 //#if UNITY_UV_STARTS_AT_TOP
    105.                 //    o.texcoord = o.texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
    106.                 //#endif
    107.        
    108.                 o.texcoordStereo = TransformStereoScreenSpaceTex(o.texcoord, 1.0);
    109.                 //#if UNITY_UV_STARTS_AT_TOP
    110.                 //    if (_MainTex_TexelSize.y < 0)
    111.                 //        o.texcoord.y = 1 - o.texcoord.y;
    112.                 //#endif
    113.                 //int index = v.texcoord.x + (2 * o.texcoord.y);
    114.                 int index = (o.texcoord.x / 2) + o.texcoord.y;
    115.                 o.ray = _CamFrustum[index];
    116.                 return o;
    117.             }
    118.  
    119.             float sdSphere(float3 position, float3 origin, float radius)
    120.             {
    121.                 return distance(position, origin) - radius;
    122.             }
    123.  
    124.             float sdf_sphere(float3 p, float3 c, float r)
    125.              {
    126.                  return distance(p, c) - r;
    127.              }
    128.  
    129.             fixed4 raymarching(float3 rayOrigin, float3 rayDirection) {
    130.                 fixed4 result = float4(1, 1, 1, 1);
    131.                 float t = 0.01; // Distance Traveled from ray origin (ro) along the ray direction (rd)
    132.  
    133.                 for (int i = 0; i < _MaxIterations; i++)
    134.                 {
    135.                     if (t > _MaxDistance)
    136.                     {
    137.                         result = float4(rayDirection, 1); // color backround from ray direction for debugging
    138.                         break;
    139.                     }
    140.  
    141.                     float3 p = rayOrigin + rayDirection * t;    // This is our current position
    142.                     //float3 p = float3(5, 0, 0) + (float3(1, 0, 0) * t);    // This is our current position
    143.                     //float d = sdSphere(p, float3(1, 0, 0), 2); // should be a sphere at (0, 0, 0) with a radius of 1
    144.                     float d = sdf_sphere(p, float3(0, 0, 0), 1);
    145.                     if (d <= _MinDistance) // We have hit something
    146.                     {
    147.                         // shading
    148.                         result = float4(1, 1, 1, 1); // yellow sphere should be drawn at (0, 0, 0)
    149.                         break;
    150.                     }
    151.  
    152.                     //t += max(0.01, 0.02 * 2);
    153.                     t += d;
    154.                 }
    155.  
    156.                 return result;
    157.             }
    158.  
    159.             fixed4 rm (float3 ro, float3 rd) {
    160.                 fixed4 result = float4(0, 0, 0, 1);
    161.                 float t = 0;
    162.  
    163.                 for (int i = 0; i < 100; i++) {
    164.                     float3 p = ro + rd * t;
    165.                     float d = sdf_sphere(p, float3(0, 0, 0), 0.8);
    166.                     if (d <= _MinDistance) // We have hit something
    167.                     {
    168.                         // shading
    169.                         result = float4(1, 1, 0, 1); // yellow sphere should be drawn at (0, 0, 0)
    170.                         break;
    171.                     }
    172.  
    173.                     t += d;
    174.                 }
    175.  
    176.                 return result;
    177.             }
    178.  
    179.             float4 frag(v2f i) : SV_Target
    180.             {
    181.                 //float rawDepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(i.uv ));
    182.                 //float dpth = Linear01Depth(rawDepth);
    183.  
    184.                 //float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.uvStereo);
    185.                 //depth = Linear01Depth(depth);
    186.  
    187.                 //float rawDepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uvStereo);
    188.                 //float dpth = Linear01Depth(rawDepth);
    189.  
    190.                 ////float4 wsDir = normalize(i.interpolatedRay);
    191.                 //float3 wsDir = normalize(i.interpolatedRay);
    192.                 //float4 wsPos = _CamWorldSpace;
    193.                 ////fixed4 result = raymarching(_CamWorldSpace, normalize(i.interpolatedRay.xyz));
    194.                 //fixed4 result = rm(_CamWorldSpace, normalize(i.interpolatedRay.xyz));
    195.                 //return result;
    196.  
    197.                 //float dpth = Linear01Depth(rawDepth);
    198.                 //return raymarching(_WorldSpaceCameraPos, normalize(i.interpolatedRay));
    199.  
    200.                 return raymarching(_CamWorldSpace, normalize(i.ray));
    201.  
    202.                 //half4 sceneColor = tex2D(_MainTex, UnityStereoTransformScreenSpaceTex(i.uv));
    203.                 //// Reconstruct world space position & direction
    204.                 //// towards this screen pixel.
    205.                 //float rawDepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(i.uv ));
    206.                 //float dpth = Linear01Depth(rawDepth);
    207.                 //float4 wsDir = dpth * i.interpolatedRay;
    208.                 //float4 wsPos = _CamWorldSpace + wsDir;
    209.  
    210.                 //return wsPos;
    211.                 //return raymarching(wsPos, wsDir);
    212.             }
    213.  
    214.             ENDHLSL
    215.         }
    216.     }
    217. }
     
    Tiz010 likes this.
  4. Roobubba

    Roobubba

    Joined:
    Nov 5, 2015
    Posts:
    29
    Have you got an example project with this in? I cannot get this to work in either the LWRP or HDRP in Unity 2019.2.0f1 or 2019.3.0b3 with the HDRP 6.9.1 or 7.0.1.

    I did get an image effect raymarching shader working with the old render system following the same tutorials as you linked, and I've read everything I can from all the links you posted, but haven't been able to get any raymarching rendering working at all under HDRP. I wonder if it's a project setting or HDRP Asset setting maybe?
    Tried everything I can think of but nothing seems to be working so far :(
     
  5. andybak

    andybak

    Joined:
    Jan 14, 2017
    Posts:
    569
    Sadly PPv2 is for 2018 only. The new Volume has replaced it and there's currently not a simple way to do custom PP with that. (although blitting to a quad that's parented to the camera would work)

    However - we should see a custom PP solution in the next release of HDRP which is already available on Github master and should be released to the package manager any day now.
     
    Roobubba likes this.
  6. naive_magic

    naive_magic

    Joined:
    Jun 5, 2020
    Posts:
    7
    Was there a resolution to this problem? Latest HDRP in Unity 2020 and custom raymarching shaders