using System.IO; using UnityEngine; using UnityEngine.Experimental.Rendering; using UnityEngine.Experimental.Rendering.HDPipeline; namespace UnityEditor.Experimental.Rendering.HDPipeline { using UnityObject = UnityEngine.Object; static class HDAssetFactory { static string s_RenderPipelineResourcesPath { get { return HDEditorUtils.GetHDRenderPipelinePath() + "RenderPipelineResources/HDRenderPipelineResources.asset"; } } class DoCreateNewAssetHDRenderPipeline : ProjectWindowCallback.EndNameEditAction { public override void Action(int instanceId, string pathName, string resourceFile) { var newAsset = CreateInstance(); newAsset.name = Path.GetFileName(pathName); // Load default renderPipelineResources / Material / Shader newAsset.renderPipelineResources = AssetDatabase.LoadAssetAtPath(s_RenderPipelineResourcesPath); AssetDatabase.CreateAsset(newAsset, pathName); ProjectWindowUtil.ShowCreatedAsset(newAsset); } } [MenuItem("Assets/Create/Rendering/High Definition Render Pipeline Asset", priority = CoreUtils.assetCreateMenuPriority1)] static void CreateHDRenderPipeline() { var icon = EditorGUIUtility.FindTexture("ScriptableObject Icon"); ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance(), "New HDRenderPipelineAsset.asset", icon, null); } // Note: move this to a static using once we can target C#6+ static T Load(string path) where T : UnityObject { return AssetDatabase.LoadAssetAtPath(path); } class DoCreateNewAssetHDRenderPipelineResources : ProjectWindowCallback.EndNameEditAction { public override void Action(int instanceId, string pathName, string resourceFile) { var newAsset = CreateInstance(); newAsset.name = Path.GetFileName(pathName); // Load default renderPipelineResources / Material / Shader string HDRenderPipelinePath = HDEditorUtils.GetHDRenderPipelinePath(); string CorePath = HDEditorUtils.GetCorePath(); newAsset.defaultDiffuseMaterial = Load(HDRenderPipelinePath + "RenderPipelineResources/DefaultHDMaterial.mat"); newAsset.defaultDecalMaterial = Load(HDRenderPipelinePath + "RenderPipelineResources/DefaultHDDecalMaterial.mat"); newAsset.defaultShader = Load(HDRenderPipelinePath + "Material/Lit/Lit.shader"); newAsset.debugFontTexture = Load(HDRenderPipelinePath + "RenderPipelineResources/DebugFont.tga"); newAsset.debugDisplayLatlongShader = Load(HDRenderPipelinePath + "Debug/DebugDisplayLatlong.Shader"); newAsset.debugViewMaterialGBufferShader = Load(HDRenderPipelinePath + "Debug/DebugViewMaterialGBuffer.Shader"); newAsset.debugViewTilesShader = Load(HDRenderPipelinePath + "Debug/DebugViewTiles.Shader"); newAsset.debugFullScreenShader = Load(HDRenderPipelinePath + "Debug/DebugFullScreen.Shader"); newAsset.debugColorPickerShader = Load(HDRenderPipelinePath + "Debug/DebugColorPicker.Shader"); newAsset.deferredShader = Load(HDRenderPipelinePath + "Lighting/Deferred.Shader"); newAsset.gaussianPyramidCS = Load(HDRenderPipelinePath + "RenderPipelineResources/ColorPyramid.compute"); newAsset.depthPyramidCS = Load(HDRenderPipelinePath + "RenderPipelineResources/DepthPyramid.compute"); newAsset.copyChannelCS = Load(CorePath + "Resources/GPUCopy.compute"); newAsset.applyDistortionCS = Load(HDRenderPipelinePath + "RenderPipelineResources/ApplyDistorsion.compute"); newAsset.clearDispatchIndirectShader = Load(HDRenderPipelinePath + "Lighting/LightLoop/cleardispatchindirect.compute"); newAsset.buildDispatchIndirectShader = Load(HDRenderPipelinePath + "Lighting/LightLoop/builddispatchindirect.compute"); newAsset.buildScreenAABBShader = Load(HDRenderPipelinePath + "Lighting/LightLoop/scrbound.compute"); newAsset.buildPerTileLightListShader = Load(HDRenderPipelinePath + "Lighting/LightLoop/lightlistbuild.compute"); newAsset.buildPerBigTileLightListShader = Load(HDRenderPipelinePath + "Lighting/LightLoop/lightlistbuild-bigtile.compute"); newAsset.buildPerVoxelLightListShader = Load(HDRenderPipelinePath + "Lighting/LightLoop/lightlistbuild-clustered.compute"); newAsset.buildMaterialFlagsShader = Load(HDRenderPipelinePath + "Lighting/LightLoop/materialflags.compute"); newAsset.deferredComputeShader = Load(HDRenderPipelinePath + "Lighting/LightLoop/Deferred.compute"); newAsset.deferredDirectionalShadowComputeShader = Load(HDRenderPipelinePath + "Lighting/DeferredDirectionalShadow.compute"); newAsset.volumetricLightingCS = Load(HDRenderPipelinePath + "Lighting/Volumetrics/Resources/VolumetricLighting.compute"); newAsset.subsurfaceScatteringCS = Load(HDRenderPipelinePath + "Material/SubsurfaceScattering/SubsurfaceScattering.compute"); newAsset.subsurfaceScattering = Load(HDRenderPipelinePath + "Material/SubsurfaceScattering/SubsurfaceScattering.shader"); newAsset.combineLighting = Load(HDRenderPipelinePath + "Material/SubsurfaceScattering/CombineLighting.shader"); // General newAsset.cameraMotionVectors = Load(HDRenderPipelinePath + "RenderPipelineResources/CameraMotionVectors.shader"); newAsset.copyStencilBuffer = Load(HDRenderPipelinePath + "RenderPipelineResources/CopyStencilBuffer.shader"); newAsset.copyDepthBuffer = Load(HDRenderPipelinePath + "RenderPipelineResources/CopyDepthBuffer.shader"); newAsset.blit = Load(HDRenderPipelinePath + "RenderPipelineResources/Blit.shader"); // Sky newAsset.blitCubemap = Load(HDRenderPipelinePath + "Sky/BlitCubemap.shader"); newAsset.buildProbabilityTables = Load(HDRenderPipelinePath + "Material/GGXConvolution/BuildProbabilityTables.compute"); newAsset.computeGgxIblSampleData = Load(HDRenderPipelinePath + "Material/GGXConvolution/ComputeGgxIblSampleData.compute"); newAsset.GGXConvolve = Load(HDRenderPipelinePath + "Material/GGXConvolution/GGXConvolve.shader"); newAsset.opaqueAtmosphericScattering = Load(HDRenderPipelinePath + "Sky/OpaqueAtmosphericScattering.shader"); newAsset.encodeBC6HCS = Load(CorePath + "Resources/EncodeBC6H.compute"); // Skybox/Cubemap is a builtin shader, must use Sahder.Find to access it. It is fine because we are in the editor newAsset.skyboxCubemap = Shader.Find("Skybox/Cubemap"); AssetDatabase.CreateAsset(newAsset, pathName); ProjectWindowUtil.ShowCreatedAsset(newAsset); } } [MenuItem("Assets/Create/Rendering/High Definition Render Pipeline Resources", priority = CoreUtils.assetCreateMenuPriority1)] static void CreateRenderPipelineResources() { var icon = EditorGUIUtility.FindTexture("ScriptableObject Icon"); ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance(), "New HDRenderPipelineResources.asset", icon, null); } } }