Пример #1
0
 // Start is called before the first frame update
 void Start()
 {
     _instance    = this;
     screenWidth  = Screen.width;
     screenHeight = Screen.height;
     //降分辨率
     resolutionRatio  = PostEffectUtil_Mobile.GetResolutionRatio(curQuality);
     isDownResolution = resolutionRatio > 1;    //Down Resolution
     if (isDownResolution)
     {
         screenWidth  = (int)(screenWidth / resolutionRatio);
         screenHeight = (int)(screenHeight / resolutionRatio);
         Screen.SetResolution(screenWidth, screenHeight, true);
     }
     //使用DepthBuffer
     if (isUseDepthBuffer)
     {
         depthBufferMgr.Init(screenWidth, screenHeight, depthBufferRatio);
         globalDepthMode = DepthTextureMode.None;
     }
     else
     {
         depthBufferMgr.enabled = false;
         globalDepthMode        = DepthTextureMode.Depth;
     }
     //后处理
     //if (effect_DofBokeh != null)
     //{
     //    effect_DofBokeh.Init(PostEffectUtil_Mobile.GetFormat(curQuality), globalDepthMode);
     //}
     //if (effect_Bloom != null)
     //{
     //    effect_Bloom.Init(PostEffectUtil_Mobile.GetFormat(curQuality), globalDepthMode);
     //}
 }
 protected virtual void OnValidate()
 {
     if (this.camera != null)
     {
         this.camera.depthTextureMode = this.depthTextureMode;
     }
 }
    protected override void Start()
    {
        base.Start();

        this.camera = base.GetComponent <Camera>();
        this.camera.depthTextureMode = this.depthTextureMode;
    }
Пример #4
0
    void OnEnable()
    {
        var currentCam = GetComponent <Camera>();

        defaultMode = currentCam.depthTextureMode;
        if (currentCam.renderingPath == RenderingPath.Forward)
        {
            currentCam.depthTextureMode |= DepthTextureMode.Depth;
        }

        var go = new GameObject("DecalLayersCamera");

        go.transform.parent        = currentCam.transform;
        go.transform.localPosition = Vector3.zero;
        go.transform.localRotation = Quaternion.identity;
        depthCamera = go.AddComponent <Camera>();
        depthCamera.CopyFrom(currentCam);
        depthCamera.renderingPath = RenderingPath.Forward;
        depthCamera.depth         = currentCam.depth - 1;
        depthCamera.cullingMask   = DecalLayers;

        CreateDepthTexture();
        depthCamera.targetTexture = rt;
        Shader.SetGlobalTexture("_LayerDecalDepthTexture", rt);
        Shader.EnableKeyword("USE_CUSTOM_DECAL_LAYERS");

        if (DecalRenderingMode == DecalLayersProperty.IgnoreSelectedLayers)
        {
            Shader.EnableKeyword("USE_CUSTOM_DECAL_LAYERS_IGNORE_MODE");
        }
    }
        public override DepthTextureMode GetCameraFlags()
        {
            BuiltinDebugViewsModel.Mode mode             = base.model.settings.mode;
            DepthTextureMode            depthTextureMode = 0;

            if (mode != BuiltinDebugViewsModel.Mode.Normals)
            {
                if (mode != BuiltinDebugViewsModel.Mode.MotionVectors)
                {
                    if (mode == BuiltinDebugViewsModel.Mode.Depth)
                    {
                        depthTextureMode |= 1;
                    }
                }
                else
                {
                    depthTextureMode |= 5;
                }
            }
            else
            {
                depthTextureMode |= 2;
            }
            return(depthTextureMode);
        }
Пример #6
0
        private void SetLegacyCameraFlags(PostProcessRenderContext context)
        {
            DepthTextureMode depthTextureMode = context.camera.depthTextureMode;

            foreach (KeyValuePair <Type, PostProcessBundle> bundle in m_Bundles)
            {
                if (bundle.Value.settings.IsEnabledAndSupported(context))
                {
                    depthTextureMode |= bundle.Value.renderer.GetCameraFlags();
                }
            }
            if (context.IsTemporalAntialiasingActive())
            {
                depthTextureMode |= temporalAntialiasing.GetCameraFlags();
            }
            if (fog.IsEnabledAndSupported(context))
            {
                depthTextureMode |= fog.GetCameraFlags();
            }
            if (debugLayer.debugOverlay != 0)
            {
                depthTextureMode |= debugLayer.GetCameraFlags();
            }
            context.camera.depthTextureMode = depthTextureMode;
        }
    public virtual void SetupTest(int numCubes, int numCameras, DepthTextureMode depthTextureMode = DepthTextureMode.Depth, bool enableCamera = false)
    {
        Application.targetFrameRate = 10000;
        QualitySettings.vSyncCount  = 0;

        _go = new GameObject("ScreenCaptureTest");

        _cameras = new Camera[numCameras];
        for (var i = 0; i < numCameras; ++i)
        {
            var go     = new GameObject("Camera" + i);
            var camera = go.AddComponent <Camera>();
            camera.enabled            = false;
            camera.transform.position = UnityEngine.Random.insideUnitSphere * 2 * kScaleFactor;
            camera.transform.LookAt(Vector3.zero);
            camera.targetTexture    = new RenderTexture(kWidth, kHeight, 24, GraphicsFormat.R8G8B8A8_UNorm);
            camera.depthTextureMode = depthTextureMode;
            camera.renderingPath    = RenderingPath.Forward;
            camera.nearClipPlane    = 8;
            _cameras[i]             = camera;
            if (i == 0)
            {
                _cameras[i].enabled = enableCamera;
                _cameras[i].tag     = "MainCamera";
            }
        }

        _directional = new DirectionalLight();

        var script = _go.AddComponent <RotatingCubes>();

        script.Setup(numCubes);

        _startTime = DateTime.Now;
    }
Пример #8
0
        /// <summary>
        /// Creates a GameObject with an OffscreenBuffer and required Camera with the specified properties.
        /// </summary>
        public static OffscreenBuffer Create(int width, int height, int depth,
                                             RenderTextureFormat format, DepthTextureMode depthMode,
                                             LayerMask layerMask, CameraClearFlags clearFlags,
                                             Color clearColor, Shader replacementShader,
                                             string replacementTag)
        {
            GameObject tmp = new GameObject("Offscreen Buffer Camera");

            // we want to do some setup before we activate so things adhere to Monobehaviour execution order.
            tmp.SetActive(false);
            tmp.AddComponent <Camera>();
            OffscreenBuffer c = tmp.AddComponent <OffscreenBuffer>();

            c.width       = width;
            c.height      = height;
            c.depth       = depth;
            c.format      = format;
            c.cullingMask = layerMask.value;
            c.clearFlags  = clearFlags;
            c.clearColor  = clearColor;
            if (replacementShader != null)
            {
                c.replacementShader = replacementShader;
                c.replacementTag    = replacementTag;
            }
            tmp.SetActive(true);
            return(c);
        }
Пример #9
0
        void OnPreRender()
        {
            var c = Camera.current;

            lastDepthTexMode   = c.depthTextureMode;
            c.depthTextureMode = DepthTextureMode.Depth;
        }
Пример #10
0
 // Update is called once per frame
 void Update()
 {
     if (_cachedMode != mode)
     {
         _cachedMode = mode;
         Camera.main.depthTextureMode = _cachedMode;
     }
 }
Пример #11
0
 protected void API_AttachCameraRenderFlags(DepthTextureMode mod)
 {
     ImageEffectManager.CameraRenderFlagsNode reslut = ImageEffectManager.API_AttachCameraRenderFlags(m_Camera, mod);
     if (null != reslut)
     {
         flagReferenceList.Add(reslut);
     }
 }
Пример #12
0
    static int IntToEnum(IntPtr L)
    {
        int arg0           = (int)LuaDLL.lua_tonumber(L, 1);
        DepthTextureMode o = (DepthTextureMode)arg0;

        LuaScriptMgr.PushEnum(L, o);
        return(1);
    }
Пример #13
0
    static private void SetupCameraWithPostShader(Camera cam, Material material, DepthTextureMode depthTextureMode = DepthTextureMode.None)
    {
        var cb = new CommandBuffer();

        cb.Blit(null, BuiltinRenderTextureType.CurrentActive, material);
        cam.AddCommandBuffer(CameraEvent.AfterEverything, cb);
        cam.depthTextureMode = depthTextureMode;
    }
Пример #14
0
    void OnPreRender()
    {
        var c = Camera.current;

        lastDepthTexMode   = c.depthTextureMode;
        c.depthTextureMode = DepthTextureMode.Depth;

        Debug.LogFormat("Projection Matrix\n{0}", GL.GetGPUProjectionMatrix(c.projectionMatrix, true));
    }
Пример #15
0
    public void PreCullEnd(bool postCamFX)
    {
        if (this.mount != null)
        {
            Transform transform = this.mount.transform;
            base.transform.position = transform.position;
            base.transform.rotation = transform.rotation;
            CameraClearFlags clearFlags       = this.camera.clearFlags;
            int cullingMask                   = this.camera.cullingMask;
            DepthTextureMode depthTextureMode = this.camera.depthTextureMode;
            this.camera.ResetProjectionMatrix();
            this.camera.ResetWorldToCameraMatrix();
            this.mount.camera.depthTextureMode = depthTextureMode;
            this.camera.CopyFrom(this.mount.camera);
            if (!postCamFX)
            {
                CameraFX.ApplyTransitionAlterations(this.camera, null, false);
            }
            this.camera.clearFlags  = clearFlags;
            this.camera.cullingMask = cullingMask;
            if (this.camera.depthTextureMode != depthTextureMode)
            {
                Debug.Log("Yea this is changing depth texture mode!", this.mount);
                this.camera.depthTextureMode = depthTextureMode;
            }
            this.mount.OnPostMount(this);
            this.lastView = this.camera.worldToCameraMatrix;
            this.lastProj = this.camera.projectionMatrix;
            this.once     = true;
        }
        else
        {
            if (!this.once)
            {
                this.lastView = this.camera.worldToCameraMatrix;
                this.lastProj = this.camera.projectionMatrix;
                this.once     = true;
            }
            this.camera.ResetProjectionMatrix();
            this.camera.ResetWorldToCameraMatrix();
            this.camera.worldToCameraMatrix = this.lastView;
            this.camera.projectionMatrix    = this.lastProj;
            if (!postCamFX)
            {
                CameraFX.ApplyTransitionAlterations(this.camera, null, false);
            }
        }
        Matrix4x4 cameraToWorldMatrix = this.camera.cameraToWorldMatrix;

        base.transform.position = cameraToWorldMatrix.MultiplyPoint(Vector3.zero);
        Vector3 forward = cameraToWorldMatrix.MultiplyVector(-Vector3.forward);

        base.transform.rotation = Quaternion.LookRotation(forward, cameraToWorldMatrix.MultiplyVector(Vector3.up));
        Shader.SetGlobalMatrix("_RUST_MATRIX_CAMERA_TO_WORLD", cameraToWorldMatrix * negateZMatrix);
        Shader.SetGlobalMatrix("_RUST_MATRIX_WORLD_TO_CAMERA", this.camera.worldToCameraMatrix * negateZMatrix);
    }
Пример #16
0
    void OnEnable()
    {
        var cam = GetComponent <Camera>();

        defaultMode = cam.depthTextureMode;
        if (cam.renderingPath == RenderingPath.Forward)
        {
            cam.depthTextureMode |= DepthTextureMode.Depth;
        }
    }
Пример #17
0
    public void SetDepthMode(DepthTextureMode mode)
    {
        if (m_camera == null)
        {
            return;
        }

        m_depthMode = mode;
        m_camera.depthTextureMode = mode;
    }
Пример #18
0
 private void UpdateInfo()
 {
     currentDepthMode = camera.depthTextureMode;
     currentRenderPath = camera.actualRenderingPath;
     PostEffectsBase[] fx = gameObject.GetComponents<PostEffectsBase>();
     int fxCount = 0;
     foreach (var post in fx)
         if (post.enabled)
             fxCount++;
     recognizedPostFxCount = fxCount;
 }
Пример #19
0
    private void Start()
    {
        if (Cam == null)
        {
            Cam = GetComponent <Camera>();
        }
        Cam.depthTextureMode = DepthTextureMode.DepthNormals;
        CamDepthTextureMode  = Cam.depthTextureMode;

        CheckLUT();
    }
Пример #20
0
        public static CameraRenderFlagsNode API_AttachCameraRenderFlags(Camera cam, DepthTextureMode mod)
        {
            CameraRenderFlagsNode reslut = null;
            ImageEffectManager    res    = GetImageEffectManager(cam);

            if (res)
            {
                reslut = res.AttachCameraRenderFlags(mod);
            }

            return(reslut);
        }
Пример #21
0
        private void OnPreCull()
        {
            this.m_Camera = base.GetComponent <Camera>();
            if (this.profile == null || this.m_Camera == null)
            {
                return;
            }
            PostProcessingContext postProcessingContext = this.m_Context.Reset();

            postProcessingContext.profile = this.profile;
            postProcessingContext.renderTextureFactory = this.m_RenderTextureFactory;
            postProcessingContext.materialFactory      = this.m_MaterialFactory;
            postProcessingContext.camera = this.m_Camera;
            this.m_DebugViews.Init(postProcessingContext, this.profile.debugViews);
            this.m_AmbientOcclusion.Init(postProcessingContext, this.profile.ambientOcclusion);
            this.m_ScreenSpaceReflection.Init(postProcessingContext, this.profile.screenSpaceReflection);
            this.m_FogComponent.Init(postProcessingContext, this.profile.fog);
            this.m_MotionBlur.Init(postProcessingContext, this.profile.motionBlur);
            this.m_Taa.Init(postProcessingContext, this.profile.antialiasing);
            this.m_EyeAdaptation.Init(postProcessingContext, this.profile.eyeAdaptation);
            this.m_DepthOfField.Init(postProcessingContext, this.profile.depthOfField);
            this.m_Bloom.Init(postProcessingContext, this.profile.bloom);
            this.m_ChromaticAberration.Init(postProcessingContext, this.profile.chromaticAberration);
            this.m_ColorGrading.Init(postProcessingContext, this.profile.colorGrading);
            this.m_UserLut.Init(postProcessingContext, this.profile.userLut);
            this.m_Grain.Init(postProcessingContext, this.profile.grain);
            this.m_Vignette.Init(postProcessingContext, this.profile.vignette);
            this.m_Dithering.Init(postProcessingContext, this.profile.dithering);
            this.m_Fxaa.Init(postProcessingContext, this.profile.antialiasing);
            if (this.m_PreviousProfile != this.profile)
            {
                this.DisableComponents();
                this.m_PreviousProfile = this.profile;
            }
            this.CheckObservers();
            DepthTextureMode depthTextureMode = postProcessingContext.camera.depthTextureMode;

            foreach (PostProcessingComponentBase postProcessingComponentBase in this.m_Components)
            {
                if (postProcessingComponentBase.active)
                {
                    depthTextureMode |= postProcessingComponentBase.GetCameraFlags();
                }
            }
            postProcessingContext.camera.depthTextureMode = depthTextureMode;
            if (!this.m_RenderingInSceneView && this.m_Taa.active && !this.profile.debugViews.willInterrupt)
            {
                this.m_Taa.SetProjectionMatrix(this.jitteredMatrixFunc);
            }
        }
Пример #22
0
        public override DepthTextureMode GetCameraFlags()
        {
            DepthTextureMode depthTextureMode = DepthTextureMode.None;

            if (this.occlusionSource == AmbientOcclusionComponent.OcclusionSource.DepthTexture)
            {
                depthTextureMode |= DepthTextureMode.Depth;
            }
            if (this.occlusionSource != AmbientOcclusionComponent.OcclusionSource.GBuffer)
            {
                depthTextureMode |= DepthTextureMode.DepthNormals;
            }
            return(depthTextureMode);
        }
Пример #23
0
 public void OnValidate()
 {
     this.target.projectionMatrix = this.projectionMatrix;
     //this.target.worldToCameraMatrix = this.worldToCameraMatrix;
     //this.target.stereoEnabled = this.stereoEnabled;
     //this.target.stereoSeparation = this.stereoSeparation;
     //this.target.stereoConvergence = this.stereoConvergence;
     this.target.eventMask            = this.eventMask.value;
     this.target.depthTextureMode     = this.depthTextureMode;
     this.target.transparencySortMode = this.transparencySortMode;
     this.target.aspect             = this.aspect;
     this.target.layerCullDistances = this.layerCullDistances.values;
     this.target.layerCullSpherical = this.layerCullSpherical;
 }
Пример #24
0
        public override DepthTextureMode GetCameraFlags()
        {
            DepthTextureMode none = DepthTextureMode.None;

            if (this.occlusionSource == OcclusionSource.DepthTexture)
            {
                none |= DepthTextureMode.Depth;
            }
            if (this.occlusionSource != OcclusionSource.GBuffer)
            {
                none |= DepthTextureMode.DepthNormals;
            }
            return(none);
        }
Пример #25
0
        protected override void ReadFromImpl(object obj)
        {
            base.ReadFromImpl(obj);
            Camera uo = (Camera)obj;

            nearClipPlane          = uo.nearClipPlane;
            farClipPlane           = uo.farClipPlane;
            fieldOfView            = uo.fieldOfView;
            renderingPath          = uo.renderingPath;
            allowHDR               = uo.allowHDR;
            allowMSAA              = uo.allowMSAA;
            allowDynamicResolution = uo.allowDynamicResolution;
            forceIntoRenderTexture = uo.forceIntoRenderTexture;
            orthographicSize       = uo.orthographicSize;
            orthographic           = uo.orthographic;
            opaqueSortMode         = uo.opaqueSortMode;
            transparencySortMode   = uo.transparencySortMode;
            transparencySortAxis   = uo.transparencySortAxis;
            depth                         = uo.depth;
            aspect                        = uo.aspect;
            cullingMask                   = uo.cullingMask;
            eventMask                     = uo.eventMask;
            layerCullSpherical            = uo.layerCullSpherical;
            cameraType                    = uo.cameraType;
            layerCullDistances            = uo.layerCullDistances;
            useOcclusionCulling           = uo.useOcclusionCulling;
            cullingMatrix                 = uo.cullingMatrix;
            backgroundColor               = uo.backgroundColor;
            clearFlags                    = uo.clearFlags;
            depthTextureMode              = uo.depthTextureMode;
            clearStencilAfterLightingPass = uo.clearStencilAfterLightingPass;
            usePhysicalProperties         = uo.usePhysicalProperties;
            sensorSize                    = uo.sensorSize;
            lensShift                     = uo.lensShift;
            focalLength                   = uo.focalLength;
            rect                        = uo.rect;
            pixelRect                   = uo.pixelRect;
            targetTexture               = ToID(uo.targetTexture);
            targetDisplay               = uo.targetDisplay;
            worldToCameraMatrix         = uo.worldToCameraMatrix;
            projectionMatrix            = uo.projectionMatrix;
            nonJitteredProjectionMatrix = uo.nonJitteredProjectionMatrix;
            useJitteredProjectionMatrixForTransparentRendering = uo.useJitteredProjectionMatrixForTransparentRendering;
            scene             = uo.scene;
            stereoSeparation  = uo.stereoSeparation;
            stereoConvergence = uo.stereoConvergence;
            stereoTargetEye   = uo.stereoTargetEye;
        }
Пример #26
0
 public void Reset()
 {
     this.target              = this.GetComponent <Camera>();
     this.velocity            = this.target.velocity;
     this.projectionMatrix    = this.target.projectionMatrix;
     this.worldToCameraMatrix = this.target.worldToCameraMatrix;
     //this.stereoEnabled = this.target.stereoEnabled;
     //this.stereoSeparation = this.target.stereoSeparation;
     //this.stereoConvergence = this.target.stereoConvergence;
     this.eventMask            = (LayerMask)this.target.eventMask;
     this.depthTextureMode     = this.target.depthTextureMode;
     this.transparencySortMode = this.target.transparencySortMode;
     this.aspect = this.target.aspect;
     this.layerCullDistances.values = this.target.layerCullDistances;
     this.layerCullSpherical        = this.target.layerCullSpherical;
 }
Пример #27
0
    void UpdateInfo()
    {
        currentDepthMode  = GetComponent <Camera>().depthTextureMode;
        currentRenderPath = GetComponent <Camera>().actualRenderingPath;
        PostEffectsBase[] fx = gameObject.GetComponents <PostEffectsBase>();
        int fxCount          = 0;

        foreach (PostEffectsBase post in fx)
        {
            if (post.enabled)
            {
                fxCount++;
            }
        }
        currentPostFxCount = fxCount;
    }
Пример #28
0
        private void UpdateInfo()
        {
            currentDepthMode  = camera.depthTextureMode;
            currentRenderPath = camera.actualRenderingPath;
            PostEffectsBase[] fx = gameObject.GetComponents <PostEffectsBase>();
            int fxCount          = 0;

            foreach (var post in fx)
            {
                if (post.enabled)
                {
                    fxCount++;
                }
            }
            recognizedPostFxCount = fxCount;
        }
Пример #29
0
 public CameraSerializable(Camera obj) : base(obj)
 {
     clearFlags          = obj.clearFlags;
     backgroundColor     = obj.backgroundColor;
     cullingMask         = obj.cullingMask;
     eventMask           = obj.eventMask;
     layerCullSpherical  = obj.layerCullSpherical;
     cameraType          = obj.cameraType;
     useOcclusionCulling = obj.useOcclusionCulling;
     projectionMatrix    = obj.projectionMatrix;
     fieldOfView         = obj.fieldOfView;
     depthTextureMode    = obj.depthTextureMode;
     targetDisplay       = obj.targetDisplay;
     rect          = obj.rect;
     nearClipPlane = obj.nearClipPlane;
     farClipPlane  = obj.farClipPlane;
     depth         = obj.depth;
 }
        public override DepthTextureMode GetCameraFlags()
        {
            BuiltinDebugViewsModel.Mode mode = base.model.settings.mode;
            DepthTextureMode            none = DepthTextureMode.None;

            if (mode == BuiltinDebugViewsModel.Mode.Normals)
            {
                none |= DepthTextureMode.DepthNormals;
            }
            else if (mode == BuiltinDebugViewsModel.Mode.MotionVectors)
            {
                none |= DepthTextureMode.MotionVectors | DepthTextureMode.Depth;
            }
            else if (mode == BuiltinDebugViewsModel.Mode.Depth)
            {
                none |= DepthTextureMode.Depth;
            }
            return(none);
        }
        public override DepthTextureMode GetCameraFlags()
        {
            BuiltinDebugViewsModel.Mode mode             = base.model.settings.mode;
            DepthTextureMode            depthTextureMode = DepthTextureMode.None;

            switch (mode)
            {
            case BuiltinDebugViewsModel.Mode.Depth:
                depthTextureMode |= DepthTextureMode.Depth;
                break;

            case BuiltinDebugViewsModel.Mode.Normals:
                depthTextureMode |= DepthTextureMode.DepthNormals;
                break;

            case BuiltinDebugViewsModel.Mode.MotionVectors:
                depthTextureMode |= (DepthTextureMode.Depth | DepthTextureMode.MotionVectors);
                break;
            }
            return(depthTextureMode);
        }
Пример #32
0
 /// <summary>
 /// Creates a GameObject with an OffscreenBuffer and required Camera with the specified properties.
 /// </summary>
 public static OffscreenBuffer Create(int width, int height, int depth,
                                      RenderTextureFormat format, DepthTextureMode depthMode,
                                      LayerMask layerMask, CameraClearFlags clearFlags,
                                      Color clearColor, Shader replacementShader,
                                      string replacementTag) {
   GameObject tmp = new GameObject("Offscreen Buffer Camera");
   // we want to do some setup before we activate so things adhere to Monobehaviour execution order.
   tmp.SetActive(false);
   tmp.AddComponent<Camera>();
   OffscreenBuffer c = tmp.AddComponent<OffscreenBuffer>();
   c.width = width;
   c.height = height;
   c.depth = depth;
   c.format = format;
   c.cullingMask = layerMask.value;
   c.clearFlags = clearFlags;
   c.clearColor = clearColor;
   if (replacementShader != null) {
     c.replacementShader = replacementShader;
     c.replacementTag = replacementTag;
   }
   tmp.SetActive(true);
   return c;
 }