1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| #ifndef __CAMERA_FOCUS_HLSL__ #define __CAMERA_FOCUS_HLSL__
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; };
struct v2f { float2 uv : TEXCOORD0; float4 positionCS : SV_POSITION; float4 positionSS : TEXCOORD1; };
half4 CalcBlurColor(v2f i, Texture2D _MainTex, SamplerState sampler_MainTex, half uvXFac, half uvYFac, half blurSize) { float blurSize2 = blurSize * 0.001; float uvXFac2 = uvXFac * blurSize2; float uvYFac2 = uvYFac * blurSize2; float2 uv = i.uv;
half4 color = half4(0,0,0,0); color += 0.01621622 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv - float2(uvXFac2 * 4.0, uvYFac2 * 4.0)); color += 0.05405405 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv - float2(uvXFac2 * 3.0, uvYFac2 * 3.0)); color += 0.12162162 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv - float2(uvXFac2 * 2.0, uvYFac2 * 2.0)); color += 0.19459459 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv - float2(uvXFac2 * 1.0, uvYFac2 * 1.0)); color += 0.22702703 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv ); color += 0.19459459 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + float2(uvXFac2 * 1.0, uvYFac2 * 1.0)); color += 0.12162162 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + float2(uvXFac2 * 2.0, uvYFac2 * 2.0)); color += 0.05405405 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + float2(uvXFac2 * 3.0, uvYFac2 * 3.0)); color += 0.01621622 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + float2(uvXFac2 * 4.0, uvYFac2 * 4.0));
return color; }
half4 CalcFocusColor(v2f i, Texture2D _MainTex, SamplerState sampler_MainTex, Texture2D _CameraDepthTexture, SamplerState sampler_CameraDepthTexture, half4 blurColor, half blurDist) { float2 screenUV = i.positionCS.xy/_ScreenParams.xy; half4 depthMap = SAMPLE_TEXTURE2D(_CameraDepthTexture, sampler_CameraDepthTexture, screenUV); half depthZ = Linear01Depth(depthMap.x, _ZBufferParams);
half blur = step(depthZ, blurDist * 0.01f);
half4 mainColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv); half4 outColor = mainColor * blur + blurColor * (1 - blur);
return outColor; }
v2f vert (appdata v) { v2f o; o.positionCS = TransformObjectToHClip(v.vertex.xyz); o.positionSS = ComputeScreenPos(o.positionCS); o.uv = v.uv; return o; }
#endif
|