public void RenderStereoDepth()
    {
        Camera camera = GetComponent <Camera>();

        // Remember camera config parameters
        CameraClearFlags clrFlgs = camera.clearFlags;
        Color            bgColor = camera.backgroundColor;
        RenderingPath    path    = camera.renderingPath;

        // Setup camera for depth stereo rendering
        camera.stereoSeparation = 0.064f;
        camera.clearFlags       = CameraClearFlags.SolidColor;
        camera.backgroundColor  = Color.black;
        camera.SetReplacementShader(depthShader, "RenderType");
        if (autoDepth)
        {
            depthCorrection = camera.stereoConvergence / camera.farClipPlane;
        }
        Shader.SetGlobalFloat("_MaxDepth", depthCorrection);
        camera.renderingPath = RenderingPath.Forward;

        // Render stero texture
        RenderCubemap(camera, "_depth");

        // Restore camera config parameters
        camera.SetReplacementShader(null, "RenderType");
        camera.renderingPath   = path;
        camera.clearFlags      = clrFlgs;
        camera.backgroundColor = bgColor;
    }
        public void GraphicsUsingRenderingPathIsReported(RenderingPath renderingPath)
        {
            var buildGroup         = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);
            var savedTier1settings = EditorGraphicsSettings.GetTierSettings(buildGroup, GraphicsTier.Tier1);
            var savedTier2settings = EditorGraphicsSettings.GetTierSettings(buildGroup, GraphicsTier.Tier2);
            var savedTier3settings = EditorGraphicsSettings.GetTierSettings(buildGroup, GraphicsTier.Tier3);

            var tier1settings = EditorGraphicsSettings.GetTierSettings(buildGroup, GraphicsTier.Tier1);
            var tier2settings = EditorGraphicsSettings.GetTierSettings(buildGroup, GraphicsTier.Tier2);
            var tier3settings = EditorGraphicsSettings.GetTierSettings(buildGroup, GraphicsTier.Tier3);

            tier1settings.renderingPath = renderingPath;
            tier2settings.renderingPath = renderingPath;
            tier3settings.renderingPath = renderingPath;

            EditorGraphicsSettings.SetTierSettings(buildGroup, GraphicsTier.Tier1, tier1settings);
            EditorGraphicsSettings.SetTierSettings(buildGroup, GraphicsTier.Tier2, tier2settings);
            EditorGraphicsSettings.SetTierSettings(buildGroup, GraphicsTier.Tier3, tier3settings);

            if (renderingPath == RenderingPath.Forward)
            {
                Assert.AreEqual(true, Evaluators.GraphicsUsingForwardRendering());
                Assert.AreEqual(false, Evaluators.GraphicsUsingDeferredRendering());
            }
            else
            {
                Assert.AreEqual(false, Evaluators.GraphicsUsingForwardRendering());
                Assert.AreEqual(true, Evaluators.GraphicsUsingDeferredRendering());
            }

            EditorGraphicsSettings.SetTierSettings(buildGroup, GraphicsTier.Tier1, savedTier1settings);
            EditorGraphicsSettings.SetTierSettings(buildGroup, GraphicsTier.Tier2, savedTier2settings);
            EditorGraphicsSettings.SetTierSettings(buildGroup, GraphicsTier.Tier3, savedTier3settings);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This is just before the rendering process starts, so both <c>DrawMesh</c> and <c>CommandBuffer</c> will work
        /// </summary>
        protected virtual void OnPreCull()
        {
            var cam = GetComponent <Camera>();

            if (cmdDepthTexture == null || cmdDepthZtest == null || prevRenderingPath != cam.actualRenderingPath)
            {
                if (cmdDepthTexture != null)
                {
                    cam.RemoveCommandBuffer(evtDepthTexture, cmdDepthTexture);
                }
                if (cmdDepthZtest != null)
                {
                    cam.RemoveCommandBuffer(evtDepthZtest, cmdDepthZtest);
                }
                prevRenderingPath = cam.actualRenderingPath;
                GetCameraEvents(prevRenderingPath, out evtDepthTexture, out evtDepthZtest);
                cmdDepthTexture = GetOrAddBuffer(evtDepthTexture);
                cmdDepthZtest   = GetOrAddBuffer(evtDepthZtest);
            }
            cmdDepthTexture.Clear();
            cmdDepthZtest.Clear();
            SetupCommandBuffer(evtDepthTexture, cmdDepthTexture);
            SetupCommandBuffer(evtDepthZtest, cmdDepthZtest);
            ResetFrame();
            DrawDecals(cmdDepthTexture, cmdDepthZtest);
        }
Ejemplo n.º 4
0
        void AddBlitCommand()
        {
            if (cam is ImmediateMixCastCamera)
            {
                insertFeedCommands = new CommandBuffer();

                if (cam.gameCamera.actualRenderingPath == RenderingPath.Forward)
                {
                    insertFeedCommands.Blit(Texture, BuiltinRenderTextureType.CurrentActive, blitMaterial);    //Insert real world
                    cam.gameCamera.AddCommandBuffer(CameraEvent.AfterForwardOpaque, insertFeedCommands);
                }
                else
                {
                    //insertFeedCommands.SetRenderTarget(BuiltinRenderTextureType.GBuffer0);
                    insertFeedCommands.Blit(Texture, BuiltinRenderTextureType.CurrentActive, blitMaterial);    //Insert real world
                    cam.gameCamera.AddCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, insertFeedCommands);
                }
                renderPath = cam.gameCamera.actualRenderingPath;
            }
            else if (cam is BufferedMixCastCamera)
            {
                BufferedMixCastCamera buffCam = cam as BufferedMixCastCamera;
                buffCam.inputMaterial = blitMaterial;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Calculates the points in the rendering pipeline decal draws should be added to
        /// </summary>
        /// <param name="path">The rendering path being used</param>
        /// <param name="depthTexture">The event for when depth needs to be read from (typically screen space)</param>
        /// <param name="depthZtest">The event for when we need ZTest to work (non-screen-space)</param>
        /// <remarks>The two events can be the same</remarks>
        protected virtual void GetCameraEvents(RenderingPath path, out CameraEvent depthTexture, out CameraEvent depthZtest)
        {
            bool hasDepthZtest = false;

            depthZtest = default(CameraEvent);
            switch (path)
            {
            case RenderingPath.Forward:
                depthTexture = CameraEvent.AfterForwardOpaque;
                break;

            case RenderingPath.DeferredShading:
                // In Deferred, the depth buffer from the previous frame is used int the G-Buffer stages
                // so for depthTexture we need to use the next stage - BeforeReflections - instead
                depthTexture  = CameraEvent.BeforeReflections;
                depthZtest    = CameraEvent.AfterGBuffer;
                hasDepthZtest = true;
                break;

            case RenderingPath.DeferredLighting:
                depthTexture = CameraEvent.AfterFinalPass;
                break;

            case RenderingPath.VertexLit:
                depthTexture = CameraEvent.BeforeImageEffects;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            if (!hasDepthZtest)
            {
                depthZtest = depthTexture;
            }
        }
Ejemplo n.º 6
0
        void RenderFinalPass()
        {
            int oldCulling                 = gameCamera.cullingMask;
            CameraClearFlags oldClear      = gameCamera.clearFlags;
            float            oldFarClip    = gameCamera.farClipPlane;
            float            oldNearClip   = gameCamera.nearClipPlane;
            RenderingPath    oldRenderPath = gameCamera.renderingPath;

            gameCamera.cullingMask   = 0;
            gameCamera.clearFlags    = CameraClearFlags.Depth;
            gameCamera.farClipPlane  = 1;
            gameCamera.nearClipPlane = 0.1f;
            gameCamera.renderingPath = RenderingPath.DeferredShading;

            gameCamera.AddCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, finalizeFrameCommand);

            gameCamera.targetTexture = Output as RenderTexture;
            gameCamera.aspect        = (float)Output.width / Output.height;
            gameCamera.Render();

            gameCamera.targetTexture = null;

            gameCamera.RemoveCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, finalizeFrameCommand);

            gameCamera.cullingMask   = oldCulling;
            gameCamera.clearFlags    = oldClear;
            gameCamera.farClipPlane  = oldFarClip;
            gameCamera.nearClipPlane = oldNearClip;
            gameCamera.renderingPath = oldRenderPath;
        }
Ejemplo n.º 7
0
    static int IntToEnum(IntPtr L)
    {
        int           arg0 = (int)LuaDLL.lua_tonumber(L, 1);
        RenderingPath o    = (RenderingPath)arg0;

        LuaScriptMgr.PushEnum(L, o);
        return(1);
    }
Ejemplo n.º 8
0
 // The screen-space deferred material needs to use front-face culling so it doesn't
 // vanish when the camera moves within the bounding box
 public override Material ModifyMaterial(Material m, RenderingPath rp)
 {
     if (m.IsKeywordEnabled(ScreenSpace) && rp == RenderingPath.DeferredShading)
     {
         return(GetMaterial(ScreenSpace, "_Cull", (int)UnityEngine.Rendering.CullMode.Front));
     }
     return(m);
 }
Ejemplo n.º 9
0
 public override int[] GetKnownPasses(RenderingPath renderingPath)
 {
     if (renderingPath == RenderingPath.DeferredShading)
     {
         return(deferredPasses);
     }
     return(base.GetKnownPasses(renderingPath));
 }
Ejemplo n.º 10
0
 public CameraSettings()
 {
     _clearFlags       = MainCamera.clearFlags;
     _renderingPath    = MainCamera.renderingPath;
     _occulsionCulling = MainCamera.useOcclusionCulling;
     _hdr  = MainCamera.allowHDR;
     _msaa = MainCamera.allowMSAA;
     _dynamicResolution = MainCamera.allowDynamicResolution;
 }
Ejemplo n.º 11
0
    // Wird aufgerufen sobald das Script aktiviert wird (also schon deutlich vor start())
    private void OnEnable()
    {
        RegisterDebugCallback(new DebugCallback(DebugMethod));
        // Ob Forward oder deferred shading. Da FR aktiviert und deaktiviert werden muss vor und nach dem zeichnen von Geometrie.

        MainCamera = GameObject.Find("Main Camera").GetComponent <Camera>();
        RenderingPath renderPath = MainCamera.actualRenderingPath;

        // Muss aktiviert sein
        if (InitFoveation())
        {
            Debug.Log("Done: Initialiserung Foveation");
        }
        else
        {
            //Debug.Log("Error: Initialiserung Foveation");
        }

        // Forward ist im Projekt
        if (renderPath == RenderingPath.Forward)
        {
            CommandBuffer CbBeforeForwardO = new CommandBuffer();
            CbBeforeForwardO.IssuePluginEvent(GetRenderEventFunc(), (int)FoveationEvent.enableFoveation);
            CbBeforeForwardO.ClearRenderTarget(false, true, Color.black);
            MainCamera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, CbBeforeForwardO);

            CommandBuffer CbAfterForwardO = new CommandBuffer();
            CbAfterForwardO.IssuePluginEvent(GetRenderEventFunc(), (int)FoveationEvent.disableFoveation);
            MainCamera.AddCommandBuffer(CameraEvent.AfterForwardAlpha, CbAfterForwardO);
        }
        else if (renderPath == RenderingPath.DeferredShading)
        {
            CommandBuffer CbBeforeGBuffer = new CommandBuffer();
            CbBeforeGBuffer.IssuePluginEvent(GetRenderEventFunc(), (int)FoveationEvent.enableFoveation);
            CbBeforeGBuffer.ClearRenderTarget(false, true, Color.black);
            MainCamera.AddCommandBuffer(CameraEvent.BeforeGBuffer, CbBeforeGBuffer);

            CommandBuffer CbAfterGBuffer = new CommandBuffer();
            CbAfterGBuffer.IssuePluginEvent(GetRenderEventFunc(), (int)FoveationEvent.disableFoveation);
            MainCamera.AddCommandBuffer(CameraEvent.AfterGBuffer, CbAfterGBuffer);

            CommandBuffer CbBeforeForwardO = new CommandBuffer();
            CbBeforeForwardO.IssuePluginEvent(GetRenderEventFunc(), (int)FoveationEvent.enableFoveation);
            MainCamera.AddCommandBuffer(CameraEvent.BeforeForwardAlpha, CbBeforeForwardO);

            CommandBuffer CbAfterForwardO = new CommandBuffer();
            CbAfterForwardO.IssuePluginEvent(GetRenderEventFunc(), (int)FoveationEvent.disableFoveation);
            MainCamera.AddCommandBuffer(CameraEvent.AfterForwardAlpha, CbAfterForwardO);
        }
        else
        {
            Debug.Log("Diese Plugin Unterstützt nur Forward oder Deffered Shading");
        }
        SetShadingRate(innerShadingRate, middleShadingRate, outerShadingRate);
        SetShadingRadii(innerRadii, middleRadii, outerRadii);
    }
Ejemplo n.º 12
0
 private void OnEnable()
 {
     this.SetGlobalParamsToNull();
     this.m_Camera = (Camera)((Component)this).GetComponent <Camera>();
     if (!Object.op_Implicit((Object)this.m_Camera))
     {
         Debug.LogError((object)("DeepSky::DS_HazeView: GameObject '" + ((Object)((Component)this).get_gameObject()).get_name() + "' does not have a camera component!"));
         ((Behaviour)this).set_enabled(false);
     }
     else if (!this.CheckHasSystemSupport())
     {
         ((Behaviour)this).set_enabled(false);
     }
     else
     {
         if (Object.op_Equality((Object)DS_HazeView.kShader, (Object)null))
         {
             DS_HazeView.kShader = (Shader)Resources.Load <Shader>("DS_Haze");
         }
         if (Object.op_Equality((Object)this.m_Material, (Object)null))
         {
             this.m_Material = new Material(DS_HazeView.kShader);
             ((Object)this.m_Material).set_hideFlags((HideFlags)61);
         }
         if (this.m_Camera.get_actualRenderingPath() == 1 && (this.m_Camera.get_depthTextureMode() & 1) != 1)
         {
             this.m_Camera.set_depthTextureMode((DepthTextureMode)(this.m_Camera.get_depthTextureMode() | 1));
         }
         if (this.m_RenderNonShadowVolumes == null)
         {
             CommandBuffer[] commandBuffers = this.m_Camera.GetCommandBuffers((CameraEvent)12);
             bool            flag           = false;
             foreach (CommandBuffer commandBuffer in commandBuffers)
             {
                 if (commandBuffer.get_name() == DS_HazeView.kRenderLightVolumeCmdBufferName)
                 {
                     this.m_RenderNonShadowVolumes = commandBuffer;
                     flag = true;
                     break;
                 }
             }
             if (!flag)
             {
                 this.m_RenderNonShadowVolumes = new CommandBuffer();
                 this.m_RenderNonShadowVolumes.set_name(DS_HazeView.kRenderLightVolumeCmdBufferName);
                 this.m_Camera.AddCommandBuffer((CameraEvent)12, this.m_RenderNonShadowVolumes);
             }
         }
         this.m_CurrentRadianceTarget  = this.m_RadianceTarget_01;
         this.m_PreviousRadianceTarget = this.m_RadianceTarget_02;
         this.SetSkyboxKeywords();
         this.SetDebugKeywords();
         this.m_ColourSpace        = QualitySettings.get_activeColorSpace();
         this.m_PreviousRenderPath = this.m_Camera.get_actualRenderingPath();
     }
 }
        internal void UpdateCameraDepthBufferCameraEvent(RenderingPath renderingPath)
        {
            camera.RemoveCommandBuffer(m_DepthCommandBufferCameraEvent, depthCommandBuffer);

            if (m_requiresDepthTexture)
            {
                m_DepthCommandBufferCameraEvent = GetAppropriateDepthBufferCameraEvent(renderingPath);
                camera.AddCommandBuffer(m_DepthCommandBufferCameraEvent, depthCommandBuffer);
            }
        }
Ejemplo n.º 14
0
 public void Apply()
 {
     myCam = GetComponent <Camera> ();
     currentUsedRenderingPath = myCam.actualRenderingPath;
     if (EnviroSky.instance.singlePassVR == true)
     {
         CreateSinglePassCameras();
     }
     RefreshCameraCommand();
 }
Ejemplo n.º 15
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;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Format a matrix in the Unity format. This should only be used with projection matrix passing into shaders.
 /// </summary>
 /// <param name="m">The matrix</param>
 /// <returns></returns>
 public static Matrix4x4 FormatProjectionMatrix(Matrix4x4 m, RenderingPath renderingPath)
 {
     if (renderingPath == RenderingPath.DeferredShading)
     {
         for (int i = 0; i < 4; i++)
         {
             m[1, i] = -m[1, i];
         }
     }
 
     return m;
 }
Ejemplo n.º 17
0
    public void renderingPathSliderChanged(float val)
    {
        string[]      renderingPathNames = System.Enum.GetNames(typeof(RenderingPath));
        string        renderingPathName  = renderingPathNames[(int)val];
        RenderingPath rp = (RenderingPath)System.Enum.Parse(typeof(RenderingPath), renderingPathName);

        foreach (GameObject cam in m_camerasObjects)
        {
            cam.GetComponent <Camera>().renderingPath = rp;
        }
        updateRenderingPathName();
    }
Ejemplo n.º 18
0
        private ScriptableRendererData CreateRendererDataAsset(string assetPath, RenderingPath renderingPath,
                                                               string fileName)
        {
            var rendererAsset =
                UniversalRenderPipelineAsset.CreateRendererAsset(assetPath, RendererType.UniversalRenderer, true, fileName)
                as UniversalRendererData;

            //Missing API to set deferred or forward
            rendererAsset.renderingMode =
                renderingPath == RenderingPath.Forward ? RenderingMode.Forward : RenderingMode.Deferred;
            //missing API to assign to pipeline asset
            return(rendererAsset);
        }
Ejemplo n.º 19
0
 static void BackupSettings()
 {
     GetInput("Horizontal");
     GetLayers();
     GetQuality();
     GetBuildSettings();
     initial_RenderPath            = PlayerSettings.renderingPath;
     initial_ColorSpace            = PlayerSettings.colorSpace;
     initial_DefaultIsFullScreen   = PlayerSettings.defaultIsFullScreen;
     initial_APICompatibilityLevel = PlayerSettings.apiCompatibilityLevel;
     initial_CompanyName           = PlayerSettings.companyName;
     initial_ProductName           = PlayerSettings.productName;
 }
        void AddBlitCommand()
        {
            if (gameCamera.actualRenderingPath == RenderingPath.Forward)
            {
                gameCamera.AddCommandBuffer(CameraEvent.AfterForwardOpaque, feedCommand);
            }
            else
            {
                gameCamera.AddCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, feedCommand);
            }

            lastRenderPath = gameCamera.actualRenderingPath;
        }
Ejemplo n.º 21
0
        private RenderingMode GetEquivalentRenderMode(RenderingPath path)
        {
            switch (path)
            {
            case RenderingPath.VertexLit:
            case RenderingPath.Forward:
                return(RenderingMode.Forward);

            case RenderingPath.DeferredShading:
                return(RenderingMode.Deferred);

            default:
                return(RenderingMode.Forward);
            }
        }
Ejemplo n.º 22
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;
        }
Ejemplo n.º 23
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;
    }
Ejemplo n.º 24
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;
        }
Ejemplo n.º 25
0
        private void SoftParticlesHintGUI()
        {
            Camera main = Camera.main;

            if (!(main == null))
            {
                RenderingPath actualRenderingPath = main.actualRenderingPath;
                if (actualRenderingPath != RenderingPath.DeferredLighting && actualRenderingPath != RenderingPath.DeferredShading)
                {
                    if ((main.depthTextureMode & DepthTextureMode.Depth) == DepthTextureMode.None)
                    {
                        EditorGUILayout.HelpBox(QualitySettingsEditor.Styles.kSoftParticlesHint.text, MessageType.Warning, false);
                    }
                }
            }
        }
Ejemplo n.º 26
0
        void OnPrecull(Camera camera)
        {
            //	In case we use Metal and deferred shading reading and writing to the depth buffer makes water vanishing. So we do a copy of the depth buffer.
            if (GrabDepthTexture)
            {
                RenderingPath path = cam.actualRenderingPath;
                //	Only needed if we use metal and deferred
                if (path == RenderingPath.DeferredShading && SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal)
                {
                    CommandBuffer cBuffer;
                    if (!m_cmdBuffer.TryGetValue(camera, out cBuffer))
                    {
                        cBuffer      = new CommandBuffer();
                        cBuffer.name = "Lux Water Grab Depth";
                        //  This adds it to the lighting of the second camera?
                        //	camera.AddCommandBuffer(CameraEvent.AfterLighting, cBuffer);
                        //	This seems to work as the 2nd camera does not render a skybox
                        camera.AddCommandBuffer(CameraEvent.BeforeSkybox, cBuffer);
                        m_cmdBuffer[camera] = cBuffer;
                    }

                    cBuffer.Clear();
                    var width       = camera.pixelWidth;
                    var height      = camera.pixelHeight;
                    int depthGrabID = Shader.PropertyToID("_Lux_GrabbedDepth");
                    cBuffer.GetTemporaryRT(depthGrabID, width, height, 0, FilterMode.Point, format, RenderTextureReadWrite.Linear);
                    cBuffer.Blit(BuiltinRenderTextureType.CurrentActive, depthGrabID, CopyDepthMat, 0);

                    //Shader.EnableKeyword("LUXWATERMETALDEFERRED");
                }
                else
                {
                    GrabDepthTexture = false;
                    foreach (var cam in m_cmdBuffer)
                    {
                        if (cam.Key != null)
                        {
                            cam.Key.RemoveCommandBuffer(CameraEvent.AfterLighting, cam.Value);
                        }
                    }
                    m_cmdBuffer.Clear();
                    ShowShaderWarning = true;

                    //Shader.DisableKeyword("LUXWATERMETALDEFERRED");
                }
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Returns what camera event the command should run
        /// at depending on the cameras rendering mode.
        /// </summary>
        CameraEvent GetCommandEvent(Camera cam)
        {
            RenderingPath path = cam.actualRenderingPath;

            if (path == RenderingPath.DeferredShading)
            {
                return(DEFERRED_EVENT);
            }
            else if (path == RenderingPath.DeferredLighting)
            {
                return(LEGACY_DEFERRED_EVENT);
            }
            else
            {
                return(FORWARD_EVENT);
            }
        }
 public void CopyFrom(Camera camera)
 {
     this.clearFlags          = camera.clearFlags;
     this.backgroundColor     = camera.backgroundColor;
     this.cullingMask         = camera.cullingMask;
     this.orthographic        = camera.orthographic;
     this.orthographicSize    = camera.orthographicSize;
     this.fieldOfView         = camera.fieldOfView;
     this.nearClipPlane       = camera.nearClipPlane;
     this.farClipPlane        = camera.farClipPlane;
     this.rect                = camera.rect;
     this.depth               = camera.depth;
     this.renderingPath       = camera.renderingPath;
     this.targetTexture       = camera.targetTexture;
     this.useOcclusionCulling = camera.useOcclusionCulling;
     this.hdr = camera.hdr;
 }
 public void CopyFrom(Camera camera)
 {
     this.clearFlags = camera.clearFlags;
     this.backgroundColor = camera.backgroundColor;
     this.cullingMask = camera.cullingMask;
     this.orthographic = camera.orthographic;
     this.orthographicSize = camera.orthographicSize;
     this.fieldOfView = camera.fieldOfView;
     this.nearClipPlane = camera.nearClipPlane;
     this.farClipPlane = camera.farClipPlane;
     this.rect = camera.rect;
     this.depth = camera.depth;
     this.renderingPath = camera.renderingPath;
     this.targetTexture = camera.targetTexture;
     this.useOcclusionCulling = camera.useOcclusionCulling;
     this.hdr = camera.hdr;
 }
Ejemplo n.º 30
0
 private void UpdateMaterialProperties()
 {
     if (this.noiseTex == null || this._quality != this.generalSettings.quality || this._noiseType != this.generalSettings.noiseType)
     {
         if (this.noiseTex != null)
         {
             UnityEngine.Object.DestroyImmediate(this.noiseTex);
         }
         float num = (float)((this.generalSettings.noiseType != HBAO.NoiseType.Dither) ? 64 : 4);
         this.CreateRandomTexture((int)num);
     }
     this._quality              = this.generalSettings.quality;
     this._noiseType            = this.generalSettings.noiseType;
     this._radius               = this.aoSettings.radius;
     this._maxRadiusPixels      = this.aoSettings.maxRadiusPixels;
     this._bias                 = this.aoSettings.bias;
     this._intensity            = this.aoSettings.intensity;
     this._luminanceInfluence   = this.aoSettings.luminanceInfluence;
     this._maxDistance          = this.aoSettings.maxDistance;
     this._distanceFalloff      = this.aoSettings.distanceFalloff;
     this._perPixelNormals      = this.aoSettings.perPixelNormals;
     this._aoBaseColor          = this.aoSettings.baseColor;
     this._colorBleedingEnabled = this.colorBleedingSettings.enabled;
     this._colorBleedSaturation = this.colorBleedingSettings.saturation;
     this._albedoMultiplier     = this.colorBleedingSettings.albedoMultiplier;
     this._blurAmount           = this.blurSettings.amount;
     this._blurSharpness        = this.blurSettings.sharpness;
     this._renderingPath        = this._hbaoCamera.renderingPath;
     this._hbaoMaterial.SetTexture("_NoiseTex", this.noiseTex);
     this._hbaoMaterial.SetFloat("_NoiseTexSize", (float)((this._noiseType != HBAO.NoiseType.Dither) ? 64 : 4));
     this._hbaoMaterial.SetFloat("_Radius", this._radius);
     this._hbaoMaterial.SetFloat("_MaxRadiusPixels", this._maxRadiusPixels);
     this._hbaoMaterial.SetFloat("_NegInvRadius2", -1f / (this._radius * this._radius));
     this._hbaoMaterial.SetFloat("_AngleBias", this._bias);
     this._hbaoMaterial.SetFloat("_AOmultiplier", 2f * (1f / (1f - this._bias)));
     this._hbaoMaterial.SetFloat("_Intensity", this._intensity);
     this._hbaoMaterial.SetFloat("_LuminanceInfluence", this._luminanceInfluence);
     this._hbaoMaterial.SetFloat("_MaxDistance", this._maxDistance);
     this._hbaoMaterial.SetFloat("_DistanceFalloff", this._distanceFalloff);
     this._hbaoMaterial.SetColor("_BaseColor", this._aoBaseColor);
     this._hbaoMaterial.SetFloat("_ColorBleedSaturation", this._colorBleedSaturation);
     this._hbaoMaterial.SetFloat("_AlbedoMultiplier", this._albedoMultiplier);
     this._hbaoMaterial.SetFloat("_BlurSharpness", this._blurSharpness);
 }
    public void RenderStereoAlbedo()
    {
        Camera camera = GetComponent <Camera>();

        // Remember camera config parameters
        RenderingPath path = camera.renderingPath;

        // Setup camera for albedo stereo rendering
        camera.stereoSeparation = 0.064f;
        camera.SetReplacementShader(null, "RenderType");
        camera.renderingPath = RenderingPath.Forward;

        // Render stero texture
        RenderCubemap(camera, "_albedo");

        // Restore camera config parameters
        camera.SetReplacementShader(null, "RenderType");
        camera.renderingPath = RenderingPath.UsePlayerSettings;
    }
Ejemplo n.º 32
0
 private void RenderPathChanged()
 {
     if (this.m_Camera.get_actualRenderingPath() == 1 && (this.m_Camera.get_depthTextureMode() & 1) != 1)
     {
         this.m_Camera.set_depthTextureMode((DepthTextureMode)(this.m_Camera.get_depthTextureMode() | 1));
     }
     if (this.m_ClearRadianceCmdBuffer != null)
     {
         CameraEvent cameraEvent = this.m_PreviousRenderPath != 3 ? ((this.m_Camera.get_depthTextureMode() & 2) != 2 ? (CameraEvent)0 : (CameraEvent)2) : (CameraEvent)4;
         foreach (CommandBuffer commandBuffer in this.m_Camera.GetCommandBuffers(cameraEvent))
         {
             if (commandBuffer.get_name() == DS_HazeView.kClearRadianceCmdBufferName)
             {
                 this.m_Camera.RemoveCommandBuffer(cameraEvent, commandBuffer);
                 break;
             }
         }
     }
     this.m_PreviousRenderPath = this.m_Camera.get_actualRenderingPath();
 }
Ejemplo n.º 33
0
 private static bool IsDeferredRenderingPath(RenderingPath rp)
 {
     return ((rp == RenderingPath.DeferredLighting) || (rp == RenderingPath.DeferredShading));
 }
 internal RenderingPath RenderingPathPopup(RenderingPath rp)
 {
     return (RenderingPath) EditorGUILayout.IntPopup((int) rp, Styles.renderingPathName, Styles.renderingPathValue, new GUILayoutOption[0]);
 }
Ejemplo n.º 35
0
 private void UpdateMaterialProperties()
 {
     if (this.noiseTex == null || this._quality != this.generalSettings.quality || this._noiseType != this.generalSettings.noiseType)
     {
         if (this.noiseTex != null)
         {
             UnityEngine.Object.DestroyImmediate(this.noiseTex);
         }
         float num = (float)((this.generalSettings.noiseType != HBAO.NoiseType.Dither) ? 64 : 4);
         this.CreateRandomTexture((int)num);
     }
     this._quality = this.generalSettings.quality;
     this._noiseType = this.generalSettings.noiseType;
     this._radius = this.aoSettings.radius;
     this._maxRadiusPixels = this.aoSettings.maxRadiusPixels;
     this._bias = this.aoSettings.bias;
     this._intensity = this.aoSettings.intensity;
     this._luminanceInfluence = this.aoSettings.luminanceInfluence;
     this._maxDistance = this.aoSettings.maxDistance;
     this._distanceFalloff = this.aoSettings.distanceFalloff;
     this._perPixelNormals = this.aoSettings.perPixelNormals;
     this._aoBaseColor = this.aoSettings.baseColor;
     this._colorBleedingEnabled = this.colorBleedingSettings.enabled;
     this._colorBleedSaturation = this.colorBleedingSettings.saturation;
     this._albedoMultiplier = this.colorBleedingSettings.albedoMultiplier;
     this._blurAmount = this.blurSettings.amount;
     this._blurSharpness = this.blurSettings.sharpness;
     this._renderingPath = this._hbaoCamera.renderingPath;
     this._hbaoMaterial.SetTexture("_NoiseTex", this.noiseTex);
     this._hbaoMaterial.SetFloat("_NoiseTexSize", (float)((this._noiseType != HBAO.NoiseType.Dither) ? 64 : 4));
     this._hbaoMaterial.SetFloat("_Radius", this._radius);
     this._hbaoMaterial.SetFloat("_MaxRadiusPixels", this._maxRadiusPixels);
     this._hbaoMaterial.SetFloat("_NegInvRadius2", -1f / (this._radius * this._radius));
     this._hbaoMaterial.SetFloat("_AngleBias", this._bias);
     this._hbaoMaterial.SetFloat("_AOmultiplier", 2f * (1f / (1f - this._bias)));
     this._hbaoMaterial.SetFloat("_Intensity", this._intensity);
     this._hbaoMaterial.SetFloat("_LuminanceInfluence", this._luminanceInfluence);
     this._hbaoMaterial.SetFloat("_MaxDistance", this._maxDistance);
     this._hbaoMaterial.SetFloat("_DistanceFalloff", this._distanceFalloff);
     this._hbaoMaterial.SetColor("_BaseColor", this._aoBaseColor);
     this._hbaoMaterial.SetFloat("_ColorBleedSaturation", this._colorBleedSaturation);
     this._hbaoMaterial.SetFloat("_AlbedoMultiplier", this._albedoMultiplier);
     this._hbaoMaterial.SetFloat("_BlurSharpness", this._blurSharpness);
 }
Ejemplo n.º 36
0
  private void UpdateBuffer()
  {
    // copy settings from main camera in case of changes
    m_bufferCam.CopyFrom(SceneCamera);

    var rect = m_bufferCam.rect;
    rect.width = 1.0f;
    rect.x = 0.0f;
    m_bufferCam.rect = rect;

    m_bufferCam.depthTextureMode |= DepthTextureMode.Depth;

    // update frustum rays
    SetFrustumRays();

    // update matrices
    m_matViewProjInverse = (m_bufferCam.projectionMatrix * m_bufferCam.worldToCameraMatrix).inverse;
    m_normalMatrix = m_bufferCam.worldToCameraMatrix.inverse.transpose;

    // save current tagret texture
    var texTmp = m_bufferCam.targetTexture;

    // save current rendering path
    var pathTmp = m_bufferCam.renderingPath;

    // generate buffer always in forward
    m_bufferCam.renderingPath = RenderingPath.Forward;

    // account for linear / gamma space
    var linearPow = LinearColorSpace ? 2.2f : 1.0f;
    Shader.SetGlobalFloat("_LinearPow", linearPow);

    // fill albedo buffer
    m_bufferCam.targetTexture = m_albedoBuffer;
    m_bufferCam.RenderWithShader(m_albedoMaterial.shader, "RenderType");

    // fill transparency buffer
    m_bufferCam.targetTexture = m_transparencyBuffer;
    m_bufferCam.RenderWithShader(m_transparencyMaterial.shader, "RenderType");

    // generate normals
    m_bufferCam.targetTexture = m_normalBuffer;
    m_bufferCam.RenderWithShader(m_normalMaterial.shader, "RenderType");

    // restore rendering path
    m_bufferCam.renderingPath = pathTmp;

    // restore previous target texture
    m_bufferCam.targetTexture = texTmp;

    // if dimensions have changed, update render buffers dimensions
    if (m_screenDim.x != Screen.width || m_screenDim.y != Screen.height)
    {
      m_screenDim = new Vector2(Screen.width, Screen.height);

      DestroyImmediate(m_albedoBuffer);
      m_albedoBuffer = new RenderTexture(Screen.width, Screen.height, 24);

      DestroyImmediate(m_transparencyBuffer);
      m_transparencyBuffer = new RenderTexture(Screen.width, Screen.height, 24);

      DestroyImmediate(m_normalBuffer);
      m_normalBuffer = new RenderTexture(Screen.width, Screen.height, 24);
    }

    // rendering path changed?
    if (m_currentRenderingPath != SceneCamera.renderingPath)
    {
      // memorize rendering path
      m_currentRenderingPath = SceneCamera.renderingPath;
      foreach (var light in m_areaLightList)
      {
        if (light == null || !light.active)
        {
          continue;
        }

        var tmp = light.GetComponent<AreaLight>();
        tmp.PickMaterial();
      }

      if (m_currentRenderingPath == RenderingPath.DeferredLighting)
      {
        Shader.DisableKeyword("FORWARD");
        Shader.EnableKeyword("DEFERRED");
      }
      else
      {
        Shader.DisableKeyword("DEFERRED");
        Shader.EnableKeyword("FORWARD");
      }
    }
  }
Ejemplo n.º 37
0
  void InitCamera()
  {
    SceneCamera = GetComponent<Camera>();

    // setup separate camera for render buffer
    var camTrans = transform.FindChild("CamNode");
    if (camTrans != null)
    {
      DestroyImmediate(camTrans.gameObject);
    }

    var camNode = new GameObject("CamNode");
    camNode.transform.parent = transform;
    m_bufferCam = camNode.AddComponent<Camera>();
    m_bufferCam.CopyFrom(SceneCamera);
    m_bufferCam.enabled = false;

    if (m_bufferCam == null)
    {
      Debug.LogError("Camera must not be null!");
    }
    m_bufferCam.depthTextureMode |= DepthTextureMode.Depth;

    // default forward rendering
    if (m_bufferCam.renderingPath == RenderingPath.UsePlayerSettings)
    {
      m_bufferCam.renderingPath = RenderingPath.Forward;
    }
    // memorize rendering path
    m_currentRenderingPath = m_bufferCam.renderingPath;

    // set initial frustum rays
    SetFrustumRays();
  }