Ejemplo n.º 1
0
        static GpuMaterialPass GetMaterialPass()
        {
            if (materialPass == null)
            {
                //generate compile arguments
                var generalDefines = new List <(string, string)>();

                //vertex program
                GpuProgram vertexProgram = GpuProgramManager.GetProgram($"Skybox_Vertex_", GpuProgramType.Vertex,
                                                                        $@"Base\Shaders\Skybox_vs.sc", generalDefines, out var error);
                if (!string.IsNullOrEmpty(error))
                {
                    Log.Warning(error);
                    return(null);
                }

                //fragment program
                GpuProgram fragmentProgram = GpuProgramManager.GetProgram($"Skybox_Fragment_", GpuProgramType.Fragment,
                                                                          $@"Base\Shaders\Skybox_fs.sc", generalDefines, out error);
                if (!string.IsNullOrEmpty(error))
                {
                    Log.Warning(error);
                    return(null);
                }

                var pass = new GpuMaterialPass(vertexProgram, fragmentProgram);
                pass.CullingMode = CullingMode.None;
                pass.DepthCheck  = true;
                pass.DepthWrite  = false;

                materialPass = pass;
            }

            return(materialPass);
        }
Ejemplo n.º 2
0
        static GpuMaterialPass GetMaterialPass(bool cube)
        {
            if (cube && materialPassCube == null || !cube && materialPass2D == null)
            {
                //generate compile arguments
                var generalDefines = new List <(string, string)>();

                if (!cube)
                {
                    generalDefines.Add(("USE_2D", ""));
                }

                //vertex program
                GpuProgram vertexProgram = GpuProgramManager.GetProgram($"Skybox_Vertex_", GpuProgramType.Vertex,
                                                                        $@"Base\Shaders\Skybox_vs.sc", generalDefines, out var error);
                if (!string.IsNullOrEmpty(error))
                {
                    Log.Warning(error);
                    return(null);
                }

                //fragment program
                GpuProgram fragmentProgram = GpuProgramManager.GetProgram($"Skybox_Fragment_", GpuProgramType.Fragment,
                                                                          $@"Base\Shaders\Skybox_fs.sc", generalDefines, out error);
                if (!string.IsNullOrEmpty(error))
                {
                    Log.Warning(error);
                    return(null);
                }

                var pass = new GpuMaterialPass(vertexProgram, fragmentProgram);
                pass.CullingMode = CullingMode.None;
                pass.DepthCheck  = true;
                pass.DepthWrite  = false;

                if (cube)
                {
                    materialPassCube = pass;
                }
                else
                {
                    materialPass2D = pass;
                }
            }

            return(cube ? materialPassCube : materialPass2D);
        }
Ejemplo n.º 3
0
        protected override void OnResultCompile()
        {
            base.OnResultCompile();

            if (!IsSupported)
            {
                return;
            }

            if (Result != null)
            {
                return;
            }

            var result = new CompiledDataSimple();

            //!!!!temp? надо ли знать о создателе? пока сделано, чтобы параметры материала получить
            result.owner = this;

            //!!!!
            EngineThreading.ExecuteFromMainThreadWait(delegate()
            {
                //generate compile arguments
                var vertexDefines   = new List <(string, string)>();
                var fragmentDefines = new List <(string, string)>();
                {
                    //var generalDefines = new List<Tuple<string, string>>();
                    //generalDefines.Add( Tuple.Create( "LIGHTTYPE_" + lightType.ToString().ToUpper(), "" ) );

                    //vertexDefines.AddRange( generalDefines );
                    //fragmentDefines.AddRange( generalDefines );
                }

                {
                    string shaderFileName = Shader;
                    if (string.IsNullOrEmpty(shaderFileName))
                    {
                        return;
                    }

                    string error2;

                    //vertex program
                    var vertexProgram = GpuProgramManager.GetProgram("RenderingEffect_Simple_Vertex_", GpuProgramType.Vertex,
                                                                     @"Base\Shaders\EffectsCommon_vs.sc", /*"main_vp", */ vertexDefines, out error2);
                    if (!string.IsNullOrEmpty(error2))
                    {
                        result.error = GpuProgramManager.GetGpuProgramCompilationErrorText(this, error2);
                        Log.Warning(result.error);
                        result.Dispose();
                        return;
                    }

                    //fragment program
                    var fragmentProgram = GpuProgramManager.GetProgram("RenderingEffect_Simple_Fragment_", GpuProgramType.Fragment,
                                                                       shaderFileName, /*"main_fp", */ fragmentDefines, out error2);
                    if (!string.IsNullOrEmpty(error2))
                    {
                        result.error = GpuProgramManager.GetGpuProgramCompilationErrorText(this, error2);
                        Log.Warning(result.error);
                        result.Dispose();
                        return;
                    }

                    result.vertexProgram   = vertexProgram;
                    result.fragmentProgram = fragmentProgram;

                    //standard material architecture:
                    //var pass = GpuMaterialPass.CreatePass( vertexProgram, fragmentProgram );
                    //result.AllPasses.Add( pass );
                    //pass.SourceBlendFactor = SceneBlendFactor.One;
                    //pass.DestBlendFactor = SceneBlendFactor.Zero;
                }
            });

            Result = result;
        }
        protected override void OnResultCompile()
        {
            base.OnResultCompile();

            if (!IsSupported)
            {
                return;
            }

            if (Result != null)
            {
                return;
            }

            var result = new CompiledDataCodeGenerated();

            //!!!!temp? надо ли знать о создателе? пока сделано, чтобы параметры материала получить
            result.owner = this;

            //!!!!
            EngineThreading.ExecuteFromMainThreadWait(delegate()
            {
                //shader generation
                if (shaderGenerationCompile)
                {
                    if (!GenerateCode(result))
                    {
                        return;
                    }
                }

                //generate compile arguments
                var vertexDefines   = new List <(string, string)>();
                var fragmentDefines = new List <(string, string)>();
                {
                    //var generalDefines = new List<(string, string)>();
                    //generalDefines.Add( ( "LIGHTTYPE_" + lightType.ToString().ToUpper(), "" ) );

                    //vertexDefines.AddRange( generalDefines );
                    //fragmentDefines.AddRange( generalDefines );

                    if (shaderGenerationEnable)
                    {
                        ////vertex
                        //var vertexCode = result.vertexGeneratedCode;
                        //if( vertexCode != null )
                        //{
                        //	if( !string.IsNullOrEmpty( vertexCode.parametersBody ) )
                        //		vertexDefines.Add( ( "VERTEX_CODE_PARAMETERS", vertexCode.parametersBody ) );
                        //	if( !string.IsNullOrEmpty( vertexCode.samplersBody ) )
                        //		vertexDefines.Add( ( "VERTEX_CODE_SAMPLERS", vertexCode.samplersBody ) );
                        //	if( !string.IsNullOrEmpty( vertexCode.codeBody ) )
                        //		vertexDefines.Add( ( "VERTEX_CODE_BODY", vertexCode.codeBody ) );
                        //}

                        //fragment
                        var fragmentCode = result.fragmentGeneratedCode;
                        if (fragmentCode != null)
                        {
                            if (!string.IsNullOrEmpty(fragmentCode.parametersBody))
                            {
                                fragmentDefines.Add(("FRAGMENT_CODE_PARAMETERS", fragmentCode.parametersBody));
                            }
                            if (!string.IsNullOrEmpty(fragmentCode.samplersBody))
                            {
                                fragmentDefines.Add(("FRAGMENT_CODE_SAMPLERS", fragmentCode.samplersBody));
                            }
                            if (!string.IsNullOrEmpty(fragmentCode.shaderScripts))
                            {
                                fragmentDefines.Add(("FRAGMENT_CODE_SHADER_SCRIPTS", fragmentCode.shaderScripts));
                            }
                            if (!string.IsNullOrEmpty(fragmentCode.codeBody))
                            {
                                fragmentDefines.Add(("FRAGMENT_CODE_BODY", fragmentCode.codeBody));
                            }
                        }
                    }
                }

                {
                    string shaderFileName = Shader;
                    if (string.IsNullOrEmpty(shaderFileName))
                    {
                        return;
                    }

                    string error2;

                    //vertex program
                    var vertexProgram = GpuProgramManager.GetProgram("RenderingEffect_CodeGenerated_Vertex_",
                                                                     GpuProgramType.Vertex, @"Base\Shaders\EffectsCommon_vs.sc", vertexDefines, out error2);
                    if (!string.IsNullOrEmpty(error2))
                    {
                        result.error = GpuProgramManager.GetGpuProgramCompilationErrorText(this, error2);
                        Log.Warning(result.error);
                        result.Dispose();
                        return;
                    }

                    //fragment program
                    var fragmentProgram = GpuProgramManager.GetProgram("RenderingEffect_CodeGenerated_Fragment_",
                                                                       GpuProgramType.Fragment, shaderFileName, fragmentDefines, out error2);
                    if (!string.IsNullOrEmpty(error2))
                    {
                        result.error = GpuProgramManager.GetGpuProgramCompilationErrorText(this, error2);
                        Log.Warning(result.error);
                        result.Dispose();
                        return;
                    }

                    result.vertexProgram   = vertexProgram;
                    result.fragmentProgram = fragmentProgram;

                    //standard material architecture:
                    //var pass = GpuMaterialPass.CreatePass( vertexProgram, fragmentProgram );
                    //result.AllPasses.Add( pass );
                    //pass.SourceBlendFactor = SceneBlendFactor.One;
                    //pass.DestBlendFactor = SceneBlendFactor.Zero;
                }
            });

            Result = result;
        }