public void OnCreate(ECSWorld world) { var fragShader = Asset.Load <ShaderAsset>("mesh_instanced_default.frag"); var vertShader = Asset.Load <ShaderAsset>("mesh_instanced_default.vert"); var shader = new ShaderPipeline(fragShader, vertShader, ShaderType.Instanced); defaultShader = shader.ShaderPair; defaultMaterial = new Material(GraphicsContext.graphicsDevice, GraphicsContext.uniform0, defaultShader); defaultMaterial.wireframe = true; instanceMatrix = new DeviceBuffer(GraphicsContext.graphicsDevice, (ulong)Unsafe.SizeOf <ObjectToWorld>(), BufferUsageFlags.VertexBuffer, BufferMemoryUsageHint.Dynamic); var matrix = mat4.Identity; var normalMatrix = new mat3(matrix); ObjectToWorld matrices = new ObjectToWorld() { model = matrix, normal = normalMatrix }; instanceMatrix.SetData(matrices, 0); MeshData initialData = new MeshData(); initialData.subMeshes = new SubMeshData[1]; initialData.subMeshes[0] = new SubMeshData(vertices, indices); defaultMesh = new Mesh(GraphicsContext.graphicsDevice, initialData, true); }
Shader LookupShader(string oldName) { for (int i = 0; i < m_mainPlayerReplaceShader.Count; i++) { ShaderPair p = m_mainPlayerReplaceShader[i]; if (p.m_name == oldName) { return(p.m_shader); } } return(null); }
// Update is called once per frame void Update() { if (!Application.isEditor) { return; } for (int i = 0; i < m_mainPlayerReplaceShader.Count; i++) { ShaderPair p = m_mainPlayerReplaceShader[i]; if (p.m_oldShader != null) { p.m_name = p.m_oldShader.name; } //if(p.m_shader != null) //{ //p.m_newName = p.m_shader.name; //} } }
public void OnCreate(ECSWorld world) { query.IncludeReadonly <ObjectToWorld>(); query.IncludeShared <DebugMeshConvexHullRenderer>(); query.ExcludeShared <CulledRenderTag>(); var fragShader = Asset.Load <ShaderAsset>("mesh_instanced_default.frag"); var vertShader = Asset.Load <ShaderAsset>("mesh_instanced_default.vert"); var shader = new ShaderPipeline(fragShader, vertShader, ShaderType.Instanced); defaultShader = shader.ShaderPair; defaultMaterial = new Material(GraphicsContext.graphicsDevice, GraphicsContext.uniform0, defaultShader); defaultMaterial.wireframe = true; instanceMatricesBuffers = new List <DeviceBuffer>(1); GrowInstanceMatrices(); }
private bool GenerateShader(ShaderType shaderType, bool isOverwrite) { ShaderPair pair = _shaderPairs[shaderType]; Shader shader_Normal = pair._shader_Normal; Shader shader_LWRP = pair._shader_LWRP; if (shader_Normal == null) { //Source가 없다. return(false); } if (shader_LWRP != null && !isOverwrite) { //이미 있으며, 덮어쓸 수 없다. return(false); } DirectoryInfo appDi = new DirectoryInfo(Application.dataPath); string projPath = appDi.Parent.ToString() + "/"; //1. 저장할 폴더가 있는지 확인. 없다면 만든다. //2. 파일을 복사한다. 이미 있다면 삭제한다. //3. 복사된 파일(LWRP)을 열고, 몇가지 코드를 수정한다. FileStream fs_Src = null; StreamReader sr_Src = null; FileStream fs_Dst = null; StreamWriter sw_Dst = null; try { //폴더 확인 후 만들기 DirectoryInfo di_LWRP = new DirectoryInfo(projPath + pair._folderPath_LWRP); if (!di_LWRP.Exists) { di_LWRP.Create(); } FileInfo fi_Normal = new FileInfo(projPath + pair._folderPath_Normal + "/" + pair._fileName_Normal); FileInfo fi_LWRP = new FileInfo(projPath + pair._folderPath_LWRP + "/" + pair._fileName_LWRP); //fi_Normal.CopyTo(projPath + pair._folderPath_LWRP + "/" + pair._fileName_LWRP, isOverwrite); fs_Src = new FileStream(fi_Normal.FullName, FileMode.Open, FileAccess.Read); sr_Src = new StreamReader(fs_Src); fs_Dst = new FileStream(fi_LWRP.FullName, FileMode.Create, FileAccess.Write); sw_Dst = new StreamWriter(fs_Dst); //하나씩 읽고 하나씩 적는다. string strReadLine = null; string strWriteLine = null; while (true) { if (sr_Src.Peek() < 0) { break; } strReadLine = sr_Src.ReadLine(); //체크해야하는 것 //- Shader 이름 : Shader "AnyPortrait/Transparent => Shader "AnyPortrait/LWRP/Transparent //- Tags : Tags{로 시작할 때 => 마지막 글자 } => [공백]"RenderPipeline" = "LightweightPipeline" "LightMode" = "LightweightForward"} if (strReadLine.StartsWith("Shader ") && strReadLine.Contains("\"AnyPortrait/Transparent/") ) { //Shader 이름 부분이다. strWriteLine = strReadLine.Replace("\"AnyPortrait/Transparent/", "\"AnyPortrait/LWRP/Transparent/"); } else if ((strReadLine.Contains("Tags {") || strReadLine.Contains("Tags{")) && strReadLine.Contains("\"RenderType\"") && strReadLine.Contains("}") && !strReadLine.Contains("LightweightPipeline") && !strReadLine.Contains("LightweightForward") && !strReadLine.Contains("//") ) { //Shader Tags 부분이다. strWriteLine = strReadLine.Replace("}", " \"RenderPipeline\" = \"LightweightPipeline\" \"LightMode\" = \"LightweightForward\"}"); } else { strWriteLine = strReadLine; //그대로 적용 } sw_Dst.WriteLine(strWriteLine); } sr_Src.Close(); fs_Src.Close(); sw_Dst.Close(); fs_Dst.Close(); sr_Src = null; fs_Src = null; sw_Dst = null; fs_Dst = null; } catch (Exception ex) { if (sr_Src != null) { sr_Src.Close(); sr_Src = null; } if (fs_Src != null) { fs_Src.Close(); fs_Src = null; } if (sw_Dst != null) { sw_Dst.Close(); sw_Dst = null; } if (fs_Dst != null) { fs_Dst.Close(); fs_Dst = null; } Debug.LogError("Generate Exception : " + ex); } return(true); }
// Sub-Functions //------------------------------------------------ private void MakePair(ShaderType shaderType, string folderPath_Normal, string fileName_Normal, string folderPath_LWRP, string fileName_LWRP) { ShaderPair newPair = new ShaderPair(shaderType, folderPath_Normal, fileName_Normal, folderPath_LWRP, fileName_LWRP); _shaderPairs.Add(shaderType, newPair); }