One way to achieve this is by creating a custom post-process blendable material that renders the scope area separately with a different field of view, creating a wider view.
Here's an example shader code for Unreal Engine 4 that can be used to implement the scope effect:
-
Create a new Material in Unreal Engine 4 and set its Material Domain to "Post Process". This will make it a blendable material.
-
Paste the following code into the material's custom expression nodes:
// The screen texture captures the original scene rendered by the camera.
Texture2D SceneTexture;
SamplerState SceneSampler;
// PostProcessInput0 (RGBA) stores the current post-process pass output to be used as input for the scope effect.
float4 PostProcessInput0 : SV_Target0;
// The size (width and height) of the rendering target.
float2 RenderTargetSize;
// The UV coordinates for the scope circle calculated in the vertex shader.
float2 ScopeUV;
// The center and radius of the scope circle on the screen.
float2 ScopeCenter; // Adjust this value to position the scope center on the screen.
float ScopeRadius; // Adjust this value to set the scope radius.
// The camera field of view (in radians) and aspect ratio.
float CameraFOV;
float CameraAspectRatio;
void VS(in float4 InPosition : POSITION, in float2 InTexture : TEXCOORD,
out float4 OutPosition : SV_POSITION, out float2 OutTexture : TEXCOORD)
{
// Pass through position and texture coordinates.
OutPosition = InPosition;
OutTexture = InTexture;
// Calculate the scope circle UV coordinates from screen space.
ScopeUV = InTexture * RenderTargetSize - ScopeCenter;
ScopeUV /= ScopeRadius;
ScopeUV.y *= CameraAspectRatio;
}
float4 PS(in float4 InPosition : SV_POSITION, in float2 InTexture : TEXCOORD) : SV_Target0
{
// Sample the scene texture inside the scope circle.
float4 sceneColor = SceneTexture.Sample(SceneSampler, ScopeUV);
// Calculate the distance from the scope center.
float scopeDistance = length(ScopeUV);
// Blend the scope and original post-process pass output based on the scope distance.
float blendFactor = saturate((ScopeRadius - scopeDistance) * 10.0);
float4 outputColor = lerp(PostProcessInput0, sceneColor, blendFactor);
// Apply field of view scaling for the scope area.
float fovScale = tan(CameraFOV * 0.5) / tan(CameraFOV * 0.5 * 0.333); // The scaling factor can be adjusted based on the desired scope FOV.
outputColor.xy *= fovScale;
return outputColor;
}
// Bind custom vertex and pixel shaders.
technique10 Scope
{
pass P0
{
SetVertexShader(CompileShader(vs_5_0, VS()));
SetPixelShader(CompileShader(ps_5_0, PS()));
}
}
-
Connect the custom code node outputs (OutPosition and OutTexture) to the material's inputs (Position and UV).
-
Set up the constants for the shader - ScopeCenter, ScopeRadius, CameraFOV, CameraAspectRatio. You can set these in the material instance or store them in a Material Parameter Collection and adjust them using Blueprints at runtime.
-
In your post-processing volume, add this material to the Blendables list under the Post Process Materials section. Now the custom scope material will be blended with the main post-process pass, creating the desired scope effect.