Пример #1
0
    protected override void Execute(CustomPassContext ctx)
    {
        // Disable it for scene view because it's horrible
        if (ctx.hdCamera.camera.cameraType == CameraType.SceneView)
        {
            return;
        }

        var currentCam = ctx.hdCamera.camera;

        // Copy settings of our current camera
        foregroundCamera.transform.SetPositionAndRotation(currentCam.transform.position, currentCam.transform.rotation);
        foregroundCamera.CopyFrom(ctx.hdCamera.camera);
        // Make sure the camera is disabled, we don't want it to render anything.
        foregroundCamera.enabled     = false;
        foregroundCamera.fieldOfView = fov;
        foregroundCamera.cullingMask = foregroundMask;

        var depthTestOverride = new RenderStateBlock(RenderStateMask.Depth)
        {
            depthState = new DepthState(false, CompareFunction.Always),
        };

        // TODO: Nuke the depth in the after depth and normal injection point
        // Override depth to 0 (avoid artifacts with screen-space effects)
        ctx.cmd.SetRenderTarget(trueDepthBuffer, 0, CubemapFace.Unknown, 0); // TODO: make it work in VR
        CustomPassUtils.RenderFromCamera(ctx, foregroundCamera, null, null, ClearFlag.None, foregroundMask, overrideMaterial: depthClearMaterial, overrideMaterialIndex: 0);
        // Render the object color
        CustomPassUtils.RenderFromCamera(ctx, foregroundCamera, ctx.cameraColorBuffer, ctx.cameraDepthBuffer, ClearFlag.None, foregroundMask, overrideRenderState: depthTestOverride);
    }
Пример #2
0
    protected override void Execute(CustomPassContext ctx)
    {
        // Disable it for scene view because it's horrible
        if (ctx.hdCamera.camera.cameraType == CameraType.SceneView)
        {
            return;
        }

        var currentCam = ctx.hdCamera.camera;

        // Copy settings of our current camera
        foregroundCamera.transform.SetPositionAndRotation(currentCam.transform.position, currentCam.transform.rotation);
        foregroundCamera.CopyFrom(ctx.hdCamera.camera);
        // Make sure the camera is disabled, we don't want it to render anything.
        foregroundCamera.enabled     = false;
        foregroundCamera.fieldOfView = fov;
        foregroundCamera.cullingMask = foregroundMask;

        var depthTestOverride = new RenderStateBlock(RenderStateMask.Depth)
        {
            depthState = new DepthState(true, CompareFunction.LessEqual),
        };

        CustomPassUtils.RenderFromCamera(ctx, foregroundCamera, ctx.cameraColorBuffer, ctx.cameraDepthBuffer, ClearFlag.None, foregroundMask, overrideRenderState: depthTestOverride);
    }
Пример #3
0
    protected override void Execute(CustomPassContext ctx)
    {
        if (customCamera0 == null || customCamera1 == null || customCamera2 == null || customCamera3 == null || customCamera4 == null)
        {
            return;
        }

        // Render from camera 0
        // Internal API, can't be tested right now
        // using (new HDRenderPipeline.OverrideCameraRendering(ctx.cmd, customCamera0))
        // {
        //     CoreUtils.SetRenderTarget(ctx.cmd, temp, ClearFlag.Color);
        //     CustomPassUtils.DrawRenderers(ctx, -1);
        // }
        // CustomPassUtils.Copy(
        //     ctx, temp, ctx.cameraColorBuffer,
        //     CustomPassUtils.fullScreenScaleBias,
        //     new Vector4(.5f, .5f, 0f, 0f)
        // );

        RenderStateBlock overrideDepth = new RenderStateBlock(RenderStateMask.Depth)
        {
            depthState = new DepthState(true, CompareFunction.LessEqual)
        };

        // Render from camera 1
        CustomPassUtils.RenderFromCamera(ctx, customCamera1, temp, ctx.customDepthBuffer.Value, ClearFlag.All, -1, overrideRenderState: overrideDepth);
        CustomPassUtils.Copy(
            ctx, temp, ctx.cameraColorBuffer,
            CustomPassUtils.fullScreenScaleBias,
            new Vector4(.5f, .5f, .5f, 0f)
            );

        // Render from camera 4 (at same position than the test camera but uses a different FoV)
        // And with the camera depth buffer (which already contains opaque objects)
        CustomPassUtils.RenderFromCamera(ctx, customCamera4, ctx.cameraColorBuffer, ctx.cameraDepthBuffer, ClearFlag.None, customCamera4.cullingMask, overrideRenderState: overrideDepth);

        // Render from camera 3 using different buffers
        CustomPassUtils.RenderDepthFromCamera(ctx, customCamera3, temp, ctx.customDepthBuffer.Value, ClearFlag.All, -1);
        CustomPassUtils.Copy(
            ctx, temp, ctx.cameraColorBuffer,
            CustomPassUtils.fullScreenScaleBias,
            new Vector4(.25f, .25f, .5f, .5f)
            );

        CustomPassUtils.RenderNormalFromCamera(ctx, customCamera3, temp, ctx.customDepthBuffer.Value, ClearFlag.All, -1);
        CustomPassUtils.Copy(
            ctx, temp, ctx.cameraColorBuffer,
            CustomPassUtils.fullScreenScaleBias,
            new Vector4(.25f, .25f, .75f, .5f)
            );

        CustomPassUtils.RenderTangentFromCamera(ctx, customCamera3, temp, ctx.customDepthBuffer.Value, ClearFlag.All, -1);
        CustomPassUtils.Copy(
            ctx, temp, ctx.cameraColorBuffer,
            CustomPassUtils.fullScreenScaleBias,
            new Vector4(.25f, .25f, .5f, .75f)
            );

        // Render from camera 2 in an half res buffer
        CustomPassUtils.RenderFromCamera(ctx, customCamera2, halfResColor, halfResDepth, ClearFlag.All, -1, overrideRenderState: overrideDepth);
        CustomPassUtils.Copy(
            ctx, halfResColor, ctx.cameraColorBuffer,
            CustomPassUtils.fullScreenScaleBias,
            new Vector4(.25f, .25f, .75f, .75f)
            );
    }