public MainMenuRenderSetup()
        {
            // Shaders
            lastResizeMode = SettingsCache.Resize;

            try {
                switch (lastResizeMode)
                {
                default:
                case SettingsCache.ResizeMode.None:
                    resizeShader = DrawTechnique.Solid;
                    break;

                case SettingsCache.ResizeMode.HQ2x:
                    resizeShader = ContentResolver.Current.RequestShader("ResizeHQ2x");
                    break;

                case SettingsCache.ResizeMode.xBRZ3:
                    resizeShader = ContentResolver.Current.RequestShader("Resize3xBRZ");
                    break;

                case SettingsCache.ResizeMode.xBRZ4:
                    resizeShader = ContentResolver.Current.RequestShader("Resize4xBRZ");
                    break;

                case SettingsCache.ResizeMode.CRT:
                    resizeShader = ContentResolver.Current.RequestShader("ResizeCRT");
                    break;

                case SettingsCache.ResizeMode.GB:
                    resizeShader = ContentResolver.Current.RequestShader("ResizeGB");
                    break;
                }
            } catch {
                resizeShader = DrawTechnique.Solid;
            }

            // Textures
            finalTexture = new Texture(null, TextureSizeMode.NonPowerOfTwo, TextureMagFilter.Nearest, TextureMinFilter.Nearest);

            finalTarget = new RenderTarget(AAQuality.Off, false, finalTexture);

            // Render steps
            AddRenderStep(RenderStepPosition.Last, new RenderStep {
                Projection     = ProjectionMode.Screen,
                VisibilityMask = VisibilityFlag.All,
                ClearFlags     = ClearFlag.None,

                Output = finalTarget
            });

            AddRenderStep(RenderStepPosition.Last, new RenderStep {
                Id = "Resize",

                Projection     = ProjectionMode.Screen,
                VisibilityMask = VisibilityFlag.None
            });
        }
Beispiel #2
0
        public LevelRenderSetup(LevelHandler levelHandler)
        {
            this.levelHandler = levelHandler;

            // Shaders
            ContentRef <DrawTechnique> lightingShader      = ContentResolver.Current.RequestShader("Lighting");
            ContentRef <DrawTechnique> lightingNoiseShader = ContentResolver.Current.RequestShader("LightingNoise");

#if !__ANDROID__
            downsampleShader = ContentResolver.Current.RequestShader("Downsample");
            blurShader       = ContentResolver.Current.RequestShader("Blur");
#endif
            combineSceneShader      = ContentResolver.Current.RequestShader("CombineScene");
            combineSceneWaterShader = ContentResolver.Current.RequestShader("CombineSceneWater");

            lastResizeMode = SettingsCache.Resize;

            try {
                switch (lastResizeMode)
                {
                default:
                case SettingsCache.ResizeMode.None:
                    resizeShader = DrawTechnique.Solid;
                    break;

                case SettingsCache.ResizeMode.HQ2x:
                    resizeShader = ContentResolver.Current.RequestShader("ResizeHQ2x");
                    break;

                case SettingsCache.ResizeMode.xBRZ3:
                    resizeShader = ContentResolver.Current.RequestShader("Resize3xBRZ");
                    break;

                case SettingsCache.ResizeMode.xBRZ4:
                    resizeShader = ContentResolver.Current.RequestShader("Resize4xBRZ");
                    break;

                case SettingsCache.ResizeMode.CRT:
                    resizeShader = ContentResolver.Current.RequestShader("ResizeCRT");
                    break;

                case SettingsCache.ResizeMode.GB:
                    resizeShader = ContentResolver.Current.RequestShader("ResizeGB");
                    break;
                }
            } catch {
                resizeShader = DrawTechnique.Solid;
            }

            // Main texture
            mainTexture   = new Texture(null, TextureSizeMode.NonPowerOfTwo, TextureMagFilter.Nearest, TextureMinFilter.Nearest);
            normalTexture = new Texture(null, TextureSizeMode.NonPowerOfTwo, TextureMagFilter.Nearest, TextureMinFilter.Nearest, format: TexturePixelFormat.Rgb);
            mainTarget    = new RenderTarget(AAQuality.Off, /*true*/ false, mainTexture, normalTexture);

            // Lighting texture
            lightingTexture = new Texture(null, TextureSizeMode.NonPowerOfTwo, TextureMagFilter.Nearest, TextureMinFilter.Nearest, format: TexturePixelFormat.Dual);
            lightingTarget  = new RenderTarget(AAQuality.Off, false, lightingTexture);

            finalTexture = new Texture(null, TextureSizeMode.NonPowerOfTwo, TextureMagFilter.Nearest, TextureMinFilter.Nearest);
            finalTarget  = new RenderTarget(AAQuality.Off, false, finalTexture);

            // Noise texture
            noiseTexture = ContentResolver.Current.RequestGraphicResource("_custom/noise.png").Texture;

            // Materials
            lightingMaterial = new Material(lightingShader, ColorRgba.White);
            lightingMaterial.Res.SetTexture("normalBuffer", normalTexture);

            lightingNoiseMaterial = new Material(lightingNoiseShader, ColorRgba.White);
            lightingNoiseMaterial.Res.SetTexture("normalBuffer", normalTexture);

            // Render steps
            AddRenderStep(RenderStepPosition.Last, new RenderStep {
                DefaultProjection = true,
                VisibilityMask    = VisibilityFlag.AllGroups,
                ClearFlags        = ClearFlag.All,
                DefaultClearColor = true,

                Output = mainTarget
                         //Output = finalTarget
            });

            AddRenderStep(RenderStepPosition.Last, new RenderStep {
                Id = "CombineScene",

                Projection     = ProjectionMode.Screen,
                VisibilityMask = VisibilityFlag.None,
                ClearFlags     = ClearFlag.None,

                Input  = new BatchInfo(DrawTechnique.Solid, mainTexture),
                Output = finalTarget
            });

            AddRenderStep(RenderStepPosition.Last, new RenderStep {
                Projection     = ProjectionMode.Screen,
                VisibilityMask = VisibilityFlag.All,
                ClearFlags     = ClearFlag.None,

                Output = finalTarget
            });

            AddRenderStep(RenderStepPosition.Last, new RenderStep {
                Id = "Resize",

                Projection     = ProjectionMode.Screen,
                VisibilityMask = VisibilityFlag.None,
                ClearFlags     = ClearFlag.None
            });
        }
Beispiel #3
0
        protected override void OnRenderPointOfView(Scene scene, DrawDevice drawDevice, Rect viewportRect, Vector2 imageSize)
        {
            // Switch between resize modes if necessary
            if (lastResizeMode != SettingsCache.Resize)
            {
                lastResizeMode = SettingsCache.Resize;

                try {
                    switch (lastResizeMode)
                    {
                    default:
                    case SettingsCache.ResizeMode.None:
                        resizeShader = DrawTechnique.Solid;
                        break;

                    case SettingsCache.ResizeMode.HQ2x:
                        resizeShader = ContentResolver.Current.RequestShader("ResizeHQ2x");
                        break;

                    case SettingsCache.ResizeMode.xBRZ3:
                        resizeShader = ContentResolver.Current.RequestShader("Resize3xBRZ");
                        break;

                    case SettingsCache.ResizeMode.xBRZ4:
                        resizeShader = ContentResolver.Current.RequestShader("Resize4xBRZ");
                        break;

                    case SettingsCache.ResizeMode.CRT:
                        resizeShader = ContentResolver.Current.RequestShader("ResizeCRT");
                        break;

                    case SettingsCache.ResizeMode.GB:
                        resizeShader = ContentResolver.Current.RequestShader("ResizeGB");
                        break;
                    }
                } catch {
                    resizeShader = DrawTechnique.Solid;
                }
            }

            // Check if resolution changed
            if (lastImageSize != imageSize)
            {
                lastImageSize = imageSize;

                const float defaultRatio = (float)defaultWidth / defaultHeight;
                float       currentRatio = imageSize.X / imageSize.Y;

                int width, height;
                if (currentRatio > defaultRatio)
                {
                    width  = MathF.Min(defaultWidth, (int)imageSize.X);
                    height = (int)(width / currentRatio);
                }
                else if (currentRatio < defaultRatio)
                {
                    height = MathF.Min(defaultHeight, (int)imageSize.Y);
                    width  = (int)(height * currentRatio);
                }
                else
                {
                    width  = MathF.Min(defaultWidth, (int)imageSize.X);
                    height = MathF.Min(defaultHeight, (int)imageSize.Y);
                }

                TargetSize = new Point2(width, height);

                ResizeRenderTarget(mainTarget, TargetSize);
                ResizeRenderTarget(lightingTarget, TargetSize);
                ResizeRenderTarget(finalTarget, TargetSize);
            }

            base.OnRenderPointOfView(scene, drawDevice, viewportRect, imageSize);
        }