using UnityEngine ;
using System.IO ;
using UnityEngine ;
using UnityEngine.Experimental.Rendering ;
using UnityEngine.Experimental.Rendering.HDPipeline ;
get { return HDEditorUtils . GetHDRenderPipelinePath ( ) + "RenderPipelineResources/HDRenderPipelineResources.asset" ; }
}
static string s_DefaultMaterialPath
{
get { return HDEditorUtils . GetHDRenderPipelinePath ( ) + "RenderPipelineResources/DefaultHDMaterial.mat" ; }
}
static string s_DefaultShaderPath
{
get { return HDEditorUtils . GetHDRenderPipelinePath ( ) + "Material/Lit/Lit.shader" ; }
}
class DoCreateNewAssetHDRenderPipeline : ProjectWindowCallback . EndNameEditAction
{
public override void Action ( int instanceId , string pathName , string resourceFile )
{
var newAsset = CreateInstance < HDRenderPipelineAsset > ( ) ;
newAsset . name = Path . GetFileName ( pathName ) ;
// Load default renderPipelineResources / Material / Shader
newAsset . renderPipelineResources = AssetDatabase . LoadAssetAtPath < RenderPipelineResources > ( s_RenderPipelineResourcesPath ) ;
newAsset . defaultDiffuseMaterial = AssetDatabase . LoadAssetAtPath < Material > ( s_DefaultMaterialPath ) ;
newAsset . defaultShader = AssetDatabase . LoadAssetAtPath < Shader > ( s_DefaultShaderPath ) ;
AssetDatabase . CreateAsset ( newAsset , pathName ) ;
ProjectWindowUtil . ShowCreatedAsset ( newAsset ) ;
}
}
var instance = ScriptableObject . CreateInstance < HDRenderPipelineAsset > ( ) ;
AssetDatabase . CreateAsset ( instance , HDEditorUtils . GetHDRenderPipelinePath ( ) + "HDRenderPipelineAsset.asset" ) ;
// If it exist, load renderPipelineResources
instance . renderPipelineResources = AssetDatabase . LoadAssetAtPath < RenderPipelineResources > ( s_RenderPipelineResourcesPath ) ;
var icon = EditorGUIUtility . FindTexture ( "ScriptableObject Icon" ) ;
ProjectWindowUtil . StartNameEditingIfProjectWindowExists ( 0 , ScriptableObject . CreateInstance < DoCreateNewAssetHDRenderPipeline > ( ) , "New HDRenderPipelineAsset.asset" , icon , null ) ;
// TODO skybox/cubemap
// Note: move this to a static using once we can target C#6+
static T Load < T > ( string path ) where T : UnityObject
{
return AssetDatabase . LoadAssetAtPath < T > ( path ) ;
}
[MenuItem("Assets/Create/Render Pipeline/High Definition/Render Pipeline Resources", priority = CoreUtils.assetCreateMenuPriority2)]
static void CreateRenderPipelineResources ( )
class DoCreateNewAssetHDRenderPipelineResources : ProjectWindowCallback . EndNameEditAction
string HDRenderPipelinePath = HDEditorUtils . GetHDRenderPipelinePath ( ) ;
string PostProcessingPath = HDEditorUtils . GetPostProcessingPath ( ) ;
string CorePath = HDEditorUtils . GetCorePath ( ) ;
public override void Action ( int instanceId , string pathName , string resourceFile )
{
var newAsset = CreateInstance < RenderPipelineResources > ( ) ;
newAsset . name = Path . GetFileName ( pathName ) ;
var instance = ScriptableObject . CreateInstance < RenderPipelineResources > ( ) ;
// Load default renderPipelineResources / Material / Shader
string HDRenderPipelinePath = HDEditorUtils . GetHDRenderPipelinePath ( ) ;
string PostProcessingPath = HDEditorUtils . GetPostProcessingPath ( ) ;
string CorePath = HDEditorUtils . GetCorePath ( ) ;
instance . debugDisplayLatlongShader = Load < Shader > ( HDRenderPipelinePath + "Debug/DebugDisplayLatlong.Shader" ) ;
instance . debugViewMaterialGBufferShader = Load < Shader > ( HDRenderPipelinePath + "Debug/DebugViewMaterialGBuffer.Shader" ) ;
instance . debugViewTilesShader = Load < Shader > ( HDRenderPipelinePath + "Debug/DebugViewTiles.Shader" ) ;
instance . debugFullScreenShader = Load < Shader > ( HDRenderPipelinePath + "Debug/DebugFullScreen.Shader" ) ;
newAsset . debugDisplayLatlongShader = Load < Shader > ( HDRenderPipelinePath + "Debug/DebugDisplayLatlong.Shader" ) ;
newAsset . debugViewMaterialGBufferShader = Load < Shader > ( HDRenderPipelinePath + "Debug/DebugViewMaterialGBuffer.Shader" ) ;
newAsset . debugViewTilesShader = Load < Shader > ( HDRenderPipelinePath + "Debug/DebugViewTiles.Shader" ) ;
newAsset . debugFullScreenShader = Load < Shader > ( HDRenderPipelinePath + "Debug/DebugFullScreen.Shader" ) ;
instance . deferredShader = Load < Shader > ( HDRenderPipelinePath + "Lighting/Deferred.Shader" ) ;
instance . subsurfaceScatteringCS = Load < ComputeShader > ( HDRenderPipelinePath + "Material/Lit/Resources/SubsurfaceScattering.compute" ) ;
instance . volumetricLightingCS = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/Volumetrics/Resources/VolumetricLighting.compute" ) ;
instance . gaussianPyramidCS = Load < ComputeShader > ( PostProcessingPath + "Shaders/Builtins/GaussianDownsample.compute" ) ;
instance . depthPyramidCS = Load < ComputeShader > ( HDRenderPipelinePath + "RenderPipelineResources/DepthDownsample.compute" ) ;
instance . copyChannelCS = Load < ComputeShader > ( CorePath + "Resources/GPUCopy.compute" ) ;
instance . applyDistortionCS = Load < ComputeShader > ( HDRenderPipelinePath + "RenderPipelineResources/ApplyDistorsion.compute" ) ;
newAsset . deferredShader = Load < Shader > ( HDRenderPipelinePath + "Lighting/Deferred.Shader" ) ;
newAsset . subsurfaceScatteringCS = Load < ComputeShader > ( HDRenderPipelinePath + "Material/Lit/Resources/SubsurfaceScattering.compute" ) ;
newAsset . gaussianPyramidCS = Load < ComputeShader > ( PostProcessingPath + "Shaders/Builtins/GaussianDownsample.compute" ) ;
newAsset . depthPyramidCS = Load < ComputeShader > ( HDRenderPipelinePath + "RenderPipelineResources/DepthDownsample.compute" ) ;
newAsset . copyChannelCS = Load < ComputeShader > ( CorePath + "Resources/GPUCopy.compute" ) ;
newAsset . applyDistortionCS = Load < ComputeShader > ( HDRenderPipelinePath + "RenderPipelineResources/ApplyDistorsion.compute" ) ;
instance . clearDispatchIndirectShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/cleardispatchindirect.compute" ) ;
instance . buildDispatchIndirectShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/builddispatchindirect.compute" ) ;
instance . buildScreenAABBShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/scrbound.compute" ) ;
instance . buildPerTileLightListShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/lightlistbuild.compute" ) ;
instance . buildPerBigTileLightListShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/lightlistbuild-bigtile.compute" ) ;
instance . buildPerVoxelLightListShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/lightlistbuild-clustered.compute" ) ;
instance . buildMaterialFlagsShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/materialflags.compute" ) ;
instance . deferredComputeShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/Deferred.compute" ) ;
newAsset . clearDispatchIndirectShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/cleardispatchindirect.compute" ) ;
newAsset . buildDispatchIndirectShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/builddispatchindirect.compute" ) ;
newAsset . buildScreenAABBShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/scrbound.compute" ) ;
newAsset . buildPerTileLightListShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/lightlistbuild.compute" ) ;
newAsset . buildPerBigTileLightListShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/lightlistbuild-bigtile.compute" ) ;
newAsset . buildPerVoxelLightListShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/lightlistbuild-clustered.compute" ) ;
newAsset . buildMaterialFlagsShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/materialflags.compute" ) ;
newAsset . deferredComputeShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/Deferred.compute" ) ;
instance . deferredDirectionalShadowComputeShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/DeferredDirectionalShadow.compute" ) ;
newAsset . deferredDirectionalShadowComputeShader = Load < ComputeShader > ( HDRenderPipelinePath + "Lighting/TilePass/DeferredDirectionalShadow.compute" ) ;
// SceneSettings
// These shaders don't need to be reference by RenderPipelineResource as they are not use at runtime (only to draw in editor)
// instance.drawSssProfile = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>(HDRenderPipelinePath + "SceneSettings/DrawSssProfile.shader");
// instance.drawTransmittanceGraphShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>(HDRenderPipelinePath + "SceneSettings/DrawTransmittanceGraph.shader");
// SceneSettings
// These shaders don't need to be reference by RenderPipelineResource as they are not use at runtime (only to draw in editor)
// instance.drawSssProfile = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>(HDRenderPipelinePath + "SceneSettings/DrawSssProfile.shader");
// instance.drawTransmittanceGraphShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>(HDRenderPipelinePath + "SceneSettings/DrawTransmittanceGraph.shader");
instance . cameraMotionVectors = Load < Shader > ( HDRenderPipelinePath + "RenderPipelineResources/CameraMotionVectors.shader" ) ;
newAsset . cameraMotionVectors = Load < Shader > ( HDRenderPipelinePath + "RenderPipelineResources/CameraMotionVectors.shader" ) ;
// Sky
instance . blitCubemap = Load < Shader > ( HDRenderPipelinePath + "Sky/BlitCubemap.shader" ) ;
instance . buildProbabilityTables = Load < ComputeShader > ( HDRenderPipelinePath + "Sky/BuildProbabilityTables.compute" ) ;
instance . computeGgxIblSampleData = Load < ComputeShader > ( HDRenderPipelinePath + "Sky/ComputeGgxIblSampleData.compute" ) ;
instance . GGXConvolve = Load < Shader > ( HDRenderPipelinePath + "Sky/GGXConvolve.shader" ) ;
instance . opaqueAtmosphericScattering = Load < Shader > ( HDRenderPipelinePath + "Sky/OpaqueAtmosphericScattering.shader" ) ;
// Sky
newAsset . blitCubemap = Load < Shader > ( HDRenderPipelinePath + "Sky/BlitCubemap.shader" ) ;
newAsset . buildProbabilityTables = Load < ComputeShader > ( HDRenderPipelinePath + "Sky/BuildProbabilityTables.compute" ) ;
newAsset . computeGgxIblSampleData = Load < ComputeShader > ( HDRenderPipelinePath + "Sky/ComputeGgxIblSampleData.compute" ) ;
newAsset . GGXConvolve = Load < Shader > ( HDRenderPipelinePath + "Sky/GGXConvolve.shader" ) ;
newAsset . opaqueAtmosphericScattering = Load < Shader > ( HDRenderPipelinePath + "Sky/OpaqueAtmosphericScattering.shader" ) ;
// Skybox/Cubemap is a builtin shader, must use Sahder.Find to access it. It is fine because we are in the editor
instance . skyboxCubemap = Shader . Find ( "Skybox/Cubemap" ) ;
// 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 ( instance , s_RenderPipelineResourcesPath ) ;
AssetDatabase . SaveAssets ( ) ;
AssetDatabase . Refresh ( ) ;
AssetDatabase . CreateAsset ( newAsset , pathName ) ;
ProjectWindowUtil . ShowCreatedAsset ( newAsset ) ;
}
// Note: move this to a static using once we can target C#6+
static T Load < T > ( string path )
where T : UnityObject
[MenuItem("Assets/Create/Render Pipeline/High Definition/Render Pipeline Resources", priority = CoreUtils.assetCreateMenuPriority1)]
static void CreateRenderPipelineResources ( )
return AssetDatabase . LoadAssetAtPath < T > ( path ) ;
var icon = EditorGUIUtility . FindTexture ( "ScriptableObject Icon" ) ;
ProjectWindowUtil . StartNameEditingIfProjectWindowExists ( 0 , ScriptableObject . CreateInstance < DoCreateNewAssetHDRenderPipelineResources > ( ) , "New HDRenderPipelineResources.asset" , icon , null ) ;
}
}
}