Ejemplo n.º 1
0
    public void SetNewShader(ShaderTypeEnum inShaderType)
    {
        //return;
        //MeshRenderer meshRenderer = myObject.GetComponent<MeshRenderer>();
        //UnityEngine.Material myMaterial;

        switch (inShaderType)
        {
        case ShaderTypeEnum.kShader_Additive:

            myObject.GetComponent <Renderer>().sharedMaterial = myAtlas.myMaterialAdditive;

            //in this case we want a new material with the new shader yeah?

/*			if (materialForColourAndAlpha == null)
 *                      {
 *                              materialForColourAndAlpha = new Material(Shader.Find( "Pi/Additive" ));
 *
 *                              if (myAtlas != null)
 *                                      materialForColourAndAlpha.mainTexture = myAtlas.myMaterial.mainTexture;
 *                              else
 *                                      materialForColourAndAlpha.mainTexture = myTexture.myMaterial.mainTexture;
 *                      }
 *                      else
 *                      {
 *                              materialForColourAndAlpha.shader = Shader.Find( "Pi/Additive" );
 *                      }
 *
 *                      usingAlpha = true;
 *                      myObject.renderer.material = materialForColourAndAlpha;*/
            break;

        case ShaderTypeEnum.kShader_Transparent:

            myObject.GetComponent <Renderer>().sharedMaterial = myAtlas.myMaterial;

            //So i think in this case we can just leave it using the sharedMaterial - which is the material ffrom the
            //atlas...

//			materialForColourAndAlpha.shader = Shader.Find( "Pi/TransparentOverlay" );
//			myObject.renderer.material = materialForColourAndAlpha;

            break;

        default:
            Default.Namespace.Globals.Assert(false);
            //	myMaterial = new UnityEngine.Material(Shader.Find( "Pi/TransparentOverlay" ));
            break;
        }

        //meshRenderer.material = myMaterial;

//		float oldAlpha = prevAlpha;
//		this.SetAlpha(prevAlpha);
    }
Ejemplo n.º 2
0
        public override bool LoadAsset(BinaryReader reader)
        {
            if (!base.LoadAsset(reader))
            {
                return(false);
            }
            this.ShaderType = (ShaderTypeEnum)reader.ReadInt32();
            int n = reader.ReadInt32();

            if (n > 0)
            {
                this.Bytecode = reader.ReadBytes(n);
            }
            return(true);
        }
Ejemplo n.º 3
0
        public static byte[] CompileShaderFromSource(string source, ShaderTypeEnum type, Dictionary <string, object> macro)
        {
            includeShader.subPath = shadersDirectory + "/";
            string            prefix         = prefixies[(int)type];
            CompilationResult ShaderByteCode = ShaderBytecode.Compile(
                source,
                prefix + "Main",
                prefix.ToLower() + "_5_0",
                ShaderFlags.PackMatrixRowMajor,
                EffectFlags.None,
                ParseMacro(macro),
                includeShader
                );

            if (ShaderByteCode == null || ShaderByteCode.Message != null)
            {
                Console.WriteLine("[ShaderCompileMessage]: " + ShaderByteCode.Message + " Source:" + source);
                return(null);
            }
            return(ShaderByteCode.Bytecode.Data);
        }
Ejemplo n.º 4
0
        public static byte[] LoadAndCompileShader(string path, ShaderTypeEnum type, string EntryPoint, Dictionary <string, object> macro)
        {
            string[] strarr = (shadersDirectory + path).Split('\\');
            if (strarr[strarr.Length - 2] != "Shaders")
            {
                includeShader.subPath = strarr[strarr.Length - 2] + "\\";
                if (strarr[strarr.Length - 3] != "Shaders")
                {
                    includeShader.subPath = strarr[strarr.Length - 3] + "\\" + includeShader.subPath;
                    if (strarr[strarr.Length - 4] != "Shaders")
                    {
                        includeShader.subPath = strarr[strarr.Length - 4] + "\\" + includeShader.subPath;
                    }
                }
            }
            else
            {
                includeShader.subPath = strarr[strarr.Length - 1] + "\\";
            }

            string prefix = prefixies[(int)type];

            CompilationResult ShaderByteCode = ShaderBytecode.CompileFromFile(
                shadersDirectory + path,
                string.IsNullOrEmpty(EntryPoint) ? prefix + "Main" : EntryPoint,
                prefix.ToLower() + "_5_0",
                ShaderFlags.PackMatrixRowMajor,
                EffectFlags.None,
                ParseMacro(macro),
                includeShader
                );

            if (ShaderByteCode == null || ShaderByteCode.Message != null)
            {
                Console.WriteLine("[ShaderCompileMessage]: " + ShaderByteCode.Message + " Path:" + path);
                return(null);
            }
            return(ShaderByteCode.Bytecode.Data);
        }
Ejemplo n.º 5
0
        public bool ImportShaderAsset(string Path, string Name, string EntryPoint, Dictionary <string, object> Macro, bool Rewrite, out BaseAsset assetRes)
        {
            string[] arr = Path.Split('.');
            string   ext = arr[arr.Length - 1].ToLower();

            assetRes = null;

            if (!shaderExts.Contains(ext))
            {
                return(false);
            }

            BaseAsset asset;

            ShaderTypeEnum ST = ShaderTypeEnum.Vertex;

            if (Name.EndsWith("VS"))
            {
                ST = ShaderTypeEnum.Vertex;
            }
            else if (Name.EndsWith("PS"))
            {
                ST = ShaderTypeEnum.Pixel;
            }
            else if (Name.EndsWith("GS"))
            {
                ST = ShaderTypeEnum.Geometry;
            }
            else if (Name.EndsWith("CS"))
            {
                ST = ShaderTypeEnum.Compute;
            }
            else if (Name.EndsWith("HS"))
            {
                ST = ShaderTypeEnum.Hull;
            }
            else if (Name.EndsWith("DS"))
            {
                ST = ShaderTypeEnum.Domain;
            }
            else
            {
                Console.WriteLine("Unknown shader type, please add correct postfix e.g. VS");
                return(false);
            }

            asset = new ShaderAsset()
            {
                Name       = Name,
                ShaderType = ST,
                EntryPoint = EntryPoint,
                Macro      = Macro,
            };

            if (!asset.ImportAsset(Path, ext))
            {
                return(false);
            }

            assetRes = asset;
            return(FSWorker.CreateAssetFile(asset, Rewrite));
        }