Esempio n. 1
0
 public void SetUp(RenderTargetHandle colorHandle, RenderTexture texture,
                   ref LookingGlassRenderingInfo dinfo, ref LookingGlassDeviceConfig dconfig)
 {
     this.colorAttachmentHandle = colorHandle;
     tiledTexture = texture;
     drawInfo     = dinfo;
     deviceConfig = dconfig;
 }
Esempio n. 2
0
        public void PassConfigToMaterial()
        {
            float screenInches = (float)deviceConfig.screenW / deviceConfig.DPI;
            float newPitch     = deviceConfig.pitch * screenInches;

            newPitch *= Mathf.Cos(Mathf.Atan(1f / deviceConfig.slope));
            lenticularMat.SetFloat("pitch", newPitch);

            float newTilt = deviceConfig.screenH / (deviceConfig.screenW * deviceConfig.slope);

            newTilt *= LookingGlassDeviceConfig.AsBool(deviceConfig.flipImageX) ? -1 : 1;
            lenticularMat.SetFloat("tilt", newTilt);

            float newCenter = deviceConfig.center;

            newCenter += LookingGlassDeviceConfig.AsBool(deviceConfig.flipImageX) ? 0.5f : 0;
            lenticularMat.SetFloat("center", newCenter);
            lenticularMat.SetFloat("invView", deviceConfig.invView);
            lenticularMat.SetFloat("flipX", deviceConfig.flipImageX);
            lenticularMat.SetFloat("flipY", deviceConfig.flipImageY);

            float subp = 1f / (deviceConfig.screenW * 3f);

            subp *= LookingGlassDeviceConfig.AsBool(deviceConfig.flipImageX) ? -1 : 1;
            lenticularMat.SetFloat("subp", subp);

            lenticularMat.SetInt("ri", !LookingGlassDeviceConfig.AsBool(deviceConfig.flipSubp) ? 0 : 2);
            lenticularMat.SetInt("bi", !LookingGlassDeviceConfig.AsBool(deviceConfig.flipSubp) ? 2 : 0);

            float portionX = 1.0f;
            float portionY = 1.0f;

            drawInfo.CalculatePortion(out portionX, out portionY);

            lenticularMat.SetVector("tile", new Vector4(
                                        drawInfo.tileX,
                                        drawInfo.tileY,
                                        portionX,
                                        portionY
                                        ));
            bool overscan = false;

            lenticularMat.SetVector("aspect", new Vector4(
                                        deviceConfig.screenW / deviceConfig.screenH,
                                        deviceConfig.screenW / deviceConfig.screenH,
                                        overscan ? 1 : 0
                                        ));
        }
Esempio n. 3
0
        public void Setup(ScriptableRenderer renderer, ref RenderingData renderingData)
        {
            Init();

            Camera camera = renderingData.cameraData.camera;

            renderer.SetupPerObjectLightIndices(ref renderingData.cullResults, ref renderingData.lightData);
            RenderTextureDescriptor baseDescriptor   = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData);
            RenderTextureDescriptor shadowDescriptor = baseDescriptor;
            ClearFlag clearFlag = ScriptableRenderer.GetCameraClearFlag(renderingData.cameraData.camera);

            shadowDescriptor.dimension = TextureDimension.Tex2D;

            bool requiresRenderToTexture = ScriptableRenderer.RequiresIntermediateColorTexture(ref renderingData.cameraData, baseDescriptor);

            RenderTargetHandle colorHandle = RenderTargetHandle.CameraTarget;
            RenderTargetHandle depthHandle = RenderTargetHandle.CameraTarget;

            if (requiresRenderToTexture)
            {
                colorHandle = ColorAttachment;
                depthHandle = DepthAttachment;

                var sampleCount = (SampleCount)renderingData.cameraData.msaaSamples;
                m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount);
                renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass);
            }


            bool mainLightShadows = false;

            if (renderingData.shadowData.supportsMainLightShadows)
            {
                mainLightShadows = m_MainLightShadowCasterPass.Setup(MainLightShadowmap, ref renderingData);
                if (mainLightShadows)
                {
                    renderer.EnqueuePass(m_MainLightShadowCasterPass);
                }
            }



            renderer.EnqueuePass(m_SetupForwardRenderingPass);


            RendererConfiguration rendererConfiguration = ScriptableRenderer.GetRendererConfiguration(renderingData.lightData.additionalLightsCount);

            m_SetupLightweightConstants.Setup(renderer.maxVisibleAdditionalLights, renderer.perObjectLightIndices);
            renderer.EnqueuePass(m_SetupLightweightConstants);
            // GameView at LGRP
            if (!renderingData.cameraData.isSceneViewCamera)
            {
                LookingGlassRenderingInfo       info = renderingData.cameraData.lookingGlassInfo;
                LookingGlassDeviceConfig        config;
                LookingGlassRenderInfoPerCamera perCameraInfo;

                var cameraDeviceInfo = camera.GetComponent <LookingGlassCameraInfo>();
                if (cameraDeviceInfo != null)
                {
                    config        = cameraDeviceInfo.config;
                    perCameraInfo = cameraDeviceInfo.renderInfo;
                }
                else
                {
                    config = new LookingGlassDeviceConfig();
                    config.SetUpDefault();
                    perCameraInfo = new LookingGlassRenderInfoPerCamera();
                    perCameraInfo.SetupDefault();
                }

                int depthValue = (info.renderMethod == LookingGlassRenderingInfo.RenderingMethod.RenderMultiPass) ? 0 : 32;
                if (tileTexture != null && oldLookingRenderInfo.HaveToRemakeRenderTexture(ref info))
                {
                    tileTexture.Release();
                    tileTexture = null;
                    Debug.Log("Recreate RenderTexture");
                }

                if (tileTexture == null || !tileTexture)
                {
                    tileTexture      = new RenderTexture(info.renderTargetW, info.renderTargetH, depthValue);
                    tileTexture.name = "LookingGlassQuiltTexture";
                }

                // tile texture draw( changed by method)
                switch (info.renderMethod)
                {
                case LookingGlassRenderingInfo.RenderingMethod.RenderMultiPass:
                    m_LookingMultiTexturePass.Setup(tileTexture, ref info, ref perCameraInfo);
                    renderer.EnqueuePass(m_LookingMultiTexturePass);
                    break;

                case LookingGlassRenderingInfo.RenderingMethod.RenderSinglePassInstancing:
                    m_LookingInstancingRenderPass.Setup(tileTexture, ref info, ref perCameraInfo);
                    renderer.EnqueuePass(m_LookingInstancingRenderPass);
                    break;
                }

                m_LookingFinalPass.SetUp(colorHandle, tileTexture, ref info, ref config);
                renderer.EnqueuePass(m_LookingFinalPass);
                // info setup
                oldLookingRenderInfo = info;
            }
            // SceneView
            else
            {
                m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, clearFlag, camera.backgroundColor, rendererConfiguration);
                renderer.EnqueuePass(m_RenderOpaqueForwardPass);
                if (camera.clearFlags == CameraClearFlags.Skybox && RenderSettings.skybox != null)
                {
                    m_DrawSkyboxPass.Setup(colorHandle, depthHandle);
                    renderer.EnqueuePass(m_DrawSkyboxPass);
                }
                m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, rendererConfiguration);
                renderer.EnqueuePass(m_RenderTransparentForwardPass);
                if (!renderingData.cameraData.isOffscreenRender && colorHandle != RenderTargetHandle.CameraTarget)
                {
                    m_FinalBlitPass.Setup(baseDescriptor, colorHandle);
                    renderer.EnqueuePass(m_FinalBlitPass);
                }
            }

#if UNITY_EDITOR
            if (renderingData.cameraData.isSceneViewCamera)
            {
                m_SceneViewDepthCopyPass.Setup(DepthTexture);
                renderer.EnqueuePass(m_SceneViewDepthCopyPass);
            }
#endif
        }