A Problem About RenderWithShader and Camera Orthographic

I currently meet a problem: I write a script to use RenderWithShader and I attach the script to my main camera. The main camera’s projection is set to Perspective, and the RenderWithShader doesn’t work. When I change the main camera’s projection into Orthographic, the RenderWithShader work!

I don’t know how this happen, and I just can’t use RenderWithShader on my perspective camera.

My script:

using UnityEngine;

using System.Collections;

 

public class DepthCamera : MonoBehaviour {

 

    public RenderTexture tempTexture1;

    public Shader depthShader;

 

    private Camera lightPosCam;

 

    void Awake()

    {

    }

    // Use this for initialization

    void Start () {

        GameObject lCam=new GameObject("LightPosCam");

        lCam.transform.position=transform.position;

        lCam.transform.rotation=transform.rotation;

        lightPosCam=(Camera)lCam.AddComponent(typeof(Camera));

        

        lightPosCam.CopyFrom(camera);

        lightPosCam.enabled = false;

 

        tempTexture1 = new RenderTexture(800, 600, 

                                         16, RenderTextureFormat.ARGBFloat);

        depthShader = Shader.Find("TestShader");

    }

 

    void OnGUI()

    {

        GUI.depth = 0;

        GUI.DrawTexture(new Rect(0, 400, 200, 200), tempTexture1);

    }

 

    // Update is called once per frame

    void Update () {

        lightPosCam.targetTexture = tempTexture1 ;

        lightPosCam.RenderWithShader(depthShader,"");

    }

    

}

My shader:

Shader "TestShader" {

    SubShader {

        Tags { "RenderType"="Opaque" }

        

        Pass

        {

            Fog {Mode off}

            

            Color (1,1,0,1)

        }

       }

}

Please help!

Images of my problem:

24617-perspective.png
24618-orthographic.png
camera.png

At last, I find out how to solve this.

Just set the Rendering Path of the main camera and the camera created in script into Forward or VertexLit .

In this case, Deferred path is not working with RenderWithShader, but I don’t know why.