protected override void Execute(CustomPassContext ctx)
    {
        if (!render || bakingCamera == null ||
            ctx.hdCamera.camera == bakingCamera)
        {
            return;
        }

        bakingCamera.TryGetCullingParameters(out var cullingParams);

        cullingParams.cullingOptions = CullingOptions.ShadowCasters;

        // Assign the custom culling result to the context
        // so it'll be used for the following operations
        cullingResultField.SetValueDirect(__makeref(ctx), ctx.renderContext.Cull(ref cullingParams));
        var overrideDepthTest = new RenderStateBlock(RenderStateMask.Depth)
        {
            depthState = new DepthState(true, CompareFunction.LessEqual)
        };

        // Sync baking camera aspect ratio with RT (see https://github.com/alelievr/HDRP-Custom-Passes/issues/24)
        bakingCamera.aspect    = ctx.hdCamera.camera.aspect;
        bakingCamera.pixelRect = ctx.hdCamera.camera.pixelRect;

        // Depth
        if (depthTexture != null)
        {
            SyncRenderTextureAspect(depthTexture, ctx.hdCamera.camera);
            CoreUtils.SetRenderTarget(ctx.cmd, depthTexture, ClearFlag.Depth);
            CustomPassUtils.RenderDepthFromCamera(ctx, bakingCamera, bakingCamera.cullingMask, overrideRenderState: overrideDepthTest);
        }

        // ctx.hdCamera.camera.pixelRect = oldRect;
    }
예제 #2
0
    protected override void Execute(CustomPassContext ctx)
    {
        if (!render || ctx.hdCamera.camera == bakingCamera || bakingCamera == null || ctx.hdCamera.camera.cameraType == CameraType.SceneView)
        {
            return;
        }

        if (depthTexture == null && normalTexture == null && tangentTexture == null)
        {
            return;
        }



        // We need to be careful about the aspect ratio of render textures when doing the culling, otherwise it could result in objects poping:
        if (depthTexture != null)
        {
            bakingCamera.aspect = Mathf.Max(bakingCamera.aspect, depthTexture.width / (float)depthTexture.height);
        }
        if (normalTexture != null)
        {
            bakingCamera.aspect = Mathf.Max(bakingCamera.aspect, normalTexture.width / (float)normalTexture.height);
        }
        if (tangentTexture != null)
        {
            bakingCamera.aspect = Mathf.Max(bakingCamera.aspect, tangentTexture.width / (float)tangentTexture.height);
        }
        bakingCamera.TryGetCullingParameters(out var cullingParams);
        cullingParams.cullingOptions = CullingOptions.None;

        // Assign the custom culling result to the context
        // so it'll be used for the following operations
        ctx.cullingResults = ctx.renderContext.Cull(ref cullingParams);
        var overrideDepthTest = new RenderStateBlock(RenderStateMask.Depth)
        {
            depthState = new DepthState(true, CompareFunction.LessEqual)
        };

        // Depth
        if (depthTexture != null)
        {
            CustomPassUtils.RenderDepthFromCamera(ctx, bakingCamera, depthTexture, ClearFlag.Depth, bakingCamera.cullingMask, overrideRenderState: overrideDepthTest);
        }

        // Normal
        if (normalTexture != null)
        {
            CustomPassUtils.RenderNormalFromCamera(ctx, bakingCamera, normalTexture, ClearFlag.All, bakingCamera.cullingMask, overrideRenderState: overrideDepthTest);
        }

        // Tangent
        if (tangentTexture != null)
        {
            CustomPassUtils.RenderTangentFromCamera(ctx, bakingCamera, tangentTexture, ClearFlag.All, bakingCamera.cullingMask, overrideRenderState: overrideDepthTest);
        }
    }
예제 #3
0
    protected override void Execute(CustomPassContext ctx)
    {
        if (!render || ctx.hdCamera.camera == bakingCamera || bakingCamera == null)
        {
            return;
        }

        bakingCamera.TryGetCullingParameters(out var cullingParams);

        cullingParams.cullingOptions = CullingOptions.ShadowCasters;

        // Assign the custom culling result to the context
        // so it'll be used for the following operations
        cullingResultField.SetValueDirect(__makeref(ctx), ctx.renderContext.Cull(ref cullingParams));

        // Depth
        if (depthTexture != null)
        {
            var overrideDepthTest = new RenderStateBlock(RenderStateMask.Depth)
            {
                depthState = new DepthState(true, CompareFunction.LessEqual)
            };
            CoreUtils.SetRenderTarget(ctx.cmd, depthTexture, ClearFlag.Depth);
            CustomPassUtils.RenderDepthFromCamera(ctx, bakingCamera, bakingCamera.cullingMask, overrideRenderState: overrideDepthTest);
        }

        // Normal
        if (normalTexture != null)
        {
            CoreUtils.SetRenderTarget(ctx.cmd, normalTexture, normalTexture.depthBuffer, ClearFlag.Depth);
            CustomPassUtils.RenderNormalFromCamera(ctx, bakingCamera, bakingCamera.cullingMask);
        }

        // Tangent
        if (tangentTexture != null)
        {
            CoreUtils.SetRenderTarget(ctx.cmd, tangentTexture, tangentTexture.depthBuffer, ClearFlag.Depth);
            CustomPassUtils.RenderTangentFromCamera(ctx, bakingCamera, bakingCamera.cullingMask);
        }
    }
예제 #4
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)
            );
    }