public MyShaderBundle GetShaderBundle(MyRenderPassType pass, MyMeshDrawTechnique technique, MyInstanceLodState state, bool isCm, bool isNg, bool isExt)
        {
            // Modify input:
            switch (technique)
            {
            case MyMeshDrawTechnique.DECAL:
            case MyMeshDrawTechnique.DECAL_CUTOUT:
            case MyMeshDrawTechnique.DECAL_NOPREMULT:
                break;

            default:
                isCm  = true;
                isNg  = true;
                isExt = true;
                break;
            }

            MyShaderBundleKey key = new MyShaderBundleKey
            {
                Pass      = pass,
                Technique = technique,
                IsCm      = isCm,
                IsNg      = isNg,
                IsExt     = isExt,
                State     = state,
            };

            if (m_cache.ContainsKey(key))
            {
                return(m_cache[key]);
            }

            MyVertexInputComponent[] viComps = GetVertexInputComponents(pass);
            VertexLayoutId           vl      = MyVertexLayouts.GetLayout(viComps);
            string             vsFilepath    = GetShaderDirpath(technique) + "Vertex.hlsl";
            string             psFilepath    = GetShaderDirpath(technique) + "Pixel.hlsl";
            List <ShaderMacro> macros        = new List <ShaderMacro>();

            AddMacrosForRenderingPass(pass, ref macros);
            AddMacrosForTechnique(technique, isCm, isNg, isExt, ref macros);
            AddMacrosVertexInputComponents(viComps, ref macros);
            AddMacrosState(state, ref macros);

            VertexShaderId vs = MyShaders.CreateVs(vsFilepath, macros.ToArray());

            ((VertexShader)vs).DebugName = GetVsDebugName(pass, technique, macros);
            PixelShaderId ps = MyShaders.CreatePs(psFilepath, macros.ToArray());

            ((PixelShader)ps).DebugName = GetPsDebugName(pass, technique, macros);;
            InputLayoutId  il           = MyShaders.CreateIL(vs.BytecodeId, vl);
            MyShaderBundle shaderBundle = new MyShaderBundle(ps, vs, il);

            m_cache.Add(key, shaderBundle);
            return(shaderBundle);
        }
Esempio n. 2
0
        internal static unsafe void Init()
        {
            //MyRender11.RegisterSettingsChangedListener(new OnSettingsChangedDelegate(RecreateShadersForSettings));

            m_directionalEnvironmentLightPixel  = MyShaders.CreatePs("Lighting/LightDir.hlsl");
            m_directionalEnvironmentLightSample = MyShaders.CreatePs("Lighting/LightDir.hlsl", MyRender11.ShaderSampleFrequencyDefine());

            m_pointlightsTiledPixel  = MyShaders.CreatePs("Lighting/LightPoint.hlsl");
            m_pointlightsTiledSample = MyShaders.CreatePs("Lighting/LightPoint.hlsl", MyRender11.ShaderSampleFrequencyDefine());

            m_preparePointLights = MyShaders.CreateCs("Lighting/PrepareLights.hlsl", new[] { new ShaderMacro("NUMTHREADS", TILE_SIZE) });

            m_spotlightProxyVs  = MyShaders.CreateVs("Lighting/LightSpot.hlsl");
            m_spotlightPsPixel  = MyShaders.CreatePs("Lighting/LightSpot.hlsl");
            m_spotlightPsSample = MyShaders.CreatePs("Lighting/LightSpot.hlsl", MyRender11.ShaderSampleFrequencyDefine());
            m_spotlightProxyIl  = MyShaders.CreateIL(m_spotlightProxyVs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION_PACKED));

            m_pointlightCullHwBuffer = MyManagers.Buffers.CreateSrv(
                "MyLightRendering", MyRender11Constants.MAX_POINT_LIGHTS, sizeof(MyPointlightConstants),
                usage: ResourceUsage.Dynamic);
        }