private void Parse(ValveMaterialFile vmt) { // idk why this is enumerable var e = vmt.Shaders.GetEnumerator(); while (e.MoveNext()) { VmtShader = e.Current.ToLower(); Lightmapped = VmtShader == "lightmappedgeneric" || VmtShader == "worldvertextransition"; Transition = VmtShader == "worldvertextransition"; AlphaTest = vmt[VmtShader].ContainsKey("$alphatest") ? vmt[VmtShader]["$alphatest"] : false; Translucent = vmt[VmtShader].ContainsKey("$translucent") ? vmt[VmtShader]["$translucent"] : false; NoCull = vmt[VmtShader].ContainsKey("$nocull") ? vmt[VmtShader]["$nocull"] : false; BaseTex = vmt[VmtShader].ContainsKey("$basetexture") ? vmt[VmtShader]["$basetexture"] : string.Empty; BaseTex2 = vmt[VmtShader].ContainsKey("$basetexture2") ? vmt[VmtShader]["$basetexture2"] : string.Empty; BumpMap = vmt[VmtShader].ContainsKey("bumpmap") ? vmt[VmtShader]["bumpmap"] : string.Empty; Color = vmt[VmtShader].ContainsKey("$color") ? vmt[VmtShader]["$color"] : new SourceUtils.Color32(255, 255, 255, 255); RefractTint = vmt[VmtShader].ContainsKey("$refracttint") ? vmt[VmtShader]["$refracttint"] : new SourceUtils.Color32(255, 255, 255, 255); SurfaceProp = vmt[VmtShader].ContainsKey("$surfaceprop") ? vmt[VmtShader]["$surfaceprop"] : "grass"; Include = vmt[VmtShader].ContainsKey("include") ? vmt[VmtShader]["include"] : string.Empty; Alpha = vmt[VmtShader].ContainsKey("$alpha") ? vmt[VmtShader]["$alpha"] : 1.0f; RefractAmount = vmt[VmtShader].ContainsKey("$refractamount") ? vmt[VmtShader]["$refractamount"] : 0.2f; CompileSky = vmt[VmtShader].ContainsKey("%compilesky") ? vmt[VmtShader]["%compilesky"] : 0; break; } }
private Material VmtToMaterial(ResourceLoader resourceLoader, ValveMaterialFile vmt, string vmtPath) { string vmtShader = default; bool lightmapped = default; bool alphaTest = default; bool translucent = default; bool noCull = default; bool transition = default; string baseTex = default; string baseTex2 = default; string bumpMap = default; string surfaceProp = default; string include = default; float alpha = default; float refractAmount = default; int compileSky = default; SourceUtils.Color32 color = default; SourceUtils.Color32 refractTint = default; var e = vmt.Shaders.GetEnumerator(); while (e.MoveNext()) { vmtShader = e.Current.ToLower(); lightmapped = vmtShader == "lightmappedgeneric" || vmtShader == "worldvertextransition"; transition = vmtShader == "worldvertextransition"; alphaTest = vmt[vmtShader].ContainsKey("$alphatest") ? vmt[vmtShader]["$alphatest"] : false; translucent = vmt[vmtShader].ContainsKey("$translucent") ? vmt[vmtShader]["$translucent"] : false; noCull = vmt[vmtShader].ContainsKey("$nocull") ? vmt[vmtShader]["$nocull"] : false; baseTex = vmt[vmtShader].ContainsKey("$basetexture") ? vmt[vmtShader]["$basetexture"] : string.Empty; baseTex2 = vmt[vmtShader].ContainsKey("$basetexture2") ? vmt[vmtShader]["$basetexture2"] : string.Empty; bumpMap = vmt[vmtShader].ContainsKey("bumpmap") ? vmt[vmtShader]["bumpmap"] : string.Empty; color = vmt[vmtShader].ContainsKey("$color") ? vmt[vmtShader]["$color"] : new SourceUtils.Color32(255, 255, 255, 255); refractTint = vmt[vmtShader].ContainsKey("$refracttint") ? vmt[vmtShader]["$refracttint"] : new SourceUtils.Color32(255, 255, 255, 255); surfaceProp = vmt[vmtShader].ContainsKey("$surfaceprop") ? vmt[vmtShader]["$surfaceprop"] : "grass"; include = vmt[vmtShader].ContainsKey("include") ? vmt[vmtShader]["include"] : string.Empty; alpha = vmt[vmtShader].ContainsKey("$alpha") ? vmt[vmtShader]["$alpha"] : 1.0f; refractAmount = vmt[vmtShader].ContainsKey("$refractamount") ? vmt[vmtShader]["$refractamount"] : 0.2f; compileSky = vmt[vmtShader].ContainsKey("%compilesky") ? vmt[vmtShader]["%compilesky"] : 0; break; } if (!string.IsNullOrEmpty(include)) { using (var fs = resourceLoader.OpenFile(include)) { var includedVmt = ValveMaterialFile.FromStream(fs); return(VmtToMaterial(resourceLoader, includedVmt, include)); } } Object materialResource; Material result; materialResource = surfaceProp == "water" ? _options.WaterMaterial : _options.FaceMaterial; if (materialResource == null) { var shader = Shader.Find("BSP/Lightmapped") ?? Shader.Find("HDRP/Lit") ?? Shader.Find("URP/Lit") ?? Shader.Find("Lightweight Render Pipeline/Lit") ?? Shader.Find("Standard"); result = new Material(shader); } else { result = GameObject.Instantiate(materialResource) as Material; } //result.SetTexture("_MainTex", LoadTexture(resourceLoader, baseTex)); result.mainTexture = LoadTexture(resourceLoader, baseTex); result.SetFloat("_Smoothness", 0); result.SetFloat("_Metallic", .8f); result.name = vmtPath; if (!string.IsNullOrEmpty(bumpMap)) { result.SetTexture("_BumpMap", LoadTexture(resourceLoader, bumpMap)); } if (transition) { result.SetTexture("_MainTex2", LoadTexture(resourceLoader, baseTex2)); } if (translucent) { var baseColor = result.GetColor("_BaseColor"); baseColor.a = alpha; result.SetColor("_BaseColor", baseColor); result.SetFloat("_SurfaceType", 1); } return(result); }