可编程渲染管线报错 Unity Universal RP asset not assigned
文章来源地址https://www.toymoban.com/news/detail-686573.html
解决
1.创建urp资产
创建成功如下图
2.打开Edit > Project Settings… > Graphics
3.设置资产
如果你安装了URP包,当你编写自定义渲染管线时,既是你设置的上图资产也会报同样的错误。
解决办法是卸载URP包。安装自定义可编程渲染管线基础包。Url为 com.unity.render-pipelines.core。复制url到packageManager里面添加基础包。
点击add package from git url ,输入url为com.unity.render-pipelines.core ,然后add
安装完成如下
后面就可以编写自定义渲染管线了
渲染管线资产
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
[CreateAssetMenu(menuName = "Rendering/MyPipeLineAsset")]
public class MyPipeLineAsset : RenderPipelineAsset
{
protected override RenderPipeline CreatePipeline()
{
return new MyRenderPipeLine();
}
}
渲染脚本文章来源:https://www.toymoban.com/news/detail-686573.html
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
public class CameraRender
{
private ScriptableRenderContext context;
private Camera _camera;
public void Render(ScriptableRenderContext context, Camera camera)
{
this.context = context;
this._camera = camera;
Draw();
}
private void Draw()
{
// 创建并调度命令以清除当前渲染目标
var cmd = new CommandBuffer();
cmd.ClearRenderTarget(true, true, Color.black);
context.ExecuteCommandBuffer(cmd);
cmd.Release();
DrawSky();
CameraCull();
Submit();
}
private void DrawSky()
{
context.SetupCameraProperties(_camera);
context.DrawSkybox(_camera);
}
private void CameraCull()
{
_camera.TryGetCullingParameters(out var parameters);
var result = context.Cull(ref parameters);
DrawingSettings drawingSettings = new DrawingSettings();
drawingSettings.SetShaderPassName(1, new ShaderTagId("SRPDefaultUnlit"));
SortingSettings sortingSettings = new SortingSettings();
sortingSettings.criteria = SortingCriteria.CommonOpaque;
drawingSettings.sortingSettings = sortingSettings;
FilteringSettings filteringSettings = new FilteringSettings(RenderQueueRange.opaque);
context.DrawRenderers(result, ref drawingSettings, ref filteringSettings);
sortingSettings.criteria = SortingCriteria.CommonTransparent;
filteringSettings.renderQueueRange = RenderQueueRange.transparent;
context.DrawRenderers(result, ref drawingSettings, ref filteringSettings);
}
private void Submit()
{
context.Submit();
}
}
public class MyRenderPipeLine : RenderPipeline
{
private CameraRender _cameraRender = new CameraRender();
protected override void Render(ScriptableRenderContext context, Camera[] cameras)
{
foreach (var camera in cameras)
{
_cameraRender.Render(context, camera);
}
}
}
到了这里,关于可编程渲染管线报错 Unity Universal RP asset not assigned的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!