public CGfxEffectDesc CloneEffectDesc() { CGfxEffectDesc result = new CGfxEffectDesc(); result.MtlShaderPatch = MtlShaderPatch; result.MdfQueueShaderPatch = MdfQueueShaderPatch.CloneMdfQueue(CEngine.Instance.RenderContext, null); result.EnvShaderPatch = EnvShaderPatch.CloneEnvShaderCode(); result.UpdateHash64(true); return(result); }
public static CGfxEffectDesc CreateDesc(CGfxMaterial mtl, Mesh.CGfxMdfQueue mdf, GfxEnvShaderCode shadingenv) { CGfxEffectDesc result = new CGfxEffectDesc(); result.MtlShaderPatch = mtl; result.MdfQueueShaderPatch = mdf.CloneMdfQueue(CEngine.Instance.RenderContext, null); result.EnvShaderPatch = shadingenv; //result.EnvShaderPatch = shadingenv.CloneShadingEnv(); result.UpdateHash64(true); return(result); }
public static async System.Threading.Tasks.Task <CGfxEffectDesc> LoadEffectDescFromXml(CRenderContext rc, IO.XmlNode node, bool testHash = true) { var result = new CGfxEffectDesc(); if (node == null) { return(result); } RName.enRNameType rNameType = RName.enRNameType.Game; var attr = node.FindAttrib("Material_RNameType"); if (attr != null) { rNameType = (RName.enRNameType)System.Convert.ToInt32(attr.Value); } attr = node.FindAttrib("Material"); if (attr != null) { result.MtlShaderPatch = await CEngine.Instance.MaterialManager.GetMaterialAsync(rc, RName.GetRName(attr.Value, rNameType)); if (result.MtlShaderPatch == null) { return(null); } } attr = node.FindAttrib("ShadingEnv"); string shadingEnvName = null; if (attr != null) { result.mEnvShaderPatch = new Graphics.GfxEnvShaderCode(); shadingEnvName = attr.Value; var attr1 = node.FindAttrib("ShadingEnvType"); if (attr1 != null) { var envType = Rtti.RttiHelper.GetTypeFromSaveString(attr1.Value); var envTemp = Rtti.RttiHelper.CreateInstance(envType) as CGfxShadingEnv; if (envTemp != null) { envTemp.InitCodeOnce(result.mEnvShaderPatch); } } var LoadDefs = new List <CShaderDefinitions.MacroDefine>(); var defs = node.FindNode("EnvMacro"); if (defs != null) { var macroAttrs = defs.GetAttribs(); for (int i = 0; i < macroAttrs.Count; i++) { result.mEnvShaderPatch.SetMacroDefineValue(macroAttrs[i].Name, macroAttrs[i].Value); } } } result.MdfQueueShaderPatch = new Mesh.CGfxMdfQueue(); var mdf = node.FindNode("MdfQueue").GetNodes(); foreach (var i in mdf) { var type = Rtti.RttiHelper.GetTypeFromSaveString(i.Name); var om = System.Activator.CreateInstance(type) as EngineNS.Graphics.Mesh.CGfxModifier; if (om == null) { continue; } result.MdfQueueShaderPatch.AddModifier(om); } result.UpdateMacroArray(); result.UpdateHash64(false); if (testHash) { attr = node.FindAttrib("HLSLHashCode"); if (attr != null) { result.HLSLHashCode = attr.Value; var hlslDesc = CEngine.Instance.FileManager.HLSLFileDescManager.FindFileDesc(RName.GetRName(shadingEnvName, RName.enRNameType.Engine).Address); if (hlslDesc != null && hlslDesc.HashWithDepends.ToString() != result.HLSLHashCode) { Profiler.Log.WriteLine(Profiler.ELogTag.Warning, "Shaders", $"effect {shadingEnvName} need recompile"); return(null); } } } return(result); }