Search Unity

Reflection Probe Depth

Discussion in 'General Graphics' started by cabbages, Jan 6, 2022.

  1. cabbages

    cabbages

    Joined:
    Nov 6, 2019
    Posts:
    1
    I currently simulating a skybox on the inside of four inverted planes.

    My goal is to render a depth texture similar to one automatically made with Unity's built in Camera, but on the render probe. I want to recreate both fog and FoV post processing effects with this.


    Here are pictures for people to wrap their heads around what my current state is.

    I am trying to create a depth buffer from the reflection probe the same way that the Unity camera automatically makes one.

    The shader I have on the planes is so:

    Code (CSharp):
    1. Shader "Custom/ReflectionDisplay"{
    2. Properties{
    3. [NoScaleOffset] _IBL ("IBL cube map", Cube) = "black" {}
    4. }

    5. SubShader{
    6. Tags { "LightMode"="ForwardBase" }
    7. Cull Back


    8. Pass{
    9. CGPROGRAM
    10. #pragma vertex vert
    11. #pragma fragment frag
    12. #include "UnityCG.cginc"
    13. #include "Lighting.cginc"
    14. #define SPECULAR_MIP_STEPS 4
    15. sampler2D _CameraDepthTexture;
    16. samplerCUBE _IBL;
    17. float3 _probePosition;

    18. struct appdata{
    19. float4 planePosition : POSITION;
    20. float3 normal : NORMAL;
    21. float2 uv : TEXCOORD0;
    22. };

    23. struct v2f{
    24. float2 uv : TEXCOORD0;
    25. float4 planePosition : SV_POSITION;
    26. float3 normal : TEXCOORD1;
    27. float3 worldPlanePos : TEXCOORD2;
    28. };


    29. v2f vert (appdata v){
    30. v2f o;
    31. o.normal = UnityObjectToWorldNormal(v.normal);
    32. o.planePosition = UnityObjectToClipPos(v.planePosition);
    33. o.uv = v.uv;
    34. o.worldPlanePos = mul(unity_ObjectToWorld,v.planePosition);
    35. return o;
    36. }

    37. fixed4 frag (v2f i) : SV_Target{
    38. float mip = 0;
    39. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.worldPlanePos);
    40. float3 indirectSpecular = texCUBElod(_IBL, float4(-viewDirection,mip));
    41. float3 color = indirectSpecular;
    42. return float4(color,1);
    43. }
    44. ENDCG
    45. }
    46. }
    47. }
    I also have this script on a parent which all the planes are attached:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. [ExecuteInEditMode]
    5. public class ReflectionProbeCommunication : MonoBehaviour
    6. {
    7. public List<Material> renderMaterials = new List<Material>();
    8. public ReflectionProbe reflectionProbe;
    9. Transform probeTransform;

    10. void Awake()
    11. {
    12. reflectionProbe.RenderProbe();
    13. probeTransform = reflectionProbe.gameObject.transform;
    14. }

    15. //TODO: Should this be update or fixed update? I'm guessing we'd want it to change based on the user's frame rate, but am unsure.
    16. void Update()
    17. {
    18. UpdateMaterials();
    19. }

    20. ///<<Summary>>Goes through materials for planes and updates accordingly.<<Summary>>
    21. void UpdateMaterials()
    22. {
    23. foreach (Material m in renderMaterials)
    24. {
    25. UpdateRenderImage(m);
    26. UpdateDepthData(m);
    27. }
    28. }

    29. ///<<Summary>>This function updates the visuals of the six planes according to the real time reflection probe moving above the city.<<Summary>>
    30. void UpdateRenderImage(Material m)
    31. {
    32. m.SetTexture("_IBL", reflectionProbe.realtimeTexture);
    33. }

    34. ///<<Summary>>This function tells generates a depth field for the reflection probe output shader via gpu.<<Summary>>
    35. void UpdateDepthData(Material m)
    36. {
    37. m.SetVector("_probePosition", probeTransform.position);
    38. }

    39. }
    Do anyone have any ideas on how to create a depth buffer that I could utilize on the given shader?

    Thanks,
    Cabbages
     
  2. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146