Search Unity

Question Applying image effects at lower resolutions to the render texture

Discussion in 'Image Effects' started by UnnervedStudios, Nov 2, 2020.

  1. UnnervedStudios

    UnnervedStudios

    Joined:
    Jun 16, 2017
    Posts:
    2
    Hello!

    I've been putting together a very expensive image effect to render volumetric fog with ray marching.
    I was wondering if anyone more experienced with image effects knew how to render the image effect at a lower resolution to the render texture resolution (e.g overlay 1080p volumetric image effect over 4K render texture).

    Here is what my code to apply my vert/frag shader currently reads as:

    Code (CSharp):
    1.     [ImageEffectOpaque]
    2.     private void OnRenderImage (RenderTexture src, RenderTexture dest) {
    3.         if (material == null) material = new Material (shader);
    4. #if !EDITOR_PLAY_MODE
    5.         // assign material properties //
    6. #endif
    7.         Graphics.Blit (src, dest, material);
    8.     }
    The shader itself effectively just multiplies the pixel by a float for transmittance and adds a float3 for the light that scatters in the volume

    Abbreviated below:

    Code (CSharp):
    1.        Cull Off ZWrite Off ZTest Always
    2.  
    3.        Pass
    4.        {
    5.            CGPROGRAM
    6.  
    7.            #pragma vertex vert
    8.            #pragma fragment frag
    9.  
    10.            #include "UnityCG.cginc"
    11.  
    12.            struct appdata {
    13.                float4 vertex : POSITION;
    14.                float2 uv : TEXCOORD0;
    15.            };
    16.  
    17.            struct v2f {
    18.                float4 pos : SV_POSITION;
    19.                float2 uv : TEXCOORD0;
    20.                float3 viewVector : TEXCOORD1;
    21.            };
    22.          
    23.            v2f vert (appdata v)
    24.                v2f output;
    25.                output.pos = UnityObjectToClipPos(v.vertex);
    26.                output.uv = v.uv;
    27.            
    28.                float3 viewVector = mul(unity_CameraInvProjection, float4(v.uv * 2 - 1, 0, -1));
    29.                output.viewVector = mul(unity_CameraToWorld, float4(viewVector,0));
    30.                return output;
    31.            }          
    32.  
    33.            float4 frag (v2f i) : SV_Target
    34.            {
    35.                // raymarch code to calculate transmittance and volumeCol //
    36.                   (uses depth texture)
    37.              
    38.                float3 baseCol = tex2D(_MainTex, i.uv);
    39.                float3 col = baseCol * transmittance + volumeCol;
    40.                return float4(col,0);
    41.            }
    42.  
    43.            ENDCG
    44.        }
    Any tips on how to approach this problem would be much appreciated :)