Example #1
0
    public RenderTexture RenderPhoto(int w, int h, SuperSampling ss, int bpc)
    {
        var canvasFormat  = (bpc == 8) ? RenderTextureFormat.ARGB32 : RenderTextureFormat.ARGBFloat;
        var canvasTexture = new RenderTexture(new RenderTextureDescriptor(w, h, canvasFormat));

        canvasTexture.Create();

        // Set up a special camera to capture the photo. Same settings as main camera, but different target.
        //var cam = new Camera();
        //cam.orthographicSize = 2;
        saveCam.targetTexture    = canvasTexture;
        saveCam.projectionMatrix = _cam.projectionMatrix;
        //_renderer.PurgeCache
        var saveProj = saveCam.projectionMatrix;
        var camProj  = _cam.projectionMatrix;

        PublishRenderer.Render(Fractal, saveCam, _pool, (int)ss);
        //GL.Flush();
        saveCam.targetTexture = null;
        //GL.InvalidateState();

        return(canvasTexture);
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        standardAA = gameObject.AddComponent<Antialiasing>();
        standardAA.ssaaShader = Shader.Find("Hidden/SSAA");
        standardAA.dlaaShader = Shader.Find("Hidden/DLAA");
        standardAA.nfaaShader = Shader.Find("Hidden/NFAA");
        standardAA.shaderFXAAPreset2 = Shader.Find("Hidden/FXAA Preset 2");
        standardAA.shaderFXAAPreset3 = Shader.Find("Hidden/FXAA Preset 3");
        standardAA.shaderFXAAII = Shader.Find("Hidden/FXAA II");
        standardAA.shaderFXAAIII = Shader.Find("Hidden/FXAA III (Console)");

        cinematicAA = gameObject.AddComponent<AntiAliasing>();
        temporalAA = gameObject.AddComponent<TemporalAntiAliasing>();
        samplingAA = gameObject.AddComponent<SuperSampling>();
    }
Example #3
0
    public void Start()
    {
        screenWidth = Screen.width;
        screenHeight = Screen.height;
        int num = (int)((float)Screen.width * scaleWidth);
        int num2 = (int)((float)Screen.height * scaleHeight);

        if (renderTexture == null || renderTexture.width != num || renderTexture.height != num2) {
            if (renderTexture != null) {
                renderTexture.Release();
            }
            renderTexture = new RenderTexture(num, num2, 24, 0);
            renderTexture.name = "SamplingTexture";
        }

        instance = this;

        if (renderCam == null) {
            renderCam = new GameObject("SamplingCamera");
            Camera camera = renderCam.AddComponent<Camera>();
            camera.CopyFrom(camara);
            camera.cullingMask = 0;
            camera.targetTexture = null;
            textureRenderer = renderCam.AddComponent<TextureRenderer>();

            if (SamplingShader != null) {
                switch (filter) {
                    case 0:
                        textureRenderer.samplingMaterial = new Material(SamplingShader[0]);
                        break;
                    case 1:
                        textureRenderer.samplingMaterial = new Material(SamplingShader[1]);
                        break;
                    case 2:
                        textureRenderer.samplingMaterial = null;
                        break;
                }
            }
        }
        active = true;
    }
Example #4
0
    public void Stop()
    {
        if (camara != null && camara.targetTexture != null) {
            camara.targetTexture = null;
        }

        active = false;
        instance = null;
        if (instance == null) {
            if (renderCam != null) {
                Destroy(renderCam);
                renderCam = null;
            }

            if (renderTexture != null) {
                renderTexture.Release();
                renderTexture = null;
            }
        }
    }
Example #5
0
    private void UpdateDynamicResolution()
    {
        if (!m_DynamicResolutionEnabled) {
            return;
        }

        if (m_LastQualityFrameCount == Time.frameCount)
            return;
        m_LastQualityFrameCount = Time.frameCount;

        int oldResolutionLevel = m_DynamicResolutionLevel;

        // Añadir la ultima medición al buffer
        int bufferSize = m_DynamicResolutionBuffer.GetLength(0);
        m_DynamicResolutiongBufferPos = (m_DynamicResolutiongBufferPos + 1) % bufferSize;
        m_DynamicResolutionBuffer[m_DynamicResolutiongBufferPos] = Time.deltaTime * 1000.0f;

        // Milisegundos que tarda un frame
        float singleFrameMs = (Screen.currentResolution.refreshRate > 0.0f) ? (1000.0f / Screen.currentResolution.refreshRate) : (1000.0f / 60.0f);

        // Limites de tiempo (en milisegundos) de los frames
        //float lowFrameMs = 0.8f * singleFrameMs;
        float extrapolationFrameMs = 1f * singleFrameMs;
        float highFrameMs = 1.2f * singleFrameMs;

        // Ultimos 3 frames
        float frame0 = m_DynamicResolutionBuffer[(m_DynamicResolutiongBufferPos - 0 + bufferSize) % bufferSize];
        float frame1 = m_DynamicResolutionBuffer[(m_DynamicResolutiongBufferPos - 1 + bufferSize) % bufferSize];
        float frame2 = m_DynamicResolutionBuffer[(m_DynamicResolutiongBufferPos - 2 + bufferSize) % bufferSize];

        // Reducir la resolucion siempre 2 niveles excepto cuando se cae del nivel 2
        int resolutionLevelDropTarget = (oldResolutionLevel == 2) ? 1 : (oldResolutionLevel - 2);

        // Reducir la resolucion 2 niveles si el ultimo frame es critico
        if (Time.frameCount >= m_DynamicResolutionFrameCountLastChanged + 2 + 1) {
            if (frame0 > highFrameMs) {
                int newLevel = Mathf.Clamp(resolutionLevelDropTarget, 0, m_DynamicResolutionScaleArray.Count - 1);
                if (newLevel != oldResolutionLevel) {
                    if (debug)
                        Debug.Log( "CAIDA CRITICA nivel " + newLevel + ". Frames = " + frame2 + "ms, " + frame1 + "ms, " + frame0 + "ms > " + highFrameMs + "\n" );
                    m_DynamicResolutionLevel = newLevel;
                    m_DynamicResolutionFrameCountLastChanged = Time.frameCount;
                    return;
                }
            }
        }

        // Reducir la resolucion 2 niveles si los ultimos 3 frames son caros
        if (Time.frameCount >= m_DynamicResolutionFrameCountLastChanged + 2 + 3) {
            if ((frame0 > highFrameMs) && (frame1 > highFrameMs) &&  (frame2 > highFrameMs)) {
                int newLevel = Mathf.Clamp(resolutionLevelDropTarget, 0, m_DynamicResolutionScaleArray.Count - 1);
                if (newLevel != oldResolutionLevel) {
                    if (debug)
                        Debug.Log("CAIDA MAXIMA nivel " + newLevel + ". Frames = " + frame2 + "ms, " + frame1 + "ms, " + frame0 + "ms > " + highFrameMs + "\n" );
                    m_DynamicResolutionLevel = newLevel;
                    m_DynamicResolutionFrameCountLastChanged = Time.frameCount;
                }
            }
        }

        // Pedrecir el coste del siguiente frame usando interpolacion lineal: max( frame-1 a frame+1, frame-2 a frame+1 )
        if (Time.frameCount >= m_DynamicResolutionFrameCountLastChanged + 2 + 2) {
            if (frame0 > extrapolationFrameMs) {
                float delta = frame0 - frame1;

                // Usar frame-2 si esta disponible
                if (Time.frameCount >= m_DynamicResolutionFrameCountLastChanged + 2 + 3) {
                    float delta2 = (frame0 - frame2) * 0.5f;
                    delta = Mathf.Max(delta, delta2);
                }

                if ((frame0 + delta) > highFrameMs) {
                    int newLevel = Mathf.Clamp(resolutionLevelDropTarget, 0, m_DynamicResolutionScaleArray.Count - 1);
                    if (newLevel != oldResolutionLevel) {
                        if (debug)
                            Debug.Log("CAIDA PREDECIDA nivel " + newLevel + ". Frames = " + frame2 + "ms, " + frame1 + "ms, " + frame0 + "ms > " + highFrameMs + "\n" );
                        m_DynamicResolutionLevel = newLevel;
                        m_DynamicResolutionFrameCountLastChanged = Time.frameCount;
                    }
                }
            }
        }

        // Aumentar la resolucion si los ultimos 3 frames son baratos
        if (Time.frameCount >= m_DynamicResolutionFrameCountLastChanged + 2 + 3) {
            if ((frame0 < highFrameMs) && (frame1 < highFrameMs) && (frame2 < highFrameMs)) {
                int newLevel = Mathf.Clamp(oldResolutionLevel + 1, 0, m_DynamicResolutionScaleArray.Count - 1);
                if (newLevel != oldResolutionLevel) {
                    if (debug)
                        Debug.Log("SUBIDA MINIMA nivel " + newLevel + ". Frames = " + frame2 + "ms, " + frame1 + "ms, " + frame0 + "ms < " + highFrameMs + "\n" );
                    m_DynamicResolutionLevel = newLevel;
                    m_DynamicResolutionFrameCountLastChanged = Time.frameCount;
                }
            }
        }

        if (superSampling != null) {
            superSampling.scaleHeight = m_DynamicResolutionScaleArray[m_DynamicResolutionLevel];
            superSampling.scaleWidth = m_DynamicResolutionScaleArray[m_DynamicResolutionLevel];
            superSampling.filter = 1;

            // Aplicar el nuevo nivel solo si ha cambiado
            if (m_DynamicResolutionLevel != oldResolutionLevel)
                superSampling.restart = true;
        }
        else {
            superSampling = GetComponent<SuperSampling>();
            superSampling.enabled = true;
        }
    }
Example #6
0
 void OnEnable()
 {
     superSampling = GetComponent<SuperSampling>();
     StartDynamicResolution();
 }