Tutorial 5


Alright, for my last exercise I'm using Cinemachine and post-processing.

I expanded on the cinemachine camera I'd already added to the scene with two extra viewpoints, one static and the other on a path.

(On Path)


(Path)

I like the pathed one in particular, with the slight dolly in tandem with the pan giving a slightly more natural feel to the camera movement.

Afterwards, I added some post-processing effects with the post-processing package. A combination of Vignette, Grain, and a custom effect leads to this output:



The custom effect is a depth-sensitive chromatic aberration - RGB channel dislocation scaled to a factor based on the pixel's distance in world space from the camera. Note the way the channels split most visibly at the furthest edges of the building.
Code Snippet
  1. Shader "Hidden/Custom/CADOF"
  2. {
  3.     HLSLINCLUDE
  4.  
  5. #include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl"
  6.  
  7.         TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex);
  8.         TEXTURE2D_SAMPLER2D(_CameraDepthTexture, sampler_CameraDepthTexture);
  9.  
  10.     float _Intensity;
  11.  
  12.     //sampler2D _CameraDepthTexture;
  13.  
  14.     float2 _rS;
  15.     float2 _gS;
  16.     float2 _bS;
  17.  
  18.     float4 Frag(VaryingsDefault i) : SV_Target
  19.     {
  20.         float p = _Intensity * 0.003;
  21.         float d = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoordStereo));
  22.         
  23.         //focal distance
  24.         d = abs(d - 20);
  25.         //focal length
  26.         d *= 0.03;
  27.  
  28.         d = clamp(d, 0, 1);
  29.  
  30.         p *= d;
  31.  
  32.         float r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + _rS * p).r;
  33.         float g = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + _gS * p).g;
  34.         float b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + _bS * p).b;
  35.         
  36.         float4 color = float4(r, g, b, 1);
  37.  
  38.         //color = float4(d, d, d, 1);
  39.  
  40.         return color;
  41.     }
  42.         ENDHLSL
  43.  
  44.         SubShader
  45.     {
  46.         Cull Off ZWrite Off ZTest Always
  47.             Pass
  48.         {
  49.             HLSLPROGRAM
  50.                 #pragma vertex VertDefault
  51.                 #pragma fragment Frag
  52.             ENDHLSL
  53.         }
  54.     }
  55. }


I also made some position-sensitive camera effects, like a red "danger" vignette to tell the player they're near a deer spawner.


Leave a comment

Log in with itch.io to leave a comment.