public static void SetShader(GStylizedTerrain terrain, GLightingModel lighting, GTexturingModel texturing, GSplatsModel splats = GSplatsModel.Splats4) { if (terrain.TerrainData == null) { throw new NullReferenceException("The selected terrain doesn't have terrain data."); } if (terrain.TerrainData.Shading.CustomMaterial == null) { throw new NullReferenceException("The selected terrain doesn't have material. Make sure you've assigned a material for it."); } Material mat = GRuntimeSettings.Instance.terrainRendering.GetClonedMaterial( GCommon.CurrentRenderPipeline, lighting, texturing, splats); if (mat == null) { throw new Exception("Fail to get template material. Try re-install render pipeline extension package."); } terrain.TerrainData.Shading.CustomMaterial.shader = mat.shader; terrain.TerrainData.Shading.UpdateMaterials(); GUtilities.DestroyObject(mat); }
public Material GetClonedMaterial(GRenderPipelineType pipeline, GLightingModel light, GTexturingModel texturing, GSplatsModel splats = GSplatsModel.Splats4) { GWizardMaterialTemplate matTemplate; List <GWizardMaterialTemplate> collection = pipeline == GRenderPipelineType.Universal ? UniversalRPMaterials : BuiltinRPMaterials; if (texturing != GTexturingModel.Splat) { matTemplate = collection.Find(m => { return(m.LightingModel == light && m.TexturingModel == texturing); }); } else { matTemplate = collection.Find(m => { return(m.LightingModel == light && m.TexturingModel == texturing && m.SplatsModel == splats); }); } Material mat = null; if (matTemplate.Material != null) { mat = UnityEngine.Object.Instantiate(matTemplate.Material); } return(mat); }