Пример #1
0
        public static void onActivateBasicLM()
        {
            Torque3D.PostEffect HDRPostFx = Sim.FindObjectByName <Torque3D.PostEffect>("HDRPostFx");
            // If HDR is enabled... enable the special format token.
            if (!Globals.GetString("platform").Equals("macos") && HDRPostFx.isEnabled())
            {
                Core.RenderManager.AL_FormatToken.enable();
            }

            // Create render pass for projected shadow.
            BL_ProjectedShadowRPM = new RenderPassManager("BL_ProjectedShadowRPM");
            BL_ProjectedShadowRPM.registerObject();

            // Create the mesh bin and add it to the manager.
            RenderMeshMgr meshBin = new RenderMeshMgr();

            meshBin.registerObject();
            BL_ProjectedShadowRPM.addManager(meshBin);

            SimGroup RootGroup = Sim.FindObjectByName <SimGroup>("RootGroup");

            // Add both to the root group so that it doesn't
            // end up in the MissionCleanup instant group.
            RootGroup.add(BL_ProjectedShadowRPM);
            RootGroup.add(meshBin);
        }
Пример #2
0
        public static void Init()
        {
            // This post effect is used to copy data from the non-MSAA back-buffer to the
            // device back buffer (which could be MSAA). It must be declared here so that
            // it is initialized when 'AL_FormatToken' is initialzed.

            GFXStateBlockData AL_FormatTokenState = new GFXStateBlockData("AL_FormatTokenState",
                                                                          PostEffect.PFX_DefaultStateBlock)
            {
                SamplersDefined = true,
                SamplerStates   = { [0] = GfxData.CommonMaterialData.SamplerClampPoint }
            };

            AL_FormatTokenState.registerSingleton();

            AL_FormatCopy = new Torque3D.PostEffect("AL_FormatCopy")
            {
                // This PostEffect is used by 'AL_FormatToken' directly. It is never added to
                // the PostEffectManager. Do not call enable() on it.
                IsEnabled        = false,
                AllowReflectPass = true,

                Shader     = "PFX_PassthruShader",
                StateBlock = AL_FormatTokenState,

                Texture = { [0] = "$inTex" },
                Target  = "$backbuffer"
            };
            AL_FormatCopy.registerObject();
        }
Пример #3
0
        public static void Init()
        {
            ShaderData ShadowFilterShaderV = new ShaderData("BL_ShadowFilterShaderV")
            {
                DXVertexShaderFile  = "data/shaders/common/lighting/basic/shadowFilterV.hlsl",
                DXPixelShaderFile   = "data/shaders/common/lighting/basic/shadowFilterP.hlsl",
                OGLVertexShaderFile = "data/shaders/common/lighting/basic/gl/shadowFilterV.glsl",
                OGLPixelShaderFile  = "data/shaders/common/lighting/basic/gl/shadowFilterP.glsl",
                SamplerNames        = { [0] = "$diffuseMap" },
                Defines             = "BLUR_DIR=float2(1.0,0.0)",
                PixVersion          = 2.0f
            };

            ShadowFilterShaderV.registerSingleton();

            new ShaderData("BL_ShadowFilterShaderH", ShadowFilterShaderV)
            {
                Defines = "BLUR_DIR=float2(0.0,1.0)"
            }.registerSingleton();


            GFXStateBlockData BL_ShadowFilterSB = new GFXStateBlockData("BL_ShadowFilterSB", Core.PostEffect.PFX_DefaultStateBlock)
            {
                ColorWriteDefined = true,
                ColorWriteRed     = false,
                ColorWriteGreen   = false,
                ColorWriteBlue    = false,
                BlendDefined      = true,
                BlendEnable       = true
            };

            BL_ShadowFilterSB.registerSingleton();

            // NOTE: This is ONLY used in Basic Lighting, and
            // only directly by the ProjectedShadow.  It is not
            // meant to be manually enabled like other PostEffects.
            Torque3D.PostEffect BL_ShadowFilterPostFx = new Torque3D.PostEffect("BL_ShadowFilterPostFx")
            {
                // Blur vertically
                Shader           = "BL_ShadowFilterShaderV",
                StateBlock       = PostEffect.PFX_DefaultStateBlock,
                TargetClear      = PFXTargetClear.PFXTargetClear_OnDraw,
                TargetClearColor = new ColorF(0.0f, 0.0f, 0.0f, 0.0f),
                Texture          = { [0] = "$inTex" },
                Target           = "$outTex"
            };

            Torque3D.PostEffect blurEffect = new Torque3D.PostEffect
            {
                Shader     = "BL_ShadowFilterShaderH",
                StateBlock = PostEffect.PFX_DefaultStateBlock,
                Texture    = { [0] = "$inTex" },
                Target     = "$outTex"
            };
            blurEffect.registerObject();
            BL_ShadowFilterPostFx.add(blurEffect);

            BL_ShadowFilterPostFx.registerObject();
        }
Пример #4
0
        public static void Init()
        {
            new ShaderData("ClearGBufferShader")
            {
                DXVertexShaderFile = "data/shaders/common/postFx/postFxV.hlsl",
                DXPixelShaderFile  = "data/shaders/common/lighting/advanced/deferredClearGBufferP.hlsl",

                OGLVertexShaderFile = "data/shaders/common/postFx/gl/postFxV.glsl",
                OGLPixelShaderFile  = "data/shaders/common/lighting/advanced/gl/deferredClearGBufferP.glsl",

                PixVersion = 2.0f
            }.registerSingleton();

            new ShaderData("DeferredColorShader")
            {
                DXVertexShaderFile = "data/shaders/common/postFx/postFxV.hlsl",
                DXPixelShaderFile  = "data/shaders/common/lighting/advanced/deferredColorShaderP.hlsl",

                OGLVertexShaderFile = "data/shaders/common/postFx/gl/postFxV.glsl",
                OGLPixelShaderFile  = "data/shaders/common/lighting/advanced/gl/deferredColorShaderP.glsl",

                PixVersion = 2.0f
            }.registerSingleton();

            // Primary Deferred Shader
            GFXStateBlockData AL_DeferredShadingState = new GFXStateBlockData("AL_DeferredShadingState", "PFX_DefaultStateBlock")
            {
                CullMode = GFXCullMode.GFXCullNone,

                BlendDefined = true,
                BlendEnable  = true,
                BlendSrc     = GFXBlend.GFXBlendSrcAlpha,
                BlendDest    = GFXBlend.GFXBlendInvSrcAlpha,

                SamplersDefined = true,
                SamplerStates   =
                {
                    [0] = CommonMaterialData.SamplerWrapLinear,
                    [1] = CommonMaterialData.SamplerWrapLinear,
                    [2] = CommonMaterialData.SamplerWrapLinear,
                    [3] = CommonMaterialData.SamplerWrapLinear
                }
            };

            AL_DeferredShadingState.registerSingleton();

            new ShaderData("AL_DeferredShader")
            {
                DXVertexShaderFile = "data/shaders/common/postFx/postFxV.hlsl",
                DXPixelShaderFile  = "data/shaders/common/lighting/advanced/deferredShadingP.hlsl",

                OGLVertexShaderFile = "data/shaders/common/postFx/gl/postFxV.glsl",
                OGLPixelShaderFile  = "data/shaders/common/lighting/advanced/gl/deferredShadingP.glsl",

                SamplerNames =
                {
                    [0] = "colorBufferTex",
                    [1] = "lightPrePassTex",
                    [2] = "matInfoTex",
                    [3] = "prepassTex"
                },

                PixVersion = 2.0f
            }.registerSingleton();

            AL_DeferredShading = new Torque3D.PostEffect("AL_DeferredShading")
            {
                RenderTime = PFXRenderTime.PFXAfterBin,
                RenderBin  = "SkyBin",
                Shader     = "AL_DeferredShader",
                StateBlock = AL_DeferredShadingState,
                Texture    =
                {
                    [0] = "#color",
                    [1] = "#lightinfo",
                    [2] = "#matinfo",
                    [3] = "#prepass"
                },

                Target           = "$backBuffer",
                RenderPriority   = 10000,
                AllowReflectPass = true
            };
            AL_DeferredShading.registerSingleton();

            // Debug shaders
            new ShaderData("AL_ColorBufferShader")
            {
                DXVertexShaderFile = "data/shaders/common/postFx/postFxV.hlsl",
                DXPixelShaderFile  = "data/shaders/common/lighting/advanced/dbgColorBufferP.hlsl",

                OGLVertexShaderFile = "data/shaders/common/postFx/gl/postFxV.glsl",
                OGLPixelShaderFile  = "data/shaders/common/lighting/advanced/gl/dbgColorBufferP.glsl",

                SamplerNames = { [0] = "colorBufferTex" },
                PixVersion   = 2.0f
            }.registerSingleton();

            AL_ColorBufferVisualize = new Torque3D.PostEffect("AL_ColorBufferVisualize")
            {
                Shader         = "AL_ColorBufferShader",
                StateBlock     = LightViz.AL_DefaultVisualizeState,
                Texture        = { [0] = "#color" },
                Target         = "$backBuffer",
                RenderPriority = 9999
            };
            AL_ColorBufferVisualize.registerSingleton();

            // Debug shaders
            new ShaderData("AL_SpecMapShader")
            {
                DXVertexShaderFile = "data/shaders/common/postFx/postFxV.hlsl",
                DXPixelShaderFile  = "data/shaders/common/lighting/advanced/dbgSpecMapVisualizeP.hlsl",

                OGLVertexShaderFile = "data/shaders/common/postFx/gl/postFxV.glsl",
                OGLPixelShaderFile  = "data/shaders/common/lighting/advanced/gl/dbgSpecMapVisualizeP.glsl",

                SamplerNames = { [0] = "matinfoTex" },
                PixVersion   = 2.0f
            }.registerSingleton();

            AL_SpecMapVisualize = new Torque3D.PostEffect("AL_SpecMapVisualize")
            {
                Shader         = "AL_SpecMapShader",
                StateBlock     = LightViz.AL_DefaultVisualizeState,
                Texture        = { [0] = "#matinfo" },
                Target         = "$backBuffer",
                RenderPriority = 9999
            };
            AL_SpecMapVisualize.registerSingleton();
        }
Пример #5
0
        public static void configureCanvas()
        {
            // Setup a good default if we don't have one already.
            if (string.IsNullOrWhiteSpace(Globals.GetString("pref::Video::Resolution")))
            {
                Globals.SetString("pref::Video::Resolution", "800 600");
            }
            if (string.IsNullOrWhiteSpace(Globals.GetString("pref::Video::FullScreen")))
            {
                Globals.SetBool("pref::Video::FullScreen", false);
            }
            if (string.IsNullOrWhiteSpace(Globals.GetString("pref::Video::BitDepth")))
            {
                Globals.SetInt("pref::Video::BitDepth", 32);
            }
            if (string.IsNullOrWhiteSpace(Globals.GetString("pref::Video::RefreshRate")))
            {
                Globals.SetInt("pref::Video::RefreshRate", 60);
            }
            if (string.IsNullOrWhiteSpace(Globals.GetString("pref::Video::AA")))
            {
                Globals.SetInt("pref::Video::AA", 4);
            }

            string[] res  = Globals.GetString("pref::Video::Resolution").Split(' ');
            uint     resX = uint.Parse(res[0]);
            uint     resY = uint.Parse(res[1]);
            bool     fs   = Globals.GetBool("pref::Video::FullScreen");
            string   _bpp = Globals.GetString("pref::Video::BitDepth");
            uint     bpp;

            uint.TryParse(_bpp, out bpp);
            int rate = Globals.GetInt("pref::Video::RefreshRate");
            int aa   = Globals.GetInt("pref::Video::AA");

            if (!string.IsNullOrEmpty("cliFullscreen"))
            {
                fs = Globals.GetBool("cliFullscreen");
                Globals.SetString("cliFullscreen", "");
            }


            Global.echo("--------------");
            Global.echo($"Attempting to set resolution to \"{resX} {resY} {fs} {bpp} {rate} {aa}\"");

            Point3F deskRes = Global.getDesktopResolution();

            // We shouldn't be getting this any more but just in case...
            if (_bpp == "Default")
            {
                bpp = (uint)deskRes.Z;
            }

            GuiCanvas canvas = Sim.FindObjectByName <GuiCanvas>("Canvas");

            // Make sure we are running at a valid resolution
            if (!fs)
            {
                // Windowed mode has to use the same bit depth as the desktop
                bpp = (uint)deskRes.Z;

                // Windowed mode also has to run at a smaller resolution than the desktop
                if ((resX >= deskRes.X) || (resY >= deskRes.Y))
                {
                    Global.warn(
                        "Warning: The requested windowed resolution is equal to or larger than the current desktop resolution. Attempting to find a better resolution");

                    int resCount = canvas.getModeCount();
                    for (int i = (resCount - 1); i >= 0; i--)
                    {
                        string   testRes      = canvas.getMode(i);
                        string[] testResSplit = testRes.Split(' ');
                        uint     testResX     = uint.Parse(testResSplit[0]);
                        uint     testResY     = uint.Parse(testResSplit[1]);
                        uint     testBPP      = uint.Parse(testResSplit[2]);

                        if (testBPP != bpp)
                        {
                            continue;
                        }

                        if ((testResX < deskRes.X) && (testResY < deskRes.Y))
                        {
                            // This will work as our new resolution
                            resX = testResX;
                            resY = testResY;

                            Global.warn($"Warning: Switching to \"{resX} {resY} {bpp}\"");

                            break;
                        }
                    }
                }
            }

            Globals.SetString("pref::Video::Resolution", resX + " " + resY);
            Globals.SetBool("pref::Video::FullScreen", fs);
            Globals.SetInt("pref::Video::BitDepth", (int)bpp);
            Globals.SetInt("pref::Video::RefreshRate", rate);
            Globals.SetInt("pref::Video::AA", aa);

            string fsLabel = "No";

            if (fs)
            {
                fsLabel = "Yes";
            }

            Global.echo("Accepted Mode: \n" +
                        $"--Resolution : {resX} {resY}\n" +
                        $"--Full Screen : {fsLabel} \n" +
                        $"--Bits Per Pixel : {bpp} \n" +
                        $"--Refresh Rate : {rate} \n" +
                        $"--FSAA Level : {aa} \n" +
                        "--------------");

            // Actually set the new video mode
            canvas.setVideoMode(resX, resY, fs, bpp, (uint)rate, (uint)aa);

            /*todo Global.commandToServer(Global.addTaggedString("setClientAspectRatio"), resX, resY);*/

            // FXAA piggybacks on the FSAA setting in $pref::Video::mode.
            if (Global.isObject("FXAA_PostEffect"))
            {
                Torque3D.PostEffect FXAA_PostEffect = Sim.FindObjectByName <Torque3D.PostEffect>("FXAA_PostEffect");
                FXAA_PostEffect.IsEnabled = (aa > 0);
            }
        }